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
NEWS
| 1 | 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 | 6 | Introduction |
| ... | ... | @@ -44,6 +44,10 @@ In this case, no spectral nodes exist and before the spectral flux() |
| 44 | 44 | method called in ctobssim::get_model_flux() was throwing an exception. |
| 45 | 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 | 52 | ctselect - CTA event selection |
| 49 | 53 | ------------------------------ | ... | ... |
src/ctobssim/ctobssim.cpp
| ... | ... | @@ -363,6 +363,9 @@ void ctobssim::run(void) |
| 363 | 363 | // Simulate source events |
| 364 | 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 | 369 | // Dump simulation results |
| 367 | 370 | if (logTerse()) { |
| 368 | 371 | wrklog << gammalib::parformat("MC events"); |
| ... | ... | @@ -1063,7 +1066,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, |
| 1063 | 1066 | } |
| 1064 | 1067 | |
| 1065 | 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 | 1070 | etrue_min, etrue_max, ereco_min, ereco_max, |
| 1068 | 1071 | dir, rad, area, |
| 1069 | 1072 | ran, wrklog, indent, |
| ... | ... | @@ -1119,6 +1122,7 @@ void ctobssim::simulate_interval(GCTAObservation* obs, |
| 1119 | 1122 | * @param[in] rsp Pointer on CTA response. |
| 1120 | 1123 | * @param[in,out] events Pointer on CTA event list. |
| 1121 | 1124 | * @param[in] model Model. |
| 1125 | + * @param[in] mc_id Monte Carlo identifier of model. | |
| 1122 | 1126 | * @param[in] tstart Start time. |
| 1123 | 1127 | * @param[in] tstop Stop time. |
| 1124 | 1128 | * @param[in] etrue_min Minimum true energy. |
| ... | ... | @@ -1140,6 +1144,7 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, |
| 1140 | 1144 | const GCTAResponseIrf* rsp, |
| 1141 | 1145 | GCTAEventList* events, |
| 1142 | 1146 | const GModelSky* model, |
| 1147 | + const int& mc_id, | |
| 1143 | 1148 | const GTime& tstart, |
| 1144 | 1149 | const GTime& tstop, |
| 1145 | 1150 | const GEnergy& etrue_min, |
| ... | ... | @@ -1207,8 +1212,17 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, |
| 1207 | 1212 | event->energy() <= ereco_max && |
| 1208 | 1213 | event->time() >= tstart && |
| 1209 | 1214 | event->time() <= tstop) { |
| 1215 | + | |
| 1216 | + // Set event identifier | |
| 1210 | 1217 | event->event_id(m_event_id); |
| 1218 | + | |
| 1219 | + // Set Monte Carlo identifier | |
| 1220 | + event->mc_id(mc_id); | |
| 1221 | + | |
| 1222 | + // Append event | |
| 1211 | 1223 | events->append(*event); |
| 1224 | + | |
| 1225 | + // Increment counters | |
| 1212 | 1226 | m_event_id++; |
| 1213 | 1227 | nevents++; |
| 1214 | 1228 | } |
| ... | ... | @@ -1217,6 +1231,9 @@ void ctobssim::simulate_time_slice(GCTAObservation* obs, |
| 1217 | 1231 | |
| 1218 | 1232 | } // endfor: looped over events |
| 1219 | 1233 | |
| 1234 | + // Signal that event list contains Monte Carlo identifiers | |
| 1235 | + events->has_mc_id(true); | |
| 1236 | + | |
| 1220 | 1237 | // Return |
| 1221 | 1238 | return; |
| 1222 | 1239 | } |
| ... | ... | @@ -1509,6 +1526,9 @@ void ctobssim::simulate_background(GCTAObservation* obs, |
| 1509 | 1526 | event->event_id(m_event_id); |
| 1510 | 1527 | m_event_id++; |
| 1511 | 1528 | |
| 1529 | + // Set Monte Carlo identifier | |
| 1530 | + event->mc_id(i+1); | |
| 1531 | + | |
| 1512 | 1532 | // Append event |
| 1513 | 1533 | events->append(*event); |
| 1514 | 1534 | |
| ... | ... | @@ -1541,6 +1561,64 @@ void ctobssim::simulate_background(GCTAObservation* obs, |
| 1541 | 1561 | |
| 1542 | 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 | 1622 | } // endif: observation pointer was valid |
| 1545 | 1623 | |
| 1546 | 1624 | // Return | ... | ... |
src/ctobssim/ctobssim.hpp
| ... | ... | @@ -100,6 +100,7 @@ protected: |
| 100 | 100 | const GCTAResponseIrf* rsp, |
| 101 | 101 | GCTAEventList* events, |
| 102 | 102 | const GModelSky* model, |
| 103 | + const int& mc_id, | |
| 103 | 104 | const GTime& tstart, |
| 104 | 105 | const GTime& tstop, |
| 105 | 106 | const GEnergy& etrue_min, |
| ... | ... | @@ -129,6 +130,9 @@ protected: |
| 129 | 130 | const GModels& models, |
| 130 | 131 | GRan& ran, |
| 131 | 132 | GLog* wrklog = NULL); |
| 133 | + void set_mc_id_names(GCTAObservation* obs, | |
| 134 | + const GModels& models, | |
| 135 | + GLog* wrklog = NULL); | |
| 132 | 136 | void save_fits(void); |
| 133 | 137 | void save_xml(void); |
| 134 | 138 | std::string outfile(const int& index); | ... | ... |