def myEventLoop(n): if (n%1000==0): print "--Processing event %d"%n rc = sTree.GetEntry(n) nTrks = sTree.MCTrack.GetEntries() dpindex = findDP() counts=[0,0,0,0,0,0,0,0] if (dpindex < 0): print "ERROR! Did not find dark photon in event %d..."%n counts[0] += 1 return counts if (prodMode=="meson"): xsw = dputil.getDPprodRate(mass,epsilon,prodMode,findMumPDGID()) else: xsw = dputil.getDPprodRate(mass,epsilon,prodMode,0) if (xsw == 0): print "ERROR! Production rate is 0 in event %d..."%n counts[1] += 1 mymass = checkMass(dpindex) wg = sTree.MCTrack[dpindex].GetWeight() LS = ROOT.gRandom.Uniform(flmin,flmax) p = sTree.MCTrack[dpindex].GetP() e = sTree.MCTrack[dpindex].GetEnergy() gam = e/ROOT.TMath.Sqrt(e*e-p*p) beta = p/e DP_instance = darkphoton.DarkPhoton(mass,epsilon) ctau = DP_instance.cTau() wnew = ROOT.TMath.Exp(-LS/(beta*gam*ctau))*( (flmax-flmin)/(beta*gam*ctau) ) #print "A' decay vertex rescaling weight: %.8g %.8g %.8g %.8g %.8g"%(beta,gam,ctau,wg,wnew) #print "A' info: %3.3f %d %d %3.3f %3.3f" %(mass,dpindex,sTree.MCTrack[dpindex].GetPdgCode(),sTree.MCTrack[dpindex].GetPt(),sTree.MCTrack[dpindex].GetRapidity()) #select only decays to mu daughters=findDecayProd(dpindex) for p in range(0,len(daughters)): h['DPdecay'].Fill(sTree.MCTrack[daughters[p]].GetPdgCode()) if (len(daughters)!=2): counts[6] += 1 print "Event %d, Daughters:\t"%n for p in range(0,len(daughters)): print "pdg %d \t"%(sTree.MCTrack[daughters[p]].GetPdgCode()) #for idx in range(0,sTree.MCTrack.GetEntries()): #print "%d %d %d %3.3f %3.3f"%(idx,sTree.MCTrack[idx].GetMotherId(),sTree.MCTrack[idx].GetPdgCode(),sTree.MCTrack[idx].GetPt(),sTree.MCTrack[idx].GetRapidity()) else: h['DPgenM'].Fill(mymass) h['DPgenMw'].Fill(mymass,wnew*xsw) #filter with vertex in decay volume: decVtxx=sTree.MCTrack[daughters[0]].GetStartX() decVtxy=sTree.MCTrack[daughters[0]].GetStartY() decVtxz=sTree.MCTrack[daughters[0]].GetStartZ() if (decVtxz < zmin or decVtxz > zmax or abs(decVtxx)>xmax or abs(decVtxy)>ymax): counts[7] += 1 return counts h['DPvtxMw'].Fill(mymass,wnew*xsw) pt1=sTree.MCTrack[daughters[0]].GetPt() pt2=sTree.MCTrack[daughters[1]].GetPt() eta1=ROOT.TMath.ASinH(sTree.MCTrack[daughters[0]].GetPz()/sTree.MCTrack[daughters[0]].GetPt()) eta2=ROOT.TMath.ASinH(sTree.MCTrack[daughters[1]].GetPz()/sTree.MCTrack[daughters[1]].GetPt()) px1 = sTree.MCTrack[daughters[0]].GetPx() py1 = sTree.MCTrack[daughters[0]].GetPy() phi1 = ROOT.TMath.ATan(py1/px1) if (px1<0): phi1 += abs(py1)/py1*3.1416 px2 = sTree.MCTrack[daughters[1]].GetPx() py2 = sTree.MCTrack[daughters[1]].GetPy() phi2 = ROOT.TMath.ATan(py2/px2) if (px2<0): phi2 += abs(py2)/py2*3.1416 lv1=ROOT.TLorentzVector(sTree.MCTrack[daughters[0]].GetPx(),sTree.MCTrack[daughters[0]].GetPy(),sTree.MCTrack[daughters[0]].GetPz(),sTree.MCTrack[daughters[0]].GetEnergy()) lv2=ROOT.TLorentzVector(sTree.MCTrack[daughters[1]].GetPx(),sTree.MCTrack[daughters[1]].GetPy(),sTree.MCTrack[daughters[1]].GetPz(),sTree.MCTrack[daughters[1]].GetEnergy()) dauMass = (lv1+lv2).M() #dauMass = 2*pt1*pt2*(ROOT.TMath.CosH(eta1-eta2)-ROOT.TMath.Cos(phi1-phi2)) if (abs(sTree.MCTrack[daughters[0]].GetPdgCode())==13 and abs(sTree.MCTrack[daughters[1]].GetPdgCode())==13): #print "Select decay to %s %s"%(sTree.MCTrack[daughters[0]].GetPdgCode(),sTree.MCTrack[daughters[1]].GetPdgCode()) h['DPselMw'].Fill(mymass,wg*xsw) h['DPselMwnew'].Fill(mymass,wnew*xsw) counts[3] += 1 h['muEta'].Fill(eta1,wnew) h['muPT'].Fill(pt1,wnew) h['muPhi'].Fill(phi1,wnew) h['muEta'].Fill(eta2,wnew) h['muPT'].Fill(pt2,wnew) h['muPhi'].Fill(phi2,wnew) h['mumuM'].Fill(dauMass,wnew*xsw) else: #select only decays to e if (abs(sTree.MCTrack[daughters[0]].GetPdgCode())==11 and abs(sTree.MCTrack[daughters[1]].GetPdgCode())==11): #print "Reject decay to %s %s"%(sTree.MCTrack[daughters[0]].GetPdgCode(),sTree.MCTrack[daughters[1]].GetPdgCode()) counts[2] += 1 h['eEta'].Fill(eta1,wnew) h['ePT'].Fill(pt1,wnew) h['ePhi'].Fill(phi1,wnew) h['eEta'].Fill(eta2,wnew) h['ePT'].Fill(pt2,wnew) h['ePhi'].Fill(phi2,wnew) h['eeM'].Fill(dauMass,wnew*xsw) #select only decays to tau elif (abs(sTree.MCTrack[daughters[0]].GetPdgCode())==15 and abs(sTree.MCTrack[daughters[1]].GetPdgCode())==15): #print "Reject decay to %s %s"%(sTree.MCTrack[daughters[0]].GetPdgCode(),sTree.MCTrack[daughters[1]].GetPdgCode()) counts[4] += 1 h['tauEta'].Fill(eta1,wnew) h['tauPT'].Fill(pt1,wnew) h['tauPhi'].Fill(phi1,wnew) h['tauEta'].Fill(eta2,wnew) h['tauPT'].Fill(pt2,wnew) h['tauPhi'].Fill(phi2,wnew) h['tautauM'].Fill(dauMass,wnew*xsw) #select only decays to hadrons else: #print "Reject decay to %s %s in event %d"%(sTree.MCTrack[daughters[0]].GetPdgCode(),sTree.MCTrack[daughters[1]].GetPdgCode(),n) counts[5] += 1 h['hadEta'].Fill(eta1,wnew) h['hadPT'].Fill(pt1,wnew) h['hadPhi'].Fill(phi1,wnew) h['hadEta'].Fill(eta2,wnew) h['hadPT'].Fill(pt2,wnew) h['hadPhi'].Fill(phi2,wnew) h['hadM'].Fill(dauMass,wnew*xsw) return counts
def configure(P8gen, mass, epsilon, inclusive, deepCopy=False): # configure pythia8 for Ship usage debug = True if debug: cf = open('pythia8_darkphotonconf.txt', 'w') #h=readFromAscii() P8gen.UseRandom3() # TRandom1 or TRandom3 ? P8gen.SetMom(400) # beam momentum in GeV if deepCopy: P8gen.UseDeepCopy() pdg = ROOT.TDatabasePDG.Instance() if inclusive == "meson": # let strange particle decay in Geant4 p8 = P8gen.getPythiaInstance() n = 1 while n != 0: n = p8.particleData.nextId(n) p = p8.particleData.particleDataEntryPtr(n) if p.tau0() > 1: command = str(n) + ":mayDecay = false" p8.readString(command) print "Pythia8 configuration: Made %s stable for Pythia, should decay in Geant4" % ( p.name()) # Configuring production P8gen.SetParameters("SoftQCD:nonDiffractive = on") if debug: cf.write('P8gen.SetParameters("SoftQCD:nonDiffractive = on")\n') elif inclusive == "qcd": P8gen.SetDY() P8gen.SetMinDPMass(0.7) if (mass < P8gen.MinDPMass()): print "WARNING! Mass is too small, minimum is set to %3.3f GeV." % P8gen.MinDPMass( ) return 0 # produce a Z' from hidden valleys model p8 = P8gen.getPythiaInstance() n = 1 while n != 0: n = p8.particleData.nextId(n) p = p8.particleData.particleDataEntryPtr(n) if p.tau0() > 1: command = str(n) + ":mayDecay = false" p8.readString(command) print "Pythia8 configuration: Made %s stable for Pythia, should decay in Geant4" % ( p.name()) # Configuring production P8gen.SetParameters("HiddenValley:ffbar2Zv = on") if debug: cf.write('P8gen.SetParameters("HiddenValley:ffbar2Zv = on")\n') P8gen.SetParameters("HiddenValley:Ngauge = 1") elif inclusive == "pbrem": P8gen.SetParameters("ProcessLevel:all = off") if debug: cf.write('P8gen.SetParameters("ProcessLevel:all = off")\n') #Also allow resonance decays, with showers in them #P8gen.SetParameters("Standalone:allowResDec = on") #Optionally switch off decays. #P8gen.SetParameters("HadronLevel:Decay = off") #Switch off automatic event listing in favour of manual. P8gen.SetParameters("Next:numberShowInfo = 0") P8gen.SetParameters("Next:numberShowProcess = 0") P8gen.SetParameters("Next:numberShowEvent = 0") proton_bremsstrahlung.protonEnergy = P8gen.GetMom() norm = proton_bremsstrahlung.prodRate(mass, epsilon) print "A' production rate per p.o.t: \t %.8g" % norm P8gen.SetPbrem( proton_bremsstrahlung.hProdPDF(mass, epsilon, norm, 350, 1500)) #Define dark photon DP_instance = darkphoton.DarkPhoton(mass, epsilon) ctau = DP_instance.cTau() print 'ctau p8dpconf file =%3.6f cm' % ctau print 'Initial particle parameters for PDGID %d :' % P8gen.GetDPId() P8gen.List(P8gen.GetDPId()) if inclusive == "qcd": P8gen.SetParameters(str(P8gen.GetDPId()) + ":m0 = " + str(mass)) #P8gen.SetParameters(str(P8gen.GetDPId())+":mWidth = "+str(u.mm/ctau)) P8gen.SetParameters( str(P8gen.GetDPId()) + ":mWidth = " + str(u.hbarc / ctau)) P8gen.SetParameters(str(P8gen.GetDPId()) + ":mMin = 0.001") P8gen.SetParameters( str(P8gen.GetDPId()) + ":tau0 = " + str(ctau / u.mm)) #P8gen.SetParameters("ParticleData:modeBreitWigner = 0") #P8gen.SetParameters(str(P8gen.GetDPId())+":isResonance = false") #P8gen.SetParameters(str(P8gen.GetDPId())+":all = A A 3 0 0 "+str(mass)+" 0.0 0.0 0.0 "+str(ctau/u.mm)+" 0 1 0 1 0") #if debug: cf.write('P8gen.SetParameters("'+str(P8gen.GetDPId())+':all = A A 3 0 0 '+str(mass)+' 0.0 0.0 0.0 '+str(ctau/u.mm)+' 0 1 0 1 0") \n') P8gen.SetParameters(str(P8gen.GetDPId()) + ":onMode = off") #print 'qcd inclusive test' else: P8gen.SetParameters( str(P8gen.GetDPId()) + ":new = A A 3 0 0 " + str(mass) + " 0.0 0.0 0.0 " + str(ctau / u.mm) + " 0 1 0 1 0") if debug: cf.write('P8gen.SetParameters("' + str(P8gen.GetDPId()) + ':new = A A 3 0 0 ' + str(mass) + ' 0.0 0.0 0.0 ' + str(ctau / u.mm) + ' 0 1 0 1 0") \n') #if (inclusive=="pbrem"): ### Do not set as resonance: decays to hadron doesn't work properly below 0.7 GeV. # P8gen.SetParameters(str(P8gen.GetDPId())+":isResonance = true") # P8gen.SetParameters(str(P8gen.GetDPId())+":mWidth = "+str(u.hbarc/ctau)) # P8gen.SetParameters(str(P8gen.GetDPId())+":mMin = 0.001") P8gen.SetParameters("Next:numberCount = 0") if debug: cf.write('P8gen.SetParameters("Next:numberCount = 0")\n') # Configuring decay modes... readDecayTable.addDarkPhotondecayChannels( P8gen, DP_instance, conffile=os.path.expandvars( '$FAIRSHIP/python/darkphotonDecaySelection.conf'), verbose=True) # Finish HNL setup... P8gen.SetParameters(str(P8gen.GetDPId()) + ":mayDecay = on") if debug: cf.write('P8gen.SetParameters("' + str(P8gen.GetDPId()) + ':mayDecay = on")\n') #P8gen.SetDPId(P8gen.GetDPId()) #if debug: cf.write('P8gen.SetDPId(%d)\n',%P8gen.GetDPId()) # also add to PDG gamma = u.hbarc / float( ctau ) #197.3269631e-16 / float(ctau) # hbar*c = 197 MeV*fm = 197e-16 GeV*cm print 'gamma=%e' % gamma addDPtoROOT(pid=P8gen.GetDPId(), m=mass, g=gamma) if inclusive == "meson": #change meson decay to dark photon depending on mass selectedMum = manipulatePhysics(mass, P8gen, cf) print 'selected mum is : %d' % selectedMum if (selectedMum == -1): return 0 #P8gen.SetParameters("Check:particleData = on") if debug: cf.close() return 1
d = open(o4, 'w+') dn = open(o4n, 'w+') dc = open(o4c, 'w+') d0 = open(o4p, 'w+') f = open(o6, 'w+') g = open(o7, 'w+') H = open(o8, 'w+') k = open(o9, 'w+') l = open(o10, 'w+') if float(h['DP'].Integral()) != 0: print h['DP'].Integral(), h['DPpur'].Integral(), h['DPvesW'].Integral( ), h['DPang'].Integral(), h['DPangWe'].Integral() NomL, NomL1, DenL = 0., 0., 0. Sum, ves_s, ang_s = 0., 0., 0. DP_instance = darkphoton.DarkPhoton(float(mass_mc), float(eps)) BR1 = DP_instance.findBranchingRatio('A -> e- e+') BR2 = DP_instance.findBranchingRatio('A -> mu- mu+') BR3 = DP_instance.findBranchingRatio('A -> tau- tau+') BR = BR1 + BR2 + BR3 BRe = BR1 / BR BRm = BR2 / BR BRt = BR3 / BR H.write('%.4g %s %.8g %.8g %.8g %.8g %.8g %.8g' % (mass_mc, eps, nEvents, float(h['DPW'].Integral()), float(h['DP'].Integral()), float(h['DPpur'].Integral()), float(h['DPves'].Integral()), float(h['DPangW'].Integral()))) H.write('\n') if float(h['DPvesW'].Integral()) != 0.: f.write('%.4g %s %.8g %.8g %.8g %.8g' % (mass_mc, eps, float(h['DP_oth'].Integral()) /