Commit 2cbd1b202afd94d836c78cfc3564370c201e5356
1 parent
e7dee704
Add startindex parameter to ctobssim (#1878)
Showing
6 changed files
with
138 additions
and
89 deletions
ChangeLog
| 1 | -2016-11-10 | |
| 1 | +2016-11-21 | |
| 2 | 2 | |
| 3 | 3 | * Version 1.2.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add startindex parameter to ctobssim (#1878) | |
| 6 | 7 | Fix energy boundary handline in cssens (#1873) |
| 7 | 8 | Add outcovmat parameter to ctlike (#1863) |
| 8 | 9 | Add publish parameter and methods to ctobssim, ctselect, cslightcrv and csspec (#1871) | ... | ... |
NEWS
| 1 | 1 | New Features and Important Changes in ctools 1.2.0 |
| 2 | 2 | |
| 3 | -10 November 2016 | |
| 3 | +21 November 2016 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | Introduction |
| ... | ... | @@ -66,6 +66,9 @@ of the tool (#1835). |
| 66 | 66 | A publish() method has been added that publishes the simulated event lists on |
| 67 | 67 | a VO hub (#1871). |
| 68 | 68 | |
| 69 | +The "startindex" parameter has been added to set the initial index for multiple | |
| 70 | +event lists (#1878). | |
| 71 | + | |
| 69 | 72 | |
| 70 | 73 | ctselect - CTA event selection |
| 71 | 74 | ------------------------------ | ... | ... |
doc/source/users/reference_manual/ctobssim.rst
| ... | ... | @@ -64,7 +64,10 @@ General parameters |
| 64 | 64 | |
| 65 | 65 | ``(prefix = sim_events_) [string]`` |
| 66 | 66 | Prefix for event list in observation definition XML file. |
| 67 | - | |
| 67 | + | |
| 68 | +``(startindex = 1) [integer]`` | |
| 69 | + Start index of event list in observation definition XML file. | |
| 70 | + | |
| 68 | 71 | ``(seed = 1) [integer]`` |
| 69 | 72 | Integer seed value to be used for Monte Carlo simulations. Keep this |
| 70 | 73 | parameter at the same value for repeatable simulations, or increment | ... | ... |
src/ctobssim/ctobssim.cpp
| ... | ... | @@ -375,17 +375,8 @@ void ctobssim::run(void) |
| 375 | 375 | // If requested, event lists are saved immediately |
| 376 | 376 | if (m_save_and_dispose) { |
| 377 | 377 | |
| 378 | - // Set event output file name. If multiple observations are | |
| 379 | - // handled, build the filename from prefix and observation | |
| 380 | - // index. Otherwise use the outfile parameter. | |
| 381 | - std::string outfile; | |
| 382 | - if (m_use_xml) { | |
| 383 | - m_prefix = (*this)["prefix"].string(); | |
| 384 | - outfile = m_prefix + gammalib::str(i) + ".fits"; | |
| 385 | - } | |
| 386 | - else { | |
| 387 | - outfile = (*this)["outevents"].filename(); | |
| 388 | - } | |
| 378 | + // Set event output file name | |
| 379 | + std::string outfile = this->outfile(i); | |
| 389 | 380 | |
| 390 | 381 | // Store output file name in original observation |
| 391 | 382 | obs->eventfile(outfile); |
| ... | ... | @@ -537,6 +528,7 @@ void ctobssim::init_members(void) |
| 537 | 528 | // Initialise user parameters |
| 538 | 529 | m_outevents.clear(); |
| 539 | 530 | m_prefix.clear(); |
| 531 | + m_startindex = 1; | |
| 540 | 532 | m_seed = 1; |
| 541 | 533 | m_eslices = 10; |
| 542 | 534 | m_apply_edisp = false; |
| ... | ... | @@ -567,6 +559,7 @@ void ctobssim::copy_members(const ctobssim& app) |
| 567 | 559 | // Copy user parameters |
| 568 | 560 | m_outevents = app.m_outevents; |
| 569 | 561 | m_prefix = app.m_prefix; |
| 562 | + m_startindex = app.m_startindex; | |
| 570 | 563 | m_seed = app.m_seed; |
| 571 | 564 | m_eslices = app.m_eslices; |
| 572 | 565 | m_apply_edisp = app.m_apply_edisp; |
| ... | ... | @@ -640,8 +633,9 @@ void ctobssim::get_parameters(void) |
| 640 | 633 | // Optionally read ahead parameters so that they get correctly |
| 641 | 634 | // dumped into the log file |
| 642 | 635 | if (read_ahead()) { |
| 643 | - m_outevents = (*this)["outevents"].filename(); | |
| 644 | - m_prefix = (*this)["prefix"].string(); | |
| 636 | + m_outevents = (*this)["outevents"].filename(); | |
| 637 | + m_prefix = (*this)["prefix"].string(); | |
| 638 | + m_startindex = (*this)["startindex"].integer(); | |
| 645 | 639 | } |
| 646 | 640 | |
| 647 | 641 | // Initialise random number generators. We initialise here one random |
| ... | ... | @@ -1512,9 +1506,8 @@ void ctobssim::save_fits(void) |
| 1512 | 1506 | ***************************************************************************/ |
| 1513 | 1507 | void ctobssim::save_xml(void) |
| 1514 | 1508 | { |
| 1515 | - // Get output filename and prefix | |
| 1516 | - m_outevents = (*this)["outevents"].filename(); | |
| 1517 | - m_prefix = (*this)["prefix"].string(); | |
| 1509 | + // Get output filename, prefix and start index | |
| 1510 | + m_outevents = (*this)["outevents"].filename(); | |
| 1518 | 1511 | |
| 1519 | 1512 | // Issue warning if output filename has no .xml suffix |
| 1520 | 1513 | log_string(TERSE, warn_xml_suffix(m_outevents)); |
| ... | ... | @@ -1535,8 +1528,7 @@ void ctobssim::save_xml(void) |
| 1535 | 1528 | if (obs->events()->size() != 0) { |
| 1536 | 1529 | |
| 1537 | 1530 | // Set event output file name |
| 1538 | - std::string outfile = m_prefix + gammalib::str(i) + | |
| 1539 | - ".fits"; | |
| 1531 | + std::string outfile = this->outfile(i); | |
| 1540 | 1532 | |
| 1541 | 1533 | // Store output file name in observation |
| 1542 | 1534 | obs->eventfile(outfile); |
| ... | ... | @@ -1561,3 +1553,50 @@ void ctobssim::save_xml(void) |
| 1561 | 1553 | // Return |
| 1562 | 1554 | return; |
| 1563 | 1555 | } |
| 1556 | + | |
| 1557 | + | |
| 1558 | +/***********************************************************************//** | |
| 1559 | + * @brief Return output filename | |
| 1560 | + * | |
| 1561 | + * @param[in] index Observation index | |
| 1562 | + * @return Output filename | |
| 1563 | + * | |
| 1564 | + * Return output filename for observation with @p index. | |
| 1565 | + ***************************************************************************/ | |
| 1566 | +std::string ctobssim::outfile(const int& index) | |
| 1567 | +{ | |
| 1568 | + // Initialise output filename | |
| 1569 | + std::string outfile; | |
| 1570 | + | |
| 1571 | + // If multiple observations are handled then build the filename from | |
| 1572 | + // prefix and observation index plus startindex. The format is | |
| 1573 | + // [prefix]NNNNNN.fits, where NNNNNN is a 6-digit integer | |
| 1574 | + if (m_use_xml) { | |
| 1575 | + | |
| 1576 | + // Get prefix and start index | |
| 1577 | + m_prefix = (*this)["prefix"].string(); | |
| 1578 | + m_startindex = (*this)["startindex"].integer(); | |
| 1579 | + | |
| 1580 | + // Build filename | |
| 1581 | + char buffer[256]; | |
| 1582 | + std::sprintf(buffer, "%s%6.6d.fits", m_prefix.c_str(), | |
| 1583 | + index + m_startindex); | |
| 1584 | + | |
| 1585 | + // Set output filename | |
| 1586 | + outfile = std::string(buffer); | |
| 1587 | + | |
| 1588 | + } | |
| 1589 | + | |
| 1590 | + // ... otherwise use the outfile parameter | |
| 1591 | + else { | |
| 1592 | + | |
| 1593 | + // Get output event list file name | |
| 1594 | + m_outevents = (*this)["outevents"].filename(); | |
| 1595 | + | |
| 1596 | + // Set output filename | |
| 1597 | + outfile = std::string(m_outevents); | |
| 1598 | + } | |
| 1599 | + | |
| 1600 | + // Return | |
| 1601 | + return outfile; | |
| 1602 | +} | ... | ... |
src/ctobssim/ctobssim.hpp
| ... | ... | @@ -71,71 +71,73 @@ public: |
| 71 | 71 | |
| 72 | 72 | protected: |
| 73 | 73 | // Protected methods |
| 74 | - void init_members(void); | |
| 75 | - void copy_members(const ctobssim& app); | |
| 76 | - void free_members(void); | |
| 77 | - void get_parameters(void); | |
| 78 | - void simulate_source(GCTAObservation* obs, | |
| 79 | - const GModels& models, | |
| 80 | - GRan& ran, | |
| 81 | - GLog* wrklog = NULL); | |
| 82 | - void simulate_interval(GCTAObservation* obs, | |
| 83 | - const GCTAResponseIrf* rsp, | |
| 84 | - GCTAEventList* events, | |
| 85 | - const GModels& models, | |
| 86 | - const GTime& tmin, | |
| 87 | - const GTime& tmax, | |
| 88 | - const GEnergy& etrue_min, | |
| 89 | - const GEnergy& etrue_max, | |
| 90 | - const GEnergy& ereco_min, | |
| 91 | - const GEnergy& ereco_max, | |
| 92 | - const GSkyDir& dir, | |
| 93 | - const double& rad, | |
| 94 | - const double& area, | |
| 95 | - GRan& ran, | |
| 96 | - GLog* wrklog, | |
| 97 | - int& indent, | |
| 98 | - std::vector<int>& nphotons, | |
| 99 | - std::vector<int>& nevents); | |
| 100 | - void simulate_time_slice(GCTAObservation* obs, | |
| 101 | - const GCTAResponseIrf* rsp, | |
| 102 | - GCTAEventList* events, | |
| 103 | - const GModelSky* model, | |
| 104 | - const GTime& tstart, | |
| 105 | - const GTime& tstop, | |
| 106 | - const GEnergy& etrue_min, | |
| 107 | - const GEnergy& etrue_max, | |
| 108 | - const GEnergy& ereco_min, | |
| 109 | - const GEnergy& ereco_max, | |
| 110 | - const GSkyDir& dir, | |
| 111 | - const double& rad, | |
| 112 | - const double& area, | |
| 113 | - GRan& ran, | |
| 114 | - GLog* wrklog, | |
| 115 | - int& indent, | |
| 116 | - int& nphotons, | |
| 117 | - int& nevents); | |
| 118 | - GEbounds get_ebounds(const GEbounds& ebounds) const; | |
| 119 | - double get_area(GCTAObservation* obs, | |
| 120 | - const GEnergy& emin, | |
| 121 | - const GEnergy& emax) const; | |
| 122 | - double get_model_flux(const GModelSky* model, | |
| 123 | - const GEnergy& emin, | |
| 124 | - const GEnergy& emax, | |
| 125 | - const GSkyDir& centre, | |
| 126 | - const double& radius, | |
| 127 | - const int& indent, | |
| 128 | - GLog* wrklog); | |
| 129 | - void simulate_background(GCTAObservation* obs, | |
| 130 | - const GModels& models, | |
| 131 | - GRan& ran, | |
| 132 | - GLog* wrklog = NULL); | |
| 133 | - void save_fits(void); | |
| 134 | - void save_xml(void); | |
| 74 | + void init_members(void); | |
| 75 | + void copy_members(const ctobssim& app); | |
| 76 | + void free_members(void); | |
| 77 | + void get_parameters(void); | |
| 78 | + void simulate_source(GCTAObservation* obs, | |
| 79 | + const GModels& models, | |
| 80 | + GRan& ran, | |
| 81 | + GLog* wrklog = NULL); | |
| 82 | + void simulate_interval(GCTAObservation* obs, | |
| 83 | + const GCTAResponseIrf* rsp, | |
| 84 | + GCTAEventList* events, | |
| 85 | + const GModels& models, | |
| 86 | + const GTime& tmin, | |
| 87 | + const GTime& tmax, | |
| 88 | + const GEnergy& etrue_min, | |
| 89 | + const GEnergy& etrue_max, | |
| 90 | + const GEnergy& ereco_min, | |
| 91 | + const GEnergy& ereco_max, | |
| 92 | + const GSkyDir& dir, | |
| 93 | + const double& rad, | |
| 94 | + const double& area, | |
| 95 | + GRan& ran, | |
| 96 | + GLog* wrklog, | |
| 97 | + int& indent, | |
| 98 | + std::vector<int>& nphotons, | |
| 99 | + std::vector<int>& nevents); | |
| 100 | + void simulate_time_slice(GCTAObservation* obs, | |
| 101 | + const GCTAResponseIrf* rsp, | |
| 102 | + GCTAEventList* events, | |
| 103 | + const GModelSky* model, | |
| 104 | + const GTime& tstart, | |
| 105 | + const GTime& tstop, | |
| 106 | + const GEnergy& etrue_min, | |
| 107 | + const GEnergy& etrue_max, | |
| 108 | + const GEnergy& ereco_min, | |
| 109 | + const GEnergy& ereco_max, | |
| 110 | + const GSkyDir& dir, | |
| 111 | + const double& rad, | |
| 112 | + const double& area, | |
| 113 | + GRan& ran, | |
| 114 | + GLog* wrklog, | |
| 115 | + int& indent, | |
| 116 | + int& nphotons, | |
| 117 | + int& nevents); | |
| 118 | + GEbounds get_ebounds(const GEbounds& ebounds) const; | |
| 119 | + double get_area(GCTAObservation* obs, | |
| 120 | + const GEnergy& emin, | |
| 121 | + const GEnergy& emax) const; | |
| 122 | + double get_model_flux(const GModelSky* model, | |
| 123 | + const GEnergy& emin, | |
| 124 | + const GEnergy& emax, | |
| 125 | + const GSkyDir& centre, | |
| 126 | + const double& radius, | |
| 127 | + const int& indent, | |
| 128 | + GLog* wrklog); | |
| 129 | + void simulate_background(GCTAObservation* obs, | |
| 130 | + const GModels& models, | |
| 131 | + GRan& ran, | |
| 132 | + GLog* wrklog = NULL); | |
| 133 | + void save_fits(void); | |
| 134 | + void save_xml(void); | |
| 135 | + std::string outfile(const int& index); | |
| 135 | 136 | |
| 136 | 137 | // User parameters |
| 137 | 138 | std::string m_outevents; //!< Output events file |
| 138 | 139 | std::string m_prefix; //!< Prefix for multiple event lists |
| 140 | + int m_startindex; //!< Start index for multiple event lists | |
| 139 | 141 | int m_seed; //!< Random number generator seed |
| 140 | 142 | int m_eslices; //!< Number of energy slices |
| 141 | 143 | bool m_apply_edisp; //!< Apply energy dispersion? | ... | ... |
src/ctobssim/ctobssim.par
| ... | ... | @@ -17,13 +17,14 @@ |
| 17 | 17 | # |
| 18 | 18 | # General parameters |
| 19 | 19 | #=================== |
| 20 | -inobs, f, h, NONE,,, "Input event list or observation definition XML file" | |
| 21 | -inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file" | |
| 22 | -caldb, s, a, prod2,,, "Calibration database" | |
| 23 | -irf, s, a, South_0.5h,,, "Instrument response function" | |
| 24 | -edisp, b, h, no,,, "Apply energy dispersion?" | |
| 25 | -outevents, f, a, events.fits,,, "Output event data file or observation definition XML file" | |
| 26 | -prefix, s, h, sim_events_,,, "Prefix for event lists in observation definition XML file" | |
| 20 | +inobs, f, h, NONE,,, "Input event list or observation definition XML file" | |
| 21 | +inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file" | |
| 22 | +caldb, s, a, prod2,,, "Calibration database" | |
| 23 | +irf, s, a, South_0.5h,,, "Instrument response function" | |
| 24 | +edisp, b, h, no,,, "Apply energy dispersion?" | |
| 25 | +outevents, f, a, events.fits,,, "Output event data file or observation definition XML file" | |
| 26 | +prefix, s, h, sim_events_,,, "Prefix for event lists in observation definition XML file" | |
| 27 | +startindex, i, h, 1,,, "Start index for event lists in observation definition XML file" | |
| 27 | 28 | |
| 28 | 29 | # |
| 29 | 30 | # Simulation parameters | ... | ... |