/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/daq/include/RAT/WaveformAnalysisLucyDDM.hh Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/daq/include/RAT/WaveformAnalysisLucyDDM.hh Source File
Ratpac-two
WaveformAnalysisLucyDDM.hh
1 #ifndef __RAT_WaveformAnalysisLucyDDM__
19 #define __RAT_WaveformAnalysisLucyDDM__
20 
21 #include <TObject.h>
22 
23 #include <RAT/DB.hh>
24 #include <RAT/DS/DigitPMT.hh>
25 #include <RAT/Digitizer.hh>
26 #include <RAT/FFTW1DTransformer.hh>
27 #include <RAT/Processor.hh>
28 #include <RAT/WaveformAnalyzerBase.hh>
29 #include <vector>
30 
31 namespace RAT {
32 
34  public:
36  WaveformAnalysisLucyDDM(std::string config_name) : WaveformAnalyzerBase("WaveformAnalysisLucyDDM", config_name) {
37  Configure(config_name);
38  };
39  virtual ~WaveformAnalysisLucyDDM(){};
40  void Configure(const std::string &config_name) override;
41 
42  protected:
43  // Digitizer settings
44  DBLinkPtr fDigit;
45 
46  // shaping parameters for SPE waveform
47  double vpe_scale; // Lognormal `m`
48  double vpe_shape; // Lognormal `sigma`
49  double vpe_charge; // nominal charge of a PE.
50  double vpe_integral =
51  -9999; // to be overwritten by the charge * termohms. Set to invalid here because termOhms is not known yet.
52  double ds; // internal sampling period in ns.
53  size_t vpe_nsamples; // number of samples in the VPE waveform.
54  std::vector<double> vpe_norm,
55  vpe_norm_flipped; // single PE waveform and its flipped version. Both normalized to integral 1.
56  std::vector<std::complex<double>> vpe_norm_fft, vpe_norm_flipped_fft; // and their fourier transforms.
57 
58  double roi_threshold; // Waveform below this threshold will be zeroed out.
59  double epsilon = 1e-10; // Small value to avoid division by zero in deconvolution
60 
61  size_t max_iterations; // max iterations to run in deconvolution
62  double stopping_nll_diff; // Stop if the change in the poisson negative log-likelihood is less than this value
63 
64  double peak_height_threshold; // peak height threshold for finding hits
65  double charge_threshold; // remove a hit if it has charge below this threshold.
66  double min_peak_distance; // if peaks are closer than this, they will be merged.
67 
68  bool npe_estimate; // if true, perform a final NPE estimation on all resolved wave packet in the deconvolved
69  // waveform. Estimate the number of PEs in each packet using a gaussian PDF on charge.
70  // The mean of the single PE charge distribution is centered around `vpe_charge`.
71  bool npe_estimate_charge_width; // the width of the gaussian single-PE charge distribution.
72  size_t npe_estimate_max_pes; // upper limit for the number of PEs in a single resolved wave packet.
73 
74  // FFT transfomration engines.
75  std::unique_ptr<FFTW1DTransformer> fft = nullptr;
76  std::unique_ptr<FFTW1DTransformer> ifft = nullptr;
77 
79  void DoAnalysis(DS::DigitPMT *pmt, const std::vector<UShort_t> &digitWfm) override;
80 
83  void RequestFFTSize(size_t size);
84 
86  std::vector<double> ConvolveFFT(const std::vector<double> &a, const std::vector<std::complex<double>> &b,
87  size_t conv_size, double dt) const;
88 
95  std::vector<double> Deconvolve(const std::vector<double> &wfm, size_t &iterations_ran) const;
96 
106  void FindHits(const std::vector<double> &phi, std::vector<double> &out_times, std::vector<double> &out_charges,
107  std::vector<double> &out_time_errors, std::vector<double> &out_charge_errors, double &chi2ndf) const;
108 
113  void MergeClosePeaks(std::vector<double> &times, std::vector<double> &charges, std::vector<double> &time_errors,
114  std::vector<double> &charge_errors);
115 
123  void ClampBelowThreshold(std::vector<double> &wfm, double thresh = -9999) const;
124 
130  std::vector<double> ReblurWaveform(const std::vector<double> &phi) const;
131 
137  std::vector<double> Resample(const std::vector<double> &wfm, size_t n_samples) const;
138 
145  double PoissonNLL(const std::vector<double> &wfm, const std::vector<double> &reblurred_wfm) const;
146 
151  double GaussianPulseTrain(double *x, double *p, size_t N) const;
152 };
153 
154 } // namespace RAT
155 #endif
Definition: DigitPMT.hh:23
Perform PMT waveform analysis using Richard-Lucy Direct Demodulation (LucyDDM).
Definition: WaveformAnalysisLucyDDM.hh:33
double GaussianPulseTrain(double *x, double *p, size_t N) const
Definition: WaveformAnalysisLucyDDM.cc:362
std::vector< double > ConvolveFFT(const std::vector< double > &a, const std::vector< std::complex< double >> &b, size_t conv_size, double dt) const
convolve a real waveform with the FFT of a kernel.
Definition: WaveformAnalysisLucyDDM.cc:170
void Configure(const std::string &config_name) override
Definition: WaveformAnalysisLucyDDM.cc:19
void ClampBelowThreshold(std::vector< double > &wfm, double thresh=-9999) const
Clamp all samples of a waveform below a threashold to epsilon (a positive value close to zero).
Definition: WaveformAnalysisLucyDDM.cc:302
std::vector< double > Resample(const std::vector< double > &wfm, size_t n_samples) const
Resample a waveform to a different sampling period using linear interpolation.
Definition: WaveformAnalysisLucyDDM.cc:333
void RequestFFTSize(size_t size)
Ensure that hte requested size can be done with the existing transformers. If the transformers are to...
Definition: WaveformAnalysisLucyDDM.cc:151
void FindHits(const std::vector< double > &phi, std::vector< double > &out_times, std::vector< double > &out_charges, std::vector< double > &out_time_errors, std::vector< double > &out_charge_errors, double &chi2ndf) const
Find hits in the deconvolved waveform.
Definition: WaveformAnalysisLucyDDM.cc:237
double PoissonNLL(const std::vector< double > &wfm, const std::vector< double > &reblurred_wfm) const
Definition: WaveformAnalysisLucyDDM.cc:313
std::vector< double > Deconvolve(const std::vector< double > &wfm, size_t &iterations_ran) const
performs Richard-Lucy deconvolution of the waveform.
Definition: WaveformAnalysisLucyDDM.cc:189
std::vector< double > ReblurWaveform(const std::vector< double > &phi) const
convolve phi with the SPE template, effectively "reblurring" the deconvolved waveform.
Definition: WaveformAnalysisLucyDDM.cc:325
void DoAnalysis(DS::DigitPMT *pmt, const std::vector< UShort_t > &digitWfm) override
Main analysis function entry point, provided by WaveformAnalyzerBase.
Definition: WaveformAnalysisLucyDDM.cc:48
void MergeClosePeaks(std::vector< double > &times, std::vector< double > &charges, std::vector< double > &time_errors, std::vector< double > &charge_errors)
Perform post processing on the hits. Occasionally LucyDDM will resolve a single PE into two peaks....
Definition: WaveformAnalysisLucyDDM.cc:96
Definition: WaveformAnalyzerBase.hh:23
Definition: CCCrossSecMessenger.hh:29