Commit 5367f5174312c6e2ab13ea204d934123f560f2b4

Authored by Jürgen Knödlseder
2 parents 0cb347f7 42aae297

Merge branch '1371-adapt-ctools-for-new-binned-interface' into integration

Conflicts:
	ChangeLog
	NEWS
	src/ctbkgcube/ctbkgcube.cpp
	test/test_ctools.sh
ChangeLog
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 Add ctulimit tool (#1363) 11 Add ctulimit tool (#1363)
12 Allow ctmodel usage for stacked analysis from command line 12 Allow ctmodel usage for stacked analysis from command line
13 Correct rate check in ctobssim for map cubes (#1452) 13 Correct rate check in ctobssim for map cubes (#1452)
  14 + Handle background cubes for stacked analysis (#1371)
14 15
15 16
16 2015-01-08 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> 17 2015-01-08 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
@@ -2,7 +2,7 @@ New Features and Important Changes in ctools 1.0.0 @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 1.0.0
2 2
3 Author(s) : Juergen Knoedlseder 3 Author(s) : Juergen Knoedlseder
4 4
5 -23 March 2015 5 +28 March 2015
6 6
7 7
8 1. Introduction 8 1. Introduction
@@ -50,12 +50,14 @@ None @@ -50,12 +50,14 @@ None
50 50
51 8. ctlike - Maximum likelihood fitting 51 8. ctlike - Maximum likelihood fitting
52 -------------------------------------- 52 --------------------------------------
53 -None 53 +The bkgcube parameter has been added to allow specification of a background
  54 +cube for stacked analysis.
54 55
55 56
56 9. cttsmap - Generation of Test Statistics map 57 9. cttsmap - Generation of Test Statistics map
57 ---------------------------------------------- 58 ----------------------------------------------
58 -None 59 +The bkgcube parameter has been added to allow specification of a background
  60 +cube for stacked analysis.
59 61
60 62
61 10. ctskymap - CTA sky mapping 63 10. ctskymap - CTA sky mapping
@@ -71,6 +73,9 @@ the original IRF information. This makes generation of model cubes substantially @@ -71,6 +73,9 @@ the original IRF information. This makes generation of model cubes substantially
71 faster. The old method of accessing the IRF response for model computation is 73 faster. The old method of accessing the IRF response for model computation is
72 still possible. 74 still possible.
73 75
  76 +The bkgcube parameter has been added to allow specification of a background
  77 +cube for stacked analysis.
  78 +
74 79
75 12. ctexpcube - CTA exposure cube generation 80 12. ctexpcube - CTA exposure cube generation
76 -------------------------------------------- 81 --------------------------------------------
@@ -94,13 +99,17 @@ None @@ -94,13 +99,17 @@ None
94 99
95 16. ctbutterfly - Generate butterfly diagrams 100 16. ctbutterfly - Generate butterfly diagrams
96 --------------------------------------------- 101 ---------------------------------------------
97 -None 102 +The bkgcube parameter has been added to allow specification of a background
  103 +cube for stacked analysis.
98 104
99 105
100 17. ctulimit - Compute upper limit 106 17. ctulimit - Compute upper limit
101 ---------------------------------- 107 ----------------------------------
102 Added an initial version of the upper limit computation tool. 108 Added an initial version of the upper limit computation tool.
103 109
  110 +The bkgcube parameter has been added to allow specification of a background
  111 +cube for stacked analysis.
  112 +
104 113
105 18. Examples 114 18. Examples
106 ------------ 115 ------------
doc/source/reference_manual/cspull.rst
@@ -26,9 +26,15 @@ General parameters @@ -26,9 +26,15 @@ General parameters
26 ``outfile [file]`` 26 ``outfile [file]``
27 ASCII file containing the individual pull values. 27 ASCII file containing the individual pull values.
28 28
29 -``ntrials [integer]``  
30 - Number of samples for generating the pull distribution.  
31 - 29 +``expcube [file]``
  30 + Exposure cube file (only needed for stacked analysis).
  31 +
  32 +``psfcube [file]``
  33 + PSF cube file (only needed for stacked analysis).
  34 +
  35 +``bkgcube [file]``
  36 + Background cube file (only needed for stacked analysis).
  37 +
32 ``caldb [string]`` 38 ``caldb [string]``
33 Calibration database. 39 Calibration database.
34 40
@@ -38,6 +44,9 @@ General parameters @@ -38,6 +44,9 @@ General parameters
38 ``(edisp = no) [boolean]`` 44 ``(edisp = no) [boolean]``
39 Apply energy dispersion to response computation. 45 Apply energy dispersion to response computation.
40 46
  47 +``ntrials [integer]``
  48 + Number of samples for generating the pull distribution.
  49 +
41 ``ra [real]`` 50 ``ra [real]``
42 Right Ascension of CTA pointing (J2000, in degrees). 51 Right Ascension of CTA pointing (J2000, in degrees).
43 52
doc/source/reference_manual/ctbutterfly.rst
@@ -25,12 +25,15 @@ General parameters @@ -25,12 +25,15 @@ General parameters
25 ``srcname [string]`` 25 ``srcname [string]``
26 Name of model component for which butterfly should be computed. 26 Name of model component for which butterfly should be computed.
27 27
28 -``expcube = NONE [file]`` 28 +``expcube [file]``
29 Exposure cube file (only needed for stacked analysis). 29 Exposure cube file (only needed for stacked analysis).
30 30
31 -``psfcube = NONE [file]`` 31 +``psfcube [file]``
32 PSF cube file (only needed for stacked analysis). 32 PSF cube file (only needed for stacked analysis).
33 33
  34 +``bkgcube [file]``
  35 + Background cube file (only needed for stacked analysis).
  36 +
34 ``caldb [string]`` 37 ``caldb [string]``
35 Calibration database. 38 Calibration database.
36 39
doc/source/reference_manual/ctlike.rst
@@ -34,6 +34,9 @@ General parameters @@ -34,6 +34,9 @@ General parameters
34 ``psfcube [file]`` 34 ``psfcube [file]``
35 PSF cube file (only needed for stacked analysis). 35 PSF cube file (only needed for stacked analysis).
36 36
  37 +``bkgcube [file]``
  38 + Background cube file (only needed for stacked analysis).
  39 +
37 ``caldb [string]`` 40 ``caldb [string]``
38 Calibration database. 41 Calibration database.
39 42
doc/source/reference_manual/ctmodel.rst
@@ -43,6 +43,9 @@ General parameters @@ -43,6 +43,9 @@ General parameters
43 ``psfcube [file]`` 43 ``psfcube [file]``
44 PSF cube file (only needed for stacked analysis). 44 PSF cube file (only needed for stacked analysis).
45 45
  46 +``bkgcube [file]``
  47 + Background cube file (only needed for stacked analysis).
  48 +
46 ``caldb [string]`` 49 ``caldb [string]``
47 Calibration database. 50 Calibration database.
48 51
doc/source/reference_manual/cttsmap.rst
@@ -31,6 +31,9 @@ General parameters @@ -31,6 +31,9 @@ General parameters
31 ``psfcube [file]`` 31 ``psfcube [file]``
32 PSF cube file (only needed for stacked analysis). 32 PSF cube file (only needed for stacked analysis).
33 33
  34 +``bkgcube [file]``
  35 + Background cube file (only needed for stacked analysis).
  36 +
34 ``caldb [string]`` 37 ``caldb [string]``
35 Calibration database. 38 Calibration database.
36 39
doc/source/reference_manual/ctulimit.rst
@@ -24,12 +24,15 @@ General parameters @@ -24,12 +24,15 @@ General parameters
24 ``srcname [string]`` 24 ``srcname [string]``
25 Name of model component for which upper limit should be computed. 25 Name of model component for which upper limit should be computed.
26 26
27 -``expcube = NONE [file]`` 27 +``expcube [file]``
28 Exposure cube file (only needed for stacked analysis). 28 Exposure cube file (only needed for stacked analysis).
29 29
30 -``psfcube = NONE [file]`` 30 +``psfcube [file]``
31 PSF cube file (only needed for stacked analysis). 31 PSF cube file (only needed for stacked analysis).
32 32
  33 +``bkgcube [file]``
  34 + Background cube file (only needed for stacked analysis).
  35 +
33 ``caldb [string]`` 36 ``caldb [string]``
34 Calibration database. 37 Calibration database.
35 38
pyext/ctbkgcube.i
1 /*************************************************************************** 1 /***************************************************************************
2 * ctbkgcube - Background cube generation tool * 2 * ctbkgcube - Background cube generation tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2014 by Chia-Chun Lu * 4 + * copyright (C) 2014-2015 by Chia-Chun Lu *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -44,11 +44,11 @@ public: @@ -44,11 +44,11 @@ public:
44 virtual ~ctbkgcube(void); 44 virtual ~ctbkgcube(void);
45 45
46 // Methods 46 // Methods
47 - void clear(void);  
48 - void run(void);  
49 - void save(void);  
50 - const GCTAEventCube& cube(void) const;  
51 - const GModels& models(void) const; 47 + void clear(void);
  48 + void run(void);
  49 + void save(void);
  50 + const GCTACubeBackground& cube(void) const;
  51 + const GModels& models(void) const;
52 }; 52 };
53 53
54 /***********************************************************************//** 54 /***********************************************************************//**
scripts/cspull.py
@@ -98,8 +98,11 @@ class cspull(ctools.cscript): @@ -98,8 +98,11 @@ class cspull(ctools.cscript):
98 pars.append(gammalib.GApplicationPar("outfile","f","a","pull.dat","","","Output file name")) 98 pars.append(gammalib.GApplicationPar("outfile","f","a","pull.dat","","","Output file name"))
99 pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Exposure cube file (only needed for stacked analysis)")) 99 pars.append(gammalib.GApplicationPar("expcube","s","a","NONE","","","Exposure cube file (only needed for stacked analysis)"))
100 pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","PSF cube file (only needed for stacked analysis)")) 100 pars.append(gammalib.GApplicationPar("psfcube","s","a","NONE","","","PSF cube file (only needed for stacked analysis)"))
  101 + pars.append(gammalib.GApplicationPar("bkgcube","s","a","NONE","","","Background cube file (only needed for stacked analysis)"))
101 pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database")) 102 pars.append(gammalib.GApplicationPar("caldb","s","a","dummy","","","Calibration database"))
102 pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function")) 103 pars.append(gammalib.GApplicationPar("irf","s","a","cta_dummy_irf","","","Instrument response function"))
  104 + pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?"))
  105 + pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials"))
103 pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)")) 106 pars.append(gammalib.GApplicationPar("ra","r","a","83.6331","0","360","RA of pointing (deg)"))
104 pars.append(gammalib.GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)")) 107 pars.append(gammalib.GApplicationPar("dec","r","a","22.0145","-90","90","Dec of pointing (deg)"))
105 pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit (TeV)")) 108 pars.append(gammalib.GApplicationPar("emin","r","a","0.1","","","Lower energy limit (TeV)"))
@@ -107,14 +110,12 @@ class cspull(ctools.cscript): @@ -107,14 +110,12 @@ class cspull(ctools.cscript):
107 pars.append(gammalib.GApplicationPar("tmin","r","h","0.0","","","Start time (MET in s)")) 110 pars.append(gammalib.GApplicationPar("tmin","r","h","0.0","","","Start time (MET in s)"))
108 pars.append(gammalib.GApplicationPar("tmax","r","a","1800.0","","","Duration (in s)")) 111 pars.append(gammalib.GApplicationPar("tmax","r","a","1800.0","","","Duration (in s)"))
109 pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins (0=unbinned)")) 112 pars.append(gammalib.GApplicationPar("enumbins","i","a","0","","","Number of energy bins (0=unbinned)"))
110 - pars.append(gammalib.GApplicationPar("npix","i","h","200","","","Number of pixels for binned"))  
111 - pars.append(gammalib.GApplicationPar("binsz","r","h","0.05","","","Pixel size for binned (deg/pixel)")) 113 + pars.append(gammalib.GApplicationPar("npix","i","a","200","","","Number of pixels for binned"))
  114 + pars.append(gammalib.GApplicationPar("binsz","r","a","0.05","","","Pixel size for binned (deg/pixel)"))
112 pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","0","1","Deadtime correction factor")) 115 pars.append(gammalib.GApplicationPar("deadc","r","h","0.95","0","1","Deadtime correction factor"))
113 pars.append(gammalib.GApplicationPar("rad","r","h","5.0","0","180","Radius of ROI (deg)")) 116 pars.append(gammalib.GApplicationPar("rad","r","h","5.0","0","180","Radius of ROI (deg)"))
114 pars.append(gammalib.GApplicationPar("pattern","s","h","single","","","Observation pattern (single/four)")) 117 pars.append(gammalib.GApplicationPar("pattern","s","h","single","","","Observation pattern (single/four)"))
115 pars.append(gammalib.GApplicationPar("offset","r","h","1.5","","","Observation pattern offset (deg)")) 118 pars.append(gammalib.GApplicationPar("offset","r","h","1.5","","","Observation pattern offset (deg)"))
116 - pars.append(gammalib.GApplicationPar("ntrials","i","a","10","","","Number of trials"))  
117 - pars.append(gammalib.GApplicationPar("edisp","b","h","no","","","Apply energy dispersion?"))  
118 pars.append_standard() 119 pars.append_standard()
119 pars.append(gammalib.GApplicationPar("logfile","f","h","cspull.log","","","Log filename")) 120 pars.append(gammalib.GApplicationPar("logfile","f","h","cspull.log","","","Log filename"))
120 pars.save(parfile) 121 pars.save(parfile)
@@ -140,7 +141,7 @@ class cspull(ctools.cscript): @@ -140,7 +141,7 @@ class cspull(ctools.cscript):
140 141
141 # Get number of energy bins 142 # Get number of energy bins
142 self.m_enumbins = self["enumbins"].integer() 143 self.m_enumbins = self["enumbins"].integer()
143 - 144 +
144 # Read parameters for binned if requested 145 # Read parameters for binned if requested
145 if not self.m_enumbins == 0: 146 if not self.m_enumbins == 0:
146 self.m_npix = self["npix"].integer() 147 self.m_npix = self["npix"].integer()
src/ctbkgcube/ctbkgcube.cpp
@@ -34,7 +34,6 @@ @@ -34,7 +34,6 @@
34 34
35 /* __ Method name definitions ____________________________________________ */ 35 /* __ Method name definitions ____________________________________________ */
36 #define G_GET_PARAMETERS "ctbkgcube::get_parameters()" 36 #define G_GET_PARAMETERS "ctbkgcube::get_parameters()"
37 -#define G_FILL_CUBE "ctbkgcube::fill_cube(GCTAObservation*)"  
38 37
39 /* __ Debug definitions __________________________________________________ */ 38 /* __ Debug definitions __________________________________________________ */
40 39
@@ -209,9 +208,6 @@ void ctbkgcube::run(void) @@ -209,9 +208,6 @@ void ctbkgcube::run(void)
209 log.cout(true); 208 log.cout(true);
210 } 209 }
211 210
212 - // Initialise run parameters  
213 - m_livetime = 0.0;  
214 -  
215 // Get task parameters 211 // Get task parameters
216 get_parameters(); 212 get_parameters();
217 213
@@ -248,15 +244,14 @@ void ctbkgcube::run(void) @@ -248,15 +244,14 @@ void ctbkgcube::run(void)
248 244
249 // Copy models from observation container and reset output model 245 // Copy models from observation container and reset output model
250 // container 246 // container
251 - m_bkgmdl = m_obs.models(); 247 + GModels models_orig = m_obs.models();
  248 + m_bkgmdl = m_obs.models();
252 m_outmdl.clear(); 249 m_outmdl.clear();
253 - m_cube_model = -1;  
254 250
255 // Remove all models that are not CTA background models from the 251 // Remove all models that are not CTA background models from the
256 // container and put all removed components in the output 252 // container and put all removed components in the output
257 // container 253 // container
258 int num = m_bkgmdl.size(); 254 int num = m_bkgmdl.size();
259 -  
260 for (int i = num-1; i >= 0; --i) { 255 for (int i = num-1; i >= 0; --i) {
261 256
262 // Flag removal 257 // Flag removal
@@ -309,75 +304,28 @@ void ctbkgcube::run(void) @@ -309,75 +304,28 @@ void ctbkgcube::run(void)
309 log.header1("Generate background cube"); 304 log.header1("Generate background cube");
310 } 305 }
311 306
312 - // Initialise observation counter  
313 - int n_observations = 0;  
314 -  
315 - // Loop over all observations in the container  
316 - for (int i = 0; i < m_obs.size(); ++i) {  
317 -  
318 - // Get CTA observation  
319 - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);  
320 -  
321 - // Continue only if observation is a CTA observation  
322 - if (obs != NULL) {  
323 -  
324 - // Write header for observation  
325 - if (logTerse()) {  
326 - if (obs->name().length() > 1) {  
327 - log.header3("Observation "+obs->name());  
328 - }  
329 - else {  
330 - log.header3("Observation "+gammalib::str(i));  
331 - }  
332 - }  
333 -  
334 - // Increment number of observations  
335 - n_observations++;  
336 -  
337 - // Fill the cube  
338 - fill_cube(obs);  
339 -  
340 - } // endif: CTA observation found 307 + // Assign background models to container
  308 + m_obs.models(m_bkgmdl);
341 309
342 - } // endfor: looped over observations 310 + // Fill background cube from observations
  311 + m_background.fill(m_obs);
343 312
344 - // Log results  
345 - if (logTerse()) {  
346 - log << gammalib::parformat("Accumulated livetime");  
347 - log << m_livetime << " sec" << std::endl;  
348 - } 313 + // Create a background model for the output background cube and append
  314 + // that model to the input model in place of the original
  315 + // background models
  316 + // TODO: We might think of creating the spectral model via user parameter
  317 + GModelSpectralPlaw spectral(1.0, 0.0, GEnergy(1.0, "TeV"));
  318 + GCTAModelCubeBackground model(spectral);
349 319
350 - // Re-normalize cube to get units of counts/MeV/s/sr  
351 - if (m_livetime > 0.0) {  
352 -  
353 - // Loop over all bins in background cube and divide the content  
354 - // by the total livetime.  
355 - for (int i = 0; i < m_bkgcube.size(); ++i) {  
356 - GCTAEventBin* bin = m_bkgcube[i];  
357 - double rate = bin->counts() / m_livetime;  
358 - bin->counts(rate);  
359 - } 320 + // Set model name
  321 + model.name("BackgroundModel");
360 322
361 - } // endif: livetime was positive 323 + // Set model instrument
  324 + // TODO: Account for possibility to have observations from different
  325 + // IACTs in the same container
  326 + model.instruments("CTA,HESS,MAGIC,VERITAS");
362 327
363 - // Log results  
364 - if (logTerse()) {  
365 - log << gammalib::parformat("Number of observations");  
366 - log << n_observations << std::endl;  
367 - }  
368 -  
369 - // Create a background model for output background cube and append  
370 - // that model to the input model in place of the original  
371 - // background model  
372 - GEnergies energies;  
373 - for (int i = 0; i < m_bkgcube.ebins(); ++i) {  
374 - energies.append(m_bkgcube.energy(i));  
375 - }  
376 - GModelSpatialDiffuseCube spatial(m_bkgcube.map(), energies, 1.0);  
377 - GModelSpectralPlaw spectral(1.0, 0.0, GEnergy(1.0, "TeV"));  
378 - GCTAModelCubeBackground model(spatial, spectral);  
379 - model.name("ctbkgcube default background model");  
380 - m_cube_model = m_outmdl.size(); // Store the slot number for save() 328 + // Append model to output container
381 m_outmdl.append(model); 329 m_outmdl.append(model);
382 330
383 // Log output model 331 // Log output model
@@ -387,6 +335,9 @@ void ctbkgcube::run(void) @@ -387,6 +335,9 @@ void ctbkgcube::run(void)
387 log << m_outmdl << std::endl; 335 log << m_outmdl << std::endl;
388 } 336 }
389 337
  338 + // Recover original models
  339 + m_obs.models(models_orig);
  340 +
390 // Return 341 // Return
391 return; 342 return;
392 } 343 }
@@ -405,47 +356,19 @@ void ctbkgcube::save(void) @@ -405,47 +356,19 @@ void ctbkgcube::save(void)
405 log.header1("Save background cube"); 356 log.header1("Save background cube");
406 } 357 }
407 358
408 - // Create energies container from energy boundaries  
409 - GEnergies energies;  
410 - for (int i = 0; i < m_ebounds.size(); ++i) {  
411 - energies.append(m_ebounds.elogmean(i));  
412 - }  
413 -  
414 // Get output filenames 359 // Get output filenames
415 std::string outfile = (*this)["outcube"].filename(); 360 std::string outfile = (*this)["outcube"].filename();
416 std::string outmodel = (*this)["outmodel"].filename(); 361 std::string outmodel = (*this)["outmodel"].filename();
417 362
418 - // Create empty FITS file  
419 - GFits fits;  
420 -  
421 - // Write background cube  
422 - m_bkgcube.map().write(fits);  
423 -  
424 - // Write energies  
425 - energies.write(fits);  
426 -  
427 - // Save FITS file  
428 - fits.saveto(outfile, clobber()); 363 + // Save background cube
  364 + m_background.save(outfile, clobber());
429 365
430 // Write output models if filename is valid 366 // Write output models if filename is valid
431 if ((outmodel.length() > 0) && (gammalib::tolower(outmodel) != "none")) { 367 if ((outmodel.length() > 0) && (gammalib::tolower(outmodel) != "none")) {
432 368
433 - // Set filename of map cube.  
434 - if (m_cube_model >= 0) {  
435 - GCTAModelCubeBackground* model =  
436 - dynamic_cast<GCTAModelCubeBackground*>(m_outmdl[m_cube_model]);  
437 - if (model != NULL) {  
438 - GModelSpatialDiffuseCube* spatial =  
439 - dynamic_cast<GModelSpatialDiffuseCube*>(model->spatial());  
440 - if (spatial != NULL) {  
441 - spatial->filename(outfile);  
442 - }  
443 - }  
444 - }  
445 -  
446 - // Save output model container 369 + // Save output model for binned analyses
447 m_outmdl.save(outmodel); 370 m_outmdl.save(outmodel);
448 - 371 +
449 } 372 }
450 373
451 // Return 374 // Return
@@ -468,12 +391,9 @@ void ctbkgcube::init_members(void) @@ -468,12 +391,9 @@ void ctbkgcube::init_members(void)
468 m_outcube.clear(); 391 m_outcube.clear();
469 m_outmodel.clear(); 392 m_outmodel.clear();
470 m_obs.clear(); 393 m_obs.clear();
471 - m_bkgcube.clear(); 394 + m_background.clear();
472 m_bkgmdl.clear(); 395 m_bkgmdl.clear();
473 m_outmdl.clear(); 396 m_outmdl.clear();
474 - m_ebounds.clear();  
475 - m_livetime = 0.0;  
476 - m_cube_model = -1;  
477 397
478 // Return 398 // Return
479 return; 399 return;
@@ -491,12 +411,9 @@ void ctbkgcube::copy_members(const ctbkgcube&amp; app) @@ -491,12 +411,9 @@ void ctbkgcube::copy_members(const ctbkgcube&amp; app)
491 m_outmodel = app.m_outmodel; 411 m_outmodel = app.m_outmodel;
492 m_outcube = app.m_outcube; 412 m_outcube = app.m_outcube;
493 m_obs = app.m_obs; 413 m_obs = app.m_obs;
494 - m_bkgcube = app.m_bkgcube; 414 + m_background = app.m_background;
495 m_bkgmdl = app.m_bkgmdl; 415 m_bkgmdl = app.m_bkgmdl;
496 m_outmdl = app.m_outmdl; 416 m_outmdl = app.m_outmdl;
497 - m_ebounds = app.m_ebounds;  
498 - m_livetime = app.m_livetime;  
499 - m_cube_model = app.m_cube_model;  
500 417
501 // Return 418 // Return
502 return; 419 return;
@@ -536,22 +453,6 @@ void ctbkgcube::get_parameters(void) @@ -536,22 +453,6 @@ void ctbkgcube::get_parameters(void)
536 453
537 } // endif: there was no observation in the container 454 } // endif: there was no observation in the container
538 455
539 -  
540 - // If there are no models associated with the observations then load now  
541 - // the model definition from the XML file  
542 - if (m_obs.models().size() == 0) {  
543 - if ((*this)["inmodel"].is_undefined()) {  
544 - std::string msg = "No model definition XML file specified. "  
545 - "Please set the \"inmodel\" parameter to the "  
546 - "XML file that contains the background model "  
547 - "definition.";  
548 - throw GException::invalid_value(G_GET_PARAMETERS, msg);  
549 - }  
550 - std::string inmodel = (*this)["inmodel"].filename();  
551 - GModels models(inmodel);  
552 - m_obs.models(models);  
553 - }  
554 -  
555 // Get the incube filename 456 // Get the incube filename
556 std::string incube = (*this)["incube"].filename(); 457 std::string incube = (*this)["incube"].filename();
557 458
@@ -560,28 +461,35 @@ void ctbkgcube::get_parameters(void) @@ -560,28 +461,35 @@ void ctbkgcube::get_parameters(void)
560 (gammalib::strip_whitespace(incube) == "")) { 461 (gammalib::strip_whitespace(incube) == "")) {
561 462
562 // Create an event cube based on task parameters 463 // Create an event cube based on task parameters
563 - m_bkgcube = create_cube(m_obs); 464 + GCTAEventCube cube = create_cube(m_obs);
  465 +
  466 + // Define background cube
  467 + m_background = GCTACubeBackground(cube);
564 468
565 } // endif: filename was not valid 469 } // endif: filename was not valid
566 470
567 // ... otherwise setup the background cube from the counts map 471 // ... otherwise setup the background cube from the counts map
568 else { 472 else {
569 -  
570 - // Load event cube from filename  
571 - m_bkgcube.load(incube);  
572 - // Loop over all bins in background cube  
573 - for (int i = 0; i < m_bkgcube.size(); ++i) {  
574 473
575 - // Get event bin  
576 - GCTAEventBin* bin = m_bkgcube[i];  
577 - bin->counts(0.0);  
578 -  
579 - } 474 + // Define background cube from file
  475 + m_background = GCTACubeBackground(incube);
580 476
581 } // endelse: cube was loaded from file 477 } // endelse: cube was loaded from file
582 478
583 - // Get energy definition  
584 - m_ebounds = m_bkgcube.ebounds(); 479 + // If there are no models associated with the observations then load now
  480 + // the model definition from the XML file
  481 + if (m_obs.models().size() == 0) {
  482 + if ((*this)["inmodel"].is_undefined()) {
  483 + std::string msg = "No model definition XML file specified. "
  484 + "Please set the \"inmodel\" parameter to the "
  485 + "XML file that contains the background model "
  486 + "definition.";
  487 + throw GException::invalid_value(G_GET_PARAMETERS, msg);
  488 + }
  489 + std::string inmodel = (*this)["inmodel"].filename();
  490 + GModels models(inmodel);
  491 + m_obs.models(models);
  492 + }
585 493
586 // Read output filenames (if needed) 494 // Read output filenames (if needed)
587 if (read_ahead()) { 495 if (read_ahead()) {
@@ -592,92 +500,3 @@ void ctbkgcube::get_parameters(void) @@ -592,92 +500,3 @@ void ctbkgcube::get_parameters(void)
592 // Return 500 // Return
593 return; 501 return;
594 } 502 }
595 -  
596 -/***********************************************************************//**  
597 - * @brief Generate background cube  
598 - *  
599 - * @param[in] obs Pointer to CTA observation.  
600 - *  
601 - * Fills the background cube with the model value for a CTA observation.  
602 - * This method will not need to load the event file as it gets the event  
603 - * ROI and GTI directly from the observation.  
604 - ***************************************************************************/  
605 -void ctbkgcube::fill_cube(GCTAObservation* obs)  
606 -{  
607 -  
608 - // Continue only if observation pointer is valid  
609 - if (obs != NULL) {  
610 -  
611 - // Initialise statistics  
612 - double sum = 0.0;  
613 - int n_bins_inside = 0;  
614 - int n_bins_outside = 0;  
615 -  
616 - // Extract region of interest from CTA observation  
617 - GCTARoi roi = obs->roi();  
618 -  
619 - // Set GTI of actual observations as the GTI of the event cube  
620 - m_bkgcube.gti(obs->gti());  
621 -  
622 - // Get observation livetime  
623 - double livetime = obs->livetime();  
624 -  
625 - // Loop over all bins in background cube  
626 - for (int i = 0; i < m_bkgcube.size(); ++i) {  
627 -  
628 - // Get event bin  
629 - GCTAEventBin* bin = m_bkgcube[i];  
630 -  
631 - // Continue only if binned in contained in ROI  
632 - if (roi.contains(*bin)) {  
633 -  
634 - // Compute model value for event bin. The model value is  
635 - // given in counts/MeV/s/sr.  
636 - double model = m_bkgmdl.eval(*bin, *obs);  
637 -  
638 - // Compute number events  
639 - sum += model * bin->size();  
640 -  
641 - // Multiply by livetime to get the correct weighting for  
642 - // each observation. We divide by the total livetime later  
643 - // to get the background model in units of counts/MeV/s/sr.  
644 - model *= livetime;  
645 -  
646 - // Add existing number of counts  
647 - model += bin->counts();  
648 -  
649 - // Store cumulated value (units: counts/MeV/sr)  
650 - bin->counts(model);  
651 -  
652 - // Increment contained bin counter  
653 - n_bins_inside++;  
654 -  
655 - } // endif: bin was contained in RoI  
656 -  
657 - // ... otherwise count bin as an outsider  
658 - else {  
659 - n_bins_outside++;  
660 - }  
661 -  
662 - } // endfor: looped over all bins  
663 -  
664 - // Accumulate livetime  
665 - m_livetime += livetime;  
666 -  
667 - // Log results  
668 - if (logTerse()) {  
669 - log << gammalib::parformat("Bins within RoI");  
670 - log << n_bins_inside << std::endl;  
671 - log << gammalib::parformat("Bins outside RoI");  
672 - log << n_bins_outside << std::endl;  
673 - log << gammalib::parformat("Background events in cube");  
674 - log << sum << std::endl;  
675 - log << gammalib::parformat("Cube livetime");  
676 - log << livetime << " sec" << std::endl;  
677 - }  
678 -  
679 - } // endif: observation pointer was not valid  
680 -  
681 - // Return  
682 - return;  
683 -}  
src/ctbkgcube/ctbkgcube.hpp
@@ -56,11 +56,11 @@ public: @@ -56,11 +56,11 @@ public:
56 ctbkgcube& operator=(const ctbkgcube& app); 56 ctbkgcube& operator=(const ctbkgcube& app);
57 57
58 // Methods 58 // Methods
59 - void clear(void);  
60 - void run(void);  
61 - void save(void);  
62 - const GCTAEventCube& cube(void) const;  
63 - const GModels& models(void) const; 59 + void clear(void);
  60 + void run(void);
  61 + void save(void);
  62 + const GCTACubeBackground& cube(void) const;
  63 + const GModels& models(void) const;
64 64
65 protected: 65 protected:
66 // Protected methods 66 // Protected methods
@@ -71,31 +71,29 @@ protected: @@ -71,31 +71,29 @@ protected:
71 void fill_cube(GCTAObservation* obs); 71 void fill_cube(GCTAObservation* obs);
72 72
73 // Protected members 73 // Protected members
74 - std::string m_outcube; //!< Filename of output cube  
75 - std::string m_outmodel; //!< Filename of output XML model  
76 - GObservations m_obs; //!< Observation container  
77 - GCTAEventCube m_bkgcube; //!< Background cube  
78 - GModels m_bkgmdl; //!< CTA background models  
79 - GModels m_outmdl; //!< Output models  
80 - GEbounds m_ebounds; //!< Energy boundaries  
81 - double m_livetime; //!< Total livetime for normalization  
82 - int m_cube_model; //!< Cube model index 74 + std::string m_outcube; //!< Filename of output cube
  75 + std::string m_outmodel; //!< Filename of output XML model
  76 + GObservations m_obs; //!< Observation container
  77 + GCTACubeBackground m_background; //!< Background cube response
  78 + GModels m_bkgmdl; //!< CTA background models
  79 + GModels m_outmdl; //!< Output models
83 }; 80 };
84 81
85 82
86 /***********************************************************************//** 83 /***********************************************************************//**
87 - * @brief Return event cube containing background rate 84 + * @brief Return background response cube containing background rate
88 * 85 *
89 - * @return Background event cube. 86 + * @return Background response cube.
90 ***************************************************************************/ 87 ***************************************************************************/
91 inline 88 inline
92 -const GCTAEventCube& ctbkgcube::cube(void) const 89 +const GCTACubeBackground& ctbkgcube::cube(void) const
93 { 90 {
94 // Return background cube 91 // Return background cube
95 - return (m_bkgcube); 92 + return (m_background);
96 } 93 }
97 94
98 95
  96 +
99 /***********************************************************************//** 97 /***********************************************************************//**
100 * @brief Return background model container 98 * @brief Return background model container
101 * 99 *
src/ctbkgcube/ctbkgcube.par
@@ -18,10 +18,10 @@ @@ -18,10 +18,10 @@
18 # Observational parameters 18 # Observational parameters
19 #=================== 19 #===================
20 inobs, f, a, "NONE",,, "Input event list or observation definition file" 20 inobs, f, a, "NONE",,, "Input event list or observation definition file"
21 -inmodel, f, a, "NONE",,, "Input (background) model XML file" 21 +inmodel, f, a, "NONE",,, "Input model XML file"
22 incube, f, a, "NONE",,, "Counts cube for background cube definition" 22 incube, f, a, "NONE",,, "Counts cube for background cube definition"
23 outcube, f, a, "bkgcube.fits",,, "Output background cube file" 23 outcube, f, a, "bkgcube.fits",,, "Output background cube file"
24 -outmodel, f, a, "NONE",,, "Output (background) model XML file" 24 +outmodel, f, a, "NONE",,, "Output model XML file"
25 caldb, s, a, "dummy",,, "Calibration database" 25 caldb, s, a, "dummy",,, "Calibration database"
26 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 26 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
27 # 27 #
src/ctbutterfly/ctbutterfly.par
@@ -22,6 +22,7 @@ inmodel, f, a, &quot;$CTOOLS/share/models/crab.xml&quot;,,, &quot;Source model&quot; @@ -22,6 +22,7 @@ inmodel, f, a, &quot;$CTOOLS/share/models/crab.xml&quot;,,, &quot;Source model&quot;
22 srcname, s, a, "Crab",,,"Source of interest" 22 srcname, s, a, "Crab",,,"Source of interest"
23 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)" 23 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)"
24 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)" 24 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)"
  25 +bkgcube, f, a, "NONE",,, "Background cube file (only needed for stacked analysis)"
25 caldb, s, a, "dummy",,, "Calibration database" 26 caldb, s, a, "dummy",,, "Calibration database"
26 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 27 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
27 outfile, f, a, "butterfly.txt",,, "Output ascii file" 28 outfile, f, a, "butterfly.txt",,, "Output ascii file"
src/ctlike/ctlike.par
@@ -21,6 +21,7 @@ inobs, f, a, &quot;events.fits&quot;,,, &quot;Event list, counts cube or observation definit @@ -21,6 +21,7 @@ inobs, f, a, &quot;events.fits&quot;,,, &quot;Event list, counts cube or observation definit
21 inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" 21 inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model"
22 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)" 22 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)"
23 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)" 23 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)"
  24 +bkgcube, f, a, "NONE",,, "Background cube file (only needed for stacked analysis)"
24 caldb, s, a, "dummy",,, "Calibration database" 25 caldb, s, a, "dummy",,, "Calibration database"
25 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 26 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
26 outmodel, f, a, "crab_results.xml",,, "Source model output file" 27 outmodel, f, a, "crab_results.xml",,, "Source model output file"
src/ctmodel/ctmodel.par
@@ -27,6 +27,7 @@ edisp, b, h, no,,, &quot;Apply energy dispersion?&quot; @@ -27,6 +27,7 @@ edisp, b, h, no,,, &quot;Apply energy dispersion?&quot;
27 inobs, f, a, "NONE",,, "Event list, counts cube or observation definition file" 27 inobs, f, a, "NONE",,, "Event list, counts cube or observation definition file"
28 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)" 28 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)"
29 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)" 29 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)"
  30 +bkgcube, f, a, "NONE",,, "Background cube file (only needed for stacked analysis)"
30 caldb, s, a, "dummy",,, "Calibration database" 31 caldb, s, a, "dummy",,, "Calibration database"
31 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 32 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
32 ra, r, a, 83.63,0,360, "RA of pointing (degrees)" 33 ra, r, a, 83.63,0,360, "RA of pointing (degrees)"
src/cttsmap/cttsmap.par
@@ -22,6 +22,7 @@ inmodel, f, a, &quot;$CTOOLS/share/models/crab.xml&quot;,,, &quot;Source model&quot; @@ -22,6 +22,7 @@ inmodel, f, a, &quot;$CTOOLS/share/models/crab.xml&quot;,,, &quot;Source model&quot;
22 srcname, s, a, "Crab",,, "Test source" 22 srcname, s, a, "Crab",,, "Test source"
23 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)" 23 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)"
24 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)" 24 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)"
  25 +bkgcube, f, a, "NONE",,, "Background cube file (only needed for stacked analysis)"
25 caldb, s, a, "dummy",,, "Calibration database" 26 caldb, s, a, "dummy",,, "Calibration database"
26 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 27 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
27 outmap, f, a, "tsmap.fits",,, "Output Test Statistic map" 28 outmap, f, a, "tsmap.fits",,, "Output Test Statistic map"
src/ctulimit/ctulimit.par
@@ -22,6 +22,7 @@ inmodel, f, a, &quot;$CTOOLS/share/models/crab.xml&quot;,,, &quot;Source model&quot; @@ -22,6 +22,7 @@ inmodel, f, a, &quot;$CTOOLS/share/models/crab.xml&quot;,,, &quot;Source model&quot;
22 srcname, s, a, "Crab",,, "Source of interest" 22 srcname, s, a, "Crab",,, "Source of interest"
23 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)" 23 expcube, f, a, "NONE",,, "Exposure cube file (only needed for stacked analysis)"
24 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)" 24 psfcube, f, a, "NONE",,, "PSF cube file (only needed for stacked analysis)"
  25 +bkgcube, f, a, "NONE",,, "Background cube file (only needed for stacked analysis)"
25 caldb, s, a, "dummy",,, "Calibration database" 26 caldb, s, a, "dummy",,, "Calibration database"
26 irf, s, a, "cta_dummy_irf",,, "Instrument response function" 27 irf, s, a, "cta_dummy_irf",,, "Instrument response function"
27 28
src/support/ctool.cpp
@@ -732,23 +732,26 @@ void ctool::set_obs_response(GCTAObservation* obs) @@ -732,23 +732,26 @@ void ctool::set_obs_response(GCTAObservation* obs)
732 // If the observation contains a counts cube, then first check whether 732 // If the observation contains a counts cube, then first check whether
733 // the expcube and psfcube parameters exist and are not NONE 733 // the expcube and psfcube parameters exist and are not NONE
734 if (dynamic_cast<const GCTAEventCube*>(obs->events()) != NULL) { 734 if (dynamic_cast<const GCTAEventCube*>(obs->events()) != NULL) {
735 - if (has_par("expcube") && has_par("psfcube")) { 735 + if (has_par("expcube") && has_par("psfcube") && has_par("bkgcube")) {
736 736
737 // Get filenames 737 // Get filenames
738 std::string expcube = (*this)["expcube"].filename(); 738 std::string expcube = (*this)["expcube"].filename();
739 std::string psfcube = (*this)["psfcube"].filename(); 739 std::string psfcube = (*this)["psfcube"].filename();
  740 + std::string bkgcube = (*this)["bkgcube"].filename();
740 741
741 // Extract response information if available 742 // Extract response information if available
742 - if ((expcube != "NONE") && (psfcube != "NONE") && 743 + if ((expcube != "NONE") && (psfcube != "NONE") && (bkgcube != "NONE") &&
743 (gammalib::strip_whitespace(expcube) != "") && 744 (gammalib::strip_whitespace(expcube) != "") &&
744 - (gammalib::strip_whitespace(psfcube) != "")) { 745 + (gammalib::strip_whitespace(psfcube) != "") &&
  746 + (gammalib::strip_whitespace(bkgcube) != "")) {
745 747
746 // Get exposure and PSF cubes 748 // Get exposure and PSF cubes
747 - GCTACubeExposure exposure(expcube);  
748 - GCTACubePsf psf(psfcube); 749 + GCTACubeExposure exposure(expcube);
  750 + GCTACubePsf psf(psfcube);
  751 + GCTACubeBackground background(bkgcube);
749 752
750 // Set reponse 753 // Set reponse
751 - obs->response(exposure, psf); 754 + obs->response(exposure, psf, background);
752 755
753 // Signal response availability 756 // Signal response availability
754 has_response = true; 757 has_response = true;
test/data/model_background_cube_const.xml deleted
1 -<?xml version="1.0" standalone="no"?>  
2 -<source_library title="source library">  
3 - <source name="CTABackgroundModel" type="CTACubeBackground" instrument="CTA">  
4 - <spectrum type="ConstantValue">  
5 - <parameter name="Value" scale="1.0" min="0.01" max="1000.0" value="1.0" free="1"/>  
6 - </spectrum>  
7 - <spatialModel type="MapCubeFunction" file="data/test_cube.fits">  
8 - <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="0"/>  
9 - </spatialModel>  
10 - </source>  
11 -</source_library>  
test/data/model_background_cube.xml renamed to test/data/model_cube_background.xml
@@ -6,8 +6,5 @@ @@ -6,8 +6,5 @@
6 <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" 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="1e6" value="1.0" min="0.01" max="1000.0" free="0"/> 7 <parameter name="Scale" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
8 </spectrum> 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> 9 </source>
13 </source_library> 10 </source_library>
test/data/test_cube.fits deleted
No preview for this file type
test/test_ctools.sh
@@ -91,27 +91,6 @@ else @@ -91,27 +91,6 @@ else
91 echo " events.fits file is not found" 91 echo " events.fits file is not found"
92 exit 1 92 exit 1
93 fi 93 fi
94 -#  
95 -# Run 2  
96 -$ctobssim inmodel="data/model_background_cube.xml" \  
97 - outevents="events2.fits" \  
98 - caldb="irf" \  
99 - irf="cta_dummy_irf" \  
100 - ra=84.17263 \  
101 - dec=22.01444 \  
102 - rad=1.0 \  
103 - tmin=0.0 \  
104 - tmax=1.0 \  
105 - emin=0.3 \  
106 - emax=8.0 chatter=4  
107 -$ECHO -n "."  
108 -if [ -s "events2.fits" ]  
109 -then  
110 - $ECHO -n "."  
111 -else  
112 - echo " events2.fits file is not found"  
113 - exit 1  
114 -fi  
115 $ECHO " ok" 94 $ECHO " ok"
116 95
117 96
@@ -148,7 +127,7 @@ $ECHO -n &quot;Test ctbin: &quot; @@ -148,7 +127,7 @@ $ECHO -n &quot;Test ctbin: &quot;
148 # 127 #
149 # Run 1 128 # Run 1
150 $ctbin inobs="events.fits" \ 129 $ctbin inobs="events.fits" \
151 - outcube="cntmap.fits" \ 130 + outcube="cntmap1.fits" \
152 emin=0.1 \ 131 emin=0.1 \
153 emax=100.0 \ 132 emax=100.0 \
154 enumbins=20 \ 133 enumbins=20 \
@@ -161,27 +140,27 @@ $ctbin inobs=&quot;events.fits&quot; \ @@ -161,27 +140,27 @@ $ctbin inobs=&quot;events.fits&quot; \
161 yref=22.01 \ 140 yref=22.01 \
162 proj="CAR" 141 proj="CAR"
163 $ECHO -n "." 142 $ECHO -n "."
164 -if [ -s "cntmap.fits" ] 143 +if [ -s "cntmap1.fits" ]
165 then 144 then
166 $ECHO -n "." 145 $ECHO -n "."
167 else 146 else
168 - $ECHO " cntmap.fits file is not found" 147 + $ECHO " cntmap1.fits file is not found"
169 exit 1 148 exit 1
170 fi 149 fi
171 # 150 #
172 # Run 2 151 # Run 2
173 -$ctbin inobs="events2.fits" \ 152 +$ctbin inobs="events.fits" \
174 outcube="cntmap2.fits" \ 153 outcube="cntmap2.fits" \
175 emin=0.3 \ 154 emin=0.3 \
176 emax=8.0 \ 155 emax=8.0 \
177 - enumbins=10 \ 156 + enumbins=7 \
178 ebinalg="LOG" \ 157 ebinalg="LOG" \
179 - nxpix=50 \  
180 - nypix=50 \  
181 - binsz=0.02 \ 158 + nxpix=30 \
  159 + nypix=30 \
  160 + binsz=0.05 \
182 coordsys="CEL" \ 161 coordsys="CEL" \
183 - xref=84.17263 \  
184 - yref=22.01444 \ 162 + xref=86.63 \
  163 + yref=22.01 \
185 proj="CAR" 164 proj="CAR"
186 $ECHO -n "." 165 $ECHO -n "."
187 if [ -s "cntmap2.fits" ] 166 if [ -s "cntmap2.fits" ]
@@ -193,6 +172,168 @@ else @@ -193,6 +172,168 @@ else
193 fi 172 fi
194 $ECHO " ok" 173 $ECHO " ok"
195 174
  175 +#
  176 +# Test ctexpcube
  177 +# ==============
  178 +$ECHO -n "Test ctexpcube: "
  179 +#
  180 +# Run 1
  181 +$ctexpcube inobs="data/crab_events.fits" \
  182 + incube="NONE" \
  183 + outcube="expcube1.fits" \
  184 + caldb="irf" \
  185 + irf="cta_dummy_irf" \
  186 + emin=0.1 \
  187 + emax=100.0 \
  188 + enumbins=20 \
  189 + nxpix=200 \
  190 + nypix=200 \
  191 + binsz=0.02 \
  192 + coordsys="CEL" \
  193 + xref=83.63 \
  194 + yref=22.01 \
  195 + proj="CAR"
  196 +$ECHO -n "."
  197 +if [ -s "expcube1.fits" ]
  198 +then
  199 +$ECHO -n "."
  200 +else
  201 +$ECHO " expcube1.fits file is not found"
  202 +exit 1
  203 +fi
  204 +#
  205 +# Run 2
  206 +$ctexpcube inobs="events.fits" \
  207 + incube="cntmap2.fits" \
  208 + outcube="expcube2.fits" \
  209 + caldb="irf" \
  210 + irf="cta_dummy_irf"
  211 +$ECHO -n "."
  212 +if [ -s "expcube2.fits" ]
  213 +then
  214 +$ECHO -n "."
  215 +else
  216 +$ECHO " expcube2.fits file is not found"
  217 +exit 1
  218 +fi
  219 +$ECHO " ok"
  220 +
  221 +
  222 +#
  223 +# Test ctpsfcube
  224 +# ==============
  225 +$ECHO -n "Test ctpsfcube: "
  226 +#
  227 +# Run 1
  228 +$ctpsfcube inobs="data/crab_events.fits" \
  229 + incube="NONE" \
  230 + outcube="psfcube1.fits" \
  231 + caldb="irf" \
  232 + irf="cta_dummy_irf" \
  233 + emin=0.1 \
  234 + emax=100.0 \
  235 + enumbins=20 \
  236 + nxpix=10 \
  237 + nypix=10 \
  238 + binsz=0.4 \
  239 + coordsys="CEL" \
  240 + xref=83.63 \
  241 + yref=22.01 \
  242 + proj="CAR" \
  243 + amax=0.3 \
  244 + anumbins=10
  245 +$ECHO -n "."
  246 +if [ -s "psfcube1.fits" ]
  247 +then
  248 +$ECHO -n "."
  249 +else
  250 +$ECHO " psfcube1.fits file is not found"
  251 +exit 1
  252 +fi
  253 +#
  254 +# Run 2
  255 +$ctpsfcube inobs="events.fits" \
  256 + incube="cntmap2.fits" \
  257 + outcube="psfcube2.fits" \
  258 + caldb="irf" \
  259 + irf="cta_dummy_irf" \
  260 + amax=0.3 \
  261 + anumbins=2
  262 +$ECHO -n "."
  263 +if [ -s "psfcube2.fits" ]
  264 +then
  265 +$ECHO -n "."
  266 +else
  267 +$ECHO " psfcube2.fits file is not found"
  268 +exit 1
  269 +fi
  270 +$ECHO " ok"
  271 +
  272 +
  273 +#
  274 +# Test ctbkgcube
  275 +# ==============
  276 +$ECHO -n "Test ctbkgcube: "
  277 +#
  278 +# Run 1
  279 +$ctbkgcube inobs="data/crab_events.fits" \
  280 + inmodel="data/crab.xml" \
  281 + incube="NONE" \
  282 + outcube="bkgcube1.fits" \
  283 + outmodel="bkgcube1.xml" \
  284 + caldb="irf" \
  285 + irf="cta_dummy_irf" \
  286 + emin=0.1 \
  287 + emax=100.0 \
  288 + enumbins=20 \
  289 + nxpix=10 \
  290 + nypix=10 \
  291 + binsz=0.4 \
  292 + coordsys="CEL" \
  293 + xref=83.63 \
  294 + yref=22.01 \
  295 + proj="CAR"
  296 +$ECHO -n "."
  297 +if [ -s "bkgcube1.fits" ]
  298 +then
  299 +$ECHO -n "."
  300 +else
  301 +$ECHO " bkgcube1.fits file is not found"
  302 +exit 1
  303 +fi
  304 +if [ -s "bkgcube1.xml" ]
  305 +then
  306 +$ECHO -n "."
  307 +else
  308 +$ECHO " bkgcube1.xml file is not found"
  309 +exit 1
  310 +fi
  311 +#
  312 +# Run 2
  313 +$ctbkgcube inobs="events.fits" \
  314 + inmodel="data/crab.xml" \
  315 + incube="cntmap2.fits" \
  316 + caldb="irf" \
  317 + irf="cta_dummy_irf" \
  318 + outcube="bkgcube2.fits" \
  319 + outmodel="bkgcube2.xml"
  320 +$ECHO -n "."
  321 +if [ -s "bkgcube2.fits" ]
  322 +then
  323 +$ECHO -n "."
  324 +else
  325 +$ECHO " bkgcube2.fits file is not found"
  326 +exit 1
  327 +fi
  328 +if [ -s "bkgcube2.fits" ]
  329 +then
  330 +$ECHO -n "."
  331 +else
  332 +$ECHO " bkgcube2.xml file is not found"
  333 +exit 1
  334 +fi
  335 +$ECHO " ok"
  336 +
196 337
197 338
198 # 339 #
@@ -201,11 +342,12 @@ $ECHO &quot; ok&quot; @@ -201,11 +342,12 @@ $ECHO &quot; ok&quot;
201 $ECHO -n "Test ctmodel: " 342 $ECHO -n "Test ctmodel: "
202 # 343 #
203 # Run 1 344 # Run 1
204 -$ctmodel inobs="cntmap.fits" \  
205 - incube="cntmap.fits" \ 345 +$ctmodel inobs="cntmap1.fits" \
  346 + incube="cntmap1.fits" \
206 outcube="modmap1.fits" \ 347 outcube="modmap1.fits" \
207 expcube="NONE" \ 348 expcube="NONE" \
208 psfcube="NONE" \ 349 psfcube="NONE" \
  350 + bkgcube="NONE" \
209 caldb="irf" \ 351 caldb="irf" \
210 irf="cta_dummy_irf" \ 352 irf="cta_dummy_irf" \
211 inmodel="data/crab.xml" 353 inmodel="data/crab.xml"
@@ -217,13 +359,35 @@ else @@ -217,13 +359,35 @@ else
217 $ECHO " modmap1.fits file is not found" 359 $ECHO " modmap1.fits file is not found"
218 exit 1 360 exit 1
219 fi 361 fi
  362 +
220 # 363 #
221 # Run 2 364 # Run 2
  365 +$ctmodel inobs="cntmap2.fits" \
  366 + incube="cntmap2.fits" \
  367 + outcube="modmap2.fits" \
  368 + expcube="expcube2.fits" \
  369 + psfcube="psfcube2.fits" \
  370 + bkgcube="bkgcube2.fits" \
  371 + caldb="irf" \
  372 + irf="cta_dummy_irf" \
  373 + inmodel="bkgcube2.xml"
  374 +$ECHO -n "."
  375 +if [ -s "modmap2.fits" ]
  376 +then
  377 +$ECHO -n "."
  378 +else
  379 +$ECHO " modmap2.fits file is not found"
  380 +exit 1
  381 +fi
  382 +
  383 +#
  384 +# Run 3
222 $ctmodel inobs="NONE" \ 385 $ctmodel inobs="NONE" \
223 incube="NONE" \ 386 incube="NONE" \
224 outcube="modmap3.fits" \ 387 outcube="modmap3.fits" \
225 expcube="NONE" \ 388 expcube="NONE" \
226 psfcube="NONE" \ 389 psfcube="NONE" \
  390 + bkgcube="NONE" \
227 caldb="irf" \ 391 caldb="irf" \
228 irf="cta_dummy_irf" \ 392 irf="cta_dummy_irf" \
229 inmodel="data/crab.xml" \ 393 inmodel="data/crab.xml" \
@@ -250,24 +414,6 @@ else @@ -250,24 +414,6 @@ else
250 $ECHO " modmap3.fits file is not found" 414 $ECHO " modmap3.fits file is not found"
251 exit 1 415 exit 1
252 fi 416 fi
253 -#  
254 -# Run 3  
255 -$ctmodel inobs="cntmap2.fits" \  
256 - incube="cntmap2.fits" \  
257 - outcube="modmap2.fits" \  
258 - expcube="NONE" \  
259 - psfcube="NONE" \  
260 - caldb="irf" \  
261 - irf="cta_dummy_irf" \  
262 - inmodel="data/model_background_cube.xml"  
263 -$ECHO -n "."  
264 -if [ -s "modmap2.fits" ]  
265 -then  
266 - $ECHO -n "."  
267 -else  
268 - $ECHO " modmap2.fits file is not found"  
269 - exit 1  
270 -fi  
271 $ECHO " ok" 417 $ECHO " ok"
272 418
273 419
@@ -301,11 +447,12 @@ $ECHO &quot; ok&quot; @@ -301,11 +447,12 @@ $ECHO &quot; ok&quot;
301 $ECHO -n "Test ctlike: " 447 $ECHO -n "Test ctlike: "
302 # 448 #
303 # Run 1 449 # Run 1
304 -$ctlike inobs="cntmap.fits" \ 450 +$ctlike inobs="cntmap1.fits" \
305 inmodel="data/crab.xml" \ 451 inmodel="data/crab.xml" \
306 outmodel="results_binned.xml" \ 452 outmodel="results_binned.xml" \
307 expcube="NONE" \ 453 expcube="NONE" \
308 psfcube="NONE" \ 454 psfcube="NONE" \
  455 + bkgcube="NONE" \
309 caldb="irf" \ 456 caldb="irf" \
310 irf="cta_dummy_irf" 457 irf="cta_dummy_irf"
311 $ECHO -n "." 458 $ECHO -n "."
@@ -331,36 +478,23 @@ else @@ -331,36 +478,23 @@ else
331 $ECHO " results_unbinned.xml file is not found" 478 $ECHO " results_unbinned.xml file is not found"
332 exit 1 479 exit 1
333 fi 480 fi
  481 +
334 # 482 #
335 # Run 3 483 # Run 3
336 -$ctlike inobs="events2.fits" \  
337 - inmodel="data/model_background_cube.xml" \  
338 - outmodel="results_unbinned_background_cube.xml" \  
339 - caldb="irf" \  
340 - irf="cta_dummy_irf"  
341 -$ECHO -n "."  
342 -if [ -s "results_unbinned_background_cube.xml" ]  
343 -then  
344 - $ECHO -n "."  
345 -else  
346 - $ECHO " results_unbinned_background_cube.xml file is not found"  
347 - exit 1  
348 -fi  
349 -#  
350 -# Run 4  
351 $ctlike inobs="cntmap2.fits" \ 484 $ctlike inobs="cntmap2.fits" \
352 - inmodel="data/model_background_cube.xml" \  
353 - outmodel="results_binned_background_cube.xml" \  
354 - expcube="NONE" \  
355 - psfcube="NONE" \ 485 + inmodel="bkgcube2.xml" \
  486 + outmodel="results_binned_cube_background.xml" \
  487 + expcube="expcube2.fits" \
  488 + psfcube="psfcube2.fits" \
  489 + bkgcube="bkgcube2.fits" \
356 caldb="irf" \ 490 caldb="irf" \
357 irf="cta_dummy_irf" 491 irf="cta_dummy_irf"
358 $ECHO -n "." 492 $ECHO -n "."
359 -if [ -s "results_binned_background_cube.xml" ] 493 +if [ -s "results_binned_cube_background.xml" ]
360 then 494 then
361 $ECHO -n "." 495 $ECHO -n "."
362 else 496 else
363 - $ECHO " results_binned_background_cube.xml file is not found" 497 + $ECHO " results_binned_cube_background.xml file is not found"
364 exit 1 498 exit 1
365 fi 499 fi
366 $ECHO " ok" 500 $ECHO " ok"
@@ -394,167 +528,6 @@ fi @@ -394,167 +528,6 @@ fi
394 $ECHO " ok" 528 $ECHO " ok"
395 529
396 530
397 -#  
398 -# Test ctexpcube  
399 -# ==============  
400 -$ECHO -n "Test ctexpcube: "  
401 -#  
402 -# Run 1  
403 -$ctexpcube inobs="data/crab_events.fits" \  
404 - incube="NONE" \  
405 - outcube="expcube1.fits" \  
406 - caldb="irf" \  
407 - irf="cta_dummy_irf" \  
408 - emin=0.1 \  
409 - emax=100.0 \  
410 - enumbins=20 \  
411 - nxpix=200 \  
412 - nypix=200 \  
413 - binsz=0.02 \  
414 - coordsys="CEL" \  
415 - xref=83.63 \  
416 - yref=22.01 \  
417 - proj="CAR"  
418 -$ECHO -n "."  
419 -if [ -s "expcube1.fits" ]  
420 -then  
421 - $ECHO -n "."  
422 -else  
423 - $ECHO " expcube1.fits file is not found"  
424 - exit 1  
425 -fi  
426 -#  
427 -# Run 2  
428 -$ctexpcube inobs="data/crab_events.fits" \  
429 - incube="data/crab_cntmap.fits" \  
430 - outcube="expcube2.fits" \  
431 - caldb="irf" \  
432 - irf="cta_dummy_irf"  
433 -$ECHO -n "."  
434 -if [ -s "expcube2.fits" ]  
435 -then  
436 - $ECHO -n "."  
437 -else  
438 - $ECHO " expcube2.fits file is not found"  
439 - exit 1  
440 -fi  
441 -$ECHO " ok"  
442 -  
443 -  
444 -#  
445 -# Test ctpsfcube  
446 -# ==============  
447 -$ECHO -n "Test ctpsfcube: "  
448 -#  
449 -# Run 1  
450 -$ctpsfcube inobs="data/crab_events.fits" \  
451 - incube="NONE" \  
452 - outcube="psfcube1.fits" \  
453 - caldb="irf" \  
454 - irf="cta_dummy_irf" \  
455 - emin=0.1 \  
456 - emax=100.0 \  
457 - enumbins=20 \  
458 - nxpix=10 \  
459 - nypix=10 \  
460 - binsz=0.4 \  
461 - coordsys="CEL" \  
462 - xref=83.63 \  
463 - yref=22.01 \  
464 - proj="CAR" \  
465 - amax=0.3 \  
466 - anumbins=10  
467 -$ECHO -n "."  
468 -if [ -s "psfcube1.fits" ]  
469 -then  
470 - $ECHO -n "."  
471 -else  
472 - $ECHO " psfcube1.fits file is not found"  
473 - exit 1  
474 -fi  
475 -#  
476 -# Run 2  
477 -$ctpsfcube inobs="data/crab_events.fits" \  
478 - incube="data/crab_cntmap.fits" \  
479 - outcube="psfcube2.fits" \  
480 - caldb="irf" \  
481 - irf="cta_dummy_irf" \  
482 - amax=0.3 \  
483 - anumbins=2  
484 -$ECHO -n "."  
485 -if [ -s "psfcube2.fits" ]  
486 -then  
487 - $ECHO -n "."  
488 -else  
489 - $ECHO " psfcube2.fits file is not found"  
490 - exit 1  
491 -fi  
492 -$ECHO " ok"  
493 -  
494 -  
495 -#  
496 -# Test ctbkgcube  
497 -# ==============  
498 -$ECHO -n "Test ctbkgcube: "  
499 -#  
500 -# Run 1  
501 -$ctbkgcube inobs="data/crab_events.fits" \  
502 - inmodel="data/crab.xml" \  
503 - incube="NONE" \  
504 - outcube="bkgcube1.fits" \  
505 - outmodel="bkgcube1.xml" \  
506 - caldb="irf" \  
507 - irf="cta_dummy_irf" \  
508 - emin=0.1 \  
509 - emax=100.0 \  
510 - enumbins=20 \  
511 - nxpix=10 \  
512 - nypix=10 \  
513 - binsz=0.4 \  
514 - coordsys="CEL" \  
515 - xref=83.63 \  
516 - yref=22.01 \  
517 - proj="CAR"  
518 -$ECHO -n "."  
519 -if [ -s "bkgcube1.fits" ]  
520 -then  
521 - $ECHO -n "."  
522 -else  
523 - $ECHO " bkgcube1.fits file is not found"  
524 - exit 1  
525 -fi  
526 -if [ -s "bkgcube1.xml" ]  
527 -then  
528 - $ECHO -n "."  
529 -else  
530 - $ECHO " bkgcube1.xml file is not found"  
531 - exit 1  
532 -fi  
533 -#  
534 -# Run 2  
535 -$ctbkgcube inobs="data/crab_events.fits" \  
536 - inmodel="data/crab.xml" \  
537 - incube="data/crab_cntmap.fits" \  
538 - caldb="irf" \  
539 - irf="cta_dummy_irf" \  
540 - outcube="bkgcube2.fits" \  
541 - outmodel="bkgcube2.xml"  
542 -$ECHO -n "."  
543 -if [ -s "bkgcube2.fits" ]  
544 -then  
545 - $ECHO -n "."  
546 -else  
547 - $ECHO " bkgcube2.fits file is not found"  
548 - exit 1  
549 -fi  
550 -if [ -s "bkgcube2.fits" ]  
551 -then  
552 - $ECHO -n "."  
553 -else  
554 - $ECHO " bkgcube2.xml file is not found"  
555 - exit 1  
556 -fi  
557 -$ECHO " ok"  
558 531
559 532
560 # 533 #
@@ -608,10 +581,10 @@ $ECHO &quot; ok&quot; @@ -608,10 +581,10 @@ $ECHO &quot; ok&quot;
608 # =============== 581 # ===============
609 $ECHO -n "Test ctulimit: " 582 $ECHO -n "Test ctulimit: "
610 $ctulimit inobs="data/crab_events.fits.gz" \ 583 $ctulimit inobs="data/crab_events.fits.gz" \
611 - inmodel="data/crab.xml" \  
612 - srcname="Crab" \  
613 - caldb="irf" \  
614 - irf="cta_dummy_irf" 584 + inmodel="data/crab.xml" \
  585 + srcname="Crab" \
  586 + caldb="irf" \
  587 + irf="cta_dummy_irf"
615 $ECHO -n "." 588 $ECHO -n "."
616 if [ -s "ctulimit.log" ] 589 if [ -s "ctulimit.log" ]
617 then 590 then