-
Notifications
You must be signed in to change notification settings - Fork 0
/
DC_read_adc_50us_inv.C
327 lines (271 loc) · 8.81 KB
/
DC_read_adc_50us_inv.C
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
{
#include "Riostream.h"
#include "TObject.h"
#include "TString.h"
#include <iostream>
#include <string>
#include <vector>
// using namespace std;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_________________________________________________IMPORT FILES________________________________________________________//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
string StringInput(string input = "config_file.txt", string key = "TEST")
{
fstream newfile;
string string_text;
newfile.open(input, ios::in); // open a file to perform read operation using file object
if (newfile.is_open())
{ // checking whether the file is open
string tp;
while (getline(newfile, tp))
{ // read data from file object and put it into string.
if (tp.rfind(key, 0) == 0)
{ // pos=0 limits the search to the prefix
istringstream stream(tp);
string s;
stream >> s >> string_text; // s starts with prefix
}
}
newfile.close(); // close the file object.
}
return string_text;
}
string input = "CONFIG_DC_NO_FILT.txt";
string folder;
string out_file;
folder = StringInput(input, "FOLDER:");
out_file = StringInput(input, "OUT_FILE:");
TString output = out_file;
TFile *fil2 = new TFile(output, "RECREATE");
////// Booking Histograms //////
int Nunits = 25002; // Nsamples for 50us
float Min = 0.;
double DeltaT = 2.;
int Nsegs = 50;
string sNevents;
sNevents = StringInput(input, "NEVENTS:");
int Nevents = stoi(sNevents);
int nsamples = Nunits;
float Max = Min + Nunits * DeltaT;
TH1F *hAux;
TH1F *hW_av[12000]; // Nsegs*Nevents
TH1F *hW_adc[12000];
TH1F *hA;
TH1F *hQ;
TH1F *hrate = new TH1F("hrate", ";DCR (mHz/mm^{2});Entries", 500, 0., 1000.);
// A histogram for every segment
for (int ie = 0; ie < Nevents; ie++)
{
for (int i = 0; i < Nsegs; i++)
{
hW_av[(Nsegs * ie) + i] = new TH1F(Form("hW_Ev%dSeg%d", ie, i), "", nsamples, Min, Max);
hW_adc[(Nsegs * ie) + i] = new TH1F(Form("hWadc_Ev%dSeg%d", ie, i), "", nsamples, Min, Max);
}
}
// Logaritmic histogram for Dt vs Amplitude
const Int_t nbins = 1000;
const Int_t nbins2 = 100;
Double_t xmin = 1.e-9;
Double_t xmax = 10.;
Double_t logxmin = TMath::Log10(xmin);
Double_t logxmax = TMath::Log10(xmax);
Double_t binwidth = (logxmax - logxmin) / nbins;
Double_t xbins[nbins + 1];
xbins[0] = xmin;
for (Int_t i = 1; i <= nbins; i++)
{
xbins[i] = xmin + TMath::Power(10, logxmin + i * binwidth);
}
TH2F *hDelta = new TH2F("hDelta", ";#DeltaT (s);Amplitude (V)", nbins, xbins, 500., 0., 0.1);
Double_t binwidth2 = (logxmax - logxmin) / nbins2;
Double_t xbins2[nbins2 + 1];
xbins2[0] = xmin;
for (Int_t i = 1; i <= nbins2; i++)
{
xbins2[i] = xmin + TMath::Power(10, logxmin + i * binwidth2);
}
TH1F *hDt = new TH1F("hDt", ";#DeltaT (s);", nbins2, xbins2);
///////////////////////////////
TString file;
TString Line1, Line2, Line3, Line4;
TString C1, C2;
Double_t Dt[50]; // Nsegs
Double_t tim, adc;
char c;
double peakA[11000]; // Vectors with pulse information
double peakT[11000];
double Delta[11000];
int p = 0; // number of pulses
// float alpha= 25./(25.+2.); // high-pass filter
float alpha = 50. / (50. + 2.);
// float alpha= 100./(100.+2.); // Used for FBK
// float alpha= 150./(150.+2.); // high-pass filter
float rate[200]; // DC rate per event
float RT = 0.;
for (int i = 0; i < Nevents; i++)
// for (int i=0;i<1; i++)
{
// file = "/pc/choozdsk01/palomare/SiPM/TT_FBK_02/DC/OV25-sec-50-50us--";
// file = "/pc/choozdsk01/palomare/SiPM/Ganging_FBK_TT/OV7/DC/DC--";
string file;
string ffile;
file = StringInput(input, "FILE:");
// file = "/pc/choozdsk01/palomare/SiPM/TT_FBK_02/DC/OV25-sec-50-50us--";
// file = "/pc/choozdsk01/palomare/SiPM/SC_11-8-21_DC/C1--Trig_SC1_OV3--";
// if ( i==35 ) continue;
if (i < 10000)
ffile = file + "0";
if (i < 1000)
ffile = file + "00";
if (i < 100)
ffile = file + "000";
if (i < 10)
ffile = file + "0000";
// file += i;
// file += ".txt";
ifstream fd1;
fd1.open(Form("%s%s%i.txt", folder.c_str(), ffile.c_str(), i));
cout << "Opening File " << i << " " << ffile << endl;
fd1 >> Line1;
fd1 >> Line2;
fd1 >> Line3;
cout << Line1 << " // " << Line2 << " // " << Line3 << endl;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//_____________________________________________READ FILE INFORMATION___________________________________________________//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Reading segment information
int Nes = 0;
for (int ij = 0; ij < Nsegs; ij++)
{
fd1 >> C1 >> C2;
TString C3(C2(9, 17));
Dt[ij] = C3.Atof();
cout << C1 << " " << Dt[ij] << endl;
}
// rate[i] = Nsegs/Dt[Nsegs-1];
// RT+=rate[i];
fd1 >> Line4;
cout << Line4 << endl;
double sum = 0.;
int is = 0;
int l = 0;
int idc = 0;
double adc_min = 0.;
double time_min = 0.;
double sum_time = 0.;
double adc_diff = 0.;
double time_diff = 0.;
double f = 0.;
double f_old = 0.;
double sum_old = 0.;
for (int ij = 0; ij < Nsegs; ij++)
{
if (hAux)
{
delete hAux;
hAux = NULL;
}
hAux = new TH1F("hAux", "", nsamples, Min, Max);
sum_time = 0.;
Double_t mean_ped_i = 0.;
Double_t mean_ped_f = 0.;
int j = 0;
double Vadc[25002];
int Nnoise = 0;
while (j < Nunits)
{
fd1 >> tim >> c >> adc;
hAux->Fill(DeltaT * (j + 0.5), adc);
// if ( adc>0.002 ) Nnoise++;
Vadc[j] = adc;
j++;
}
int maximumS1 = hAux->GetMaximumBin();
Double_t MaxS1 = hAux->GetBinContent(maximumS1);
int minimumS1 = hAux->GetMinimumBin();
Double_t MinS1 = hAux->GetBinContent(minimumS1);
// if ( MaxS1<-0.003 ) cout << "maximumS1 " << MaxS1 << endl;
// if ( MaxS1>-0.003 ) Nes++;
if (MaxS1 > 0.005)
cout << "maximumS1 " << MaxS1 << endl;
// if ( MaxS1>0.005 ) Nes++;
if (MaxS1 > 0.005)
Nes++;
if (MinS1 < -0.01)
cout << "Nnoise " << Nnoise << endl;
j = 0;
// while (j<Nunits && MaxS1>-0.003)
while (j < Nunits && MaxS1 > 0.01)
{
// Pedestal info
if (j < 20)
mean_ped_i += Vadc[j];
if (j == 20)
{
mean_ped_i /= 20.;
}
if (j > 480 && j < 500)
mean_ped_f += Vadc[j];
if (j == 500)
mean_ped_f /= 20.;
// f = Vadc[j];
// High-pass filtering
if (f == 0)
{
f = Vadc[j];
f_old = f;
}
else
{
// f = alpha*f_old+alpha*(Vadc[j]-sum_old);
f = Vadc[j];
f_old = f;
sum_old = Vadc[j];
}
// hW_av[(Nsegs*i)+ij]->Fill(DeltaT*(j+0.5),f);
hW_adc[(Nsegs * i) + ij]->Fill(DeltaT * (j + 0.5), Vadc[j]);
// Searching for pulses
if ((f > 0.012 && sum_time < 200. && j > 5) || (sum_time > 0 && sum_time < 200.)) // Threshold and timing should be tuned
// if ( (f<-0.003 && sum_time<200.) || (sum_time>0 && sum_time<100.) ) // Threshold and timing should be tuned
{
if (f > adc_min)
{
adc_min = f;
time_min = Dt[ij] * 1.e+9 + DeltaT * (j + 0.5);
}
l++;
sum_time = DeltaT * l;
// l++;
}
else if (sum_time >= 200.)
{
peakA[p] = adc_min;
peakT[p] = time_min;
if (p > 0)
Delta[p] = time_min - peakT[p - 1];
if (Delta[p] > 200.)
idc++;
cout << ">> p " << p << " Seg " << ij << " A " << peakA[p] << " T " << peakT[p] << " D " << Delta[p] << endl;
hDelta->Fill(Delta[p] * 1.e-9, peakA[p]);
hDt->Fill(Delta[p] * 1.e-9);
p++;
sum_time = 0.;
adc_min = 0.;
time_min = 0.;
l = 0;
}
j++;
} // end loop one segment
} // end loop segments
rate[i] = Nes / Dt[Nsegs - 1];
float dcr = rate[i] * 1000. / 36.;
hrate->Fill(dcr);
RT += rate[i];
} // end loop Events
for (int i = 0; i < Nevents; i++)
cout << i << " " << rate[i] << endl;
RT /= float(Nevents);
cout << "Total DC Rate " << RT << endl;
fil2->Write();
fil2->Close();
}