Commit 3c202bd5a5c35fa9a66b1db61d90151d39a51fa3
1 parent
80804d0f
Add reference documentation for ctphase
Showing
10 changed files
with
176 additions
and
344 deletions
doc/source/users/reference_manual/ctphase.rst
0 → 100644
| 1 | +.. _ctphase: | |
| 2 | + | |
| 3 | +ctphase | |
| 4 | +======= | |
| 5 | + | |
| 6 | +Computes the phase of each event using a temporal phase curve model. | |
| 7 | + | |
| 8 | + | |
| 9 | +Synopsis | |
| 10 | +-------- | |
| 11 | + | |
| 12 | +This tool computes for each event the phase value based on a temporal phase | |
| 13 | +curve model. The phase computation is required to derive for example the phase | |
| 14 | +curve of a pulsar or a gamma-ray binary. | |
| 15 | + | |
| 16 | +The tool takes on input an event list or an observation definiton XML file and | |
| 17 | +appends on output to each event file a ``PHASE`` column containing the phase | |
| 18 | +value. | |
| 19 | + | |
| 20 | + | |
| 21 | +General parameters | |
| 22 | +------------------ | |
| 23 | + | |
| 24 | +``inobs [file]`` | |
| 25 | + Input event list or observation definition XML file. | |
| 26 | + | |
| 27 | +``outobs [file]`` | |
| 28 | + Output event list or observation definition XML file. | |
| 29 | + | |
| 30 | +``(prefix = "phased_") [string]`` | |
| 31 | + Prefix for output event lists in observation definition XML file. | |
| 32 | + | |
| 33 | +``inmodel [string]`` | |
| 34 | + Input model definition XML file. If ``NONE`` is specified the phase | |
| 35 | + computation will be based on the ``mjd``, ``phase``, ``f0``, ``f1``, and ``f2`` | |
| 36 | + parameters. | |
| 37 | + | |
| 38 | +``srcname [string]`` | |
| 39 | + Name of the source in the model definition XML file which should be used | |
| 40 | + to compute the event phases. | |
| 41 | + | |
| 42 | +``mjd [real]`` | |
| 43 | + Reference time in Modified Julian Days for phase computation (in days). | |
| 44 | + | |
| 45 | +``phase [real]`` | |
| 46 | + Phase value at reference time. | |
| 47 | + | |
| 48 | +``f0 [real]`` | |
| 49 | + Frequency at reference time (in Hz). | |
| 50 | + | |
| 51 | +``f1 [real]`` | |
| 52 | + First frequency derivative at reference time (in s^-2). | |
| 53 | + | |
| 54 | +``f2 [real]`` | |
| 55 | + Second frequency derivative at reference time (in s^-3). | |
| 56 | + | |
| 57 | + | |
| 58 | +Standard parameters | |
| 59 | +------------------- | |
| 60 | + | |
| 61 | +``(publish = no) [boolean]`` | |
| 62 | + Specifies whether the event list(s) should be published on VO Hub. | |
| 63 | + | |
| 64 | +``(chatter = 2) [integer]`` | |
| 65 | + Verbosity of the executable: | |
| 66 | + chatter = 0: no information will be logged | |
| 67 | + | |
| 68 | + chatter = 1: only errors will be logged | |
| 69 | + | |
| 70 | + chatter = 2: errors and actions will be logged | |
| 71 | + | |
| 72 | + chatter = 3: report about the task execution | |
| 73 | + | |
| 74 | + chatter = 4: detailed report about the task execution | |
| 75 | + | |
| 76 | +``(clobber = yes) [boolean]`` | |
| 77 | + Specifies whether existing output files should be overwritten. | |
| 78 | + | |
| 79 | +``(debug = no) [boolean]`` | |
| 80 | + Enables debug mode. In debug mode the executable will dump any log file output to the console. | |
| 81 | + | |
| 82 | +``(mode = ql) [string]`` | |
| 83 | + Mode of automatic parameters (default is "ql", i.e. "query and learn"). | |
| 84 | + | |
| 85 | +``(logfile = ctphase.log) [string]`` | |
| 86 | + Name of log file. | |
| 87 | + | |
| 88 | + | |
| 89 | +Related tools or scripts | |
| 90 | +------------------------ | |
| 91 | + | |
| 92 | +:doc:`ctprob` | |
| 93 | +:doc:`csphasecrv` | ... | ... |
doc/source/users/reference_manual/ctprob.rst
| 1 | 1 | .. _ctprob: |
| 2 | 2 | |
| 3 | 3 | ctprob |
| 4 | -======== | |
| 4 | +====== | |
| 5 | 5 | |
| 6 | 6 | Compute event probability for a given model. |
| 7 | 7 | |
| ... | ... | @@ -9,16 +9,12 @@ Compute event probability for a given model. |
| 9 | 9 | Synopsis |
| 10 | 10 | -------- |
| 11 | 11 | |
| 12 | -This tool takes an event list file (or an XML observation definition file) and | |
| 13 | -a model as input and computes for each event the probability that it originates | |
| 14 | -from a specific model component. The probability is computed by by evaluating | |
| 15 | -the differential event probability for a given model and normalizing these | |
| 16 | -probabilities so that the sum of the probabilities for all model components is | |
| 17 | -unity for each event. | |
| 12 | +This tool computes for each event the probability that the event originates | |
| 13 | +from a one of the components of a model. | |
| 18 | 14 | |
| 19 | -The tool appends for each model component a single precision column to the event | |
| 20 | -list that contains the event probabilities. The name of the column is build from | |
| 21 | -the model name prefixed with ``PROB_``. | |
| 15 | +The tool takes on input an event list or an observation definiton XML file and | |
| 16 | +appends on output to each event file columns that provide the probabilities. | |
| 17 | +The column names are formed from the model name that is prefixed with ``PROB_``. | |
| 22 | 18 | |
| 23 | 19 | |
| 24 | 20 | General parameters |
| ... | ... | @@ -31,7 +27,7 @@ General parameters |
| 31 | 27 | Output event list or observation definition XML file. |
| 32 | 28 | |
| 33 | 29 | ``(prefix = "prob_") [string]`` |
| 34 | - Prefix for output event lists in observation definition file. | |
| 30 | + Prefix for output event lists in observation definition XML file. | |
| 35 | 31 | |
| 36 | 32 | ``inmodel [string]`` |
| 37 | 33 | Input model definition XML file. |
| ... | ... | @@ -82,4 +78,3 @@ Related tools or scripts |
| 82 | 78 | |
| 83 | 79 | :doc:`ctphase` |
| 84 | 80 | :doc:`csphasecrv` |
| 85 | - | ... | ... |
doc/source/users/reference_manual/index.rst
| ... | ... | @@ -26,8 +26,9 @@ ctools |
| 26 | 26 | ctmapcube --- Generates a map cube <ctmapcube> |
| 27 | 27 | ctmodel --- Computes model counts cube <ctmodel> |
| 28 | 28 | ctobssim --- Simulate observations <ctobssim> |
| 29 | - ctpsfcube --- Generates point spread function cube <ctpsfcube> | |
| 29 | + ctphase --- Computes the phase of each event <ctphase> | |
| 30 | 30 | ctprob --- Computes event probability for a given model <ctprob> |
| 31 | + ctpsfcube --- Generates point spread function cube <ctpsfcube> | |
| 31 | 32 | ctselect --- Selects event data <ctselect> |
| 32 | 33 | ctskymap --- Generates sky map <ctskymap> |
| 33 | 34 | cttsmap --- Generates Test Statistic map <cttsmap> | ... | ... |
pyext/ctphase.i
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctphase.i |
| 23 | - * @brief Append phase information to CTA events file | |
| 23 | + * @brief Event phase computation tool interface definition | |
| 24 | 24 | * @author Joshua Cardenzana |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| ... | ... | @@ -32,7 +32,7 @@ |
| 32 | 32 | /***********************************************************************//** |
| 33 | 33 | * @class ctphase |
| 34 | 34 | * |
| 35 | - * @brief Data selection tool | |
| 35 | + * @brief Event phase computation tool | |
| 36 | 36 | ***************************************************************************/ |
| 37 | 37 | class ctphase : public ctobservation { |
| 38 | 38 | public: | ... | ... |
src/ctphase/ctphase.cpp
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctphase.cpp |
| 23 | - * @brief Append phase information to CTA events file | |
| 23 | + * @brief Event phase computation tool implementation | |
| 24 | 24 | * @author Joshua Cardenzana |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -360,9 +360,6 @@ void ctphase::publish(const std::string& name) |
| 360 | 360 | ***************************************************************************/ |
| 361 | 361 | void ctphase::init_members(void) |
| 362 | 362 | { |
| 363 | - // Initialise parameters | |
| 364 | - m_chatter = static_cast<GChatter>(2); | |
| 365 | - | |
| 366 | 363 | // Initialise protected members |
| 367 | 364 | m_phase.clear(); |
| 368 | 365 | |
| ... | ... | @@ -378,9 +375,6 @@ void ctphase::init_members(void) |
| 378 | 375 | ***************************************************************************/ |
| 379 | 376 | void ctphase::copy_members(const ctphase& app) |
| 380 | 377 | { |
| 381 | - // Copy parameters | |
| 382 | - m_chatter = app.m_chatter; | |
| 383 | - | |
| 384 | 378 | // Copy protected members |
| 385 | 379 | m_phase = app.m_phase; |
| 386 | 380 | |
| ... | ... | @@ -402,43 +396,47 @@ void ctphase::free_members(void) |
| 402 | 396 | /***********************************************************************//** |
| 403 | 397 | * @brief Get application parameters |
| 404 | 398 | * |
| 405 | - * Get all user parameters from parameter file or (if required) by querying | |
| 406 | - * the user. Times are assumed to be in the native CTA MJD format. | |
| 407 | - * | |
| 408 | - * This method also loads observations if no observations are yet allocated. | |
| 409 | - * Observations are either loaded from a single CTA even list, or from a | |
| 410 | - * XML file using the metadata information that is stored in that file. | |
| 399 | + * Get all application parameters by either querying the parameters or by | |
| 400 | + * retrieving the parameters for the parameter file. | |
| 411 | 401 | ***************************************************************************/ |
| 412 | 402 | void ctphase::get_parameters(void) |
| 413 | 403 | { |
| 414 | - | |
| 415 | 404 | // Setup observations from "inobs" parameter. Do not request response |
| 416 | 405 | // information and do not accept counts cubes. |
| 417 | 406 | setup_observations(m_obs, false, true, false); |
| 418 | 407 | |
| 419 | - // If a model definition XML file is provided the | |
| 420 | - GFilename inmodel = (*this)["inmodel"].filename(); | |
| 421 | - if (is_valid_filename(inmodel)) { | |
| 422 | - | |
| 423 | - // Load the models from the XML file | |
| 424 | - GModels models(inmodel); | |
| 408 | + // If there are no models in the observation container then load model | |
| 409 | + // from a model definiton XML file specified by the "inmodel" parameter. | |
| 410 | + // The model is only loaded of the file is valid. | |
| 411 | + if (m_obs.models().size() == 0) { | |
| 412 | + GFilename inmodel = (*this)["inmodel"].filename(); | |
| 413 | + if (is_valid_filename(inmodel)) { | |
| 414 | + m_obs.models(inmodel); | |
| 415 | + } | |
| 416 | + } | |
| 425 | 417 | |
| 418 | + // If there are models in the model container then attempt to build | |
| 419 | + // a temporal phase curve model from the specified source ... | |
| 420 | + if (m_obs.models().size() != 0) { | |
| 421 | + | |
| 426 | 422 | // Get the source component |
| 427 | - std::string source = (*this)["source"].string(); | |
| 423 | + std::string srcname = (*this)["srcname"].string(); | |
| 428 | 424 | |
| 429 | 425 | // Throw an exception if source is not found in the model container |
| 430 | - if (!models.contains(source)) { | |
| 431 | - std::string msg = "Source model \""+source+"\" not found in model " | |
| 432 | - "definition XML file \""+inmodel.url()+"\"."; | |
| 426 | + if (!m_obs.models().contains(srcname)) { | |
| 427 | + std::string msg = "Source model \""+srcname+"\" not found in " | |
| 428 | + "model container."; | |
| 433 | 429 | throw GException::invalid_value(G_GET_PARAMETERS, msg); |
| 434 | 430 | } |
| 435 | 431 | |
| 436 | 432 | // Get pointer to source model |
| 437 | - GModelSky* sky = dynamic_cast<GModelSky*>(models[source]); | |
| 433 | + const GModelSky* sky = | |
| 434 | + dynamic_cast<const GModelSky*>(m_obs.models()[srcname]); | |
| 438 | 435 | |
| 439 | 436 | // Throw an exception if model is not a sky model |
| 440 | 437 | if (sky == NULL) { |
| 441 | - std::string msg = "Source model \""+source+"\" is not a sky model."; | |
| 438 | + std::string msg = "Source model \""+srcname+"\" is not a sky " | |
| 439 | + "model."; | |
| 442 | 440 | throw GException::invalid_value(G_GET_PARAMETERS, msg); |
| 443 | 441 | } |
| 444 | 442 | |
| ... | ... | @@ -449,7 +447,7 @@ void ctphase::get_parameters(void) |
| 449 | 447 | // Throw an exception if model has not a temporal phase curve |
| 450 | 448 | // component |
| 451 | 449 | if (phasecurve == NULL) { |
| 452 | - std::string msg = "Source model \""+source+"\" does not have a " | |
| 450 | + std::string msg = "Source model \""+srcname+"\" does not have a " | |
| 453 | 451 | "temporal component with phase information."; |
| 454 | 452 | throw GException::invalid_value(G_GET_PARAMETERS, msg); |
| 455 | 453 | } |
| ... | ... | @@ -459,7 +457,7 @@ void ctphase::get_parameters(void) |
| 459 | 457 | |
| 460 | 458 | } // endif: model definition XML file provided |
| 461 | 459 | |
| 462 | - // Otherwise read phase curve information from the parameter files | |
| 460 | + // ... otherwise read phase curve information from the parameter files | |
| 463 | 461 | else { |
| 464 | 462 | |
| 465 | 463 | // Read phase curve user parameters |
| ... | ... | @@ -483,9 +481,6 @@ void ctphase::get_parameters(void) |
| 483 | 481 | |
| 484 | 482 | } // endelse: read phase curve information from User parameters |
| 485 | 483 | |
| 486 | - // Get other User parameters | |
| 487 | - m_chatter = static_cast<GChatter>((*this)["chatter"].integer()); | |
| 488 | - | |
| 489 | 484 | // Optionally read ahead parameters so that they get correctly |
| 490 | 485 | // dumped into the log file |
| 491 | 486 | if (read_ahead()) { |
| ... | ... | @@ -507,7 +502,7 @@ void ctphase::get_parameters(void) |
| 507 | 502 | * @param[in,out] obs CTA observation. |
| 508 | 503 | * |
| 509 | 504 | * @exception GException::invalid_value |
| 510 | - * No events extension found in FITS file. | |
| 505 | + * No events found in observation. | |
| 511 | 506 | * |
| 512 | 507 | * Append phase information to events from a FITS file by adding a "PHASE" |
| 513 | 508 | * column to the FITS file. | ... | ... |
src/ctphase/ctphase.hpp
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctphase.hpp |
| 23 | - * @brief Append phase information to CTA events file | |
| 23 | + * @brief Event phase computation tool interface definition | |
| 24 | 24 | * @author Joshua Cardenzana |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -41,7 +41,9 @@ |
| 41 | 41 | /***********************************************************************//** |
| 42 | 42 | * @class ctphase |
| 43 | 43 | * |
| 44 | - * @brief Append phase columm to observation files | |
| 44 | + * @brief Event phase computation tool | |
| 45 | + * | |
| 46 | + * Computes the phase of each event using a temporal phase curve model | |
| 45 | 47 | ***************************************************************************/ |
| 46 | 48 | class ctphase : public ctobservation { |
| 47 | 49 | |
| ... | ... | @@ -70,11 +72,8 @@ protected: |
| 70 | 72 | void get_parameters(void); |
| 71 | 73 | void phase_events(GCTAObservation* obs); |
| 72 | 74 | |
| 73 | - // User parameters | |
| 74 | - GChatter m_chatter; //!< Chattiness | |
| 75 | - | |
| 76 | 75 | // Protected members |
| 77 | - GModelTemporalPhaseCurve m_phase; //!< Phase curve model | |
| 76 | + GModelTemporalPhaseCurve m_phase; //!< Phase curve model | |
| 78 | 77 | }; |
| 79 | 78 | |
| 80 | 79 | ... | ... |
src/ctphase/ctphase.par
| ... | ... | @@ -19,17 +19,17 @@ |
| 19 | 19 | inobs, f, a, "events.fits",,, "Input event list or observation definition XML file" |
| 20 | 20 | outobs, f, a, "phased_events.fits",,, "Output event list or observation definition XML file" |
| 21 | 21 | prefix, s, h, "phased_",,, "Prefix for event lists in observation definition XML file" |
| 22 | -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Model file defining the phase information" | |
| 23 | -source, s, a, "Crab",,, "Source in model file to use for phase information" | |
| 22 | +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Model definition XML file" | |
| 23 | +srcname, s, a, "Crab",,, "Source in model definition XML file to use for phase computation" | |
| 24 | 24 | |
| 25 | 25 | # |
| 26 | 26 | # Phase information parameters |
| 27 | 27 | #===================== |
| 28 | -mjd, r, a, 51544.5,,, "Reference MJD for phase information" | |
| 28 | +mjd, r, a, 51544.5,,, "Reference MJD for phase computation" | |
| 29 | 29 | phase, r, a, 0.0,0.0,1.0, "Phase at reference MJD" |
| 30 | 30 | f0, r, a, 1.0,,, "Frequency at reference MJD (Hz)" |
| 31 | -f1, r, a, 0.1,,, "First freq. derivative at reference MJD (s^-2)" | |
| 32 | -f2, r, a, 0.01,,, "Second freq. derivative at reference MJD (s^-3)" | |
| 31 | +f1, r, a, 0.1,,, "First frequency derivative at reference MJD (s^-2)" | |
| 32 | +f2, r, a, 0.01,,, "Second frequency derivative at reference MJD (s^-3)" | |
| 33 | 33 | |
| 34 | 34 | # |
| 35 | 35 | # Standard parameters | ... | ... |
src/ctprob/ctprob.cpp
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctprob.cpp |
| 23 | - * @brief Computes event probability for a given model | |
| 23 | + * @brief Event probability computation tool implementation | |
| 24 | 24 | * @author Leonardo Di Venere |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -33,7 +33,6 @@ |
| 33 | 33 | #include "GTools.hpp" |
| 34 | 34 | |
| 35 | 35 | /* __ Method name definitions ____________________________________________ */ |
| 36 | -#define G_GET_OBS "ctprob::get_obs()" | |
| 37 | 36 | #define G_EVALUATE_PROB "ctprob::evaluate_probability(GCTAObservation*)" |
| 38 | 37 | |
| 39 | 38 | /* __ Debug definitions __________________________________________________ */ |
| ... | ... | @@ -289,12 +288,12 @@ void ctprob::save(void) |
| 289 | 288 | |
| 290 | 289 | // Case A: Save event file(s) and XML metadata information |
| 291 | 290 | if (m_use_xml) { |
| 292 | - save_xml(); | |
| 291 | + save_events_xml(); | |
| 293 | 292 | } |
| 294 | 293 | |
| 295 | 294 | // Case B: Save event file as FITS file |
| 296 | 295 | else { |
| 297 | - save_fits(); | |
| 296 | + save_events_fits(); | |
| 298 | 297 | } |
| 299 | 298 | |
| 300 | 299 | // Return |
| ... | ... | @@ -368,14 +367,9 @@ void ctprob::publish(const std::string& name) |
| 368 | 367 | void ctprob::init_members(void) |
| 369 | 368 | { |
| 370 | 369 | // Initialise parameters |
| 371 | - m_outobs.clear(); | |
| 372 | - m_prefix.clear(); | |
| 373 | - m_chatter = static_cast<GChatter>(2); | |
| 374 | - | |
| 375 | - // Initialise protected members | |
| 376 | - m_infiles.clear(); | |
| 377 | - m_evtname.clear(); | |
| 378 | - m_gtiname.clear(); | |
| 370 | + m_apply_edisp = false; | |
| 371 | + m_publish = false; | |
| 372 | + m_chatter = static_cast<GChatter>(2); | |
| 379 | 373 | |
| 380 | 374 | // Return |
| 381 | 375 | return; |
| ... | ... | @@ -390,14 +384,9 @@ void ctprob::init_members(void) |
| 390 | 384 | void ctprob::copy_members(const ctprob& app) |
| 391 | 385 | { |
| 392 | 386 | // Copy parameters |
| 393 | - m_outobs = app.m_outobs; | |
| 394 | - m_prefix = app.m_prefix; | |
| 395 | - m_chatter = app.m_chatter; | |
| 396 | - | |
| 397 | - // Copy protected members | |
| 398 | - m_infiles = app.m_infiles; | |
| 399 | - m_evtname = app.m_evtname; | |
| 400 | - m_gtiname = app.m_gtiname; | |
| 387 | + m_apply_edisp = app.m_apply_edisp; | |
| 388 | + m_publish = app.m_publish; | |
| 389 | + m_chatter = app.m_chatter; | |
| 401 | 390 | |
| 402 | 391 | // Return |
| 403 | 392 | return; |
| ... | ... | @@ -417,25 +406,14 @@ void ctprob::free_members(void) |
| 417 | 406 | /***********************************************************************//** |
| 418 | 407 | * @brief Get application parameters |
| 419 | 408 | * |
| 420 | - * Get all user parameters from parameter file or (if required) by querying | |
| 421 | - * the user. Times are assumed to be in the native CTA MJD format. | |
| 422 | - * | |
| 423 | - * This method also loads observations if no observations are yet allocated. | |
| 424 | - * Observations are either loaded from a single CTA even list, or from a | |
| 425 | - * XML file using the metadata information that is stored in that file. | |
| 409 | + * Get all application parameters by either querying the parameters or by | |
| 410 | + * retrieving the parameters for the parameter file. | |
| 426 | 411 | ***************************************************************************/ |
| 427 | 412 | void ctprob::get_parameters(void) |
| 428 | 413 | { |
| 429 | - // Setup observations from "inobs" parameter. Do not request response | |
| 430 | - // information and do not accept counts cubes. | |
| 431 | - if (m_obs.size() == 0) { | |
| 432 | - get_obs(); | |
| 433 | - } | |
| 434 | - // ... otherwise add response information and energy boundaries in case | |
| 435 | - // that they are missing | |
| 436 | - else { | |
| 437 | - setup_observations(m_obs); | |
| 438 | - } | |
| 414 | + // Setup observations from "inobs" parameter. Request response | |
| 415 | + // information, accept event lists but do not accept counts cubes. | |
| 416 | + setup_observations(m_obs, true, true, false); | |
| 439 | 417 | |
| 440 | 418 | // Read model definition file if required |
| 441 | 419 | if (m_obs.models().size() == 0) { |
| ... | ... | @@ -451,7 +429,6 @@ void ctprob::get_parameters(void) |
| 451 | 429 | // Get energy dispersion flag parameters |
| 452 | 430 | m_apply_edisp = (*this)["edisp"].boolean(); |
| 453 | 431 | |
| 454 | - | |
| 455 | 432 | // Get remaining parameters |
| 456 | 433 | m_publish = (*this)["publish"].boolean(); |
| 457 | 434 | m_chatter = static_cast<GChatter>((*this)["chatter"].integer()); |
| ... | ... | @@ -459,8 +436,8 @@ void ctprob::get_parameters(void) |
| 459 | 436 | // Optionally read ahead parameters so that they get correctly |
| 460 | 437 | // dumped into the log file |
| 461 | 438 | if (read_ahead()) { |
| 462 | - m_outobs = (*this)["outobs"].filename(); | |
| 463 | - m_prefix = (*this)["prefix"].string(); | |
| 439 | + (*this)["outobs"].filename(); | |
| 440 | + (*this)["prefix"].string(); | |
| 464 | 441 | } |
| 465 | 442 | |
| 466 | 443 | // Write parameters into logger |
| ... | ... | @@ -472,77 +449,6 @@ void ctprob::get_parameters(void) |
| 472 | 449 | |
| 473 | 450 | |
| 474 | 451 | /***********************************************************************//** |
| 475 | - * @brief Get observation container | |
| 476 | - * | |
| 477 | - * @exception GException::invalid_value | |
| 478 | - * Invalid FITS file. | |
| 479 | - * | |
| 480 | - * Get an observation container according to the user parameters. The method | |
| 481 | - * supports loading of a individual FITS file or an observation definition | |
| 482 | - * file in XML format. | |
| 483 | - ***************************************************************************/ | |
| 484 | -void ctprob::get_obs(void) | |
| 485 | -{ | |
| 486 | - // Get the filename from the input parameters | |
| 487 | - std::string filename = (*this)["inobs"].filename(); | |
| 488 | - | |
| 489 | - // If no observation definition file throw an exception | |
| 490 | - if (!is_valid_filename(filename)) { | |
| 491 | - throw GException::invalid_value(G_GET_OBS, "Input event list is not valid."); | |
| 492 | - } // endif: filename was not valid | |
| 493 | - | |
| 494 | - // ... otherwise we have a file name | |
| 495 | - else { | |
| 496 | - | |
| 497 | - // If file is a FITS file then create an empty CTA observation | |
| 498 | - // and load file into observation | |
| 499 | - if (GFilename(filename).is_fits()) { | |
| 500 | - | |
| 501 | - // Allocate empty CTA observation | |
| 502 | - GCTAObservation cta; | |
| 503 | - | |
| 504 | - // Load data | |
| 505 | - cta.load(filename); | |
| 506 | - | |
| 507 | - // Set response | |
| 508 | - set_obs_response(&cta); | |
| 509 | - | |
| 510 | - // Append observation to container | |
| 511 | - m_obs.append(cta); | |
| 512 | - | |
| 513 | - // Signal that no XML file should be used for storage | |
| 514 | - m_use_xml = false; | |
| 515 | - | |
| 516 | - } | |
| 517 | - | |
| 518 | - // ... otherwise load file into observation container | |
| 519 | - else { | |
| 520 | - | |
| 521 | - // Load observations from XML file | |
| 522 | - m_obs.load(filename); | |
| 523 | - | |
| 524 | - // For all observations that have no response, set the response | |
| 525 | - // from the task parameters | |
| 526 | - set_response(m_obs); | |
| 527 | - | |
| 528 | - // Set observation boundary parameters (emin, emax, rad) | |
| 529 | - set_obs_bounds(m_obs); | |
| 530 | - | |
| 531 | - // Signal that XML file should be used for storage | |
| 532 | - m_use_xml = true; | |
| 533 | - | |
| 534 | - } // endelse: file was an XML file | |
| 535 | - | |
| 536 | - } | |
| 537 | - | |
| 538 | - // Return | |
| 539 | - return; | |
| 540 | - | |
| 541 | -} | |
| 542 | - | |
| 543 | - | |
| 544 | - | |
| 545 | -/***********************************************************************//** | |
| 546 | 452 | * @brief Evaluate probability for events |
| 547 | 453 | * |
| 548 | 454 | * @param[in,out] obs CTA observation. |
| ... | ... | @@ -632,153 +538,3 @@ void ctprob::evaluate_probability(GCTAObservation* obs) |
| 632 | 538 | // Return |
| 633 | 539 | return; |
| 634 | 540 | } |
| 635 | - | |
| 636 | - | |
| 637 | -/***********************************************************************//** | |
| 638 | - * @brief Set output file name. | |
| 639 | - * | |
| 640 | - * @param[in] filename Input file name. | |
| 641 | - * | |
| 642 | - * Converts an input file name into an output filename by prepending the | |
| 643 | - * prefix stored in the member m_prefix to the input file name. Any path as | |
| 644 | - * well as extension will be stripped from the input file name. Also a | |
| 645 | - * trailing ".gz" will be stripped as one cannot write into gzipped files. | |
| 646 | - ***************************************************************************/ | |
| 647 | -std::string ctprob::set_outfile_name(const std::string& filename) const | |
| 648 | -{ | |
| 649 | - // Create filename | |
| 650 | - GFilename fname(filename); | |
| 651 | - | |
| 652 | - // Split input filename without any extensions into path elements | |
| 653 | - std::vector<std::string> elements = gammalib::split(fname.url(), "/"); | |
| 654 | - | |
| 655 | - // The last path element is the filename | |
| 656 | - std::string outname = m_prefix + elements[elements.size()-1]; | |
| 657 | - | |
| 658 | - // Strip any ".gz" | |
| 659 | - outname = gammalib::strip_chars(outname, ".gz"); | |
| 660 | - | |
| 661 | - // Return output filename | |
| 662 | - return outname; | |
| 663 | -} | |
| 664 | - | |
| 665 | - | |
| 666 | -/***********************************************************************//** | |
| 667 | - * @brief Save event list in FITS format. | |
| 668 | - * | |
| 669 | - * Save the event list as a FITS file. The file name of the FITS file is | |
| 670 | - * specified by the `outobs` parameter. | |
| 671 | - ***************************************************************************/ | |
| 672 | -void ctprob::save_fits(void) | |
| 673 | -{ | |
| 674 | - // Save only if there are observations | |
| 675 | - if (m_obs.size() > 0) { | |
| 676 | - | |
| 677 | - // Get output filename | |
| 678 | - m_outobs = (*this)["outobs"].filename(); | |
| 679 | - | |
| 680 | - // Loop over all unbinned CTA observations in the container | |
| 681 | - for (GCTAObservation* obs = first_unbinned_observation(); obs != NULL; | |
| 682 | - obs = next_unbinned_observation()) { | |
| 683 | - | |
| 684 | - // Get input file name and default extension names | |
| 685 | - std::string infile = obs->eventfile(); | |
| 686 | - std::string evtname = gammalib::extname_cta_events; | |
| 687 | - std::string gtiname = gammalib::extname_gti; | |
| 688 | - | |
| 689 | - // Create file name object | |
| 690 | - GFilename fname(m_outobs); | |
| 691 | - | |
| 692 | - // Extract filename and event extension name | |
| 693 | - std::string outfile = fname.url(); | |
| 694 | - | |
| 695 | - // Append event extension name. We handle here the possibility | |
| 696 | - // to write the events into a different extension. | |
| 697 | - if (fname.has_extname()) { | |
| 698 | - outfile += "["+fname.extname()+"]"; | |
| 699 | - } | |
| 700 | - else { | |
| 701 | - outfile += "["+gammalib::extname_cta_events+"]"; | |
| 702 | - } | |
| 703 | - | |
| 704 | - // Log filename | |
| 705 | - log_value(NORMAL, "Event list file", outfile); | |
| 706 | - | |
| 707 | - // Save event list | |
| 708 | - save_event_list(obs, infile, evtname, gtiname, outfile); | |
| 709 | - | |
| 710 | - // Exit the loop (if this method is called we should only | |
| 711 | - // have a single unbinned observation in the observation | |
| 712 | - // container | |
| 713 | - break; | |
| 714 | - | |
| 715 | - } // endfor: looped over all unbinned observations | |
| 716 | - | |
| 717 | - } // endif: there were observations | |
| 718 | - | |
| 719 | - // Return | |
| 720 | - return; | |
| 721 | -} | |
| 722 | - | |
| 723 | - | |
| 724 | -/***********************************************************************//** | |
| 725 | - * @brief Save event list(s) in XML format. | |
| 726 | - * | |
| 727 | - * Save the event list(s) into FITS files and write the file path information | |
| 728 | - * into a XML file. The filename of the XML file is specified by the `outobs` | |
| 729 | - * parameter, the filename(s) of the event lists are built by prepending a | |
| 730 | - * prefix to the input event list filenames. Any path present in the input | |
| 731 | - * filename will be stripped, i.e. the event list(s) will be written in the | |
| 732 | - * local working directory (unless a path is specified in the prefix). | |
| 733 | - ***************************************************************************/ | |
| 734 | -void ctprob::save_xml(void) | |
| 735 | -{ | |
| 736 | - // Get output filename and prefix | |
| 737 | - m_outobs = (*this)["outobs"].filename(); | |
| 738 | - m_prefix = (*this)["prefix"].string(); | |
| 739 | - | |
| 740 | - // Issue warning if output filename has no .xml suffix | |
| 741 | - log_string(TERSE, warn_xml_suffix(m_outobs)); | |
| 742 | - | |
| 743 | - // Loop over all unbinned CTA observations in the container | |
| 744 | - for (GCTAObservation* obs = first_unbinned_observation(); obs != NULL; | |
| 745 | - obs = next_unbinned_observation()) { | |
| 746 | - | |
| 747 | - // Get input file name and default extension names | |
| 748 | - std::string infile = obs->eventfile(); | |
| 749 | - std::string evtname = gammalib::extname_cta_events; | |
| 750 | - std::string gtiname = gammalib::extname_gti; | |
| 751 | - | |
| 752 | - // Extract event and GTI extension names from input FITS file | |
| 753 | - GFilename fname(infile); | |
| 754 | - if (fname.has_extname()) { | |
| 755 | - evtname = fname.extname(); | |
| 756 | - } | |
| 757 | - gtiname = get_gtiname(fname.url(), evtname); | |
| 758 | - | |
| 759 | - // Set event output file name | |
| 760 | - std::string outfile = set_outfile_name(infile); | |
| 761 | - | |
| 762 | - // Append event extension name | |
| 763 | - outfile += "["+evtname+"]"; | |
| 764 | - | |
| 765 | - // Log filename | |
| 766 | - log_value(NORMAL, "Event list file", outfile); | |
| 767 | - | |
| 768 | - // Store output file name in observation | |
| 769 | - obs->eventfile(outfile); | |
| 770 | - | |
| 771 | - // Save event list | |
| 772 | - save_event_list(obs, infile, evtname, gtiname, outfile); | |
| 773 | - | |
| 774 | - } // endfor: looped over observations | |
| 775 | - | |
| 776 | - // Write observation definition XML file name into logger | |
| 777 | - log_value(NORMAL, "Obs. definition file", m_outobs); | |
| 778 | - | |
| 779 | - // Save observations in XML file | |
| 780 | - m_obs.save(m_outobs); | |
| 781 | - | |
| 782 | - // Return | |
| 783 | - return; | |
| 784 | -} | ... | ... |
src/ctprob/ctprob.hpp
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctprob.hpp |
| 23 | - * @brief Computes event probability for a given model | |
| 23 | + * @brief Event probability computation tool interface definition | |
| 24 | 24 | * @author Leonardo Di Venere |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -41,7 +41,7 @@ |
| 41 | 41 | /***********************************************************************//** |
| 42 | 42 | * @class ctprob |
| 43 | 43 | * |
| 44 | - * @brief Data selection tool | |
| 44 | + * @brief Event probability computation tool | |
| 45 | 45 | ***************************************************************************/ |
| 46 | 46 | class ctprob : public ctobservation { |
| 47 | 47 | |
| ... | ... | @@ -64,27 +64,16 @@ public: |
| 64 | 64 | |
| 65 | 65 | protected: |
| 66 | 66 | // Protected methods |
| 67 | - void init_members(void); | |
| 68 | - void copy_members(const ctprob& app); | |
| 69 | - void free_members(void); | |
| 70 | - void get_parameters(void); | |
| 71 | - void get_obs(void); | |
| 72 | - void evaluate_probability(GCTAObservation* obs); | |
| 73 | - std::string set_outfile_name(const std::string& filename) const; | |
| 74 | - void save_fits(void); | |
| 75 | - void save_xml(void); | |
| 67 | + void init_members(void); | |
| 68 | + void copy_members(const ctprob& app); | |
| 69 | + void free_members(void); | |
| 70 | + void get_parameters(void); | |
| 71 | + void evaluate_probability(GCTAObservation* obs); | |
| 76 | 72 | |
| 77 | 73 | // User parameters |
| 78 | - std::string m_outobs; //!< Output event list or XML file | |
| 79 | - std::string m_prefix; //!< Prefix for multiple event lists | |
| 80 | - bool m_apply_edisp; //!< Apply energy dispersion? | |
| 81 | - bool m_publish; //!< Publish event list? | |
| 82 | - GChatter m_chatter; //!< Chattiness | |
| 83 | - | |
| 84 | - // Protected members | |
| 85 | - std::vector<std::string> m_infiles; //!< Input event filenames | |
| 86 | - std::vector<std::string> m_evtname; //!< Event extension names | |
| 87 | - std::vector<std::string> m_gtiname; //!< GTI extension names | |
| 74 | + bool m_apply_edisp; //!< Apply energy dispersion? | |
| 75 | + bool m_publish; //!< Publish event list? | |
| 76 | + GChatter m_chatter; //!< Chattiness | |
| 88 | 77 | }; |
| 89 | 78 | |
| 90 | 79 | #endif /* CTPROB_HPP */ | ... | ... |
test/test_ctphase.py
| ... | ... | @@ -72,7 +72,7 @@ class Test(test): |
| 72 | 72 | # Setup ctphase command |
| 73 | 73 | cmd = ctphase+' inobs="'+self._events+'"'+ \ |
| 74 | 74 | ' outobs="ctphase_cmd1.fits"'+ \ |
| 75 | - ' inmodel="'+self._model_file+'" source="Crab"'+ \ | |
| 75 | + ' inmodel="'+self._model_file+'" srcname="Crab"'+ \ | |
| 76 | 76 | ' logfile="ctphase_cmd1.log" chatter=1' |
| 77 | 77 | |
| 78 | 78 | # Check if execution of wrong command fails |
| ... | ... | @@ -89,7 +89,7 @@ class Test(test): |
| 89 | 89 | # Setup ctphase command |
| 90 | 90 | cmd = ctphase+' inobs="event_file_that_does_not_exist.fits"'+ \ |
| 91 | 91 | ' outobs="ctphase_cmd2.fits"'+ \ |
| 92 | - ' inmodel="'+self._model_file+'" source="Crab"'+ \ | |
| 92 | + ' inmodel="'+self._model_file+'" srcname="Crab"'+ \ | |
| 93 | 93 | ' logfile="ctphase_cmd2.log" chatter=1' |
| 94 | 94 | |
| 95 | 95 | # Check if execution failed |
| ... | ... | @@ -124,7 +124,7 @@ class Test(test): |
| 124 | 124 | |
| 125 | 125 | # Check that saving does nothing |
| 126 | 126 | phase['inmodel'] = self._model_file |
| 127 | - phase['source'] = 'Crab' | |
| 127 | + phase['srcname'] = 'Crab' | |
| 128 | 128 | phase['outobs'] = 'ctphase_py0.fits' |
| 129 | 129 | phase['logfile'] = 'ctphase_py0.log' |
| 130 | 130 | phase.logFileOpen() |
| ... | ... | @@ -138,7 +138,7 @@ class Test(test): |
| 138 | 138 | # Now set ctphase parameters |
| 139 | 139 | phase['inobs'] = self._events |
| 140 | 140 | phase['inmodel'] = self._model_file |
| 141 | - phase['source'] = 'Crab' | |
| 141 | + phase['srcname'] = 'Crab' | |
| 142 | 142 | phase['outobs'] = 'ctphase_py1.fits' |
| 143 | 143 | phase['logfile'] = 'ctphase_py1.log' |
| 144 | 144 | phase['chatter'] = 2 |
| ... | ... | @@ -151,9 +151,13 @@ class Test(test): |
| 151 | 151 | # Check result file |
| 152 | 152 | self._check_result_file('ctphase_py1.fits') |
| 153 | 153 | |
| 154 | + # Clear phase tool | |
| 155 | + phase.clear() | |
| 156 | + | |
| 154 | 157 | # Now run ctphase tool without a model file |
| 158 | + phase['inobs'] = self._events | |
| 155 | 159 | phase['inmodel'] = 'NONE' |
| 156 | - phase['source'] = 'NONE' | |
| 160 | + phase['srcname'] = 'NONE' | |
| 157 | 161 | phase['mjd'] = 51544.5 |
| 158 | 162 | phase['phase'] = 0.0 |
| 159 | 163 | phase['f0'] = 1.0 | ... | ... |