wavecatcher-analysis
Loading...
Searching...
No Matches
ReadRun.h
Go to the documentation of this file.
1
2#ifndef _ReadRun
3#define _ReadRun
4
5// contact: christian.scharf@physik.hu-berlin.de
6
7#include <Math/Minimizer.h>
8#include <Math/Factory.h>
9#include <Math/Functor.h>
10#include <TClonesArray.h>
11#include <TObjString.h>
12#include <TLine.h>
13#include <TGraph.h>
14#include <TGraph2D.h>
15#include <TMultiGraph.h>
16#include <TString.h>
17#include <TCanvas.h>
18#include <TFile.h>
19#include <TTree.h>
20#include <TH1D.h>
21#include <TMath.h>
22#include <TF1.h>
23#include <TStyle.h>
24#include <TH1F.h>
25#include <TH2D.h>
26#include <TEfficiency.h>
27#include <TLegend.h>
28#include <THStack.h>
29#include <THistPainter.h>
30#include <TText.h>
31#include <TFitResultPtr.h>
32#include <TFitResult.h>
33#include <TSpline.h>
34#include <TPaveStats.h>
35#include <TError.h> // root verbosity level
36#include <TSystem.h>
37#include <TROOT.h>
38#include <TLatex.h>
39
40//C, C++
41#include <stdio.h>
42#include <assert.h>
43#include <iostream>
44#include <iomanip>
45#include <fstream>
46#include <vector>
47#include <stdlib.h>
48#include <sstream>
49#include <stdexcept>
50
51#include "utils/FitFunctions.h"
52#include "utils/Helpers.h"
53#include "utils/Filters.h"
54
55using namespace std;
56
57class ReadRun {
58private:
60 int PrintChargeSpectrum_cnt;
62 int PlotChannelAverages_cnt;
64 int PrintWFProjection_cnt;
66 int PlotWFHeatmaps_cnt;
67
68
69#pragma pack(1) // byte padding suppression for WaveCatcher data format
70 // structs copied from
71 // WaveCatcher binary -> root converter
72 // by manu chauveau@cenbg.in2p3.fr
73 struct event_data
74 {
75 int EventNumber;
76 double EpochTime;
77 unsigned int Year;
78 unsigned int Month;
79 unsigned int Day;
80 unsigned int Hour;
81 unsigned int Minute;
82 unsigned int Second;
83 unsigned int Millisecond;
84 unsigned long long int TDCsamIndex;
85 int nchannelstored;
86 };
87
88 struct channel_data_without_measurement
89 {
90 int channel;
91 int EventIDsamIndex;
92 int FirstCellToPlotsamIndex;
93 short waveform[1024];
94 };
95
96 struct channel_data_with_measurement
97 {
98 int channel;
99 int EventIDsamIndex;
100 int FirstCellToPlotsamIndex;
101 float MeasuredBaseline;
102 float AmplitudeValue;
103 float ComputedCharge;
104 float RiseTimeInstant;
105 float FallTimeInstant;
106 float RawTriggerRate;
107 short waveform[1024];
108 };
109#pragma pack() // byte padding suppression for WaveCatcher data format
110
111protected:
113 void checkData() const {
114 if (eventnr_storage.empty()) {
115 throw std::runtime_error(
116 "Error: No data has been loaded yet!\n \
117 Please call ReadFile() before calling any functions which manipulate data.\n \
118 Aborting execution.");
119 }
120 }
121
122public:
125
128
131
132 // plots amplValuessum
133 void PlotChannelSums(bool = false, bool = false, double = 0., double = 0., int = 2);
134
135 void PlotChannelAverages(bool = false);
136
137 TH2F* WFHeatmapChannel(int, float = -20, float = 200, int = 880);
138 void PlotWFHeatmaps(float = -20, float = 200, int = 880, string = "", float = 0, EColorPalette = kGistEarth);
139
140 // baseline correction (shifts all waveforms individually in y)
141 void CorrectBaseline(float, float = -999);
142 void CorrectBaseline_function(TH1F*, float, float, int);
143
144 void CorrectBaselineMinSlopeRMS(vector<float>, double = 0, int = 2, int = 3);
145 void CorrectBaselineMinSlopeRMS(int = 100, bool = false, double = 0.5, int = 0, int = 0, int = 2);
146
147 void CorrectBaselineMin(vector<float>, double = 0, int = 2, int = 2);
148 void CorrectBaselineMin(int = 100, double = 0.5, int = 0, int = 0, int = 2);
149
150 // functions to check baseline correction results
151 TH1F* WFProjectionChannel(int, int = 0, int = 1024, float = -50, float = 50, int = 200);
152 void PrintWFProjection(float = 0, float = 320, float = -50, float = 50, int = 200);
153
154 TH1F* BaselineCorrectionResults(int, int, float = -5, float = 5, int = 200);
155 void PrintBaselineCorrectionResults(float = -5, float = 5, int = 200);
156
157 // get timing of peaks
158 void GetTimingCFD(float = .3, float = 100, float = 140, double = 0., bool = true, int = 2, bool = false);
159 void SkipEventsTimeDiffCut(int, int, double, double, bool = false);
160
161 void FractionEventsAboveThreshold(float = 4, bool = true, bool = true, double = 0., double = 0., bool = false);
162
163 // average all waveforms to simplify peak ID
164 void SmoothAll(double, int);
165 void SmoothAll(double, string = "Gaus");
166 void FilterAll(double = .3, double = .9, double = .2);
167 void ShiftAllToAverageCF();
168
169 // functions for charge spectrum
170 int* GetIntWindow(TH1F*, float, float, float, float, int = 0);
171 float GetPeakIntegral(TH1F*, float, float, float, float, int = 0);
172 void PrintChargeSpectrumWF(float, float, float = 0, float = 300, int = 1, float = 0., float = 0., float = 0., float = 0.);
173 TH1F* ChargeSpectrum(int, float, float, float = 0, float = 300, float = -50, float = 600, int = 750);
174 void PrintChargeSpectrum(float, float, float = 0, float = 300, float = -50, float = 600, int = 750, float = 0., float = 0., int = 99, int = 0, bool = false);
177
178
179 float* ChargeList(int, float = 20, float = 80, float = 0, float = 300, bool = 1);
180 void SaveChargeLists(float = 20, float = 80, float = 0, float = 300, bool = 1);
181 void ChargeCorrelation(float, float, float, float, float, float, int, int, int, bool = false);
182
183 // SiPM specific
184 void PrintDCR(float = 15, float = 85, float = 0, float = 300, double = 3); // based on PMT::PrintChargeSpectrumPMTthreshold()
185
186 // functions for time distribution
187 TH1F* TimeDist(int, float = 0, float = 300, float = 0, float = 300, int = 100, int = 0, float = .3);
188 void PrintTimeDist(float = 0, float = 300, float = 0, float = 300, int = 100, int = 0, float = .3);
189 TGraph2D* MaxDist(int, float = 0, float = 300);
190 void PrintMaxDist(float = 0, float = 300);
191
192 TH1F* His_GetTimingCFD(int, float, float, int = -999);
193 void Print_GetTimingCFD(float = 100, float = 140, int = 0, int = -999, string = "S", bool = true);
194 TH1F* His_GetTimingCFD_diff(vector<int>, vector<int>, float, float, int = -999);
195 void Print_GetTimingCFD_diff(vector<int>, vector<int>, float = 100, float = 140, int = 0, int = -999, float = -999, float = -999, string = "RS", bool = true);
196
197
198 // helper functions
199 TH1F* Getwf(int); // waveform number
200 TH1F* Getwf(int, int, int = 1); // channel, eventnr, color
201 double* getx(double = 0.); // x values
202 double* gety(int); // y values for waveform index
203 double* gety(int, int); // y values for waveform(channel, event)
204
205 static pair<float, bool> LinearInterpolation(float, float, float, float, float); // linear interpolation
206
207 int GetEventIndex(unsigned int); // get index of a triggered event (finds the correct event if files are not read sequentially)
208 int GetChannelIndex(int); // get index of a certain channel
209 int GetCurrentChannel(int); // get index of channel for a certain waveform
210 int GetCurrentEvent(int); // get index of event for a certain waveform
211
212 bool PlotChannel(int); // check if channel should be plotted
213
214
222
223 void ReadFile(string, bool = false, int = 9, string = "out.root", bool = false);
224
225 virtual ~ReadRun();
226
230 string data_path;
231
240
241
248
261
267 int nwf;
271 int maxNWF = 1e7;
272
274 float SP = .3125;
278 float DAQ_factor = 250. / 4096.;
280 int binNumber = 1024;
282 int nChannelsWC = 64;
283
288
296
301
304
307
312 int Nevents_good();
313
314 void SkipEventsPerChannel(vector<float>, float = 0, float = 0, bool = false); // in case you want to have indiviual thresholds in individual channels
315 void IntegralFilter(vector<float>, vector<bool>, float, float, float = 50, float = 250, bool = false, bool = false); // Same as SkipEventsPerChannel() but filtering all events with integrals <(>) threshold
316 void PrintSkippedEvents();
317 void UnskipAll();
318
321
336
339
340 //other controls
341
346 float tCutg;
348 float tCutEndg;
349
355 float tWF_CF = 0.3;
358 int tWF_CF_bin = 375;
360 int tWF_CF_lo = 320;
362 int tWF_CF_hi = 500;
363
368};
369#endif
TH1F * Getwf(int)
Helper that returns the waveform histogram for a certain waveform number number.
Definition ReadRun.cc:2547
int maxNWF
Maximum possible number of waveforms in data: number of active channels x number of events.
Definition ReadRun.h:271
void Print_GetTimingCFD(float=100, float=140, int=0, int=-999, string="S", bool=true)
Plot results of GetTimingCFD()
Definition ReadRun.cc:2300
void ChargeCorrelation(float, float, float, float, float, float, int, int, int, bool=false)
Plot correlation of integrals/amplitudes between two channels.
Definition ReadRun.cc:1765
float tCutEndg
End of time window for baseline correction when using ReadRun::Using_BaselineCorrection_in_file_loop.
Definition ReadRun.h:348
TH1F * ChargeSpectrum(int, float, float, float=0, float=300, float=-50, float=600, int=750)
Histogram of the "charge" spectrum for one channel.
Definition ReadRun.cc:1807
float DAQ_factor
DAQ conversion factor for wavecatcher output to mV.
Definition ReadRun.h:278
int nevents
Number of triggered events in data.
Definition ReadRun.h:263
vector< bool > skip_event
Stores the event numbers which should be skipped in the analysis.
Definition ReadRun.h:311
double * gety(int)
Get array of y values for a certain waveform.
Definition ReadRun.cc:2580
vector< int > active_channels
Stores the numbers of the active channels.
Definition ReadRun.h:290
void checkData() const
Primitive check to see if data has been loaded.
Definition ReadRun.h:113
float GetPeakIntegral(TH1F *, float, float, float, float, int=0)
Calculate the integral around a peak with several options explained in GetIntWindow().
Definition ReadRun.cc:1588
int GetEventIndex(unsigned int)
Returns index of a certain event number (if data files are read in parallel threads)
Definition ReadRun.cc:2597
TH1F * His_GetTimingCFD(int, float, float, int=-999)
Plot results of GetTimingCFD()
Definition ReadRun.cc:2277
void FilterAll(double=.3, double=.9, double=.2)
Filter all waveforms.
Definition ReadRun.cc:641
int GetChannelIndex(int)
Match channel number (wavecatcher input channel) to channel index.
Definition ReadRun.cc:2615
float tCutg
Start of time window for baseline correction when using ReadRun::Using_BaselineCorrection_in_file_loo...
Definition ReadRun.h:346
float * ChargeList(int, float=20, float=80, float=0, float=300, bool=1)
Returns array with the individual "charge"/amplitude for all events of one channel.
Definition ReadRun.cc:1697
TFile * root_out
Stores results of analysis.
Definition ReadRun.h:338
int tWF_CF_lo
Start of range of bins where the signal is expected for ReadRun::Shift_WFs_in_file_loop.
Definition ReadRun.h:360
int nChannelsWC
Wavecatcher hardware max. number of channels (reduce/increase if not using the 64 channel crate)
Definition ReadRun.h:282
void FractionEventsAboveThreshold(float=4, bool=true, bool=true, double=0., double=0., bool=false)
Find events with max/min above/below a certain threshold.
Definition ReadRun.cc:1328
void CorrectBaselineMinSlopeRMS(vector< float >, double=0, int=2, int=3)
Baseline correction method searching for non-monotonic, rather constant regions.
Definition ReadRun.cc:784
void PrintBaselineCorrectionResults(float=-5, float=5, int=200)
Print histogram of the baseline correction values for all channels.
Definition ReadRun.cc:1138
vector< float > PrintChargeSpectrum_pars
Starting values of the fit parameters for PrintChargeSpectrum()
Definition ReadRun.h:176
bool Using_BaselineCorrection_in_file_loop
Set true for baseline correction during data reading. Needs to be called before ReadFile().
Definition ReadRun.h:344
void PrintWFProjection(float=0, float=320, float=-50, float=50, int=200)
Plots waveform projection histograms of all channels.
Definition ReadRun.cc:1079
void PlotChannelAverages(bool=false)
Plot averages only of the good, corrected waveforms for each channel.
Definition ReadRun.cc:454
bool PlotChannel(int)
Check if a channel index should be plotted according to ReadRun::plot_active_channels.
Definition ReadRun.cc:2643
int Nevents_good()
Number of good events that are not skipped.
Definition ReadRun.cc:1510
void ReadFile(string, bool=false, int=9, string="out.root", bool=false)
Routine to read files created by the wavecatcher.
Definition ReadRun.cc:66
int MaxNoOfBinFilesToRead
Number of last .bin file to be read in.
Definition ReadRun.h:235
int tWF_CF_hi
End of range of bins where the signal is expected for ReadRun::Shift_WFs_in_file_loop.
Definition ReadRun.h:362
int start_read_at_channel
Do analysis only for limited range of channels to reduce memory usage.
Definition ReadRun.h:258
int * GetIntWindow(TH1F *, float, float, float, float, int=0)
Determine indices for integration window for peaks.
Definition ReadRun.cc:1534
void PrintChargeSpectrumWF(float, float, float=0, float=300, int=1, float=0., float=0., float=0., float=0.)
Plot waveforms of all channels for a given event number and add the determined integration windows to...
Definition ReadRun.cc:1613
float tWF_CF
Constant fraction of maximum (between ~0.1 and 1) for ReadRun::Shift_WFs_in_file_loop.
Definition ReadRun.h:355
vector< float > mean_integral
Stores the mean integral/lightyield from PrintChargeSpectrum() for all channels.
Definition ReadRun.h:306
bool discard_original_eventnr
Can be used to discard the original event numbering of the data.
Definition ReadRun.h:247
vector< int > switch_polarity_for_channels
Stores the channel number where the polarity should be inverted. Example use to switch polarity for c...
Definition ReadRun.h:300
TH1F * WFProjectionChannel(int, int=0, int=1024, float=-50, float=50, int=200)
Waveform projections for one channel.
Definition ReadRun.cc:1052
void GetTimingCFD(float=.3, float=100, float=140, double=0., bool=true, int=2, bool=false)
Determine the timing of the maximum peak with constant fraction discrimination.
Definition ReadRun.cc:1188
TGraph2D * MaxDist(int, float=0, float=300)
Finds maximum amplitude for a given channel in time window ["from", "to"] and creates 3d map of wavef...
Definition ReadRun.cc:2227
int nwf
Total number of waveforms read from data: number of active channels x number of events.
Definition ReadRun.h:267
TH1F * TimeDist(int, float=0, float=300, float=0, float=300, int=100, int=0, float=.3)
Time distribution of maximum, CFD, or 10% - 90% rise time in a certain time window.
Definition ReadRun.cc:2127
void IntegralFilter(vector< float >, vector< bool >, float, float, float=50, float=250, bool=false, bool=false)
Skip events with threshold on integral.
Definition ReadRun.cc:1443
TH1F * BaselineCorrectionResults(int, int, float=-5, float=5, int=200)
Histograms of the contents of baseline_correction_result.
Definition ReadRun.cc:1118
void PrintDCR(float=15, float=85, float=0, float=300, double=3)
Calculate (SiPM) dark count rate.
Definition ReadRun.cc:2103
void SmoothAll(double, int)
Smoothing all waveforms which are not skipped (for testing, careful when using for analysis!...
Definition ReadRun.cc:599
void CorrectBaseline(float, float=-999)
Baseline correction constant window.
Definition ReadRun.cc:707
void CorrectBaselineMin(vector< float >, double=0, int=2, int=2)
Baseline correction using minimum sum ( mean) in range for correction.
Definition ReadRun.cc:938
int binNumber
Number of bins (always 1024 samples per waveform). Do not change!
Definition ReadRun.h:280
vector< vector< float > > PrintChargeSpectrum_cal
Calibration values to normalize charge spectrum to number of photoelectrons Chennels must be ordered ...
Definition ReadRun.h:367
vector< vector< float > > timing_results
Matrix to store timing of peaks from GetTimingCFD()
Definition ReadRun.h:333
void SaveChargeLists(float=20, float=80, float=0, float=300, bool=1)
Saves TGraphs to root file with the individual "charge"/amplitude for all events and all channels.
Definition ReadRun.cc:1717
vector< vector< float > > baseline_correction_result
Stores baseline correction results for CorrectBaseline() and related functions.
Definition ReadRun.h:320
TH1F * His_GetTimingCFD_diff(vector< int >, vector< int >, float, float, int=-999)
Plot timing difference between the mean timings of two channel ranges.
Definition ReadRun.cc:2350
void SkipEventsTimeDiffCut(int, int, double, double, bool=false)
Skip events where the time difference between two channels is outside of specified range.
Definition ReadRun.cc:1285
void SkipEventsPerChannel(vector< float >, float=0, float=0, bool=false)
Skip events above/below individual thresholds per channel.
Definition ReadRun.cc:1393
string data_path
Path to data.
Definition ReadRun.h:230
TClonesArray * rundata
Stores data.
Definition ReadRun.h:124
void PrintMaxDist(float=0, float=300)
Finds maximum amplitude for a given channel in time window ["from", "to"] and creates 3d map of wavef...
Definition ReadRun.cc:2254
void PrintChargeSpectrum(float, float, float=0, float=300, float=-50, float=600, int=750, float=0., float=0., int=99, int=0, bool=false)
Plots the "charge" spectrums of all channels.
Definition ReadRun.cc:1861
int end_read_at_channel
See ReadRun::start_read_at_channel.
Definition ReadRun.h:260
int nchannels
Number of active channels in data.
Definition ReadRun.h:265
void UnskipAll()
Sets skip_event flag to false for all events, removing any previous cuts.
Definition ReadRun.cc:1504
float SP
Sampling: ns per bin of data, sampling rate 3.2 GS/s -> 0.3125 ns.
Definition ReadRun.h:274
vector< TFitResultPtr > timing_fit_results
Stores the fit results of Print_GetTimingCFD() for all channels.
Definition ReadRun.h:335
void PlotWFHeatmaps(float=-20, float=200, int=880, string="", float=0, EColorPalette=kGistEarth)
Plot stacks of all non-skipped waveforms for all active channels.
Definition ReadRun.cc:556
int GetCurrentEvent(int)
Get the current event index for a certain waveform index.
Definition ReadRun.cc:2637
int tWF_CF_bin
Time bin all events will be shifted to for ReadRun::Shift_WFs_in_file_loop Needs to be 300<"tWF_CF_bi...
Definition ReadRun.h:358
virtual ~ReadRun()
Destructor.
Definition ReadRun.cc:376
void PlotChannelSums(bool=false, bool=false, double=0., double=0., int=2)
Plot sums of all raw waveforms for each channel.
Definition ReadRun.cc:396
void CorrectBaseline_function(TH1F *, float, float, int)
Helper function called by CorrectBaseline()
Definition ReadRun.cc:730
void PrintTimeDist(float=0, float=300, float=0, float=300, int=100, int=0, float=.3)
Time distribution of maximum, CFD, or 10% - 90% rise time in a certain time window.
Definition ReadRun.cc:2191
float ** amplValuessum
Collects sums of all waveforms for each channel.
Definition ReadRun.h:127
vector< int > plot_active_channels
Stores the numbers of the active channels which should be plotted.
Definition ReadRun.h:295
static pair< float, bool > LinearInterpolation(float, float, float, float, float)
Simple linear interpolation for x.
Definition ReadRun.cc:2658
void ShiftAllToAverageCF()
This function shifts all waveforms to the average signal starting times for each channel.
Definition ReadRun.cc:661
vector< TFitResultPtr > fit_results
Stores the fit results of PrintChargeSpectrum() for all channels and all function calls in ascending ...
Definition ReadRun.h:303
int GetCurrentChannel(int)
Get the current channel index for a certain waveform index.
Definition ReadRun.cc:2630
int MinNoOfBinFilesToRead
Number first of .bin file to be read in.
Definition ReadRun.h:239
void PrintSkippedEvents()
Prints a list of all skipped events into the terminal for diagnostics.
Definition ReadRun.cc:1491
double * getx(double=0.)
Get array of x axis (time) for standard wavecatcher settings.
Definition ReadRun.cc:2569
int * maxSumBin
Stores bin numbers where the sum of waveforms have their maximum.
Definition ReadRun.h:287
bool Shift_WFs_in_file_loop
Shift waveforms with CFD so that all events start at the same time Call after initializing class and ...
Definition ReadRun.h:353
TH2F * WFHeatmapChannel(int, float=-20, float=200, int=880)
2D histogram of all non-skipped waveforms for one channel
Definition ReadRun.cc:524
void Print_GetTimingCFD_diff(vector< int >, vector< int >, float=100, float=140, int=0, int=-999, float=-999, float=-999, string="RS", bool=true)
Plot timing difference between the mean timings of two channel ranges.
Definition ReadRun.cc:2438
vector< unsigned int > eventnr_storage
Events will be stored here in the order they have been read.
Definition ReadRun.h:130