-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPhotonisONOFFAnalysis.C
366 lines (291 loc) · 13.9 KB
/
PhotonisONOFFAnalysis.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
#ifdef __MAKECINT__
#pragma link C++ class vector<vector<float> >+;
#endif
#include <iostream>
#include <fstream>
#include <sstream>
#include "TFile.h"
#include "TTree.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TMath.h"
#include "TF1.h"
#include "TGraph.h"
#include "TCanvas.h"
#include "TVirtualFitter.h"
#include "TPaveText.h"
#include "TProfile.h"
#include "TLegend.h"
#include "TStyle.h"
#include "TColor.h"
#include "TGraphErrors.h"
#include "TGraphAsymmErrors.h"
#include "TLatex.h"
#include "TEfficiency.h"
void MakeAmplitudePlot(string filename, string plotname, double scalefactor, double fitmin, double fitmax) {
// Get the tree
TFile *inputfile = new TFile(filename.c_str(),"READ");
TTree *tree = (TTree*)inputfile->Get("tree");
// get the variables from the ntuple
float t1gausroot = 0;
float t2gausroot = 0;
float t3gausroot = 0;
float t4gausroot = 0;
float ch1Amp = 0;
float ch2Amp = 0;
float ch3Amp = 0;
float ch4Amp = 0;
float ch1Int = 0;
float ch2Int = 0;
float ch3Int = 0;
float ch4Int = 0;
unsigned int ch1QualityBit = 0;
unsigned int ch2QualityBit = 0;
unsigned int ch3QualityBit = 0;
unsigned int ch4QualityBit = 0;
tree->SetBranchAddress("t1gausroot",&t1gausroot);
tree->SetBranchAddress("t2gausroot",&t2gausroot);
tree->SetBranchAddress("t3gausroot",&t3gausroot);
tree->SetBranchAddress("t4gausroot",&t4gausroot);
tree->SetBranchAddress("ch1Amp",&ch1Amp);
tree->SetBranchAddress("ch2Amp",&ch2Amp);
tree->SetBranchAddress("ch3Amp",&ch3Amp);
tree->SetBranchAddress("ch4Amp",&ch4Amp);
tree->SetBranchAddress("ch1Int",&ch1Int);
tree->SetBranchAddress("ch2Int",&ch2Int);
tree->SetBranchAddress("ch3Int",&ch3Int);
tree->SetBranchAddress("ch4Int",&ch4Int);
tree->SetBranchAddress("ch1QualityBit",&ch1QualityBit);
tree->SetBranchAddress("ch2QualityBit",&ch2QualityBit);
tree->SetBranchAddress("ch3QualityBit",&ch3QualityBit);
tree->SetBranchAddress("ch4QualityBit",&ch4QualityBit);
//create histograms
TH1F *dt;
TH1F *histAmplitude;
histAmplitude = new TH1F("histAmplitude","; Amplitude [V];Number of Events",20,0,0.5);
dt = new TH1F("dt","; #Delta t [ns]; Number of Events", 1000, -10,10);
double Denominator = 0;
double Numerator = 0;
//read all entries and fill the histograms
Long64_t nentries = tree->GetEntries();
std::cout<<"Number of events in Physics Sample: "<<nentries<<std::endl;
for (Long64_t iEntry=0;iEntry<nentries;iEntry++) {
tree->GetEntry(iEntry);
//require cherenkov and signal in the front MCP
if (ch1Amp > 0.05 && ch4Amp > 0.1) {
if (ch3Amp < 0.49) histAmplitude->Fill(ch3Amp);
if (ch3Amp > 0.02
&& ch1Amp < 0.49 && ch3Amp < 0.49
//&& ch1QualityBit == 0 && ch2QualityBit == 0
) {
dt->Fill(t3gausroot - t1gausroot);
}
if (ch2Amp > 0.02) {
Denominator++;
if (ch3Amp > 0.02) Numerator++;
}
}
}
TCanvas * c = 0;
//Energy plot
c = new TCanvas("c","c",600,600);
histAmplitude->SetAxisRange(0.0,0.5,"X");
histAmplitude->SetTitle("");
histAmplitude->GetXaxis()->SetTitle("Pulse Height [V]");
histAmplitude->GetXaxis()->SetTitleSize(0.045);
histAmplitude->GetXaxis()->SetLabelSize(0.045);
histAmplitude->GetYaxis()->SetTitle("Number of Events");
histAmplitude->GetYaxis()->SetTitleOffset(1.05);
histAmplitude->GetYaxis()->SetTitleSize(0.045);
histAmplitude->GetYaxis()->SetLabelSize(0.045);
histAmplitude->SetMaximum(1.2*histAmplitude->GetMaximum());
histAmplitude->Draw();
histAmplitude->SetStats(0);
histAmplitude->Fit("gaus","","",fitmin,fitmax);
TVirtualFitter * fitter = TVirtualFitter::GetFitter();
TLatex *tex = new TLatex();
tex->SetNDC();
tex->SetTextSize(0.050);
tex->SetTextFont(42);
tex->SetTextColor(kBlack);
//tex->DrawLatex(0.55, 0.80, Form("#sigma/#mu = %.1f %s",100*fitter->GetParameter(2)/fitter->GetParameter(1),"%"));
tex->DrawLatex(0.45, 0.85, Form("Mean = %.2f #pm %.2f %s",fitter->GetParameter(1),fitter->GetParError(1),"V"));
//tex->DrawLatex(0.15, 0.92, Form("Attenuation Factor = %.3f",scalefactor));
c->SaveAs( Form("%s_amplitude.gif", plotname.c_str()) );
c->SaveAs( Form("%s_amplitude.pdf", plotname.c_str()) );
//time resolution plot
c = new TCanvas("c","c",600,600);
dt->SetAxisRange(2.8,3.6,"X");
dt->SetTitle("");
dt->GetXaxis()->SetTitle("#Delta t [ns]");
dt->GetYaxis()->SetTitle("Number of Events");
dt->GetYaxis()->SetTitleOffset(1.1);
dt->GetXaxis()->SetTitleSize(0.045);
dt->GetXaxis()->SetLabelSize(0.045);
dt->GetYaxis()->SetTitleSize(0.045);
dt->GetYaxis()->SetLabelSize(0.040);
dt->SetMaximum(1.2*dt->GetMaximum());
dt->Draw();
dt->SetStats(0);
dt->Fit("gaus","","",2.5,4);
TVirtualFitter * fitter = TVirtualFitter::GetFitter();
TLatex *tex = new TLatex();
tex->SetNDC();
tex->SetTextSize(0.045);
tex->SetTextFont(42);
tex->SetTextColor(kBlack);
tex->DrawLatex(0.53, 0.80, Form("#sigma = %.0f #pm %.0f ps",1000*fitter->GetParameter(2),1000*fitter->GetParError(2)));
// tex->DrawLatex(0.53, 0.85, Form("Mean = %.2f #pm %.2f ps",fitter->GetParameter(1),fitter->GetParError(1)));
tex->DrawLatex(0.53, 0.85, Form("Mean = %.1f ns",fitter->GetParameter(1)));
c->SaveAs( Form("%s_dt.gif", plotname.c_str()) );
c->SaveAs( Form("%s_dt.pdf", plotname.c_str()) );
double effErrlow = Numerator / Denominator - TEfficiency::ClopperPearson((UInt_t)Denominator, (UInt_t)Numerator, 0.68269, kFALSE);
double effErrhigh = TEfficiency::ClopperPearson((UInt_t)Denominator, (UInt_t)Numerator, 0.68269, kTRUE) - Numerator / Denominator;
cout << "Photonis Detection Efficiency (Amplitude > 20mV) : " << Numerator / Denominator
<< " + " << effErrhigh << " - " << effErrlow
<< "\n";
}
Double_t TOFResolutionFunction(Double_t *x,Double_t *par)
{
Double_t arg = 0;
//if (par[2] != 0) arg = (x[0] - par[1])/par[2];
arg = x[0];
Double_t fitval = par[0]*(1.0 / sqrt(arg)) + par[1];
return fitval;
}
void MakeAmplitudeVsShowerDepthGraph() {
//use beam energy for xaxis
float x_photocathodeON[5] = { 2.5, 4.5, 6.5, 8.5, 10.5 };
float xerr_photocathodeON[5] = { 0.25, 0.25, 0.25, 0.25, 0.25 };
float y_photocathodeON[5] = { 0.12, 0.19, 0.19, 0.21, 0.14 };
float yerr_photocathodeON[5] = { 0.01, 0.01, 0.01, 0.03, 0.01 };
float eff_photocathodeON[5] = { 98.5, 97.3, 99.0, 99.5, 94.4 };
float efferrl_photocathodeON[5] = { 0.9, 1.1, 0.8, 0.7, 3.2 };
float efferrh_photocathodeON[5] = { 0.6, 0.8, 0.5, 0.3, 2.2 };
float x_photocathodeOFF[5] = { 2.5, 4.5, 6.5, 8.5, 10.5 };
float xerr_photocathodeOFF[5] = { 0.25, 0.25, 0.25, 0.25, 0.25 };
//float y_photocathodeOFF[5] = { 0.13, 0.32, 0.31, 0.24, 0.24 }; // with low pass filter
float y_photocathodeOFF[5] = { 0.14, 0.33, 0.33, 0.26, 0.23 }; // no low pass filter
float yerr_photocathodeOFF[5] = { 0.01, 0.05, 0.05, 0.03, 0.01 };
float eff_photocathodeOFF[5] = { 99.1, 100, 100, 100, 99.7 };
float efferrl_photocathodeOFF[5] = { 0.7, 0.4, 0.5, 0.8, 0.8 };
float efferrh_photocathodeOFF[5] = { 0.4, 0.0, 0.0, 0.0, 0.3 };
TCanvas * c = 0;
TLegend *legend = 0;
//**********************************
//Amplitude Plot
//**********************************
TGraphErrors *graphON = new TGraphErrors(5,x_photocathodeON,y_photocathodeON,xerr_photocathodeON,yerr_photocathodeON);
TGraphErrors *graphOFF = new TGraphErrors(5,x_photocathodeOFF,y_photocathodeOFF,xerr_photocathodeOFF,yerr_photocathodeOFF);
graphOFF->SetLineWidth(3);
graphON->SetLineWidth(3);
graphON->SetLineColor(kBlue);
c = new TCanvas("c","c",800,600);
graphOFF->Draw("AP");
// graphON->Draw("Psame");
legend = new TLegend (0.65,0.7,0.8,0.85);
legend->SetTextSize(0.03);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->AddEntry(graphOFF, "Photocathode OFF","LP");
//legend->AddEntry(graphON, "Photocathode ON","LP");
legend->Draw();
graphOFF->SetTitle("");
graphOFF->GetXaxis()->SetTitle("Absorber Thickness [X_{0}]");
graphOFF->GetXaxis()->SetTitleOffset(1.2);
graphOFF->GetYaxis()->SetTitle("Mean Amplitude [V]");
graphOFF->GetYaxis()->SetTitleOffset(1.25);
graphOFF->GetYaxis()->SetRangeUser(0,0.6);
c->SaveAs( "AmplitudeVsTungstenThickness_PhotonisPCOFF.gif" );
c->SaveAs( "AmplitudeVsTungstenThickness_PhotonisPCOFF.pdf" );
//**********************************
//Efficiency Plot
//**********************************
c = new TCanvas("c","c",800,600);
TGraphAsymmErrors *EfficiencyGraphOFF = new TGraphAsymmErrors(5,x_photocathodeON,eff_photocathodeOFF,xerr_photocathodeON,xerr_photocathodeON, efferrl_photocathodeOFF, efferrh_photocathodeOFF);
TGraphAsymmErrors *EfficiencyGraphON = new TGraphAsymmErrors(5,x_photocathodeON,eff_photocathodeON,xerr_photocathodeON,xerr_photocathodeON, efferrl_photocathodeON, efferrh_photocathodeON);
EfficiencyGraphOFF->Draw("AP");
EfficiencyGraphOFF->SetLineWidth(3);
legend = new TLegend (0.65,0.3,0.8,0.45);
legend->SetTextSize(0.03);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->AddEntry(EfficiencyGraphOFF, "Photocathode OFF","LP");
//legend->AddEntry(EfficiencyGraphON, "Photocathode ON","LP");
//legend->Draw();
EfficiencyGraphOFF->SetTitle("");
EfficiencyGraphOFF->GetXaxis()->SetTitle("Tungsten Absorber Thickness [X_{0}]");
EfficiencyGraphOFF->GetXaxis()->SetTitleOffset(0.98);
EfficiencyGraphOFF->GetXaxis()->SetTitleSize(0.045);
EfficiencyGraphOFF->GetXaxis()->SetLabelSize(0.040);
EfficiencyGraphOFF->GetYaxis()->SetTitle("Detection Efficiency (%)");
EfficiencyGraphOFF->GetYaxis()->SetTitleSize(0.045);
EfficiencyGraphOFF->GetYaxis()->SetTitleOffset(1.0);
EfficiencyGraphOFF->GetYaxis()->SetRangeUser(95,101);
TLine *line = new TLine(1.45,100,11.6,100);
line->SetLineStyle(2);
line->SetLineWidth(2);
line->Draw();
c->SaveAs( "EfficiencyVsTungstenThickness_PhotonisPCOFF.gif" );
c->SaveAs( "EfficiencyVsTungstenThickness_PhotonisPCOFF.pdf" );
}
void MakeTimeResolutionVsShowerDepthGraph() {
float x_photocathodeON[5] = { 2.5, 4.5, 6.5, 8.5, 10.5 };
float xerr_photocathodeON[5] = { 0.25 , 0.25, 0.25, 0.25, 0.25 };
float y_photocathodeON[5] = { 59 , 62 , 56 , 54, 60 };
float yerr_photocathodeON[5] = { 3 , 3, 2 , 2 , 3 };
float x_photocathodeOFF[5] = { 2.5, 4.5, 6.5, 8.5, 10.5 };
float xerr_photocathodeOFF[5] = { 0.25 , 0.25, 0.25, 0.25, 0.25 };
float y_photocathodeOFF[5] = { 60 , 49 , 48 , 47 , 74 };
float yerr_photocathodeOFF[5] = { 2 , 2, 2 , 2 , 4 };
TGraphErrors *graphON = new TGraphErrors(5,x_photocathodeON,y_photocathodeON,xerr_photocathodeON,yerr_photocathodeON);
TGraphErrors *graphOFF = new TGraphErrors(5,x_photocathodeOFF,y_photocathodeOFF,xerr_photocathodeOFF,yerr_photocathodeOFF);
graphOFF->SetLineWidth(3);
graphOFF->SetLineColor(kBlue);
graphOFF->SetMarkerStyle(21);
graphOFF->SetMarkerSize(1.5);
graphOFF->SetMarkerColor(kBlue);
graphON->SetLineWidth(3);
graphON->SetLineColor(kRed);
graphON->SetMarkerStyle(1);
graphON->SetMarkerColor(kRed);
graphON->SetMarkerSize(1.5);
TCanvas * c = new TCanvas("c","c",800,600);
graphOFF->Draw("AP");
graphON->Draw("Psame");
TLegend *legend = new TLegend (0.40,0.65,0.8,0.85);
legend->SetTextSize(0.05);
legend->SetFillStyle(0);
legend->SetBorderSize(0);
legend->AddEntry(graphOFF, "Photocathode OFF","LP");
legend->AddEntry(graphON, "Photocathode ON","LP");
legend->Draw();
graphOFF->GetXaxis()->SetTitle("Tungsten Absorber Thickness [X_{0}]");
graphOFF->GetXaxis()->SetTitleOffset(0.98);
graphOFF->GetXaxis()->SetTitleSize(0.045);
graphOFF->GetXaxis()->SetLabelSize(0.040);
graphOFF->GetYaxis()->SetTitle("Time Resolution [ps]");
graphOFF->GetYaxis()->SetTitleSize(0.05);
graphOFF->GetYaxis()->SetTitleOffset(0.9);
graphOFF->GetYaxis()->SetRangeUser(0,120);
graphOFF->SetTitle("");
c->SaveAs( "PhotonisTimeResolutionVsAbsorberThickness.gif" );
c->SaveAs( "PhotonisTimeResolutionVsAbsorberThickness.pdf" );
}
void PhotonisONOFFAnalysis() {
//*************************************
// Photocathode ON Vs Shower Depth
//*************************************
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_61.root.ana_lowpassfilter.root","PhotonisPhotocathodeON_Electron_NoAbsorber_8GeV", 1.0, 0.03, 0.3);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_60.root.ana_lowpassfilter.root","PhotonisPhotocathodeON_Electron_2X0Tungsten_8GeV", 1.0, 0.05, 0.4);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_62.root.ana_lowpassfilter.root","PhotonisPhotocathodeON_Electron_4X0Tungsten_8GeV", 1.0, 0.05, 0.4);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_63.root.ana_lowpassfilter.root","PhotonisPhotocathodeON_Electron_6X0Tungsten_8GeV", 1.0, 0.05, 0.4);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_64.root.ana_lowpassfilter.root","PhotonisPhotocathodeON_Electron_8X0Tungsten_8GeV", 1.0, 0.05, 0.4);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_52.ana.root","PhotonisPhotocathodeOFF_Electron_NoAbsorber_8GeV", 1.0, 0.03, 0.3);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_51.ana.root","PhotonisPhotocathodeOFF_Electron_2X0Tungsten_8GeV", 1.0, 0.01, 0.5);
MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_53.root.ana_lowpassfilter.root","PhotonisPhotocathodeOFF_Electron_4X0Tungsten_8GeV", 1.0, 0.01, 0.5);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_54And55.ana.root","PhotonisPhotocathodeOFF_Electron_6X0Tungsten_8GeV", 1.0, 0.01, 0.5);
//MakeAmplitudePlot("/uscms_data/d2/sxie/releases/CMSSW_7_2_3/src/Timing/t1058-jan-2015/t1058_jan2015_run_56And57.ana.root","PhotonisPhotocathodeOFF_Electron_8X0Tungsten_8GeV", 1.0, 0.01, 0.5);
//MakeAmplitudeVsShowerDepthGraph();
// MakeTimeResolutionVsShowerDepthGraph();
}