17 from ROOT
import TCanvas
18 from ROOT
import TEfficiency
26 tm = ROOT.TreeManager(
"./structuredtree.root")
27 bt = ROOT.Backtracker(tm)
29 pdgDB = ROOT.TDatabasePDG()
32 pdgToName = {11 :
"e^{-}",
35 -12 :
"#bar{#nu}_{e}",
39 -14 :
"#bar{#nu}_{#mu}",
43 -16 :
"#bar{#nu}_{#tau}",
72 hg4nus = TH2F(
"hg4nus",
"g4Tree;N^{0} #nu's;GENIE scatter code",3,0,3,30,0,30)
73 hnureg = TH1F(
"hnureg",
";#nu vertex region;",10,0,10)
74 hngen = TH1F(
"hngen",
"genTree;N^{0} MCTruth;",5,0,5)
77 hnprim = TH1F(
"hnprim",
"g4Tree;N^{0} primaries;",40,0,40)
78 hprim_pdg = TH1F(
"hprim_pdg",
"g4Tree; MCParticle PDG code;",3400,-400,3000)
79 hprim_mumom = TH1F(
"hprim_mumom",
"g4Tree;true momentum [GeV/c];",50,0,5)
80 hprim_pmom = TH1F(
"hprim_pmom",
"g4Tree;true momentum [GeV/c];",50,0,5)
81 hprim_mumult = TH1F(
"hprim_mumult",
"g4Tree;primary particle multiplicity;",19,0,19)
82 hprim_pmult = TH1F(
"hprim_pmult",
"g4Tree;primary particle multiplicity;",19,0,19)
83 hprim_stopmult_tpc = TH1F(
"hprim_stopmult_tpc",
"g4Tree; N^{0} primaries stopping in active volume",10,0,10)
84 hprim_stopmult_calo = TH1F(
"hprim_stopmult_calo",
"g4Tree; N^{0} primaries stopping in active volume",10,0,10)
85 hprim_chgmult_tpc = TH1F(
"hprim_chgmult_tpc",
"g4Tree;N^{0} charged primaries;",19,0,19)
86 hprim_chgmult_calo = TH1F(
"hprim_chgmult_calo",
"g4Tree;N^{0} charged primaries;",19,0,19)
89 hprim_theta_all = TH1F(
"hprim_theta_all",
"g4Tree: primaries;#theta [deg]",90,0,180)
90 hprim_theta_mu = TH1F(
"hprim_theta_mu",
"g4Tree: primaries;#theta [deg]",90,0,180)
91 hprim_theta_p = TH1F(
"hprim_theta_p",
"g4Tree: primaries;#theta [deg]",90,0,180)
92 hprim_theta_pic = TH1F(
"hprim_theta_pic",
"g4Tree: primaries;#theta [deg]",90,0,180)
95 hprim_t0 = TH1F(
"hprim_t0",
"g4Tree; time [ns];",100,0,1e4)
96 hprim_tf = TH1F(
"hprim_tf",
"g4Tree; time [ns];",100,0,1e4)
97 hall_t0 = TH1F(
"hall_t0",
"g4Tree; time [ns];",100,0,1e4)
98 hall_tf = TH1F(
"hall_tf",
"g4Tree; time [ns];",100,0,1e4)
99 henu_mu = TH1F(
"henu_mu",
"genTree;E_{#nu} [GeV]", 50,0,10)
100 henu_mubar = TH1F(
"henu_mubar",
"genTree;E_{#nu} [GeV]",50,0,10)
101 henu_e = TH1F(
"henu_e",
"genTree;E_{#nu} [GeV]", 50,0,10)
102 henu_ebar = TH1F(
"henu_ebar",
"genTree;E_{#nu} [GeV]", 50,0,10)
105 hx = TH1F(
"hx",
"g4Tree;x [cm]",100,-300,300)
106 hy = TH1F(
"hy",
"g4Tree;y [cm]",100,-450,120)
107 hz = TH1F(
"hz",
"g4Tree;z [cm]",100,1250,1750)
114 for ientry
in range(gen.NEntries()):
118 if not (gen.IsGenie(0)
and gen.IsCC(0)
and gen.NuPDG(0)==14
and gen.NuInAV(0)) :
continue 122 hnprim.Fill(g4.NPrimary())
134 for ig4
in range(g4.NSim()) :
136 if g4.IsPrimary(ig4) :
138 theta = ROOT.TMath.RadToDeg()*g4.SimMomBegin(ig4).Theta()
139 hprim_theta_all.Fill(theta)
140 hx.Fill(g4.SimPosBegin(ig4).
X())
141 hy.Fill(g4.SimPosBegin(ig4).
Y())
142 hz.Fill(g4.SimPosBegin(ig4).
Z())
144 if g4.IsCathodeCrosser(ig4) : print(
'found cathode crossing primary!')
146 pdgcode = g4.PDG(ig4)
147 if abs(pdgcode) > 6000 :
continue 149 partPDG = pdgDB.GetParticle(pdgcode)
151 if not pdgcode
in pdgcts :
156 if g4.HasPassedCalo(ig4) :
157 if not pdgcode
in pdgcts_calo :
158 pdgcts_calo[pdgcode] = 0
159 pdgcts_calo[pdgcode] += 1
161 hprim_pdg.Fill(pdgcode)
162 if g4.IsStoppedTPC(ig4) : nstop_tpc +=1
163 if g4.IsStoppedCalo(ig4) : nstop_calo +=1
164 if partPDG.Charge()!=0 :
165 if g4.HasPassedTPC(ig4): nprim_chg_tpc +=1
166 if g4.HasPassedCalo(ig4): nprim_chg_calo +=1
169 if abs(g4.PDG(ig4)) == 13 :
170 hprim_mumom.Fill(g4.SimMomBegin(ig4).
P())
171 hprim_theta_mu.Fill(theta)
174 if abs(g4.PDG(ig4)) == 211 :
175 hprim_theta_pic.Fill(theta)
177 if g4.PDG(ig4) == 2212 :
178 hprim_pmom.Fill(g4.SimMomBegin(ig4).
P())
179 hprim_theta_p.Fill(theta)
183 if g4.IsCathodeCrosser(ig4) : print(
'found cathode crossing secondary!')
186 if (
abs(g4.PDG(ig4))==12
or abs(g4.PDG(ig4))==14) :
189 hprim_mumult.Fill(nprim_mu)
190 hprim_pmult.Fill(nprim_p)
191 hprim_stopmult_tpc.Fill(nstop_tpc)
192 hprim_stopmult_calo.Fill(nstop_calo)
193 hprim_chgmult_tpc.Fill(nprim_chg_tpc)
194 hprim_chgmult_calo.Fill(nprim_chg_calo)
197 hngen.Fill(gen.NGen())
198 for igen
in range(gen.NGen()):
200 if not gen.IsGenie(igen) :
continue 201 enu = gen.NuP(igen).
E()
203 if gen.NuPDG(igen)==14 : henu_mu.Fill(enu)
204 if gen.NuPDG(igen)==-14 : henu_mubar.Fill(enu)
205 if gen.NuPDG(igen)==12 : henu_e.Fill(enu)
206 if gen.NuPDG(igen)==-12 : henu_ebar.Fill(enu)
208 hnureg.Fill(gen.NuRegion(igen))
212 hpdgtxt = TH1F(
"hpdgtxt",
"g4Tree: primaries;; counts per species",len(pdgcts),0,len(pdgcts))
213 hpdgtxt_calo = TH1F(
"hpdgtxt_calo",
"g4Tree: primaries;; counts per species",len(pdgcts),0,len(pdgcts))
216 for i, (k,v)
in enumerate(dict(sorted(pdgcts.items(), key=
lambda item: item[1])).items()):
217 hpdgtxt.SetBinContent(i+1,v)
218 hpdgtxt.GetXaxis().SetBinLabel(i+1,pdgToName[k])
220 if k
in pdgcts_calo.keys():
221 hpdgtxt_calo.SetBinContent(i+1,pdgcts_calo[k])
228 hnprim.Draw(
"e0hist")
234 hnureg.Draw(
"e0hist")
237 henu_mubar.SetLineColor(ROOT.kCyan)
238 henu_e.SetLineColor(ROOT.kRed)
239 henu_ebar.SetLineColor(ROOT.kMagenta)
242 henu_mu.Draw(
"e0hist")
243 henu_mubar.Draw(
"e0hist same")
244 henu_e.Draw(
"e0hist same")
245 henu_ebar.Draw(
"e0hist same")
248 cprim_pdg = TCanvas()
249 hprim_pdg.Draw(
"e0hist")
252 hprim_pmom.SetLineColor(ROOT.kRed)
253 hprim_mumom.SetLineWidth(2)
254 hprim_pmom.SetLineWidth(2)
256 cprim_mom = TCanvas()
257 hprim_pmom.Draw(
"e0hist")
258 hprim_mumom.Draw(
"e0hist same")
261 hprim_pmult.SetLineColor(ROOT.kRed)
262 hprim_mumult.SetLineWidth(2)
263 hprim_pmult.SetLineWidth(2)
265 cprim_mult = TCanvas()
266 hprim_mumult.Draw(
"e0hist")
267 hprim_pmult.Draw(
"e0hist same")
268 leg3 = ROOT.TLegend(0.6,0.6,0.8,0.8)
269 leg3.SetBorderSize(0)
270 leg3.AddEntry(hprim_mumult,
"#mu^{#pm}",
"l")
271 leg3.AddEntry(hprim_pmult,
"p^{+}",
"l")
275 hprim_stopmult_calo.SetLineColor(ROOT.kRed)
276 hprim_stopmult_tpc.SetLineWidth(2)
277 hprim_stopmult_calo.SetLineWidth(2)
279 cprim_stopmult = TCanvas()
280 hprim_stopmult_tpc.Draw(
"e0hist")
281 hprim_stopmult_calo.Draw(
"e0hist same")
282 leg4 = ROOT.TLegend(0.6,0.6,0.8,0.8)
283 leg4.SetBorderSize(0)
284 leg4.AddEntry(hprim_stopmult_tpc,
"TPC",
"l")
285 leg4.AddEntry(hprim_stopmult_calo,
"TPC",
"l")
289 hprim_chgmult_calo.SetLineColor(ROOT.kRed)
290 hprim_chgmult_tpc.SetLineWidth(2)
291 hprim_chgmult_calo.SetLineWidth(2)
293 cprim_chgmult = TCanvas()
294 hprim_chgmult_tpc.Draw(
"e0hist")
295 hprim_chgmult_calo.Draw(
"e0hist same")
299 hpdgtxt.SetFillColor(ROOT.kBlue)
300 hpdgtxt_calo.SetFillColor(ROOT.kRed)
301 hpdgtxt.GetXaxis().SetLabelSize(0.07)
303 ROOT.gStyle.SetOptStat(0)
306 hpdgtxt.Draw(
"HBAR1 E0")
307 hpdgtxt_calo.Draw(
"HBAR1 E0 same")
309 leg = ROOT.TLegend(0.6,0.2,0.8,0.4)
311 leg.AddEntry(
"hpdgtxt",
"primaries in TPC",
"F")
312 leg.AddEntry(
"hpdgtxt_calo",
"primaries in ECal",
"F")
316 hprim_theta_all.SetLineWidth(2)
317 hprim_theta_mu.SetLineWidth(2)
318 hprim_theta_p.SetLineWidth(2)
319 hprim_theta_pic.SetLineWidth(2)
321 hprim_theta_mu.SetLineColor(ROOT.kGreen-1)
322 hprim_theta_p.SetLineColor(ROOT.kRed)
323 hprim_theta_pic.SetLineColor(ROOT.kMagenta)
326 hprim_theta_all.Draw(
"e0hist")
327 hprim_theta_mu.Draw(
"e0hist same")
328 hprim_theta_p.Draw(
"e0hist same")
329 hprim_theta_pic.Draw(
"e0hist same")
330 leg2 = ROOT.TLegend(0.6,0.6,0.8,0.8)
331 leg2.SetBorderSize(0)
332 leg2.AddEntry(hprim_theta_all,
"all",
"l")
333 leg2.AddEntry(hprim_theta_mu,
"#mu^{#pm}",
"l")
334 leg2.AddEntry(hprim_theta_p,
"p^{+}",
"l")
335 leg2.AddEntry(hprim_theta_pic,
"#pi^{#pm}",
"l")
351 null =
input(
"press <Enter> to close canvas and exit program.")
std::pair< float, std::string > P
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.