-
Notifications
You must be signed in to change notification settings - Fork 0
/
Displayer.cxx
273 lines (265 loc) · 10.7 KB
/
Displayer.cxx
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
#if !defined (__CINT__) || defined(__ROOTCINT__)
#include "TFile.h"
#include "TTree.h"
#include "TClonesArray.h"
#include "TH1D.h"
#include "TStyle.h"
#include "TEfficiency.h"
#include "Point.h"
#include "Hit.h"
#include "TMath.h"
#include "TPad.h"
#include "TCanvas.h"
#include <algorithm>
#include <vector>
#include <string>
#endif
using namespace std;
using namespace TMath;
//Function to print the resolution histogram
void ResolutionHistogram(string input_file_name){
TFile *input_file = new TFile(input_file_name.c_str());
if(input_file->IsZombie()) {
cout<< "File Not Found! Please check file name"<<endl;
return;
}
TTree *input_tree = (TTree*)input_file->Get("ppSimulation");
Point VTX;
Point *VTX_ptr=&VTX;
Double_t RecoVTX_Z;
Bool_t isReconstructed;
TBranch *b1=input_tree->GetBranch("Vertex");
b1->SetAddress(&VTX_ptr);
TBranch *b2=input_tree->GetBranch("RecoVertexZ");
b2->SetAddress(&RecoVTX_Z);
TBranch *b3=input_tree->GetBranch("is_reconstructed");
b3->SetAddress(&isReconstructed);
TCanvas *c1 = new TCanvas("c1","Resolution Histogram");
TH1D *ResHist = new TH1D("Resolution","Resolution;#DeltaZ (cm)",75,-0.25,0.25);
ResHist->SetDirectory(0);
for (Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
if(isReconstructed)ResHist->Fill(VTX.GetZ()-RecoVTX_Z);
// cout << VTX.GetZ()<<"\t"<<RecoVTX_Z<<endl;
// if (((VTX.GetZ()-RecoVTX_Z) < -2)&&isReconstructed) cout << i << endl;
}
ResHist->Draw();
input_file->Close();
delete input_file;
}
//Function to plot the resolution vs generated Z histogram (best results are obtained if Z is generated with a uniform distribution)
void ResolutionVsGeneratedZHistogram(string input_file_name,Int_t bins){
TFile *input_file = new TFile(input_file_name.c_str());
if(input_file->IsZombie()) {
cout<< "File Not Found! Please check file name"<<endl;
return;
}
TTree *input_tree = (TTree*)input_file->Get("ppSimulation");
Point VTX;
Point *VTX_ptr=&VTX;
Double_t RecoVTX_Z;
Bool_t isReconstructed;
vector<Double_t>GeneratedZ;
vector<Double_t>RecoZ;
TBranch *b1=input_tree->GetBranch("Vertex");
b1->SetAddress(&VTX_ptr);
TBranch *b2=input_tree->GetBranch("RecoVertexZ");
b2->SetAddress(&RecoVTX_Z);
TBranch *b3=input_tree->GetBranch("is_reconstructed");
b3->SetAddress(&isReconstructed);
for (Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
if (isReconstructed){
GeneratedZ.push_back(VTX.GetZ());
RecoZ.push_back(RecoVTX_Z);
}
}
TH1D *ResHist = new TH1D("ResolutionHistogram","Risoluzione",75,-0.25,0.25);
vector<Double_t>GeneratedZAux(GeneratedZ);
sort(GeneratedZAux.begin(),GeneratedZAux.end());
Double_t binsize = (GeneratedZAux.back()-GeneratedZAux.front())/bins;
TCanvas *c1 = new TCanvas("c1","Resolution Vs Z Histogram");
TH1D *ResVsZHist = new TH1D("ResolutionVsZHistogram","Resolution vs Generated Z;Z (cm);Resolution (cm)",bins,GeneratedZAux.front(),GeneratedZAux.back());
ResVsZHist->SetDirectory(0);
for (Int_t i=1;i<=bins;i++){
Int_t counter=0;
for(unsigned j=0;j<GeneratedZ.size();j++){
if(GeneratedZ.at(j)>=GeneratedZAux.front()+binsize*(i-1) && GeneratedZ.at(j)<GeneratedZAux.front()+binsize*(i)){
ResHist->Fill(GeneratedZ.at(j)-RecoZ.at(j));
counter++;
}
}
ResVsZHist->SetBinContent(i,ResHist->GetStdDev());
ResVsZHist->SetBinError(i,ResHist->GetStdDevError());
ResHist->Reset();
}
ResVsZHist->SetLineColor(kBlack);
ResVsZHist->SetMarkerStyle(8);
ResVsZHist->GetYaxis()->SetTitleOffset(1.2);
gStyle->SetOptStat(0);
ResVsZHist->Draw("E1 P");
delete ResHist;
input_file->Close();
delete input_file;
}
//Function to plot the resolution vs generated multiplicity histogram (best results are obtained if the multiplicity is generated with a uniform distribution)
void ResolutionVsMultiplicityHistogram(string input_file_name,Int_t bins){
TFile *input_file = new TFile(input_file_name.c_str());
if(input_file->IsZombie()) {
cout<< "File Not Found! Please check file name"<<endl;
return;
}
TTree *input_tree = (TTree*)input_file->Get("ppSimulation");
Point VTX;
Point *VTX_ptr=&VTX;
Double_t RecoVTX_Z;
Bool_t isReconstructed;
vector<Double_t>GeneratedZ;
vector<Double_t>RecoZ;
Int_t multiplicity;
vector<Int_t>Multiplicity;
TBranch *b1=input_tree->GetBranch("Vertex");
b1->SetAddress(&VTX_ptr);
TBranch *b2=input_tree->GetBranch("RecoVertexZ");
b2->SetAddress(&RecoVTX_Z);
TBranch *b3=input_tree->GetBranch("is_reconstructed");
b3->SetAddress(&isReconstructed);
TBranch *b4=input_tree->GetBranch("Multiplicity");
b4->SetAddress(&multiplicity);
for (Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
if (isReconstructed){
GeneratedZ.push_back(VTX.GetZ());
RecoZ.push_back(RecoVTX_Z);
Multiplicity.push_back(multiplicity);
}
}
TH1D *ResHist = new TH1D("ResolutionHistogram","Risoluzione",500,-2,2);
vector<Int_t> MultiplicityAux(Multiplicity);
sort(MultiplicityAux.begin(),MultiplicityAux.end());
Double_t binsize = (MultiplicityAux.back()-MultiplicityAux.front())/bins;
TCanvas *c1 = new TCanvas("c1","Resolution Vs Multiplicity Histogram");
TH1D *ResVsZHist = new TH1D("ResolutionVsMultiplicityHistogram","Resolution vs Multiplicity;Multiplicity;Resolution (cm)",bins,MultiplicityAux.front(),MultiplicityAux.back());
ResVsZHist->SetDirectory(0);
for (Int_t i=1;i<=bins;i++){
Int_t counter=0;
for(unsigned j=0;j<Multiplicity.size();j++){
if(Multiplicity.at(j)>=MultiplicityAux.front()+binsize*(i-1) && Multiplicity.at(j)<MultiplicityAux.front()+binsize*(i)){
ResHist->Fill(GeneratedZ.at(j)-RecoZ.at(j));
counter++;
}
}
cout<<counter<<endl;
ResVsZHist->SetBinContent(i,ResHist->GetStdDev());
ResVsZHist->SetBinError(i,ResHist->GetStdDevError());
ResHist->Reset();
}
ResVsZHist->SetLineColor(kBlack);
ResVsZHist->SetMarkerStyle(8);
ResVsZHist->GetYaxis()->SetTitleOffset(1.2);
gStyle->SetOptStat(0);
ResVsZHist->Draw("E1 P");
delete ResHist;
input_file->Close();
delete input_file;
}
//Function to print the efficiency vs generated multiplicity histogram (must be run on a file created with a custom multiplicity distribution between 0 and 50, giving discrete multiplicities with equal probabilities)
void EfficiencyVsMultiplicityHistogram(string input_file_name){
TFile *input_file = new TFile(input_file_name.c_str());
if(input_file->IsZombie()) {
cout<< "File Not Found! Please check file name"<<endl;
return;
}
TTree *input_tree = (TTree*)input_file->Get("ppSimulation");
Bool_t isReconstructed;
Int_t multiplicity;
TBranch *b1=input_tree->GetBranch("is_reconstructed");
b1->SetAddress(&isReconstructed);
TBranch *b2=input_tree->GetBranch("Multiplicity");
b2->SetAddress(&multiplicity);
TCanvas *c1 = new TCanvas("c1","Efficiency Vs Multiplicity");
TEfficiency *eff = new TEfficiency("eff","Efficiency Vs Multiplicity;Multiplicity;Efficiency",50,0.5,50.5);
eff->SetDirectory(0);
for(Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
eff->Fill(isReconstructed,multiplicity);
}
eff->Draw("AP");
input_file->Close();
delete input_file;
}
//Function to print the efficiency vs generated multiplicity histogram for particles within 1 sigma(best results are obtained with a uniform multiplicity distribution)
void EfficiencyVsMultiplicityHistogram1Sigma(string input_file_name){
TFile *input_file = new TFile(input_file_name.c_str());
if(input_file->IsZombie()) {
cout<< "File Not Found! Please check file name"<<endl;
return;
}
TTree *input_tree = (TTree*)input_file->Get("ppSimulation");
Bool_t isReconstructed;
Int_t multiplicity;
Point VTX;
Point *VTX_ptr=&VTX;
Double_t RecoVTX_Z;
TBranch *b1=input_tree->GetBranch("is_reconstructed");
b1->SetAddress(&isReconstructed);
TBranch *b2=input_tree->GetBranch("Multiplicity");
b2->SetAddress(&multiplicity);
TBranch *b3=input_tree->GetBranch("Vertex");
b3->SetAddress(&VTX_ptr);
TBranch *b4=input_tree->GetBranch("RecoVertexZ");
b4->SetAddress(&RecoVTX_Z);
TH1D *ResHist = new TH1D("ResolutionHistogram","Risoluzione",500,-2,2);
TCanvas *c1 = new TCanvas("c1","Efficiency Vs Multiplicity 1 Sigma");
TEfficiency *eff = new TEfficiency("eff","Efficiency Vs Multiplicity for particles within #sigma;Multiplicity;Efficiency",50,0.5,50.5);
eff->SetDirectory(0);
for (Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
if(isReconstructed)ResHist->Fill(VTX.GetZ());
}
Double_t sigma = ResHist->GetStdDev();
Double_t mean = ResHist->GetMean();
delete ResHist;
for(Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
if(TMath::Abs(VTX.GetZ()-mean)<sigma){
eff->Fill(isReconstructed,multiplicity);
}
}
eff->Draw("AP");
input_file->Close();
delete input_file;
}
//Function to print the efficiency vs noise histogram (must be run on a variable noise dataset)
void EfficiencyVsNoiseHistogram(string input_file_name){
TFile *input_file = new TFile(input_file_name.c_str());
if(input_file->IsZombie()) {
cout<< "File Not Found! Please check file name"<<endl;
return;
}
TClonesArray *ptr_L1_hits = new TClonesArray("Hit",400);
TClonesArray &L1_hits = *ptr_L1_hits;
TTree *input_tree = (TTree*)input_file->Get("ppSimulation");
Bool_t isReconstructed;
Int_t multiplicity;
TBranch *b1=input_tree->GetBranch("is_reconstructed");
b1->SetAddress(&isReconstructed);
TBranch *b2=input_tree->GetBranch("Multiplicity");
b2->SetAddress(&multiplicity);
TBranch *b3=input_tree->GetBranch("L1_Hits");
b3->SetAddress(&ptr_L1_hits);
TCanvas *c1 = new TCanvas("c1","Efficiency Vs Multiplicity");
TEfficiency *eff = new TEfficiency("eff","Efficiency Vs Multiplicity;Multiplicity;Efficiency",25,0.5,50.5);
eff->SetDirectory(0);
for(Int_t i=0;i<input_tree->GetEntries();i++){
input_tree->GetEvent(i);
Int_t noise = 0;
for(Int_t j=0;j<ptr_L1_hits->GetEntries();j++){
if(((Hit*)ptr_L1_hits->At(j))->GetLabel()==-1)noise++;
}
eff->Fill(isReconstructed,noise);
}
eff->Draw("AP");
input_file->Close();
delete input_file;
}