diff options
author | Stan Seibert <stan@mtrr.org> | 2011-10-13 14:58:55 -0400 |
---|---|---|
committer | tlatorre <tlatorre@uchicago.edu> | 2021-05-09 08:42:38 -0700 |
commit | 391ac356158d8c807e282b0438e9581321ac97fd (patch) | |
tree | 88ada2a989eb01a38938e5fe09ba8b32660f6f99 | |
parent | 5ef32be9b5a37ee2423452b72fe6a383c4c90316 (diff) | |
download | chroma-391ac356158d8c807e282b0438e9581321ac97fd.tar.gz chroma-391ac356158d8c807e282b0438e9581321ac97fd.tar.bz2 chroma-391ac356158d8c807e282b0438e9581321ac97fd.zip |
Factor calculation of channel hit probabilities and PDF densities to separate function for easier debugging of channel-level likelihood behavior.
-rw-r--r-- | chroma/likelihood.py | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/chroma/likelihood.py b/chroma/likelihood.py index cbd6187..9c4010d 100644 --- a/chroma/likelihood.py +++ b/chroma/likelihood.py @@ -41,14 +41,14 @@ class Likelihood(object): "Set the detector event being reconstructed." self.event = event - @profile_if_possible - def eval(self, vertex_generator, nevals, nreps=16, ndaq=50): - """ - Return the negative log likelihood that the detector event set in the - constructor or by set_event() was the result of a particle generated - by `vertex_generator`. If `nreps` set to > 1, each set of photon - vertices will be propagated `nreps` times. - """ + def eval_channel_vbin(self, vertex_generator, nevals, nreps=16, ndaq=50): + '''Evaluate the hit probability and observable (time or + time+charge) probability density for each channel using the + variable bin window method. + + Returns: (array of hit probabilities, array of PDF values) + ''' + ntotal = nevals * nreps * ndaq vertex_generator = islice(vertex_generator, nevals) @@ -77,9 +77,24 @@ class Likelihood(object): print 'channels with no data:', (bad_value & self.event.channels.hit).astype(int).sum() + return hit_prob, pdf_prob, pdf_prob_uncert + + @profile_if_possible + def eval(self, vertex_generator, nevals, nreps=16, ndaq=50): + """ + Return the negative log likelihood that the detector event set in the + constructor or by set_event() was the result of a particle generated + by `vertex_generator`. If `nreps` set to > 1, each set of photon + vertices will be propagated `nreps` times. + """ + + hit_prob, pdf_prob, pdf_prob_uncert = \ + self.eval_channel_vbin(vertex_generator, nevals, nreps, ndaq) + # NLL calculation: note that negation is at the end # Start with the probabilties of hitting (or not) the channels - hit_channel_prob = np.log(hit_prob[self.event.channels.hit]).sum() + np.log(1.0-hit_prob[~self.event.channels.hit]).sum() + hit_channel_prob = np.log(hit_prob[self.event.channels.hit]).sum() \ + + np.log(1.0-hit_prob[~self.event.channels.hit]).sum() log_likelihood = ufloat((hit_channel_prob, 0.0)) # Then include the probability densities of the observed |