Commit 681e4450b2a040c979fe416f51a90828e367fe1c

Authored by Jürgen Knödlseder
1 parent a4f4e0f1

Write only used Monte Carlo identifiers in header

ChangeLog
1   -2017-04-14
  1 +2017-05-23
2 2  
3 3 * Version 1.3.0 released
4 4 ========================
... ...
1 1 New Features and Important Changes in ctools 1.3.0.dev1
2 2  
3   -14 April 2017
  3 +23 May 2017
4 4  
5 5  
6 6 Introduction
... ...
src/ctobssim/ctobssim.cpp
... ... @@ -1579,6 +1579,9 @@ void ctobssim::simulate_background(GCTAObservation* obs,
1579 1579 * @param[in] wrklog Pointer to logger.
1580 1580 *
1581 1581 * Sets the correspondance between Monte Carlo identifier and model names.
  1582 + * The method collects all Monte Carlo identifiers from the event list and
  1583 + * sets the corresponding source names using the
  1584 + * GCTAEventList::set_mc_id_names method.
1582 1585 ***************************************************************************/
1583 1586 void ctobssim::set_mc_id_names(GCTAObservation* obs,
1584 1587 const GModels& models,
... ... @@ -1600,26 +1603,53 @@ void ctobssim::set_mc_id_names(GCTAObservation* obs,
1600 1603 std::vector<int> ids;
1601 1604 std::vector<std::string> names;
1602 1605  
1603   - // Loop over all models
1604   - for (int i = 0; i < models.size(); ++i) {
  1606 + // Collect all Monte Carlo identifiers
  1607 + for (int i = 0; i < events->size(); ++i) {
1605 1608  
1606   - // Append identifier and names
1607   - ids.push_back(i+1);
1608   - names.push_back(models[i]->name());
  1609 + // Get Monte Carlo identifier for event
  1610 + int id = (*events)[i]->mc_id();
1609 1611  
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;
  1612 + // If this is the first event then push the Monte Carlo
  1613 + // identifier into list ...
  1614 + if (i == 0) {
  1615 + ids.push_back(id);
  1616 + names.push_back(models[id-1]->name());
1615 1617 }
1616 1618  
1617   - } // endfor: looped over all models
  1619 + // ... otherwise push the Monte Carlo identifier only into list
  1620 + // if the ID does not yet exist
  1621 + else {
  1622 + bool id_found = false;
  1623 + for (int k = 0; k < ids.size(); ++k) {
  1624 + if (ids[k] == id) {
  1625 + id_found = true;
  1626 + break;
  1627 + }
  1628 + }
  1629 + if (!id_found) {
  1630 + ids.push_back(id);
  1631 + names.push_back(models[id-1]->name());
  1632 + }
  1633 + }
  1634 +
  1635 + } // endfor: collected all Monte Carlo identifiers
1618 1636  
1619 1637 // Set correspondance for the event list
1620 1638 if ((ids.size() > 0) && (names.size() > 0)) {
  1639 +
  1640 + // Set Monte Carlo identifiers for event list
1621 1641 events->set_mc_id_names(ids, names);
1622   - }
  1642 +
  1643 + // Log Monte Carlo identifiers into log file
  1644 + if (logNormal()) {
  1645 + for (int k = 0; k < ids.size(); ++k) {
  1646 + *wrklog << gammalib::parformat("MC identifier " +
  1647 + gammalib::str(ids[k]));
  1648 + *wrklog << names[k] << std::endl;
  1649 + }
  1650 + }
  1651 +
  1652 + } // endif: there were Monte Carlo identifiers
1623 1653  
1624 1654 } // endif: observation pointer was valid
1625 1655  
... ...