def costheta_CS(pt1, eta1, phi1, pt2, eta2, phi2, l1id): mu1 = TLorentzVector() mu2 = TLorentzVector() Q = TLorentzVector() if (l1id < 0): mu1.SetPtEtaPhiM(pt1, eta1, phi1, 0) mu2.SetPtEtaPhiM(pt2, eta2, phi2, 0) else: mu1.SetPtEtaPhiM(pt2, eta2, phi2, 0) mu2.SetPtEtaPhiM(pt1, eta1, phi1, 0) Q = mu1 + mu2 mu1plus = ((2.0)**(-0.5)) * (mu1.E() + mu1.Pz()) mu1minus = ((2.0)**(-0.5)) * (mu1.E() - mu1.Pz()) mu2plus = ((2.0)**(-0.5)) * (mu2.E() + mu2.Pz()) mu2minus = ((2.0)**(-0.5)) * (mu2.E() - mu2.Pz()) costheta = ((2.0 / Q.Mag()) / ((Q.Mag()**2.0 + Q.Pt()**2.0)**(0.5))) * (mu1plus * mu2minus - mu1minus * mu2plus) return costheta
def computeProcessedFeatures(muon1_p4, muon2_p4, unpairedMuon_p4, jpsi_p4, bc_p4): if ( bc_p4.M() != 0): bcPtCorrected = (bcPdgMass * bc_p4.Pt())/ bc_p4.M() else: bcPtCorrected = bc_p4.Pt() muonsSystem_p4 = muon1_p4 + muon2_p4 + unpairedMuon_p4 bcCorrected_p4 = TLorentzVector() bcCorrected_p4.SetPtEtaPhiM(bcPtCorrected, muonsSystem_p4.Eta(), muonsSystem_p4.Phi(), #bc_p4.M()) bcPdgMass) boostToBcCorrectedRestFrame = -bcCorrected_p4.BoostVector() #boostToJpsiRestFrame = -(muon1_p4+muon2_p4).BoostVector() boostToJpsiRestFrame = -jpsi_p4.BoostVector() unpairedMuonBoostedToBcCorrectedRestFrame_p4 = TLorentzVector() unpairedMuonBoostedToBcCorrectedRestFrame_p4.SetPtEtaPhiM(unpairedMuon_p4.Pt(), unpairedMuon_p4.Eta(), unpairedMuon_p4.Phi(), unpairedMuon_p4.M()) unpairedMuonBoostedToBcCorrectedRestFrame_p4.Boost(boostToBcCorrectedRestFrame) unpairedMuonBoostedToJpsiRestFrame_p4 = TLorentzVector() unpairedMuonBoostedToJpsiRestFrame_p4.SetPtEtaPhiM(unpairedMuon_p4.Pt(), unpairedMuon_p4.Eta(), unpairedMuon_p4.Phi(), unpairedMuon_p4.M()) unpairedMuonBoostedToJpsiRestFrame_p4.Boost(boostToJpsiRestFrame) nn_energyBcRestFrame = unpairedMuonBoostedToBcCorrectedRestFrame_p4.E() #nn_missMass2 = (bcCorrected_p4 - muon1_p4 - muon2_p4 - unpairedMuon_p4).M2() nn_missMass2 = (bcCorrected_p4 - jpsi_p4 - unpairedMuon_p4).M2() #nn_q2 = (bc_p4 - muon1_p4 - muon2_p4).M2() nn_q2 = (bcCorrected_p4 - jpsi_p4).M2() #nn_missPt = bcCorrected_p4.Pt() - muon1_p4.Pt() - muon2_p4.Pt() - unpairedMuon_p4.Pt() nn_missPt = bcCorrected_p4.Pt() - jpsi_p4.Pt() - unpairedMuon_p4.Pt() nn_energyJpsiRestFrame = unpairedMuonBoostedToJpsiRestFrame_p4.E() #nn_varPt = (muon1_p4 + muon2_p4).Pt() - unpairedMuon_p4.Pt() nn_varPt = jpsi_p4.Pt() - unpairedMuon_p4.Pt() nn_deltaRMu1Mu2 = muon1_p4.DeltaR(muon2_p4) nn_unpairedMuPhi = unpairedMuon_p4.Phi() nn_unpairedMuPt = unpairedMuon_p4.Pt() nn_unpairedMuEta = unpairedMuon_p4.Eta() featuresEntry = np.array([ [bcCorrected_p4.Pt()], [bcCorrected_p4.Px()], [bcCorrected_p4.Py()], [bcCorrected_p4.Pz()], [bcCorrected_p4.E()], [nn_energyBcRestFrame], [nn_missMass2], [nn_q2], [nn_missPt], [nn_energyJpsiRestFrame], [nn_varPt], [nn_deltaRMu1Mu2], [nn_unpairedMuPhi], [nn_unpairedMuPt], [nn_unpairedMuEta]], dtype=np.double) return featuresEntry
def fillProcessedFeaturesArray(featuresProcessed, channel): inputFileName = "rootuples/RootupleBcTo3Mu_"+channel+"Channel.root" inputFile = TFile.Open(inputFileName) inputTree = inputFile.Get("rootuple/ntuple") for event in inputTree: if(event.nBc < 1) : continue iBcSelected = bcSelector(event, isBkg = False) for iBc in iBcSelected: muon1_p4 = TLorentzVector() muon2_p4 = TLorentzVector() unpairedMuon_p4 = TLorentzVector() jpsi_p4 = TLorentzVector() bc_p4 = TLorentzVector() muon1_p4.SetXYZM(event.Bc_jpsi_mu1_px[iBc], event.Bc_jpsi_mu1_py[iBc], event.Bc_jpsi_mu1_pz[iBc], muonPdgMass) muon2_p4.SetXYZM(event.Bc_jpsi_mu2_px[iBc], event.Bc_jpsi_mu2_py[iBc], event.Bc_jpsi_mu2_pz[iBc], muonPdgMass) unpairedMuon_p4.SetXYZM(event.Bc_mu_px[iBc], event.Bc_mu_py[iBc], event.Bc_mu_pz[iBc], muonPdgMass) bc_p4.SetXYZM(event.Bc_px[iBc], event.Bc_py[iBc], event.Bc_pz[iBc], event.Bc_mass[iBc]) jpsi_p4.SetXYZM(event.Bc_jpsi_px[iBc], event.Bc_jpsi_py[iBc], event.Bc_jpsi_pz[iBc], event.Bc_jpsi_mass[iBc]) #print("---") #print("event.gen_mu_p4.Px(): ", event.gen_mu_p4.Px()) #print("event.Bc_mu_px[iBc]: ", event.Bc_mu_px[iBc]) featuresEntry = computeProcessedFeatures(event.gen_jpsi_mu1_p4, event.gen_jpsi_mu2_p4, event.gen_mu_p4, event.gen_jpsi_p4, event.gen_b_p4) #featuresEntry = computeProcessedFeatures(muon1_p4, muon2_p4, unpairedMuon_p4, jpsi_p4, bc_p4) featuresEntry = np.append(featuresEntry, np.array([[bc_p4.E()]]), axis=0) featuresEntry = np.append(featuresEntry, np.array([[jpsi_p4.E()]]), axis=0) featuresEntry = np.append(featuresEntry, np.array([[muon1_p4.E()]]), axis=0) featuresEntry = np.append(featuresEntry, np.array([[muon2_p4.E()]]), axis=0) featuresEntry = np.append(featuresEntry, np.array([[unpairedMuon_p4.E()]]), axis=0) #featuresEntry = computeProcessedFeatures(event.gen_muonPositive_p4, event.gen_muonNegative_p4, event.gen_unpairedMuon_p4, event.gen_jpsi_p4, event.gen_b_p4) #featuresEntry = np.append(featuresEntry, np.array([[event.triggerMatchDimuon0[iBc]]]), axis=0) #featuresEntry = np.append(featuresEntry, np.array([[event.triggerMatchJpsiTk[iBc]]]), axis=0) #featuresEntry = np.append(featuresEntry, np.array([[event.triggerMatchJpsiTkTk[iBc]]]), axis=0) #featuresEntry = np.append(featuresEntry, np.array([[event.signalDecayPresent[iBc]]]), axis=0) #featuresEntry = np.append(featuresEntry, np.array([[event.normalizationDecayPresent[iBc]]]), axis=0) #featuresEntry = np.append(featuresEntry, np.array([[event.background1DecayPresent[iBc]]]), axis=0) featuresProcessed = np.append(featuresProcessed,featuresEntry, axis=1) return featuresProcessed
def process(self, event): '''Smear the beam energy. The two incoming particle energies are smeared under a Gaussian pdf of width sigma relative to the beam energy All outgoing particles are then boosted to the new com system ''' genptcs = getattr(event, self.cfg_ana.gen_particles) sigma = self.cfg_ana.sigma f1 = random.gauss(1, sigma) f2 = random.gauss(1, sigma) beamptcs = [p for p in genptcs if p.status() == 4] pprint.pprint(beamptcs) assert(len(beamptcs) == 2) def smear(ptc, factor): e = ptc.p4().E() * factor pz = math.sqrt(e ** 2 - ptc.m() ** 2) if ptc.p4().Pz() < 0: pz = -pz ptc._tlv.SetPxPyPzE( ptc.p4().Px(), ptc.p4().Py(), pz, e) newcom = TLorentzVector() for ptc, factor in zip(beamptcs, [f1, f2]): smear(ptc, factor) ptc.p4().Print() print ptc.m() newcom += ptc.p4() print 'new com:' newcom.Print() boost = newcom.BoostVector() stablep4_before = TLorentzVector() stablep4 = TLorentzVector() for p in genptcs: if p in beamptcs: continue if p.status() == 1: stablep4_before += p._tlv # p._tlv.Boost(boost) p._tlv.Boost(boost) if p.status() == 1: stablep4 += p._tlv pprint.pprint(beamptcs) print newcom.E(), newcom.Pz() print stablep4.E(), stablep4.Pz() print stablep4_before.E(), stablep4_before.Pz() boost.Print()
def fixMiss(self): self.fillUnknowns() miss = TLorentzVector(0., 0., 0., 1.) for i in range(5): miss -= TLorentzVector(self.x[i]*self.beta[i]*sin(self.theta[i])*cos(self.phi[i]), \ self.x[i]*self.beta[i]*sin(self.theta[i])*sin(self.phi[i]), \ self.x[i]*self.beta[i]*cos(self.theta[i]), \ self.x[i]) self.alpha[5] = miss.E() self.alpha[6] = miss.P() / miss.E() self.alpha[7] = miss.Theta() self.alpha[8] = miss.Phi() self.fillUnknowns() self.fillConstraints(False)
def jet_processing(jet): # Find the jet (eta, phi) center=jet.sum(axis=0) v_jet=TLorentzVector(center[1], center[2], center[3], center[0]) # Centering parameters phi=v_jet.Phi() bv = v_jet.BoostVector() bv.SetPerp(0) for n in np.arange(len(jet)): if np.sum(jet[n,:]) != 0: v = TLorentzVector(jet[n,1], jet[n,2], jet[n,3], jet[n,0]) v.RotateZ(-phi) v.Boost(-bv) jet[n,:] = v[3], v[0], v[1], v[2] #(E,Px,Py,Pz) # Rotating parameters weighted_phi=0 weighted_eta=0 for n in np.arange(len(jet)): if np.sum(jet[n,:]) != 0: v = TLorentzVector(jet[n,1], jet[n,2], jet[n,3], jet[n,0]) r = np.sqrt(v.Phi()**2 + v.Eta()**2) if r != 0: #in case there is only one component weighted_phi += v.Phi() * v.E()/r weighted_eta += v.Eta() * v.E()/r #alpha = np.arctan2(weighted_phi, weighted_eta) #approximately align at eta alpha = np.arctan2(weighted_eta, weighted_phi) #approximately align at phi for n in np.arange(len(jet)): if np.sum(jet[n,:]) != 0: v = TLorentzVector(jet[n,1], jet[n,2], jet[n,3], jet[n,0]) #v.rotate_x(alpha) #approximately align at eta v.RotateX(-alpha) #approximately align at phi jet[n,:] = v[3], v[0], v[1], v[2] #(E,Px,Py,Pz) return jet
def jet_Lorentz_4v(jet): for n in np.arange(len(jet)): if np.sum(jet[n,:]) != 0: v = TLorentzVector(0, 0, 0, 0) v.SetPtEtaPhiM(jet[n,0], jet[n,1], jet[n,2], jet[n,3]) jet[n,:] = v.E(), v.Px(), v.Py(), v.Pz() return jet
def CostHE(p1, charge1, p2): #Cosine of the theta decay angle (top (Q=+2/3)) in the Helicity frame pTop1CM = TLorentzVector(0,0,-1,1) # In the CM frame pTop2CM = TLorentzVector(0,0,-1,1) # In the CM frame pDitopCM = TLorentzVector(0,0,-1,1) # In the CM frame pTop1Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTop2Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame beta = TVector3(0,0,0) zaxisCS = TVector3(0,0,0) # Get the muons parameters in the CM frame pTop1CM.SetPxPyPzE(p1.Px(),p1.Py(),p1.Pz(),p1.E()) pTop2CM.SetPxPyPzE(p2.Px(),p2.Py(),p2.Pz(),p2.E()) # Obtain the Ditop parameters in the CM frame pDitopCM=pTop1CM+pTop2CM # Translate the muon parameters in the Ditop rest frame beta=(-1./pDitopCM.E())*pDitopCM.Vect() if(beta.Mag()>=1): return 666. pTop1Ditop=pTop1CM pTop2Ditop=pTop2CM pTop1Ditop.Boost(beta) pTop2Ditop.Boost(beta) # Determine the z axis for the calculation of the polarization angle (i.e. the direction of the Ditop in the CM system) zaxis=(pDitopCM.Vect()).Unit() # Calculation of the polarization angle (angle between mu+ and the z axis defined above) cost = -999. if(charge1>0): cost = zaxis.Dot((pTop1Ditop.Vect()).Unit()) else: cost = zaxis.Dot((pTop2Ditop.Vect()).Unit()) return cost
def JpsiKst_Angles(kaon, pion, mu1, mu2): """ paula """ P11p = kaon[1] P12p = pion[1] P21p = mu1[1] P22p = mu2[1] from ROOT import TLorentzVector, TVector3 def NProductV(alpha, Vect): Vect1 = [Vect.x(), Vect.y(), Vect.z()] for i in range(0, 3): Vect1[i] = alpha * Vect[i] return TVector3(Vect1[0], Vect1[1], Vect1[2]) p1 = TLorentzVector(P11p[0], P11p[1], P11p[2], kaon[0]) p2 = TLorentzVector(P12p[0], P12p[1], P12p[2], pion[0]) p3 = TLorentzVector(P21p[0], P21p[1], P21p[2], mu1[0]) p4 = TLorentzVector(P22p[0], P22p[1], P22p[2], mu2[0]) p1Psi = TLorentzVector(p1) p12 = TLorentzVector(p1 + p2) p34 = TLorentzVector(p3 + p4) BK0S = TLorentzVector(p1 + p2 + p3 + p4) BPsi = TLorentzVector(p1 + p2 + p3 + p4) p1.Boost(NProductV(-1. / (p12.E()), p12.Vect())) BK0S.Boost(NProductV(-1. / (p12.E()), p12.Vect())) ThK = (p1.Vect()).Angle(-BK0S.Vect()) p1Psi.Boost(NProductV(-1. / (p34.E()), p34.Vect())) BPsi.Boost(NProductV(-1. / (p34.E()), p34.Vect())) xtr = BPsi.Vect().Unit() ytr = (p1Psi.Vect().Unit() - NProductV( (p1Psi.Vect().Unit()).Dot(xtr), xtr)).Unit() ztr = xtr.Cross(ytr) p3.Boost(NProductV(-1. / (p34.E()), p34.Vect())) Thtr = ztr.Angle(p3.Vect()) Phitr = xtr.Angle(p3.Vect() - NProductV(ztr.Dot(p3.Vect()), ztr)) if (ytr.Angle(p3.Vect() - NProductV(ztr.Dot(p3.Vect()), ztr)) > pi / 2.): Phitr = -Phitr return ThK, Thtr, Phitr
def GeneratePrimaries(self, anEvent): global debug, nevTot t_0 = time.time() npart = 0 while npart == 0: myPythia.GenerateEvent() nevTot += 1 myTimer['pythia'] += time.time() - t_0 # pythia interaction happens at 0,0,0 #x = rnr.Uniform(-3.,3.) #y = rnr.Uniform(-3.,3.) # leave this smearing for later # create new primaries and set them to the vertex particles = myPythia.GetListOfParticles() z = rnr.Exp(10 * cm) - 50. * m # tungsten interaction length ztarget = G4ThreeVector(0 * cm, 0 * cm, z) vertex = G4PrimaryVertex(ztarget, 0.) v = TLorentzVector() for p in particles: if p.GetStatusCode() != 1: continue pid = p.GetPdgCode() if tauOnly and abs(pid) != 16: continue mkey = p.GetMother(0) + 1 mother = myPythia.GetParticle(mkey) if JpsiMainly and abs( pid) != 13 and mother.GetPdgCode() != 443: continue qed = pid in qedlist # use cut only for photons, leptons/neutrinos, protons and neutrons p.Momentum(v) Ekin = (v.E() - v.M()) if Ekin * GeV < ecut and (qed or allPart): continue G4particle = G4PrimaryParticle(pid) G4particle.Set4Momentum(v.Px() * GeV, v.Py() * GeV, v.Pz() * GeV, v.E() * GeV) # store mother ID curPid = p.GetPdgCode() + 10000 # make it positive moPid = mother.GetPdgCode() + 10000 w = curPid + moPid * 100000 G4particle.SetWeight(w) vertex.SetPrimary(G4particle) npart += 1 # if debug: myPythia.EventListing() anEvent.AddPrimaryVertex(vertex) if debug: print 'new event at ', ztarget.z / m myTimer['geant4_conv'] += time.time() - t_0
def main(): #Aufgabenteil b) # initialisiere TLorentzVector-Objekt und setze Pt, eta, phi und M. Damit ist der Vierervektor vollstaendig bestimmt c_ = TLorentzVector() c_.SetPtEtaPhiM(99.83, 0.332, -2.45, 0) s = TLorentzVector() s.SetPtEtaPhiM(22.08, 0.137, 2.215, 0) ny = TLorentzVector() ny.SetPtEtaPhiM(44.73, 0, -2.472, 0) mu = TLorentzVector() mu.SetPtEtaPhiM(65.58, 1.08, -0.851, 0) wp = ny + mu # Addiere zwei Vierervektoren wm = c_ + s b = TLorentzVector() b_ = TLorentzVector() b_.SetPtEtaPhiM(74.01, 1.379, 0.494, 0) b.SetPtEtaPhiM(65.34, -0.228, 1.340, 0) t_ = wm + b_ t = wp + b # Ausgabe der invarianten Masse eines Vierervektors print("Masse Anti-Top: " + str(t_.M())) print("Masse Top: " + str(t.M())) print(t_) # Aufgabenteil c) s = t + t_ rapidity = 1 / 2 * math.log((s.E() + s.Pt()) / (s.E() - s.Pt())) print(s.M()) print(s.Pt()) print(s.E()) print(rapidity)
def Boosted_Angle(pt1, eta1, phi1, pt2, eta2, phi2, ptz, etaz, phiz, mass): mu1 = TLorentzVector() mu2 = TLorentzVector() zb = TLorentzVector() mu1.SetPtEtaPhiM(pt1, eta1, phi1, 0) mu2.SetPtEtaPhiM(pt2, eta2, phi2, 0) angle = mu1.Angle(mu2.Vect()) zb.SetPtEtaPhiM(ptz, etaz, phiz, mass) angle_Z1 = zb.Angle(mu1.Vect()) angle_Z2 = zb.Angle(mu2.Vect()) mu1.Boost(-zb.Px() / zb.E(), -zb.Py() / zb.E(), -zb.Pz() / zb.E()) mu2.Boost(-zb.Px() / zb.E(), -zb.Py() / zb.E(), -zb.Pz() / zb.E()) angleBoost = mu1.Angle(mu2.Vect()) angleBoost_Z1 = zb.Angle(mu1.Vect()) angleBoost_Z2 = zb.Angle(mu2.Vect()) #print "******&&&&******", angle, angleBoost return [angleBoost, angle, angleBoost_Z1, angle_Z1, angle_Z2]
def fill_evis_hist(collection, hist, norm_factor=1.0): v = TLorentzVector() for p in collection: if isinstance(p, TLorentzVector): v += p else: v += p.P4() hist.Fill(v.E() / norm_factor)
class particle: def __init__(self, tree=None, i=None, original=None): if tree: #Build particle instance from TTree self.PID = tree.Particle[i].PID self.mom = tree.Particle[i].Mother1 self.daughters = [] self.m = tree.Particle[i].M self.e = tree.Particle[i].E self.p = TLorentzVector() self.p.SetPxPyPzE(tree.Particle[i].Px, tree.Particle[i].Py, tree.Particle[i].Pz, tree.Particle[i].E) self.pt = self.p.Pt() self.eta = self.p.Eta() self.phi = self.p.Phi() self.SF = 1 self.smear = None self.res = None elif original: #Make a resolution smeared version of the original self.PID = copy(original.PID) self.mom = copy(original.mom) self.daughters = copy(original.daughters) self.res = jetEnergyResolution(original.p.E()) self.smearE = -1 while self.smearE < 0: self.smearE = np.random.normal(0.985, self.res) # self.offsetM = -1 # while self.offsetM+original.p.M() < 5: self.offsetM = np.random.normal(5, 5) # self.smearM = -1 # while self.smearM < 0.5: self.smearM = np.random.normal(1, 1) self.p = TLorentzVector() self.p.SetPtEtaPhiM(original.p.Pt() * self.smearE, original.p.Eta(), original.p.Phi(), 0) # self.p.SetPtEtaPhiM( original.p.Pt() * self.smearE, # original.p.Eta(), # original.p.Phi(), # (original.p.M()+self.offsetM) * self.smearM) self.pt = self.p.Pt() self.eta = self.p.Eta() self.phi = self.p.Phi() self.m = self.p.M() self.e = self.p.E() self.SF = 1 def getDump(self): out = "PID " + str(self.PID).rjust(3) + " | mom " + str( self.mom).rjust(3) + " | mass " + str(self.m).ljust( 12) + " | pt " + str(self.pt).ljust(20) + " | eta " + str( self.eta).ljust(20) + " | phi " + str(self.phi).ljust(20) if self.res: out += " | res " + str(self.res).ljust(20) + " | smear " + str( self.smear).ljust(20) return out def dump(self): print(self.getDump())
def GeneratePrimaries(self, anEvent): global debug, nevTot t_0 = time.time() npart = 0 while npart == 0: myPythia.GenerateEvent() nevTot += 1 myTimer['pythia'] += time.time() - t_0 # pythia interaction happens at 0,0,0 #x = rnr.Uniform(-3.,3.) #y = rnr.Uniform(-3.,3.) # leave this smearing for later pos = G4ThreeVector(0 * cm, 0 * cm, -50 * m) vertex = G4PrimaryVertex(pos, 0.) # create new primaries and set them to the vertex particles = myPythia.GetListOfParticles() for p in particles: if p.GetStatusCode() != 1: continue pid = p.GetPdgCode() if tauOnly and abs(pid) != 16: continue if pid in notWanted: continue G4particle = G4PrimaryParticle(pid) v = TLorentzVector() p.Momentum(v) if v.E() * GeV < ecut: continue G4particle.Set4Momentum(v.Px() * GeV, v.Py() * GeV, v.Pz() * GeV, v.E() * GeV) vertex.SetPrimary(G4particle) # store mother ID mkey = p.GetMother(0) + 1 mother = myPythia.GetParticle(mkey) curPid = p.GetPdgCode() + 10000 # make it positive moPid = mother.GetPdgCode() + 10000 w = curPid + moPid * 100000 G4particle.SetWeight(w) npart += 1 if tauOnly and debug: myPythia.EventListing() anEvent.AddPrimaryVertex(vertex) myTimer['geant4_conv'] += time.time() - t_0
def PhiCS(p1, charge1, p2): # Phi decay angle (top (Q=+2/3)) in the Collins-Soper frame pTop1CM = TLorentzVector(0,0,-1,1) # In the CM frame pTop2CM = TLorentzVector(0,0,-1,1) # In the CM frame pProjCM = TLorentzVector(0,0,-1,1) # In the CM frame pTargCM = TLorentzVector(0,0,-1,1) # In the CM frame pDitopCM = TLorentzVector(0,0,-1,1) # In the CM frame pTop1Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTop2Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pProjDitop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTargDitop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame beta = TVector3(0,0,0) yaxisCS = TVector3(0,0,0) xaxisCS = TVector3(0,0,0) zaxisCS = TVector3(0,0,0) mp = 0.93827231 ep = 6500. # Fill the Lorentz vector for projectile and target in the CM frame pProjCM.SetPxPyPzE(0.,0.,-ep,TMath.Sqrt(ep*ep+mp*mp)) pTargCM.SetPxPyPzE(0.,0.,+ep,TMath.Sqrt(ep*ep+mp*mp)) # Get the muons parameters in the CM frame pTop1CM.SetPxPyPzE(p1.Px(),p1.Py(),p1.Pz(),p1.E()) pTop2CM.SetPxPyPzE(p2.Px(),p2.Py(),p2.Pz(),p2.E()) # Obtain the Ditop parameters in the CM frame pDitopCM=pTop1CM+pTop2CM # Translate the Ditop parameters in the Ditop rest frame beta=(-1./pDitopCM.E())*pDitopCM.Vect() if(beta.Mag()>=1): return 666. pTop1Ditop=pTop1CM pTop2Ditop=pTop2CM pProjDitop=pProjCM pTargDitop=pTargCM pTop1Ditop.Boost(beta) pTop2Ditop.Boost(beta) pProjDitop.Boost(beta) pTargDitop.Boost(beta) # Determine the z axis for the CS angle zaxisCS=(((pProjDitop.Vect()).Unit())-((pTargDitop.Vect()).Unit())).Unit() yaxisCS=(((pProjDitop.Vect()).Unit()).Cross((pTargDitop.Vect()).Unit())).Unit() xaxisCS=(yaxisCS.Cross(zaxisCS)).Unit() phi = -999. if(charge1>0.): phi = TMath.ATan2((pTop1Ditop.Vect()).Dot(yaxisCS),((pTop1Ditop.Vect()).Dot(xaxisCS))) else: phi = TMath.ATan2((pTop2Ditop.Vect()).Dot(yaxisCS),((pTop2Ditop.Vect()).Dot(xaxisCS))) if(phi>TMath.Pi()): phi = phi-TMath.Pi() return phi
def PhiHE(p1, charge1, p2): # Phi decay angle (top (Q=+2/3)) in the Helicity frame pTop1Lab = TLorentzVector(0,0,-1,1) # In the lab. frame pTop2Lab = TLorentzVector(0,0,-1,1) # In the lab. frame pProjLab = TLorentzVector(0,0,-1,1) # In the lab. frame pTargLab = TLorentzVector(0,0,-1,1) # In the lab. frame pDitopLab = TLorentzVector(0,0,-1,1) # In the lab. frame pTop1Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTop2Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pProjDitop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTargDitop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame beta = TVector3(0,0,0) xaxis = TVector3(0,0,0) yaxis = TVector3(0,0,0) zaxis = TVector3(0,0,0) mp = 0.93827231 ep = 6500. # Get the muons parameters in the LAB frame pTop1Lab.SetPxPyPzE(p1.Px(),p1.Py(),p1.Pz(),p1.E()) pTop2Lab.SetPxPyPzE(p2.Px(),p2.Py(),p2.Pz(),p2.E()) # Obtain the Ditop parameters in the LAB frame pDitopLab=pTop1Lab+pTop2Lab zaxis=(pDitopLab.Vect()).Unit() # Translate the muon parameters in the Ditop rest frame beta=(-1./pDitopLab.E())*pDitopLab.Vect() if(beta.Mag()>=1.): return 666. pProjLab.SetPxPyPzE(0.,0.,-ep,TMath.Sqrt(ep*ep+mp*mp)) pTargLab.SetPxPyPzE(0.,0.,+ep,TMath.Sqrt(ep*ep+mp*mp)) pProjDitop=pProjLab pTargDitop=pTargLab pProjDitop.Boost(beta) pTargDitop.Boost(beta) yaxis=((pProjDitop.Vect()).Cross(pTargDitop.Vect())).Unit() xaxis=(yaxis.Cross(zaxis)).Unit() pTop1Ditop=pTop1Lab pTop2Ditop=pTop2Lab pTop1Ditop.Boost(beta) pTop2Ditop.Boost(beta) phi = -999. if(charge1>0.): phi = TMath.ATan2((pTop1Ditop.Vect()).Dot(yaxis),(pTop1Ditop.Vect()).Dot(xaxis)) else: phi = TMath.ATan2((pTop2Ditop.Vect()).Dot(yaxis),(pTop2Ditop.Vect()).Dot(xaxis)) return phi
def print_vec(self, vec): print "theta vec:", TMath.Pi() - vec.Theta() print return print "pxyz:", vec.Px(), vec.Py(), vec.Pz() print "en, phi:", vec.E(), vec.Phi() print v3 = vec.Vect() print "vxyz:", v3.x(), v3.y(), v3.z() print "theta v3: ", TMath.Pi() - v3.Theta() print theta_add = 1e-5 v3.SetTheta(v3.Theta() - theta_add) print "vxyz:", v3.x(), v3.y(), v3.z() print "theta v3: ", TMath.Pi() - v3.Theta() print vec2 = TLorentzVector(vec) vec3 = TLorentzVector(vec) vec.SetVect(v3) print "theta vec:", TMath.Pi() - vec.Theta() print "pxyz:", vec.Px(), vec.Py(), vec.Pz() print "en, phi:", vec.E(), vec.Phi() print vec2.SetTheta(vec2.Theta() - theta_add) print "theta vec:", TMath.Pi() - vec2.Theta() print "pxyz:", vec2.Px(), vec2.Py(), vec2.Pz() print "en, phi:", vec2.E(), vec2.Phi() print print "Delta theta, en, phi", vec3.Theta() - vec.Theta(), vec3.E( ) - vec.E(), vec3.Phi() - vec.Phi() print "Delta theta, en, phi", vec3.Theta() - vec2.Theta(), vec3.E( ) - vec2.E(), vec3.Phi() - vec2.Phi()
def momentum_aftr_boost(df, args): #args must have 4 elements xyzt or pxpypzE px, py, pz = getXYZ(df, args) E = DfToNp(df[[args[3]]].dropna(axis=0)) l = TLorentzVector() with np.nditer([px, py, pz, E, None, None, None, None]) as it: for pi, pj, pk, el, pm, pn, po, eq in it: l.SetPxPyPzE(pi, pj, pk, el) bi = pi / el l.Boost(-bi, 0, 0) pm[...] = l.Px() pn[...] = l.Py() po[...] = l.Pz() eq[...] = l.E() return (it.operands[4], it.operands[5], it.operands[6], it.operands[7])
def CostCS(p1, charge1, p2): #Cosine of the theta decay angle (top (Q=+2/3)) in the Collins-Soper frame pTop1CM = TLorentzVector(0,0,-1,1) # In the CM. frame pTop2CM = TLorentzVector(0,0,-1,1) # In the CM. frame pProjCM = TLorentzVector(0,0,-1,1) # In the CM. frame pTargCM = TLorentzVector(0,0,-1,1) # In the CM. frame pDitopCM = TLorentzVector(0,0,-1,1) # In the CM. frame pTop1Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTop2Ditop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pProjDitop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame pTargDitop = TLorentzVector(0,0,-1,1) # In the Ditop rest frame beta = TVector3(0,0,0) zaxisCS = TVector3(0,0,0) mp = 0.93827231 ep = 6500. # Fill the Lorentz vector for projectile and target in the CM frame pProjCM.SetPxPyPzE(0.,0.,-ep,TMath.Sqrt(ep*ep+mp*mp)) pTargCM.SetPxPyPzE(0.,0.,+ep,TMath.Sqrt(ep*ep+mp*mp)) # Get the Topons parameters in the CM frame pTop1CM.SetPxPyPzE(p1.Px(),p1.Py(),p1.Pz(),p1.E()) pTop2CM.SetPxPyPzE(p2.Px(),p2.Py(),p2.Pz(),p2.E()) # Obtain the Ditop parameters in the CM frame pDitopCM=pTop1CM+pTop2CM # Translate the Ditop parameters in the Ditop rest frame beta=(-1./pDitopCM.E())*pDitopCM.Vect() if(beta.Mag()>=1): return 666. pTop1Ditop=pTop1CM pTop2Ditop=pTop2CM pProjDitop=pProjCM pTargDitop=pTargCM pTop1Ditop.Boost(beta) pTop2Ditop.Boost(beta) pProjDitop.Boost(beta) pTargDitop.Boost(beta) # Determine the z axis for the CS angle zaxisCS=(((pProjDitop.Vect()).Unit())-((pTargDitop.Vect()).Unit())).Unit(); # Determine the CS angle (angle between Top+ and the z axis defined above) cost = -999 if(charge1>0): cost = zaxisCS.Dot((pTop1Ditop.Vect()).Unit()) else: cost = zaxisCS.Dot((pTop2Ditop.Vect()).Unit()) return cost
def boost(df, args): #args must have 4 elements xyzt or pxpypzE px, py, pz = getXYZ(df, args) E = DfToNp(df[[args[3]]].dropna(axis=0)) l = TLorentzVector() with np.nditer([px, py, pz, E, None, None, None, None]) as it: for pi, pj, pk, el, pm, en, phi, cost in it: l.SetPxPyPzE(pi, pj, pk, el) bi = pi / el bj = pj / el bk = pk / el l.Boost(-bi, -bj, -bk) pm[...] = l.Px() en[...] = l.E() phi[...] = l.Phi() cost[...] = l.CosTheta() return (it.operands[4], it.operands[5], it.operands[6], it.operands[7])
if negMu1 < 0: negMu1 = imu else: if posMu1 < 0: posMu1 = imu ## Skip events without a +/- charge pair if posMu1 < 0 or negMu1 < 0: continue ## Fill these chosen muons into the TLorentzVectors posMuon1.SetPtEtaPhiM(t.Muon_pt[posMu1], t.Muon_eta[posMu1], t.Muon_phi[posMu1], t.Muon_mass[posMu1]) negMuon1.SetPtEtaPhiM(t.Muon_pt[negMu1], t.Muon_eta[negMu1], t.Muon_phi[negMu1], t.Muon_mass[negMu1]) ## Create a list of physics quantities allmuons = [ posMuon1.E(), negMuon1.E(), posMuon1.Px(), negMuon1.Px(), posMuon1.Py(), negMuon1.Py(), posMuon1.Pz(), negMuon1.Pz() ] ## Test it! This is just for you Z = posMuon1 + negMuon1 hist.Fill(Z.M()) ## Store this event's information into the text file textfile.write(str(allmuons)[1:-2] + '\n')
class particle: #_____________________________________________________________________________ def __init__(self, pdg): #particle Lorentz vector self.vec = TLorentzVector() #index in particle list self.idx = 0 #status code self.stat = 0 #pdg code self.pdg = pdg #particle database for pass and codes self.pdgdat = TDatabasePDG.Instance() #mass, GeV self.mass = self.pdgdat.GetParticle(self.pdg).Mass() #parent particle id self.parent_id = 0 #vertex coordinates, mm self.vx = 0. self.vy = 0. self.vz = 0. #precision for momentum and energy self.pxyze_prec = 6 #_____________________________________________________________________________ def write_tx(self, track_list): #output line in TX format #Geant code and momentum lin = "TRACK: " + str(self.pdgdat.ConvertPdgToGeant3(self.pdg)) pxyz_form = " {0:." + str(self.pxyze_prec) + "f}" lin += pxyz_form.format(self.vec.Px()) lin += pxyz_form.format(self.vec.Py()) lin += pxyz_form.format(self.vec.Pz()) #track id lin += " " + str(len(track_list)) #start and stop vertex and pdg lin += " 1 0 " + str(self.pdg) track_list.append(lin) #_____________________________________________________________________________ def write_tparticle(self, particles, ipos): #write to TParticle clones array p = particles.ConstructedAt(ipos) p.SetMomentum(self.vec) p.SetPdgCode(self.pdg) p.SetProductionVertex(self.vx, self.vy, self.vz, 0) #_____________________________________________________________________________ def make_hepmc_particle(self, hepmc): #create HepMC3 particle p = hepmc.GenParticle( hepmc.FourVector(self.vec.Px(), self.vec.Py(), self.vec.Pz(), self.vec.E()), self.pdg, 1) return p
def PruneGenr8File(fname_in, fname_out, e_gamma_curr, theta_curr, verbose=False): # print "directory: " + os.getcwd() # print "input genr8 file: " + fname_in # print "output file: " + fname_out counter = 1 line1_out = "" #Run and event info line2_out = "" #Gamma ID info line3_out = "" #Gamma P4 info line4_out = "" #Proton ID info line5_out = "" #Proton P4 info line6_out = "" #Pi+ ID info line7_out = "" #Pi+ P4 info line8_out = "" #Pi- ID info line9_out = "" #Pi- P4 info rand = TRandom3(int(e_gamma_curr * 1000.)) p4_proton = TLorentzVector() for line in open(fname_in, 'r'): if (counter % 9 == 1): #Event info value_in_line = 1 run = "" event = "" for value in line.split(): if (value_in_line == 1): run = value if (value_in_line == 2): event = value if (verbose and value_in_line == 1): print "Run " + value if (verbose and value_in_line == 2): print "Event " + value if (verbose and value_in_line == 3): print "NParticles " + value value_in_line += 1 line1_out = run + " " + event + " " + "4\n" if (counter % 9 == 2): #Pi0 info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 if (counter % 9 == 3): #Pi0 p4 value_in_line = 1 p4_string = line.split() p4_gam1 = TLorentzVector(float(p4_string[1]), float(p4_string[2]), float(p4_string[3]), float(p4_string[4])) for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 if (counter % 9 == 4): #Pi+ info value_in_line = 1 line2_str = line for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 line6_out = "3 8 0.13957\n" if (counter % 9 == 5): #Pi+ p4 value_in_line = 1 p4_string = line.split() p4_pipl = TLorentzVector(float(p4_string[1]), float(p4_string[2]), float(p4_string[3]), float(p4_string[4])) for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 line7_out = " 1 " + str(p4_pipl.Px()) + " " + str( p4_pipl.Py()) + " " + str(p4_pipl.Pz()) + " " + str( p4_pipl.E()) + "\n" if (counter % 9 == 6): #Pi- info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 line8_out = "4 9 0.13957\n" if (counter % 9 == 7): #Pi- p4 value_in_line = 1 p4_string = line.split() p4_pim = TLorentzVector(float(p4_string[1]), float(p4_string[2]), float(p4_string[3]), float(p4_string[4])) for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 line9_out = " -1 " + str(p4_pim.Px()) + " " + str( p4_pim.Py()) + " " + str(p4_pim.Pz()) + " " + str( p4_pim.E()) + "\n" if (counter % 9 == 8): #proton info value_in_line = 1 for value in line.split(): if (verbose and value_in_line == 1): print "Particle number in event: " + value if (verbose and value_in_line == 2): print "Particle enum value " + value if (verbose and value_in_line == 3): print "Particle mass " + value value_in_line += 1 line4_out = "2 14 0.938272\n" if (counter % 9 == 0): #proton p4 value_in_line = 1 p4_string = line.split() p4_proton = TLorentzVector(float(p4_string[1]), float(p4_string[2]), float(p4_string[3]), float(p4_string[4])) p4_proton_boost_px = p4_proton.Px() p4_proton_boost_py = p4_proton.Py() p4_proton_boost_pz = p4_proton.Pz() p4_proton_boost_E = sqrt( abs(p4_proton_boost_px**2 + p4_proton_boost_py**2 + p4_proton_boost_pz**2 - 0.938272**2)) p4_proton_boost = TLorentzVector(p4_proton_boost_px, p4_proton_boost_py, p4_proton_boost_pz, p4_proton_boost_E) for value in line.split(): if (verbose and value_in_line == 1): print "Charge: " + value if (verbose and value_in_line == 2): print "Px " + value if (verbose and value_in_line == 3): print "Py " + value if (verbose and value_in_line == 4): print "Pz " + value if (verbose and value_in_line == 5): print "E " + value value_in_line += 1 line5_out = " 1 " + str(p4_proton.Px()) + " " + str( p4_proton.Py()) + " " + str(p4_proton.Pz()) + " " + str( p4_proton.E()) + "\n" my_phi = p4_proton_boost.Phi() + 3.14159 #Opposite proton my_theta = theta_curr * (3.14159 / 180.) gamma_px = str(e_gamma_curr * TMath.Sin(my_theta) * TMath.Cos(my_phi)) gamma_py = str(e_gamma_curr * TMath.Sin(my_theta) * TMath.Sin(my_phi)) gamma_pz = str(e_gamma_curr * TMath.Cos(my_theta)) line2_out = "1 1 0\n" line3_out = " 0 " + gamma_px + " " + gamma_py + " " + gamma_pz + " " + str( e_gamma_curr) + "\n" p4_gam_fcal = TLorentzVector(float(gamma_px), float(gamma_py), float(gamma_pz), e_gamma_curr) # print "Beam photon: " + str( (p4_gam_fcal+p4_proton_boost).E()) with open(fname_out, "a") as myfile: myfile.write(line1_out) myfile.write(line2_out) myfile.write(line3_out) myfile.write(line4_out) myfile.write(line5_out) myfile.write(line6_out) myfile.write(line7_out) myfile.write(line8_out) myfile.write(line9_out) counter += 1 # if(counter>200): break return
G *= Heaviside(4.5 - abs(q2.Eta())) G *= Heaviside(q1.Pt() - 30.0e+3) G *= Heaviside(q2.Pt() - 30.0e+3) if G > 0: # Invariant mass of Z1 and Z2 mll[0] = (l1 + l2).M() mqq[0] = (q1 + q2).M() mZZ[0] = (l1 + l2 + q1 + q2).M() PtZZ[0] = (l1 + l2 + q1 + q2).Pt() Ptll[0] = (l1 + l2).Pt() Ptqq[0] = (q1 + q2).Pt() # Boost to X's static system l_X = TLorentzRotation().Boost(-1. * X.Px() / X.E(), -1. * X.Py() / X.E(), -1. * X.Pz() / X.E()) X = l_X * X Z1 = l_X * Z1 Z2 = l_X * Z2 l1 = l_X * l1 l2 = l_X * l2 q1 = l_X * q1 q2 = l_X * q2 # Boost to Z1's static system l_Z1 = TLorentzRotation().Boost(-1. * Z1.Px() / Z1.E(), -1. * Z1.Py() / Z1.E(), -1. * Z1.Pz() / Z1.E()) Z1_Z1SS = l_Z1 * Z1
tau_lorentz_no_neutrino = TLorentzVector() # firedCount = 0 for index in range(0, tau_features_test.shape[1], 3): lorentz = TLorentzVector() lorentz.SetPtEtaPhiM((tau_features_test[event][index]), (tau_features_test[event][index + 1]), (tau_features_test[event][index + 2]), (0.139)) tau_lorentz_no_neutrino += lorentz print("I fired") #firedCount += 1 tofill['tau_pt_no_neutrino'] = tau_lorentz_no_neutrino.Pt() print("tau_lorentz_neutrino.Px()", tau_lorentz_no_neutrino.Px()) print("tau_lorentz_no_neutrino.Py()", tau_lorentz_no_neutrino.Py()) print("tau_lorentz_no_neutrino.Pz()", tau_lorentz_no_neutrino.Pz()) print("tau_lorentz_no_neutrino.E()", tau_lorentz_no_neutrino.E()) tofill['tau_eta_no_neutrino'] = tau_lorentz_no_neutrino.Eta() tofill['tau_phi_no_neutrino'] = tau_lorentz_no_neutrino.Phi() tofill['tau_mass_no_neutrino'] = tau_lorentz_no_neutrino.M() print("tau_mass_no_neutrino", tau_lorentz_no_neutrino.M()) print("tau_eta_no_neutrino", tau_lorentz_no_neutrino.Eta()) tau_lorentz = TLorentzVector() tau_lorentz.SetPxPyPzE( tau_lorentz_no_neutrino.Px(), tau_lorentz_no_neutrino.Py(), tau_lorentz_no_neutrino.Pz(), tau_lorentz_no_neutrino.E(), ) print("tau_lorentz.Px()", tau_lorentz.Px()) print("tau_lorentz.Py()", tau_lorentz.Py())
def __init__(self, parse, tree, hepmc_attrib): print("Quasi-real configuration:") #electron and proton beam energy, GeV self.Ee = parse.getfloat("main", "Ee") self.Ep = parse.getfloat("main", "Ep") print("Ee =", self.Ee, "GeV") print("Ep =", self.Ep, "GeV") #electron and proton mass self.me = TDatabasePDG.Instance().GetParticle(11).Mass() mp = TDatabasePDG.Instance().GetParticle(2212).Mass() #boost vector pbvec of proton beam pbeam = TLorentzVector() pbeam.SetPxPyPzE(0, 0, TMath.Sqrt(self.Ep**2-mp**2), self.Ep) self.pbvec = pbeam.BoostVector() #electron beam energy Ee_p in proton beam rest frame ebeam = TLorentzVector() ebeam.SetPxPyPzE(0, 0, -TMath.Sqrt(self.Ee**2-self.me**2), self.Ee) ebeam.Boost(-self.pbvec.x(), -self.pbvec.y(), -self.pbvec.z()) # transform to proton beam frame self.Ee_p = ebeam.E() #center-of-mass squared s, GeV^2 self.s = self.get_s(self.Ee, self.Ep) print("s =", self.s, "GeV^2") print("sqrt(s) =", TMath.Sqrt(self.s), "GeV") #range in x xmin = parse.getfloat("main", "xmin") xmax = parse.getfloat("main", "xmax") print("xmin =", xmin) print("xmax =", xmax) #range in u = log_10(x) umin = TMath.Log10(xmin) umax = TMath.Log10(xmax) print("umin =", umin) print("umax =", umax) #range in y ymin = parse.getfloat("main", "ymin") ymax = parse.getfloat("main", "ymax") #range in W wmin = -1. wmax = -1. if parse.has_option("main", "Wmin"): wmin = parse.getfloat("main", "Wmin") print("Wmin =", wmin) if parse.has_option("main", "Wmax"): wmax = parse.getfloat("main", "Wmax") print("Wmax =", wmax) #adjust range in y according to W if wmin > 0 and ymin < wmin**2/self.s: ymin = wmin**2/self.s if wmax > 0 and ymax > wmax**2/self.s: ymax = wmax**2/self.s print("ymin =", ymin) print("ymax =", ymax) #range in v = log_10(y) vmin = TMath.Log10(ymin) vmax = TMath.Log10(ymax) print("vmin =", vmin) print("vmax =", vmax) #range in Q2 self.Q2min = parse.getfloat("main", "Q2min") self.Q2max = parse.getfloat("main", "Q2max") print("Q2min =", self.Q2min) print("Q2max =", self.Q2max) #constant term in the cross section self.const = TMath.Log(10)*TMath.Log(10)*(1./137)/(2.*math.pi) #cross section formula for d^2 sigma / dxdy, Eq. II.6 #transformed as x -> u = log_10(x) and y -> v = log_10(y) self.eq_II6_uv_par = self.eq_II6_uv(self) self.eq = TF2("d2SigDuDvII6", self.eq_II6_uv_par, umin, umax, vmin, vmax) self.eq.SetNpx(1000) self.eq.SetNpy(1000) #uniform generator for azimuthal angles self.rand = TRandom3() self.rand.SetSeed(5572323) #generator event variables in output tree tnam = ["gen_u", "gen_v", "true_x", "true_y", "true_Q2", "true_W2"] tnam += ["true_el_Q2"] tnam += ["true_el_pT", "true_el_theta", "true_el_phi", "true_el_E"] #create the tree variables tcmd = "struct gen_out { Double_t " for i in tnam: tcmd += i + ", " tcmd = tcmd[:-2] + ";};" gROOT.ProcessLine( tcmd ) self.out = rt.gen_out() #put zero to all variables for i in tnam: exec("self.out."+i+"=0") #set the variables in the tree if tree is not None: for i in tnam: tree.Branch(i, addressof(self.out, i), i+"/D") #event attributes for hepmc self.hepmc_attrib = hepmc_attrib #counters for all generated and selected events self.nall = 0 self.nsel = 0 #print generator statistics at the end atexit.register(self.show_stat) #total integrated cross section self.sigma_tot = self.eq.Integral(umin, umax, vmin, vmax) print("Total integrated cross section for a given x and y range:", self.sigma_tot, "mb") print("Quasi-real photoproduction initialized")
def jetdisplay(): outputfile = "Jetdisplay" displayfile = TFile(outputfile+".root","RECREATE") inputfile = "wwlj1k.root" inputfile = TFile(inputfile) print "Analyzing: "+str(inputfile)+" \n" tree = TTree() inputfile.GetObject("B4", tree) graph = TH1F("energyjet", "energyjet", 100, 0., 200.) graph2 = TH1F("energycherjet", "energycherjet", 100, 0., 200.) graph3 = TH1F("energyscinjet", "energyscinjet", 100, 0., 200.) graphmass = TH1F("mass_jet", "mass_jet", 100, 0., 200.) graph4 = TH1F("energy", "energy", 100, 0., 200.) graph5 = TH1F("energycher", "energycher", 100, 0., 200.) graph6 = TH1F("energyscin", "energyscin", 100, 0., 200.) #loop over events for Event in range(tree.GetEntries()): tree.GetEntry(Event) #Set values of the tree PrimaryParticleName = tree.PrimaryParticleName # MC truth: primary particle Geant4 name PrimaryParticleEnergy = tree.PrimaryParticleEnergy EnergyTot = tree.EnergyTot # Total energy deposited in calorimeter Energyem = tree.Energyem # Energy deposited by the em component EnergyScin = tree.EnergyScin # Energy deposited in Scin fibers (not Birk corrected) EnergyCher = tree.EnergyCher # Energy deposited in Cher fibers (not Birk corrected) NofCherenkovDetected = tree.NofCherenkovDetected # Total Cher p.e. detected BarrelR_VectorSignals = tree.VectorSignalsR # Vector of energy deposited in Scin fibers (Birk corrected) BarrelL_VectorSignals = tree.VectorSignalsL # Vector of energy deposited in Scin fibers (Birk corrected) BarrelR_VectorSignalsCher = tree.VectorSignalsCherR # Vector of Cher p.e. detected in Cher fibers BarrelL_VectorSignalsCher = tree.VectorSignalsCherL VectorR = tree.VectorR VectorL = tree.VectorL Calib_BarrelL_VectorSignals = calibration.calibscin(BarrelL_VectorSignals) Calib_BarrelR_VectorSignals = calibration.calibscin(BarrelR_VectorSignals) Calib_BarrelL_VectorSignalsCher = calibration.calibcher(BarrelL_VectorSignalsCher) Calib_BarrelR_VectorSignalsCher = calibration.calibcher(BarrelR_VectorSignalsCher) energy = float(sum(Calib_BarrelR_VectorSignals)+sum(Calib_BarrelL_VectorSignals)) energycher = float(sum(Calib_BarrelR_VectorSignalsCher)+sum(Calib_BarrelL_VectorSignalsCher)) threshold = 0.0 #(GeV) if energy>70.: #event displays with signals (p.e.) #if Event < 1: #displayfile.cd() #ROOTHistograms.create_eventdisplay_scin("Jet", BarrelR_VectorSignals, BarrelL_VectorSignals, "signal"+str(Event)) #ROOTHistograms.create_eventdisplay_cher("Jet", BarrelR_VectorSignalsCher, BarrelL_VectorSignalsCher, "signal"+str(Event)) #event displays with energy (GeV) if Event<10: displayfile.cd() ROOTHistograms.create_eventdisplay_scin("Jet_energy", Calib_BarrelR_VectorSignals, Calib_BarrelL_VectorSignals, "energy"+str(Event), threshold) ROOTHistograms.create_eventdisplay_cher("Jet_energy", Calib_BarrelR_VectorSignalsCher, Calib_BarrelL_VectorSignalsCher, "energy"+str(Event), threshold) inputparticles_scin = [] inputparticles_cher = [] #right part for towerindex in range(75*36): theta, phi, eta = newmap.maptower(towerindex, "right") energy_scin = Calib_BarrelR_VectorSignals[towerindex] pt_scin = energy_scin*np.sin(theta*math.pi/180.) energy_cher = Calib_BarrelR_VectorSignalsCher[towerindex] pt_cher = energy_cher*np.sin(theta*math.pi/180.) towerscin = TLorentzVector() towerscin.SetPtEtaPhiM(pt_scin, eta, phi*math.pi/180., 0.) towercher = TLorentzVector() towercher.SetPtEtaPhiM(pt_cher, eta, phi*math.pi/180., 0.) if energy_scin > threshold: #print "truth towers: "+str(energy_scin)+" "+str(eta)+" "+str(phi) inputparticles_scin.append(fastjet.PseudoJet(towerscin.Px(), towerscin.Py(), towerscin.Pz(), towerscin.E())) inputparticles_cher.append(fastjet.PseudoJet(towercher.Px(), towercher.Py(), towercher.Pz(), towercher.E())) #left part for towerindex in range(75*36): theta, phi, eta = newmap.maptower(towerindex, "left") energy_scin = Calib_BarrelL_VectorSignals[towerindex] pt_scin = energy_scin*np.sin(theta*math.pi/180.) energy_cher = Calib_BarrelL_VectorSignalsCher[towerindex] pt_cher = energy_cher*np.sin(theta*math.pi/180.) towerscin = TLorentzVector() towerscin.SetPtEtaPhiM(pt_scin, eta, phi*math.pi/180., 0.) towercher = TLorentzVector() towercher.SetPtEtaPhiM(pt_cher, eta, phi*math.pi/180., 0.) if energy_scin > threshold: #print "truth towers: "+str(energy_scin)+" "+str(eta)+" "+str(phi) inputparticles_scin.append(fastjet.PseudoJet(towerscin.Px(), towerscin.Py(), towerscin.Pz(), towerscin.E())) inputparticles_cher.append(fastjet.PseudoJet(towercher.Px(), towercher.Py(), towercher.Pz(), towercher.E())) jet_def = fastjet.JetDefinition(fastjet.ee_genkt_algorithm, 2*math.pi, 1.) clust_seq = fastjet.ClusterSequence(inputparticles_scin, jet_def) print "Event: "+str(Event)+" energy (GeV): "+str(energy)+" n-jets: "+str(len(clust_seq.exclusive_jets(int(2))))+" truth: "+str(len(inputparticles_scin)) clust_seq_cher = fastjet.ClusterSequence(inputparticles_cher, jet_def) jet1_scin = fastjet.sorted_by_E(clust_seq.exclusive_jets(int(2)))[0] jet2_scin = fastjet.sorted_by_E(clust_seq.exclusive_jets(int(2)))[1] jet1_cher = fastjet.sorted_by_E(clust_seq_cher.exclusive_jets(int(2)))[0] jet2_cher = fastjet.sorted_by_E(clust_seq_cher.exclusive_jets(int(2)))[1] print "DeltaR jet1_scin: "+str(jet1_scin.delta_R(jet1_cher))+" "+str(jet1_scin.delta_R(jet2_cher)) c = 0.34 #chi factor jet1, jet2 = mergejet(jet1_scin, jet2_scin, jet1_cher, jet2_cher) graph.Fill(jet1.e()+jet2.e()) graph3.Fill(jet1_scin.e()+jet2_scin.e()) graph2.Fill(jet1_cher.e()+jet2_cher.e()) j = jet1+jet2 graphmass.Fill(j.m()) graph4.Fill((energy-c*energycher)/(1.-c)) graph5.Fill(energycher) graph6.Fill(energy) graph.Write() graph2.Write() graph3.Write() graph4.Write() graph5.Write() graph6.Write() graphmass.Write()
gStyle.SetPalette(55) #####Homework 2 Question 1 energy1 = [] energy2 = [] vec1 = TLorentzVector() vec2 = TLorentzVector() lines = [line.rstrip('\n') for line in open('data1')] fig = plt.figure(num=None, figsize=(8, 8), dpi=800, facecolor='w', edgecolor='k') for line in lines: a = np.array(np.loadtxt(StringIO(line))) vec1.SetPxPyPzE(a[1], a[2], a[3], a[0]) vec2.SetPxPyPzE(a[5], a[6], a[7], a[4]) energy1.append(vec1.E()) energy2.append(vec2.E()) plt.hist(energy1, 25, histtype=u'stepfilled', alpha=0.5) plt.xlabel(r'Energy (GeV)') plt.ylabel(r'Counts (#)') plt.title(r'Energy four vector 1') #plt.show() fig.savefig('Problem_1.pdf')
def processCHSJets(self, jets, rho): i = 0 for item in jets: jetp4 = item.P4() self.jetchs_pt[i] = jetp4.Pt() self.jetchs_eta[i] = jetp4.Eta() self.jetchs_phi[i] = jetp4.Phi() self.jetchs_mass[i] = jetp4.M() self.jetchs_idpass[i] = 0 # DUMMY ### JETID: Jet constituents seem to broken!! For now set all Jet ID to True TO BE FIXED ###### # compute jet id by looping over jet constituents if self.debug: print ' new CHS jet: ', item.PT, item.Eta, item.Phi, item.Mass p4tot = ROOT.TLorentzVector(0., 0., 0., 0.) nconst = 0 neutralEmEnergy = 0. chargedEmEnergy = 0. neutralHadEnergy = 0. chargedHadEnergy = 0. for j in xrange(len(item.Constituents)): const = item.Constituents.At(j) p4 = ROOT.TLorentzVector(0., 0., 0., 0.) if isinstance(const, ROOT.ParticleFlowCandidate): p4 = ROOT.ParticleFlowCandidate(const).P4() nconst += 1 if self.debug: print ' PFCandidate: ', const.PID, p4.Pt( ), p4.Eta(), p4.Phi(), p4.M() p4tot += p4 if const.Charge == 0: if const.PID == 22: neutralEmEnergy += const.E if const.PID == 0: neutralHadEnergy += const.E else: if abs(const.PID) == 11: chargedEmEnergy += const.E elif abs(const.PID) != 13: chargedHadEnergy += const.E corr = TLorentzVector() for r in rho: if item.Eta > r.Edges[0] and item.Eta < r.Edges[1]: corr = item.Area * r.Rho neutralEmEnergy -= corr.E() EmEnergy = neutralEmEnergy + chargedEmEnergy #neutralHadEnergy -= corr.E() HadEnergy = neutralHadEnergy + chargedHadEnergy if EmEnergy > 0.: neutralEmEF = neutralEmEnergy / EmEnergy else: neutralEmEF = 0. if HadEnergy > 0.: neutralHadEF = neutralHadEnergy / HadEnergy else: neutralHadEF = 0. if self.debug: print ' -> Nconst: ', nconst if self.debug: print ' -> Nconst: ', nconst sumpTcorr = p4tot - corr if self.debug: print ' jet const sum uncorr. : ', p4tot.Pt(), p4tot.Eta( ), p4tot.Phi(), p4tot.M() if self.debug: print ' jet const sum corr. : ', sumpTcorr.Pt( ), sumpTcorr.Eta(), sumpTcorr.Phi(), sumpTcorr.M() if self.debug: print ' jet : ', jetp4.Pt(), jetp4.Eta( ), jetp4.Phi(), jetp4.M() # compute jet Id (0: LOOSE, 1: MEDIUM, 2: TIGHT) if nconst > 1 and neutralEmEF < 0.99 and neutralHadEF < 0.99: self.jetchs_idpass[i] |= 1 << 0 if nconst > 1 and neutralEmEF < 0.99 and neutralHadEF < 0.99: self.jetchs_idpass[i] |= 1 << 1 if nconst > 1 and neutralEmEF < 0.90 and neutralHadEF < 0.90: self.jetchs_idpass[i] |= 1 << 2 i += 1 self.jetchs_size[0] = i