Commit 5c3a8508cb67f8909dc9441f06d498ad2686f7b5
1 parent
51c98949
Exclude consistently binned and non CTA observations from the processing.
Showing
5 changed files
with
188 additions
and
198 deletions
scripts/cslightcrv.py
| @@ -112,7 +112,6 @@ class cslightcrv(ctools.cscript): | @@ -112,7 +112,6 @@ class cslightcrv(ctools.cscript): | ||
| 112 | pars.append(gammalib.GApplicationPar("tmax","r","a","51544.6","","days","Lightcurve stop time [MJD]")) | 112 | pars.append(gammalib.GApplicationPar("tmax","r","a","51544.6","","days","Lightcurve stop time [MJD]")) |
| 113 | pars.append(gammalib.GApplicationPar("tbins","i","a","5","","","Number of time bins")) | 113 | pars.append(gammalib.GApplicationPar("tbins","i","a","5","","","Number of time bins")) |
| 114 | pars.append(gammalib.GApplicationPar("tbinfile","f","a","tbins.fits","","", "File defining the time binning")) | 114 | pars.append(gammalib.GApplicationPar("tbinfile","f","a","tbins.fits","","", "File defining the time binning")) |
| 115 | - #pars.append(gammalib.GApplicationPar("binned","b","a","no","yes|no","","Use binned analysis in each time bin")) | ||
| 116 | pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins per light curve bin (0=unbinned)")) | 115 | pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins per light curve bin (0=unbinned)")) |
| 117 | pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit of events (TeV)")) | 116 | pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit of events (TeV)")) |
| 118 | pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit of events (TeV)")) | 117 | pars.append(gammalib.GApplicationPar("emax","r","a","100.0","","","Upper energy limit of events (TeV)")) |
src/ctbin/ctbin.cpp
| @@ -244,37 +244,40 @@ void ctbin::run(void) | @@ -244,37 +244,40 @@ void ctbin::run(void) | ||
| 244 | // Get CTA observation | 244 | // Get CTA observation |
| 245 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | 245 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); |
| 246 | 246 | ||
| 247 | - // Continue only if observation is a CTA observation | ||
| 248 | - if (obs != NULL) { | ||
| 249 | - | ||
| 250 | - // Write header for observation | 247 | + // Skip observation if it's not CTA |
| 248 | + if (obs == NULL) { | ||
| 251 | if (logTerse()) { | 249 | if (logTerse()) { |
| 252 | - if (obs->name().length() > 1) { | ||
| 253 | - log.header3("Observation "+obs->name()); | ||
| 254 | - } | ||
| 255 | - else { | ||
| 256 | - log.header3("Observation"); | ||
| 257 | - } | 250 | + log << "Warning: Skipping "+m_obs[i]->instrument(); |
| 251 | + log << " observation \""; | ||
| 252 | + log << m_obs[i]->name() << "\"" << std::endl; | ||
| 258 | } | 253 | } |
| 254 | + continue; | ||
| 255 | + } | ||
| 259 | 256 | ||
| 260 | - // Skip observation if we don't have an unbinned observation | ||
| 261 | - if (obs->eventtype() != "EventList") { | ||
| 262 | - | ||
| 263 | - // Log that we skip the this observation | ||
| 264 | - if (logTerse()) { | ||
| 265 | - log << "Warning: Skipping binned observation \""+obs->name()+"\""; | ||
| 266 | - log << std::endl; | ||
| 267 | - } | ||
| 268 | - continue; | 257 | + // Skip observation if we have a binned observation |
| 258 | + if (obs->eventtype() == "CountsCube") { | ||
| 259 | + if (logTerse()) { | ||
| 260 | + log << "Warning: Skipping binned observation \""; | ||
| 261 | + log << obs->name()+"\"" << std::endl; | ||
| 269 | } | 262 | } |
| 263 | + continue; | ||
| 264 | + } | ||
| 270 | 265 | ||
| 271 | - // Fill the cube | ||
| 272 | - fill_cube(obs); | 266 | + // Write header for observation |
| 267 | + if (logTerse()) { | ||
| 268 | + if (obs->name().length() > 1) { | ||
| 269 | + log.header3("Observation "+obs->name()); | ||
| 270 | + } | ||
| 271 | + else { | ||
| 272 | + log.header3("Observation"); | ||
| 273 | + } | ||
| 274 | + } | ||
| 273 | 275 | ||
| 274 | - // Dispose events to free memory | ||
| 275 | - obs->dispose_events(); | 276 | + // Fill the cube |
| 277 | + fill_cube(obs); | ||
| 276 | 278 | ||
| 277 | - } // endif: CTA observation found | 279 | + // Dispose events to free memory |
| 280 | + obs->dispose_events(); | ||
| 278 | 281 | ||
| 279 | } // endfor: looped over observations | 282 | } // endfor: looped over observations |
| 280 | 283 |
src/ctobssim/ctobssim.cpp
| @@ -327,93 +327,89 @@ void ctobssim::run(void) | @@ -327,93 +327,89 @@ void ctobssim::run(void) | ||
| 327 | // Get pointer on CTA observation | 327 | // Get pointer on CTA observation |
| 328 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | 328 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); |
| 329 | 329 | ||
| 330 | - // Continue only if observation is a CTA observation | ||
| 331 | - if (obs != NULL) { | ||
| 332 | - | ||
| 333 | - // Write header for observation | 330 | + // Skip observation if it's not CTA |
| 331 | + if (obs == NULL) { | ||
| 334 | if (logTerse()) { | 332 | if (logTerse()) { |
| 335 | - if (obs->name().length() > 1) { | ||
| 336 | - wrklog.header3("Observation "+obs->name()); | ||
| 337 | - } | ||
| 338 | - else { | ||
| 339 | - wrklog.header3("Observation"); | ||
| 340 | - } | 333 | + log << "Warning: Skipping "+m_obs[i]->instrument(); |
| 334 | + log << " observation \""; | ||
| 335 | + log << m_obs[i]->name() << "\"" << std::endl; | ||
| 341 | } | 336 | } |
| 337 | + continue; | ||
| 338 | + } | ||
| 342 | 339 | ||
| 343 | - // Skip observation if we don't have an unbinned observation | ||
| 344 | - if (obs->eventtype() != "EventList") { | 340 | + // Skip observation if we have a binned observation |
| 341 | + if (obs->eventtype() == "CountsCube") { | ||
| 342 | + if (logTerse()) { | ||
| 343 | + log << "Warning: Skipping binned observation \""; | ||
| 344 | + log << obs->name()+"\"" << std::endl; | ||
| 345 | + } | ||
| 346 | + continue; | ||
| 347 | + } | ||
| 345 | 348 | ||
| 346 | - // Log that we skip the this observation | ||
| 347 | - if (logTerse()) { | ||
| 348 | - log << "Warning: Skipping binned observation \""+obs->name()+"\""; | ||
| 349 | - log << std::endl; | ||
| 350 | - } | ||
| 351 | - continue; | 349 | + // Write header for observation |
| 350 | + if (logTerse()) { | ||
| 351 | + if (obs->name().length() > 1) { | ||
| 352 | + wrklog.header3("Observation "+obs->name()); | ||
| 353 | + } | ||
| 354 | + else { | ||
| 355 | + wrklog.header3("Observation"); | ||
| 352 | } | 356 | } |
| 357 | + } | ||
| 353 | 358 | ||
| 354 | - // Work on a clone of the CTA observation. This makes sure that | ||
| 355 | - // any memory allocated for computing (for example a response | ||
| 356 | - // cache) is properly de-allocated on exit of this run | ||
| 357 | - GCTAObservation obs_clone = *obs; | 359 | + // Work on a clone of the CTA observation. This makes sure that |
| 360 | + // any memory allocated for computing (for example a response | ||
| 361 | + // cache) is properly de-allocated on exit of this run | ||
| 362 | + GCTAObservation obs_clone = *obs; | ||
| 358 | 363 | ||
| 359 | - // Save number of events before entering simulation | ||
| 360 | - int events_before = obs_clone.events()->size(); | 364 | + // Save number of events before entering simulation |
| 365 | + int events_before = obs_clone.events()->size(); | ||
| 361 | 366 | ||
| 362 | - // Simulate source events | ||
| 363 | - simulate_source(&obs_clone, models, m_rans[i], &wrklog); | 367 | + // Simulate source events |
| 368 | + simulate_source(&obs_clone, models, m_rans[i], &wrklog); | ||
| 364 | 369 | ||
| 365 | - // Simulate source events | ||
| 366 | - simulate_background(&obs_clone, models, m_rans[i], &wrklog); | 370 | + // Simulate source events |
| 371 | + simulate_background(&obs_clone, models, m_rans[i], &wrklog); | ||
| 367 | 372 | ||
| 368 | - // Dump simulation results | ||
| 369 | - if (logNormal()) { | ||
| 370 | - wrklog << gammalib::parformat("MC events"); | ||
| 371 | - wrklog << obs_clone.events()->size() - events_before; | ||
| 372 | - wrklog << " (all models)"; | ||
| 373 | - wrklog << std::endl; | ||
| 374 | - } | ||
| 375 | - | ||
| 376 | - // Append the event list to the original observation | ||
| 377 | - obs->events(*(obs_clone.events())); | 373 | + // Dump simulation results |
| 374 | + if (logNormal()) { | ||
| 375 | + wrklog << gammalib::parformat("MC events"); | ||
| 376 | + wrklog << obs_clone.events()->size() - events_before; | ||
| 377 | + wrklog << " (all models)"; | ||
| 378 | + wrklog << std::endl; | ||
| 379 | + } | ||
| 378 | 380 | ||
| 379 | - // If requested, event lists are saved immediately | ||
| 380 | - if (m_save_and_dispose) { | 381 | + // Append the event list to the original observation |
| 382 | + obs->events(*(obs_clone.events())); | ||
| 381 | 383 | ||
| 382 | - // Set event output file name. If multiple observations are | ||
| 383 | - // handled, build the filename from prefix and observation | ||
| 384 | - // index. Otherwise use the outfile parameter. | ||
| 385 | - std::string outfile; | ||
| 386 | - if (m_use_xml) { | ||
| 387 | - m_prefix = (*this)["prefix"].string(); | ||
| 388 | - outfile = m_prefix + gammalib::str(i) + ".fits"; | ||
| 389 | - } | ||
| 390 | - else { | ||
| 391 | - outfile = (*this)["outevents"].filename(); | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | - // Store output file name in original observation | ||
| 395 | - obs->eventfile(outfile); | 384 | + // If requested, event lists are saved immediately |
| 385 | + if (m_save_and_dispose) { | ||
| 396 | 386 | ||
| 397 | - // Save observation into FITS file. This is a critical zone | ||
| 398 | - // to avoid multiple threads writing simultaneously | ||
| 399 | - #pragma omp critical | ||
| 400 | - { | ||
| 401 | - obs_clone.save(outfile, clobber()); | ||
| 402 | - } | 387 | + // Set event output file name. If multiple observations are |
| 388 | + // handled, build the filename from prefix and observation | ||
| 389 | + // index. Otherwise use the outfile parameter. | ||
| 390 | + std::string outfile; | ||
| 391 | + if (m_use_xml) { | ||
| 392 | + m_prefix = (*this)["prefix"].string(); | ||
| 393 | + outfile = m_prefix + gammalib::str(i) + ".fits"; | ||
| 394 | + } | ||
| 395 | + else { | ||
| 396 | + outfile = (*this)["outevents"].filename(); | ||
| 397 | + } | ||
| 403 | 398 | ||
| 404 | - // Dispose events | ||
| 405 | - obs->dispose_events(); | 399 | + // Store output file name in original observation |
| 400 | + obs->eventfile(outfile); | ||
| 406 | 401 | ||
| 402 | + // Save observation into FITS file. This is a critical zone | ||
| 403 | + // to avoid multiple threads writing simultaneously | ||
| 404 | + #pragma omp critical | ||
| 405 | + { | ||
| 406 | + obs_clone.save(outfile, clobber()); | ||
| 407 | } | 407 | } |
| 408 | 408 | ||
| 409 | - // ... otherwise append the event list to the original observation | ||
| 410 | - /* | ||
| 411 | - else { | ||
| 412 | - obs->events(*(obs_clone.events())); | ||
| 413 | - } | ||
| 414 | - */ | 409 | + // Dispose events |
| 410 | + obs->dispose_events(); | ||
| 415 | 411 | ||
| 416 | - } // endif: CTA observation found | 412 | + } |
| 417 | 413 | ||
| 418 | } // endfor: looped over observations | 414 | } // endfor: looped over observations |
| 419 | 415 |
src/ctselect/ctselect.cpp
| @@ -249,85 +249,88 @@ void ctselect::run(void) | @@ -249,85 +249,88 @@ void ctselect::run(void) | ||
| 249 | // Get CTA observation | 249 | // Get CTA observation |
| 250 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | 250 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); |
| 251 | 251 | ||
| 252 | - // Continue only if observation is a CTA observation | ||
| 253 | - if (obs != NULL) { | ||
| 254 | - | ||
| 255 | - // Write header for observation | 252 | + // Skip observation if it's not CTA |
| 253 | + if (obs == NULL) { | ||
| 256 | if (logTerse()) { | 254 | if (logTerse()) { |
| 257 | - if (obs->name().length() > 1) { | ||
| 258 | - log.header3("Observation "+obs->name()); | ||
| 259 | - } | ||
| 260 | - else { | ||
| 261 | - log.header3("Observation"); | ||
| 262 | - } | 255 | + log << "Warning: Skipping "+m_obs[i]->instrument(); |
| 256 | + log << " observation \""; | ||
| 257 | + log << m_obs[i]->name() << "\"" << std::endl; | ||
| 263 | } | 258 | } |
| 259 | + continue; | ||
| 260 | + } | ||
| 264 | 261 | ||
| 265 | - // Increment counter | ||
| 266 | - n_observations++; | ||
| 267 | - | ||
| 268 | - // Save event file name (for possible saving) | ||
| 269 | - m_infiles[i] = obs->eventfile(); | ||
| 270 | - | ||
| 271 | - // Skip observation if we don't have an unbinned observation | ||
| 272 | - if (obs->eventtype() != "EventList") { | ||
| 273 | - | ||
| 274 | - // Log that we skip the this observation | ||
| 275 | - if (logTerse()) { | ||
| 276 | - log << "Warning: Skipping binned observation \""+obs->name()+"\""; | ||
| 277 | - log << std::endl; | ||
| 278 | - } | ||
| 279 | - continue; | 262 | + // Skip observation if we have a binned observation |
| 263 | + if (obs->eventtype() == "CountsCube") { | ||
| 264 | + if (logTerse()) { | ||
| 265 | + log << "Warning: Skipping binned observation \""; | ||
| 266 | + log << obs->name()+"\"" << std::endl; | ||
| 280 | } | 267 | } |
| 268 | + continue; | ||
| 269 | + } | ||
| 281 | 270 | ||
| 282 | - // Fall through in case that the event file is empty | ||
| 283 | - if (obs->events()->size() == 0) { | ||
| 284 | - if (logTerse()) { | ||
| 285 | - log << " Warning: No events in event file \""; | ||
| 286 | - log << m_infiles[i] << "\". Event selection skipped."; | ||
| 287 | - log << std::endl; | ||
| 288 | - } | ||
| 289 | - continue; | 271 | + // Write header for observation |
| 272 | + if (logTerse()) { | ||
| 273 | + if (obs->name().length() > 1) { | ||
| 274 | + log.header3("Observation "+obs->name()); | ||
| 275 | + } | ||
| 276 | + else { | ||
| 277 | + log.header3("Observation"); | ||
| 290 | } | 278 | } |
| 279 | + } | ||
| 280 | + | ||
| 281 | + // Increment counter | ||
| 282 | + n_observations++; | ||
| 283 | + | ||
| 284 | + // Save event file name (for possible saving) | ||
| 285 | + m_infiles[i] = obs->eventfile(); | ||
| 291 | 286 | ||
| 292 | - // Get temporary file name | ||
| 293 | - #if G_USE_MKSTEMP | ||
| 294 | - char tpl[] = "ctselectXXXXXX"; | ||
| 295 | - int fileid = mkstemp(tpl); | ||
| 296 | - std::string filename(tpl); | ||
| 297 | - #else | ||
| 298 | - std::string filename = std::tmpnam(NULL); | ||
| 299 | - #endif | ||
| 300 | - | ||
| 301 | - // Save observation in temporary file | ||
| 302 | - obs->save(filename, true); | ||
| 303 | - | ||
| 304 | - // Log saved FITS file | ||
| 305 | - if (logExplicit()) { | ||
| 306 | - GFits tmpfile(filename); | 287 | + // Fall through in case that the event file is empty |
| 288 | + if (obs->events()->size() == 0) { | ||
| 289 | + if (logTerse()) { | ||
| 290 | + log << " Warning: No events in event file \""; | ||
| 291 | + log << m_infiles[i] << "\". Event selection skipped."; | ||
| 307 | log << std::endl; | 292 | log << std::endl; |
| 308 | - log.header1("FITS file content of temporary file"); | ||
| 309 | - log << tmpfile << std::endl; | ||
| 310 | - tmpfile.close(); | ||
| 311 | } | 293 | } |
| 294 | + continue; | ||
| 295 | + } | ||
| 312 | 296 | ||
| 313 | - // Check temporary file | ||
| 314 | - std::string message = check_infile(filename); | ||
| 315 | - if (message.length() > 0) { | ||
| 316 | - throw GException::app_error(G_RUN, message); | ||
| 317 | - } | 297 | + // Get temporary file name |
| 298 | + #if G_USE_MKSTEMP | ||
| 299 | + char tpl[] = "ctselectXXXXXX"; | ||
| 300 | + int fileid = mkstemp(tpl); | ||
| 301 | + std::string filename(tpl); | ||
| 302 | + #else | ||
| 303 | + std::string filename = std::tmpnam(NULL); | ||
| 304 | + #endif | ||
| 305 | + | ||
| 306 | + // Save observation in temporary file | ||
| 307 | + obs->save(filename, true); | ||
| 308 | + | ||
| 309 | + // Log saved FITS file | ||
| 310 | + if (logExplicit()) { | ||
| 311 | + GFits tmpfile(filename); | ||
| 312 | + log << std::endl; | ||
| 313 | + log.header1("FITS file content of temporary file"); | ||
| 314 | + log << tmpfile << std::endl; | ||
| 315 | + tmpfile.close(); | ||
| 316 | + } | ||
| 317 | + | ||
| 318 | + // Check temporary file | ||
| 319 | + std::string message = check_infile(filename); | ||
| 320 | + if (message.length() > 0) { | ||
| 321 | + throw GException::app_error(G_RUN, message); | ||
| 322 | + } | ||
| 318 | 323 | ||
| 319 | - // Load observation from temporary file, including event selection | ||
| 320 | - select_events(obs, filename); | 324 | + // Load observation from temporary file, including event selection |
| 325 | + select_events(obs, filename); | ||
| 321 | 326 | ||
| 322 | - // Close temporary file | ||
| 323 | - #if G_USE_MKSTEMP | ||
| 324 | - close(fileid); | ||
| 325 | - #endif | 327 | + // Close temporary file |
| 328 | + #if G_USE_MKSTEMP | ||
| 329 | + close(fileid); | ||
| 330 | + #endif | ||
| 326 | 331 | ||
| 327 | - // Remove temporary file | ||
| 328 | - std::remove(filename.c_str()); | ||
| 329 | - | ||
| 330 | - } // endif: had a CTA observation | 332 | + // Remove temporary file |
| 333 | + std::remove(filename.c_str()); | ||
| 331 | 334 | ||
| 332 | } // endfor: looped over all observations | 335 | } // endfor: looped over all observations |
| 333 | 336 |
src/ctskymap/ctskymap.cpp
| @@ -250,54 +250,43 @@ void ctskymap::run(void) | @@ -250,54 +250,43 @@ void ctskymap::run(void) | ||
| 250 | // Get CTA observation | 250 | // Get CTA observation |
| 251 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | 251 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); |
| 252 | 252 | ||
| 253 | - // Continue only if observation is a CTA observation | ||
| 254 | - if (obs != NULL) { | ||
| 255 | - | ||
| 256 | - // Write header for current observation | 253 | + // Skip observation if it's not CTA |
| 254 | + if (obs == NULL) { | ||
| 257 | if (logTerse()) { | 255 | if (logTerse()) { |
| 258 | - if (obs->name().length() > 1) { | ||
| 259 | - log.header3("Observation "+obs->name()); | ||
| 260 | - } | ||
| 261 | - else { | ||
| 262 | - log.header3("Observation"); | ||
| 263 | - } | 256 | + log << "Warning: Skipping "+m_obs[i]->instrument(); |
| 257 | + log << " observation \""; | ||
| 258 | + log << m_obs[i]->name() << "\"" << std::endl; | ||
| 264 | } | 259 | } |
| 260 | + continue; | ||
| 261 | + } | ||
| 265 | 262 | ||
| 266 | - // Skip observation if we don't have an unbinned observation | ||
| 267 | - if (obs->eventtype() != "EventList") { | 263 | + // Skip observation if we have a binned observation |
| 264 | + if (obs->eventtype() == "CountsCube") { | ||
| 265 | + if (logTerse()) { | ||
| 266 | + log << "Warning: Skipping binned observation \""; | ||
| 267 | + log << obs->name()+"\"" << std::endl; | ||
| 268 | + } | ||
| 269 | + continue; | ||
| 270 | + } | ||
| 268 | 271 | ||
| 269 | - // Log that we skip the this observation | ||
| 270 | - if (logTerse()) { | ||
| 271 | - log << "Warning: Skipping binned observation \""+obs->name()+"\""; | ||
| 272 | - log << std::endl; | ||
| 273 | - } | ||
| 274 | - continue; | 272 | + // Write header for current observation |
| 273 | + if (logTerse()) { | ||
| 274 | + if (obs->name().length() > 1) { | ||
| 275 | + log.header3("Observation "+obs->name()); | ||
| 276 | + } | ||
| 277 | + else { | ||
| 278 | + log.header3("Observation"); | ||
| 275 | } | 279 | } |
| 280 | + } | ||
| 276 | 281 | ||
| 277 | - // Map events into sky map | ||
| 278 | - map_events(obs); | 282 | + // Map events into sky map |
| 283 | + map_events(obs); | ||
| 279 | 284 | ||
| 280 | - // Increment observation counter | ||
| 281 | - num_obs++; | ||
| 282 | - | ||
| 283 | - } // endif: CTA observation found | 285 | + // Increment observation counter |
| 286 | + num_obs++; | ||
| 284 | 287 | ||
| 285 | } // endfor: looped over observations | 288 | } // endfor: looped over observations |
| 286 | 289 | ||
| 287 | - // Write observation(s) into logger | ||
| 288 | -/* | ||
| 289 | - if (logTerse()) { | ||
| 290 | - log << std::endl; | ||
| 291 | - if (m_obs.size() > 1) { | ||
| 292 | - log.header1("Map observations"); | ||
| 293 | - } | ||
| 294 | - else { | ||
| 295 | - log.header1("Map observation"); | ||
| 296 | - } | ||
| 297 | - log << m_obs << std::endl; | ||
| 298 | - } | ||
| 299 | -*/ | ||
| 300 | - | ||
| 301 | // Return | 290 | // Return |
| 302 | return; | 291 | return; |
| 303 | } | 292 | } |