Commit dd903c61b36f94853461a6e1c6a9b4e39b7db1c2

Authored by Jürgen Knödlseder
1 parent 05643325

Add caldb and irf parameters to ctskymap, and store background and significance map

doc/source/users/reference_manual/ctskymap.rst
@@ -21,56 +21,68 @@ If ``IRF`` is selected, the background template that are shipped with the @@ -21,56 +21,68 @@ If ``IRF`` is selected, the background template that are shipped with the
21 Instrument Response Functions will be used for background subtraction. 21 Instrument Response Functions will be used for background subtraction.
22 22
23 ctskymap generates a FITS file comprising a sky map as primary extension. 23 ctskymap generates a FITS file comprising a sky map as primary extension.
  24 +If a background subtraction method was selected, the FITS file will contain
  25 +the additional extensions ``BACKGRAOUND`` and ``SIGNIFICANCE`` that contain
  26 +the background map and a significance map, respectively. For the latter, the
  27 +significance of the signal is computed for each sky map pixel.
24 28
25 29
26 General parameters 30 General parameters
27 ------------------ 31 ------------------
28 32
29 ``inobs [file]`` 33 ``inobs [file]``
30 - Input event list or observation definition XML file  
31 - 34 + Input event list or observation definition XML file.
  35 +
  36 +``caldb [string]``
  37 + Calibration database (only required for IRF background subtraction if no
  38 + response information is provided by ``inobs``).
  39 +
  40 +``irf [string]``
  41 + Instrument response function (only required for IRF background subtraction
  42 + if no response information is provided by ``inobs``).
  43 +
32 ``outmap [file]`` 44 ``outmap [file]``
33 - Output sky map file 45 + Output sky map file.
34 46
35 ``emin [real]`` 47 ``emin [real]``
36 - Minimum energy in map (in TeV) 48 + Minimum energy in map (in TeV).
37 49
38 ``emax [real]`` 50 ``emax [real]``
39 - Maximum energy in map (in TeV) 51 + Maximum energy in map (in TeV).
40 52
41 ``(usepnt = no) [boolean]`` 53 ``(usepnt = no) [boolean]``
42 Use pointing instead of xref/yref parameters? 54 Use pointing instead of xref/yref parameters?
43 55
44 ``nxpix [integer]`` 56 ``nxpix [integer]``
45 - Size of the Right Ascension / Galactic longitude axis (in pixels) 57 + Size of the Right Ascension / Galactic longitude axis (in pixels).
46 58
47 ``nypix [integer]`` 59 ``nypix [integer]``
48 - Size of the Declination / Galactic latitude axis (in pixels) 60 + Size of the Declination / Galactic latitude axis (in pixels).
49 61
50 ``binsz [real]`` 62 ``binsz [real]``
51 Pixel size (in degrees/pixel). 63 Pixel size (in degrees/pixel).
52 64
53 ``coordsys <CEL|GAL> [string]`` 65 ``coordsys <CEL|GAL> [string]``
54 - Coordinate system (CEL - celestial, GAL - galactic) 66 + Coordinate system (CEL - celestial, GAL - galactic).
55 67
56 ``proj <AIT|AZP|CAR|MER|STG|TAN> [string]`` 68 ``proj <AIT|AZP|CAR|MER|STG|TAN> [string]``
57 - Projection method 69 + Projection method.
58 70
59 ``xref [real]`` 71 ``xref [real]``
60 - Right Ascension / Galactic longitude of image centre (J2000, in degrees) 72 + Right Ascension / Galactic longitude of image centre (J2000, in degrees).
61 73
62 ``yref [real]`` 74 ``yref [real]``
63 - Declination / Galactic latitude of image centre (J2000, in degrees) 75 + Declination / Galactic latitude of image centre (J2000, in degrees).
64 76
65 ``bkgsubtract <NONE|IRF> [string]`` 77 ``bkgsubtract <NONE|IRF> [string]``
66 - Background subtraction method 78 + Background subtraction method.
67 79
68 80
69 Standard parameters 81 Standard parameters
70 ------------------- 82 -------------------
71 83
72 ``(publish = no) [boolean]`` 84 ``(publish = no) [boolean]``
73 - Specifies whether the sky map should be published on VO Hub 85 + Specifies whether the sky map should be published on VO Hub.
74 86
75 ``(chatter = 2) [integer]`` 87 ``(chatter = 2) [integer]``
76 Verbosity of the executable: 88 Verbosity of the executable:
@@ -85,16 +97,17 @@ Standard parameters @@ -85,16 +97,17 @@ Standard parameters
85 chatter = 4: detailed report about the task execution 97 chatter = 4: detailed report about the task execution
86 98
87 ``(clobber = yes) [boolean]`` 99 ``(clobber = yes) [boolean]``
88 - Specifies whether an existing output sky map file should be overwritten 100 + Specifies whether an existing output sky map file should be overwritten.
89 101
90 ``(debug = no) [boolean]`` 102 ``(debug = no) [boolean]``
91 - Enables debug mode. In debug mode the executable will dump any log file output to the console. 103 + Enables debug mode. In debug mode the executable will dump any log file
  104 + output to the console.
92 105
93 ``(mode = ql) [string]`` 106 ``(mode = ql) [string]``
94 - Mode of automatic parameters (default is "ql", i.e. "query and learn") 107 + Mode of automatic parameters (default is "ql", i.e. "query and learn").
95 108
96 ``(logfile = ctskymap.log) [string]`` 109 ``(logfile = ctskymap.log) [string]``
97 - Name of log file 110 + Name of log file.
98 111
99 112
100 Related tools or scripts 113 Related tools or scripts
src/ctskymap/ctskymap.cpp
@@ -233,11 +233,23 @@ void ctskymap::run(void) @@ -233,11 +233,23 @@ void ctskymap::run(void)
233 // Map events into sky map 233 // Map events into sky map
234 map_events(obs); 234 map_events(obs);
235 235
236 - // Subtract background from sky map  
237 - bkg_subtract(obs); 236 + // Compute background sky map
  237 + map_background(obs);
238 238
239 } // endfor: looped over observations 239 } // endfor: looped over observations
240 240
  241 + // If background subtract was required then compute significance map
  242 + // and subtract background map from counts map
  243 + if (m_bkgsubtract != "NONE") {
  244 +
  245 + // Compute significance map
  246 + m_sigmap = (m_skymap - m_bkgmap) / sqrt(m_skymap);
  247 +
  248 + // Subtract background map from counts map
  249 + m_skymap -= m_bkgmap;
  250 +
  251 + } // endif: background subtraction was requested
  252 +
241 // Optionally publish sky map 253 // Optionally publish sky map
242 if (m_publish) { 254 if (m_publish) {
243 publish(); 255 publish();
@@ -271,6 +283,24 @@ void ctskymap::save(void) @@ -271,6 +283,24 @@ void ctskymap::save(void)
271 // Write sky map into FITS file 283 // Write sky map into FITS file
272 m_skymap.write(fits); 284 m_skymap.write(fits);
273 285
  286 + // If background subtraction is requested then write background map
  287 + // and significance map to FITS file
  288 + if (m_bkgsubtract != "NONE") {
  289 +
  290 + // Write background map into FITS file
  291 + m_bkgmap.write(fits);
  292 +
  293 + // Set background map extension name
  294 + fits[fits.size()-1]->extname("BACKGROUND");
  295 +
  296 + // Write significance map into FITS file
  297 + m_sigmap.write(fits);
  298 +
  299 + // Set significance map extension name
  300 + fits[fits.size()-1]->extname("SIGNIFICANCE");
  301 +
  302 + } // endif: background subtraction was requested
  303 +
274 // Save FITS file to disk 304 // Save FITS file to disk
275 fits.saveto(m_outmap, clobber()); 305 fits.saveto(m_outmap, clobber());
276 306
@@ -328,6 +358,8 @@ void ctskymap::init_members(void) @@ -328,6 +358,8 @@ void ctskymap::init_members(void)
328 { 358 {
329 // Initialise members 359 // Initialise members
330 m_skymap.clear(); 360 m_skymap.clear();
  361 + m_bkgmap.clear();
  362 + m_sigmap.clear();
331 m_emin = 0.0; 363 m_emin = 0.0;
332 m_emax = 0.0; 364 m_emax = 0.0;
333 m_bkgsubtract = "NONE"; 365 m_bkgsubtract = "NONE";
@@ -348,6 +380,8 @@ void ctskymap::copy_members(const ctskymap&amp; app) @@ -348,6 +380,8 @@ void ctskymap::copy_members(const ctskymap&amp; app)
348 { 380 {
349 // Copy attributes 381 // Copy attributes
350 m_skymap = app.m_skymap; 382 m_skymap = app.m_skymap;
  383 + m_bkgmap = app.m_bkgmap;
  384 + m_sigmap = app.m_sigmap;
351 m_emin = app.m_emin; 385 m_emin = app.m_emin;
352 m_emax = app.m_emax; 386 m_emax = app.m_emax;
353 m_bkgsubtract = app.m_bkgsubtract; 387 m_bkgsubtract = app.m_bkgsubtract;
@@ -387,10 +421,18 @@ void ctskymap::get_parameters(void) @@ -387,10 +421,18 @@ void ctskymap::get_parameters(void)
387 // Create sky map based on task parameters 421 // Create sky map based on task parameters
388 m_skymap = create_map(m_obs); 422 m_skymap = create_map(m_obs);
389 423
390 - // Get remaining parameters 424 + // Get further parameters
391 m_emin = (*this)["emin"].real(); 425 m_emin = (*this)["emin"].real();
392 m_emax = (*this)["emax"].real(); 426 m_emax = (*this)["emax"].real();
393 m_bkgsubtract = (*this)["bkgsubtract"].string(); 427 m_bkgsubtract = (*this)["bkgsubtract"].string();
  428 +
  429 + // If IRF background subtraction is requested then make sure that the
  430 + // CTA observations in the observation container have response information
  431 + if (m_bkgsubtract == "IRF") {
  432 + set_response(m_obs);
  433 + }
  434 +
  435 + // Get remaining parameters
394 m_publish = (*this)["publish"].boolean(); 436 m_publish = (*this)["publish"].boolean();
395 m_chatter = static_cast<GChatter>((*this)["chatter"].integer()); 437 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
396 438
@@ -399,6 +441,13 @@ void ctskymap::get_parameters(void) @@ -399,6 +441,13 @@ void ctskymap::get_parameters(void)
399 m_outmap = (*this)["outmap"].filename(); 441 m_outmap = (*this)["outmap"].filename();
400 } 442 }
401 443
  444 + // Create background map and significance map if background subtraction
  445 + // is requested
  446 + if (m_bkgsubtract != "NONE") {
  447 + m_bkgmap = create_map(m_obs);
  448 + m_sigmap = create_map(m_obs);
  449 + }
  450 +
402 // Write parameters into logger 451 // Write parameters into logger
403 log_parameters(TERSE); 452 log_parameters(TERSE);
404 453
@@ -487,22 +536,23 @@ void ctskymap::map_events(GCTAObservation* obs) @@ -487,22 +536,23 @@ void ctskymap::map_events(GCTAObservation* obs)
487 536
488 537
489 /***********************************************************************//** 538 /***********************************************************************//**
490 - * @brief Subtract background events from skymap 539 + * @brief Estimates the background in sky map for observation
491 * 540 *
492 * @param[in] obs CTA observation. 541 * @param[in] obs CTA observation.
493 * 542 *
494 - * Subtracts background events from the sky map using various methods. The  
495 - * background subtraction method is specified by the "bkgsubtract" parameter  
496 - * which can take the following values: 543 + * Estimates the background in the sky map for a given observation and adds
  544 + * this estimate to the background sky map. The background estimation method
  545 + * is specified by the "bkgsubtract" parameter which can take the following
  546 + * values:
497 * 547 *
498 - * NONE - No background subtraction  
499 - * IRF - Background subtraction based on IRF template 548 + * NONE - No background estimation
  549 + * IRF - Background estimation based on IRF template
500 ***************************************************************************/ 550 ***************************************************************************/
501 -void ctskymap::bkg_subtract(GCTAObservation* obs) 551 +void ctskymap::map_background(GCTAObservation* obs)
502 { 552 {
503 - // Dispatch to apporpriate background subtraction method 553 + // Dispatch to appropriate background estimation method
504 if (m_bkgsubtract == "IRF") { 554 if (m_bkgsubtract == "IRF") {
505 - bkg_subtract_irf(obs); 555 + map_background_irf(obs);
506 } 556 }
507 557
508 // Return 558 // Return
@@ -511,7 +561,7 @@ void ctskymap::bkg_subtract(GCTAObservation* obs) @@ -511,7 +561,7 @@ void ctskymap::bkg_subtract(GCTAObservation* obs)
511 561
512 562
513 /***********************************************************************//** 563 /***********************************************************************//**
514 - * @brief Subtract background events based on IRF template from sky map 564 + * @brief Estimates the background in sky map based on IRF template
515 * 565 *
516 * @param[in] obs CTA observation. 566 * @param[in] obs CTA observation.
517 * 567 *
@@ -519,9 +569,10 @@ void ctskymap::bkg_subtract(GCTAObservation* obs) @@ -519,9 +569,10 @@ void ctskymap::bkg_subtract(GCTAObservation* obs)
519 * No response information available for observation. 569 * No response information available for observation.
520 * No background template available in instrument response function. 570 * No background template available in instrument response function.
521 * 571 *
522 - * Subtracts background events from the sky map using the IRF template. 572 + * Estimates the background in the sky map using the IRF template for a given
  573 + * observation and adds this estimate to the background sky map.
523 ***************************************************************************/ 574 ***************************************************************************/
524 -void ctskymap::bkg_subtract_irf(GCTAObservation* obs) 575 +void ctskymap::map_background_irf(GCTAObservation* obs)
525 { 576 {
526 // Get IRF response 577 // Get IRF response
527 const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*>(obs->response()); 578 const GCTAResponseIrf* rsp = dynamic_cast<const GCTAResponseIrf*>(obs->response());
@@ -563,11 +614,11 @@ void ctskymap::bkg_subtract_irf(GCTAObservation* obs) @@ -563,11 +614,11 @@ void ctskymap::bkg_subtract_irf(GCTAObservation* obs)
563 // Setup energy nodes for computation 614 // Setup energy nodes for computation
564 GEnergies energies(nebin, emin, emax); // More complicated nbins later 615 GEnergies energies(nebin, emin, emax); // More complicated nbins later
565 616
566 - // Loop over all sky map pixels  
567 - for (int i = 0; i < m_skymap.npix(); ++i) { 617 + // Loop over all background map pixels
  618 + for (int i = 0; i < m_bkgmap.npix(); ++i) {
568 619
569 // Get sky direction of pixel 620 // Get sky direction of pixel
570 - GSkyDir skydir = m_skymap.inx2dir(i); 621 + GSkyDir skydir = m_bkgmap.inx2dir(i);
571 622
572 // Convert sky direction in instrument direction 623 // Convert sky direction in instrument direction
573 GCTAInstDir instdir = obs->pointing().instdir(skydir); 624 GCTAInstDir instdir = obs->pointing().instdir(skydir);
@@ -587,12 +638,12 @@ void ctskymap::bkg_subtract_irf(GCTAObservation* obs) @@ -587,12 +638,12 @@ void ctskymap::bkg_subtract_irf(GCTAObservation* obs)
587 } 638 }
588 639
589 // Multiply background rate with livetime and solid angle 640 // Multiply background rate with livetime and solid angle
590 - value *= obs->livetime() * m_skymap.solidangle(i); 641 + value *= obs->livetime() * m_bkgmap.solidangle(i);
591 642
592 - // Subtract background value from sky map  
593 - m_skymap(i,0) -= value; 643 + // Add number of background events to background map
  644 + m_bkgmap(i,0) += value;
594 645
595 - } // endfor: looped over sky map pixels 646 + } // endfor: looped over background map pixels
596 647
597 // Return 648 // Return
598 return; 649 return;
src/ctskymap/ctskymap.hpp
@@ -70,8 +70,8 @@ protected: @@ -70,8 +70,8 @@ protected:
70 void free_members(void); 70 void free_members(void);
71 void get_parameters(void); 71 void get_parameters(void);
72 void map_events(GCTAObservation* obs); 72 void map_events(GCTAObservation* obs);
73 - void bkg_subtract(GCTAObservation* obs);  
74 - void bkg_subtract_irf(GCTAObservation* obs); 73 + void map_background(GCTAObservation* obs);
  74 + void map_background_irf(GCTAObservation* obs);
75 75
76 // User parameters 76 // User parameters
77 GFilename m_outmap; //!< Output file name 77 GFilename m_outmap; //!< Output file name
@@ -83,6 +83,8 @@ protected: @@ -83,6 +83,8 @@ protected:
83 83
84 // Protected members 84 // Protected members
85 GSkyMap m_skymap; //!< Sky map 85 GSkyMap m_skymap; //!< Sky map
  86 + GSkyMap m_bkgmap; //!< Background map
  87 + GSkyMap m_sigmap; //!< Significance map
86 }; 88 };
87 89
88 90
src/ctskymap/ctskymap.par
@@ -17,6 +17,8 @@ @@ -17,6 +17,8 @@
17 # General parameters 17 # General parameters
18 #=================== 18 #===================
19 inobs, f, a, "events.fits",,, "Input event list or observation definition XML file" 19 inobs, f, a, "events.fits",,, "Input event list or observation definition XML file"
  20 +caldb, s, a, "prod2",,, "Calibration database"
  21 +irf, s, a, "South_0.5h",,, "Instrument response function"
20 outmap, f, a, "skymap.fits",,, "Output skymap file" 22 outmap, f, a, "skymap.fits",,, "Output skymap file"
21 23
22 # 24 #
test/test_ctskymap.py
@@ -70,7 +70,7 @@ class Test(test): @@ -70,7 +70,7 @@ class Test(test):
70 ' outmap="ctskymap_cmd1.fits"'+ \ 70 ' outmap="ctskymap_cmd1.fits"'+ \
71 ' emin=0.1 emax=100.0 nxpix=200 nypix=200'+ \ 71 ' emin=0.1 emax=100.0 nxpix=200 nypix=200'+ \
72 ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \ 72 ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \
73 - ' xref=83.63 yref=22.01'+ \ 73 + ' xref=83.63 yref=22.01 bkgsubtract="NONE"'+ \
74 ' logfile="ctskymap_cmd1.log" chatter=1' 74 ' logfile="ctskymap_cmd1.log" chatter=1'
75 75
76 # Check if execution of wrong command fails 76 # Check if execution of wrong command fails
@@ -89,7 +89,7 @@ class Test(test): @@ -89,7 +89,7 @@ class Test(test):
89 ' outmap="ctskymap_cmd2.fits"'+ \ 89 ' outmap="ctskymap_cmd2.fits"'+ \
90 ' emin=0.1 emax=100.0 nxpix=200 nypix=200'+ \ 90 ' emin=0.1 emax=100.0 nxpix=200 nypix=200'+ \
91 ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \ 91 ' binsz=0.02 coordsys="CEL" proj="CAR"'+ \
92 - ' xref=83.63 yref=22.01'+ \ 92 + ' xref=83.63 yref=22.01 bkgsubtract="NONE"'+ \
93 ' logfile="ctskymap_cmd2.log" chatter=2' 93 ' logfile="ctskymap_cmd2.log" chatter=2'
94 94
95 # Check if execution failed 95 # Check if execution failed
@@ -134,19 +134,20 @@ class Test(test): @@ -134,19 +134,20 @@ class Test(test):
134 skymap.clear() 134 skymap.clear()
135 135
136 # Now set ctskymap parameters 136 # Now set ctskymap parameters
137 - skymap['inobs'] = self._events  
138 - skymap['emin'] = 0.1  
139 - skymap['emax'] = 100  
140 - skymap['nxpix'] = 200  
141 - skymap['nypix'] = 200  
142 - skymap['binsz'] = 0.02  
143 - skymap['coordsys'] = 'CEL'  
144 - skymap['proj'] = 'CAR'  
145 - skymap['xref'] = 83.63  
146 - skymap['yref'] = 22.01  
147 - skymap['outmap'] = 'ctskymap_py1.fits'  
148 - skymap['logfile'] = 'ctskymap_py1.log'  
149 - skymap['chatter'] = 2 137 + skymap['inobs'] = self._events
  138 + skymap['emin'] = 0.1
  139 + skymap['emax'] = 100
  140 + skymap['nxpix'] = 200
  141 + skymap['nypix'] = 200
  142 + skymap['binsz'] = 0.02
  143 + skymap['coordsys'] = 'CEL'
  144 + skymap['proj'] = 'CAR'
  145 + skymap['xref'] = 83.63
  146 + skymap['yref'] = 22.01
  147 + skymap['bkgsubtract'] = 'NONE'
  148 + skymap['outmap'] = 'ctskymap_py1.fits'
  149 + skymap['logfile'] = 'ctskymap_py1.log'
  150 + skymap['chatter'] = 2
150 151
151 # Run ctskymap tool 152 # Run ctskymap tool
152 skymap.logFileOpen() # Make sure we get a log file 153 skymap.logFileOpen() # Make sure we get a log file
@@ -190,18 +191,19 @@ class Test(test): @@ -190,18 +191,19 @@ class Test(test):
190 191
191 # Allocate ctskymap tool from observation container 192 # Allocate ctskymap tool from observation container
192 skymap = ctools.ctskymap(obs) 193 skymap = ctools.ctskymap(obs)
193 - skymap['emin'] = 0.1  
194 - skymap['emax'] = 100  
195 - skymap['nxpix'] = 200  
196 - skymap['nypix'] = 200  
197 - skymap['binsz'] = 0.02  
198 - skymap['coordsys'] = 'GAL'  
199 - skymap['proj'] = 'CAR'  
200 - skymap['xref'] = 184.5575  
201 - skymap['yref'] = -5.7844  
202 - skymap['outmap'] = 'ctskymap_py3.fits'  
203 - skymap['logfile'] = 'ctskymap_py3.log'  
204 - skymap['chatter'] = 4 194 + skymap['emin'] = 0.1
  195 + skymap['emax'] = 100
  196 + skymap['nxpix'] = 200
  197 + skymap['nypix'] = 200
  198 + skymap['binsz'] = 0.02
  199 + skymap['coordsys'] = 'GAL'
  200 + skymap['proj'] = 'CAR'
  201 + skymap['xref'] = 184.5575
  202 + skymap['yref'] = -5.7844
  203 + skymap['bkgsubtract'] = 'NONE'
  204 + skymap['outmap'] = 'ctskymap_py3.fits'
  205 + skymap['logfile'] = 'ctskymap_py3.log'
  206 + skymap['chatter'] = 4
205 207
206 # Execute tool 208 # Execute tool
207 skymap.logFileOpen() # Needed to get a new log file 209 skymap.logFileOpen() # Needed to get a new log file
@@ -213,6 +215,31 @@ class Test(test): @@ -213,6 +215,31 @@ class Test(test):
213 # Publish with name 215 # Publish with name
214 skymap.publish('My sky map') 216 skymap.publish('My sky map')
215 217
  218 + # Allocate ctskymap tool from observation container
  219 + skymap = ctools.ctskymap(obs)
  220 + skymap['emin'] = 0.1
  221 + skymap['emax'] = 100
  222 + skymap['nxpix'] = 200
  223 + skymap['nypix'] = 200
  224 + skymap['binsz'] = 0.02
  225 + skymap['coordsys'] = 'GAL'
  226 + skymap['proj'] = 'CAR'
  227 + skymap['xref'] = 184.5575
  228 + skymap['yref'] = -5.7844
  229 + skymap['bkgsubtract'] = 'IRF'
  230 + skymap['caldb'] = self._caldb
  231 + skymap['irf'] = self._irf
  232 + skymap['outmap'] = 'ctskymap_py4.fits'
  233 + skymap['logfile'] = 'ctskymap_py4.log'
  234 + skymap['chatter'] = 4
  235 +
  236 + # Execute tool
  237 + skymap.logFileOpen() # Needed to get a new log file
  238 + skymap.execute()
  239 +
  240 + # Check result file
  241 + self._check_result_file('ctskymap_py3.fits')
  242 +
216 # Return 243 # Return
217 return 244 return
218 245