Commit d75e51d0fd1b61d2fb3b16a6e5c6086dec2a3e71
1 parent
e47a5b50
Properly implement usage of cterror in cspull.
cspull now loops over all model components and call cterror for each model component.
Showing
2 changed files
with
16 additions
and
8 deletions
pyext/ctools/obsutils.py
| ... | ... | @@ -172,12 +172,13 @@ def fit(obs, log=False, debug=False, chatter=2, edisp=False): |
| 172 | 172 | # ============================================================== # |
| 173 | 173 | # Fit observations and determine errors using likelihood profile # |
| 174 | 174 | # ============================================================== # |
| 175 | -def cterror(obs, log=False, debug=False, chatter=2): | |
| 175 | +def cterror(obs, srcname, log=False, debug=False, chatter=2): | |
| 176 | 176 | """ |
| 177 | 177 | Perform maximum likelihood fitting of observations in the container. |
| 178 | 178 | |
| 179 | 179 | Parameters: |
| 180 | - obs - Observation container | |
| 180 | + obs - Observation container | |
| 181 | + srcname - Source name | |
| 181 | 182 | Keywords: |
| 182 | 183 | log - Create log file(s) |
| 183 | 184 | debug - Create screen dump |
| ... | ... | @@ -186,6 +187,9 @@ def cterror(obs, log=False, debug=False, chatter=2): |
| 186 | 187 | """ |
| 187 | 188 | # Allocate cterror application |
| 188 | 189 | error = ctools.cterror(obs) |
| 190 | + | |
| 191 | + # Set cterror parameters | |
| 192 | + error["srcname"].string(srcname) | |
| 189 | 193 | |
| 190 | 194 | # Optionally open the log file |
| 191 | 195 | if log: | ... | ... |
scripts/cspull.py
| ... | ... | @@ -276,7 +276,7 @@ class cspull(ctools.cscript): |
| 276 | 276 | seed - Random number generator seed |
| 277 | 277 | """ |
| 278 | 278 | # Write header |
| 279 | - if self.logExplicit(): | |
| 279 | + if self.logNormal(): | |
| 280 | 280 | self.log.header2("Trial "+str(seed+1)) |
| 281 | 281 | |
| 282 | 282 | # Simulate events |
| ... | ... | @@ -294,7 +294,7 @@ class cspull(ctools.cscript): |
| 294 | 294 | nevents += run.events().number() |
| 295 | 295 | |
| 296 | 296 | # Write simulation results |
| 297 | - if self.logExplicit(): | |
| 297 | + if self.logNormal(): | |
| 298 | 298 | self.log.header3("Simulation") |
| 299 | 299 | self.log.parformat("Number of simulated events") |
| 300 | 300 | self.log(nevents) |
| ... | ... | @@ -302,8 +302,12 @@ class cspull(ctools.cscript): |
| 302 | 302 | |
| 303 | 303 | # Fit model |
| 304 | 304 | if self.m_profile: |
| 305 | - like = obsutils.cterror(obs, \ | |
| 306 | - log=self.m_log, debug=self.m_debug) | |
| 305 | + models = obs.models() | |
| 306 | + for i in range(models.size()): | |
| 307 | + model_name = models[i].name() | |
| 308 | + like = obsutils.cterror(obs, model_name, \ | |
| 309 | + log=self.m_log, \ | |
| 310 | + debug=self.m_debug) | |
| 307 | 311 | else: |
| 308 | 312 | like = obsutils.fit(obs, edisp=self.m_edisp, \ |
| 309 | 313 | log=self.m_log, debug=self.m_debug) |
| ... | ... | @@ -314,7 +318,7 @@ class cspull(ctools.cscript): |
| 314 | 318 | models = like.obs().models() |
| 315 | 319 | |
| 316 | 320 | # Write result header |
| 317 | - if self.logExplicit(): | |
| 321 | + if self.logNormal(): | |
| 318 | 322 | self.log.header3("Pulls") |
| 319 | 323 | |
| 320 | 324 | # Gather results |
| ... | ... | @@ -356,7 +360,7 @@ class cspull(ctools.cscript): |
| 356 | 360 | values["Unc_"+name] = error |
| 357 | 361 | |
| 358 | 362 | # Write result |
| 359 | - if self.logExplicit(): | |
| 363 | + if self.logNormal(): | |
| 360 | 364 | self.log.parformat(name) |
| 361 | 365 | self.log(pull) |
| 362 | 366 | self.log(" (") | ... | ... |