-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildDiphotons.C
134 lines (119 loc) · 4.73 KB
/
buildDiphotons.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
#include "src/Constants.h"
double calc_Pt(TLorentzVector, TLorentzVector, TLorentzVector);
int buildDiphotons(const char * input_file=""){
// Read the TFile
TFile *f = new TFile(input_file,"UPDATE");
// Read the TTree
TTree *EventTree = (TTree*)f->Get("EventTree");
double x, Q2, W,y;
int Nmax=100;
int run=0;
double px[Nmax], py[Nmax], pz[Nmax], E[Nmax], theta[Nmax], phi[Nmax];
double p_gamma[Nmax];
int pid[Nmax];
EventTree->SetBranchAddress("run",&run);
EventTree->SetBranchAddress("x",&x);
EventTree->SetBranchAddress("Q2",&Q2);
EventTree->SetBranchAddress("W",&W);
EventTree->SetBranchAddress("y",&y);
EventTree->SetBranchAddress("Nmax",&Nmax);
EventTree->SetBranchAddress("px",px);
EventTree->SetBranchAddress("py",py);
EventTree->SetBranchAddress("pz",pz);
EventTree->SetBranchAddress("E",E);
EventTree->SetBranchAddress("theta",theta);
EventTree->SetBranchAddress("phi",phi);
EventTree->SetBranchAddress("p_gamma",p_gamma);
EventTree->SetBranchAddress("pid",pid);
//Create the new TTree
TString treename="diphoton";
//If dihadron tree already exists, remove it
if (f->Get(treename)) f->Delete("diphoton*;*");
TTree *outtree = new TTree(treename,"Diphoton-by-Diphoton info");
double z,pT,M_gg,p_gamma_1,p_gamma_2,E_gamma_1,E_gamma_2,E_ele,th_ele,phi_ele,E_gg,th_gg,phi_gg;
outtree->Branch("run",&run,"run/D");
outtree->Branch("x",&x,"x/D");
outtree->Branch("Q2",&Q2,"Q2/D");
outtree->Branch("y",&y,"y/D");
outtree->Branch("W",&W,"W/D");
outtree->Branch("z",&z,"z/D");
outtree->Branch("pT",&pT,"pT/D");
outtree->Branch("M_gg",&M_gg,"M_gg/D");
outtree->Branch("p_gamma_1",&p_gamma_1,"p_gamma_1/D");
outtree->Branch("p_gamma_2",&p_gamma_2,"p_gamma_2/D");
outtree->Branch("E_gamma_1",&E_gamma_1,"E_gamma_1/D");
outtree->Branch("E_gamma_2",&E_gamma_2,"E_gamma_2/D");
outtree->Branch("E_ele",&E_ele,"E_ele/D");
outtree->Branch("th_ele",&th_ele,"th_ele/D");
outtree->Branch("phi_ele",&phi_ele,"phi_ele/D");
outtree->Branch("E_gg",&E_gg,"E_gg/D");
outtree->Branch("th_gg",&th_gg,"th_gg/D");
outtree->Branch("phi_gg",&phi_gg,"phi_gg/D");
// Initial particles
TLorentzVector init_electron(0,0,0,0); // To be set one run is found
TLorentzVector init_target(0,0,0,0.938272);
// Photons
TLorentzVector gamma1,gamma2,diphoton;
// for loop over all events
int N = EventTree->GetEntries();
for (int ev=0; ev<N; ev++){
EventTree->GetEntry(ev);
init_electron.SetE(runBeamEnergy(run));
init_electron.SetPz(sqrt(init_electron.E()*init_electron.E()-0.000511*0.000511));
//Loop over all particles in the event to find electron
TLorentzVector electron;
TLorentzVector q; // virtual photon
// Maximum energy electron is assumed to be scattered e- (see hipo2tree.C)
int idx_e=-1;
double max_e=-1;
for (int i=0; i<Nmax; i++){
if(pid[i]==11){
if(E[i]>max_e){
idx_e=i;
max_e=E[i];
}
}
}
electron.SetPxPyPzE(px[idx_e],py[idx_e],pz[idx_e],E[idx_e]);
q=init_electron-electron;
E_ele = electron.E();
th_ele = electron.Theta();
phi_ele = electron.Phi();
// Loop over first set of photons
for(int i = 0; i<Nmax; i++){
if(pid[i]!=22) continue;
gamma1.SetPxPyPzE(px[i],py[i],pz[i],E[i]);
p_gamma_1=p_gamma[i]; // <--- classifier output
E_gamma_1=E[i];
// Loop over second set of photons
for(int j = i+1; j<Nmax; j++){
if(pid[j]!=22) continue;
gamma2.SetPxPyPzE(px[j],py[j],pz[j],E[j]);
p_gamma_2=p_gamma[j]; // <--- classifier output
E_gamma_2=E[j];
// Now we have a diphoton, so we will be saving the info the the output TTree "diphoton"
diphoton=gamma1+gamma2;
z = (init_target*diphoton)/(init_target*q);
pT = calc_Pt(q,diphoton,init_target);
M_gg = diphoton.M();
E_gg = diphoton.E();
th_gg = diphoton.Theta();
phi_gg = diphoton.Phi();
outtree->Fill();
}
}
}
f->cd();
outtree->Write();
f->Close();
return 0;
}
double calc_Pt(TLorentzVector q, TLorentzVector p, TLorentzVector init_target){
TLorentzVector com = q+init_target;
TVector3 comBOOST = com.BoostVector();
TLorentzVector qq = q;
TLorentzVector pp = p;
qq.Boost(-comBOOST);
pp.Boost(-comBOOST);
return pp.Pt(qq.Vect());
}