-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfrag.py
More file actions
216 lines (181 loc) · 7.52 KB
/
frag.py
File metadata and controls
216 lines (181 loc) · 7.52 KB
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
#!/usr/bin/env python
import sys
import ROOT
import math
import numpy as np
def savehist(hist, histname):
"""At the end of the function, there are no more references to `file`.
The `TFile` object gets deleted, which in turn saves and closes
the ROOT file."""
myfile.WriteObject(hist, histname)
printStuff = True
printHistograms = False
try:
input = raw_input
except:
pass
if len(sys.argv) < 3:
print(" Usage: frag.py LEP-1000.root results_name")
sys.exit(1)
print("Beginning...")
ROOT.gSystem.Load("libDelphes")
try:
ROOT.gInterpreter.Declare('#include "classes/DelphesClasses.h"')
ROOT.gInterpreter.Declare('#include "external/ExRootAnalysis/ExRootTreeReader.h"')
except:
pass
inputFile = sys.argv[1]
# Create .root file to save histograms
# Path starts in Delphes directory
myfile = ROOT.TFile.Open("../FragmentationStudy/root_files/"+sys.argv[2]+"_histograms.root", "RECREATE")
# Create chain of root trees
chain = ROOT.TChain("Delphes")
chain.Add(inputFile)
# Create object of class ExRootTreeReader
treeReader = ROOT.ExRootTreeReader(chain)
numberOfEntries = treeReader.GetEntries()
# Get pointers to branches used in this analysis
branchGenJet = treeReader.UseBranch("GenJet")
branchParticle = treeReader.UseBranch("Particle")
branchGenMissingET = treeReader.UseBranch("GenMissingET")
if printHistograms is True:
# Book histograms
# TH1F::TH1F(const char* name, const char* title, int nbinsx, double xlow, double xup) =>
histGenJetP = ROOT.TH1F("GenJet_p", "GenJet P; GenJet P; #", 100, 0.0, 100.0)
histGenJetPT = ROOT.TH1F("GenJet_pt", "GenJet PT; GenJet PT; #", 100, 0.0, 100.0)
histGenJetM = ROOT.TH1F("GenJet_mass", "GenJet Mass; GenJet Mass; #", 100, 0.0, 10.0)
# TH2F::TH2F(const char* name, const char* title, int nbinsx, double xlow, double xup, int nbinsy, double ylow,
# double yup) =>
histPartVsP = ROOT.TH2F(
"# of particles Vs p", "Number of Particles Vs GenJet P; GenJet P; # of particles",
100, 0.0, 500.0, 50, 0.0, 50.0)
histPartVsPT = ROOT.TH2F(
"# of particles Vs pt", "Number of Particles Vs GenJet PT; GenJet PT; # of particles",
100, 0.0, 500.0, 50, 0.0, 50.0)
# Four momentum vector
px, py, pz, E = 0, 0, 0, 0
four_vector = [px, py, pz, E]
# Loop over all events
event_num = 0
pt_num = 0
#for entry in range(0, numberOfEntries):
for entry in range(0, 10):
event_num += 1
# four_vector = [px, py, pz, E]
# Load selected branches with data from specified event
treeReader.ReadEntry(entry)
# Determines if event has a high PT photon
highPtPhoton = False
hasJetAbove50GeV = False
# Determines if event has a jet with pt < 50 GeV
for ijet in range(branchGenJet.GetEntries()):
GenJet = branchGenJet.At(ijet)
if 100 < GenJet.PT < 150:
jetInInterval = True
print(GenJet.Particles.GetEntries())
sumPT = 0
sumE = 0
for iparticle in range(GenJet.Particles.GetEntries()):
Particle = GenJet.Particles.At(iparticle)
four_vector[0] += Particle.Px
four_vector[1] += Particle.Py
four_vector[2] += Particle.Pz
four_vector[3] += Particle.E
sumPT += Particle.PT
sumE += Particle.E
# print(Particle.E)
mag = np.array(four_vector)
print(four_vector)
print("Magnitude of four-vector: %f" % np.linalg.norm(mag))
print("GenJet.PT: %f" % GenJet.PT)
print("SumPT of particles: %f" % sumPT)
print("SumE of particles: %f" % sumE)
break
if hasJetAbove50GeV is True:
for ijet in range(branchGenJet.GetEntries()):
# Take first GenJet
GenJet = branchGenJet.At(ijet)
# GenMissingET = branchGenMissingET.At(ijet)
# if GenJet.PT < 50:
# hasJetAbove50GeV = True
if printStuff:
P = GenJet.PT * math.cosh(GenJet.Eta)
print("Event: %d" % event_num)
print("Jet: %d" % ijet)
# print("GenMissingET.MET", GenMissingET.MET)
# print("GenJet.Particles ", GenJet.Particles)
# print("Particle Unique ID: ", Particle.fUniqueID)
print("GenJet.PT: %f" % GenJet.PT)
print("GenJet.P: %f" % P)
# print("GenJet.Eta: ", GenJet.Eta)
# print("GenJet.Phi: ", GenJet.Phi)
print("GenJet.NCharged %d" % GenJet.NCharged)
print("GenJet.NNeutrals %d" % GenJet.NNeutrals)
if printHistograms is True:
P = GenJet.PT * math.cosh(GenJet.Eta)
histGenJetM.Fill(GenJet.Mass)
histGenJetP.Fill(P)
histPartVsP.Fill(P, GenJet.NCharged + GenJet.NNeutrals)
histGenJetPT.Fill(GenJet.PT)
histPartVsPT.Fill(GenJet.PT, GenJet.NCharged + GenJet.NNeutrals)
print(" ")
for iparticle in range(branchParticle.GetEntries()):
Particle = branchParticle.At(iparticle)
# four_vector[0] += Particle.Px
# four_vector[1] += Particle.Py
# four_vector[2] += Particle.Pz
# four_vector[3] += Particle.E
# print("Particle Status: %d" % Particle.Status)
print("Particle ID: %d, Particle Status: %d, Px: %f, Py: %f, Pz: %f, E: %f" % (Particle.PID, Particle.Status, Particle.Px, Particle.Py, Particle.Pz, Particle.E))
mag = np.array(four_vector)
print("Magnitude of particle four vector: %f" % np.linalg.norm(mag))
print(" ")
if hasJetAbove50GeV is True:
pt_num += 1
# mag = np.array(four_vector)
# print("Magnitude: %f" % np.linalg.norm(mag))
print(" ")
# print("number of events PT < 50: %d" % pt_num)
# mag = np.array(four_vector)
# print("Magnitude: ", np.linalg.norm(mag))
# print("num of status=1 ", num)
if printHistograms is True:
# Show resulting histograms
c0 = ROOT.TCanvas()
c0.Update()
histGenJetP.Draw()
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_GenJetP.png")
c0.Clear()
c0.Update()
histGenJetPT.Draw()
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_GenJetPT.png")
c0.Clear()
c0.Update()
histGenJetM.Draw()
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_GenJetMass.png")
c0.Clear()
c0.Update()
histPartVsP.SetContour(1000)
profx = histPartVsP.ProfileX("profilex", 0, 100)
profx.Draw()
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_PartVsPprofx.png")
histPartVsP.Draw("colz")
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_PartVsP.png")
c0.Clear()
c0.Update()
histPartVsPT.SetContour(1000)
pt_profx = histPartVsPT.ProfileX("profilex", 0, 100)
pt_profx.Draw()
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_PartVsPTprofx.png")
histPartVsPT.Draw("colz")
c0.Print("../FragmentationStudy/plots/"+sys.argv[2]+"_PartVsPT.png")
c0.Clear()
# Save resulting histograms to .root file
savehist(histPartVsP, "PartVsP")
savehist(histGenJetP, "GenJetP")
savehist(profx, "PartVsPprofx")
savehist(histPartVsPT, "PartVsPT")
savehist(histGenJetPT, "GenJetPT")
savehist(pt_profx, "PartVsPTprofx")
savehist(histGenJetM, "GenJetMass")
print("Done!")