Commit 0b1dbd1a661e9e201a524f277e050ac535a754ff

Authored by Jürgen Knödlseder
1 parent be3e4fa0

Revert some code changes made for debugging

scripts/cspull.py
... ... @@ -2,7 +2,7 @@
2 2 # ==========================================================================
3 3 # This script generates the pull distribution for all model parameters.
4 4 #
5   -# Copyright (C) 2011-2014 Juergen Knoedlseder
  5 +# Copyright (C) 2011-2015 Juergen Knoedlseder
6 6 #
7 7 # This program is free software: you can redistribute it and/or modify
8 8 # it under the terms of the GNU General Public License as published by
... ... @@ -19,7 +19,7 @@
19 19 #
20 20 # ==========================================================================
21 21 import gammalib
22   -import ctools
  22 +#import ctools
23 23 #import obsutils
24 24 from ctools import obsutils
25 25 import sys
... ... @@ -46,8 +46,8 @@ class cspull(gammalib.GApplication):
46 46 self.version = "0.4.0"
47 47  
48 48 # Initialise some members
49   - self.obs = None
50   - self.model = None
  49 + self.obs = None
  50 + self.model = None
51 51 self.m_inmodel = None
52 52  
53 53 # Make sure that parfile exists
... ... @@ -123,16 +123,7 @@ class cspull(gammalib.GApplication):
123 123 """
124 124 Get parameters from parfile and setup the observation.
125 125 """
126   -
127   -# sim = ctools.ctobssim()
128   -# sim.run()
129   -# self.obs = sim.obs()
130   -# sim = ctools.ctobssim()
131   -# sim.run()
132   -# self.obs = sim.obs().copy()
133   -# print self.obs
134   -#
135   -# # Get parameters
  126 + # Get parameters
136 127 if self.model == None:
137 128 self.m_inmodel = self["inmodel"].filename()
138 129 self.m_outfile = self["outfile"].filename()
... ... @@ -155,7 +146,7 @@ class cspull(gammalib.GApplication):
155 146  
156 147 # Set some fixed parameters
157 148 self.m_log = False # Logging in client tools
158   - self.m_debug = True # Debugging in client tools
  149 + self.m_debug = True # Debugging in client tools
159 150  
160 151 # Setup observations
161 152 self.obs = self.set_obs()
... ... @@ -271,23 +262,18 @@ class cspull(gammalib.GApplication):
271 262 if self.logExplicit():
272 263 self.log.header2("Trial "+str(seed+1))
273 264  
274   -# sim = ctools.ctobssim(self.obs)
275   -# sim["seed"].integer(seed)
276   -# sim.run()
277   - print self.obs
278 265 # Simulate events
279   - sim_obs = obsutils.sim(self.obs, \
280   - nbins=self.m_enumbins, \
281   - seed=seed, \
282   - binsz=self.m_binsz, \
283   - npix=self.m_npix, \
284   - edisp=self.m_edisp, \
285   - log=self.m_log, debug=self.m_debug)
286   - print "SIM"
287   - print sim_obs
  266 + obs = obsutils.sim(self.obs, \
  267 + nbins=self.m_enumbins, \
  268 + seed=seed, \
  269 + binsz=self.m_binsz, \
  270 + npix=self.m_npix, \
  271 + edisp=self.m_edisp, \
  272 + log=self.m_log, debug=self.m_debug)
  273 +
288 274 # Determine number of events in simulation
289 275 nevents = 0.0
290   - for run in sim_obs:
  276 + for run in obs:
291 277 nevents += run.events().number()
292 278  
293 279 # Write simulation results
... ... @@ -298,10 +284,8 @@ class cspull(gammalib.GApplication):
298 284 self.log("\n")
299 285  
300 286 # Fit model
301   - like = ctools.ctlike(sim_obs)
302   - like.run()
303   -# like = obsutils.fit(obs, edisp=self.m_edisp, \
304   -# log=self.m_log, debug=self.m_debug)
  287 + like = obsutils.fit(obs, edisp=self.m_edisp, \
  288 + log=self.m_log, debug=self.m_debug)
305 289  
306 290 # Store results
307 291 logL = like.opt().value()
... ... @@ -338,7 +322,7 @@ class cspull(gammalib.GApplication):
338 322  
339 323 # Compute pull
340 324 fitted_value = par.value()
341   - real_value = self.obs.models()[i][k].value()
  325 + real_value = self.model[i][k].value()
342 326 error = par.error()
343 327 if error != 0.0:
344 328 pull = (fitted_value - real_value) / error
... ...
scripts/cstsdist.py
... ... @@ -3,7 +3,7 @@
3 3 # This script generates the TS distribution for a particular model based
4 4 # on Monte-Carlo simulations.
5 5 #
6   -# Copyright (C) 2011-2014 Juergen Knoedlseder
  6 +# Copyright (C) 2011-2015 Juergen Knoedlseder
7 7 #
8 8 # This program is free software: you can redistribute it and/or modify
9 9 # it under the terms of the GNU General Public License as published by
... ... @@ -42,7 +42,7 @@ class cstsdist(GApplication):
42 42 """
43 43 # Set name
44 44 self.name = "cstsdist"
45   - self.version = "0.1.0"
  45 + self.version = "0.2.0"
46 46  
47 47 # Initialise some members
48 48 self.obs = None
... ... @@ -381,11 +381,6 @@ class cstsdist(GApplication):
381 381 self.log.parformat("Number of simulated events")
382 382 self.log(nevents)
383 383 self.log("\n")
384   -
385   -# sim.models(self.full_model)
386   -
387   -# like = obsutils.fit(sim, log = self.m_log, debug = self.m_debug)
388   -# ts = like.obs().models()["Test"].ts()
389 384  
390 385 # Fit background only
391 386 sim.models(self.bkg_model)
... ... @@ -413,7 +408,6 @@ class cstsdist(GApplication):
413 408 # Fit background and test source
414 409 sim.models(self.full_model)
415 410 like_all = obsutils.fit(sim, log=self.m_log, debug=self.m_debug)
416   - print like_all.obs().models()
417 411 result_all = like_all.obs().models()
418 412 LogL_all = like_all.opt().value()
419 413 npred_all = like_all.obs().npred()
... ...