Commit 0b1dbd1a661e9e201a524f277e050ac535a754ff
1 parent
be3e4fa0
Revert some code changes made for debugging
Showing
2 changed files
with
20 additions
and
42 deletions
scripts/cspull.py
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | # ========================================================================== | 2 | # ========================================================================== |
| 3 | # This script generates the pull distribution for all model parameters. | 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 | # 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 |
| 8 | # it under the terms of the GNU General Public License as published by | 8 | # it under the terms of the GNU General Public License as published by |
| @@ -19,7 +19,7 @@ | @@ -19,7 +19,7 @@ | ||
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | import gammalib | 21 | import gammalib |
| 22 | -import ctools | 22 | +#import ctools |
| 23 | #import obsutils | 23 | #import obsutils |
| 24 | from ctools import obsutils | 24 | from ctools import obsutils |
| 25 | import sys | 25 | import sys |
| @@ -46,8 +46,8 @@ class cspull(gammalib.GApplication): | @@ -46,8 +46,8 @@ class cspull(gammalib.GApplication): | ||
| 46 | self.version = "0.4.0" | 46 | self.version = "0.4.0" |
| 47 | 47 | ||
| 48 | # Initialise some members | 48 | # Initialise some members |
| 49 | - self.obs = None | ||
| 50 | - self.model = None | 49 | + self.obs = None |
| 50 | + self.model = None | ||
| 51 | self.m_inmodel = None | 51 | self.m_inmodel = None |
| 52 | 52 | ||
| 53 | # Make sure that parfile exists | 53 | # Make sure that parfile exists |
| @@ -123,16 +123,7 @@ class cspull(gammalib.GApplication): | @@ -123,16 +123,7 @@ class cspull(gammalib.GApplication): | ||
| 123 | """ | 123 | """ |
| 124 | Get parameters from parfile and setup the observation. | 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 | if self.model == None: | 127 | if self.model == None: |
| 137 | self.m_inmodel = self["inmodel"].filename() | 128 | self.m_inmodel = self["inmodel"].filename() |
| 138 | self.m_outfile = self["outfile"].filename() | 129 | self.m_outfile = self["outfile"].filename() |
| @@ -155,7 +146,7 @@ class cspull(gammalib.GApplication): | @@ -155,7 +146,7 @@ class cspull(gammalib.GApplication): | ||
| 155 | 146 | ||
| 156 | # Set some fixed parameters | 147 | # Set some fixed parameters |
| 157 | self.m_log = False # Logging in client tools | 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 | # Setup observations | 151 | # Setup observations |
| 161 | self.obs = self.set_obs() | 152 | self.obs = self.set_obs() |
| @@ -271,23 +262,18 @@ class cspull(gammalib.GApplication): | @@ -271,23 +262,18 @@ class cspull(gammalib.GApplication): | ||
| 271 | if self.logExplicit(): | 262 | if self.logExplicit(): |
| 272 | self.log.header2("Trial "+str(seed+1)) | 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 | # Simulate events | 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 | # Determine number of events in simulation | 274 | # Determine number of events in simulation |
| 289 | nevents = 0.0 | 275 | nevents = 0.0 |
| 290 | - for run in sim_obs: | 276 | + for run in obs: |
| 291 | nevents += run.events().number() | 277 | nevents += run.events().number() |
| 292 | 278 | ||
| 293 | # Write simulation results | 279 | # Write simulation results |
| @@ -298,10 +284,8 @@ class cspull(gammalib.GApplication): | @@ -298,10 +284,8 @@ class cspull(gammalib.GApplication): | ||
| 298 | self.log("\n") | 284 | self.log("\n") |
| 299 | 285 | ||
| 300 | # Fit model | 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 | # Store results | 290 | # Store results |
| 307 | logL = like.opt().value() | 291 | logL = like.opt().value() |
| @@ -338,7 +322,7 @@ class cspull(gammalib.GApplication): | @@ -338,7 +322,7 @@ class cspull(gammalib.GApplication): | ||
| 338 | 322 | ||
| 339 | # Compute pull | 323 | # Compute pull |
| 340 | fitted_value = par.value() | 324 | fitted_value = par.value() |
| 341 | - real_value = self.obs.models()[i][k].value() | 325 | + real_value = self.model[i][k].value() |
| 342 | error = par.error() | 326 | error = par.error() |
| 343 | if error != 0.0: | 327 | if error != 0.0: |
| 344 | pull = (fitted_value - real_value) / error | 328 | pull = (fitted_value - real_value) / error |
scripts/cstsdist.py
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | # This script generates the TS distribution for a particular model based | 3 | # This script generates the TS distribution for a particular model based |
| 4 | # on Monte-Carlo simulations. | 4 | # on Monte-Carlo simulations. |
| 5 | # | 5 | # |
| 6 | -# Copyright (C) 2011-2014 Juergen Knoedlseder | 6 | +# Copyright (C) 2011-2015 Juergen Knoedlseder |
| 7 | # | 7 | # |
| 8 | # This program is free software: you can redistribute it and/or modify | 8 | # This program is free software: you can redistribute it and/or modify |
| 9 | # it under the terms of the GNU General Public License as published by | 9 | # it under the terms of the GNU General Public License as published by |
| @@ -42,7 +42,7 @@ class cstsdist(GApplication): | @@ -42,7 +42,7 @@ class cstsdist(GApplication): | ||
| 42 | """ | 42 | """ |
| 43 | # Set name | 43 | # Set name |
| 44 | self.name = "cstsdist" | 44 | self.name = "cstsdist" |
| 45 | - self.version = "0.1.0" | 45 | + self.version = "0.2.0" |
| 46 | 46 | ||
| 47 | # Initialise some members | 47 | # Initialise some members |
| 48 | self.obs = None | 48 | self.obs = None |
| @@ -381,11 +381,6 @@ class cstsdist(GApplication): | @@ -381,11 +381,6 @@ class cstsdist(GApplication): | ||
| 381 | self.log.parformat("Number of simulated events") | 381 | self.log.parformat("Number of simulated events") |
| 382 | self.log(nevents) | 382 | self.log(nevents) |
| 383 | self.log("\n") | 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 | # Fit background only | 385 | # Fit background only |
| 391 | sim.models(self.bkg_model) | 386 | sim.models(self.bkg_model) |
| @@ -413,7 +408,6 @@ class cstsdist(GApplication): | @@ -413,7 +408,6 @@ class cstsdist(GApplication): | ||
| 413 | # Fit background and test source | 408 | # Fit background and test source |
| 414 | sim.models(self.full_model) | 409 | sim.models(self.full_model) |
| 415 | like_all = obsutils.fit(sim, log=self.m_log, debug=self.m_debug) | 410 | like_all = obsutils.fit(sim, log=self.m_log, debug=self.m_debug) |
| 416 | - print like_all.obs().models() | ||
| 417 | result_all = like_all.obs().models() | 411 | result_all = like_all.obs().models() |
| 418 | LogL_all = like_all.opt().value() | 412 | LogL_all = like_all.opt().value() |
| 419 | npred_all = like_all.obs().npred() | 413 | npred_all = like_all.obs().npred() |