ctools  2.0.0
 All Classes Namespaces Files Functions Variables Macros Pages
ctobssim.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * ctobssim - Observation simulator tool *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2011-2022 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file ctobssim.hpp
23  * @brief Observation simulator tool definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef CTOBSSIM_HPP
28 #define CTOBSSIM_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include "GammaLib.hpp"
32 #include "GCTALib.hpp"
33 #include "ctobservation.hpp"
34 
35 /* __Definitions _________________________________________________________ */
36 #define CTOBSSIM_NAME "ctobssim"
37 
38 
39 /***********************************************************************//**
40  * @class ctobssim
41  *
42  * @brief Observation simulator tool
43  *
44  * This class simulates CTA observation(s) using Monte Carlo sampling of the
45  * source and background models. The class supports simulation of data of
46  * multiple CTA observations in one shot. If multiple CTA observations are
47  * processed and the save method is called, events FITS files will be written
48  * for each observation.
49  ***************************************************************************/
50 class ctobssim : public ctobservation {
51 
52 public:
53  // Constructors and destructors
54  ctobssim(void);
55  explicit ctobssim(const GObservations& obs);
56  ctobssim(int argc, char *argv[]);
57  ctobssim(const ctobssim& app);
58  virtual ~ctobssim(void);
59 
60  // Operators
61  ctobssim& operator=(const ctobssim& app);
62 
63  // Methods
64  void clear(void);
65  void process(void);
66  void save(void);
67  void publish(const std::string& name = "");
68  const double& max_rate(void) const;
69  void max_rate(const double& max_rate);
70  void models(const GModels& models);
71 
72 protected:
73  // Protected methods
74  void init_members(void);
75  void copy_members(const ctobssim& app);
76  void free_members(void);
77  void get_parameters(void);
78  void simulate_source(GCTAObservation* obs,
79  const GModels& models,
80  GRan& ran,
81  GLog* wrklog = NULL);
82  void simulate_interval(GCTAObservation* obs,
83  const GCTAResponseIrf* rsp,
84  GCTAEventList* events,
85  const GModels& models,
86  const GTime& tmin,
87  const GTime& tmax,
88  const GEnergy& etrue_min,
89  const GEnergy& etrue_max,
90  const GEnergy& ereco_min,
91  const GEnergy& ereco_max,
92  const GSkyDir& dir,
93  const double& rad,
94  const double& area,
95  GRan& ran,
96  GLog* wrklog,
97  int& indent,
98  std::vector<int>& nphotons,
99  std::vector<int>& nevents);
100  void simulate_time_slice(GCTAObservation* obs,
101  const GCTAResponseIrf* rsp,
102  GCTAEventList* events,
103  const GModelSky* model,
104  const int& mc_id,
105  const GTime& tstart,
106  const GTime& tstop,
107  const GEnergy& etrue_min,
108  const GEnergy& etrue_max,
109  const GEnergy& ereco_min,
110  const GEnergy& ereco_max,
111  const GSkyDir& dir,
112  const double& rad,
113  const double& area,
114  GRan& ran,
115  GLog* wrklog,
116  int& indent,
117  int& nphotons,
118  int& nevents);
119  GEbounds get_ebounds(const GEbounds& ebounds) const;
120  double get_area(GCTAObservation* obs,
121  const GEnergy& emin,
122  const GEnergy& emax) const;
123  double get_model_flux(const GModelSky* model,
124  const GEnergy& emin,
125  const GEnergy& emax,
126  const GSkyDir& centre,
127  const double& radius,
128  const int& indent,
129  GLog* wrklog);
130  void simulate_background(GCTAObservation* obs,
131  const GModels& models,
132  GRan& ran,
133  GLog* wrklog = NULL);
134  void set_mc_id_names(GCTAObservation* obs,
135  const GModels& models,
136  GLog* wrklog = NULL);
137  void save_fits(void);
138  void save_xml(void);
139  std::string outfile(const int& index);
140 
141  // User parameters
142  std::string m_outevents; //!< Output events file
143  std::string m_prefix; //!< Prefix for multiple event lists
144  int m_startindex; //!< Start index for multiple event lists
145  int m_seed; //!< Random number generator seed
146  int m_eslices; //!< Number of energy slices
147  bool m_apply_edisp; //!< Apply energy dispersion?
148  double m_max_rate; //!< Maximum photon rate
149 
150  // Protected members
151  GModels m_models; //!< Optionally provided models
152  mutable bool m_save_and_dispose; //!< Save and dispose immediately
153  int m_max_photons; //!< Maximum number of photons/slice
154  std::vector<GRan> m_rans; //!< Random number generators
155  int m_event_id; //!< Event identifier
156 };
157 
158 
159 /***********************************************************************//**
160  * @brief Return maximum photon rate
161  *
162  * @return Reference to maximum photon rate.
163  ***************************************************************************/
164 inline
165 const double& ctobssim::max_rate(void) const
166 {
167  return (m_max_rate);
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Set maximum photon rate
173  *
174  * @param[in] max_rate Maximum photon rate.
175  ***************************************************************************/
176 inline
177 void ctobssim::max_rate(const double& max_rate)
178 {
180  return;
181 }
182 
183 
184 /***********************************************************************//**
185  * @brief Set models for simulation
186  *
187  * @param[in] models Model container.
188  *
189  * Sets the model container that should be used for simulations. If a
190  * model container exists already in the input observations the model
191  * container will be overwritten. The models will not be queried, and
192  * any model specified using the "inmodel" parameter will be ignored.
193  ***************************************************************************/
194 inline
195 void ctobssim::models(const GModels& models)
196 {
197  m_models = models;
198  return;
199 }
200 
201 #endif /* CTOBSSIM_HPP */
std::string m_outevents
Output events file.
Definition: ctobssim.hpp:142
void save(void)
Save the selected event list(s)
Definition: ctobssim.cpp:451
int m_startindex
Start index for multiple event lists.
Definition: ctobssim.hpp:144
bool m_apply_edisp
Apply energy dispersion?
Definition: ctobssim.hpp:147
virtual ~ctobssim(void)
Destructor.
Definition: ctobssim.cpp:147
void process(void)
Process the ctobssim tool.
Definition: ctobssim.cpp:235
const GObservations & obs(void) const
Return observation container.
std::string m_prefix
Prefix for multiple event lists.
Definition: ctobssim.hpp:143
void clear(void)
Clear ctobssim tool.
Definition: ctobssim.cpp:206
std::vector< GRan > m_rans
Random number generators.
Definition: ctobssim.hpp:154
double get_model_flux(const GModelSky *model, const GEnergy &emin, const GEnergy &emax, const GSkyDir &centre, const double &radius, const int &indent, GLog *wrklog)
Determine sky model flux.
Definition: ctobssim.cpp:1350
void save_fits(void)
Save event list in FITS format.
Definition: ctobssim.cpp:1692
double get_area(GCTAObservation *obs, const GEnergy &emin, const GEnergy &emax) const
Get simulation area (cm^2)
Definition: ctobssim.cpp:1303
std::string outfile(const int &index)
Return output filename.
Definition: ctobssim.cpp:1792
GEbounds get_ebounds(void)
Return energy boundaries from User parameters.
Definition: ctool.cpp:1378
GModels m_models
Optionally provided models.
Definition: ctobssim.hpp:151
Observation simulator tool.
Definition: ctobssim.hpp:50
bool m_save_and_dispose
Save and dispose immediately.
Definition: ctobssim.hpp:152
void get_parameters(void)
Get application parameters.
Definition: ctobssim.cpp:611
Observation tool base class interface definition.
int m_event_id
Event identifier.
Definition: ctobssim.hpp:155
Base class for observation tools.
void publish(const std::string &name="")
Publish event lists.
Definition: ctobssim.cpp:476
void simulate_source(GCTAObservation *obs, const GModels &models, GRan &ran, GLog *wrklog=NULL)
Simulate source events from photon list.
Definition: ctobssim.cpp:748
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< int > &nphotons, std::vector< int > &nevents)
Simulate source events for a time and energy interval.
Definition: ctobssim.cpp:969
int m_seed
Random number generator seed.
Definition: ctobssim.hpp:145
ctobssim & operator=(const ctobssim &app)
Assignment operator.
Definition: ctobssim.cpp:171
double m_max_rate
Maximum photon rate.
Definition: ctobssim.hpp:148
void copy_members(const ctobssim &app)
Copy class members.
Definition: ctobssim.cpp:569
ctobssim(void)
Void constructor.
Definition: ctobssim.cpp:74
void simulate_time_slice(GCTAObservation *obs, const GCTAResponseIrf *rsp, GCTAEventList *events, const GModelSky *model, const int &mc_id, 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)
Simulate source events for a time slice.
Definition: ctobssim.cpp:1169
void models(const GModels &models)
Set models for simulation.
Definition: ctobssim.hpp:195
int m_eslices
Number of energy slices.
Definition: ctobssim.hpp:146
const double & max_rate(void) const
Return maximum photon rate.
Definition: ctobssim.hpp:165
void simulate_background(GCTAObservation *obs, const GModels &models, GRan &ran, GLog *wrklog=NULL)
Simulate background events from model.
Definition: ctobssim.cpp:1486
void save_xml(void)
Save event list(s) in XML format.
Definition: ctobssim.cpp:1730
int m_max_photons
Maximum number of photons/slice.
Definition: ctobssim.hpp:153
void free_members(void)
Delete class members.
Definition: ctobssim.cpp:595
void set_mc_id_names(GCTAObservation *obs, const GModels &models, GLog *wrklog=NULL)
Set correspondance between Monte Carlo identifier and model names.
Definition: ctobssim.cpp:1611
void init_members(void)
Initialise class members.
Definition: ctobssim.cpp:537