Newer
Older
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
#include "UTIL/LCTOOLS.h"
#include "UTIL/Operators.h"
#include <UTIL/CellIDDecoder.h>
//#include "DD4hep/LCDD.h"
//#include "DD4hep/DD4hepUnits.h"
// check directory
#include <sys/stat.h>
#include <TROOT.h>
#include <TFile.h>
#include <TH1D.h>
#include "TMath.h"
#include"time.h"
#include <dirent.h>
#include <string>
#include <vector>
#include <map>
struct stat sb;
std::vector<std::string> get_files_in_directory(std::string path = "data/.") {
std::vector<std::string> files;
if (stat(path.c_str(), &sb) == 0 && S_ISDIR(sb.st_mode)) {
DIR* dir;
dirent* pdir;
dir = opendir(path.c_str());
while( pdir = readdir(dir) ){
string rfile=path + "/" + pdir->d_name;
if (rfile.find(".slcio") != std::string::npos)
files.push_back(rfile);
}
} else {
cout << "Directory " << path << " does not exist!!" << endl;
std::exit(0);
}
return files;
}
//______________________________________________________________________________
void TOF_analysis(
const char* DIRNAME = "data/electrons",
const char* result_file_prefix = "SID_1T",
const char* compact_file = "detectors/SiD/compact/sid_working/sidloi3_v00.xml")
{
DD4hep::Geometry::LCDD& lcdd = DD4hep::Geometry::LCDD::getInstance();
lcdd.fromCompact(compact_file);
const double position[3]={0,0,0}; // position to calculate magnetic field at (the origin in this case)
double bField[3]={0,0,0};
lcdd.field().magneticField(position,bField);
_Bz = bField[2]/dd4hep::tesla;
std::cout << " Magnetic Field Bz = " << _Bz << std::endl;
return;
//lcdd.field();
//CellIDDecoder<SimTrackerHit> cellid_decoder( hitCol );
//for(int i=0; i<nhits; i++){
// SimTrackerHit *hit =dynamic_cast <SimTrackerHit*>( hitCol->getElementAt(i) );
// int subdetectorID = cellid_decoder( hit )["subdet"];
// int layerID = cellid_decoder( hit )["layer"];
// int moduleID = cellid_decoder( hit )["module"];
//}
// Put the equivalent lines in your .rootlogon.C
//gSystem->AddIncludePath(" -I$EIC_SOFTWARE/local/include");
//gSystem->Load("liblcio.so");
//gSystem->Load("liblcioDict.so");
using namespace EVENT ;
using namespace UTIL;
using namespace IMPL ;
TH1F * hTime= new TH1F("hTime","hit time ;time [ns];",100,0,100);
TH1F * hEDep= new TH1F("hEDep","EDep ;E [GeV];",500,0,0.001);
TH1F * hdEdx= new TH1F("hdEdx","dEdx ;E [GeV];",500,0,0.01);
TH2F * hEDepVSdEdx= new TH2F("hEDepVSdEdx","EDep Vs dEdx ;dEdx [GeV];EDep [GeV]",500,0,0.01,500,0,0.001);
TH2F * hEDepVSnhit= new TH2F("hEDepVSnhit","dEdx Vs nhit ;nhit ;dEdx [GeV]",20,0,20,500,0,0.01);
TProfile * hdEdx_vs_p= new TProfile("hdEdx_vs_p","dEdx Vs P ;P [GeV/c] ;dEdx [GeV]",20,0,20,0,0.005);
TH1F * h1 = new TH1F("hh1","P_{T};P_{T} [GeV];",80,0,40);
TH1F * hP = new TH1F("hP" , "P;P [GeV/c];" , 80 , 0 , 40);
TH1F * hPT = new TH1F("hPT" , "P_{T};P_{T} [GeV/c];", 80 , 0 , 40);
TH1F * hPDG = new TH1F("hPDG", "PDG Code; PDG code;" , 40 , -20 , 20);
auto eff_vs_Pt2 = new TEfficiency("eff_vs_Pt2","Track timing2;P_{T} [GeV];#epsilon",50,0,10);
auto eff_vs_Pt = new TEfficiency("eff_vs_Pt","Track timing;P_{T} [GeV];#epsilon",50,0,10);
auto eff_vs_P = new TEfficiency("eff_vs_P","Track timing;P [GeV];#epsilon",50,0,10);
auto eff_vs_Pt3 = new TEfficiency("eff_vs_Pt2","Track timing2;P_{T} [GeV];#epsilon",50,0,10);
auto eff_vs_Pt4 = new TEfficiency("eff_vs_Pt2","Track timing2;P_{T} [GeV];#epsilon",50,0,10);
auto chi2_vs_Pt = new TProfile("chi2_vs_Pt","#chi^{2} vs P_{T};P_{T} [GeV];#chi^{2}",20,0,10,0,100);
auto chi2_vs_P = new TProfile("chi2_vs_P","#chi^{2} vs P;P [GeV];#chi^{2}",20,0,10,0,100);
int max_files = 10;
int nEvents = 0 ;
int n_files_read = 0;
auto files = get_files_in_directory(DIRNAME);
IO::LCReader* lcReader = IOIMPL::LCFactory::getInstance()->createLCReader() ;
EVENT::LCEvent* evt = 0 ;
std::string mcpType("std::vector<IMPL::MCParticleImpl*>") ;
std::string mcpName("MCParticle") ;
std::sort(files.begin(),files.end());
for(auto aFile : files) {
std::cout << "Opening " << aFile << '\n';
lcReader->open( aFile.c_str() ) ;
n_files_read++;
//----------- the event loop -----------
while( (evt = lcReader->readNextEvent()) != 0 ) {
if(nEvents%1000==0) {
if(nEvents==0)UTIL::LCTOOLS::dumpEvent( evt ) ;
std::cout << "Event " << nEvents << '\n';
}
IMPL::LCCollectionVec* thrown_col = (IMPL::LCCollectionVec*) evt->getCollection( "MCParticle" ) ;
IMPL::LCCollectionVec* tracks_col = (IMPL::LCCollectionVec*) evt->getCollection( "Tracks" ) ;
IMPL::LCCollectionVec* simtrackhits_col = (IMPL::LCCollectionVec*) evt->getCollection("SiTrackerEndcapHits") ;
//UTIL::LCTOOLS::printMCParticles( col ) ;
int nMCP = thrown_col->getNumberOfElements() ;
int nTracks = tracks_col->getNumberOfElements() ;
bool hasOneTrack = (nTracks==1);
bool hasTwoTracks = (nTracks==2);
int nSimTrackHits = simtrackhits_col->getNumberOfElements() ;
for(int i_thrown=0 ; i_thrown<nMCP ; ++i_thrown) {
auto part = (EVENT::MCParticle*) thrown_col->getElementAt(i_thrown);
if( (part->getGeneratorStatus() == 1) ) {
// (part->getPDG() == 11)
//std::cout << int(part->getGeneratorStatus()) << std::endl;;
//std::cout << *part << std::endl;;
//std::cout << (UTIL::lcio_short<EVENT::MCParticle>(*part));
//<< std::endl;;
TVector3 p(part->getMomentum());
double eta = p.PseudoRapidity();
hPT->Fill(p.Pt());
hP->Fill(p.Mag());
hPDG->Fill(part->getPDG());
eff_vs_P ->Fill(hasOneTrack, p.Mag());
eff_vs_Pt ->Fill(hasOneTrack, p.Pt());
eff_vs_Pt2->Fill(hasOneTrack||hasTwoTracks, p.Pt());
if( TMath::Abs(eta) < 1 ) {
eff_vs_Pt3 ->Fill(hasOneTrack, p.Pt());
}
if( TMath::Abs(TMath::Abs(eta)-1.5) < 0.5) {
eff_vs_Pt4 ->Fill(hasOneTrack, p.Pt());
}
//std::cout << "Tracks: " << nTracks << "\n";
for(int i_track=0 ; i_track<nTracks ; ++i_track) {
auto track = (EVENT::Track*) tracks_col->getElementAt(i_track);
chi2_vs_Pt->Fill(p.Pt(), track->getChi2(), 1);
chi2_vs_P->Fill( p.Mag(),track->getChi2(), 1);
double dEdx = track->getdEdx();
hdEdx->Fill(dEdx);
auto hits = track->getTrackerHits();
hEDepVSnhit->Fill( hits.size(),dEdx);
hdEdx_vs_p->Fill(p.Mag(), dEdx);
for(auto ahit : hits) {
double hit_time = ahit->getTime();
double EDep = ahit->getEDep();
if(hit_time != 0.0) {
std::cout << " time " << hit_time << '\n';
}
//if(EDep != 0.0) {
// std::cout << " EDep " << EDep << '\n';
//}
hEDep->Fill(EDep);
hEDepVSdEdx->Fill(dEdx,EDep);
}
//if(nTracks>1) {
// std::cout << (*track) << std::endl;
//}
}
//std::cout << "Tracks: " << nTracks << "\n";
for(int i_simtrack=0 ; i_simtrack<nSimTrackHits ; ++i_simtrack) {
auto sim_track_hit = (EVENT::SimTrackerHit*) simtrackhits_col->getElementAt(i_simtrack);
double ht = sim_track_hit->getTime();
//if(ht != 0.0) {
// std::cout << " time " << ht << '\n';
//}
hTime->Fill(ht);
}
}
}
nEvents++;
}
// -------- end of event loop -----------
lcReader->close() ;
if(n_files_read >= max_files) break;
}
std::cout << std::endl
<< " " << nEvents
<< " events read from file: "
<< DIRNAME << std::endl ;
delete lcReader ;
gSystem->mkdir("results/timing",true);
TCanvas * c = new TCanvas();
eff_vs_Pt ->SetLineWidth(2);
eff_vs_Pt2->SetLineWidth(2);
eff_vs_Pt3->SetLineWidth(2);
eff_vs_Pt4->SetLineWidth(2);
eff_vs_Pt ->SetLineColor(1);
eff_vs_Pt2->SetLineColor(2);
eff_vs_Pt3->SetLineColor(4);
eff_vs_Pt4->SetLineColor(8);
eff_vs_Pt->Draw();
eff_vs_Pt2->Draw("same");
eff_vs_Pt3->Draw("same");
eff_vs_Pt4->Draw("same");
c->SaveAs(Form("results/timing/%s_effVsPT.pdf",result_file_prefix));
c = new TCanvas();
eff_vs_P->Draw();
c->SaveAs(Form("results/timing/%s_effVsP.pdf",result_file_prefix));
c = new TCanvas();
chi2_vs_Pt->Draw();
c->SaveAs(Form("results/timing/%s_Chi2VsPT.pdf",result_file_prefix));
c = new TCanvas();
chi2_vs_P->Draw();
c->SaveAs(Form("results/timing/%s_Chi2VsP.pdf",result_file_prefix));
c = new TCanvas();
hTime->Draw();
c->SaveAs(Form("results/timing/%s_Time.pdf",result_file_prefix));
c = new TCanvas();
hEDep->Draw();
c->SaveAs(Form("results/timing/%s_EDep.pdf",result_file_prefix));
c = new TCanvas();
hdEdx->Draw();
c->SaveAs(Form("results/timing/%s_dEdx.pdf",result_file_prefix));
c = new TCanvas();
hEDepVSdEdx->Draw("colz");
c->SaveAs(Form("results/timing/%s_EDepVSdEdx.pdf",result_file_prefix));
c = new TCanvas();
hEDepVSnhit->Draw("colz");
c->SaveAs(Form("results/timing/%s_EDepVSnhit.pdf",result_file_prefix));
c = new TCanvas();
hdEdx_vs_p->Draw("colz");
c->SaveAs(Form("results/timing/%s_dEdx_vs_p.pdf",result_file_prefix));
//c = new TCanvas();
//hPDG->Draw();
//c->SaveAs(Form("results/resolution/%s_dPTOverPT.pdf",result_file_prefix));
}