diff --git a/ChangeLog b/ChangeLog index d0274ea..3fa23ea 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-11-10 +2016-11-21 * Version 1.2.0 released ======================== + Add startindex parameter to ctobssim (#1878) Fix energy boundary handline in cssens (#1873) Add outcovmat parameter to ctlike (#1863) Add publish parameter and methods to ctobssim, ctselect, cslightcrv and csspec (#1871) diff --git a/NEWS b/NEWS index a758b89..b74f336 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.2.0 -10 November 2016 +21 November 2016 Introduction @@ -66,6 +66,9 @@ of the tool (#1835). A publish() method has been added that publishes the simulated event lists on a VO hub (#1871). +The "startindex" parameter has been added to set the initial index for multiple +event lists (#1878). + ctselect - CTA event selection ------------------------------ diff --git a/doc/source/users/reference_manual/ctobssim.rst b/doc/source/users/reference_manual/ctobssim.rst index de435c6..75b6d3d 100644 --- a/doc/source/users/reference_manual/ctobssim.rst +++ b/doc/source/users/reference_manual/ctobssim.rst @@ -64,7 +64,10 @@ General parameters ``(prefix = sim_events_) [string]`` Prefix for event list in observation definition XML file. - + +``(startindex = 1) [integer]`` + Start index of event list in observation definition XML file. + ``(seed = 1) [integer]`` Integer seed value to be used for Monte Carlo simulations. Keep this parameter at the same value for repeatable simulations, or increment diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index 2504c3b..a85faa2 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -375,17 +375,8 @@ void ctobssim::run(void) // If requested, event lists are saved immediately if (m_save_and_dispose) { - // Set event output file name. If multiple observations are - // handled, build the filename from prefix and observation - // index. Otherwise use the outfile parameter. - std::string outfile; - if (m_use_xml) { - m_prefix = (*this)["prefix"].string(); - outfile = m_prefix + gammalib::str(i) + ".fits"; - } - else { - outfile = (*this)["outevents"].filename(); - } + // Set event output file name + std::string outfile = this->outfile(i); // Store output file name in original observation obs->eventfile(outfile); @@ -537,6 +528,7 @@ void ctobssim::init_members(void) // Initialise user parameters m_outevents.clear(); m_prefix.clear(); + m_startindex = 1; m_seed = 1; m_eslices = 10; m_apply_edisp = false; @@ -567,6 +559,7 @@ void ctobssim::copy_members(const ctobssim& app) // Copy user parameters m_outevents = app.m_outevents; m_prefix = app.m_prefix; + m_startindex = app.m_startindex; m_seed = app.m_seed; m_eslices = app.m_eslices; m_apply_edisp = app.m_apply_edisp; @@ -640,8 +633,9 @@ void ctobssim::get_parameters(void) // Optionally read ahead parameters so that they get correctly // dumped into the log file if (read_ahead()) { - m_outevents = (*this)["outevents"].filename(); - m_prefix = (*this)["prefix"].string(); + m_outevents = (*this)["outevents"].filename(); + m_prefix = (*this)["prefix"].string(); + m_startindex = (*this)["startindex"].integer(); } // Initialise random number generators. We initialise here one random @@ -1512,9 +1506,8 @@ void ctobssim::save_fits(void) ***************************************************************************/ void ctobssim::save_xml(void) { - // Get output filename and prefix - m_outevents = (*this)["outevents"].filename(); - m_prefix = (*this)["prefix"].string(); + // Get output filename, prefix and start index + m_outevents = (*this)["outevents"].filename(); // Issue warning if output filename has no .xml suffix log_string(TERSE, warn_xml_suffix(m_outevents)); @@ -1535,8 +1528,7 @@ void ctobssim::save_xml(void) if (obs->events()->size() != 0) { // Set event output file name - std::string outfile = m_prefix + gammalib::str(i) + - ".fits"; + std::string outfile = this->outfile(i); // Store output file name in observation obs->eventfile(outfile); @@ -1561,3 +1553,50 @@ void ctobssim::save_xml(void) // Return return; } + + +/***********************************************************************//** + * @brief Return output filename + * + * @param[in] index Observation index + * @return Output filename + * + * Return output filename for observation with @p index. + ***************************************************************************/ +std::string ctobssim::outfile(const int& index) +{ + // Initialise output filename + std::string outfile; + + // If multiple observations are handled then build the filename from + // prefix and observation index plus startindex. The format is + // [prefix]NNNNNN.fits, where NNNNNN is a 6-digit integer + if (m_use_xml) { + + // Get prefix and start index + m_prefix = (*this)["prefix"].string(); + m_startindex = (*this)["startindex"].integer(); + + // Build filename + char buffer[256]; + std::sprintf(buffer, "%s%6.6d.fits", m_prefix.c_str(), + index + m_startindex); + + // Set output filename + outfile = std::string(buffer); + + } + + // ... otherwise use the outfile parameter + else { + + // Get output event list file name + m_outevents = (*this)["outevents"].filename(); + + // Set output filename + outfile = std::string(m_outevents); + } + + // Return + return outfile; +} diff --git a/src/ctobssim/ctobssim.hpp b/src/ctobssim/ctobssim.hpp index c9adb1f..2dd0bd1 100644 --- a/src/ctobssim/ctobssim.hpp +++ b/src/ctobssim/ctobssim.hpp @@ -71,71 +71,73 @@ public: protected: // Protected methods - void init_members(void); - void copy_members(const ctobssim& app); - void free_members(void); - void get_parameters(void); - void simulate_source(GCTAObservation* obs, - const GModels& models, - GRan& ran, - GLog* wrklog = NULL); - void simulate_interval(GCTAObservation* obs, - const GCTAResponseIrf* rsp, - GCTAEventList* events, - const GModels& models, - const GTime& tmin, - const GTime& tmax, - const GEnergy& etrue_min, - const GEnergy& etrue_max, - const GEnergy& ereco_min, - const GEnergy& ereco_max, - const GSkyDir& dir, - const double& rad, - const double& area, - GRan& ran, - GLog* wrklog, - int& indent, - std::vector& nphotons, - std::vector& nevents); - void simulate_time_slice(GCTAObservation* obs, - const GCTAResponseIrf* rsp, - GCTAEventList* events, - const GModelSky* model, - const GTime& tstart, - const GTime& tstop, - const GEnergy& etrue_min, - const GEnergy& etrue_max, - const GEnergy& ereco_min, - const GEnergy& ereco_max, - const GSkyDir& dir, - const double& rad, - const double& area, - GRan& ran, - GLog* wrklog, - int& indent, - int& nphotons, - int& nevents); - GEbounds get_ebounds(const GEbounds& ebounds) const; - double get_area(GCTAObservation* obs, - const GEnergy& emin, - const GEnergy& emax) const; - double get_model_flux(const GModelSky* model, - const GEnergy& emin, - const GEnergy& emax, - const GSkyDir& centre, - const double& radius, - const int& indent, - GLog* wrklog); - void simulate_background(GCTAObservation* obs, - const GModels& models, - GRan& ran, - GLog* wrklog = NULL); - void save_fits(void); - void save_xml(void); + void init_members(void); + void copy_members(const ctobssim& app); + void free_members(void); + void get_parameters(void); + void simulate_source(GCTAObservation* obs, + const GModels& models, + GRan& ran, + GLog* wrklog = NULL); + void simulate_interval(GCTAObservation* obs, + const GCTAResponseIrf* rsp, + GCTAEventList* events, + const GModels& models, + const GTime& tmin, + const GTime& tmax, + const GEnergy& etrue_min, + const GEnergy& etrue_max, + const GEnergy& ereco_min, + const GEnergy& ereco_max, + const GSkyDir& dir, + const double& rad, + const double& area, + GRan& ran, + GLog* wrklog, + int& indent, + std::vector& nphotons, + std::vector& nevents); + void simulate_time_slice(GCTAObservation* obs, + const GCTAResponseIrf* rsp, + GCTAEventList* events, + const GModelSky* model, + const GTime& tstart, + const GTime& tstop, + const GEnergy& etrue_min, + const GEnergy& etrue_max, + const GEnergy& ereco_min, + const GEnergy& ereco_max, + const GSkyDir& dir, + const double& rad, + const double& area, + GRan& ran, + GLog* wrklog, + int& indent, + int& nphotons, + int& nevents); + GEbounds get_ebounds(const GEbounds& ebounds) const; + double get_area(GCTAObservation* obs, + const GEnergy& emin, + const GEnergy& emax) const; + double get_model_flux(const GModelSky* model, + const GEnergy& emin, + const GEnergy& emax, + const GSkyDir& centre, + const double& radius, + const int& indent, + GLog* wrklog); + void simulate_background(GCTAObservation* obs, + const GModels& models, + GRan& ran, + GLog* wrklog = NULL); + void save_fits(void); + void save_xml(void); + std::string outfile(const int& index); // User parameters std::string m_outevents; //!< Output events file std::string m_prefix; //!< Prefix for multiple event lists + int m_startindex; //!< Start index for multiple event lists int m_seed; //!< Random number generator seed int m_eslices; //!< Number of energy slices bool m_apply_edisp; //!< Apply energy dispersion? diff --git a/src/ctobssim/ctobssim.par b/src/ctobssim/ctobssim.par index 274e9aa..3d65c0c 100644 --- a/src/ctobssim/ctobssim.par +++ b/src/ctobssim/ctobssim.par @@ -17,13 +17,14 @@ # # General parameters #=================== -inobs, f, h, NONE,,, "Input event list or observation definition XML file" -inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file" -caldb, s, a, prod2,,, "Calibration database" -irf, s, a, South_0.5h,,, "Instrument response function" -edisp, b, h, no,,, "Apply energy dispersion?" -outevents, f, a, events.fits,,, "Output event data file or observation definition XML file" -prefix, s, h, sim_events_,,, "Prefix for event lists in observation definition XML file" +inobs, f, h, NONE,,, "Input event list or observation definition XML file" +inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model XML file" +caldb, s, a, prod2,,, "Calibration database" +irf, s, a, South_0.5h,,, "Instrument response function" +edisp, b, h, no,,, "Apply energy dispersion?" +outevents, f, a, events.fits,,, "Output event data file or observation definition XML file" +prefix, s, h, sim_events_,,, "Prefix for event lists in observation definition XML file" +startindex, i, h, 1,,, "Start index for event lists in observation definition XML file" # # Simulation parameters