1from __future__
import print_function
2from __future__
import division
5import ROOT,time,os,sys,random,getopt
7ROOT.gROOT.LoadMacro(
"$VMCWORKDIR/gconfig/basiclibs.C")
11fname=
'/eos/experiment/ship/data/Charm/Cascade-parp16-MSTP82-1-MSEL4-76Mpot_1'
18print(
"usage: python $FAIRSHIP/macro/makeDecay.py -f ")
21 opts, args = getopt.getopt(sys.argv[1:],
"f:p:c:",[\
23except getopt.GetoptError:
25 print(
' enter -f: input file with charm hadrons')
26 print(
' for experts: p pot= number of protons on target per spill to normalize on')
27 print(
' : c chicc= ccbar over mbias cross section')
31 fname = a.replace(
'.root',
'')
32 if o
in (
"-p",
"--pot"):
34 if o
in (
"-c",
"--chicc"):
39tmp = os.path.abspath(FIN).split(
'/')
40FOUT=
'Decay-'+tmp[len(tmp)-1]
41if FIN.find(
'eos')<0: fin = ROOT.TFile(FIN)
42else: fin = ROOT.TFile.Open(ROOT.gSystem.Getenv(
"EOSSHIP")+FIN)
43sTree = fin.FindObjectAny(
"pythia6")
44nEvents = sTree.GetEntries()
52 fhin = ROOT.TFile(FIN.replace(
'ntuple',
'hists'))
56nrcpot=hc[
'2'].GetBinContent(1)/2.
57print(
'Input file: ',FIN,
' with ',nEvents,
' entries, corresponding to nr-pot=',nrcpot)
59print(
'Output ntuples written to: ',FOUT)
61P8gen = ROOT.TPythia8()
63P8.readString(
"ProcessLevel:all = off")
68 n = p8.particleData.nextId(n)
69 p = p8.particleData.particleDataEntryPtr(n)
71 command = str(n)+
":mayDecay = false"
72 p8.readString(command)
73 print(
"Pythia8 configuration: Made %s stable for Pythia, should decay in Geant4",p.name())
78ftup = ROOT.TFile.Open(FOUT,
'RECREATE')
79Ntup = ROOT.TNtuple(
"Decay",
"pythia8 heavy flavour decays",
"id:px:py:pz:E:M:weight:mid:mpx:mpy:mpz:mE:pot:ptGM:pzGM")
84PDG = ROOT.TDatabasePDG.Instance()
85for idnu
in range(12,18,2):
87 for idadd
in range(-1,3,2):
93 name=PDG.GetParticle(idw).GetName()
94 ut.bookHist(h,str(idhnu),name+
' momentum (GeV)',400,0.,400.)
95 ut.bookHist(h,str(idhnu+100),name+
' log10-p vs log10-pt',100,-0.3,1.7,100,-2.,0.5)
96 ut.bookHist(h,str(idhnu+200),name+
' log10-p vs log10-pt',25,-0.3,1.7,100,-2.,0.5)
103for n
in range(nEvents):
104 rc = sTree.GetEvent(n)
107 if not setByHand
and sTree.M>5:
109 print(
"automatic detection of beauty, configured for beauty")
110 print(
'bb cross section / mbias ',chicc)
112 print(
'cc cross section / mbias ',chicc)
114 print(
'weights: ',nrpotspill,
' p.o.t. per spill')
116 wspill=nrpotspill*chicc/nrcpot
118 pt=ROOT.TMath.Sqrt(sTree.mpx**2+sTree.mpy**2)
120 if pt<1.e-5
and int(sTree.mid)==2212:
123 idabs=int(abs(sTree.id))
124 if idabs==431: nDsprim+=1
126 P8.event.append(int(sTree.id),1,0,0,sTree.px,sTree.py,sTree.pz,sTree.E,sTree.M,0.,9.)
129 for n
in range(P8.event.size()):
131 if P8.event[n].isFinal():
133 idabs=int(abs(P8.event[n].id()))
134 if idabs>11
and idabs<17:
136 ptGM = ROOT.TMath.Sqrt(sTree.mpx*sTree.mpx+sTree.mpy*sTree.mpy)
137 Ntup.Fill(par.id(),par.px(),par.py(),par.pz(),par.e(),par.m(),wspill,sTree.id,sTree.px,sTree.py,sTree.pz,sTree.E,sTree.M,ptGM,sTree.mpz)
139 if idabs==16
or idabs==14
or idabs==12:
141 if par.id()<0: idhnu+=1000
142 pt2=par.px()**2+par.py()**2
143 ptot=ROOT.TMath.Sqrt(pt2+par.pz()**2)
144 l10ptot=min(max(ROOT.TMath.Log10(ptot),-0.3),1.69999)
145 l10pt=min(max(ROOT.TMath.Log10(ROOT.TMath.Sqrt(pt2)),-2.),0.4999)
146 h[str(idhnu)].Fill(ptot,wspill)
147 h[str(idhnu+100)].Fill(l10ptot,l10pt,wspill)
148 h[str(idhnu+200)].Fill(l10ptot,l10pt,wspill)
150print(
'Now at Ntup.Write() for pot=',pot,nrcpot)
151if (1.-pot/nrcpot)<1.e-2:
152 print(
'write ntuple, weight/event=',nrpotspill,
'x',chicc,
'/',nrcpot,
'=',wspill)
154 for akey
in h: h[akey].Write()
156 print(
'Neutrino statistics/spill of 5.e15 pot:')
157 for idnu
in range(12,18,2):
159 for idadd
in range(-1,3,2):
165 print(idhnu,h[str(idhnu)].GetTitle(),(
"%8.3E "%(h[str(idhnu)].Integral())))
167 fDsP6=1.*nDsprim/ntotprim
170 print(
'fDs of primary proton interactions in P6=',fDsP6,
' should be ',fDs)
173 print(
'*********** WARNING ***********')
174 print(
'number of POT does not agree between ntuple and hists, i.e.:',pot,
'<>',nrcpot)
175 print(
'mu/neutrino ntuple has NOT been written')