Commit 817bb2df203793f2348cf5fc0a12f0829b197be0

Authored by Jürgen Knödlseder
1 parent b00117e5

Adapt for handling energy dispersion.

True photons are now drawn over a sufficiently large energy band so that when dispersed the selected energy range is correctly filled.
src/ctobssim/ctobssim.cpp
... ... @@ -256,6 +256,18 @@ void ctobssim::run(void)
256 256 }
257 257 }
258 258  
  259 + // Set energy dispersion flag for all CTA observations and save old
  260 + // values in save_edisp vector
  261 + std::vector<bool> save_edisp;
  262 + save_edisp.assign(m_obs.size(), false);
  263 + for (int i = 0; i < m_obs.size(); ++i) {
  264 + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
  265 + if (obs != NULL) {
  266 + save_edisp[i] = obs->response().apply_edisp();
  267 + obs->response().apply_edisp(m_apply_edisp);
  268 + }
  269 + }
  270 +
259 271 // Write observation(s) into logger
260 272 if (logTerse()) {
261 273 log << std::endl;
... ... @@ -349,6 +361,14 @@ void ctobssim::run(void)
349 361 m_use_xml = true;
350 362 }
351 363  
  364 + // Restore energy dispersion flag for all CTA observations
  365 + for (int i = 0; i < m_obs.size(); ++i) {
  366 + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
  367 + if (obs != NULL) {
  368 + obs->response().apply_edisp(save_edisp[i]);
  369 + }
  370 + }
  371 +
352 372 // Return
353 373 return;
354 374 }
... ... @@ -468,7 +488,8 @@ void ctobssim::get_parameters(void)
468 488 }
469 489  
470 490 // Get other parameters
471   - m_seed = (*this)["seed"].integer();
  491 + m_seed = (*this)["seed"].integer();
  492 + m_apply_edisp = (*this)["edisp"].boolean();
472 493  
473 494 // Optionally read ahead parameters so that they get correctly
474 495 // dumped into the log file
... ... @@ -544,15 +565,14 @@ void ctobssim::set_list(GCTAObservation* obs)
544 565 if (obs != NULL) {
545 566  
546 567 // Get CTA observation parameters
547   - m_ra = (*this)["ra"].real();
548   - m_dec = (*this)["dec"].real();
549   - m_rad = (*this)["rad"].real();
550   - m_tmin = (*this)["tmin"].real();
551   - m_tmax = (*this)["tmax"].real();
552   - m_emin = (*this)["emin"].real();
553   - m_emax = (*this)["emax"].real();
554   - m_apply_edisp = (*this)["edisp"].boolean();
555   - m_deadc = (*this)["deadc"].real();
  568 + m_ra = (*this)["ra"].real();
  569 + m_dec = (*this)["dec"].real();
  570 + m_rad = (*this)["rad"].real();
  571 + m_tmin = (*this)["tmin"].real();
  572 + m_tmax = (*this)["tmax"].real();
  573 + m_emin = (*this)["emin"].real();
  574 + m_emax = (*this)["emax"].real();
  575 + m_deadc = (*this)["deadc"].real();
556 576  
557 577 // Allocate CTA event list
558 578 GCTAEventList events;
... ... @@ -628,10 +648,8 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels&amp; models,
628 648 wrklog = &log;
629 649 }
630 650  
631   - // Get pointer on CTA response. Throw an exception if the response
632   - // is not defined.
633   - GCTAResponse& rsp = const_cast<GCTAResponse&>(obs->response());
634   - rsp.apply_edisp(m_apply_edisp);
  651 + // Get CTA response
  652 + const GCTAResponse& rsp = obs->response();
635 653  
636 654 // Make sure that the observation holds a CTA event list. If this
637 655 // is not the case then allocate and attach a CTA event list now.
... ... @@ -686,13 +704,24 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels&amp; models,
686 704 GEnergy emin = events->ebounds().emin(ie);
687 705 GEnergy emax = events->ebounds().emax(ie);
688 706  
  707 + // Set true photon energy limits for simulation. If observation
  708 + // has energy dispersion then add margin
  709 + GEnergy e_true_min = emin;
  710 + GEnergy e_true_max = emax;
  711 + if (rsp.use_edisp()) {
  712 + e_true_min = rsp.ebounds_src(e_true_min).emin();
  713 + e_true_max = rsp.ebounds_src(e_true_max).emax();
  714 + }
  715 +
689 716 // Dump energy range
690 717 if (logNormal()) {
691 718 if (events->ebounds().size() > 1) {
692 719 indent++;
693 720 wrklog->indent(indent);
694 721 }
695   - *wrklog << gammalib::parformat("Energy range", indent);
  722 + *wrklog << gammalib::parformat("Photon energy range", indent);
  723 + *wrklog << e_true_min << " - " << e_true_max << std::endl;
  724 + *wrklog << gammalib::parformat("Event energy range", indent);
696 725 *wrklog << emin << " - " << emax << std::endl;
697 726 }
698 727  
... ... @@ -757,7 +786,7 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels&amp; models,
757 786  
758 787 // Get photons
759 788 GPhotons photons = model->mc(m_area, dir, rad,
760   - emin, emax,
  789 + e_true_min, e_true_max,
761 790 tstart, tstop, ran);
762 791  
763 792 // Dump number of simulated photons
... ... @@ -785,7 +814,12 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels&amp; models,
785 814 if (event != NULL) {
786 815  
787 816 // Use event only if it falls within ROI
788   - if (events->roi().contains(*event)) {
  817 + // energy boundary and time slice
  818 + if (events->roi().contains(*event) &&
  819 + event->energy() >= emin &&
  820 + event->energy() <= emax &&
  821 + event->time() >= tstart &&
  822 + event->time() <= tstop) {
789 823 event->event_id(m_event_id);
790 824 events->append(*event);
791 825 m_event_id++;
... ... @@ -998,7 +1032,7 @@ void ctobssim::init_members(void)
998 1032 m_tmax = 0.0;
999 1033 m_emin = 0.0;
1000 1034 m_emax = 0.0;
1001   - m_apply_edisp = true;
  1035 + m_apply_edisp = false;
1002 1036 m_deadc = 1.0;
1003 1037  
1004 1038 // Initialise protected members
... ...
src/ctobssim/ctobssim.par
... ... @@ -17,13 +17,13 @@
17 17 #
18 18 # File information
19 19 #=================
20   -infile, f, a, "test/data/crab.xml",,, "Model"
21   -outfile,f, a, "events.fits",,, "Output event data file or observation definition file"
22   -prefix, s, h, "sim_events_",,, "Prefix for event lists in observation definition file"
  20 +infile, f, a, "$CTOOLS/share/models/crab.xml",,, "Model"
  21 +outfile,f, a, "events.fits",,, "Output event data file or observation definition file"
  22 +prefix, s, h, "sim_events_",,, "Prefix for event lists in observation definition file"
23 23 #
24 24 # Observation parameters
25 25 #=======================
26   -caldb, s, a, "",,, "Calibration database"
  26 +caldb, s, a, "$CTOOLS/share/caldb/data/cta/dummy",,, "Calibration database"
27 27 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
28 28 #
29 29 # Simulation parameters
... ...