-
Notifications
You must be signed in to change notification settings - Fork 2
/
analyze_3inch_data.cpp
194 lines (137 loc) · 4.99 KB
/
analyze_3inch_data.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/// This is a trivial script for analyzing the timing resolution for DT5720 data for 3" Hamamatsu PMT.
/// We fit the pulses for the monitor and 3" PMT and calculate the time difference between them.
///
/// The difficult part of this script was tweaking the parameters for the
/// Exponentially modified Gaussian for the different run conditions
/// This particular script is for PMT running at 3e6 gain, with no shapers.
///
/// T. Lindner , April 2016
///
double funcEMG(double* x, double* p){
//Exponential gaussian used for fitting
// p[0]: amplitude
// p[1]: gaussian mu
// p[2]: gaussian sig
// p[3]: exponential decay constant - ???
// p[4]: baseline
double y = p[4] + (p[0]/0.3)*(p[3]/2.)*exp((p[1]+p[2]*p[2]/p[3]/2.-x[0])/(p[3]))*
TMath::Erfc((p[1]+p[2]*p[2]/p[3] -x[0])/sqrt(2.)/p[2]);
return y;
}
// Generalizede Normal Version 2 (Skewed Gaussian)
double funcGNV2(double* x, double* p) {
//http://en.wikipedia.org/wiki/Generalized_normal_distribution -- version 2
//p[3] = baseline
//p[4] = mag
//p[5] = sigma
//p[6] = start
//p[7] = end
double alpha, kappa, Xi, y, phi, range; // scale, shape, location, --, standard normal gaussian, pulse region
alpha = p[0];
Xi = p[1];
range = p[7]-p[6];
kappa = p[2];
// For Normal dist (kappa = 0).
if(kappa == 0.)
y = (x[0] - Xi)/alpha;
else
y = - log(1 - kappa*(x[0] - Xi)/alpha) / kappa;
phi = exp(-y*y/p[5]) / sqrt(2*TMath::Pi());
if(x[0] < (p[6]-range) || x[0] > (p[7]+range)) {
return p[3]; // return baseline; helps stabilize
} else {
return p[3] + p[4] * phi / (alpha - kappa*(x[0] - Xi)) * exp(-0.5*pow((x[0]-Xi)/p[5],2));
// Gaussian factor at end
}
}
void findMin(TGraph *gr,double &min, double &min_bin){
double x,y;
for(int j = 0; j < gr->GetN(); j++){
gr->GetPoint(j,x,y);
if(y < min){
min = y;
min_bin = x;
}
}
// std::cout << "min " << min_bin << " " << min << std::endl;
}
void analyze_3inch_data(int nnnn){
{
TFile *f = new TFile("waveforms_r12199_1100V_digitizer_4ns.root");
TTree *waveforms = (TTree*)f->Get("waveformTree");
if(waveforms)
std::cout << "N entries: " << waveforms->GetEntries() << std::endl;
TGraph *gr1 = new TGraph();
waveforms->SetBranchAddress("g_ch1",&gr1);
TGraph *gr2 = new TGraph();
waveforms->SetBranchAddress("g_ch2",&gr2);
TH1F *tdiff = new TH1F("diff","diff",200,0,100);
for(int i = 1; i < waveforms->GetEntries(); i++){
waveforms->GetEntry(i);
// Loop over channels
double times[2] = {-9999,-9999};
for(int ch = 0; ch < 2; ch++){
TGraph *gr;
if(ch == 0) gr = gr1;
else gr = gr2;
// Find the minimum bin
double min = 999999, min_bin = -1;
findMin(gr,min,min_bin);
if(ch == 0){
// Currently only has range set up for EMG, but EMG works well
TF1 *fitted_ref = new TF1("EMG",funcEMG,min_bin-18,min_bin+14,5);
fitted_ref->SetParameter(0,-150);
fitted_ref->SetParameter(1,min_bin);
fitted_ref->FixParameter(2,2);
fitted_ref->FixParameter(3,0.3);
fitted_ref->FixParameter(4,2162);
//Exponential gaussian used for fitting
// p[0]: amplitude
// p[1]: gaussian mu
// p[2]: gaussian sig
// p[3]: exponential decay constant - ???
// p[4]: baseline
gr->Fit("EMG","Q","",min_bin-18,min_bin+14);
times[ch] = fitted_ref->GetParameter(1);
fitted_ref->Draw("SAME");
//sleep(5);
//char c;
//cin << c;
delete fitted_ref;
}else{
if(min <= 3939){
gr->Draw("AP*");
std::cout << "Fitting ch2" << std::endl;
// Currently only has range set up for EMG, but EMG works well
TF1 *fitted_ref = new TF1("EMG",funcEMG,min_bin-18,min_bin+14,5);
fitted_ref->SetParameter(0,-20);
fitted_ref->SetParameter(1,min_bin);
fitted_ref->FixParameter(2,2.5);
fitted_ref->FixParameter(3,3.0);
fitted_ref->FixParameter(4,3943);
//Exponential gaussian used for fitting
// p[0]: amplitude
// p[1]: gaussian mu
// p[2]: gaussian sig
// p[3]: exponential decay constant - ???
// p[4]: baseline
gr->Fit("EMG","Q","",min_bin-18,min_bin+14);
// std::cout << fitted_ref->GetParameter(1) << std::endl;
fitted_ref->Draw("SAME");
times[ch] = fitted_ref->GetParameter(1);
//sleep(5);
//char c;
//cin << c;
delete fitted_ref;
}
}
}
double diff = times[1] - times[0];
std::cout << "diff " << diff << std::endl;
if(times[1] > 0)
tdiff->Fill(diff);
}
TCanvas *c = new TCanvas("C2");
tdiff->Draw();
}
}