Commit cc97b1079697578e26dd99eff5c22de4e88c3f0e
1 parent
9c0e2e0a
ctobssim adds Monte Carlo identifiers to simulated events (#1483)
Showing
4 changed files
with
90 additions
and
3 deletions
ChangeLog
| 1 | -2017-04-13 | 1 | +2017-04-14 |
| 2 | 2 | ||
| 3 | * Version 1.3.0 released | 3 | * Version 1.3.0 released |
| 4 | ======================== | 4 | ======================== |
| 5 | 5 | ||
| 6 | + ctobssim adds Monte Carlo identifiers to simulated events (#1483) | ||
| 6 | Add "phase" parameter to ctselect (#1996) | 7 | Add "phase" parameter to ctselect (#1996) |
| 7 | Add ctphase tool (#1982) | 8 | Add ctphase tool (#1982) |
| 8 | Add ctprob tool (#1991) | 9 | Add ctprob tool (#1991) |
NEWS
| 1 | New Features and Important Changes in ctools 1.3.0.dev1 | 1 | New Features and Important Changes in ctools 1.3.0.dev1 |
| 2 | 2 | ||
| 3 | -13 April 2017 | 3 | +14 April 2017 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | Introduction | 6 | Introduction |
| @@ -44,6 +44,10 @@ In this case, no spectral nodes exist and before the spectral flux() | @@ -44,6 +44,10 @@ In this case, no spectral nodes exist and before the spectral flux() | ||
| 44 | method called in ctobssim::get_model_flux() was throwing an exception. | 44 | method called in ctobssim::get_model_flux() was throwing an exception. |
| 45 | Now, for map cubes outside the RoI the flux is set to zero. | 45 | Now, for map cubes outside the RoI the flux is set to zero. |
| 46 | 46 | ||
| 47 | +The tool now also added Monte Carlo identifiers to the simulated events | ||
| 48 | +so that each event can be traced back to the model from which it originated | ||
| 49 | +(#1483). | ||
| 50 | + | ||
| 47 | 51 | ||
| 48 | ctselect - CTA event selection | 52 | ctselect - CTA event selection |
| 49 | ------------------------------ | 53 | ------------------------------ |
src/ctobssim/ctobssim.cpp
| @@ -363,6 +363,9 @@ void ctobssim::run(void) | @@ -363,6 +363,9 @@ void ctobssim::run(void) | ||
| 363 | // Simulate source events | 363 | // Simulate source events |
| 364 | simulate_background(&obs_clone, models, m_rans[i], &wrklog); | 364 | simulate_background(&obs_clone, models, m_rans[i], &wrklog); |
| 365 | 365 | ||
| 366 | + // Set Monte Carlo identifier and name correspondance | ||
| 367 | + set_mc_id_names(&obs_clone, models); | ||
| 368 | + | ||
| 366 | // Dump simulation results | 369 | // Dump simulation results |
| 367 | if (logTerse()) { | 370 | if (logTerse()) { |
| 368 | wrklog << gammalib::parformat("MC events"); | 371 | wrklog << gammalib::parformat("MC events"); |
| @@ -1063,7 +1066,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, | @@ -1063,7 +1066,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, | ||
| 1063 | } | 1066 | } |
| 1064 | 1067 | ||
| 1065 | // Simulate time slice | 1068 | // Simulate time slice |
| 1066 | - simulate_time_slice(obs, rsp, events, model, tstart, tstop, | 1069 | + simulate_time_slice(obs, rsp, events, model, i+1, tstart, tstop, |
| 1067 | etrue_min, etrue_max, ereco_min, ereco_max, | 1070 | etrue_min, etrue_max, ereco_min, ereco_max, |
| 1068 | dir, rad, area, | 1071 | dir, rad, area, |
| 1069 | ran, wrklog, indent, | 1072 | ran, wrklog, indent, |
| @@ -1119,6 +1122,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, | @@ -1119,6 +1122,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, | ||
| 1119 | * @param[in] rsp Pointer on CTA response. | 1122 | * @param[in] rsp Pointer on CTA response. |
| 1120 | * @param[in,out] events Pointer on CTA event list. | 1123 | * @param[in,out] events Pointer on CTA event list. |
| 1121 | * @param[in] model Model. | 1124 | * @param[in] model Model. |
| 1125 | + * @param[in] mc_id Monte Carlo identifier of model. | ||
| 1122 | * @param[in] tstart Start time. | 1126 | * @param[in] tstart Start time. |
| 1123 | * @param[in] tstop Stop time. | 1127 | * @param[in] tstop Stop time. |
| 1124 | * @param[in] etrue_min Minimum true energy. | 1128 | * @param[in] etrue_min Minimum true energy. |
| @@ -1140,6 +1144,7 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, | @@ -1140,6 +1144,7 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, | ||
| 1140 | const GCTAResponseIrf* rsp, | 1144 | const GCTAResponseIrf* rsp, |
| 1141 | GCTAEventList* events, | 1145 | GCTAEventList* events, |
| 1142 | const GModelSky* model, | 1146 | const GModelSky* model, |
| 1147 | + const int& mc_id, | ||
| 1143 | const GTime& tstart, | 1148 | const GTime& tstart, |
| 1144 | const GTime& tstop, | 1149 | const GTime& tstop, |
| 1145 | const GEnergy& etrue_min, | 1150 | const GEnergy& etrue_min, |
| @@ -1207,8 +1212,17 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, | @@ -1207,8 +1212,17 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, | ||
| 1207 | event->energy() <= ereco_max && | 1212 | event->energy() <= ereco_max && |
| 1208 | event->time() >= tstart && | 1213 | event->time() >= tstart && |
| 1209 | event->time() <= tstop) { | 1214 | event->time() <= tstop) { |
| 1215 | + | ||
| 1216 | + // Set event identifier | ||
| 1210 | event->event_id(m_event_id); | 1217 | event->event_id(m_event_id); |
| 1218 | + | ||
| 1219 | + // Set Monte Carlo identifier | ||
| 1220 | + event->mc_id(mc_id); | ||
| 1221 | + | ||
| 1222 | + // Append event | ||
| 1211 | events->append(*event); | 1223 | events->append(*event); |
| 1224 | + | ||
| 1225 | + // Increment counters | ||
| 1212 | m_event_id++; | 1226 | m_event_id++; |
| 1213 | nevents++; | 1227 | nevents++; |
| 1214 | } | 1228 | } |
| @@ -1217,6 +1231,9 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, | @@ -1217,6 +1231,9 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, | ||
| 1217 | 1231 | ||
| 1218 | } // endfor: looped over events | 1232 | } // endfor: looped over events |
| 1219 | 1233 | ||
| 1234 | + // Signal that event list contains Monte Carlo identifiers | ||
| 1235 | + events->has_mc_id(true); | ||
| 1236 | + | ||
| 1220 | // Return | 1237 | // Return |
| 1221 | return; | 1238 | return; |
| 1222 | } | 1239 | } |
| @@ -1509,6 +1526,9 @@ void ctobssim::simulate_background(GCTAObservation* obs, | @@ -1509,6 +1526,9 @@ void ctobssim::simulate_background(GCTAObservation* obs, | ||
| 1509 | event->event_id(m_event_id); | 1526 | event->event_id(m_event_id); |
| 1510 | m_event_id++; | 1527 | m_event_id++; |
| 1511 | 1528 | ||
| 1529 | + // Set Monte Carlo identifier | ||
| 1530 | + event->mc_id(i+1); | ||
| 1531 | + | ||
| 1512 | // Append event | 1532 | // Append event |
| 1513 | events->append(*event); | 1533 | events->append(*event); |
| 1514 | 1534 | ||
| @@ -1541,6 +1561,64 @@ void ctobssim::simulate_background(GCTAObservation* obs, | @@ -1541,6 +1561,64 @@ void ctobssim::simulate_background(GCTAObservation* obs, | ||
| 1541 | 1561 | ||
| 1542 | } // endfor: looped over all models | 1562 | } // endfor: looped over all models |
| 1543 | 1563 | ||
| 1564 | + // Signal that event list contains Monte Carlo identifiers | ||
| 1565 | + events->has_mc_id(true); | ||
| 1566 | + | ||
| 1567 | + } // endif: observation pointer was valid | ||
| 1568 | + | ||
| 1569 | + // Return | ||
| 1570 | + return; | ||
| 1571 | +} | ||
| 1572 | + | ||
| 1573 | + | ||
| 1574 | +/***********************************************************************//** | ||
| 1575 | + * @brief Set correspondance between Monte Carlo identifier and model names | ||
| 1576 | + * | ||
| 1577 | + * @param[in] obs Pointer on CTA observation. | ||
| 1578 | + * @param[in] models Models. | ||
| 1579 | + * @param[in] wrklog Pointer to logger. | ||
| 1580 | + * | ||
| 1581 | + * Sets the correspondance between Monte Carlo identifier and model names. | ||
| 1582 | + ***************************************************************************/ | ||
| 1583 | +void ctobssim::set_mc_id_names(GCTAObservation* obs, | ||
| 1584 | + const GModels& models, | ||
| 1585 | + GLog* wrklog) | ||
| 1586 | +{ | ||
| 1587 | + // Continue only if observation pointer is valid | ||
| 1588 | + if (obs != NULL) { | ||
| 1589 | + | ||
| 1590 | + // If no logger is specified then use the default logger | ||
| 1591 | + if (wrklog == NULL) { | ||
| 1592 | + wrklog = &log; | ||
| 1593 | + } | ||
| 1594 | + | ||
| 1595 | + // Get pointer on event list (circumvent const correctness) | ||
| 1596 | + GCTAEventList* events = | ||
| 1597 | + static_cast<GCTAEventList*>(const_cast<GEvents*>(obs->events())); | ||
| 1598 | + | ||
| 1599 | + // Initialise lists | ||
| 1600 | + std::vector<int> ids; | ||
| 1601 | + std::vector<std::string> names; | ||
| 1602 | + | ||
| 1603 | + // Loop over all models | ||
| 1604 | + for (int i = 0; i < models.size(); ++i) { | ||
| 1605 | + | ||
| 1606 | + // Append identifier and names | ||
| 1607 | + ids.push_back(i+1); | ||
| 1608 | + names.push_back(models[i]->name()); | ||
| 1609 | + | ||
| 1610 | + // Dump identifier name correspondance | ||
| 1611 | + if (logNormal()) { | ||
| 1612 | + *wrklog << gammalib::parformat("MC identifier " + | ||
| 1613 | + gammalib::str(i+1)); | ||
| 1614 | + *wrklog << models[i]->name() << std::endl; | ||
| 1615 | + } | ||
| 1616 | + | ||
| 1617 | + } // endfor: looped over all models | ||
| 1618 | + | ||
| 1619 | + // Set correspondance for the event list | ||
| 1620 | + events->set_mc_id_names(ids, names); | ||
| 1621 | + | ||
| 1544 | } // endif: observation pointer was valid | 1622 | } // endif: observation pointer was valid |
| 1545 | 1623 | ||
| 1546 | // Return | 1624 | // Return |
src/ctobssim/ctobssim.hpp
| @@ -100,6 +100,7 @@ protected: | @@ -100,6 +100,7 @@ protected: | ||
| 100 | const GCTAResponseIrf* rsp, | 100 | const GCTAResponseIrf* rsp, |
| 101 | GCTAEventList* events, | 101 | GCTAEventList* events, |
| 102 | const GModelSky* model, | 102 | const GModelSky* model, |
| 103 | + const int& mc_id, | ||
| 103 | const GTime& tstart, | 104 | const GTime& tstart, |
| 104 | const GTime& tstop, | 105 | const GTime& tstop, |
| 105 | const GEnergy& etrue_min, | 106 | const GEnergy& etrue_min, |
| @@ -129,6 +130,9 @@ protected: | @@ -129,6 +130,9 @@ protected: | ||
| 129 | const GModels& models, | 130 | const GModels& models, |
| 130 | GRan& ran, | 131 | GRan& ran, |
| 131 | GLog* wrklog = NULL); | 132 | GLog* wrklog = NULL); |
| 133 | + void set_mc_id_names(GCTAObservation* obs, | ||
| 134 | + const GModels& models, | ||
| 135 | + GLog* wrklog = NULL); | ||
| 132 | void save_fits(void); | 136 | void save_fits(void); |
| 133 | void save_xml(void); | 137 | void save_xml(void); |
| 134 | std::string outfile(const int& index); | 138 | std::string outfile(const int& index); |