gaps-online-software 0.10
online software for the TOF system for the GAPS experiment
Loading...
Searching...
No Matches
legacy.h
1#ifdef BUILD_ROOTCOMPONENTS
2#ifndef LEGACY_H_INCLUDED
3#define LEGACY_H_INCLUDED
4
5#include <vector>
6
7#include "tof_typedefs.h"
8
17#define NCHN 9
18#define MAX_NUM_PEAKS 50
19#define ERRVAL (999999999)
20
21// These two #defines give the necessary information for integrating to
22// find the charge in the peak (these should be in ns)
23#define PEAK_OFFSET -4
24#define PEAK_LENGTH 12
25
26
27void RemoveSpikes(double wf[NCHN][1024], unsigned int tCell, int spikes[]);
28
29
30namespace GAPS {
31
32enum class PADDLE_END : u16 {
33 A = 10,
34 B = 20,
35 UNKNOWN = 30
36};
37
38// Types of Thresholds to use in determining timing
39enum THRTYPE { CONSTANT, CFD_ELEC, CFD_SIMPLE, PCONSTANT, PCFD };
40
41// I moved these to cfde_frac and cfde_offset below and made routines
42// so that they can be set without recompiling.
43//#define CFD_FRACTION 0.1
44// CFD_OFFSET should be an integer so we don't have to interpolate our
45// FADC data.
46//#define CFD_OFFSET 5.0
47
48// Note: The NORMAL entry is there to make it easier to fill the
49// channel_status flag in the PMT0 bank. A value of zero there
50// indicates "no stacq data", so, it will be filled with 1 if the data
51// is valid and not saturated. Otherwise, it will be filled with zero
52// if the data is not valid and with the saturated flag value if it is
53// valid.
54enum SAT_FLAGS { NOT_SAT, NORMAL, SAT, NO_FIT, FIT_GOOD, FIT_BAD};
55
56double Pulse(double *x, double *par);
57
58class Waveform {
59
60public:
61
62 Waveform (double *data, double *time, int chnl, int flag = 0);
63 // Constructor 'flag' is set by default unless the waveform is
64 // constructed with a call to the contrary. Thus, the default
65 // behavior is to provide immediate access to pulse positions,
66 // times, heights, etc.... For someone who wants to do a more
67 // specialized analysis, the constructor can be called with flag=0
68 // so that we do not waste time doing the ped and peak calculations.
69
70 Waveform (int size);
71 ~Waveform (void);
72
73 // MEMBER FUNCTIONS
74
75 void SetWave(std::vector<double>);
76 void SetTime(std::vector<double>);
77
78 // Stuff related to the actual data
79 void SetThreshold(float PmtThreshold);
80 int GetWaveSize(void){return wf_size;}
81 double SetBin(int idx, double val);
82 double GetBin(int idx);
83 double GetBinTime(int idx);
84 int GetBinDC(int idx);
85 int GetMaxBin(int lo, int size);
86 double GetMaxBinTime(int lo, int size);
87 double GetMaxVal(int lo, int size);
88 int GetMinBin(int lo, int size);
89 double GetMinBinTime(int lo, int size);
90 double GetMinVal(int lo, int size);
91 double GetPeakValue(float lo, float size);
92 void Rescale(double factor);
93 double Integrate(float lo, float size);
94
95 // Stuff related to the pedestals
96 void SetPedestal(double pedestal){wf_pedestal = pedestal;}
97 void SetRunPedestal(double runped){run_pedestal = runped;}
98 void SetPedRange(float range);
99 void SetPedBegin(float begin);
100 int GetPedRange(void){return wf_ped_range;}
101 int GetPedBegin(void){return wf_ped_begin;}
102 double GetPedestal(void){return wf_pedestal;}
103 double GetPedsigma(void){return wf_pedsigma;}
104 void CalcPedestalRange(void);
105 void CalcPedestalDynamic(void);
106 void SubtractPedestal(void);
107
108 // Stuff related to the peaks
109 void SetMaxPeaks(int max_num);
110 int GetMaxPeaks(void){return max_num_peaks;}
111 void CleanUpPeaks(void);
112 int GetNumPeaks(void);
113 void SetCFDSFraction(double fraction) {cfds_frac = fraction;}
114 void SetCFDEFraction(double fraction) {cfde_frac = fraction;}
115 void SetCFDEOffset(int offset) {cfde_offset = offset;}
116 void FindPeaks(float start, float size);
117 void FindTdc(int pk_num, int th_type = CFD_SIMPLE);
118 int GetSpikes(int i);
119 double GetTdcs(int i);
120 double GetCharge(int i);
121 double GetHeight(int i);
122 double GetWidth(int i);
123 double GetPeakTime(void) {return PeakValueTime;}
124
125 // Stuff related to the pulses
126 double GetPulsepars(int i) {return pulsepars[i];}
127 double GetPulsechi2() {return pulsechi2;}
128 double GetNDF() {return ndf;}
129 void FitPulse(void);
130
131 // Stuff related to converting from mV to DC and vice versa
132 double GetNsPerBin(void) {return bin_ns;}
133 double GetOffset(void) {return offset;}
134 double GetTimingCorr(void){return timing_corr;}
135 double GetImpedance(void) {return impedance;}
136 void SetImpedance(double val) {if (val>0) impedance = val;}
137
138private:
139
140 // DATA MEMBERS
141
142 int ch; // STACEE channel we are working with
143 int runno; // Run Number
144 float Threshold; // PMT Threshold in DC (for now...)
145
146 // Stuff related to the actual data
147 int wf_size; // How much data was written to disk
148 double base; // 0 mV baseline in FADC counts
149 double *WaveData; // 'in memory' waveform data
150 double *WaveTime; // 'in memory' waveform times
151 double *wf_baseline; // To subtract reference baseline (mV)
152 double PeakValueTime; // Time of peak (GetPeakValue sets)
153
154 // Stuff related to the pedestals
155 int wf_ped_range; // How much data used for ped calcs
156 int wf_ped_begin; // Start of trace for ped calcs
157 double wf_pedestal; // Pedestal value
158 double run_pedestal; // Average pedestal for run
159 double wf_pedsigma; // Deviation of pedestal distribution
160 double wf_pedshift; // Amount pedestal shifts (in DC) just
161 // because we connect inputs to FADCs
162
163 // Stuff related to the peaks
164 int max_num_peaks;
165 int num_peaks;
166 int peaks_found; // Have we found the peaks yet?
167 int peaks_allocated; // Have we measured the peak properties yet?
168 int peak_plot; // Show peak positions when plotting?
169 int large_peaks; // Extrapolate saturated peaks?
170 int *begin_pk; // First bin included in peak
171 int *end_pk; // Last bin included in peak
172 int *spikes; // How smooth is the peak
173 int *peaks; // Bin values of the actual peak positions
174 int cfde_offset; // Offset for electronic CFD (in bin values)
175 double cfds_frac; // Fraction of peak ave for simple CFD
176 double cfde_frac; // Fraction of trace for electronic CFD
177 double *tdcs; // Something similar to what a TDC would give
178 double *width;
179 double *height;
180 double *charge;
181
182 double pulsepars[4]; // Pulse parameters
183 double pulsechi2;
184 int ndf;
185 float pulse_start;
186
187 // Converting from FADC data to mV, charge, etc...
188 int acq_ch;
189 double dc2mv;
190 double offset;
191 double bin_ns;
192 double impedance;
193 double saturated_lo;
194 double saturated_hi;
195
196 // Since the trace in the Dig0 bank is stored in integer increments,
197 // but we want times in floats, we have to correct for the round off
198 // error (which is written in the Dig0 bank).
199 double timing_corr;
200
201 // MEMBER FUNCTIONS
202 void InitializePointers();
203 void InitializeVariables(int no_acq);
204 void Message(const char *s); // Print out messages as needed
205 // Stuff related to the peaks
206 void AllocatePeaks();
207 double FindInterpolatedTime(float thresh, int idx, int size);
208 double FindCFDElecTime(float thresh, int idx, int size);
209 double FindCFDSimpTime(int pk_num);
210 int Time2Bin(float t_ns);
211
212};
213
214} // end of namespace GAPS
215
216#endif
217#endif