Commit 92a52a335e5167c50f905a4da92994b07349e8e1
1 parent
a5248dac
Append response if no information is specified in the XML file
Showing
1 changed file
with
48 additions
and
3 deletions
src/ctlike/ctlike.cpp
| ... | ... | @@ -336,15 +336,18 @@ void ctlike::get_parameters(void) |
| 336 | 336 | // Get event file name |
| 337 | 337 | std::string filename = (*this)["infile"].filename(); |
| 338 | 338 | |
| 339 | - // Try first to open as unbinned FITS file | |
| 339 | + // Try first to open as FITS file | |
| 340 | 340 | try { |
| 341 | 341 | |
| 342 | 342 | // Determine whether FITS file has EVENTS extension |
| 343 | + /* | |
| 343 | 344 | GFits fits(filename); |
| 344 | 345 | bool is_unbinned = fits.contains("EVENTS"); |
| 345 | 346 | fits.close(); |
| 347 | + */ | |
| 346 | 348 | |
| 347 | 349 | // If FITS file has an events header then load as unbinned |
| 350 | + /* | |
| 348 | 351 | if (is_unbinned) { |
| 349 | 352 | obs.load_unbinned(filename); |
| 350 | 353 | } |
| ... | ... | @@ -353,8 +356,12 @@ void ctlike::get_parameters(void) |
| 353 | 356 | else { |
| 354 | 357 | obs.load_binned(filename); |
| 355 | 358 | } |
| 359 | + */ | |
| 356 | 360 | |
| 357 | - // Get task parameters for event file loading | |
| 361 | + // Load data | |
| 362 | + obs.load(filename); | |
| 363 | + | |
| 364 | + // Get other task parameters | |
| 358 | 365 | m_stat = gammalib::toupper((*this)["stat"].string()); |
| 359 | 366 | m_caldb = (*this)["caldb"].string(); |
| 360 | 367 | m_irf = (*this)["irf"].string(); |
| ... | ... | @@ -388,7 +395,45 @@ void ctlike::get_parameters(void) |
| 388 | 395 | // Load observations from XML file |
| 389 | 396 | m_obs.load(filename); |
| 390 | 397 | |
| 391 | - } | |
| 398 | + // Check if all observations have response information. If | |
| 399 | + // not, get the calibration database parameters and set | |
| 400 | + // the response properly | |
| 401 | + bool asked_for_response = false; | |
| 402 | + for (int i = 0; i < m_obs.size(); ++i) { | |
| 403 | + | |
| 404 | + // Get CTA observation | |
| 405 | + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | |
| 406 | + | |
| 407 | + // Continue only if observation is a CTA observation | |
| 408 | + if (obs != NULL) { | |
| 409 | + | |
| 410 | + // If there is no effective area information then | |
| 411 | + // set response from task parameters | |
| 412 | + if (obs->response().aeff() == NULL) { | |
| 413 | + | |
| 414 | + // Get calibration parameters | |
| 415 | + if (!asked_for_response) { | |
| 416 | + m_caldb = (*this)["caldb"].string(); | |
| 417 | + m_irf = (*this)["irf"].string(); | |
| 418 | + asked_for_response = true; | |
| 419 | + } | |
| 420 | + | |
| 421 | + // Set response | |
| 422 | + GCaldb caldb; | |
| 423 | + if (gammalib::dir_exists(m_caldb)) { | |
| 424 | + caldb.rootdir(m_caldb); | |
| 425 | + } | |
| 426 | + else { | |
| 427 | + caldb.open("cta", m_caldb); | |
| 428 | + } | |
| 429 | + obs->response(m_irf, caldb); | |
| 430 | + | |
| 431 | + } // endif: there was no response | |
| 432 | + } // endif: observation was a CTA observation | |
| 433 | + | |
| 434 | + } // endfor: looped over observations | |
| 435 | + | |
| 436 | + } // endcatch: file was an XML file | |
| 392 | 437 | |
| 393 | 438 | } // endif: there was no observation in the container |
| 394 | 439 | ... | ... |