def getLorentzVector(self, mom): p = TLorentzVector(0, 0, 0, me) p.SetPx(float(mom[0])) p.SetPy(float(mom[1])) p.SetPz(float(mom[2])) p.SetE(float(self.pMag(mom))) # p.Print() return p
def getFourMomentum(mcParticle): p = TLorentzVector(0, 0, 0, me) p.SetPx(float(mcParticle[6])) p.SetPy(float(mcParticle[7])) p.SetPz(float(mcParticle[8])) p.SetE(float(mcParticle[9])) # p.Print() return p
def rotateFourMomentum(self, pFour, rotMatrix): pArray = [pFour.X(), pFour.Y(), pFour.Z()] pRot = np.dot(rotMatrix, np.asarray(pArray)) p = TLorentzVector(0, 0, 0, me) p.SetPx(float(pRot[0])) p.SetPy(float(pRot[1])) p.SetPz(float(pRot[2])) p.SetE(float(pFour.E())) return p
def Transform(Px, Py, Pz, E): N = Px.shape[0] Pt = np.zeros(N) Eta = np.zeros(N) Phi = np.zeros(N) M = np.zeros(N) LV = TLorentzVector() print('\tStarting Transformation') for i in range(0, N): sys.stdout.write('\r') sys.stdout.write('\tCurrent process : %0.2f%%' % (i % N / N * 100)) sys.stdout.flush() LV.SetPx(Px[i]) LV.SetPy(Py[i]) LV.SetPz(Pz[i]) LV.SetE(E[i]) Pt[i] = LV.Pt() Eta[i] = LV.Eta() Phi[i] = LV.Phi() M[i] = LV.M() print() return Pt, Eta, Phi, M
q1 = TLorentzVector(0., 0., 0., 0.) q2 = TLorentzVector(0., 0., 0., 0.) isMuon = False qcount = 0 for i in range(len(e['particles'])): # Check if final state if e['particles'][i]['status'] == 1: pdgid = e['particles'][i]['id'] Px = e['particles'][i]['px'] Py = e['particles'][i]['py'] Pz = e['particles'][i]['pz'] E = e['particles'][i]['e'] if pdgid == -13 or pdgid == -11: l1.SetPx(Px) l1.SetPy(Py) l1.SetPz(Pz) l1.SetE(E) if pdgid == -11: isMuon = False else: isMuon = True elif pdgid == 13 or pdgid == 11: l2.SetPx(Px) l2.SetPy(Py) l2.SetPz(Pz) l2.SetE(E) elif (pdgid == 21 or abs(pdgid) < 7) and qcount == 0: q1.SetPx(Px) q1.SetPy(Py) q1.SetPz(Pz) q1.SetE(E)
X = TLorentzVector(0., 0., 0., 0.) Z1 = TLorentzVector(0., 0., 0., 0.) Z2 = TLorentzVector(0., 0., 0., 0.) l1 = TLorentzVector(0., 0., 0., 0.) l2 = TLorentzVector(0., 0., 0., 0.) q1 = TLorentzVector(0., 0., 0., 0.) q2 = TLorentzVector(0., 0., 0., 0.) ID1 = 0 ID2 = 0 isMuon = False bosonCount = 0 for i in range(len(e['particles'])): if e['particles'][i]['id'] == -13 or e['particles'][i]['id'] == -11: l1.SetPx(e['particles'][i]['px']) l1.SetPy(e['particles'][i]['py']) l1.SetPz(e['particles'][i]['pz']) l1.SetE(e['particles'][i]['e']) ID1 = int(e['particles'][i]['mother1'] - 1) if e['particles'][i]['id'] == -11: isMuon = False else: isMuon = True elif e['particles'][i]['id'] == 13 or e['particles'][i]['id'] == 11: l2.SetPx(e['particles'][i]['px']) l2.SetPy(e['particles'][i]['py']) l2.SetPz(e['particles'][i]['pz']) l2.SetE(e['particles'][i]['e']) elif abs(e['particles'][i] ['id']) < 7 and e['particles'][i]['id'] < 0: q1.SetPx(e['particles'][i]['px']) q1.SetPy(e['particles'][i]['py'])
hhiggssdmass.Fill(ak8jet_sdmass[j], evtwt) if nHiggs < 1: continue #if nhiggsmatched < 1: continue ncut += 1 hCutflow.Fill(ncut, evtwt) #------------------------------------------------------------------------ # MASS RECONSTRUCTION #------------------------------------------------------------------------ # Finding Pz for Neutrino nuP4 = TLorentzVector(0.0, 0.0, 0.0, 0.0) nuP4.SetPx(met_px) nuP4.SetPy(met_py) nuP4.SetPz(met_pz) sol1 = 0.0 sol2 = 0.0 isNuPz, sol1, sol2 = SolveNuPz(primarylep, nuP4, 80.4, sol1, sol2) if abs(sol1) < abs(sol2): nuP4.SetPz(sol1) else: nuP4.SetPz(sol2) nuP4 = AdjustEnergyForMass(nuP4, 0.0) # Initialize topMass = 174.0 higgsMass = 125.0 chi2_dR_boost1 = 0.0 chi2_dR_boost2 = 0.0
def process(self, event): #survival variable is for an artififcal cut flow because the real selection is done in the ROOT macro survival = 'dead' self.counters['cut_flow'].inc('All events') det = getattr(event, self.cfg_ana.det) if det == 1: print 'no Solution for scaling factor!' return False jets = getattr(event, self.cfg_ana.input_jets) if len(jets) == 2: self.counters['cut_flow'].inc('2 jets') #bjets are actually all jets bjets = [jet for jet in jets] realbjets = [jet for jet in jets if jet.tags['bmatch']] #assuming 100% b-tag efficiency if len(realbjets) == 2: self.counters['cut_flow'].inc('2 b jets') survival = 'alive' elif len(realbjets) == 1: self.counters['cut_flow'].inc('1 b jet') #emratio returns the energy ration (electromagnetic E/total E) of the jet in which it is the greatest emratio = [] for i in range(2): emratio.append(bjets[i].constituents[22].e() / bjets[i].e()) setattr(event, self.cfg_ana.emratio, max(emratio)) #Total visible mass###################################### pvis = bjets[0].p4() + bjets[1].p4() mvis = pvis.M() setattr(event, self.cfg_ana.mvis, mvis) if mvis < 10 or mvis > 180: survival = 'dead' elif survival == 'alive': self.counters['cut_flow'].inc('mvis between 10 and 180') #missing mass############################################ misenergy = getattr(event, self.cfg_ana.misenergy) if misenergy.m() > 125 or misenergy.m() < 65: survival = 'dead' elif survival == 'alive': self.counters['cut_flow'].inc('m_miss between 65 and 125') #transversal momentum########################################### #cross check: succeeded # print 'compare ', bjets[0].pt(),' to ',math.sqrt(bjets[0].p3().Px()**2+bjets[0].p3().Py()**2) pTges = 0 lix = [] liy = [] for jet in bjets: lix.append(jet.p3().Px()) liy.append(jet.p3().Py()) xve = lix[0] + lix[1] yve = liy[0] + liy[1] pTges = math.sqrt(xve**2 + yve**2) setattr(event, self.cfg_ana.pTges, pTges) if pTges <= 15.: survival = 'dead' elif survival == 'alive': self.counters['cut_flow'].inc('Trans momentum > 15 GeV') #cross check: succeeded # pTtest=math.sqrt((bjets[0].p3().Px()+bjets[1].p3().Px())**2+(bjets[0].p3().Py()+bjets[1].p3().Py())**2) # print 'compare ',pTtest,' to ', pTges #longitudinal moementum############################################ pLges = 0 liz = [] for jet in bjets: liz.append(jet.p3().Pz()) pLges = abs(liz[0] + liz[1]) setattr(event, self.cfg_ana.pLges, abs(pLges)) if abs(pLges) >= 50.: survival = 'dead' elif survival == 'alive': self.counters['cut_flow'].inc('Long momentum < 50 GeV') #cross check: succeeded # pLtest=math.sqrt((bjets[0].p3().Pz()+bjets[1].p3().Pz())**2) # print 'compare ',pLtest,' to ',pLges #alpha: angle between the 2 jets############################################ # skalarp is the scalar product of bjet_1 and bjet_2; skalarpa(b) is the product of bjet_1(bjet_2) # with itself skalarp = bjets[1].p3().Px() * bjets[0].p3().Px() + bjets[0].p3().Py( ) * bjets[1].p3().Py() + bjets[0].p3().Pz() * bjets[1].p3().Pz() skalarpa = bjets[0].p3().Px() * bjets[0].p3().Px() + bjets[0].p3().Py( ) * bjets[0].p3().Py() + bjets[0].p3().Pz() * bjets[0].p3().Pz() skalarpb = bjets[1].p3().Px() * bjets[1].p3().Px() + bjets[1].p3().Py( ) * bjets[1].p3().Py() + bjets[1].p3().Pz() * bjets[1].p3().Pz() # print bjets[0].scalarp(bjets[0]) cosa = skalarp / (math.sqrt(skalarpa) * math.sqrt(skalarpb)) # alpha is the angle between the two jets in degrees try: alpha = 360 * math.acos(cosa) / (2 * math.pi) except ValueError: #Very Rare...something like 1 of 100000 events in qqbar #This ValueError is very weird and must come from some roudning problems in python. It happens very rarely. The particles are exactly back to back so cosa is -1 but the way cosa is calc it becomes just slightly smaller than -1 and math.acos(cosa) returns ValueError. Instead of returning False its prob better to set alpha to 180. But gonna check this in more detail print "#################ValueError#################" print "cosa= ", cosa #this prints 1 or -1 print "skalarp= ", skalarp print "skalarpa=", skalarpa print "skalarpb=", skalarpb return False setattr(event, self.cfg_ana.alpha, alpha) if alpha < 100: survival = 'dead' elif survival == 'alive': self.counters['cut_flow'].inc('Angle between jets > 100 degrees') #cross variable ################################################################ # normal vector of the plane between the two vectors i.e. cross product normvec = TLorentzVector(0, 0, 0, 0) normvec.SetPx(bjets[0].p3().Py() * bjets[1].p3().Pz() - bjets[0].p3().Pz() * bjets[1].p3().Py()) normvec.SetPy(bjets[0].p3().Pz() * bjets[1].p3().Px() - bjets[0].p3().Px() * bjets[1].p3().Pz()) normvec.SetPz(bjets[0].p3().Px() * bjets[1].p3().Py() - bjets[0].p3().Py() * bjets[1].p3().Px()) cross = abs(normvec.Pz() / (math.sqrt(skalarpa * skalarpb))) cross = math.asin(cross) * 180. / math.pi setattr(event, self.cfg_ana.cross, cross) #cross check for cross variable (Patricks code): succeeded # p1=TVector3(bjets[0].p3().Px(),bjets[0].p3().Py(),bjets[0].p3().Pz()) # p2=TVector3(bjets[1].p3().Px(),bjets[1].p3().Py(),bjets[1].p3().Pz()) # cross2=p1.Unit().Cross(p2.Unit()) # cross2=abs(cross2.Unit().z()) # cross2=math.asin(cross2)*180./math.pi #cross check: succeeded # print 'compare: ',bjets[0].norm(), 'to : ',math.sqrt(bjets[0].scalarp(bjets[0])) # cross check: succeeded # print abs(normvec.Pz()),'-----',abs((bjets[0].cross(bjets[1])).Pz()) # beta is the angle between the plane of the two jets and the beamaxis #ZeroDivisonError if math.sqrt(normvec.Px()**2 + normvec.Py()**2 + normvec.Pz()**2) == 0: print "##########normvec has norm of 0!!!#########" #A very rare case...about 1 in 1000000 qqbar events #reason is the angle between the 2 jets is 0 print "Px= ", normvec.Px() print "Py= ", normvec.Py() print "Pz= ", normvec.Pz() print "jet energies= ", bjets[0].e(), "_,", bjets[1].e() print "angle betwee nthe jets= ", alpha #this returns 0 return False cosb = normvec.Pz() / (math.sqrt(normvec.Px()**2 + normvec.Py()**2 + normvec.Pz()**2)) beta = 360 * math.acos(cosb) / (2 * math.pi) beta1 = 180 - beta #cross check Colins acoplanarity code: succeeded # j1=bjets[0].p3() # j2=bjets[1].p3() # axis=TVector3(0,0,1) # normal = j1.Cross(j2).Unit() # angle=normal.Angle(axis)-math.pi/2. # print angle,angle*180./math.pi,90-min(beta,beta1),cross2 # cross check: succeeded # sintest=abs(normvec.Pz())/(math.sqrt(normvec.Px()**2+normvec.Py()**2+normvec.Pz()**2)) # betatest=360*math.asin(sintest)/(2*math.pi) # print 'compare ',betatest, ' to ',90-min(beta,beta1) setattr(event, self.cfg_ana.beta, 90 - min(beta, beta1)) if cross < 10: survival = 'dead' elif survival == 'alive': self.counters['cut_flow'].inc('cross > 10') if survival == 'alive': self.counters['cut_flow'].inc('Total # of events after cuts') setattr(event, self.cfg_ana.cutlife, survival) #cross check:succeeded # ptcs = getattr(event, self.cfg_ana.particles) # pvis = TLorentzVector(0,0,0,0) # for ptc in ptcs: # pvis+=ptc.p4() # print pvis.M() # print mvis #Total number of charged tracks nchargedtracks = bjets[0].constituents[211].num( ) + bjets[1].constituents[211].num() setattr(event, self.cfg_ana.ctracks, nchargedtracks)