Fork me on GitHub

source: git/python/DelphesAnalysis/Delphes.py@ 32b2ff1

Timing
Last change on this file since 32b2ff1 was 407aeba, checked in by ksuruliz <ksuruliz@…>, 6 years ago

Fixing pythonisation of classes for recent ROOT versions

  • Property mode set to 100644
File size: 8.2 KB
RevLine 
[ae1d49f]1import ROOT
2import libPyROOT as _root
3ROOT.gSystem.Load("libDelphes")
4
5#####################################################
6### Definition of the string conversion methods ###
7#####################################################
8
9def _Event__str__( self ):
10 theString = "Event number %i\n" % self.Number
11 theString += "Read in %f and processed in %f.\n" % (self.ReadTime, self.ProcTime)
12 return theString
13
[407aeba]14if hasattr(_root,"MakeRootClass"):
15 _root.MakeRootClass( "Event" ).__str__ = _Event__str__
16else:
17 _root.CreateScopeProxy( "Event" ).__str__ = _Event__str__
[ae1d49f]18
19def _LHCOEvent__str__( self ):
20 theString = "Trigger word: %b\n" % self.Trigger
21 return theString
22
[407aeba]23if hasattr(_root,"MakeRootClass"):
24 _root.MakeRootClass( "LHCOEvent" ).__str__ = _LHCOEvent__str__
25else:
26 _root.CreateScopeProxy( "LHCOEvent" ).__str__ = _LHCOEvent__str__
[ae1d49f]27
28def _LHEFEvent__str__( self ):
29 hepmcstr = "Process ID: %i\n" % self.ProcessID
30 hepmcstr += "ScalePDF = %f\n" % self.ScalePDF
31 hepmcstr += "Alpha QED = %f\n" % self.AlphaQED
32 hepmcstr += "Alpha DCQ = %f\n" % self.AlphaQCD
33 hepmcstr += "Event weight = %f\n" % self.Weight
34 return hepmcstr
35
[407aeba]36if hasattr(_root,"MakeRootClass"):
37 _root.MakeRootClass( "LHEFEvent" ).__str__ = _LHEFEvent__str__
38else:
39 _root.CreateScopeProxy( "LHEFEvent" ).__str__ = _LHEFEvent__str__
[ae1d49f]40
41def _HepMCEvent__str__( self ):
42 hepmcstr = "Process ID: %i\n" % self.ProcessID
43 hepmcstr += "Energy scale: %f\n" % self.Scale
44 hepmcstr += "Alpha QED = %f\n" % self.AlphaQED
45 hepmcstr += "Alpha QCD = %f\n" % self.AlphaQCD
46 hepmcstr += "Number of multi parton interactions: %f\n" % self.MPI
47 hepmcstr += """Q-scale used in evaluation of PDFs (in GeV): %f\n""" % self.ScalePDF
48 hepmcstr += """Fraction of beam momentum carried by %i parton ("beam side"): %f\n""" % (self.ID1,self.X1)
49 hepmcstr += """Fraction of beam momentum carried by %i parton ("target side"): %f\n""" % (self.ID2,self.X2)
50 hepmcstr += "PDF (id1, x1, Q) = %f\n" % self.PDF1
51 hepmcstr += "PDF (id2, x2, Q) = %f\n" % self.PDF2
52 return hepmcstr
53
[407aeba]54if hasattr(_root,"MakeRootClass"):
55 _root.MakeRootClass( "HepMCEvent" ).__str__ = _HepMCEvent__str__
56else:
57 _root.CreateScopeProxy( "HepMCEvent" ).__str__ = _HepMCEvent__str__
58
[ae1d49f]59
60def _GenParticle__str__( self ):
61 thestring = "Particle HEP ID number = %d\n" % self.PID
62 thestring += "Particle status: %d\n" % self.Status
63 if self.IsPU: thestring += "That particle is from PU.\n"
64 thestring += "Particle 1st mother: %d\n" % self.M1
65 thestring += "Particle 2nd mother: %d\n" % self.M2
66 thestring += "Particle 1st daughter: %d\n" % self.D1
67 thestring += "Particle last daughter: %d\n" % self.D2
68 thestring += "(Px,Py,Pz,E) = (%f,%f,%f,%f)\n" % (self.Px,self.Py,self.Pz,self.E)
69 thestring += "(Pt,Eta,Phi) = (%f,%f,%f)\n" % (self.PT,self.Eta,self.Phi)
70 thestring += "Rapidity = %f\n" % self.Rapidity
71 thestring += "Charge: %d\n" % self.Charge
72 thestring += "Mass: %f\n" % self.Mass
73 thestring += "Vertex position: (x,y,z,t) = (%f,%f,%f,%f)\n" % (self.X,self.Y,self.Z,self.T)
74 return thestring
75
[407aeba]76if hasattr(_root,"MakeRootClass"):
77 _root.MakeRootClass( "GenParticle" ).__str__ = _GenParticle__str__
78else:
79 _root.CreateScopeProxy( "GenParticle" ).__str__ = _GenParticle__str__
[ae1d49f]80
81def _GenParticle_printDecay( self, db, particles, pre="" ):
82 thestring = "%s (%f,%f,%f,%f) (status %d)\n" % (db.GetParticle(self.PID).GetName(),self.Px,self.Py,self.Pz,self.E, self.Status)
83 for daughter in range(self.D1,self.D2+1):
84 if daughter==-1: break
85 if daughter<self.D2 : thestring += "%s+->%s" % (pre,particles.At(daughter).printDecay(db,particles,pre+"| "))
86 else: thestring += "%s+->%s" % (pre,particles.At(daughter).printDecay(db,particles,pre+" "))
87 return thestring
88
[407aeba]89if hasattr(_root,"MakeRootClass"):
90 _root.MakeRootClass( "GenParticle" ).printDecay = _GenParticle_printDecay
91else:
92 _root.CreateScopeProxy( "GenParticle" ).printDecay = _GenParticle_printDecay
[ae1d49f]93
94def _MissingET__str__( self ):
95 thestring = "Mising transverse energy: %f\n" % self.MET
96 thestring += "Mising energy azimuthal angle: %f\n" % self.Phi
97 return thestring
[407aeba]98
99if hasattr(_root,"MakeRootClass"):
100 _root.MakeRootClass( "MissingET" ).__str__ = _MissingET__str__
101else:
102 _root.CreateScopeProxy( "MissingET" ).__str__ = _MissingET__str__
[ae1d49f]103
104def _ScalarHT__str__( self ):
105 thestring = "Scalar sum of transverse momenta: %f\n" %self.HT
106
[407aeba]107if hasattr(_root,"MakeRootClass"):
108 _root.MakeRootClass( "ScalarHT" ).__str__ = _ScalarHT__str__
109else:
110 _root.CreateScopeProxy( "ScalarHT" ).__str__ = _ScalarHT__str__
[ae1d49f]111
112def _Photon__str__( self ):
113 thestring = "(Pt,Eta,Phi) =(%f,%f,%f)\n" % (self.PT,self.Eta,self.Phi)
114 return thestring
115
[407aeba]116if hasattr(_root,"MakeRootClass"):
117 _root.MakeRootClass( "Photon" ).__str__ = _Photon__str__
118else:
119 _root.CreateScopeProxy( "Photon" ).__str__ = _Photon__str__
[ae1d49f]120
121def _Electron__str__( self ):
122 thestring = "(Pt,Eta,Phi) =(%f,%f,%f)\n" % (self.PT,self.Eta,self.Phi)
123 thestring += "charge: %d\n" % self.Charge
124 return thestring
125
[407aeba]126if hasattr(_root,"MakeRootClass"):
127 _root.MakeRootClass( "Electron" ).__str__ = _Electron__str__
128else:
129 _root.CreateScopeProxy( "Electron" ).__str__ = _Electron__str__
[ae1d49f]130
131def _Muon__str__( self ):
132 thestring = "(Pt,Eta,Phi) =(%f,%f,%f)\n" % (self.PT,self.Eta,self.Phi)
133 thestring += "charge: %d\n" % self.Charge
134 return thestring
135
[407aeba]136if hasattr(_root,"MakeRootClass"):
137 _root.MakeRootClass( "Muon" ).__str__ = _Muon__str__
138else:
139 _root.CreateScopeProxy( "Muon" ).__str__ = _Muon__str__
140
[ae1d49f]141
142def _Jet__str__( self ):
143 thestring = "(Pt,Eta,Phi) =(%f,%f,%f)\n" % (self.PT,self.Eta,self.Phi)
144 thestring += "Charge: %d\n" % self.Charge
145 thestring += "Mass: %f\n" % self.Mass
146 if self.BTag: thestring += "This jet is b-tagged.\n"
147 if self.TauTag: thestring += "This jet is tagged as a tau-jet.\n"
148 thestring += "Jet radius in (eta,phi) = (%f,%f)\n" % (self.DeltaEta,self.DeltaPhi)
149 thestring += "Number of constituents: %d\n" % self.Constituents.GetEntries()
150 thestring += "H/E ratio in the calorimeters: %f\n" % self.EhadOverEem
151 nch = 0
152 ech = 0.
153 for constit in self.Constituents:
154 if constit.Charge != 0:
155 fourvector = ROOT.TLorentzVector()
156 fourvector.SetPtEtaPhiM(constit.PT,constit.Eta,constit.Phi,0.)
157 nch += 1
158 ech += fourvector.E()
159 thestring += "Charged Energy fraction: %f\n" % (ech/self.P4().E())
160 thestring += "Charged Multiplicity: %d\n" % nch
161 return thestring
162
[407aeba]163if hasattr(_root,"MakeRootClass"):
164 _root.MakeRootClass( "Jet" ).__str__ = _Jet__str__
165else:
166 _root.CreateScopeProxy( "Jet" ).__str__ = _Jet__str__
[ae1d49f]167
168def _Track__str__( self ):
169 thestring = "Particle HEP ID number = %d\n" % self.PID
170 thestring += "(Pt,Eta,Phi) = (%f,%f,%f)\n" % (self.PT,self.Eta,self.Phi)
171 thestring += "Charge: %d\n" % self.Charge
172 thestring += "At calorimeter surface: (Pt,Eta,Phi) = (%f,%f,%f)\n" % (self.PT,self.EtaOuter,self.PhiOuter)
173 thestring += "Vertex position: (x,y,z) = (%f,%f,%f)\n" % (self.X,self.Y,self.Z)
174 thestring += "Position at calorimer surface: (x,y,z) = (%f,%f,%f)\n" % (self.XOuter,self.YOuter,self.ZOuter)
175 return thestring
176
[407aeba]177if hasattr(_root,"MakeRootClass"):
178 _root.MakeRootClass( "Track" ).__str__ = _Track__str__
179else:
180 _root.CreateScopeProxy( "Track" ).__str__ = _Track__str__
[ae1d49f]181
182def _Tower__str__( self):
183 thestring = "(Et,Eta,Phi) = (%f,%f,%f)\n" % (self.ET,self.Eta,self.Phi)
184 thestring += "(E,Eem,Ehad) = (%f,%f,%f)\n" % (tower.E,tower.Eem,tower.Ehad)
185 thestring += "Edges: %f, %f, %f, %f\n" % (tower.Edges[0],tower.Edges[1],tower.Edges[2],tower.Edges[3])
186 return thestring
187
[407aeba]188if hasattr(_root,"MakeRootClass"):
189 _root.MakeRootClass( "Tower" ).__str__ = _Tower__str__
190else:
191 _root.CreateScopeProxy( "Tower" ).__str__ = _Tower__str__
[ae1d49f]192
193#####################################################
194### Definition of additional ROOT methods ###
195#####################################################
196
197def _lorentzVector__str__( self ):
198 theString = "(pt, eta, phi) = (%f,%f,%f)\n" % (self.Pt(), self.Eta(), self.Phi())
199 theString += "mass = %f, p = %f, mt = %f\n" % (self.M(), self.P(), self.Mt())
200 return theString
201
[407aeba]202if hasattr(_root,"MakeRootClass"):
203 _root.MakeRootClass( "TLorentzVector" ).__str__ = _lorentzVector__str__
204else:
205 _root.CreateScopeProxy( "TLorentzVector" ).__str__ = _lorentzVector__str__
[ae1d49f]206
207
Note: See TracBrowser for help on using the repository browser.