GRSISort "v4.0.0.5"
An extension of the ROOT analysis Framework
Loading...
Searching...
No Matches
TPulseAnalyzer.h
Go to the documentation of this file.
1#ifndef TPULSE_ANALYZER_H
2#define TPULSE_ANALYZER_H
3
4/** \addtogroup Fitting Fitting & Analysis
5 * @{
6 */
7
8#include "TFragment.h"
9
10#include <vector>
11#include <cstdlib>
12#include <cstdio>
13#include <cstring>
14#include <cmath>
15
16#include "Rtypes.h"
17#include "TH1.h"
18#include "TF1.h"
19#include "TGraph.h"
20
21////////////////////////////////////////////////////////////////////////////////
22/// \class TPulseAnalyzer
23///
24/// Mostly a direct port of SFU code
25/// I have stripped out some surplus and encapsulated it, but I havent changed much
26/// I'm sure there is more that can be stripped and reformated but it is working currently.
27///
28////////////////////////////////////////////////////////////////////////////////
29
31private:
32 struct WaveFormPar {
33 // parameters for baseline
35 double baseline; // baseline
36 double baselineStDev; // baseline variance
37 double baselinefin; // baseline
38 double baselineStDevfin; // baseline variance
39 bool bflag; // flag for baseline determiniation
40 // paramaters for oscillation
41 double baseamp; // amplitude of baseline oscillations
42 double basefreq; // tick frequency of baseline oscillations
43 double basephase; // flag for baseline determination
44 int osciflag; // flag for baseline determination
45 // paremeters for exclusion zone
46 double max; // max value of the filtered waveform
47 double tmax; // x position of the max value of the filtered waveform
48 double baselineMin; // max crossing point for exclusion zone
49 double baselineMax; // max crossing point for exclusion zone
50 int temax; // x position, exclusion zone upper limit
51 int temin; // x position, exclusion zone lower limit
52 double afit, bfit; // parameters for the line which fits risetime above temax
53 int mflag; // flag for tmax found
54 int teflag; // flag for exclusion zone determined
55 double t0; // required for compilation of map.c - check that it works
56 double t0_local;
57 // new stuff necessary for compiliation of Kris' waveform analyzer changes
58 double b0;
59 double b1;
60 long double s0;
61 long double s1;
62 long double s2;
63 double t90;
64 double t50;
65 double t30;
66 double t10;
67 double t10t90;
73 int thigh;
74 double sig2noise;
75 double amplitude; // amplitude from sili fits
76 double tauDecay;
77 double tauRise;
78 };
79
80 struct LinePar {
81 double slope;
82 double intercept;
83 double chisq;
84 double ndf;
85 };
86
87 struct ParPar {
88 double constant;
89 double linear;
90 double quadratic;
91 double chisq;
92 double ndf;
93 };
94
95 struct SinPar {
96 double A;
97 double t0;
98 double C;
99 };
100
101 struct ShapePar {
102 double chisq;
103 int ndf;
104 int type;
105 // decay constants for the fits
106 long double t[5]; // NOLINT(*-avoid-c-arrays)
107 // associated aplitudes for the decay constants
108 long double am[5]; // NOLINT(*-avoid-c-arrays)
109 double rf[5]; // NOLINT(*-avoid-c-arrays)
110
111 // new stuff necessary for compiliation of Kris' waveform analyzer changes
112 long double chisq_ex;
113 long double chisq_f;
115 int ndf_f;
116 };
117
118public:
120 explicit TPulseAnalyzer(const TFragment& fragment, double = 0);
121 explicit TPulseAnalyzer(const std::vector<Short_t>& wave, double = 0, std::string name = "");
123 TPulseAnalyzer(TPulseAnalyzer&&) noexcept = default;
124 TPulseAnalyzer& operator=(const TPulseAnalyzer&) = default;
125 TPulseAnalyzer& operator=(TPulseAnalyzer&&) noexcept = default;
126 virtual ~TPulseAnalyzer();
127
128 void SetData(const TFragment& fragment, double = 0);
129 void SetData(const std::vector<Short_t>& wave, double = 0);
130 void Clear(Option_t* opt = "");
131 bool IsSet() const { return set; }
132
133 double Get_wpar_T0() { return cWpar->t0; }
135 double Get_wpar_amplitude() { return cWpar->amplitude; }
136 double Get_wpar_decay() { return cWpar->tauDecay; }
137 double Get_wpar_rise() { return cWpar->tauRise; }
138
139 bool SiliShapePrepare(double tauDecay, double tauRise);
140 bool GetSiliShape(double tauDecay, double tauRise); // Added for Spice, parameters to be found : t0 and Amplitude
141 bool GetSiliShapeTF1(double tauDecay, double tauRise, double baseline, double basefreq = 0); // Added for Spice, full slow fit to establish parameters, needs initial estimates
142 bool Get_bflag() { return cWpar->bflag; }
143 TF1 Getsilifit();
144 double GetsiliSmirnov();
145 void Drawsilifit();
146
147 static double SiLiFitFunction(double* i, double* p);
148
149 double fit_newT0();
150 double fit_rf(double = 2 * 8.48409);
151 double get_sig2noise();
152 int16_t good_baseline();
153 void print_WavePar();
154 TH1I* GetWaveHist();
155 TGraph* GetWaveGraph();
156 static int fNameIter;
157 void DrawWave();
158 void DrawT0fit();
159 void DrawRFFit();
160
161 // CsI functions:
162 double CsIPID();
163 double CsIt0();
164 void DrawCsIExclusion();
165 void DrawCsIFit();
166 int GetCsIChiSq();
167 int GetCsIFitType();
168
169private:
170 bool set{false};
172 int cN{0};
173 // TFragment* frag;
174 std::vector<Short_t> cWavebuffer;
175 SinPar* spar{nullptr};
176 ShapePar* shpar{nullptr};
177 WaveFormPar* csiTestWpar[4]{nullptr}; // NOLINT(*-avoid-c-arrays)
178 ShapePar* csiTestShpar[4]{nullptr}; // NOLINT(*-avoid-c-arrays)
179
180 std::string fName;
181
182 // pulse fitting parameters
183 int FILTER; // integration region for noise reduction (in samples)
184 int T0RANGE; // tick range over which baseline is calulated
186
187 // linear equation dataholders
189 long double lineq_matrix[20][20]; // NOLINT(*-avoid-c-arrays)
190 long double lineq_vector[20]; // NOLINT(*-avoid-c-arrays)
191 long double lineq_solution[20]; // NOLINT(*-avoid-c-arrays)
192 long double copy_matrix[20][20]; // NOLINT(*-avoid-c-arrays)
193
194 // CsI functions
195 void GetCsIExclusionZone();
196 double GetCsITau(int, ShapePar*);
197 double GetCsIt0(ShapePar*, WaveFormPar*);
198 int GetCsIShape();
199 int FitCsIShape(int, ShapePar*, WaveFormPar*);
200
201 bool CsISet;
202 double EPS;
203
204 void SetCsI(bool option = true) { CsISet = option; }
205 bool CsIIsSet() const { return CsISet; }
206
207 // internal methods
208 int solve_lin_eq();
209 long double determinant(int);
210
211 int fit_parabola(int, int, ParPar*);
212 int fit_smooth_parabola(int, int, double, ParPar*);
213 int fit_line(int, int, LinePar*);
214 double get_linear_T0();
215 double get_parabolic_T0();
216 double get_smooth_T0();
217
218 void get_baseline();
219 void get_baseline_fin();
220 void get_tmax();
221
222 double get_tfrac(double, double, double);
223 void get_t10();
224 void get_t30();
225 void get_t50();
226 void get_t90();
227
228 double get_sin_par(double);
229
230 void GetQuickPara();
231
232 // bad chi squares for debugging
233 const static int BADCHISQ_SMOOTH_T0 = -1024 - 2; // smooth_t0 gives bad result
234 const static int BADCHISQ_PAR_T0 = -1024 - 3; // parabolic_t0 gives bad result
235 const static int BADCHISQ_LIN_T0 = -1024 - 4; // linear_t0 gives bad result
236 const static int BADCHISQ_MAT = -1024 - 5; // matrix for fit is not invertable
237 const static int BADCHISQ_FAIL_DIRECT = -1024 - 9; // generic fit failure
238 const static int BAD_EXCLUSION_ZONE = -1024 - 10; // fails finding exclusion zone
239 const static int BAD_MAX = -1024 - 11;
240 const static int BAD_BASELINE_RANGE = -1024 - 12;
241 const static int BAD_PID = -1024; // PID value returned when the fit fails
242
243 // new definitions for Kris' changes to the waveform analyzer
244 const static int PIN_BASELINE_RANGE = 16; // minimum ticks before max for a valid signal
245 const static int MAX_SAMPLES = 4096;
246
247 const static int CSI_BASELINE_RANGE = 50; // baseline range in channels
248 const static int NOISE_LEVEL_CSI = 100; // noise level for CsI
249 const static int NSHAPE = 5; // number of trial functions for waveform fit
250
251 const static int BADCHISQ_T0 = -1024 - 7;
252 const static int BADCHISQ_NEG = -1024 - 1;
253 const static int BADCHISQ_AMPL = -1024 - 6;
254
255 /// \cond CLASSIMP
256 ClassDef(TPulseAnalyzer, 4) // NOLINT(readability-else-after-return)
257 /// \endcond
258};
259/*! @} */
260#endif
long double lineq_solution[20]
std::vector< Short_t > cWavebuffer
double fit_rf(double=2 *8.48409)
long double determinant(int)
bool CsIIsSet() const
static const int BADCHISQ_PAR_T0
static const int BADCHISQ_LIN_T0
bool GetSiliShapeTF1(double tauDecay, double tauRise, double baseline, double basefreq=0)
static const int CSI_BASELINE_RANGE
static const int BAD_EXCLUSION_ZONE
double GetCsIt0(ShapePar *, WaveFormPar *)
double get_tfrac(double, double, double)
TPulseAnalyzer(const TPulseAnalyzer &)=default
static const int NSHAPE
void SetCsI(bool option=true)
static const int BADCHISQ_FAIL_DIRECT
void Clear(Option_t *opt="")
bool IsSet() const
double GetCsITau(int, ShapePar *)
static const int BAD_BASELINE_RANGE
static double SiLiFitFunction(double *i, double *p)
double Get_wpar_decay()
long double copy_matrix[20][20]
ShapePar * csiTestShpar[4]
static const int BADCHISQ_SMOOTH_T0
long double lineq_vector[20]
bool SiliShapePrepare(double tauDecay, double tauRise)
int fit_parabola(int, int, ParPar *)
int fit_line(int, int, LinePar *)
WaveFormPar * cWpar
TPulseAnalyzer(TPulseAnalyzer &&) noexcept=default
static int fNameIter
std::string fName
static const int BADCHISQ_AMPL
int fit_smooth_parabola(int, int, double, ParPar *)
double Get_wpar_rise()
static const int MAX_SAMPLES
static const int BADCHISQ_MAT
static const int PIN_BASELINE_RANGE
static const int BAD_MAX
WaveFormPar * csiTestWpar[4]
int16_t good_baseline()
long double lineq_matrix[20][20]
int FitCsIShape(int, ShapePar *, WaveFormPar *)
double get_parabolic_T0()
static const int NOISE_LEVEL_CSI
static const int BADCHISQ_NEG
static const int BADCHISQ_T0
void SetData(const TFragment &fragment, double=0)
TGraph * GetWaveGraph()
bool GetSiliShape(double tauDecay, double tauRise)
double Get_wpar_amplitude()
double Get_wpar_baselinefin()
double get_sin_par(double)
static const int BAD_PID