Commit 5d99317b4868bde3a2f541df61981551573fe147

Authored by knodlseder
1 parent 8c7c388f

introduce internal time slices (fixed to 1800 s) to reduce the memory requirements of the task

pyext/ctobssim.i
... ... @@ -52,8 +52,7 @@ public:
52 52 GObservations& obs(void);
53 53 void get_parameters(void);
54 54 void set_list(GCTAObservation* obs);
55   - GPhotons simulate_photons(const GCTAObservation* obs, const GModels& models);
56   - void simulate_source(GCTAObservation* obs, const GPhotons& photons);
  55 + void simulate_source(GCTAObservation* obs, const GModels& models);
57 56 void simulate_background(GCTAObservation* obs, const GModels& models);
58 57 };
59 58  
... ...
src/ctobssim/ctobssim.cpp
... ... @@ -275,10 +275,11 @@ void ctobssim::run(void)
275 275 }
276 276  
277 277 // Simulate photons
278   - GPhotons photons = simulate_photons(obs, m_obs.models());
  278 + //GPhotons photons = simulate_photons(obs, m_obs.models());
279 279  
280 280 // Simulate source events
281   - simulate_source(obs, photons);
  281 + //simulate_source(obs, photons);
  282 + simulate_source(obs, m_obs.models());
282 283  
283 284 // Simulate source events
284 285 simulate_background(obs, m_obs.models());
... ... @@ -466,128 +467,6 @@ void ctobssim::set_list(GCTAObservation* obs)
466 467  
467 468  
468 469 /***********************************************************************//**
469   - * @brief Simulate photons for a given CTA observation
470   - *
471   - * @param[in] obs Pointer on CTA observation.
472   - * @param[in] models Models.
473   - *
474   - * This method simulates photons for a given CTA observation. It will loop
475   - * over all energy boundaries, all Good Time Intervals and all sky models
476   - * to generate a list of photons.
477   - *
478   - * @todo Add margins to the data selections so that we generate also photons
479   - * that fall slightly outside the ROI and the energy interval so that
480   - * they can be scatter within the ROI and energy interval by the
481   - * PSF and energy dispersion.
482   - ***************************************************************************/
483   -GPhotons ctobssim::simulate_photons(const GCTAObservation* obs,
484   - const GModels& models)
485   -{
486   - // Initialise indentation for logging
487   - int indent = 0;
488   -
489   - // Get CTA event list
490   - const GCTAEventList* events = dynamic_cast<const GCTAEventList*>(obs->events());
491   -
492   - // Extract ROI
493   - GSkyDir dir = events->roi().centre().skydir();
494   - double rad = events->roi().radius();
495   -
496   - // Dump simulation cone information
497   - if (logNormal()) {
498   - log << parformat("Simulation area");
499   - log << str(m_area) << " cm2" << std::endl;
500   - log << parformat("Simulation cone");
501   - log << "RA=" << dir.ra_deg() << " deg";
502   - log << ", Dec=" << dir.dec_deg() << "deg";
503   - log << ", r=" << rad << " deg" << std::endl;
504   - }
505   -
506   - // Allocate photons
507   - GPhotons photons;
508   -
509   - // Loop over all Good Time Intervals
510   - for (int it = 0; it < events->gti().size(); ++it) {
511   -
512   - // Extract time interval
513   - GTime tmin = events->gti().tstart(it);
514   - GTime tmax = events->gti().tstop(it);
515   -
516   - // Dump time interval
517   - if (logNormal()) {
518   - if (events->gti().size() > 1) {
519   - indent++;
520   - log.indent(indent);
521   - }
522   - log << parformat("Time interval");
523   - log << tmin << " - " << tmax << std::endl;
524   - }
525   -
526   - // Loop over all energy boundaries
527   - for (int ie = 0; ie < events->ebounds().size(); ++ie) {
528   -
529   - // Extract energy boundaries
530   - GEnergy emin = events->ebounds().emin(ie);
531   - GEnergy emax = events->ebounds().emax(ie);
532   -
533   - // Dump energy range
534   - if (logNormal()) {
535   - if (events->ebounds().size() > 1) {
536   - indent++;
537   - log.indent(indent);
538   - }
539   - log << parformat("Energy range");
540   - log << emin << " - " << emax << std::endl;
541   - }
542   -
543   - // Loop over all sky models
544   - for (int i = 0; i < models.size(); ++i) {
545   -
546   - // Get sky model (NULL if not a sky model)
547   - const GModelSky* model = dynamic_cast<const GModelSky*>(&models[i]);
548   -
549   - // If we have a sky model then simulate photons
550   - if (model != NULL) {
551   -
552   - // Get photons
553   - GPhotons p = model->mc(m_area, dir, rad, emin, emax,
554   - tmin, tmax, m_ran);
555   -
556   - // Reserve new space for photons
557   - photons.reserve(photons.size() + p.size());
558   -
559   - // Add photons to list
560   - for (int k = 0; k < p.size(); ++k) {
561   - p[k].mcid(i);
562   - photons.push_back(p[k]);
563   - }
564   -
565   - // Dump simulation result for model
566   - if (logNormal()) {
567   - log << parformat("MC source photons");
568   - log << str(p.size());
569   - if (model->name().length() > 0)
570   - log << " [" << model->name() << "]";
571   - log << std::endl;
572   - }
573   -
574   - } // endif: model was a sky model
575   -
576   - } // endfor: looped over models
577   -
578   - } // endfor: looped over all energy boundaries
579   -
580   - } // endfor: looped over all time intervals
581   -
582   - // Reset indentation
583   - log.indent(0);
584   -
585   - // Return photons
586   - return photons;
587   -}
588   -
589   -
590   -/***********************************************************************//**
591 470 * @brief Simulate source events from photon list
592 471 *
593 472 * @param[in] obs Pointer on CTA observation.
... ... @@ -603,8 +482,13 @@ GPhotons ctobssim::simulate_photons(const GCTAObservation* obs,
603 482 *
604 483 * This method does nothing if the observation pointer is NULL. It also
605 484 * verifies if the observation has a valid pointing and response.
  485 + *
  486 + * @todo Add margins to the data selections so that we generate also photons
  487 + * that fall slightly outside the ROI and the energy interval so that
  488 + * they can be scatter within the ROI and energy interval by the
  489 + * PSF and energy dispersion.
606 490 ***************************************************************************/
607   -void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons& photons)
  491 +void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models)
608 492 {
609 493 // Continue only if observation pointer is valid
610 494 if (obs != NULL) {
... ... @@ -631,24 +515,173 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GPhotons&amp; photons)
631 515 // Get pointer on event list (circumvent const correctness)
632 516 GCTAEventList* events = (GCTAEventList*)(obs->events());
633 517  
634   - // Reserves space for source events in event list
635   - events->reserve(photons.size());
  518 + // Extract ROI
  519 + GSkyDir dir = events->roi().centre().skydir();
  520 + double rad = events->roi().radius();
636 521  
637   - // Simulate events from photons
638   - for (int i = 0; i < photons.size(); ++i) {
639   - GCTAEventAtom* event = rsp->mc(m_area, photons[i], *pnt, m_ran);
640   - if (event != NULL) {
641   - events->append(*event);
642   - delete event;
643   - }
644   - }
645   -
646   - // Dump simulation results
  522 + // Dump simulation cone information
647 523 if (logNormal()) {
648   - log << parformat("MC source events");
649   - log << str(events->size()) << std::endl;
  524 + log << parformat("Simulation area");
  525 + log << str(m_area) << " cm2" << std::endl;
  526 + log << parformat("Simulation cone");
  527 + log << "RA=" << dir.ra_deg() << " deg";
  528 + log << ", Dec=" << dir.dec_deg() << "deg";
  529 + log << ", r=" << rad << " deg" << std::endl;
650 530 }
651 531  
  532 + // Initialise indentation for logging
  533 + int indent = 0;
  534 +
  535 + // Loop over all Good Time Intervals
  536 + for (int it = 0; it < events->gti().size(); ++it) {
  537 +
  538 + // Extract time interval
  539 + GTime tmin = events->gti().tstart(it);
  540 + GTime tmax = events->gti().tstop(it);
  541 +
  542 + // Dump time interval
  543 + if (logNormal()) {
  544 + if (events->gti().size() > 1) {
  545 + indent++;
  546 + log.indent(indent);
  547 + }
  548 + log << parformat("Time interval");
  549 + log << tmin << " - " << tmax << std::endl;
  550 + }
  551 +
  552 + // Loop over all energy boundaries
  553 + for (int ie = 0; ie < events->ebounds().size(); ++ie) {
  554 +
  555 + // Extract energy boundaries
  556 + GEnergy emin = events->ebounds().emin(ie);
  557 + GEnergy emax = events->ebounds().emax(ie);
  558 +
  559 + // Dump energy range
  560 + if (logNormal()) {
  561 + if (events->ebounds().size() > 1) {
  562 + indent++;
  563 + log.indent(indent);
  564 + }
  565 + log << parformat("Energy range");
  566 + log << emin << " - " << emax << std::endl;
  567 + }
  568 +
  569 + // Loop over all sky models
  570 + for (int i = 0; i < models.size(); ++i) {
  571 +
  572 + // Get sky model (NULL if not a sky model)
  573 + const GModelSky* model = dynamic_cast<const GModelSky*>(&models[i]);
  574 +
  575 + // If we have a sky model then simulate photons
  576 + if (model != NULL) {
  577 +
  578 + // To reduce memory requirements we split long time
  579 + // intervals into several slices. The maximum length
  580 + // of a slice is determined by the fixed parameter
  581 + // m_time_max
  582 + GTime tstart = tmin;
  583 + GTime tstop = tstart + m_time_max;
  584 +
  585 + // Initialise cumulative photon counter
  586 + int nphotons = 0;
  587 +
  588 + // Loop over time slices
  589 + while (tstart < tmax) {
  590 +
  591 + // Make sure that tstop <= tmax
  592 + if (tstop > tmax)
  593 + tstop = tmax;
  594 +
  595 + // Dump time slice
  596 + if (logExplicit()) {
  597 + if (tmax - tmin > m_time_max) {
  598 + indent++;
  599 + log.indent(indent);
  600 + }
  601 + log << parformat("Time slice");
  602 + log << tstart << " - " << tstop << std::endl;
  603 + }
  604 +
  605 + // Get photons
  606 + GPhotons photons = model->mc(m_area, dir, rad,
  607 + emin, emax,
  608 + tstart, tstop, m_ran);
  609 +
  610 + // Bookkeeping of simulated number of photons
  611 + nphotons += photons.size();
  612 +
  613 + // Simulate events from photons
  614 + for (int i = 0; i < photons.size(); ++i) {
  615 + GCTAEventAtom* event = rsp->mc(m_area, photons[i], *pnt, m_ran);
  616 + if (event != NULL) {
  617 + events->append(*event);
  618 + delete event;
  619 + }
  620 + }
  621 +
  622 + // Go to next time slice
  623 + tstart = tstop;
  624 + tstop = tstart + m_time_max;
  625 +
  626 + // Reset indentation
  627 + if (logExplicit()) {
  628 + if (tmax - tmin > m_time_max) {
  629 + indent--;
  630 + log.indent(indent);
  631 + }
  632 + }
  633 +
  634 + } // endwhile: looped over time slices
  635 +
  636 + // Dump simulation results
  637 + if (logNormal()) {
  638 + log << parformat("MC source photons");
  639 + log << str(nphotons);
  640 + if (model->name().length() > 0)
  641 + log << " [" << model->name() << "]";
  642 + log << std::endl;
  643 + log << parformat("MC source events");
  644 + log << str(events->size());
  645 + if (model->name().length() > 0)
  646 + log << " [" << model->name() << "]";
  647 + log << std::endl;
  648 + }
  649 +
  650 + } // endif: model was a sky model
  651 +
  652 + } // endfor: looped over models
  653 +
  654 + // Dump simulation results
  655 + if (logNormal()) {
  656 + log << parformat("MC source events");
  657 + log << str(events->size());
  658 + log << " (all source models)";
  659 + log << std::endl;
  660 + }
  661 +
  662 + // Reset indentation
  663 + if (logNormal()) {
  664 + if (events->ebounds().size() > 1) {
  665 + indent--;
  666 + log.indent(indent);
  667 + }
  668 + }
  669 +
  670 + } // endfor: looped over all energy boundaries
  671 +
  672 + // Reset indentation
  673 + if (logNormal()) {
  674 + if (events->gti().size() > 1) {
  675 + indent--;
  676 + log.indent(indent);
  677 + }
  678 + }
  679 +
  680 + } // endfor: looped over all time intervals
  681 +
  682 + // Reset indentation
  683 + log.indent(0);
  684 +
652 685 } // endif: observation pointer was valid
653 686  
654 687 // Return
... ... @@ -750,7 +783,8 @@ void ctobssim::init_members(void)
750 783 m_emax = 0.0;
751 784  
752 785 // Set fixed parameters
753   - m_area = 19634954.0 * 1.0e4; //!< pi*(2500^2) m^2
  786 + m_area = 19634954.0 * 1.0e4; //!< pi*(2500^2) m^2
  787 + m_time_max.met(1800.0); //!< Maximum length of time slice (s)
754 788  
755 789 // Set logger properties
756 790 log.date(true);
... ... @@ -768,20 +802,21 @@ void ctobssim::init_members(void)
768 802 void ctobssim::copy_members(const ctobssim& app)
769 803 {
770 804 // Copy attributes
771   - m_infile = app.m_infile;
772   - m_outfile = app.m_outfile;
773   - m_caldb = app.m_caldb;
774   - m_irf = app.m_irf;
775   - m_obs = app.m_obs;
776   - m_seed = app.m_seed;
777   - m_ra = app.m_ra;
778   - m_dec = app.m_dec;
779   - m_rad = app.m_rad;
780   - m_tmin = app.m_tmin;
781   - m_tmax = app.m_tmax;
782   - m_emin = app.m_emin;
783   - m_emax = app.m_emax;
784   - m_area = app.m_area;
  805 + m_infile = app.m_infile;
  806 + m_outfile = app.m_outfile;
  807 + m_caldb = app.m_caldb;
  808 + m_irf = app.m_irf;
  809 + m_obs = app.m_obs;
  810 + m_seed = app.m_seed;
  811 + m_ra = app.m_ra;
  812 + m_dec = app.m_dec;
  813 + m_rad = app.m_rad;
  814 + m_tmin = app.m_tmin;
  815 + m_tmax = app.m_tmax;
  816 + m_emin = app.m_emin;
  817 + m_emax = app.m_emax;
  818 + m_area = app.m_area;
  819 + m_time_max = app.m_time_max;
785 820  
786 821 // Return
787 822 return;
... ...
src/ctobssim/ctobssim.hpp
... ... @@ -33,7 +33,7 @@
33 33  
34 34 /* __Definitions _________________________________________________________ */
35 35 #define CTOBSSIM_NAME "ctobssim"
36   -#define CTOBSSIM_VERSION "00-02-02"
  36 +#define CTOBSSIM_VERSION "00-03-00"
37 37  
38 38  
39 39 /***********************************************************************//**
... ... @@ -67,8 +67,7 @@ public:
67 67 GObservations& obs(void) { return m_obs; }
68 68 void get_parameters(void);
69 69 void set_list(GCTAObservation* obs);
70   - GPhotons simulate_photons(const GCTAObservation* obs, const GModels& models);
71   - void simulate_source(GCTAObservation* obs, const GPhotons& photons);
  70 + void simulate_source(GCTAObservation* obs, const GModels& models);
72 71 void simulate_background(GCTAObservation* obs, const GModels& models);
73 72  
74 73 protected:
... ... @@ -93,6 +92,7 @@ protected:
93 92  
94 93 // Protected members
95 94 double m_area; //!< Surface area for simulation (cm2)
  95 + GTime m_time_max; //!< Maximum length of time slice (sec)
96 96 GRan m_ran; //!< Random number generator
97 97 GObservations m_obs; //!< Observation container
98 98 };
... ...
src/ctobssim/ctobssim.par
... ... @@ -5,7 +5,7 @@
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # File: ctobssim.par #
8   -# Version: 00-02-02 #
  8 +# Version: 00-03-00 #
9 9 # #
10 10 # Author: Jurgen Knodlseder #
11 11 # knodlseder@cesr.fr #
... ...