Commit cacfe07ce798720fd9c951573c2efa338d8a8d7b

Authored by Jürgen Knödlseder
1 parent 4eab7742

Add support for general GModelData simulations.

Background simulations can now be done for any model of type GModelData. This is thanks to the abstract mc() method that has been introduced in GModelData. A test case for the new GCTABackground model has been added to the unit tests.
ChangeLog
1 -2013-04-09 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> 1 +2013-11-19 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2
3 * Version 0.7.0 released 3 * Version 0.7.0 released
4 ======================== 4 ========================
5 5
6 Adapt to GammaLib-00-08-00 interface 6 Adapt to GammaLib-00-08-00 interface
7 - ctobssim now only simulates events within ROI 7 + ctobssim now only simulates events within ROI and supports
  8 + all kinds of data space models
8 9
9 2012-12-21 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> 10 2012-12-21 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
10 11
@@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-07-00 @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-07-00
2 2
3 Author(s) : Juergen Knoedlseder 3 Author(s) : Juergen Knoedlseder
4 4
5 -April 9th, 2013 5 +19 November 2013
6 6
7 7
8 1. Introduction 8 1. Introduction
@@ -33,6 +33,10 @@ ra and dec) and region radius (parameter rad). A margin of 0.5 has been @@ -33,6 +33,10 @@ ra and dec) and region radius (parameter rad). A margin of 0.5 has been
33 added internally to the radius so that also sources at the edge but 33 added internally to the radius so that also sources at the edge but
34 slightly outside of the ROI will be simulated correctly. 34 slightly outside of the ROI will be simulated correctly.
35 35
  36 +ctobssim now supports any kind of data space model for background
  37 +simulations, using the abstract mc() method that is now available
  38 +in the GModelData base class.
  39 +
36 40
37 5. ctselect - CTA event selection 41 5. ctselect - CTA event selection
38 --------------------------------- 42 ---------------------------------
src/ctobssim/ctobssim.cpp
@@ -872,49 +872,56 @@ void ctobssim::simulate_background(GCTAObservation* obs, @@ -872,49 +872,56 @@ void ctobssim::simulate_background(GCTAObservation* obs,
872 // Loop over all models 872 // Loop over all models
873 for (int i = 0; i < models.size(); ++i) { 873 for (int i = 0; i < models.size(); ++i) {
874 874
875 - // Get model (NULL if not a radial acceptance model)  
876 - const GCTAModelRadialAcceptance* model =  
877 - dynamic_cast<const GCTAModelRadialAcceptance*>(models[i]); 875 + // Get data model (NULL if not a data model)
  876 + const GModelData* model =
  877 + dynamic_cast<const GModelData*>(models[i]);
878 878
879 - // If we have a radial acceptance model then simulate events  
880 - if (model != NULL) { 879 + // If we have a data model that applies to CTA then simulate
  880 + // events
  881 + if (model != NULL && model->isvalid("CTA", "")) {
881 882
882 - // Get simulated event list. Note that this method includes  
883 - // the deadtime correction.  
884 - GCTAEventList* list = model->mc(*obs, ran); 883 + // Get simulated CTA event list. Note that this method
  884 + // includes the deadtime correction.
  885 + GCTAEventList* list =
  886 + dynamic_cast<GCTAEventList*>(model->mc(*obs, ran));
885 887
886 - // Reserves space for events  
887 - events->reserve(list->size()+events->size()); 888 + // Continue only if we got a CTA event list
  889 + if (list != NULL) {
888 890
889 - // Append events  
890 - for (int k = 0; k < list->size(); k++) { 891 + // Reserves space for events
  892 + events->reserve(list->size()+events->size());
891 893
892 - // Get event pointer  
893 - GCTAEventAtom* event = (*list)[k]; 894 + // Append events
  895 + for (int k = 0; k < list->size(); k++) {
894 896
895 - // Use event only if it falls within ROI  
896 - if (event->dir().dist_deg(events->roi().centre().dir()) <=  
897 - events->roi().radius()) { 897 + // Get event pointer
  898 + GCTAEventAtom* event = (*list)[k];
898 899
899 - // Set event identifier  
900 - event->event_id(m_event_id);  
901 - m_event_id++; 900 + // Use event only if it falls within ROI
  901 + if (event->dir().dist_deg(events->roi().centre().dir()) <=
  902 + events->roi().radius()) {
902 903
903 - // Append event  
904 - events->append(*event); 904 + // Set event identifier
  905 + event->event_id(m_event_id);
  906 + m_event_id++;
905 907
906 - } // endif: event was within ROI 908 + // Append event
  909 + events->append(*event);
907 910
908 - } // endfor: looped over all events 911 + } // endif: event was within ROI
909 912
910 - // Dump simulation results  
911 - if (logNormal()) {  
912 - *wrklog << gammalib::parformat("MC background events");  
913 - *wrklog << list->size() << std::endl;  
914 - } 913 + } // endfor: looped over all events
  914 +
  915 + // Dump simulation results
  916 + if (logNormal()) {
  917 + *wrklog << gammalib::parformat("MC background events");
  918 + *wrklog << list->size() << std::endl;
  919 + }
  920 +
  921 + // Free event list
  922 + delete list;
915 923
916 - // Free event list  
917 - delete list; 924 + } // endif: we had a CTA event list
918 925
919 } // endif: model was valid 926 } // endif: model was valid
920 927
test/data/model_background_cube.xml 0 → 100644
  1 +<?xml version="1.0" standalone="no"?>
  2 +<source_library title="source library">
  3 + <source name="CTABackgroundModel" type="CTABackground" instrument="CTA">
  4 + <spectrum type="PowerLaw">
  5 + <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e+3" free="1"/>
  6 + <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/>
  7 + <parameter name="Scale" scale="1e12" value="1.0" min="0.01" max="1000.0" free="0"/>
  8 + </spectrum>
  9 + <spatialModel type="MapCubeFunction" file="data/test_cube.fits">
  10 + <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="0"/>
  11 + </spatialModel>
  12 + </source>
  13 +</source_library>
test/data/test_cube.fits 0 → 100644
No preview for this file type
test/test_ctools.sh
@@ -61,6 +61,8 @@ export PFILES=pfiles @@ -61,6 +61,8 @@ export PFILES=pfiles
61 # Test ctobssim 61 # Test ctobssim
62 # ============= 62 # =============
63 $ECHO -n "Test ctobssim: " 63 $ECHO -n "Test ctobssim: "
  64 +#
  65 +# Run 1
64 $ctobssim infile="data/crab.xml" \ 66 $ctobssim infile="data/crab.xml" \
65 outfile="events.fits" \ 67 outfile="events.fits" \
66 caldb="irf" \ 68 caldb="irf" \
@@ -80,6 +82,27 @@ else @@ -80,6 +82,27 @@ else
80 echo " events.fits file is not valid" 82 echo " events.fits file is not valid"
81 exit 1 83 exit 1
82 fi 84 fi
  85 +#
  86 +# Run 2
  87 +$ctobssim infile="data/model_background_cube.xml" \
  88 + outfile="events2.fits" \
  89 + caldb="irf" \
  90 + irf="cta_dummy_irf" \
  91 + ra=84.17263 \
  92 + dec=22.01444 \
  93 + rad=1.0 \
  94 + tmin=0.0 \
  95 + tmax=1800.0 \
  96 + emin=0.1 \
  97 + emax=100.0
  98 +$ECHO -n "."
  99 +if [ -s "events2.fits" ]
  100 +then
  101 + $ECHO -n "."
  102 +else
  103 + echo " events2.fits file is not valid"
  104 + exit 1
  105 +fi
83 $ECHO " ok" 106 $ECHO " ok"
84 107
85 108