Commit cd7164011b9c2aac26e01174f46d7e43ab6c3c4d

Authored by Jürgen Knödlseder
1 parent 79f16c8e

Add handling of D2 modules with failed PMT flag to comobsbin and support DRBPhib…

…arBins in comobsmodel script
ChangeLog
1 -2021-11-29 1 +2021-12-01
2 2
3 * Version 2.0.0 released 3 * Version 2.0.0 released
4 ======================== 4 ========================
5 5
6 - Add phi_first and phi_last parameters to comlixfit and comlixmap (#3912)  
7 Add csadd2caldb script 6 Add csadd2caldb script
8 Add restart of bisection in case of bad convergence in ctulimit 7 Add restart of bisection in case of bad convergence in ctulimit
9 Add COMPTEL analysis scripts (#3738) 8 Add COMPTEL analysis scripts (#3738)
1 New Features and Important Changes in ctools 2.0.0 1 New Features and Important Changes in ctools 2.0.0
2 2
3 -29 November 2021 3 +1 December 2021
4 4
5 5
6 Introduction 6 Introduction
@@ -399,17 +399,11 @@ regions (#3248). @@ -399,17 +399,11 @@ regions (#3248).
399 399
400 comlixfit - COMPTEL maximum likelihood fitting using SRCLIX algorithm 400 comlixfit - COMPTEL maximum likelihood fitting using SRCLIX algorithm
401 --------------------------------------------------------------------- 401 ---------------------------------------------------------------------
402 -Added phi_first and phi_last parameters to allow selection of the Phibar layers  
403 -during the maximum likelihood fit (#3912).  
404 -  
405 Added script (#3738). 402 Added script (#3738).
406 403
407 404
408 comlixmap - Generation of COMPTEL Test Statistic map using SRCLIX algorithm 405 comlixmap - Generation of COMPTEL Test Statistic map using SRCLIX algorithm
409 --------------------------------------------------------------------------- 406 ---------------------------------------------------------------------------
410 -Added phi_first and phi_last parameters to allow selection of the Phibar layers  
411 -during the maximum likelihood fit (#3912).  
412 -  
413 Added script (#3738). 407 Added script (#3738).
414 408
415 409
README.md
1 ctools information 1 ctools information
2 ================== 2 ==================
3 -* Version: 2.0.0.dev (29 November 2021) 3 +* Version: 2.0.0.dev (1 December 2021)
4 * GammaLib dependency: 2.0.0.dev 4 * GammaLib dependency: 2.0.0.dev
5 5
6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/) 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/)
doc/source/users/reference_manual/comobsbin.rst
@@ -66,6 +66,18 @@ General parameters @@ -66,6 +66,18 @@ General parameters
66 ``(nphibar = 25) [integer]`` 66 ``(nphibar = 25) [integer]``
67 Number of bins in Phibar direction. 67 Number of bins in Phibar direction.
68 68
  69 +``(psdmin = 0) [integer]``
  70 + Minimum PSD value.
  71 +
  72 +``(psdmax = 110) [integer]``
  73 + Maximum PSD value.
  74 +
  75 +``(zetamin = 5.0) [real]``
  76 + Minimum Earth horizon - Phibar (zeta) angle (deg).
  77 +
  78 +``(fpmtflag = 0) [integer]``
  79 + Handling of D2 modules with failed PMT flag (0: exclude, 1: include, 2: exclude PMT).
  80 +
69 81
70 Standard parameters 82 Standard parameters
71 ------------------- 83 -------------------
doc/source/users/reference_manual/comobsmodel.rst
@@ -41,9 +41,12 @@ General parameters @@ -41,9 +41,12 @@ General parameters
41 ``iso <NONE|MAP|CUBE> [string]`` 41 ``iso <NONE|MAP|CUBE> [string]``
42 Isotropic component. 42 Isotropic component.
43 43
44 -``modeltype <NODES|BINS> [string]`` 44 +``diffusetype <NODES|BINS> [string]``
45 Diffuse model type. 45 Diffuse model type.
46 46
  47 +``bkgtype <NODES|BINS> [string]``
  48 + Background model type.
  49 +
47 ``(bremsmap = $COMDATA/../skymaps/galprop/map_comptel_bremsstrahlung.fits) [file]`` 50 ``(bremsmap = $COMDATA/../skymaps/galprop/map_comptel_bremsstrahlung.fits) [file]``
48 Bremsstrahlung map file name. 51 Bremsstrahlung map file name.
49 52
modules/comscripts/comobsbin.par
@@ -39,7 +39,8 @@ npsi, i, h, 80,1,500, &quot;Number of bins in Psi direction&quot; @@ -39,7 +39,8 @@ npsi, i, h, 80,1,500, &quot;Number of bins in Psi direction&quot;
39 nphibar, i, h, 25,1,100, "Number of bins in Phibar direction" 39 nphibar, i, h, 25,1,100, "Number of bins in Phibar direction"
40 psdmin, i, h, 0,0,110, "Minimum PSD value" 40 psdmin, i, h, 0,0,110, "Minimum PSD value"
41 psdmax, i, h, 110,0,110, "Maximum PSD value" 41 psdmax, i, h, 110,0,110, "Maximum PSD value"
42 -zetamin, r, h, 5.0,0.0,10.0, "Minimum Earth horizon - Phibar (zeta) angle" 42 +zetamin, r, h, 5.0,0.0,10.0, "Minimum Earth horizon - Phibar (zeta) angle (deg)"
  43 +fpmtflag, i, h, 0,0,2, "Handling of D2 modules with failed PMT flag (0: exclude, 1: include, 2: exclude PMT)"
43 44
44 # 45 #
45 # Standard parameters 46 # Standard parameters
modules/comscripts/comobsbin.py
@@ -74,6 +74,7 @@ class comobsbin(ctools.csobservation): @@ -74,6 +74,7 @@ class comobsbin(ctools.csobservation):
74 self['psdmin'].integer() 74 self['psdmin'].integer()
75 self['psdmax'].integer() 75 self['psdmax'].integer()
76 self['zetamin'].real() 76 self['zetamin'].real()
  77 + self['fpmtflag'].integer()
77 78
78 # Query ahead output model filename 79 # Query ahead output model filename
79 if self._read_ahead(): 80 if self._read_ahead():
@@ -191,13 +192,14 @@ class comobsbin(ctools.csobservation): @@ -191,13 +192,14 @@ class comobsbin(ctools.csobservation):
191 # Set phases 192 # Set phases
192 self._select.phases(self._phases) 193 self._select.phases(self._phases)
193 194
194 - # Set suffix 195 + # Set DRE, DRG and DRX suffix
195 phases = self['phase'].string() 196 phases = self['phase'].string()
196 - self._drx_suffix = '_phases'+phases.replace(';', '_')  
197 - self._drg_suffix = '_phases'+phases.replace(';', '_')  
198 self._dre_suffix = '_phases'+phases.replace(';', '_') 197 self._dre_suffix = '_phases'+phases.replace(';', '_')
  198 + self._drg_suffix = '_phases'+phases.replace(';', '_')
  199 + self._drx_suffix = '_phases'+phases.replace(';', '_')
199 200
200 # If PSD interval differs from standard interval then set the interval 201 # If PSD interval differs from standard interval then set the interval
  202 + # and append flag to suffix
201 if self['psdmin'].integer() != 0 or self['psdmax'].integer() != 110: 203 if self['psdmin'].integer() != 0 or self['psdmax'].integer() != 110:
202 204
203 # Set PSD interval 205 # Set PSD interval
@@ -208,10 +210,22 @@ class comobsbin(ctools.csobservation): @@ -208,10 +210,22 @@ class comobsbin(ctools.csobservation):
208 self._dre_suffix += '_psd%d-%d' % (self['psdmin'].integer(), 210 self._dre_suffix += '_psd%d-%d' % (self['psdmin'].integer(),
209 self['psdmax'].integer()) 211 self['psdmax'].integer())
210 212
211 - # If zeta angle differs from standard value then append zeta angle to suffix 213 + # If zeta angle differs from standard value then append zeta angle to DRE
  214 + # and DRG suffix
212 if self['zetamin'].real() != 5.0: 215 if self['zetamin'].real() != 5.0:
213 - self._drg_suffix += '_zeta%.1f' % (self['zetamin'].real())  
214 self._dre_suffix += '_zeta%.1f' % (self['zetamin'].real()) 216 self._dre_suffix += '_zeta%.1f' % (self['zetamin'].real())
  217 + self._drg_suffix += '_zeta%.1f' % (self['zetamin'].real())
  218 +
  219 + # If handling of D2 modules with failed PMT flag differs from standard then
  220 + # set the flag and append flag to suffix
  221 + if self['fpmtflag'].integer() != 0:
  222 +
  223 + # Set handling of D2 modules with failed PMT flag
  224 + self._select.fpmtflag(self['fpmtflag'].integer())
  225 +
  226 + # Set DRE and DRG suffix
  227 + self._dre_suffix += '_fpmt%1d' % (self['fpmtflag'].integer())
  228 + self._drg_suffix += '_fpmt%1d' % (self['fpmtflag'].integer())
215 229
216 # Log input observations 230 # Log input observations
217 self._log_string(gammalib.NORMAL, str(self._select)) 231 self._log_string(gammalib.NORMAL, str(self._select))
modules/comscripts/comobsmodel.par
@@ -22,18 +22,19 @@ outmodel, f, a, models.xml,,, &quot;Output model definition file&quot; @@ -22,18 +22,19 @@ outmodel, f, a, models.xml,,, &quot;Output model definition file&quot;
22 # 22 #
23 # Script parameters 23 # Script parameters
24 #================== 24 #==================
25 -ra, r, a, NONE,,, "Right Ascension of point source (deg)"  
26 -dec, r, a, NONE,,, "Declinaison of point source (deg)"  
27 -srcname, s, a, NONE,,, "Name of point source"  
28 -brems, s, a, NONE,NONE|MAP|CUBE,, "Bremsstrahlung component"  
29 -ic, s, a, NONE,NONE|MAP|CUBE,, "Inverse Compton component"  
30 -iso, s, a, NONE,NONE|CONST|CONSTFIX,, "Isotropic component"  
31 -modeltype, s, h, BINS,NODES|BINS,, "Diffuse model type"  
32 -ebinfile, f, h, NONE,,, "Name of the file containing the diffuse model energy bin definition"  
33 -bremsmap, f, h, $COMDATA/../skymaps/galprop/map_comptel_bremsstrahlung.fits,,, "Bremsstrahlungs map"  
34 -bremscube, f, h, $COMDATA/../skymaps/galprop/bremss_mapcube_54_77Xvarh7S.fits,,, "Bremsstrahlungs cube"  
35 -icmap, f, h, $COMDATA/../skymaps/galprop/map_comptel_ic.fits,,, "Inverse Compton map"  
36 -iccube, f, h, $COMDATA/../skymaps/galprop/ics_isotropic_mapcube_54_77Xvarh7S.fits,,, "Inverse Compton cube" 25 +ra, r, a, NONE,,, "Right Ascension of point source (deg)"
  26 +dec, r, a, NONE,,, "Declinaison of point source (deg)"
  27 +srcname, s, a, NONE,,, "Name of point source"
  28 +brems, s, a, NONE,NONE|MAP|CUBE,, "Bremsstrahlung component"
  29 +ic, s, a, NONE,NONE|MAP|CUBE,, "Inverse Compton component"
  30 +iso, s, a, NONE,NONE|CONST|CONSTFIX,, "Isotropic component"
  31 +diffusetype, s, h, BINS,NODES|BINS,, "Diffuse model type"
  32 +bkgtype, s, h, BINS,NODES|BINS,, "Background model type"
  33 +ebinfile, f, h, NONE,,, "Name of the file containing the diffuse model energy bin definition"
  34 +bremsmap, f, h, $COMDATA/../skymaps/galprop/map_comptel_bremsstrahlung.fits,,, "Bremsstrahlungs map"
  35 +bremscube, f, h, $COMDATA/../skymaps/galprop/bremss_mapcube_54_77Xvarh7S.fits,,, "Bremsstrahlungs cube"
  36 +icmap, f, h, $COMDATA/../skymaps/galprop/map_comptel_ic.fits,,, "Inverse Compton map"
  37 +iccube, f, h, $COMDATA/../skymaps/galprop/ics_isotropic_mapcube_54_77Xvarh7S.fits,,, "Inverse Compton cube"
37 38
38 # 39 #
39 # Standard parameters 40 # Standard parameters
modules/comscripts/comobsmodel.py
@@ -64,7 +64,8 @@ class comobsmodel(ctools.csobservation): @@ -64,7 +64,8 @@ class comobsmodel(ctools.csobservation):
64 self['brems'].string() 64 self['brems'].string()
65 self['ic'].string() 65 self['ic'].string()
66 self['iso'].string() 66 self['iso'].string()
67 - self['modeltype'].string() 67 + self['diffusetype'].string()
  68 + self['bkgtype'].string()
68 if self['ebinfile'].is_valid(): 69 if self['ebinfile'].is_valid():
69 self['ebinfile'].filename() 70 self['ebinfile'].filename()
70 self['bremsmap'].filename() 71 self['bremsmap'].filename()
@@ -111,9 +112,9 @@ class comobsmodel(ctools.csobservation): @@ -111,9 +112,9 @@ class comobsmodel(ctools.csobservation):
111 # Return energy boundaries 112 # Return energy boundaries
112 return ebounds 113 return ebounds
113 114
114 - def _generate_background_model(self, obs): 115 + def _generate_background_nodes_model(self, obs):
115 """ 116 """
116 - Generate background model component for observation 117 + Generate nodes background model component for observation
117 118
118 Parameters 119 Parameters
119 ---------- 120 ----------
@@ -164,6 +165,60 @@ class comobsmodel(ctools.csobservation): @@ -164,6 +165,60 @@ class comobsmodel(ctools.csobservation):
164 # Return model 165 # Return model
165 return model 166 return model
166 167
  168 + def _generate_background_bins_model(self, obs):
  169 + """
  170 + Generate bins background model component for observation
  171 +
  172 + Parameters
  173 + ----------
  174 + obs : `~gammalib.GCOMObservation`
  175 + COMPTEL observation
  176 +
  177 + Returns
  178 + -------
  179 + model : `~gammalib.GCOMModelDRBPhibarBins`
  180 + Background model
  181 + """
  182 + # Set model attributes
  183 + name = 'Background_%s' % obs.id()
  184 + id = obs.id()
  185 +
  186 + # Extract attributes from observation
  187 + drb = obs.drb()
  188 + npix = drb.nchi() * drb.npsi()
  189 + nphibar = drb.nphibar()
  190 + dphibar = 2.0 # Fixed so far as we have no method to recover
  191 +
  192 + # Create XML model list object
  193 + xml = gammalib.GXml()
  194 + lib = xml.append('source_library title="source library"')
  195 + src = lib.append('source name="%s" type="DRBPhibarBins" instrument="COM" id="%s"' % (name, id))
  196 +
  197 + # Loop over all phibar layers
  198 + for k in range(nphibar):
  199 +
  200 + # Compute DRB content for phibar layer
  201 + sum_drb = 0.0
  202 + for i in range(npix):
  203 + index = i + k * npix
  204 + sum_drb += drb[index]
  205 +
  206 + # Free or fix parameter
  207 + if sum_drb > 0.0:
  208 + free = '1'
  209 + else:
  210 + free = '0'
  211 +
  212 + # Add bin
  213 + src.append('parameter name="Normalization" value="1.00" '
  214 + 'scale="1" min="0" max="1000" free="%s"' % free)
  215 +
  216 + # Create background model from XML source element
  217 + model = gammalib.GCOMModelDRBPhibarBins(src)
  218 +
  219 + # Return model
  220 + return model
  221 +
167 def _generate_source_model(self): 222 def _generate_source_model(self):
168 """ 223 """
169 Generate source model 224 Generate source model
@@ -231,7 +286,7 @@ class comobsmodel(ctools.csobservation): @@ -231,7 +286,7 @@ class comobsmodel(ctools.csobservation):
231 ebds = ebounds 286 ebds = ebounds
232 287
233 # Re-sample model for 'NODES' model type 288 # Re-sample model for 'NODES' model type
234 - if self['modeltype'].string() == 'NODES': 289 + if self['diffusetype'].string() == 'NODES':
235 290
236 # Setup energies vector for bin mean energies 291 # Setup energies vector for bin mean energies
237 energies = gammalib.GEnergies() 292 energies = gammalib.GEnergies()
@@ -485,7 +540,10 @@ class comobsmodel(ctools.csobservation): @@ -485,7 +540,10 @@ class comobsmodel(ctools.csobservation):
485 self._log_string(gammalib.NORMAL, str(obs)) 540 self._log_string(gammalib.NORMAL, str(obs))
486 541
487 # Generate model 542 # Generate model
488 - model = self._generate_background_model(obs) 543 + if self['bkgtype'].string() == 'NODES':
  544 + model = self._generate_background_nodes_model(obs)
  545 + else:
  546 + model = self._generate_background_bins_model(obs)
489 547
490 # Log model 548 # Log model
491 self._log_string(gammalib.EXPLICIT, str(model)) 549 self._log_string(gammalib.EXPLICIT, str(model))