Commit f49abdad5afd783b599f690218fb0df8b452bc5f

Authored by knodlseder
1 parent 1f9bd74e

upgrade to new GammaLib interface

src/ctbin/ctbin.cpp
@@ -227,19 +227,21 @@ void ctbin::bin(void) @@ -227,19 +227,21 @@ void ctbin::bin(void)
227 log << num_outside_ebds << std::endl; 227 log << num_outside_ebds << std::endl;
228 } 228 }
229 229
230 - // Log observation 230 + // Log map
231 if (logTerse()) { 231 if (logTerse()) {
232 log << std::endl; 232 log << std::endl;
233 log.header1("Counts map"); 233 log.header1("Counts map");
234 log << map << std::endl; 234 log << map << std::endl;
235 } 235 }
236 -  
237 - // Save counts map  
238 - GFits file;  
239 - map.write(&file);  
240 - obs.ebounds().write(&file);  
241 - obs.gti().write(&file);  
242 - file.saveto(m_outfile, clobber()); 236 +
  237 + // Create events cube from sky map
  238 + GCTAEventCube cube(map);
  239 +
  240 + // Replace event list by event cube in observation
  241 + obs.events(&cube);
  242 +
  243 + // Save observation
  244 + obs.save(m_outfile, clobber());
243 245
244 // Return 246 // Return
245 return; 247 return;
src/ctlike/ctlike.cpp
@@ -104,6 +104,7 @@ ctlike::~ctlike(void) @@ -104,6 +104,7 @@ ctlike::~ctlike(void)
104 ***************************************************************************/ 104 ***************************************************************************/
105 void ctlike::run(void) 105 void ctlike::run(void)
106 { 106 {
  107 + log.cout(true);
107 // Get parameters 108 // Get parameters
108 get_parameters(); 109 get_parameters();
109 110
@@ -119,6 +120,13 @@ void ctlike::run(void) @@ -119,6 +120,13 @@ void ctlike::run(void)
119 else 120 else
120 binned(m_cntmap); 121 binned(m_cntmap);
121 122
  123 + // Write observation into logger
  124 + if (logTerse()) {
  125 + log << std::endl;
  126 + log.header1("Observation");
  127 + log << m_obs << std::endl;
  128 + }
  129 +
122 // Setup models for optimizing. 130 // Setup models for optimizing.
123 m_models = GModels(m_srcmdl); 131 m_models = GModels(m_srcmdl);
124 m_obs.models(m_models); 132 m_obs.models(m_models);
@@ -265,7 +273,7 @@ void ctlike::unbinned(const std::string&amp; evfile) @@ -265,7 +273,7 @@ void ctlike::unbinned(const std::string&amp; evfile)
265 // for analysis 273 // for analysis
266 run.load_unbinned(evfile); 274 run.load_unbinned(evfile);
267 run.response(m_irf, m_caldb); 275 run.response(m_irf, m_caldb);
268 - run.roi(roi); 276 + run.roi(&roi);
269 run.ebounds(ebds); 277 run.ebounds(ebds);
270 m_obs.append(run); 278 m_obs.append(run);
271 279
src/ctobssim/ctobssim.cpp
@@ -108,6 +108,9 @@ void ctobssim::run(void) @@ -108,6 +108,9 @@ void ctobssim::run(void)
108 if (logTerse()) { 108 if (logTerse()) {
109 log_parameters(); 109 log_parameters();
110 log << std::endl; 110 log << std::endl;
  111 + log << m_pnt << std::endl;
  112 + log << m_obs << std::endl;
  113 + log << m_models << std::endl;
111 } 114 }
112 115
113 // Write header 116 // Write header
@@ -174,6 +177,36 @@ void ctobssim::get_parameters(void) @@ -174,6 +177,36 @@ void ctobssim::get_parameters(void)
174 // Initialise random number generator 177 // Initialise random number generator
175 m_ran.seed(m_seed); 178 m_ran.seed(m_seed);
176 179
  180 + // Set CTA pointing
  181 + GSkyDir dir;
  182 + dir.radec_deg(m_ra, m_dec);
  183 + m_pnt.dir(dir);
  184 +
  185 + // Set GTI
  186 + GGti gti;
  187 + GTime tstart;
  188 + GTime tstop;
  189 + tstart.met(m_tmin);
  190 + tstop.met(m_tmax);
  191 + gti.append(tstart, tstop);
  192 +
  193 + // Set energy boundaries
  194 + GEbounds ebds;
  195 + GEnergy emin;
  196 + GEnergy emax;
  197 + emin.TeV(m_emin);
  198 + emax.TeV(m_emax);
  199 + ebds.append(emin, emax);
  200 +
  201 + // Set observation
  202 + m_obs.ebounds(ebds);
  203 + m_obs.gti(gti);
  204 + m_obs.response(m_irf, m_caldb);
  205 + m_obs.pointing(m_pnt);
  206 +
  207 + // Load models
  208 + m_models.load(m_infile);
  209 +
177 // Return 210 // Return
178 return; 211 return;
179 } 212 }
@@ -198,17 +231,14 @@ GPhotons ctobssim::simulate_photons(void) @@ -198,17 +231,14 @@ GPhotons ctobssim::simulate_photons(void)
198 tmin.met(m_tmin); 231 tmin.met(m_tmin);
199 tmax.met(m_tmax); 232 tmax.met(m_tmax);
200 233
201 - // Load models  
202 - GModels models(m_infile);  
203 -  
204 // Allocate photons 234 // Allocate photons
205 GPhotons photons; 235 GPhotons photons;
206 236
207 // Simulate photons for all sky models 237 // Simulate photons for all sky models
208 - for (int i = 0; i < models.size(); ++i) { 238 + for (int i = 0; i < m_models.size(); ++i) {
209 239
210 // Get sky model (NULL if not a sky model) 240 // Get sky model (NULL if not a sky model)
211 - GModelSky* model = dynamic_cast<GModelSky*>(models(i)); 241 + GModelSky* model = dynamic_cast<GModelSky*>(m_models(i));
212 242
213 // If we have a sky model then simulate photons 243 // If we have a sky model then simulate photons
214 if (model != NULL) { 244 if (model != NULL) {
@@ -260,21 +290,15 @@ GPhotons ctobssim::simulate_photons(void) @@ -260,21 +290,15 @@ GPhotons ctobssim::simulate_photons(void)
260 ***************************************************************************/ 290 ***************************************************************************/
261 GCTAEventList* ctobssim::simulate_events(const GPhotons& photons) 291 GCTAEventList* ctobssim::simulate_events(const GPhotons& photons)
262 { 292 {
263 - // Setup CTA response  
264 - GCTAResponse rsp(m_irf, m_caldb);  
265 -  
266 - // Setup CTA pointing  
267 - GCTAPointing pnt;  
268 -  
269 // Allocate CTA event list 293 // Allocate CTA event list
270 GCTAEventList* events = new GCTAEventList; 294 GCTAEventList* events = new GCTAEventList;
271 295
272 // Reserves space for events 296 // Reserves space for events
273 events->reserve(photons.size()); 297 events->reserve(photons.size());
274 298
275 - // Simulate events 299 + // Simulate events from photons
276 for (int i = 0; i < photons.size(); ++i) { 300 for (int i = 0; i < photons.size(); ++i) {
277 - GCTAEventAtom* event = rsp.mc(m_area, photons[i], pnt, m_ran); 301 + GCTAEventAtom* event = m_obs.response()->mc(m_area, photons[i], m_pnt, m_ran);
278 if (event != NULL) 302 if (event != NULL)
279 events->append(*event); 303 events->append(*event);
280 delete event; 304 delete event;
@@ -282,9 +306,43 @@ GCTAEventList* ctobssim::simulate_events(const GPhotons&amp; photons) @@ -282,9 +306,43 @@ GCTAEventList* ctobssim::simulate_events(const GPhotons&amp; photons)
282 306
283 // Dump simulation results 307 // Dump simulation results
284 if (logNormal()) { 308 if (logNormal()) {
285 - log << parformat("Simulated events") << str(events->size()) << std::endl; 309 + log << parformat("MC source events");
  310 + log << str(events->size()) << std::endl;
286 } 311 }
287 312
  313 + // Simulate background events
  314 + for (int i = 0; i < m_models.size(); ++i) {
  315 +
  316 + // Get model (NULL if not a radial acceptance model)
  317 + GCTAModelRadialAcceptance* model =
  318 + dynamic_cast<GCTAModelRadialAcceptance*>(m_models(i));
  319 +
  320 + // If we have a radial acceptance model then simulate events
  321 + if (model != NULL) {
  322 +
  323 + // Get simulated event list
  324 + GCTAEventList* list = model->mc(m_obs, m_ran);
  325 +
  326 + // Reserves space for events
  327 + events->reserve(list->size()+events->size());
  328 +
  329 + // Append events
  330 + for (int k = 0; k < list->size(); k++)
  331 + events->append(*(list->pointer(k)));
  332 +
  333 + // Dump simulation results
  334 + if (logNormal()) {
  335 + log << parformat("MC background events");
  336 + log << str(list->size()) << std::endl;
  337 + }
  338 +
  339 + // Free event list
  340 + delete list;
  341 +
  342 + } // endif: model was valid
  343 +
  344 + } // endfor: looped over all models
  345 +
288 // Return event list 346 // Return event list
289 return events; 347 return events;
290 } 348 }
@@ -353,9 +411,13 @@ void ctobssim::set_events_keywords(GFits* file) @@ -353,9 +411,13 @@ void ctobssim::set_events_keywords(GFits* file)
353 hdu->card("ONTIME", m_tmax-m_tmin, "[s] Total good time including deadtime"); 411 hdu->card("ONTIME", m_tmax-m_tmin, "[s] Total good time including deadtime");
354 hdu->card("LIVETIME", m_tmax-m_tmin, "[s] Total livetime"); 412 hdu->card("LIVETIME", m_tmax-m_tmin, "[s] Total livetime");
355 413
  414 + // Set target information
  415 + //hdu->card("RA_OBJ", m_ra, "[deg] Target Right Ascension");
  416 + //hdu->card("DEC_OBJ", m_dec, "[deg] Target Declination");
  417 +
356 // Set pointing information 418 // Set pointing information
357 - hdu->card("RA_OBJ", m_ra, "[deg] Target Right Ascension");  
358 - hdu->card("DEC_OBJ", m_dec, "[deg] Target Declination"); 419 + hdu->card("RA_PNT", m_ra, "[deg] Pointing Right Ascension");
  420 + hdu->card("DEC_PNT", m_dec, "[deg] Pointing Declination");
359 421
360 // Return 422 // Return
361 return; 423 return;
@@ -378,6 +440,8 @@ void ctobssim::init_members(void) @@ -378,6 +440,8 @@ void ctobssim::init_members(void)
378 m_outfile.clear(); 440 m_outfile.clear();
379 m_caldb.clear(); 441 m_caldb.clear();
380 m_irf.clear(); 442 m_irf.clear();
  443 + m_obs.clear();
  444 + m_pnt.clear();
381 m_seed = 1; 445 m_seed = 1;
382 m_ra = 0.0; 446 m_ra = 0.0;
383 m_dec = 0.0; 447 m_dec = 0.0;
src/ctobssim/ctobssim.hpp
@@ -54,20 +54,23 @@ protected: @@ -54,20 +54,23 @@ protected:
54 void free_members(void); 54 void free_members(void);
55 55
56 // User parameters 56 // User parameters
57 - std::string m_infile; //!< Input model  
58 - std::string m_outfile; //!< Output events file  
59 - std::string m_caldb; //!< Calibration database repository  
60 - std::string m_irf; //!< Instrument response function  
61 - int m_seed; //!< Random number generator seed  
62 - double m_ra; //!< RA of ROI centre  
63 - double m_dec; //!< DEC of ROI centre  
64 - double m_rad; //!< ROI radius  
65 - double m_tmin; //!< Start time (MET)  
66 - double m_tmax; //!< Stop time (MET)  
67 - double m_emin; //!< Lower energy (TeV)  
68 - double m_emax; //!< Upper energy (TeV)  
69 - double m_area; //!< Surface area for simulation (cm2)  
70 - GRan m_ran; //!< Random number generator 57 + std::string m_infile; //!< Input model
  58 + std::string m_outfile; //!< Output events file
  59 + std::string m_caldb; //!< Calibration database repository
  60 + std::string m_irf; //!< Instrument response function
  61 + int m_seed; //!< Random number generator seed
  62 + double m_ra; //!< RA of pointing direction
  63 + double m_dec; //!< DEC of pointing direction
  64 + double m_rad; //!< FOV radius
  65 + double m_tmin; //!< Start time (MET)
  66 + double m_tmax; //!< Stop time (MET)
  67 + double m_emin; //!< Lower energy (TeV)
  68 + double m_emax; //!< Upper energy (TeV)
  69 + double m_area; //!< Surface area for simulation (cm2)
  70 + GRan m_ran; //!< Random number generator
  71 + GCTAPointing m_pnt; //!< CTA pointing
  72 + GCTAObservation m_obs; //!< CTA observation
  73 + GModels m_models; //!< Models
71 }; 74 };
72 75
73 #endif /* CTOBSSIM_HPP */ 76 #endif /* CTOBSSIM_HPP */