Commit 7e03bf6054f689b7bc7eb8a70e894536e14c3d77
1 parent
dc062fcd
Extended ctselect to consider user defined energy thresholds
Showing
3 changed files
with
127 additions
and
22 deletions
src/ctselect/ctselect.cpp
| ... | ... | @@ -36,6 +36,9 @@ |
| 36 | 36 | #define G_RUN "ctselect::run()" |
| 37 | 37 | #define G_SELECT_EVENTS "ctselect::select_events(GCTAObservation*, "\ |
| 38 | 38 | "std::string&)" |
| 39 | +#define G_FIND_EBOUNDS "ctselect::find_ebounds(GCTAObservation*, "\ | |
| 40 | + "GEbounds&)" | |
| 41 | +#define G_GET_PARAMETERS "ctselect::get_parameters()" | |
| 39 | 42 | |
| 40 | 43 | /* __ Debug definitions __________________________________________________ */ |
| 41 | 44 | |
| ... | ... | @@ -296,6 +299,7 @@ void ctselect::run(void) |
| 296 | 299 | // Load observation from temporary file, including event selection |
| 297 | 300 | select_events(obs, filename); |
| 298 | 301 | |
| 302 | + | |
| 299 | 303 | // Close temporary file |
| 300 | 304 | #if G_USE_MKSTEMP |
| 301 | 305 | close(fileid); |
| ... | ... | @@ -397,6 +401,7 @@ void ctselect::init_members(void) |
| 397 | 401 | m_emin = 0.0; |
| 398 | 402 | m_emax = 0.0; |
| 399 | 403 | m_expr.clear(); |
| 404 | + m_usethres.clear(); | |
| 400 | 405 | |
| 401 | 406 | // Initialise protected members |
| 402 | 407 | m_obs.clear(); |
| ... | ... | @@ -435,6 +440,7 @@ void ctselect::copy_members(const ctselect& app) |
| 435 | 440 | m_emin = app.m_emin; |
| 436 | 441 | m_emax = app.m_emax; |
| 437 | 442 | m_expr = app.m_expr; |
| 443 | + m_usethres = app.m_usethres; | |
| 438 | 444 | |
| 439 | 445 | // Copy protected members |
| 440 | 446 | m_obs = app.m_obs; |
| ... | ... | @@ -520,6 +526,11 @@ void ctselect::get_parameters(void) |
| 520 | 526 | m_emin = (*this)["emin"].real(); |
| 521 | 527 | m_emax = (*this)["emax"].real(); |
| 522 | 528 | m_expr = (*this)["expr"].string(); |
| 529 | + m_usethres = (*this)["usethres"].string(); | |
| 530 | + if (m_usethres != "NONE" && m_usethres != "DEFAULT" && m_usethres != "USER") { | |
| 531 | + std::string msg = "Parameter \"usethres\" must be one of \"NONE\", \"DEFAULT\" or \"USER\""; | |
| 532 | + throw GException::invalid_value(G_GET_PARAMETERS, msg); | |
| 533 | + } | |
| 523 | 534 | |
| 524 | 535 | // Optionally read ahead parameters so that they get correctly |
| 525 | 536 | // dumped into the log file |
| ... | ... | @@ -563,6 +574,7 @@ void ctselect::get_parameters(void) |
| 563 | 574 | ***************************************************************************/ |
| 564 | 575 | void ctselect::select_events(GCTAObservation* obs, const std::string& filename) |
| 565 | 576 | { |
| 577 | + | |
| 566 | 578 | // Initialise selection string |
| 567 | 579 | std::string selection; |
| 568 | 580 | |
| ... | ... | @@ -646,31 +658,38 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) |
| 646 | 658 | |
| 647 | 659 | // Set the energy boundaries. Make sure that they overlap with any |
| 648 | 660 | // existing energy boundaries |
| 649 | - const GEbounds& ebounds = list->ebounds(); | |
| 650 | - if (ebounds.size() >= 1) { | |
| 661 | + | |
| 662 | + // Find the energy boundaries, taking into account any previous selections | |
| 663 | + // and also user or default energy thresholds | |
| 664 | + GEbounds ebounds = find_ebounds(obs,list->ebounds()); | |
| 665 | + | |
| 666 | + // Check if energy bounds are valid | |
| 667 | + if (ebounds.size() > 0) { | |
| 668 | + | |
| 669 | + // Write ebounds to log | |
| 651 | 670 | if (logTerse()) { |
| 652 | - log << gammalib::parformat("Energy range of data"); | |
| 653 | - log << ebounds.emin(0).TeV() << " - "; | |
| 654 | - log << ebounds.emax(0).TeV() << " TeV" << std::endl; | |
| 655 | - } | |
| 656 | - if (emin < ebounds.emin(0).TeV()) { | |
| 657 | - emin = ebounds.emin(0).TeV(); | |
| 658 | - } | |
| 659 | - if (emax > ebounds.emax(0).TeV()) { | |
| 660 | - emax = ebounds.emax(0).TeV(); | |
| 671 | + log << emin << " - " << emax << " TeV" << std::endl; | |
| 661 | 672 | } |
| 662 | - } | |
| 663 | 673 | |
| 664 | - // Log the selected energy range | |
| 665 | - if (logTerse()) { | |
| 666 | - log << gammalib::parformat("Selected energy range"); | |
| 667 | - if (emin >= emax) { | |
| 668 | - log << "None. There is no overlap between existing "; | |
| 669 | - log << "and requested energy range." << std::endl; | |
| 670 | - } | |
| 671 | - else { | |
| 672 | - log << emin << " - " << emax << " TeV" << std::endl; | |
| 674 | + // Set emin and emax values | |
| 675 | + emin = ebounds.emin(0).TeV(); | |
| 676 | + emax = ebounds.emax(0).TeV(); | |
| 677 | + | |
| 678 | + } //endif: ebounds were valid | |
| 679 | + | |
| 680 | + else { | |
| 681 | + | |
| 682 | + // Write log that energy range is not existent | |
| 683 | + if (logTerse()) { | |
| 684 | + log << gammalib::parformat("Selected energy range"); | |
| 685 | + if (emin >= emax) { | |
| 686 | + log << "None. There is no overlap between existing "; | |
| 687 | + log << "and requested energy range." << std::endl; | |
| 688 | + } | |
| 673 | 689 | } |
| 690 | + | |
| 691 | + // Signal to remove all events | |
| 692 | + remove_all = true; | |
| 674 | 693 | } |
| 675 | 694 | |
| 676 | 695 | // Format energy selection |
| ... | ... | @@ -679,7 +698,7 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) |
| 679 | 698 | sprintf(cmin, "%.8f", emin); |
| 680 | 699 | sprintf(cmax, "%.8f", emax); |
| 681 | 700 | selection += "ENERGY >= "+std::string(cmin)+" && ENERGY <= "+std::string(cmax); |
| 682 | - | |
| 701 | + | |
| 683 | 702 | } // endif: made energy selection |
| 684 | 703 | |
| 685 | 704 | // Make ROI selection |
| ... | ... | @@ -1061,3 +1080,86 @@ void ctselect::save_event_list(const GCTAObservation* obs, |
| 1061 | 1080 | return; |
| 1062 | 1081 | } |
| 1063 | 1082 | |
| 1083 | +GEbounds ctselect::find_ebounds(GCTAObservation* obs, const GEbounds& list_ebounds) const | |
| 1084 | +{ | |
| 1085 | + // Initialise ebounds | |
| 1086 | + GEbounds ebounds; | |
| 1087 | + | |
| 1088 | + // Set emin and emax values from user parameters | |
| 1089 | + double emin = m_emin; | |
| 1090 | + double emax = m_emax; | |
| 1091 | + | |
| 1092 | + // Check if list already has ebounds | |
| 1093 | + if (list_ebounds.size() >= 1) { | |
| 1094 | + | |
| 1095 | + // Make sure the user parameters don't condradict previous selections | |
| 1096 | + if (emin < ebounds.emin(0).TeV()) { | |
| 1097 | + emin = ebounds.emin(0).TeV(); | |
| 1098 | + } | |
| 1099 | + if (emax > ebounds.emax(0).TeV()) { | |
| 1100 | + emax = ebounds.emax(0).TeV(); | |
| 1101 | + } | |
| 1102 | + } //endif: ebounds were valid | |
| 1103 | + | |
| 1104 | + // Check if threshold should be applied on default | |
| 1105 | + if (m_usethres == "DEFAULT") { | |
| 1106 | + | |
| 1107 | + // Get CTA IRF respsonse pointer and throw exception | |
| 1108 | + // if we don't find IRF | |
| 1109 | + GCTAResponseIrf* rsp = static_cast<GCTAResponseIrf*>(const_cast<GCTAResponse*>(obs->response())); | |
| 1110 | + if (rsp == NULL) { | |
| 1111 | + std::string msg = "No IRF response attached to given observation"; | |
| 1112 | + throw GException::invalid_value(G_FIND_EBOUNDS, msg); | |
| 1113 | + } | |
| 1114 | + | |
| 1115 | + // retrieve energy range from response information | |
| 1116 | + double lo_save_thres = rsp->lo_save_thres(); | |
| 1117 | + double hi_save_thres = rsp->hi_save_thres(); | |
| 1118 | + | |
| 1119 | + // Check threshold information for validity | |
| 1120 | + // throw exception if not valid | |
| 1121 | + if (lo_save_thres >= hi_save_thres){ | |
| 1122 | + std::string msg = "Energy range provided by response from \""+obs->name()+"\" not valid"; | |
| 1123 | + throw GException::invalid_value(G_FIND_EBOUNDS, msg); | |
| 1124 | + } | |
| 1125 | + | |
| 1126 | + // Overwrite energy threshold definitions if necessary | |
| 1127 | + if (emin < lo_save_thres) { | |
| 1128 | + emin = lo_save_thres; | |
| 1129 | + } | |
| 1130 | + if (emax > hi_save_thres) { | |
| 1131 | + emax = hi_save_thres; | |
| 1132 | + } | |
| 1133 | + | |
| 1134 | + } //endif: m_usethres was "DEFAULT" | |
| 1135 | + | |
| 1136 | + else if (m_usethres == "USER") { | |
| 1137 | + | |
| 1138 | + // Retrieve parameters from observation | |
| 1139 | + // these should have been set via the xml file | |
| 1140 | + double lo_user_thres = obs->lo_user_thres(); | |
| 1141 | + double hi_user_thres = obs->hi_user_thres(); | |
| 1142 | + | |
| 1143 | + // Check provided energy range for validity | |
| 1144 | + if (lo_user_thres >= hi_user_thres) { | |
| 1145 | + std::string msg = "User defined energy range which is provided in observation \""+obs->name()+"\" not valid"; | |
| 1146 | + throw GException::invalid_value(G_FIND_EBOUNDS, msg); | |
| 1147 | + } | |
| 1148 | + | |
| 1149 | + // Overwrite energy range definition if necessary | |
| 1150 | + if (emin < lo_user_thres) { | |
| 1151 | + emin = lo_user_thres; | |
| 1152 | + } | |
| 1153 | + if (emax > hi_user_thres) { | |
| 1154 | + emax = hi_user_thres; | |
| 1155 | + } | |
| 1156 | + | |
| 1157 | + } // endif: usethres was "USER | |
| 1158 | + | |
| 1159 | + // set ebounds for selection | |
| 1160 | + ebounds.append(GEnergy(emin, "TeV"), GEnergy(emax, "TeV")); | |
| 1161 | + | |
| 1162 | + // Return ebounds | |
| 1163 | + return ebounds; | |
| 1164 | + | |
| 1165 | +} | ... | ... |
src/ctselect/ctselect.hpp
| ... | ... | @@ -78,6 +78,7 @@ protected: |
| 78 | 78 | void save_event_list(const GCTAObservation* obs, |
| 79 | 79 | const std::string& infile, |
| 80 | 80 | const std::string& outfile) const; |
| 81 | + GEbounds find_ebounds(GCTAObservation* obs, const GEbounds& list_ebounds) const; | |
| 81 | 82 | |
| 82 | 83 | // User parameters |
| 83 | 84 | std::string m_infile; //!< Input event list or XML file |
| ... | ... | @@ -92,6 +93,7 @@ protected: |
| 92 | 93 | double m_emin; //!< Lower energy |
| 93 | 94 | double m_emax; //!< Upper energy |
| 94 | 95 | std::string m_expr; //!< Selection expression |
| 96 | + std::string m_usethres;//!<Choice of energy threshold usage | |
| 95 | 97 | |
| 96 | 98 | // Protected members |
| 97 | 99 | GObservations m_obs; //!< Observations container | ... | ... |
src/ctselect/ctselect.par
| ... | ... | @@ -32,6 +32,7 @@ tmax, r, a, 0.0, 0, , "End time (CTA MET in seconds)" |
| 32 | 32 | emin, r, a, 0.1, 0, , "Lower energy limit (TeV)" |
| 33 | 33 | emax, r, a, 100.0, 0, , "Upper energy limit (TeV)" |
| 34 | 34 | expr, s, h, "", , , "Additional selection expression" |
| 35 | +usethres,s,h,"NONE",NONE|DEFAULT|USER, ,"Threshold applying algorithm" | |
| 35 | 36 | # |
| 36 | 37 | # Standard parameters |
| 37 | 38 | #==================== | ... | ... |