43 ut.bookCanvas(h,key=
'P',title=
'momentum',nx=1800,ny=1200,cx=3,cy=2)
44 ut.bookCanvas(h,key=
'>P',title=
'N >P', nx=1800,ny=1200,cx=3,cy=2)
45 ut.bookCanvas(h,key=
'PT',title=
'Pt',nx=1800,ny=1200,cx=3,cy=2)
46 ut.bookCanvas(h,key=
'>PT',title=
'N >Pt', nx=1800,ny=1200,cx=3,cy=2)
47 cuts = {
'mu':
'abs(id)==13',
'nu':
'abs(id)!=13',
'mu-':
'id==13',
'mu+':
'id==-13',
48 'nutau':
'id==16',
'nutaubar':
'id==-16',
'numu':
'id==14',
'numubar':
'id==-14',
49 'nue':
'id==12',
'nuebar':
'id==-12',
'nuesum':
'abs(id)==12',
'numusum':
'abs(id)==14',
'nutausum':
'abs(id)==16'}
50 OpenCharm = {
'':
'',
'charm':
"&(pythiaid==id & (abs(parentid) == 15 || abs(parentid) == 4112 || abs(parentid) == 4122 || abs(parentid) == 4132 \
51 || abs(parentid) == 431 || abs(parentid) == 421 || abs(parentid) == 411) )"}
53 for x
in [
'',
'charm']:
58 ut.bookHist(h,hn, p +
' ;p [GeV] ;N',400,0.0,400.0)
59 ut.bookHist(h,hnt, p +
' ;pt [GeV] ;N',40,0.0,4.0)
60 sTree.Draw(
'sqrt(px**2+py**2+pz**2)>>'+hn,
'w*('+cuts[q]+OpenCharm[x]+
')',
'goff')
61 sTree.Draw(
'sqrt(px**2+py**2)>>'+hnt,
'w*('+cuts[q]+OpenCharm[x]+
')',
'goff')
62 if q==
'mu+': h[hn].SetLineColor(3)
63 if q==
'mu-': h[hn].SetLineColor(4)
65 for q
in [
'mu',
'mu-',
'mu+',
'nu',
'nue',
'nuesum',
'nuebar',
'numusum',
'numu',
'numubar',
'nutau',
'nutaubar']:
66 for x
in [
'',
'charm']:
70 h[hi]=h[
'T'+p].Clone(hi)
73 for i
in range(h[hi].GetNbinsX()+1,0,-1):
74 nsum+=h[
'T'+p].GetBinContent(i)
75 h[hi].SetBinContent(i,nsum)
78 for x
in [
'mu',
'nu']:
84 if h[
'T'+p].GetEntries()<1:
continue
85 if not p.find(
'mu')<0:
86 h[
'T'+p+
'+'].Draw(
'same')
87 h[
'T'+p+
'-'].Draw(
'same')
98 h[
'tlnu'+z+str(k)] = ROOT.TLegend(0.49,0.13,0.88,0.36)
99 for p
in [
'numu',
'numubar',
'nue',
'nuebar',
'nutau',
'nutaubar']:
101 h[
'tlnu'+z+str(k)].AddEntry(h[hn],z+
' '+p,
'PL')
102 h[hn].SetLineColor(i)
103 h[hn+
'8']=h[hn].Clone()
104 h[hn+
'8'].SetName(hn+
'8')
110 h[hn+
'8'].Draw(
'same')
111 h[
'tlnu'+z+str(k)].Draw()
146 for p
in productions:
147 f = ROOT.TFile.Open(eospath+productions[p][
"file"])
148 t = f.FindObjectAny(
"pythia8-Geant4")
152 for l
in t.GetListOfLeaves():
153 if tuples ==
'': tuples += l.GetName()
154 else: tuples +=
":"+l.GetName()
155 fxx = fnew.replace(
'.root',opt+
'.root')
156 if storeCharm: fxx = fnew.replace(
'.root',
'old-charm.root')
157 h[
'N'] = ROOT.TFile(fxx,
'RECREATE')
158 print(
'new file created',fxx)
159 h[
'ntuple'] = ROOT.TNtuple(
"pythia8-Geant4",
"min bias flux after 3m hadron absorber "+opt,tuples)
162 if storeCharm: t.Draw(
">>temp",cuts[opt]+
"&"+OpCharm)
163 else: t.Draw(
">>temp",cuts[opt]+
"&"+noOpCharm)
164 temp = ROOT.gROOT.FindObjectAny(
'temp')
167 leaves = t.GetListOfLeaves()
168 nL = leaves.GetEntries()
169 for iev
in range(nev) :
170 rc = t.GetEntry(temp.GetEntry(iev))
175 if nL > 11
and (k==7
or k==8
or k==9):
continue
176 vlist.append( leaves.At(x).GetValue() )
177 if len(vlist) != 11 :
178 print(
"this should never happen, big error",len(vlist),k,p,iev,nev)
183 Psq = vlist[1]**2+vlist[2]**2+vlist[3]**2
184 if abs(vlist[0])==13: Ekin = ROOT.TMath.Sqrt(Mmu2+Psq)-Mmu
185 else: Ekin = ROOT.TMath.Sqrt(Psq)
199 vlist[9] = norm/( pot[
"CERN-Cracow"][100.] + pot[
"Yandex"][5.] + pot[
"Yandex2"][10.] )
201 vlist[9] = norm/( pot[
"CERN-Cracow"][10.] + pot[
"Yandex"][5.] + pot[
"Yandex2"][10.] )
203 vlist[9] = norm/( pot[
"CERN-Cracow"][1.] + pot[
"Yandex"][5.] )
205 vlist[9] = norm/( pot[
"CERN-Cracow"][1.] + pot[
"Yandex"][0.5] )
207 vlist[9] = norm/( pot[
"Yandex"][0.5] )
209 print(
"this should not happen, except some rounding errors",p,Ekin,vlist[9])
213 vlist[6] = endOfHadronAbsorber
214 h[
'ntuple'].Fill(vlist[0],vlist[1],vlist[2],vlist[3],vlist[4],vlist[5],vlist[6],
215 vlist[7],vlist[8],vlist[9],vlist[10])
233 f = ROOT.TFile.Open(eospath+productions[p][
"file"])
234 t = f.FindObjectAny(
"pythia8-Geant4")
239 for l
in t.GetListOfLeaves():
240 if tuples ==
'': tuples += l.GetName()
241 else: tuples +=
":"+l.GetName()
242 h[
'N'] = ROOT.TFile(fnew,
'RECREATE')
243 print(
'new file created',fnew)
244 h[
'ntuple'] = ROOT.TNtuple(
"pythia8-Geant4",t.GetTitle()+
" no charm",tuples)
247 t.Draw(
">>temp",noOpCharm)
248 temp = ROOT.gROOT.FindObjectAny(
'temp')
251 leaves = t.GetListOfLeaves()
252 nL = leaves.GetEntries()
253 for iev
in range(nev):
254 rc = t.GetEntry(temp.GetEntry(iev))
256 for x
in range(leaves.GetEntries()):
257 vlist.append( leaves.At(x).GetValue() )
258 h[
'ntuple'].Fill(vlist)
268 fcascade = ROOT.TFile.Open(eospath+
"/Charm/Decay-Cascade-parp16-MSTP82-1-MSEL4-76Mpot_1.root")
270 newFile = ROOT.TFile(
"pythia8_Charm.root",
'RECREATE')
271 nt = ROOT.TNtuple(
"pythia8-Geant4",
"mu/nu flux from charm",
"id:px:py:pz:x:y:z:opx:opy:opz:ox:oy:oz:pythiaid:parentid:w:ecut")
272 for n
in range(t.GetEntries()):
274 ztarget = rnr.Exp(0.16) + startOfTarget
276 x = t.id,t.px,t.py,t.pz,0.,0.,ztarget,t.px,t.py,t.pz,0.,0.,ztarget,t.id,t.mid,t.weight,0.
277 for ax
in x: vlist.append(ax)
283 os.system(
"hadd -f pythia8_Geant4-withCharm.root pythia8_Geant4-noOpenCharm.root pythia8_Charm.root")
284 print(
" progress: minbias and charm merged")
288 event = ROOT.std.vector(
"float")
289 f = ROOT.TFile(
"pythia8_Geant4-withCharm.root")
290 t = f.FindObjectAny(
'pythia8-Geant4')
291 leaves = t.GetListOfLeaves()
292 L = leaves.GetEntries()
295 for n
in range(t.GetEntries()):
297 if m%1000000==0 : print(
'status read',m)
300 for l
in range(L): a.push_back(leaves.At(l).GetValue())
304 for n
in range(len(allEvents)): evList.append(n)
305 random.shuffle(evList)
306 leaves = t.GetListOfLeaves()
309 if tuples==
'': tuples += l.GetName()
310 else: tuples +=
":"+l.GetName()
311 newFile = ROOT.TFile(
"pythia8_Geant4-withCharm-ram.root",
'RECREATE')
312 randomTuple = ROOT.TNtuple(t.GetName(),t.GetTitle(),tuples)
316 if m%1000000==0 : print(
'status write',m)
319 for x
in a: vlist.append(x)
320 randomTuple.Fill(vlist)
326 print(
" progress: order of events randomized")
329 cuts = {
'_onlyNeutrinos':
'abs(id)==12||abs(id)==14||abs(id)==16',
'_onlyMuons':
'abs(id)==13'}
330 fName =
"pythia8_Geant4-withCharm-ram.root"
331 f = ROOT.TFile(fName)
332 t = f.FindObjectAny(
"pythia8-Geant4")
335 for idnu
in [16,-16,14,-14,12,-12]:
336 name = pdg.GetParticle(idnu).GetName()
338 if idnu < 0: idhnu=2000+abs(idnu)
339 ut.bookHist(h,str(idhnu),name+
' momentum (GeV)',400,0.,400.)
340 ut.bookHist(h,str(idhnu+100),name+
' log10(ptot) vs log10(pt+0.01)',100,-0.3,1.7,100,-2.,1.)
341 ut.bookHist(h,str(idhnu+200),name+
' log10(ptot) vs log10(pt+0.01)',25,-0.3,1.7,100,-2.,1.)
342 leaves = t.GetListOfLeaves()
344 if tuples ==
'': tuples += l.GetName()
345 else: tuples +=
":"+l.GetName()
347 fxx = fName.replace(
'-ram.root',opt+
'.root')
348 N = ROOT.TFile(fxx,
'RECREATE')
349 ntuple = ROOT.TNtuple(
"pythia8-Geant4",opt.replace(
"_only",
"")+
" flux mbias and charm"+opt,tuples)
352 t.Draw(
">>temp",cuts[opt])
353 temp = ROOT.gROOT.FindObjectAny(
'temp')
355 for iev
in range(temp.GetN()) :
356 rc = t.GetEntry(temp.GetEntry(iev))
358 for n
in range(leaves.GetSize()):
359 vlist.append(leaves.At(n).GetValue())
361 if "Neutrinos" in opt:
363 ptot=ROOT.TMath.Sqrt(pt2+t.pz**2)
364 l10ptot=min(max(ROOT.TMath.Log10(ptot),-0.3),1.69999)
365 l10pt=min(ROOT.TMath.Log10(ROOT.TMath.Sqrt(pt2)+0.01),0.9999)
368 if idnu < 0: idhnu=2000+abs(idnu)
369 h[str(idhnu)].Fill(ptot,t.w)
370 h[str(idhnu+100)].Fill(l10ptot,l10pt,t.w)
371 h[str(idhnu+200)].Fill(l10ptot,l10pt,t.w)
375 if "Neutrinos" in opt:
377 cln = h[akey].Class().GetName()
378 if not cln.find(
'TH')<0: h[akey].Write()
380 print(
" progress: splitted "+opt)
386 test(eospath+
'pythia8_Geant4_onlyMuons.root')
389 for ahist
in [
'mu-',
'mu+',
'mu',
'mu-charm',
'mu+charm',
'mucharm']:
390 h[
'TP'+z+ahist+x]=h[
'T'+z+ahist+x].Clone(
'CT'+ahist+x)
391 test(eospath+
'pythia8_Geant4_Yandex_onlyNeutrinos.root')
394 for ahist
in [
'numusum',
'nuesum',
'numusumcharm',
'nuesumcharm',
'numu',
'numubar',
'nue',
'nuebar',
'numucharm',
'numubarcharm',
'nuecharm',
'nuebarcharm']:
395 h[
'TP'+z+ahist+x]=h[
'T'+z+ahist+x].Clone(
'CT'+ahist+x)
396 test(eospath+
'Mbias/pythia8_Geant4-withCharm-ram.root')
403 h[
'T'+p+x].SetTitle(
'musum')
405 h[
'T'+p+
'charm'+x].Draw(
'same')
406 h[
'TP'+p+x].Draw(
'same')
407 h[
'TP'+p+x].SetLineColor(6)
408 h[
'TP'+p+
'charm'+x].Draw(
'same')
409 h[
'TP'+p+
'charm'+x].SetLineColor(3)
410 h[
'T'+p+
'charm'+x].SetLineColor(2)
411 h[
'T'+p+x].SetLineColor(4)
412 h[
'L'+p+x] = ROOT.TLegend(0.33,0.69,0.99,0.94)
413 h[
'L'+p+x].AddEntry(h[
'T'+p+x],
'muon new with charm, cascade, k-fac',
'PL')
414 h[
'L'+p+x].AddEntry(h[
'T'+p+
'charm'+x],
'muon from charm new with charm, cascade, k-fac',
'PL')
415 h[
'L'+p+x].AddEntry(h[
'TP'+p+x],
'muon old CERN-Cracow prod',
'PL')
416 h[
'L'+p+x].AddEntry(h[
'TP'+p+
'charm'+x],
'muon from charm old CERN-Cracow prod',
'PL')
421 h[
'T'+p+
'charm'+x].Draw(
'same')
422 h[
'TP'+p+x].Draw(
'same')
423 h[
'TP'+p+x].SetLineColor(6)
424 h[
'TP'+p+
'charm'+x].Draw(
'same')
425 h[
'TP'+p+
'charm'+x].SetLineColor(3)
426 h[
'T'+p+
'charm'+x].SetLineColor(2)
427 h[
'T'+p+x].SetLineColor(4)
428 h[
'L'+p+x] = ROOT.TLegend(0.33,0.69,0.99,0.94)
429 h[
'L'+p+x].AddEntry(h[
'T'+p+x],
'nu_mu new with charm, cascade, k-fac',
'PL')
430 h[
'L'+p+x].AddEntry(h[
'T'+p+
'charm'+x],
'nu_mu from charm new with charm, cascade, k-fac',
'PL')
431 h[
'L'+p+x].AddEntry(h[
'TP'+p+x],
'nu_mu old CERN-Cracow prod',
'PL')
432 h[
'L'+p+x].AddEntry(h[
'TP'+p+
'charm'+x],
'nu_mu from charm old CERN-Cracow prod',
'PL')
438 h[
'T'+p+
'charm'+x].Draw(
'same')
439 h[
'TP'+p+x].Draw(
'same')
440 h[
'TP'+p+x].SetLineColor(6)
441 h[
'TP'+p+
'charm'+x].Draw(
'same')
442 h[
'TP'+p+
'charm'+x].SetLineColor(3)
443 h[
'T'+p+
'charm'+x].SetLineColor(2)
444 h[
'T'+p+x].SetLineColor(4)
445 h[
'L'+p+x] = ROOT.TLegend(0.33,0.69,0.99,0.94)
446 h[
'L'+p+x].AddEntry(h[
'T'+p+x],
'nu_e new with charm, cascade, k-fac',
'PL')
447 h[
'L'+p+x].AddEntry(h[
'T'+p+
'charm'+x],
'nu_e from charm new with charm, cascade, k-fac',
'PL')
448 h[
'L'+p+x].AddEntry(h[
'TP'+p+x],
'nu_e old CERN-Cracow prod',
'PL')
449 h[
'L'+p+x].AddEntry(h[
'TP'+p+
'charm'+x],
'nu_e from charm old CERN-Cracow prod',
'PL')
454 h[
'Lmuc'+z+x] = ROOT.TLegend(0.33,0.73,0.99,0.94)
456 h[
'T'+p+x].SetTitle(
'mu-/mu+')
458 h[
'TP'+p+x].Draw(
'same')
459 h[
'TP'+p+x].SetLineColor(6)
460 h[
'T'+p+x].SetLineColor(4)
461 h[
'Lmuc'+z+x].AddEntry(h[
'T'+p+x],
'mu- new with charm, cascade, k-fac',
'PL')
462 h[
'Lmuc'+z+x].AddEntry(h[
'TP'+p+x],
'mu- old Yandex prod',
'PL')
464 h[
'T'+p+x].Draw(
'same')
465 h[
'TP'+p+x].Draw(
'same')
466 h[
'TP'+p+x].SetLineColor(3)
467 h[
'T'+p+x].SetLineColor(2)
468 h[
'Lmuc'+z+x].AddEntry(h[
'T'+p+x],
'mu+ new with charm, cascade, k-fac',
'PL')
469 h[
'Lmuc'+z+x].AddEntry(h[
'TP'+p+x],
'mu+ old Yandex prod',
'PL')
474 h[
'Lnumu'+z+x] = ROOT.TLegend(0.33,0.73,0.99,0.94)
476 h[
'T'+p+x].SetTitle(
'numu/numubar')
478 h[
'TP'+p+x].Draw(
'same')
479 h[
'TP'+p+x].SetLineColor(6)
480 h[
'T'+p+x].SetLineColor(4)
481 h[
'Lnumu'+z+x].AddEntry(h[
'T'+p+x],
'nu_mu new with charm, cascade, k-fac',
'PL')
482 h[
'Lnumu'+z+x].AddEntry(h[
'TP'+p+x],
'nu_mu old Yandex prod',
'PL')
484 h[
'T'+p+x].Draw(
'same')
485 h[
'TP'+p+x].Draw(
'same')
486 h[
'TP'+p+x].SetLineColor(3)
487 h[
'T'+p+x].SetLineColor(2)
488 h[
'Lnumu'+z+x].AddEntry(h[
'T'+p+x],
'anti nu_mu new with charm, cascade, k-fac',
'PL')
489 h[
'Lnumu'+z+x].AddEntry(h[
'TP'+p+x],
'anti nu_mu old Yandex prod',
'PL')
490 h[
'Lnumu'+z+x].Draw()
494 h[
'Lnue'+z+x] = ROOT.TLegend(0.33,0.73,0.99,0.94)
495 h[
'T'+p+x].SetTitle(
'nue/nuebar')
497 h[
'TP'+p+x].Draw(
'same')
498 h[
'TP'+p+x].SetLineColor(6)
499 h[
'T'+p+x].SetLineColor(4)
500 h[
'Lnue'+z+x].AddEntry(h[
'T'+p+x],
'nu_e new with charm, cascade, k-fac',
'PL')
501 h[
'Lnue'+z+x].AddEntry(h[
'TP'+p+x],
'nu_e old Yandex prod',
'PL')
503 h[
'T'+p+x].Draw(
'same')
504 h[
'TP'+p+x].Draw(
'same')
505 h[
'TP'+p+x].SetLineColor(3)
506 h[
'T'+p+x].SetLineColor(2)
507 h[
'Lnue'+z+x].AddEntry(h[
'T'+p+x],
'anti nu_e new with charm, cascade, k-fac',
'PL')
508 h[
'Lnue'+z+x].AddEntry(h[
'TP'+p+x],
'anti nu_e old Yandex prod',
'PL')
511 h[t].Print(
'comparison'+z+x.replace(
'_>',
'')+
'.png')
512 h[t].Print(
'comparison'+z+x.replace(
'_>',
'')+
'.pdf')
516 h[z+
'muRatio'+x]=h[
'T'+z+
'mu'+x].Clone(z+
'muRatio'+x)
517 h[z+
'muRatio'+x].Divide(h[
'TP'+z+
'mu'+x])
518 h[z+
'numuRatio'+x]=h[
'T'+z+
'numusum'+x].Clone(z+
'numuRatio'+x)
519 h[z+
'numuRatio'+x].Divide(h[
'TP'+z+
'numusum'+x])
520 h[z+
'nueRatio'+x]=h[
'T'+z+
'nuesum'+x].Clone(z+
'nueRatio'+x)
521 h[z+
'nueRatio'+x].Divide(h[
'TP'+z+
'nuesum'+x])
522 ut.bookCanvas(h,key=
'ratios',title=
'ratios',nx=1800,ny=600,cx=2,cy=1)
525 h[
'Lratio'+z+x] = ROOT.TLegend(0.21,0.74,0.71,0.85)
526 tc = h[
'ratios'].cd(n)
528 h[z+
'muRatio'+x].SetLineColor(2)
529 h[z+
'muRatio'+x].SetMaximum(max(h[z+
'muRatio'+x].GetMaximum(),h[z+
'numuRatio'+x].GetMaximum()))
530 h[z+
'muRatio'+x].SetMinimum(0)
531 h[z+
'muRatio'+x].SetStats(0)
532 h[z+
'muRatio'+x].Draw()
533 h[z+
'numuRatio'+x].SetLineColor(3)
534 h[z+
'numuRatio'+x].SetStats(0)
535 h[z+
'numuRatio'+x].Draw(
'same')
538 h[
'Lratio'+z+x].AddEntry(h[z+
'muRatio'+x],
'muon flux new / old ',
'PL')
539 h[
'Lratio'+z+x].AddEntry(h[z+
'numuRatio'+x],
'nu_mu flux new / old ',
'PL')
541 h[
'Lratio'+z+x].Draw()
542 h[
'ratios'].Print(
'comparisonRatios.png')
543 h[
'ratios'].Print(
'comparisonRatios.pdf')