Exemple #1
0
def findMatch_pfc_old(lepton, pfcands):

    drmin = 10
    idx = -1

    if lepton.pt() > 0:

        leptonTlv = TLorentzVector()
        leptonTlv.SetPxPyPzE(lepton.px(), lepton.py(), lepton.pz(),
                             lepton.energy())

        for ipfc, pfc in enumerate(pfcands):

            if pfc.trackRef().isNull(): continue
            if pfc.trackRef().get().numberOfValidHits() == 0: continue
            if pfc.trackRef().get().ndof() == 0: continue
            if pfc.trackRef().get().charge() == 0: continue

            #			if not passesPreselection_basic_pfc(pfc): continue

            if not pfc.charge() * lepton.charge() > 0: continue

            #			if not abs(pfc.pt() - lepton.pt()) / lepton.pt() < 0.2: continue

            pfcTlv = TLorentzVector()
            pfcTlv.SetPxPyPzE(pfc.px(), pfc.py(), pfc.pz(), pfc.energy())

            dr = pfcTlv.DeltaR(leptonTlv)

            if dr < drmin:

                drmin = dr
                idx = ipfc

    return idx, drmin
Exemple #2
0
def ObtainAbb(mc_px, mc_py, mc_pz, mc_en, mc_id, mc_momidx):
  n = len(mc_px)
  genaobj = collections.namedtuple('GenAObj', 'aLVec aIdx')
  genbobj = collections.namedtuple('GenBObj', 'bLVec bMomId bMomIdx')
  lgenaobj = []
  lgenbobj = []
  for imc in range( 0, n):
    if abs(mc_id[imc]) == 5:
      thislb = TLorentzVector()
      thislb.SetPxPyPzE( mc_px[imc], mc_py[imc], mc_pz[imc], mc_en[imc] )
      lgenbobj.append( genbobj( bLVec = thislb, bMomId = mc_id[mc_momidx[imc]], bMomIdx = mc_momidx[imc] ) )
    if mc_id[imc] == 36:
      thisla = TLorentzVector()
      thisla.SetPxPyPzE( mc_px[imc], mc_py[imc], mc_pz[imc], mc_en[imc] )
      lgenaobj.append( genaobj( aLVec = thisla, aIdx = imc ) )
  
  lAbb = []
  for aobj in lgenaobj:
    this = Abb()
    this.a = aobj.aLVec
    for bobj in lgenbobj:
      if aobj.aIdx == bobj.bMomIdx and bobj.bMomId == 36:
        this.lb.append( bobj.bLVec )
    lAbb.append(this)
  return lAbb
Exemple #3
0
def METGL2(neutralinos, charginos, neutrinos, MET):  # neutrinos,
    #Define TLorentzVector for neutralinos and charginos
    met_n = TLorentzVector()
    met_c = TLorentzVector()
    met_nt = TLorentzVector()

    MET_nX = 0
    MET_nY = 0
    for n in neutralinos:
        MET_nX = MET_nX + n.P4().Px()
        MET_nY = MET_nY + n.P4().Py()
    met_n.SetPxPyPzE(MET_nX, MET_nY, 0, 0)

    MET_cX = 0
    MET_cY = 0
    for c in charginos:
        MET_cX = MET_cX + c.P4().Px()
        MET_cY = MET_cY + c.P4().Py()
    met_c.SetPxPyPzE(MET_cX, MET_cY, 0, 0)

    MET_ntX = 0
    MET_ntY = 0
    for nt in neutrinos:
        MET_ntX = MET_ntX + nt.P4().Px()
        MET_ntY = MET_ntY + nt.P4().Py()
    met_nt.SetPxPyPzE(MET_ntX, MET_ntY, 0, 0)

    ## Sum of the vector components
    met_gl = met_n + met_c + met_nt

    for m in MET:
        m.MET = abs(met_gl.Mag())
        m.Phi = met_gl.Phi()
    return MET
Exemple #4
0
    def IsMuonsGhosts(self, entry_number, entry, all_muons):
        """
		Check muons angle to see if not ghost particule

		Returns:
			Bool --
		"""

        muP = TLorentzVector()
        muM = TLorentzVector()
        muP.SetPxPyPzE(getattr(entry, self.dimuon_leafs[0] + '_PX'),
                       getattr(entry, self.dimuon_leafs[0] + '_PY'),
                       getattr(entry, self.dimuon_leafs[0] + '_PZ'),
                       getattr(entry, self.dimuon_leafs[0] + '_PE'))
        muM.SetPxPyPzE(getattr(entry, self.dimuon_leafs[1] + '_PX'),
                       getattr(entry, self.dimuon_leafs[1] + '_PY'),
                       getattr(entry, self.dimuon_leafs[1] + '_PZ'),
                       getattr(entry, self.dimuon_leafs[1] + '_PE'))

        if entry_number == 1:
            all_muons.append([muP, muM])
            return False
        else:

            for cand in all_muons:
                deltaThetaMuM = cand[0].Angle(muP.Vect())
                deltaThetaMuM = cand[1].Angle(muM.Vect())

                if deltaThetaMuM > 0.9999 and deltaThetaMuM > 0.9999:
                    return True
        all_muons.append([muP, muM])
        return False
Exemple #5
0
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
Exemple #6
0
def findMatch_track_old_random(lepton, tracks):

    drmin = 10
    idx = -1

    if lepton.pt() > 0:

        leptonTlv = TLorentzVector()
        leptonTlv.SetPxPyPzE(lepton.px(), lepton.py(), lepton.pz(),
                             lepton.energy())

        for itrack, track in enumerate(tracks):

            if track.numberOfValidHits() == 0: continue
            if track.ndof() == 0: continue
            if track.charge() == 0: continue

            #			if not passesPreselection_basic_track(track): continue

            if not track.charge() * lepton.charge() < 0: continue

            #			if not abs(track.pt() - lepton.pt()) / lepton.pt() < 0.2: continue

            trackTlv = TLorentzVector()
            trackTlv.SetPxPyPzE(track.px(), track.py(), track.pz(),
                                track.pt() * TMath.CosH(track.eta()))

            dr = trackTlv.DeltaR(leptonTlv)

            if dr < drmin:

                drmin = dr
                idx = itrack

    return idx, drmin
Exemple #7
0
def selection(event):
    vect = TLorentzVector()
    vect.SetPxPyPzE(event.GenJet[0], event.GenJet[1], event.GenJet[2],
                    event.GenJet[3])
    if abs(vect.Eta()) > 0.5 or vect.Pt() < 50 or vect.Pt() > 70:
        return False
    vect.SetPxPyPzE(event.Jet[0], event.Jet[1], event.Jet[2], event.Jet[3])
    if abs(vect.Eta()) > 0.5 or vect.Pt() < 50:
        return False
    else:
        return True
Exemple #8
0
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
Exemple #9
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
Exemple #10
0
def get_incoming_partons(ZZjj_p4):

    com_energy_half = ZZjj_p4.M() / 2.
    parton_1 = TLorentzVector()
    parton_1.SetPxPyPzE(0, 0, com_energy_half, com_energy_half)
    parton_2 = TLorentzVector()
    parton_2.SetPxPyPzE(0, 0, -com_energy_half, com_energy_half)

    boost = ZZjj_p4.BoostVector()

    parton_1.Boost(boost)
    parton_2.Boost(boost)

    return [p4_to_MG_vector(parton_1), p4_to_MG_vector(parton_2)]
Exemple #11
0
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
Exemple #12
0
def invariantMass(electron1, electron2):

    electronTlv1 = TLorentzVector()

    electronTlv2 = TLorentzVector()

    electronTlv1.SetPxPyPzE(electron1.px(), electron1.py(), electron1.pz(),
                            electron1.energy())

    electronTlv2.SetPxPyPzE(electron2.px(), electron2.py(), electron2.pz(),
                            electron2.energy())

    invMass = (electronTlv1 + electronTlv2).M()

    return invMass
Exemple #13
0
def wreco(lepp4, metpt, metphi):
    nu4 = TLorentzVector()
    px = metpt * cos(metphi)
    py = metpt * sin(metphi)
    pz = 0.
    pxl = lepp4.Px()
    pyl = lepp4.Py()
    pzl = lepp4.Pz()
    El = lepp4.E()
    a = MW_ * MW_ + 2. * pxl * px + 2. * pyl * py
    A = 4. * (El * El - pzl * pzl)
    B = -4. * a * pzl
    C = 4. * El * El * (px * px + py * py) - a * a
    tmproot = B * B - 4. * A * C

    if tmproot < 0:
        pz = -1. * B / (2 * A)
    else:
        tmpsol1 = (-B + math.sqrt(tmproot)) / (2.0 * A)
        tmpsol2 = (-B - math.sqrt(tmproot)) / (2.0 * A)
        if abs(tmpsol2 - pzl) < abs(tmpsol1 - pzl):
            pz = tmpsol2
        else:
            pz = tmpsol1
    if abs(pz) > 300:
        if abs(tmpsol1) < abs(tmpsol2):
            pz = tmpsol1
        else:
            pz = tmpsol2
    nu4.SetPxPyPzE(px, py, pz, math.sqrt(px * px + py * py + pz * pz))
    wp4 = lepp4 + nu4
    return wp4
Exemple #14
0
def toLV(track):
    lv = TLorentzVector()
    lv.SetPxPyPzE(track.px() * 1000,
                  track.py() * 1000,
                  track.pz() * 1000,
                  track.e() * 1000)  ## in MeV!
    return lv
Exemple #15
0
def GetEtaPhi(px, py, pz, en):
  l = TLorentzVector()
  l.SetPxPyPzE(px,py,pz,en)
  #print( "sizeof4Floats: %d, sizeofTL: %d" % ( 4*sys.getsizeof(e), sys.getsizeof(l) ) )
  eta = l.Eta()
  phi = l.Phi()
  return eta, phi
def makeseed(cluster1,cluster2,i1,i2,particles):
   p = TLorentzVector()
   r1 = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
   r2 = [ROOT.Double(), ROOT.Double(), ROOT.Double()]
   cluster1.GetPoint(i1,r1[0],r1[1],r1[2])
   cluster2.GetPoint(i2,r2[0],r2[1],r2[2])
   
   x0 = 0
   z0 = zofx(r1,r2,x0)
   xExit = xofz(r1,r2,zDipoleExit)*cm2m
   q = 1 if(particles=="electrons") else -1
   H = (zDipoleExit-z0)*cm2m
   R = H*(LB)/xExit + xExit ## look this up in my sides
   P = 0.3*B*R
   
   v1 = TVector2(r1[2],r1[1])
   v2 = TVector2(r2[2],r2[1])
   u = rUnit2(v2,v1)
   uz = u.X()
   uy = u.Y()
   px = 0
   py = P*uy
   pz = P*uz
   p.SetPxPyPzE(px,py,pz,math.sqrt(P*P+me2))
   
   return p
def makeTL(tree, index):
    particleFourVector = TLorentzVector()
    # Define TLorentz Vector
    particleFourVector.SetPxPyPzE(tree.mcPx[index], tree.mcPy[index],
                                  tree.mcPz[index], tree.mcE[index])
    # particleFourVector.SetPtEtaPhiE(tree.mcPt[index], tree.mcEta[index],
    #                     tree.mcPhi[index],tree.mcE[index])
    return particleFourVector
Exemple #18
0
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())
Exemple #19
0
def pointingAngle(track1, track2, pv_pos, sv_pos):

    trk1Tlv = TLorentzVector()
    trk1Tlv.SetPxPyPzE(track1.px(), track1.py(), track1.pz(),
                       track1.pt() * np.cosh(track1.eta()))
    trk2Tlv = TLorentzVector()
    trk2Tlv.SetPxPyPzE(track2.px(), track2.py(), track2.pz(),
                       track2.pt() * np.cosh(track2.eta()))
    combinedMomentum = trk2Tlv - trk1Tlv

    PVtoSV = [
        sv_pos[0] - pv_pos.x(), sv_pos[1] - pv_pos.y(), sv_pos[2] - pv_pos.z()
    ]

    pointingAngle = np.arctan2(PVtoSV[0] - combinedMomentum.X(),
                               PVtoSV[1] - combinedMomentum.Y())

    return pointingAngle
Exemple #20
0
def calculateFinalStateMomenta_GOLD(mB0, m23, mMuMu, cosTheta1, cosTheta2, phi,
                                    mMuPlus, mMuMinus, mPi, mK, pion_ID):
    if (pion_ID > 0):  # anti-B0
        if (phi > 0): phi = pi - phi
        else: phi = -pi - phi
        cosTheta1 = -cosTheta1

    pJpsi = daughterMomentum(mB0, mMuMu, m23)
    p4Jpsi = TLorentzVector(0, 0, +pJpsi, sqrt(mMuMu * mMuMu + pJpsi * pJpsi))
    p4Kpi = TLorentzVector(0, 0, -pJpsi, sqrt(m23 * m23 + pJpsi * pJpsi))
    pB = TLorentzVector(0, 0, 0, mB0)

    # 4-momenta of muons, first in dimuon rest frame which are then boosted
    # using p4Jpsi to B0 rest frame
    pMu = daughterMomentum(mMuMu, mMuPlus, mMuMinus)

    pMuPlus = TLorentzVector()
    pMuMinus = TLorentzVector()
    pPi = TLorentzVector()
    pK = TLorentzVector()

    pMuPlus.SetPxPyPzE(pMu * sqrt(1 - cosTheta1 * cosTheta1), 0,
                       pMu * cosTheta1, sqrt(mMuPlus * mMuPlus + pMu * pMu))

    pMuMinus.SetPxPyPzE(-pMu * sqrt(1 - cosTheta1 * cosTheta1),
                        0, -pMu * cosTheta1,
                        sqrt(mMuMinus * mMuMinus + pMu * pMu))

    pMuPlus.Boost(p4Jpsi.BoostVector())
    pMuMinus.Boost(p4Jpsi.BoostVector())

    # Now kaon and pion to finish
    ppK = daughterMomentum(m23, mK, mPi)
    pz = ppK * cosTheta2
    pT = ppK * sqrt(1 - cosTheta2 * cosTheta2)
    py = -pT * sin(phi)
    px = -pT * cos(phi)

    pK.SetPxPyPzE(px, -py, -pz, sqrt(mK * mK + ppK * ppK))
    pPi.SetPxPyPzE(-px, py, pz, sqrt(mPi * mPi + ppK * ppK))
    pK.Boost(p4Kpi.BoostVector())
    pPi.Boost(p4Kpi.BoostVector())
    return pMuPlus, pMuMinus, pPi, pK
Exemple #21
0
def mcjetmatch(lmc, jet_px, jet_py, jet_pz, jet_en, drmax):
  #lmc = TLorentzVector()
  #lmc.SetPxPyPzE( amc_px, amc_py, amc_pz, amc_en )
  aeta = lmc.Eta()
  aphi = lmc.Phi()
  n = len(jet_px)
  for ijet in range(0, n):
    ljet = TLorentzVector()
    ljet.SetPxPyPzE( jet_px[ijet], jet_py[ijet], jet_pz[ijet], jet_en[ijet] )
    if DeltaR( aeta, aphi, ljet.Eta(), ljet.Phi() ) < drmax:
      return True
  return False
Exemple #22
0
def fourmomentum(gen):
    """Returns the four-momentum representation of a particle."""
    Px = gen.pt() * math.cos(gen.phi())
    Py = gen.pt() * math.sin(gen.phi())
    Pz = gen.pt() * math.sinh(gen.eta())
    M = gen.mass()
    c = 1
    P = math.sqrt(Px**2 + Py**2 + Pz**2)
    E = math.sqrt(P**2 * c**2 + M**2 * c**4)
    pVec = TLorentzVector()
    pVec.SetPxPyPzE(Px, Py, Pz, E)
    return pVec
Exemple #23
0
def findMinDr_track(aTrack, tracks, threshold):

    drmin = 10
    idx = -1
    matchingTrack = None
    match = False

    if aTrack.pt() > 0:

        for itrack, track in enumerate(tracks):

            if not passesPreselection_basic_track(track): continue

            if not track.charge() * aTrack.charge() > 0: continue

            if not abs(track.pt() - aTrack.pt()) / aTrack.pt() < 0.2: continue

            if not abs(track.eta() - aTrack.eta()) < 0.1: continue

            if not abs(deltaPhi(track.phi(), aTrack.phi())) < 1.57: continue

            aTrackTlv = TLorentzVector()
            aTrackTlv.SetPxPyPzE(aTrack.px(), aTrack.py(), aTrack.pz(),
                                 aTrack.pt() * np.cosh(aTrack.eta()))
            trkTlv = TLorentzVector()
            trkTlv.SetPxPyPzE(track.px(), track.py(), track.pz(),
                              track.pt() * np.cosh(track.eta()))

            dr = trkTlv.DeltaR(aTrackTlv)

            if dr < drmin:

                drmin = dr
                idx = itrack
                matchingTrack = track

    if drmin < threshold: match = True
    return match, idx, drmin, matchingTrack
Exemple #24
0
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 IsMuonsGhosts(self, entry_number, entry, prev_muons):
        """
		Check if muon angls between current candidate
		and previous one are not too close

		Returns:
			Bool
		"""

        mu1 = TLorentzVector()
        mu2 = TLorentzVector()
        mu1.SetPxPyPzE(getattr(entry, self.daughter_leafs[0] + '_PX'),
                       getattr(entry, self.daughter_leafs[0] + '_PY'),
                       getattr(entry, self.daughter_leafs[0] + '_PZ'),
                       getattr(entry, self.daughter_leafs[0] + '_PE'))
        mu2.SetPxPyPzE(getattr(entry, self.daughter_leafs[1] + '_PX'),
                       getattr(entry, self.daughter_leafs[1] + '_PY'),
                       getattr(entry, self.daughter_leafs[1] + '_PZ'),
                       getattr(entry, self.daughter_leafs[1] + '_PE'))

        if entry_number == 1:
            prev_muons.append(mu1)
            prev_muons.append(mu2)
            return False
        else:

            deltaThetaMu1 = prev_muons[0].Angle(mu1.Vect())
            deltaThetaMu2 = prev_muons[1].Angle(mu2.Vect())

            if deltaThetaMu1 > 0.9999 and deltaThetaMu2 > 0.9999:
                prev_muons[0] = mu1
                prev_muons[1] = mu2
                return True

        prev_muons[0] = mu1
        prev_muons[1] = mu2
        return False
Exemple #26
0
def OffMissingET(jets, electrons, muons, MET):
    """ Calculate the MissingET from jets, electrons and muons """
    #Define TLorentzVector for jets, electrons and muons
    met_j = TLorentzVector()
    met_e = TLorentzVector()
    met_mu = TLorentzVector()

    ## The x and y components must be with (-1)
    MET_jX = 0
    MET_jY = 0
    for j in jets:
        MET_jX = j.P4().Px() + MET_jX
        MET_jY = j.P4().Py() + MET_jY
    met_j.SetPxPyPzE(-MET_jX, -MET_jY, 0, 0)

    MET_eX = 0
    MET_eY = 0
    for e in electrons:
        MET_eX = e.P4().Px() + MET_eX
        MET_eY = e.P4().Py() + MET_eY
    met_e.SetPxPyPzE(-MET_eX, -MET_eY, 0, 0)

    MET_mX = 0
    MET_mY = 0
    for m in muons:
        MET_mX = m.P4().Px() + MET_mX
        MET_mY = m.P4().Py() + MET_mY
    met_mu.SetPxPyPzE(-MET_mX, -MET_mY, 0, 0)

    ##sum of the vector components
    offmet = met_j + met_e + met_mu

    for m in MET:
        m.MET = abs(offmet.Mag())
        m.Phi = offmet.Phi()
    return MET
Exemple #27
0
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])
Exemple #28
0
def cosThetaBoost(pa, ida, pb, idb, doflip=False):
   #  http://xrootd.slac.stanford.edu/BFROOT/www/doc/workbook_backup_010108/analysis/analysis.html
   #  A useful quantity in many analyses is the helicity angle.
   #  In the reaction Y . X . a + b, the helicity angle of
   #  particle a is the angle measured in the rest frame of the
   #  deidaying parent particle, X, between the direction of the
   #  deiday daughter a and the direction of the grandparent particle Y.
   pTmp = pa+pb;                     # this is the mumu system (Z) 4vector
   ZboostVector = pTmp.BoostVector() # this is the 3vector of the Z
   p = TLorentzVector(0,0,-1,1)      # this is the muon 4vector
   if  (ida>0): p.SetPxPyPzE(pa.Px(),pa.Py(),pa.Pz(),pa.E())
   else:        p.SetPxPyPzE(pb.Px(),pb.Py(),pb.Pz(),pb.E())
   p.Boost(-ZboostVector) # boost p to the Ditop CM (rest) frame
   cosThetaB = p.Vect()*pTmp.Vect()/(p.P()*pTmp.P())
   if(ySystem(pa,pb)<0. and doflip): cosThetaB *= -1. # reclassify ???
   return cosThetaB
Exemple #29
0
def position_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]) as it:
        for pi, pj, pk, el, x, y, z in it:
            l.SetPxPyPzE(pi, pj, pk, el)
            #p = math.hypot(pi,pj)
            #p = math.hypot(pk,p)
            bi = pi / el
            bj = pj / el
            bk = pk / el
            #print(b)
            l.Boost(-bi, -bj, -bk)
            z[...] = l.X()
            y[...] = l.Y()
            z[...] = l.Z()
        return (it.operands[4], it.operands[5], it.operands[6])
def Analyze(n, event):
    nphot = 0
    for j in range(event.E.size()):
        wgt = event.wgt[j]
        nphot += wgt
        ### all photons
        histos["h_E"].Fill(event.E[j], wgt)
        p = TLorentzVector()
        p.SetPxPyPzE(event.px[j], event.py[j], event.pz[j], event.E[j])
        v = p.Vect()
        vxHat = (v.X() / v.Mag())
        vyHat = (v.Y() / v.Mag())
        vzHat = (v.Z() / v.Mag())

        r1 = TVector3(R1 * vxHat, R1 * vyHat, R1 * vzHat)
        histos["h_R1_x"].Fill(r1.X(), wgt)
        histos["h_R1_y"].Fill(r1.Y(), wgt)
        histos["h_R1_xy"].Fill(r1.X(), r1.Y(), wgt)
        histos["h_R1_xE"].Fill(r1.X(), event.E[j], wgt)
        histos["h_R1_yE"].Fill(r1.Y(), event.E[j], wgt)

        r2 = TVector3(R2 * vxHat, R2 * vyHat, R2 * vzHat)
        histos["h_R2_x"].Fill(r2.X(), wgt)
        histos["h_R2_y"].Fill(r2.Y(), wgt)
        histos["h_R2_xy"].Fill(r2.X(), r2.Y(), wgt)
        histos["h_R2_xE"].Fill(r2.X(), event.E[j], wgt)
        histos["h_R2_yE"].Fill(r2.Y(), event.E[j], wgt)

        xVtx = event.vx[j]
        yVtx = event.vy[j]
        zVtx = event.vz[j]
        histos["h_xVtx"].Fill(xVtx, wgt)
        histos["h_yVtx"].Fill(yVtx, wgt)
        histos["h_zVtx"].Fill(zVtx, wgt)
        histos["h_xyVtx"].Fill(xVtx, yVtx, wgt)
    histos["h_photons"].Fill(nphot)
    return nphot