Commit 50c2d0a7b26f827aeeef0f04e00092fd0cec045c

Authored by Jürgen Knödlseder
1 parent d8468231

Add On/Off pull distribution to science verification

cscripts/cspull.par
... ... @@ -18,7 +18,7 @@
18 18 #============================
19 19 inobs, f, h, NONE,,, "Input event list, counts cube, or observation definition XML file"
20 20 inmodel, f, a, $CTOOLS/share/models/crab.xml,,, "Input model definition XML file"
21   -onsrc, s, a, ,,, "Name of On source (only for On/Off analysis)"
  21 +onsrc, s, a, NONE,,, "Name of On source (only for On/Off analysis)"
22 22 onrad, r, a, 0.2,,, "Radius of On region (deg)"
23 23 caldb, s, a, prod2,,, "Calibration database"
24 24 irf, s, a, South_0.5h,,, "Instrument response function"
... ...
cscripts/cspull.py
... ... @@ -65,7 +65,7 @@ class cspull(ctools.csobservation):
65 65 enumbins = self['enumbins'].integer()
66 66  
67 67 # Query parameters for On/Off observation
68   - if len(self['onsrc'].string()) > 0:
  68 + if gammalib.toupper(self['onsrc'].string()) != 'NONE':
69 69 self['onrad'].real()
70 70  
71 71 # Query parameters for binned if requested
... ... @@ -112,7 +112,7 @@ class cspull(ctools.csobservation):
112 112 # Extract information from observation
113 113 if obs.classname() == 'GCTAOnOffObservation':
114 114 emin = obs.on_spec().ebounds().emin().TeV()
115   - emax = obs.on_spec().ebounds().emin().TeV()
  115 + emax = obs.on_spec().ebounds().emax().TeV()
116 116 mode = 'On/Off'
117 117 else:
118 118 emin = obs.events().ebounds().emin().TeV()
... ... @@ -164,7 +164,7 @@ class cspull(ctools.csobservation):
164 164 coordsys = 'CEL'
165 165  
166 166 # If we have a On source name then set On region radius
167   - if len(onsrc) > 0:
  167 + if gammalib.toupper(onsrc) != 'NONE':
168 168 onrad = self['onrad'].real()
169 169 emin = self['emin'].real()
170 170 emax = self['emax'].real()
... ...
doc/source/users/reference_manual/cspull.rst
... ... @@ -41,6 +41,12 @@ General parameters
41 41 ``inmodel [file]``
42 42 Input model XML file.
43 43  
  44 +``onsrc [string]``
  45 + Name of On source (only for On/Off analysis; specify ``NONE`` for other analyses).
  46 +
  47 +``onrad [real]``
  48 + Radius of On region (deg).
  49 +
44 50 ``caldb [string]``
45 51 Calibration database.
46 52  
... ...
test/data/sciver/crab_plaw_onoff.xml 0 → 100644
  1 +<?xml version="1.0" standalone="no"?>
  2 +<source_library title="source library">
  3 + <source name="Crab" type="PointSource">
  4 + <spectrum type="PowerLaw">
  5 + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/>
  6 + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
  7 + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
  8 + </spectrum>
  9 + <spatialModel type="PointSource">
  10 + <parameter name="RA" scale="1.0" value="83.6331" min="-360" max="360" free="0"/>
  11 + <parameter name="DEC" scale="1.0" value="22.0145" min="-90" max="90" free="0"/>
  12 + </spatialModel>
  13 + </source>
  14 + <source name="Background" type="CTAIrfBackground" instrument="CTA">
  15 + <spectrum type="PowerLaw">
  16 + <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e3" free="1"/>
  17 + <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/>
  18 + <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/>
  19 + </spectrum>
  20 + </source>
  21 +</source_library>
... ...
test/data/sciver/obs_onoff.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<observation_list title="observation list">
  3 + <observation name="Crab" id="0001" instrument="CTA" statistic="cstat">
  4 + <parameter name="Pointing" ra="83.63" dec="22.51" />
  5 + <parameter name="GoodTimeIntervals" tmin="0" tmax="900" />
  6 + <parameter name="TimeReference" mjdrefi="51544" mjdreff="0.5" timeunit="s" timesys="TT" timeref="LOCAL" />
  7 + <parameter name="Deadtime" deadc="0.98" />
  8 + <parameter name="Calibration" database="Prod2" response="South_0.5h" />
  9 + </observation>
  10 + <observation name="Crab" id="0002" instrument="CTA" statistic="cstat">
  11 + <parameter name="Pointing" ra="83.63" dec="21.51" />
  12 + <parameter name="GoodTimeIntervals" tmin="900" tmax="1800" />
  13 + <parameter name="TimeReference" mjdrefi="51544" mjdreff="0.5" timeunit="s" timesys="TT" timeref="LOCAL" />
  14 + <parameter name="Deadtime" deadc="0.98" />
  15 + <parameter name="Calibration" database="Prod2" response="South_0.5h" />
  16 + </observation>
  17 +</observation_list>
  18 +
... ...
test/science_verification.py
... ... @@ -39,8 +39,8 @@ import cscripts
39 39 # ========================== #
40 40 # Generate pull distribution #
41 41 # ========================== #
42   -def generate_pull_distribution(model, obs='NONE', trials=100, \
43   - caldb='prod2', irf='South_50h', \
  42 +def generate_pull_distribution(model, obs='NONE', onsrc='NONE', onrad=0.2, \
  43 + trials=100, caldb='prod2', irf='South_50h', \
44 44 deadc=0.98, edisp=False, \
45 45 ra=83.63, dec=22.01, rad=5.0, \
46 46 emin=0.1, emax=100.0, enumbins=0, \
... ... @@ -57,6 +57,10 @@ def generate_pull_distribution(model, obs=&#39;NONE&#39;, trials=100, \
57 57 Model XML filename (without .xml extension)
58 58 obs : str, optional
59 59 Input observation definition XML filename
  60 + onsrc : str, optional
  61 + Name of On source for On/Off analysis
  62 + onrad : float, optional
  63 + Radius of On region
60 64 trials : int, optional
61 65 Number of trials
62 66 caldb : str, optional
... ... @@ -108,6 +112,8 @@ def generate_pull_distribution(model, obs=&#39;NONE&#39;, trials=100, \
108 112 pull = cscripts.cspull()
109 113 pull['inobs'] = obs
110 114 pull['inmodel'] = inmodel
  115 + pull['onsrc'] = onsrc
  116 + pull['onrad'] = onrad
111 117 pull['outfile'] = outfile
112 118 pull['caldb'] = caldb
113 119 pull['irf'] = irf
... ... @@ -164,7 +170,6 @@ def analyse_pull_distribution(filename):
164 170  
165 171 # Read rows
166 172 first = True
167   - #index = -1
168 173 samples = 0.0
169 174 for row in reader:
170 175  
... ... @@ -237,6 +242,7 @@ class sciver(gammalib.GPythonTestSuite):
237 242 self.append(self.spec_plaw, 'Test power law model')
238 243 self.append(self.spec_plaw_edisp, 'Test power law model with energy dispersion')
239 244 self.append(self.spec_plaw_stacked, 'Test power law model with stacked analysis')
  245 + self.append(self.spec_plaw_onoff, 'Test power law model with On/Off analysis')
240 246 self.append(self.spec_plaw2, 'Test power law 2 model')
241 247 self.append(self.spec_smoothbplaw, 'Test smoothly broken power law model')
242 248 self.append(self.spec_eplaw, 'Test exponentially cut off power law model')
... ... @@ -263,7 +269,8 @@ class sciver(gammalib.GPythonTestSuite):
263 269 return
264 270  
265 271 # Generate and analyse pull distributions
266   - def pull(self, model, obs='NONE', trials=100, duration=1800.0,
  272 + def pull(self, model, obs='NONE', onsrc='NONE',
  273 + trials=100, duration=1800.0,
267 274 ra=83.63, dec=22.01, rad=5.0,
268 275 emin=0.1, emax=100.0, enumbins=0,
269 276 edisp=False, debug=False):
... ... @@ -276,6 +283,8 @@ class sciver(gammalib.GPythonTestSuite):
276 283 Model XML filename (without .xml extension)
277 284 obs : str, optional
278 285 Input observation definition XML filename
  286 + onsrc : str, optional
  287 + Name of On source for On/Off analysis
279 288 trials : int, optional
280 289 Number of trials
281 290 duration : float, optional
... ... @@ -298,8 +307,8 @@ class sciver(gammalib.GPythonTestSuite):
298 307 Enable debugging?
299 308 """
300 309 # Generate pull distribution
301   - outfile = generate_pull_distribution(model, obs=obs, trials=trials,
302   - duration=duration,
  310 + outfile = generate_pull_distribution(model, obs=obs, onsrc=onsrc,
  311 + trials=trials, duration=duration,
303 312 ra=ra, dec=dec, rad=rad,
304 313 emin=emin, emax=emax,
305 314 enumbins=enumbins,
... ... @@ -402,6 +411,20 @@ class sciver(gammalib.GPythonTestSuite):
402 411 self.test('Pull_BackgroundModel_Index')
403 412 return
404 413  
  414 + # Test power law model with On/Off analysis
  415 + def spec_plaw_onoff(self):
  416 + """
  417 + Test power law model with On/Off analysis
  418 + """
  419 + self.pull('data/sciver/crab_plaw_onoff',
  420 + obs='data/sciver/obs_onoff.xml', onsrc='Crab',
  421 + emin=0.1, emax=100.0, enumbins=20)
  422 + self.test('Pull_Crab_Prefactor')
  423 + self.test('Pull_Crab_Index')
  424 + self.test('Pull_Background_Prefactor')
  425 + self.test('Pull_Background_Index')
  426 + return
  427 +
405 428 # Test power law 2 model
406 429 def spec_plaw2(self):
407 430 """
... ...