MUSIC unknown
Analysis for the MUSIC active-target ionization chamber
Loading...
Searching...
No Matches
PulseHistory.hpp
Go to the documentation of this file.
1#ifndef PULSE_HISTORY_HPP
2#define PULSE_HISTORY_HPP
3
21#include "BinaryUtils.hpp"
22#include <Rtypes.h>
23#include <TString.h>
24#include <vector>
25
26class TH1D;
27class TH2D;
28class TProfile;
29
30namespace PulseHistory {
31
33const UInt_t kFlagClamped = 0x2000;
36const Int_t kNBins = 30;
37const Double_t kLogLo = -6.0;
38const Double_t kLogHi =
39 -3.5;
41const Int_t kMAX_AMP_BINS = 6;
44const Long64_t kMinPairsPerChannel = 2000;
55const Int_t kNTauGrid = 21;
56const Double_t kTauGridLoUs = 4.0;
57const Double_t kTauGridHiUs = 64.0;
68const Double_t kTauFitLoUs = 8.0;
69const Double_t kTauFitHiUs = 130.0;
71const Int_t kTauFitMinEntries = 100;
73
95
96const char *GroupName(Int_t g);
98const char *GroupTag(Int_t g);
101Int_t ChainOf(Int_t g);
104Bool_t IsLongGroup(Int_t g);
108Bool_t GroupEnabled(Int_t g);
111Bool_t GroupWantsForm(Int_t g);
114Double_t GroupTauUs(Int_t g);
115
125struct Kernel {
126 Bool_t ok = kFALSE;
129 Bool_t from_group = kFALSE;
130 TString why_group;
131 Int_t n_amp = 1;
139
148 Bool_t form = kFALSE;
149 Bool_t form_ok = kFALSE;
150 Int_t j_tau = -1;
151 Double_t tau_us = 0.0;
152 Bool_t tau_given = kFALSE;
155 Double_t tau_free_us = 0.0;
156 Double_t r2_form_free = 0.0;
157 Double_t
159 Double_t cb[kMAX_AMP_BINS];
161 Int_t n_free = 0;
162 Double_t t_m_us = 0.0;
163 Double_t t_f_us = 0.0;
164 Double_t t_lo_us = 0.0;
165 Double_t intercept_form = 0.0;
166 Double_t r2_form = 0.0;
167 Double_t rms_after_form = 0.0;
168 Double_t r2_binned = 0.0;
171 Double_t r2_group = 0.0;
172 Double_t rms_after_binned = 0.0;
176 Double_t FormAt(Int_t a, Double_t dt_us) const;
179 Double_t EffectiveWindowUs(Int_t a) const;
193 struct TauFit {
194 Bool_t ok = kFALSE;
195 Bool_t flat = kTRUE;
196 Double_t p0 = 0.0;
197 Double_t p1 = 0.0;
198 Double_t p1err = 0.0;
199 Double_t p2 = 0.0;
200 Double_t p2err = 0.0;
201 Double_t p3 = 0.0;
202 Double_t chi2 = 0.0;
203 Int_t ndf = 0;
204 };
206 Double_t intercept = 0.0;
207 Double_t r2 = 0.0;
208 Double_t rms_before = 0.0;
209 Double_t rms_after = 0.0;
210 Long64_t n = 0;
211 Long64_t n_beam = 0;
212
214 Kernel();
215};
216
223struct Result {
230 std::vector<Kernel> kernel_ch;
231 std::vector<Int_t> group_of;
232 std::vector<TString> name_ch;
233 Bool_t
235 Long64_t n_hits = 0;
236 Long64_t n_seeds = 0;
237 Long64_t n_beam_events = 0;
238 Long64_t n_corrected = 0;
239 Long64_t n_clamped = 0;
242 Bool_t sorted_input = kTRUE;
245 std::vector<Double_t> mode;
255 TProfile
260 std::vector<TProfile *> dtprev_before_ch;
261 std::vector<TProfile *> dtprev_after_ch;
263
264 Result();
265 ~Result();
267 void FreeDiagnostics();
268};
269
273Int_t BinOf(Double_t dt_s);
276Double_t BinCentreUs(Int_t b);
282Int_t AmpBinOf(Double_t e_prev, Double_t mode, Int_t n_amp);
283
286std::vector<Int_t> BuildGroupMap();
287
303Bool_t Measure(std::vector<RawHit> &hits, const std::vector<Int_t> &group_of,
304 Result &res, const TString &file_label);
305
320void Apply(std::vector<RawHit> &hits, const std::vector<Int_t> &group_of,
321 Result &res);
322
330TString Report(const Result &res, const TString &file_label,
331 Bool_t detail = kTRUE);
335void SavePlots(Result &res, const TString &file_label);
339void WriteToEventsFile(const TString &events_subpath, const Result &res);
340
341} // namespace PulseHistory
342
343#endif
Bool_t GroupWantsForm(Int_t g)
Whether the configuration asks for the pole-zero form on this group rather than the binned kernel.
ChannelGroup
Channel groups, one kernel each.
@ kLONG_LEFT
Long end, left chain.
@ kNONE
Not part of any corrected group.
@ kSHORT_RIGHT
Short end, right chain.
@ kNGROUPS
Count of groups; not a group itself.
@ kSTRIP0
Strip 0, unsegmented.
@ kGRID
The Frisch grid: the seed channel, one per event.
@ kSTRIP17
Strip 17, unsegmented.
@ kSHORT_LEFT
Short end, left chain.
@ kLONG_RIGHT
Long end, right chain.
const Double_t kTauFitLoUs
const Double_t kTauGridLoUs
const Double_t kLogHi
Highest dt bin edge: log10 of 316 us in seconds.
Double_t GroupTauUs(Int_t g)
The preamp decay time the configuration gives for this group, in microseconds; 0 when it is to be pro...
Int_t ChainOf(Int_t g)
Which readout chain a group belongs to.
const Int_t kNBins
Bins in the kernel, spanning kLogLo to kLogHi in log10 of dt: twelve per decade, 0....
const Double_t kLogLo
Lowest dt bin edge: log10 of 1 us in seconds.
const Int_t kTauFitMinEntries
Below this many (event, channel) pairs in the window the fit is skipped.
const Double_t kTauFitHiUs
Double_t BinCentreUs(Int_t b)
Centre of a kernel bin, in microseconds, for reports.
const Int_t kMAX_AMP_BINS
Maximum amplitude bands a kernel may split the previous pulse into.
const Int_t kNTauGrid
const char * GroupTag(Int_t g)
Short tag for filenames: L, R, Ls, Rs, S0, S17.
std::vector< Int_t > BuildGroupMap()
Group lookup for every (board, channel) under the active map.
const Long64_t kMinPairsPerChannel
Fewest (event, channel) pairs a channel needs for a kernel of its own; below it the channel is correc...
Int_t BinOf(Double_t dt_s)
Kernel bin for a time since the previous pulse.
void Apply(std::vector< RawHit > &hits, const std::vector< Int_t > &group_of, Result &res)
Apply the measured kernels to the hit stream, in place.
Bool_t Measure(std::vector< RawHit > &hits, const std::vector< Int_t > &group_of, Result &res, const TString &file_label)
Measure the kernels on this subfile's beam-like events.
Bool_t IsLongGroup(Int_t g)
Whether a group is a long end rather than a short end or an unsegmented strip.
void SavePlots(Result &res, const TString &file_label)
Draw and save the diagnostics, then free them.
Bool_t GroupEnabled(Int_t g)
Whether the groups in force (Constants::ActivePulseHistoryGroups()) have this group corrected.
const UInt_t kFlagClamped
Flag set on a hit whose correction was clamped rather than applied in full.
const Double_t kTauGridHiUs
Int_t AmpBinOf(Double_t e_prev, Double_t mode, Int_t n_amp)
Amplitude band of a previous pulse.
void WriteToEventsFile(const TString &events_subpath, const Result &res)
Record the kernels and counters alongside a subfile's events.
const char * GroupName(Int_t g)
Human-readable name of a Group.
TString Report(const Result &res, const TString &file_label, Bool_t detail=kTRUE)
Format the pass as a human-readable report.
Single-exponential summary of the dt profile for this group.
Double_t p0
Level at large dt, ADC.
Bool_t flat
Amplitude within 2 sigma of zero: no decay.
Double_t chi2
Chi2 of the fit over the window.
Double_t p3
Linear lift (the baseline term), ADC/us.
Int_t ndf
Its degrees of freedom.
Bool_t ok
Whether the fit converged.
Double_t p1err
Its error, ADC.
Double_t p2err
Its error, us.
Double_t p1
Tail amplitude at dt = 0, ADC.
Double_t p2
Decay time, us.
One fitted correction: a channel's own, or a group's.
Double_t rms_before
Channel-deviation RMS before correction.
Double_t t_m_us
Read point after a pulse: rise + peaking.
Double_t r2
Coefficient of determination.
Double_t tau_us
The applied form's decay time: given or profiled.
Int_t j_tau
Grid index of the applied tau; internal.
Double_t FormAt(Int_t a, Double_t dt_us) const
The form at one gap for one band, per unit previous height.
Double_t rms_after_form
Deviation RMS after the form.
Double_t k_low[kMAX_AMP_BINS][kNBins]
Free coefficients, bins < n_free.
Long64_t n_beam
Beam-like events passing this group's selection.
Double_t EffectiveWindowUs(Int_t a) const
Effective restorer window implied by the fitted amplitudes, c tau / c_B, in microseconds; 0 when c_B ...
Double_t intercept_form
The form fit's intercept, ADC.
Double_t c[kMAX_AMP_BINS]
Direct-tail amplitude per band; > 0 undershoot.
Double_t r2_binned
And the binned fit's, for comparison.
Double_t k_binned[kMAX_AMP_BINS][kNBins]
The binned fit's coefficients, always kept so the form can be judged against them.
Double_t cb[kMAX_AMP_BINS]
Baseline-term amplitude per band.
Bool_t ok
Whether this kernel was successfully fitted.
Double_t t_lo_us
From where the form holds: (2 rise + flat) - t_m.
Int_t n_free
Bins below t_lo that stay free under the form.
Bool_t tau_given
Whether tau_us came from the configuration.
Long64_t n
(event, channel) pairs entering the fit.
TauFit tau
Summary of the dt profile, all hits.
Bool_t from_group
Channel kernels only: this is a copy of the group's kernel because the channel's own could not be fit...
Double_t tau_free_us
The profile's own preference, on the grid, and its fit quality: the check on a given tau_us.
Double_t r2_form
Coefficient of determination of the form.
Double_t r2_group
Channel kernels only: the R^2 the group's kernel reaches on this channel's pairs, so the gain from a ...
Double_t intercept
Fit intercept, in ADC.
Double_t rms_after
And after, so the gain is visible.
Double_t t_f_us
Baseline freeze after a trigger: 2 rise + flat.
Int_t n_amp
Amplitude bands actually used, at most kMAX_AMP_BINS.
Kernel()
Construct unfitted, with zeroed coefficients.
Double_t k[kMAX_AMP_BINS][kNBins]
The applied kernel at the bin centres, [amplitude band][dt bin]: the binned coefficients themselves,...
Everything one subfile's pulse-history pass produced.
TH1D * dev_after[kNGROUPS]
And after.
std::vector< TProfile * > dtprev_before_ch
Per channel index, deviation against time to previous pulse before and after the channel's own kernel...
~Result()
Frees any diagnostic histograms still held.
Long64_t n_corrected
Hits that received a correction.
std::vector< Double_t > mode
Beam peak per (board, channel) index, in ADC.
TH2D * dev_vs_pred[kNGROUPS]
Channel deviation against predicted shift.
void FreeDiagnostics()
Delete every diagnostic histogram and null the pointers.
Long64_t n_beam_events
Beam-like events the fit drew on.
TProfile * dtprev_after[kNGROUPS]
And after.
Bool_t enabled[kNGROUPS]
Whether the group was configured for correction.
TProfile * dtprev_before[kNGROUPS]
Deviation against time to previous pulse.
Long64_t n_clamped_group[kNGROUPS]
Clamps per group.
Long64_t n_seeds
Hits usable as a previous pulse.
Bool_t sorted_input
Whether the input arrived time-ordered.
std::vector< Int_t > group_of
The group map Measure() was given.
std::vector< TString > name_ch
Channel-map name per index.
Double_t mean_shift[kNGROUPS]
Mean subtracted term per group, ADC.
Long64_t n_clamped
Corrections clamped rather than applied in full.
std::vector< Kernel > kernel_ch
The applied kernels, one per (board, channel) index as in the group map (empty before Measure()): the...
Kernel kernel[kNGROUPS]
The group fits, one per Group: each the fit over the sum of its channels, the fallback for a channel ...
TH1D * shift[kNGROUPS]
Shift applied per hit.
std::vector< TProfile * > dtprev_after_ch
Result()
Construct with zeroed counters and null diagnostics.
Long64_t n_hits
Hits examined.
TH1D * dev_before[kNGROUPS]
Deviation distribution before correction.