18 def xAODHist(evt, phys=False, analysis=False, histfile=None):
21 histfilename = histfile
23 histfilename =
"hist.root"
26 hfile = ROOT.TFile( histfilename,
'RECREATE',
'ROOT file with histograms' )
29 hphys_nclus = ROOT.TH1F(
'phys_nclus',
'phys_nclus', 20, 0, 20 )
30 hphys_nidtracks = ROOT.TH1F(
'phys_nidtracks',
'phys_nidtracks', 20, 0, 20 )
31 hphys_ntautracks = ROOT.TH1F(
'phys_ntautracks',
'phys_ntautracks', 20, 0, 20 )
32 hphys_ntaus = ROOT.TH1F(
'phys_ntaus',
'phys_taus', 20, 0, 20 )
33 hphys_nmuons = ROOT.TH1F(
'phys_nmuons',
'phys_nmuons', 20, 0, 20 )
34 hphys_nelecs = ROOT.TH1F(
'phys_nelecs',
'phys_nelecs', 20, 0, 20 )
35 hphys_nphotons = ROOT.TH1F(
'phys_nphotons',
'phys_nphotons', 20, 0, 20 )
36 hphys_njets = ROOT.TH1F(
'phys_njets',
'phys_njets', 20, 0, 20 )
37 hphys_nfakeelectrons = ROOT.TH1F(
'phys_nfakeelectrons',
'phys_nfakeelectrons', 20, 0, 20 )
38 hphys_nfakephotons = ROOT.TH1F(
'phys_nfakephotons',
'phys_nfakephotons', 20, 0, 20 )
41 hntaujet = ROOT.TH1F(
'ana_ntaujet',
'ana_ntaujet', 20, 0, 20 )
42 htaujetpt = ROOT.TH1F(
'ana_taujet_pt',
'ana_taujet_pt', 200, 0, 200 )
43 htaujeteta = ROOT.TH1F(
'ana_taujet_eta',
'ana_taujet_eta', 100, -5, 5 )
44 htaujetphi = ROOT.TH1F(
'ana_taujet_phi',
'ana_taujet_phi', 70, -3.5, 3.5 )
46 hnelectron = ROOT.TH1F(
'ana_nelectron',
'ana_nelectron', 20, 0, 20 )
47 helectronpt = ROOT.TH1F(
'ana_electron_pt',
'ana_electron_pt', 200, 0, 200 )
48 helectroneta = ROOT.TH1F(
'ana_electron_eta',
'ana_electron_eta', 100, -5, 5 )
49 helectronphi = ROOT.TH1F(
'ana_electron_phi',
'ana_electron_phi', 70, -3.5, 3.5 )
51 hnmuon = ROOT.TH1F(
'ana_nmuon',
'ana_nmuon', 20, 0, 20 )
52 hmuonpt = ROOT.TH1F(
'ana_muon_pt',
'ana_muon_pt', 200, 0, 200 )
53 hmuoneta = ROOT.TH1F(
'ana_muon_eta',
'ana_muon_eta', 100, -5, 5 )
54 hmuonphi = ROOT.TH1F(
'ana_muon_phi',
'ana_muon_phi', 70, -3.5, 3.5 )
56 hnphoton = ROOT.TH1F(
'ana_nphoton',
'ana_nphoton', 20, 0, 20 )
57 hphotonpt = ROOT.TH1F(
'ana_photon_pt',
'ana_photon_pt', 200, 0, 200 )
58 hphotoneta = ROOT.TH1F(
'ana_photon_eta',
'ana_photon_eta', 100, -5, 5 )
59 hphotonphi = ROOT.TH1F(
'ana_photon_phi',
'ana_photon_phi', 70, -3.5, 3.5 )
61 hnjet = ROOT.TH1F(
'ana_njet',
'ana_njet', 20, 0, 20 )
62 hjetpt = ROOT.TH1F(
'ana_jet_pt',
'ana_jet_pt', 200, 0, 200 )
63 hjeteta = ROOT.TH1F(
'ana_jet_eta',
'ana_jet_eta', 100, -5, 5 )
64 hjetphi = ROOT.TH1F(
'ana_jet_phi',
'ana_jet_phi', 70, -3.5, 3.5 )
67 for i
in range(0, evt.getEntries()):
72 evt,
"xAOD::CaloClusterContainer",
"CaloCalTopoClusters")
74 hphys_nclus.Fill( nclus )
77 "xAOD::TrackParticleContainer",
"InDetTrackParticles")
78 nIdTracks = len(idTracks)
79 hphys_nidtracks.Fill( nIdTracks )
81 tautracks =
safeRetrieve(evt,
"xAOD::TauTrackContainer",
"TauTracks")
82 nTauTracks = len(tautracks)
83 hphys_ntautracks.Fill( nTauTracks )
85 taus =
safeRetrieve(evt,
"xAOD::TauJetContainer",
"TauJets")
87 hphys_ntaus.Fill( nTaus )
89 muons =
safeRetrieve(evt,
"xAOD::MuonContainer",
"Muons")
91 hphys_nmuons.Fill( nMuons )
93 electrons =
safeRetrieve(evt,
"xAOD::ElectronContainer",
"Electrons")
94 nElec = len(electrons)
95 hphys_nelecs.Fill( nElec )
97 photons =
safeRetrieve(evt,
"xAOD::PhotonContainer",
"Photons")
99 hphys_nphotons.Fill( nPhot )
101 jets =
safeRetrieve(evt,
"xAOD::JetContainer",
"AntiKt4EMPFlowJets")
103 hphys_njets.Fill( nJet )
107 acc = ROOT.SG.ConstAccessor(
108 'ElementLink< xAOD::TruthParticleContainer>')(
'truthParticleLink')
110 if nElec > 0
and acc.isAvailable(electrons.at(0)):
111 for i
in range(nElec):
112 truthLink =
acc(electrons.at(i))
113 if(truthLink.isValid()):
114 pdgId = truthLink.pdgId()
118 if nPhot > 0
and acc.isAvailable(photons.at(0)):
119 for i
in range(nPhot):
120 truthLink =
acc(photons.at(i))
121 if(truthLink.isValid()):
122 pdgId = truthLink.pdgId()
126 nFakeElectrons = nElec - nTrueElectrons
127 nFakePhotons = nPhot - nTruePhotons
128 hphys_nfakeelectrons.Fill( nFakeElectrons )
129 hphys_nfakephotons.Fill( nFakePhotons )
133 ana_taujets =
safeRetrieve(evt,
"xAOD::TauJetContainer",
"AnalysisTauJets")
134 ana_ntaujet = len(ana_taujets)
135 hntaujet.Fill( ana_ntaujet )
136 for j
in ana_taujets:
137 htaujetpt.Fill( j.pt()/1000. )
138 htaujeteta.Fill( j.eta() )
139 htaujetphi.Fill( j.phi() )
141 ana_muons =
safeRetrieve(evt,
"xAOD::MuonContainer",
"AnalysisMuons")
142 ana_nmuon = len(ana_muons)
143 hnmuon.Fill( ana_nmuon )
145 hmuonpt.Fill( j.pt()/1000. )
146 hmuoneta.Fill( j.eta() )
147 hmuonphi.Fill( j.phi() )
149 ana_electrons =
safeRetrieve(evt,
"xAOD::ElectronContainer",
"AnalysisElectrons")
150 ana_nelectron = len(ana_electrons)
151 hnelectron.Fill( ana_nelectron )
152 for j
in ana_electrons:
153 helectronpt.Fill( j.pt()/1000. )
154 helectroneta.Fill( j.eta() )
155 helectronphi.Fill( j.phi() )
157 ana_photons =
safeRetrieve(evt,
"xAOD::PhotonContainer",
"AnalysisPhotons")
158 ana_nPhot = len(ana_photons)
159 hnphoton.Fill( ana_nPhot )
160 for j
in ana_photons:
161 hphotonpt.Fill( j.pt()/1000. )
162 hphotoneta.Fill( j.eta() )
163 hphotonphi.Fill( j.phi() )
165 ana_jets =
safeRetrieve(evt,
"xAOD::JetContainer",
"AnalysisJets")
166 ana_nJet = len(ana_jets)
167 hnjet.Fill( ana_nJet )
169 hjetpt.Fill( j.pt()/1000. )
170 hjeteta.Fill( j.eta() )
171 hjetphi.Fill( j.phi() )
179 hphys_nidtracks.Write()
180 hphys_ntautracks.Write()
184 hphys_nphotons.Write()
186 hphys_nfakeelectrons.Write()
187 hphys_nfakephotons.Write()
191 hfile.mkdir(
"AnalysisJets")
192 hfile.cd(
"AnalysisJets")
199 hfile.mkdir(
"AnalysisPhotons")
200 hfile.cd(
"AnalysisPhotons")
207 hfile.mkdir(
"AnalysisTauJets")
208 hfile.cd(
"AnalysisTauJets")
215 hfile.mkdir(
"AnalysisElectrons")
216 hfile.cd(
"AnalysisElectrons")
223 hfile.mkdir(
"AnalysisMuons")
224 hfile.cd(
"AnalysisMuons")