/
thScan.cpp
297 lines (255 loc) · 10.3 KB
/
thScan.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
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
//g++ -o thScan `root-config --cflags --glibs` thScan.cpp
// ./thScan WaveForms_BTF/scan.dat
#include <cstdio>
#include <cstdlib>
#include <stdint.h>
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <stdint.h>
#include <iomanip>
#include <ctime>
#include <map>
#include <math.h>
#include "TROOT.h"
#include "TFile.h"
#include "TSystem.h"
#include "TStyle.h"
#include "TChain.h"
#include "TF1.h"
#include "TH1F.h"
#include "TH1D.h"
#include "TProfile.h"
#include "TMath.h"
#include "TString.h"
#include "TClass.h"
#include "TApplication.h"
#include "analysis_tools.h"
#include "InitTree_BTF.h"
int main (int argc, char** argv)
{
// get run number
std::string inputName = std::string(argv[1]);
char split_char = '/';
std::vector<std::string> tokens;
std::istringstream split(inputName);
for(std::string each; getline(split, each, split_char);
tokens.push_back(each));
split_char = '_';
std::vector<std::string> tokens_name;
std::istringstream split_name(tokens.at(1));
for(std::string each; getline(split_name, each, split_char);
tokens_name.push_back(each));
const int Ch_ref1 = atoi((tokens_name.at(1)).c_str());
const int Ch_ref2 = atoi((tokens_name.at(3)).c_str());
const int Ch_1 = atoi((tokens_name.at(5)).c_str());
const int Ch_2 = atoi((tokens_name.at(7)).c_str());
const int Ch_3 = atoi((tokens_name.at(9)).c_str());
std::vector<std::string> nameMCP;
nameMCP.push_back("MiB1");
nameMCP.push_back("MiB2");
nameMCP.push_back("ScB");
nameMCP.push_back("Planacon");
nameMCP.push_back("MiB3");
nameMCP.push_back("Roma2");
if(tokens_name.at(0) == "Scan3") nameMCP.at(1) = "Roma1";
std::vector<std::string> pcMCP;
for(unsigned int ii=0; ii<nameMCP.size(); ++ii) pcMCP.push_back("");
pcMCP.at(Ch_ref1) = tokens_name.at(2);
pcMCP.at(Ch_ref2) = tokens_name.at(4);
pcMCP.at(Ch_1) = tokens_name.at(6);
pcMCP.at(Ch_2) = tokens_name.at(8);
pcMCP.at(Ch_3) = tokens_name.at(10);
//---treshold setup Scan-dependent
init();
const int iScanTh = atoi(argv[2])-1;
float Ch_th[6]={0,0,0,0,0,0};
Ch_th[Ch_ref1] = _th[iScanTh][Ch_ref1];
Ch_th[Ch_ref2] = _th[iScanTh][Ch_ref2];
Ch_th[Ch_1] = _th[iScanTh][Ch_1];
Ch_th[Ch_2] = _th[iScanTh][Ch_2];
Ch_th[Ch_3] = _th[iScanTh][Ch_3];
TFile* out = TFile::Open((tokens_name.at(0)+"_outHistos.root").c_str(),"recreate");
out->cd();
//Output dat
std::ofstream data1(("analized_data/"+tokens_name.at(0)+"_"+nameMCP.at(Ch_1)+"_pc_"+pcMCP.at(Ch_1)+".dat").data());
std::ofstream data2(("analized_data/"+tokens_name.at(0)+"_"+nameMCP.at(Ch_2)+"_pc_"+pcMCP.at(Ch_2)+".dat").data());
std::ofstream data3(("analized_data/"+tokens_name.at(0)+"_"+nameMCP.at(Ch_3)+"_pc_"+pcMCP.at(Ch_3)+".dat").data());
int nFiles = 1, iRun = 0, goodEvt = 0;
int iScan = 0;
//---usefull histos
TH1F* chHistoBase_All[9];
TH1F* chHistoSignal_All[9];
TH1F* timeDiffHisto[9];
TH1F* timeDiffHisto_Double = new TH1F("timeDiffHisto_Double", "timeDiffHisto_Double",5000,-10,10);
//---histos initialization
for(int iCh=0; iCh<6; ++iCh)
{
char h1[30], h2[30], h3[30];
sprintf(h1, "histoBase_All_Ch%d", iCh);
sprintf(h2, "histoSignal_All_Ch%d", iCh);
sprintf(h3, "histoTime_Ch%d", iCh);
chHistoBase_All[iCh] = new TH1F(h1,h1,30000,-30000,1000);
chHistoSignal_All[iCh] = new TH1F(h2, h2,30000,-30000,1000);
timeDiffHisto[iCh] = new TH1F(h3, h3,1024,0,1024);
}
//---do runs loop
ifstream log (argv[1], ios::in);
while(log >> nFiles)
{
++iScan;
vector<float> digiCh[9];
float timeCF[9];
float baseline[9];
float intSignal[9], intBase[9];
int count[5]={0,0,0,0,0}, spare[5]={0,0,0,0,0}, spare2[5]={0,0,0,0,0};
int tot_tr1 = 0, tot_tr0 = 0, trig = 0;
int HV1=0, HV2=0, HV3=0;
TH1F* chHistoWF_Ch[9];
TH1F* chHistoBase_Ch[9];
TH1F* chHistoSignal_Ch[9];
TH1F* timeDiffHisto_Triple_Ch1 = new TH1F(Form("timeDiffHisto_Triple_Ch1_Scan%d",iScan), "", 5000,-100,100);
TH1F* timeDiffHisto_Triple_Ch2 = new TH1F(Form("timeDiffHisto_Triple_Ch2_Scan%d",iScan), "", 5000,-100,100);
TH1F* timeDiffHisto_Triple_Ch3 = new TH1F(Form("timeDiffHisto_Triple_Ch3_Scan%d",iScan), "", 5000,-100,100);
char ha[10];
for (int iiw=0;iiw<9;++iiw){
sprintf (ha,"histoWF_Ch%d_Scan_%d",iiw, iScan);
chHistoWF_Ch[iiw] = new TH1F( ha, "", 1024,0.,1024);
chHistoWF_Ch[iiw]->SetXTitle("Waveform");
sprintf (ha,"histoBase_Ch%d_Scan_%d",iiw, iScan);
chHistoBase_Ch[iiw] = new TH1F( ha, "", 30000,-30000,1000);
chHistoBase_Ch[iiw] -> SetXTitle ("Integral BaseLine Ch(ADC)");
sprintf (ha,"histoSignal_Ch%d_Scan_%d",iiw, iScan);
chHistoSignal_Ch[iiw] = new TH1F( ha, "", 30000,-30000,1000);
chHistoSignal_Ch[iiw] -> SetXTitle ("Integral Signal Ch(ADC)");
}
//---data chain
TChain* chain = new TChain("eventRawData");
InitTree(chain);
for(int iFiles=0; iFiles<nFiles; iFiles++){
log >> iRun;
char iRun_str[30];
sprintf(iRun_str, "../Analysis_TB/DATA/run_IMCP_%d_*.root", iRun);
chain->Add(iRun_str);
cout << "Reading: ../Analysis_TB/DATA/run_IMCP_" << iRun << endl;
}
log >> HV1 >> HV2 >> HV3;
for(int iEntry=0; iEntry<chain->GetEntries(); iEntry++) {
//---always clear the std::vector !!!
for(int iCh=0; iCh<9; iCh++) digiCh[iCh].clear();
//---Read the entry
chain->GetEntry(iEntry);
//---DAQ bug workaround
if(iRun < 145) goodEvt = 10;
else goodEvt = 1;
if(evtNumber % goodEvt == 0){
//---Read SciFront ADC value and set the e- multiplicity
//---(default = 1)
trig = 1;
for(int iCh=0; iCh<nAdcChannels; iCh++)
{
if(adcData[iCh] > 1500 && adcBoard[iCh] == 1 && adcChannel[iCh] == 0) trig=2;
if(adcData[iCh] < 500 && adcBoard[iCh] == 1 && adcChannel[iCh] == 0) trig=0;
}
if(trig > 1) continue;
//---Read digitizer samples
for(int iSample=0; iSample<nDigiSamples; iSample++){
if(digiChannel[iSample] == 3){
digiCh[digiChannel[iSample]].push_back(-digiSampleValue[iSample]);
chHistoWF_Ch[digiChannel[iSample]]->SetBinContent(digiSampleIndex[iSample]+1, -digiSampleValue[iSample]);
}
else{
digiCh[digiChannel[iSample]].push_back(digiSampleValue[iSample]);
chHistoWF_Ch[digiChannel[iSample]]->SetBinContent(digiSampleIndex[iSample]+1, digiSampleValue[iSample]);
}
}
for(int iCh=0; iCh<6; iCh++){
// baseline[iCh] = SubtractBaseline(5, 25, &digiCh[iCh]);
baseline[iCh] = SubtractBaseline(26, 46, &digiCh[iCh]);
intBase[iCh] = ComputeIntegral(26, 46, &digiCh[iCh]);
if(trig == 0) {
chHistoBase_All[iCh]->Fill(ComputeIntegral(26, 46, &digiCh[iCh]));
chHistoBase_Ch[iCh]->Fill(ComputeIntegral(26, 46, &digiCh[iCh]));
// chHistoBase_All[iCh]->Fill(ComputeIntegral(0, 150, &digiCh[iCh]));
// chHistoBase_Ch[iCh]->Fill(ComputeIntegral(0, 150, &digiCh[iCh]));
}
timeCF[iCh]=TimeConstFrac(30, 500, &digiCh[iCh], 0.5);
// timeDiffHisto[iCh]->Fill(timeCF[iCh]*0.2-timeCF[0]*0.2);
timeDiffHisto[iCh]->Fill(timeCF[iCh]);
int t1 = (int)(timeCF[iCh]/0.2) - 3;
int t2 = (int)(timeCF[iCh]/0.2) + 17;
//---Fill the signal integral histo only if the e- multiplicity is 1
if(t1 > 30 && t1 < 1024 && t2 > 30 && t2 < 1024 && trig == 1)
{
chHistoSignal_All[iCh]->Fill(ComputeIntegral(t1, t2, &digiCh[iCh]));
chHistoSignal_Ch[iCh]->Fill(ComputeIntegral(t1, t2, &digiCh[iCh]));
intSignal[iCh] = ComputeIntegral(t1, t2, &digiCh[iCh]);
}
else intSignal[iCh] = ComputeIntegral(50, 70, &digiCh[iCh]);
}// loop over Ch
//---Multiplicity == 1 --> compute efficency, fake rate and timing
if(intSignal[Ch_ref1] < Ch_th[Ch_ref1] && intSignal[Ch_ref2] < Ch_th[Ch_ref2] && trig == 1){
++tot_tr1;
float tDiff = (timeCF[Ch_ref1] - timeCF[Ch_ref2]);
float tMean = (timeCF[Ch_ref1] + timeCF[Ch_ref2])*0.5;
timeDiffHisto_Double->Fill(tDiff);
timeDiffHisto_Triple_Ch1->Fill(tMean - timeCF[Ch_1]);
timeDiffHisto_Triple_Ch2->Fill(tMean - timeCF[Ch_2]);
timeDiffHisto_Triple_Ch3->Fill(tMean - timeCF[Ch_3]);
if(intSignal[Ch_1] < Ch_th[Ch_1]) ++count[1];
if(intSignal[Ch_2] < Ch_th[Ch_2]) ++count[2];
if(intSignal[Ch_3] < Ch_th[Ch_3]) ++count[3];
if(intBase[Ch_1] < Ch_th[Ch_1]) ++spare[1];
if(intBase[Ch_2] < Ch_th[Ch_2]) ++spare[2];
if(intBase[Ch_3] < Ch_th[Ch_3]) ++spare[3];
}
}// good Event
}// loop over entries
std::cout << "HV1 = " << HV1 << " HV2 = " << HV2 << " HV3 = " << HV3 << std::endl;
double eff1 = ((double)count[1]-(double)spare[1])/(double)tot_tr1;
double eff2 = ((double)count[2]-(double)spare[2])/(double)tot_tr1;
double eff3 = ((double)count[3]-(double)spare[3])/(double)tot_tr1;
double eff1Err = TMath::Sqrt((eff1*(1-eff1))/tot_tr1);
double eff2Err = TMath::Sqrt((eff2*(1-eff2))/tot_tr1);
double eff3Err = TMath::Sqrt((eff3*(1-eff3))/tot_tr1);
std::cout << "Ch_1 eff = " << eff1 << " +/- " << eff1Err << std::endl;
std::cout << "Ch_2 eff = " << eff2 << " +/- " << eff2Err << std::endl;
std::cout << "Ch_3 eff = " << eff3 << " +/- " << eff3Err << std::endl;
/*
data1 << HV1 << " " << eff1 << " " << 0 << " " << eff1Err << std::endl;
data1 << HV2 << " " << eff2 << " " << 0 << " " << eff2Err << std::endl;
data1 << HV3 << " " << eff3 << " " << 0 << " " << eff3Err << std::endl;
*/
for(int iw=0; iw<6; ++iw){
if(iw == 2) continue;
chHistoBase_Ch[iw]->Write();
chHistoSignal_Ch[iw]->Write();
chHistoWF_Ch[iw]->Write();
}
timeDiffHisto_Triple_Ch1->Write();
timeDiffHisto_Triple_Ch2->Write();
timeDiffHisto_Triple_Ch3->Write();
chain->Delete();
}
for(int iw=0; iw<6; ++iw){
if(iw == 2) continue;
chHistoBase_All[iw]->Write();
chHistoSignal_All[iw]->Write();
timeDiffHisto[iw]->Write();
}
data1.close();
data2.close();
data3.close();
timeDiffHisto_Double->Write();
out->Close();
return 0;
}