Skip to content

Commit

Permalink
making seg physical also at low gains. no neg values.
Browse files Browse the repository at this point in the history
  • Loading branch information
cecilia-ferrari committed Dec 6, 2023
1 parent 6136f4d commit 1d3e219
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions flamedisx/lxe_blocks/final_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ class MakeFinalSignals(fd.Block):
signal_name: str

def _simulate(self, d):
d[self.signal_name] = stats.norm.rvs(
loc=(d[self.quanta_name + 's_detected']
* self.gimme_numpy(self.quanta_name + '_gain_mean')),
scale=(d[self.quanta_name + 's_detected']**0.5
* self.gimme_numpy(self.quanta_name + '_gain_std')))
if self.quanta_name == 'electron':
mean = (d[self.quanta_name + 's_detected']
* self.gimme_numpy(self.quanta_name + '_gain_mean'))
std = (d[self.quanta_name + 's_detected']**0.5
* self.gimme_numpy(self.quanta_name + '_gain_std'))
alfa = (mean/(std + 1e-10))**2
beta = mean/(std + 1e-10)**2
d[self.signal_name] = stats.gamma.rvs(
loc=alfa,
scale=1/beta)
else:
d[self.signal_name] = stats.norm.rvs(
loc=(d[self.quanta_name + 's_detected']
* self.gimme_numpy(self.quanta_name + '_gain_mean')),
scale=(d[self.quanta_name + 's_detected']**0.5
* self.gimme_numpy(self.quanta_name + '_gain_std')))

# Call add_extra_columns now, since s1 and s2 are known and derived
# observables from it (cs1, cs2) might be used in the acceptance.
Expand Down Expand Up @@ -76,9 +87,16 @@ def _compute(self,
std = quanta_detected ** 0.5 * std_per_q

# add offset to std to avoid NaNs from norm.pdf if std = 0
result = tfp.distributions.Normal(
loc=mean, scale=std + 1e-10
).prob(s_observed)
if self.quanta_name == 'electron':
alfa = (mean/(std + 1e-10))**2
beta = mean/(std + 1e-10)**2
result = tfp.distributions.Gamma(
concentration = alpha, rate=beta,
).prob(s_observed)
else:
result = tfp.distributions.Normal(
loc=mean, scale=std + 1e-10
).prob(s_observed)

# Add detection/selection efficiency
result *= self.gimme(SIGNAL_NAMES[self.quanta_name] + '_acceptance',
Expand Down

0 comments on commit 1d3e219

Please sign in to comment.