-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaccess_tree.C
executable file
·67 lines (48 loc) · 1.77 KB
/
access_tree.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
R__LOAD_LIBRARY(libeicsmear);
void access_tree(){
//Event Class
erhic::EventPythia *event(NULL); //Note that I use Pointer
//Particle Class
erhic::ParticleMC *particle(NULL); //Also use Pointer
//Load ROOT File
TFile *f = new TFile("../pythia/outfiles/ep_10_100_norad.root");
//Get EICTree Tree
TTree *tree = (TTree*)f->Get("EICTree");
Int_t nEntries = tree->GetEntries();
cout<<"-------------------------------"<<endl;
cout<<"Total Number of Events = "<<nEntries<<endl<<endl;
//Access event Branch
tree->SetBranchAddress("event",&event); //Note &event, even with event being a pointer
//Define Some Variables
Float_t Q2(0);
Int_t nParticles(0);
Float_t Eta[500];
Float_t Px[500];
Int_t Status[500];
Int_t id[500];
//Loop Over Events
for(Int_t i=0;i<10;i++){
tree->GetEntry(i);
//Write Out Q2
Q2 = (Float_t) event->GetQ2(); //Can also do event->QSquared
printf("For Event %d, Q^2 = %.3f GeV^2!\n",i,Q2);
//Get Total Number of Particles
nParticles = event->GetNTracks();
printf("For Event %d, we have %d particles!\n",i,nParticles);
//Loop Over Each Particle
for(Int_t j=0;j<nParticles;j++){
particle = event->GetTrack(j);
Eta[j] = (Float_t) particle->GetEta();
Px[j] = (Float_t) particle->GetPx();
Status[j] = (Int_t) particle->GetStatus(); //Can also do particle->KS
id[j] = (Int_t) particle->Id();
if(Status[j]==1){
printf("For Event %d, particle %d Eta = %.3f!\n",i,j,Eta[j]);
printf("For Event %d, particle %d Px = %.3f GeV/c!\n",i,j,Px[j]);
printf("For Event %d, particle %d Status = %d!\n",i,j,Status[j]);
printf("For Event %d, particle %d Id = %d!\n",i,j,id[j]);
}
}
}
cout<<"-------------------------------"<<endl;
}