Exemple #1
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 #2
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
def mis_energy(tree, histdict):
    '''Read the tree and fill the histogram event per events'''

    count_ISR_evt = 0

    for iev, evt in enumerate(tree):

        # if evt.reco_lepton_size == 0:
        #     continue

        # ISR_evt_flag = False

        if iev % 1000 == 0:
            print("Processing events {} on {} ".format(iev, tree.GetEntries()))

        # jet1_tlv = TLorentzVector(evt.reco_jet1_px, evt.reco_jet1_py, evt.reco_jet1_pz, evt.reco_jet1_e)
        # jet2_tlv = TLorentzVector(evt.reco_jet2_px, evt.reco_jet2_py, evt.reco_jet2_pz, evt.reco_jet2_e)

        # angle_jets = jet1_tlv.Angle(jet2_tlv.Vect())
        # histdict["h_recoJetsAngle"].Fill(angle_jets)
        # histdict["h_recoJetsTheta"].Fill(evt.reco_jet1_theta)
        # histdict["h_recoJetsTheta"].Fill(evt.reco_jet2_theta)
        # histdict["h_recoJetEnergy"].Fill(evt.reco_jet1_e)
        # histdict["h_recoJetEnergy"].Fill(evt.reco_jet2_e)

        lepton_tlv = TLorentzVector(evt.gen_lepton_px, evt.gen_lepton_py,
                                    evt.gen_lepton_pz, evt.gen_lepton_e)

        FSR_ph = zip(elementSelection(evt.fsr_e), elementSelection(evt.fsr_px),
                     elementSelection(evt.fsr_py),
                     elementSelection(evt.fsr_pz))
        for e, px, py, pz in FSR_ph:
            FSR_ph = TLorentzVector(px, py, pz, e)
            p_FSR = FSR_ph.P()
            E_p_FSR = e / p_FSR

            histdict["h_E_p_vs_E_FSR"].Fill(e, E_p_FSR)

            angle = FSR_ph.Angle(lepton_tlv.Vect())
            if e >= 0.2:
                histdict["h_FSR_lepton_angle_vs_E"].Fill(e, angle)

        nonFSR_ph = zip(elementSelection(evt.nonFSRPh_e),
                        elementSelection(evt.nonFSRPh_px),
                        elementSelection(evt.nonFSRPh_py),
                        elementSelection(evt.nonFSRPh_pz))
        for e, px, py, pz in nonFSR_ph:
            nonFSR_ph = TLorentzVector(px, py, pz, e)
            p_nonFSR = nonFSR_ph.P()
            E_p_nonFSR = e / p_nonFSR

            histdict["h_E_p_vs_E_nonFSR"].Fill(e, E_p_nonFSR)

            angle = nonFSR_ph.Angle(lepton_tlv.Vect())
            if e >= 0.2 and angle > 0.02:
                histdict["h_nonFSR_lepton_angle_vs_E"].Fill(e, angle)
Exemple #4
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 #5
0
def cosThetaTrue(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().Z()/p.Vect().Mag()
   if(ySystem(pa,pb)<0. and doflip): cosThetaB *= -1. # reclassify ???
   return cosThetaB
Exemple #6
0
 def test_ip_simple(self):
     '''This simple test works for all three methods'''
     # goes along x
     p4 = TLorentzVector(1, 0, 0, 1.1)
     # starts at y = 0.1
     vertex = TVector3(0, 0.1, 0)
     helix = Helix(1, 1, p4, vertex)
     # global origin
     origin = TVector3(0, 0, 0)
     # Lucas' calculation
     ip = helix.compute_IP(origin, p4.Vect())
     self.assertAlmostEqual(ip, 0.1, places=8)
     # Nicolo's calculation
     ip2 = compute_IP(helix, origin, p4.Vect())
     self.assertAlmostEqual(ip2, 0.1, places=8)
     # and a hybrid one
     ip3 = helix.compute_IP_2(origin, p4.Vect())
     self.assertAlmostEqual(ip3, 0.1, places=8)
def sintheta_CM(pt1, eta1, phi1, ptz, etaz, phiz, mass):
    mu1 = TLorentzVector()
    zb = TLorentzVector()
    mu1.SetPtEtaPhiM(pt1, eta1, phi1, 0)
    zb.SetPtEtaPhiM(ptz, etaz, phiz, mass)
    Sintheta = 2.0 * (pt1 / mass) * math.sin(zb.Angle(mu1.Vect()))
    #if (	zb.Angle(mu1.Vect()) < 0.0 ):
    #print zb.Angle(mu1.Vect()), "******%%%%%%%%%%*"
    return Sintheta
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
    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 #11
0
def monojet(pdgids, theta, phi, pstar, jetenergy, vertex=None):
    particles = []
    if vertex is None:
        vertex = TVector3(0., 0., 0.)
    jetp4star = TLorentzVector()
    for pdgid in pdgids[:-1]:
        mass, charge = particle_data[pdgid]
        phistar = random.uniform(-math.pi, math.pi)
        thetastar = random.uniform(-math.pi, math.pi)
        sint = math.sin(thetastar)
        cost = math.cos(thetastar)
        sinp = math.sin(phistar)
        cosp = math.cos(phistar)
        pz = pstar * cost
        px = pstar * sint * cosp
        py = pstar * sint * sinp
        p4 = TLorentzVector()
        p4.SetXYZM(px, py, pz, mass)
        jetp4star += p4
        particles.append(Particle(p4, vertex, charge, pdgid))
    pdgid = pdgids[-1]
    mass, charge = particle_data[pdgid]
    p4 = TLorentzVector()
    p4.SetVectM(-jetp4star.Vect(), mass)
    particles.append(Particle(p4, vertex, charge, pdgid))
    jetp4star += p4

    #boosting to lab
    gamma = jetenergy / jetp4star.M()
    beta = math.sqrt(1 - 1 / gamma**2)
    boostvec = TVector3(
        math.sin(theta) * math.cos(phi),
        math.sin(theta) * math.sin(phi), math.cos(theta))
    boostvec *= beta
    boosted_particles = []
    jetp4 = LorentzVector()
    for ptc in particles:
        bp4 = LorentzVector(ptc.p4())
        bp4.Boost(boostvec)
        jetp4 += bp4
        boosted_particles.append(
            Particle(bp4, ptc.vertex, ptc.q(), ptc.pdgid()))
    # print jetp4.M(), jetp4.E()
    return boosted_particles
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 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
Exemple #14
0
def jpsimuDirections(chiccand, jpsicand, frame='hx'):
    """return two directions: 
       1. direction vector of jpsi in the chic rest frame, wrt to the direction of chic
       2. direction vector of muon in the jpsi rest frame, wrt to the direction of the psi as seen in the chic rest frame"""

    pbeam = 3500
    Mpsi = 3.097
    Mprot = 0.938

    Ebeam = sqrt(pbeam**2 + Mprot**2)

    targ = TLorentzVector(0., 0., -pbeam, Ebeam)
    beam = TLorentzVector(0., 0., pbeam, Ebeam)

    # chic 4vector in lab frame
    chi = TLorentzVector()
    #chi.SetXYZM(chiccand.px(), chiccand.py(), chiccand.pz(), mass)
    chi.SetXYZM(chiccand.px(), chiccand.py(), chiccand.pz(), chiccand.mass())

    chi_direction = chi.Vect().Unit()

    # psi 4vector in lab fram
    psi = TLorentzVector()
    psi.SetXYZM(jpsicand.px(), jpsicand.py(), jpsicand.pz(), jpsicand.mass())

    cm_to_chi = -chi.BoostVector()
    chi_to_cm = chi.BoostVector()

    cm_to_psi = -psi.BoostVector()

    beam_chi = beam
    beam_chi.Boost(cm_to_chi)  # beam in the chi rest frame

    targ_chi = targ
    targ_chi.Boost(cm_to_chi)  # target in the chi rest frame

    beam_direction_chi = beam_chi.Vect().Unit()
    targ_direction_chi = targ_chi.Vect().Unit()
    beam_targ_bisec_chi = (beam_direction_chi - targ_direction_chi).Unit()

    psi_chi = psi
    psi_chi.Boost(cm_to_chi)  # psi in the chi rest frame

    psi_direction_chi = psi_chi.Vect().Unit()

    # all polarization frames have the same Y axis = the normal to the plane
    # formed by the directions of the colliding hadrons

    Yaxis = (beam_direction_chi.Cross(targ_direction_chi)).Unit()

    # transform(rotation) psi momentum components from polarization axis system
    # to the system with x,y,z axes as in the laboratory

    ChiPolAxis = chi_direction
    # helicity frame
    if frame is 'cs':
        ChiPolAxis = beam_targ_bisec_chi

    newZaxis = ChiPolAxis
    newYaxis = Yaxis
    newXaxis = newYaxis.Cross(newZaxis)

    # rotation needed to go to the chi rest frame
    rotation = TRotation()
    rotation.SetToIdentity()
    rotation.RotateAxes(newXaxis, newYaxis, newZaxis)
    rotation.Invert()

    psi_chi_rotated = psi_chi.Vect()

    psi_chi_rotated.Transform(rotation)
    # direction of the psi in the chi rest frame
    # relative to direction of chi in the lab

    # now calculate muon direction in the jpsi rest frame wrt chi direction
    mumass = 0.105

    Yaxis = (ChiPolAxis.Cross(psi_direction_chi)).Unit()

    newZaxis = psi_direction_chi
    newYaxis = Yaxis
    newXaxis = newYaxis.Cross(newZaxis)

    rotation.SetToIdentity()
    rotation.RotateAxes(newXaxis, newYaxis, newZaxis)
    rotation.Invert()

    #muon in the lab
    lepton = TLorentzVector()
    lepton.SetXYZM(
        jpsicand.daughter(0).px(),
        jpsicand.daughter(0).py(),
        jpsicand.daughter(0).pz(), mumass)

    #muon in the psi rest frame
    lepton_psi = lepton
    lepton_psi.Boost(cm_to_psi)

    lepton_psi_rotated = lepton_psi.Vect()
    lepton_psi_rotated.Transform(rotation)

    return psi_chi_rotated, lepton_psi_rotated
Exemple #15
0
                higgs = mcpi
            elif mcpi.getPDG() == 21:
                higgs = mcpi
            elif mcpi.getPDG() == 23:
                higgs = mcpi

            if mcpi.getPDG() == 6:
                top = mcpi
            if mcpi.getPDG() == -6:
                topbar = mcpi

        higgs_4v = TLorentzVector(higgs.getMomentum())
        top_4v = TLorentzVector(top.getMomentum())
        topbar_4v = TLorentzVector(topbar.getMomentum())

        tHang1 = higgs_4v.Angle(top_4v.Vect())
        tHang2 = higgs_4v.Angle(topbar_4v.Vect())

        if (tHang1 < tHang2):
            higgs_hist.Fill(tHang1)
            higgs_coshist.Fill(math.cos(tHang1))
        else:
            higgs_hist.Fill(tHang2)
            higgs_coshist.Fill(math.cos(tHang2))

        event = reader.readNextEvent()

gluon_files = [
    100, 102, 103, 104, 105, 106, 109, 110, 111, 112, 113, 114, 115, 116, 118,
    119, 121, 122, 123
]
Exemple #16
0
class TestPath(unittest.TestCase):
    def setUp(self):
        # goes along x
        self.p4 = TLorentzVector(1, 0, 0, 1.1)
        # starts at y = 0.1
        self.true_IP = 0.1
        self.vertex = TVector3(0, self.true_IP, 0)
        self.helix = Helix(1, 1, self.p4, self.vertex)
        # global origin
        self.origin = TVector3(0, 0, 0)

    def test_ip_simple(self):
        '''This simple test works for all three methods'''
        # Lucas' calculation
        ##        ip = self.helix.compute_IP(self.origin, self.p4.Vect())
        ##        self.assertAlmostEqual(ip, self.true_IP, places=8)
        # Nicolo's calculation
        ip2 = compute_IP(self.helix, self.origin, self.p4.Vect())
        self.assertAlmostEqual(abs(ip2), self.true_IP, places=5)
        # and a hybrid one


##        ip3 = self.helix.compute_IP_2(self.origin, self.p4.Vect())
##        self.assertAlmostEqual(ip3, self.true_IP, places=8)

    def test_ip_many(self):
        npoints = 100
        scale = 1e-6
        radii = np.linspace(0.1 * scale, 0.2 * scale, npoints)
        angles = np.linspace(0, math.pi, npoints)
        momenta = np.linspace(200, 500, npoints)
        mass = 0.5
        field = 1e-5
        origin = TVector3(0, 0, 0)
        for radius, angle, momentum in zip(radii, angles, momenta):
            ip_pos = TVector3(math.cos(angle), math.sin(angle), 0)
            ip_pos *= radius
            p3 = TVector3(math.cos(angle - math.pi / 2.),
                          math.sin(angle - math.pi / 2.), 0)
            p3 *= momentum
            p4 = TLorentzVector()
            p4.SetVectM(p3, mass)
            helix_vertex = copy.deepcopy(ip_pos)
            delta = copy.deepcopy(p3.Unit())
            delta *= radius
            helix_vertex += delta
            helix = Helix(field, 1., p4, helix_vertex)
            # jet direction is 0.1 radians away from particle direction
            # to obtain a positivive IP sign
            jet_dir = copy.deepcopy(p3).Unit()
            jet_dir.RotateZ(0.1)
            ip_nic = compute_IP(helix, origin, jet_dir)
            ip_obj = ImpactParameter(helix, origin, jet_dir)
            verbose = False
            places = 8
            if verbose:
                print '-' * 50
                print math.cos(angle), math.sin(angle), radius
                print 'obj', ip_obj.value, '({})'.format(
                    abs(ip_obj.value) - radius)
                print 'nic', ip_nic, '({})'.format(abs(ip_nic) - radius)
            else:
                self.assertAlmostEqual(abs(ip_obj.value),
                                       radius,
                                       places=places)
                #COLIN->NIC: Nicolo's minimization does not give the right result
                # could be that it only works for very small distances?
                # can be tested by uncommenting the following line and
                # running this test file
                self.assertAlmostEqual(abs(ip_nic), radius, places=places)

    def test_ipclass(self):
        self.p4.Vect().Print()
        ip = ImpactParameter(self.helix, self.origin, self.p4.Vect())
        self.assertAlmostEqual(ip.value, self.true_IP, places=5)
                    v3_found = 1
                    v3_gen.SetXYZ(float(lin_list[3]), float(lin_list[4]),
                                  float(lin_list[5]))

            lin = fil.readline()
            lin_list = lin.split(None)

        p4g.SetVectM(p3g, 0.0)
        p4targ.SetXYZT(0, 0, 0, m_proton)
        p4L.SetVectM(p3L, m_lam)
        p4k.SetVectM(p3k, m_kplus)
        p4p.SetVectM(p3p, m_proton)
        p4mu.SetVectM(p3mu, m_muon)

        p4nu = p4g + p4targ - p4k - p4p - p4mu
        p3nu = p4nu.Vect()
        p4tot_i = p4g + p4targ
        p4tot_f = p4k + p4p + p4mu + p4nu

        if v3_found == 0:
            v3_gen = v2_gen

        outfeats.append(p3g.Mag())
        header.append('p_gamma')
        outfeats.append(p3k.CosTheta())
        header.append('costheta_k')
        outfeats.append(p4k.E())  #e_k
        header.append('e_k')
        outfeats.append(p3k.Mag())  #p_k
        header.append('p_k')
        outfeats.append(
            Z2_Z2SS = l_Z2 * Z2
            q1_Z2SS = l_Z2 * q1
            q2_Z2SS = l_Z2 * q2

            # Five angular information (theta1, theta2, Phi, Phi1, thetaStar)
            theta1[0] = math.acos(
                (-1.) * Z2_Z1SS.Vect().Unit().Dot(l1_Z1SS.Vect().Unit()))
            theta1p = math.acos(
                (-1.) * Z2_Z1SS.Vect().Unit().Dot(l2_Z1SS.Vect().Unit()))

            theta2[0] = math.acos(
                (-1.) * Z1_Z2SS.Vect().Unit().Dot(q1_Z2SS.Vect().Unit()))
            theta2p = math.acos(
                (-1.) * Z1_Z2SS.Vect().Unit().Dot(q2_Z2SS.Vect().Unit()))

            v1ortho = l1.Vect().Cross(l2.Vect())
            v2ortho = q1.Vect().Cross(q2.Vect())
            n1 = v1ortho.Unit()
            n2 = v2ortho.Unit()
            A = Z1.Vect().Dot(n1.Cross(n2))
            Phi[0] = A / abs(A) * math.acos((-1.) * n1.Dot(n2))

            nz = TVector3(0, 0, 1)
            nsc = (nz.Cross(Z1.Vect())).Unit()
            B = Z1.Vect().Dot(n1.Cross(nsc))
            Phi1[0] = B / abs(B) * math.acos(n1.Dot(nsc))

            thetaStar[0] = Z1.Vect().Theta()
            thetaStar2[0] = Z2.Vect().Theta()

            # Event selection
Exemple #19
0
def get_gen_kin(rootfile):

    intree = rfile.Get('kin')
    d = tree2array(intree)

    Px = d['Px_FinalState']
    Py = d['Py_FinalState']
    Pz = d['Pz_FinalState']
    E = d['E_FinalState']

    Px_beam = d['Px_Beam']
    Py_beam = d['Py_Beam']
    Pz_beam = d['Pz_Beam']
    E_beam = d['E_Beam']

    #get numpy arrays to save later
    mproton = np.zeros_like(Px)
    metap = np.zeros_like(Px)
    mpi0 = np.zeros_like(Px)
    metaprimepi0 = np.zeros_like(Px)
    beam_energy = np.zeros_like(Px)
    cos_theta = np.zeros_like(Px)

    #declare  TLorentzVector
    Beam_P4 = TLorentzVector()
    Proton_P4 = TLorentzVector()
    Etaprime_P4 = TLorentzVector()
    Pi0_P4 = TLorentzVector()
    Etaprimepi0_P4 = TLorentzVector()

    #declare stuff to convert to GJ frame
    boostGJ = TVector3()
    Beam_P4_GJ = TLorentzVector()
    Proton_P4_GJ = TLorentzVector()
    Etaprime_P4_GJ = TLorentzVector()
    Pi0_P4_GJ = TLorentzVector()
    Etaprimepi0_P4_GJ = TLorentzVector()

    z_GJ = TVector3()
    z_hat_GJ = TVector3()

    y_GJ = TVector3()
    y_hat_GJ = TVector3()

    x_hat_GJ = TVector3()
    vetaprime = TVector3()

    for i in range(len(Px)):
        #for i in range(100):
        #m = np.sqrt(E[i][0]**2 - (Px[i][0]**2 + Py[i][0]**2 + Pz[i][0]**2))
        #metap[i] = m

        #get  TLorentzVector vectors
        Beam_P4.SetPxPyPzE(Px_beam[i], Py_beam[i], Pz_beam[i], E_beam[i])
        Proton_P4.SetPxPyPzE(Px[i][0], Py[i][0], Pz[i][0], E[i][0])
        Etaprime_P4.SetPxPyPzE(Px[i][1], Py[i][1], Pz[i][1], E[i][1])
        Pi0_P4.SetPxPyPzE(Px[i][2], Py[i][2], Pz[i][2], E[i][2])

        #do stuff here
        Etaprimepi0_P4 = Etaprime_P4 + Pi0_P4

        #get the boost vector
        boostGJ = (-1) * (Etaprimepi0_P4.Vect()) * (1.0 / Etaprimepi0_P4.E())

        Beam_P4_GJ = Beam_P4
        Proton_P4_GJ = Proton_P4
        Etaprime_P4_GJ = Etaprime_P4
        Pi0_P4_GJ = Pi0_P4
        Etaprimepi0_P4_GJ = Etaprimepi0_P4

        #boost vectors to GJ frame
        Beam_P4_GJ.Boost(boostGJ)
        Proton_P4_GJ.Boost(boostGJ)
        Etaprime_P4_GJ.Boost(boostGJ)
        Pi0_P4_GJ.Boost(boostGJ)
        Etaprimepi0_P4_GJ.Boost(boostGJ)

        z_GJ.SetXYZ(Beam_P4_GJ.X(), Beam_P4_GJ.Y(), Beam_P4_GJ.Z())
        z_hat_GJ = z_GJ.Unit()

        y_GJ = Beam_P4.Vect().Cross(Etaprimepi0_P4.Vect())
        y_hat_GJ = y_GJ.Unit()

        x_hat_GJ = y_hat_GJ.Cross(z_hat_GJ)

        vetaprime.SetXYZ(Etaprime_P4_GJ.Vect() * x_hat_GJ,
                         Etaprime_P4_GJ.Vect() * y_hat_GJ,
                         Etaprime_P4_GJ.Vect() * z_hat_GJ)
        cos_theta[i] = vetaprime.CosTheta()

        mproton[i] = Proton_P4.M()
        metap[i] = Etaprime_P4.M()
        mpi0[i] = Pi0_P4.M()
        metaprimepi0[i] = Etaprimepi0_P4.M()
        beam_energy[i] = Beam_P4.E()

    return np.savez(
        '/Users/rupeshdotel/analysis/work/pi0pippimeta/data/MC/check_events.npz',
        mproton=mproton,
        metap=metap,
        mpi0=mpi0,
        metaprimepi0=metaprimepi0,
        cos_theta=cos_theta,
        beam_energy=beam_energy)
Exemple #20
0
            print 'ID:', p.pdgId()
            lep_mad.SetPtEtaPhiE(p.pt(), p.eta(), p.phi(), p.energy())
            madspin_TLorentzVector.append(lep_mad.Clone())
            madspin_pdgid_index.append(p.pdgId())
    for i in range(len(madspin_pdgid_index)):
        tau_mad = tau_mad + madspin_TLorentzVector[i]
    tauphi_mad.Fill(tau_mad.Phi(), weight_mad)
    taueta_mad.Fill(tau_mad.Eta(), weight_mad)
    taupt_mad.Fill(tau_mad.Pt(), weight_mad)
    tau_mad_boost = tau_mad.BoostVector()
    tau_mad.Boost(-tau_mad_boost)
    if -16 in madspin_pdgid_index: neu_posi = madspin_pdgid_index.index(-16)
    if 16 in madspin_pdgid_index: neu_posi = madspin_pdgid_index.index(16)
    neu_mad = madspin_TLorentzVector[neu_posi]
    neu_mad.Boost(-tau_mad_boost)
    nphi_mad.Fill(cos(neu_mad.Angle(tau_mad.Vect())), weight_mad)
    if -11 in madspin_pdgid_index: ele_posi = madspin_pdgid_index.index(-11)
    if 11 in madspin_pdgid_index: ele_posi = madspin_pdgid_index.index(11)
    if ele_posi != -999:
        ele_mad = madspin_TLorentzVector[ele_posi]
        ele_mad.Boost(-tau_mad_boost)
        elephi_mad.Fill(cos(ele_mad.Angle(tau_mad.Vect())), weight_mad)
    if -13 in madspin_pdgid_index: mu_posi = madspin_pdgid_index.index(-13)
    if 13 in madspin_pdgid_index: mu_posi = madspin_pdgid_index.index(13)
    if mu_posi != -999:
        mu_mad = madspin_TLorentzVector[mu_posi]
        mu_mad.Boost(-tau_mad_boost)
        muphi_mad.Fill(cos(mu_mad.Angle(tau_mad.Vect())), weight_mad)
    del madspin_TLorentzVector[:]
    del madspin_pdgid_index[:]
tauphi_mad.Scale(1. / tauphi_mad.Integral())
Exemple #21
0
        l1_Z1SS = l_Z1 * l1
        l2_Z1SS = l_Z1 * l2
        
        # Boost to Z2's static system
        l_Z2 = TLorentzRotation().Boost(-1.*Z2.Px()/Z2.E(), -1.*Z2.Py()/Z2.E(), -1.*Z2.Pz()/Z2.E())
        Z1_Z2SS = l_Z2 * Z1
        Z2_Z2SS = l_Z2 * Z2
        q1_Z2SS = l_Z2 * q1
        q2_Z2SS = l_Z2 * q2
       
        # Five angular information (theta1, theta2, Phi, Phi1, thetaStar)
        theta1[0] = math.acos((-1.)*Z2_Z1SS.Vect().Unit().Dot(l1_Z1SS.Vect().Unit()))

        theta2[0] = math.acos((-1.)*Z1_Z2SS.Vect().Unit().Dot(q1_Z2SS.Vect().Unit()))
        
        v1ortho = l1.Vect().Cross(l2.Vect())
        v2ortho = q1.Vect().Cross(q2.Vect())
        n1 = v1ortho.Unit()
        n2 = v2ortho.Unit()
        A = Z1.Vect().Dot(n1.Cross(n2))
        if A!=0 : phi[0] = A/abs(A)*math.acos((-1.)*n1.Dot(n2))
        else : phi[0] = -99
        
        nz = TVector3(0,0,1)
        nsc = (nz.Cross(Z1.Vect())).Unit()
        B = Z1.Vect().Dot(n1.Cross(nsc))
        phi1[0] = B/abs(B)*math.acos(n1.Dot(nsc))
        
        thetaStar[0] = Z1.Vect().Theta()

Exemple #22
0
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
Exemple #23
0
    def fitmZ(self):

        dilepton = False
        diele = False
        dimu = False

        if self.leptons[0].pdgId() + self.leptons[1].pdgId() == 0 and \
           abs( self.leptons[0].pdgId() - self.leptons[1].pdgId()) > 20 :
            dilepton = True

        #if not(dilepton) : return -99.

        diele = abs(self.leptons[0].pdgId() - self.leptons[1].pdgId()) == 22
        dimu = abs(self.leptons[0].pdgId() - self.leptons[1].pdgId()) == 26

        l1 = TLorentzVector(self.leptons[0].px(), self.leptons[0].py(),
                            self.leptons[0].pz(), self.leptons[0].energy())
        l2 = TLorentzVector(self.leptons[1].px(), self.leptons[1].py(),
                            self.leptons[1].pz(), self.leptons[1].energy())
        c12 = l1.Vect().Dot(l2.Vect()) / l1.P() / l2.P()
        st1 = l1.Pt() / l1.P()
        st2 = l2.Pt() / l2.P()
        m12 = (l1 + l2).M() / sqrt(l1.E() * l2.E())
        fac = 91.188 / (l1 + l2).M()
        energies = [l1.E() * fac, l2.E() * fac]
        measts = [l1.E(), l2.E()]

        def chi2(e):
            def breitw2(m, m0, g0):
                m02 = m0 * m0
                g02 = g0 * g0
                delta = m * m - m02
                return m02 * g02 / (delta * delta + g02 * m02)

            def breitw(m, m0, g0):
                delta = m - m0
                return m0 * g0 / (delta * delta + g0 * m0)

            chi2 = 0.
            fudge = 1.
            mz = m12 * sqrt(e[0] * e[1])
            mzm = m12 * sqrt(measts[0] * measts[1])
            #mz = sqrt(2.*e[0]*e[1]*(1.-c12))
            #print 'mz = ',mz
            sigma1 = 0
            sigma2 = 0
            if dimu:
                chi2 = ( 1./measts[0]-1./e[0] ) * ( 1./measts[0]-1./e[0] ) / (st1*st1) \
                     + ( 1./measts[1]-1./e[1] ) * ( 1./measts[1]-1./e[1] ) / (st2*st2)
                chi2 /= 25E-8
                sigma1 = 5E-4 * 5E-4 * e[0] * e[0] * e[0] * e[0] * st1 * st1
                sigma2 = 5E-4 * 5E-4 * e[1] * e[1] * e[0] * e[0] * st2 * st2
                fudge = 0.5
            elif diele:
                sigma1 = (0.155 * 0.155 + 0.043 * 0.043 * e[0] +
                          0.02 * 0.02 * e[0] * e[0])
                sigma2 = (0.155 * 0.155 + 0.043 * 0.043 * e[1] +
                          0.02 * 0.02 * e[1] * e[1])
                chi2 = (measts[0]-e[0])*(measts[0]-e[0]) / sigma1 \
                     + (measts[1]-e[1])*(measts[1]-e[1]) / sigma2
                fudge = 2.0
            else:
                sigma1 = (0.5 * 0.5 * e[0] / st1 + 0.04 * 0.04 * e[0] * e[0])
                sigma2 = (0.5 * 0.5 * e[1] / st2 + 0.04 * 0.04 * e[1] * e[1])
                chi2 = (measts[0]-e[0])*(measts[0]-e[0]) / sigma1 \
                     + (measts[1]-e[1])*(measts[1]-e[1]) / sigma2
                fudge = 1.0
            #print 'chi2 partial  = ',chi2
            sigmaM = mz * mz * (sigma1 / (e[0] * e[0]) + sigma2 /
                                (e[1] * e[1])) / 4.
            #chi2 = (mzm-mz)*(mzm-mz)/sigmaM
            self.chi2partiel = copy.copy(chi2)
            chi2 -= fudge * log(breitw2(mz, 91.188,
                                        2.497)) * sqrt(sigmaM) / 2.497
            self.chi2total = copy.copy(chi2)
            #if diele:
            #    print 'chi2 partie/complet = ',dimu,diele,mz,mzm,sqrt(sigma1),sqrt(sigma2),sqrt(sigmaM),self.chi2partiel,self.chi2total
            return chi2

        def fillDerivatives(funga):
            def deriv(funga, gamma, i, epsilon):
                g = deepcopy(gamma)
                g[i] += epsilon
                chip = funga(g)
                g[i] -= 2. * epsilon
                chim = funga(g)
                g[i] += epsilon
                return (chip - chim) / (2. * epsilon)

            def deriv2(funga, gamma, i, j, epsilon, mu):
                g = deepcopy(gamma)
                g[i] += epsilon
                derp = deriv(funga, g, j, mu)
                g[i] -= 2. * epsilon
                derm = deriv(funga, g, j, mu)
                g[i] += epsilon
                return (derp - derm) / (2. * epsilon)

            rows = []
            deri = []
            for i in range(len(energies)):
                column = []
                for j in range(len(energies)):
                    column.append(deriv2(funga, energies, i, j, 0.001, 0.001))
                rows.append(column)
                deri.append(deriv(funga, energies, i, 0.001))
            return array(rows), array(deri)

        from numpy import array, linalg, dot, add
        from copy import deepcopy

        #print chi2(energies)
        Delta = 1E9
        t = 0
        while Delta > 1E-3 and t < 200:
            #print "iteration ",t
            t += 1

            d2, d = fillDerivatives(chi2)
            delta = linalg.solve(d2, d)
            Delta = abs(delta[0]) + abs(delta[1])
            #print '------------------- '
            #print 'Delta = ',Delta
            Ki2 = chi2(energies)

            factor = 1.
            for i in range(len(energies)):
                #print i, energies[i], delta[i], d[i]
                if abs(delta[i]) > energies[i] / 10.:
                    factor = min(factor, energies[i] / 10. / abs(delta[i]))
            delta = map(lambda x: x * factor, delta)

            def chinew(funga, gamma, delta):
                gnew = deepcopy(gamma)
                for i, g in enumerate(gamma):
                    gnew[i] -= delta[i]
                return funga(gnew) - Ki2

            while chinew(chi2, energies, delta) > 1E-5:
                delta = map(lambda x: -x * 0.6, delta)

            #print ' '
            for i in range(len(energies)):
                energies[i] -= delta[i]
        if t >= 199:
            print 'Warning - reached iteration ', t
            print diele, dimu, chi2(energies)
            for i in range(len(energies)):
                print i, energies[i], delta[i], d[i]
        #print t, chi2(energies)

        l1 *= energies[0] / l1.E()
        l2 *= energies[1] / l2.E()
        #if not(dimu):
        #    m12 = (l1+l2).M()
        #    l1 *= sqrt(91.188/m12)
        #    l2 *= sqrt(91.188/m12)

        #print self.leptons[0]
        p41 = self.leptons[0].p4()
        p41.SetPxPyPzE(l1.X(), l1.Y(), l1.Z(), l1.T())
        self.leptons[0].setP4(p41)
        #print self.leptons[1]
        p42 = self.leptons[1].p4()
        p42.SetPxPyPzE(l2.X(), l2.Y(), l2.Z(), l2.T())
        self.leptons[1].setP4(p42)
        return chi2(energies)
Exemple #24
0
from ROOT import TFile, TTree, TLorentzVector, TVector3
import math

def acop_colin(jet1, jet2):
    normal = jet1.Cross(jet2).Unit()
    angle = normal.Angle( TVector3(0, 0, 1)) - math.pi / 2.    
    return abs(angle * 180 / math.pi)

f = TFile('tree.root')
events = f.Get("events")
for event in events:
    jet1 = TLorentzVector(event.jet1_px, event.jet1_py, event.jet1_pz, event.jet1_e)
    jet2 = TLorentzVector(event.jet2_px, event.jet2_py, event.jet2_pz, event.jet2_e)
    acop = acop_colin(jet1.Vect(), jet2.Vect())
    # assert(acop == event.higgs_acop)
    print acop, event.higgs_acop
Exemple #25
0
def multiple_scattering(particle, detector_element, field):
    '''This function computes the scattering of a particle while propagating through the detector.
    
    As described in the pdg booklet, Passage of particles through matter, multiple scattering through small angles.
    the direction of a charged particle is modified.
    
    This function takes a particle (that has been propagated until the detector element
    where it will be scattered) and the detector element responsible for the scattering.
    The magnetic field has to be specified in order to create the new trajectory.
    
    Then this function computes the new direction, randomly choosen according to
    Moliere's theory of multiple scattering (see pdg booklet) and replaces the
    initial path of the particle by this new scattered path.
    
    The particle can now be propagated in the next part of the detector.
    '''

    if not particle.q():
        return
    # reject particles that could not be extrapolated to detector element
    # (particle created too late, out of the detector element)
    surface_in = '{}_in'.format(detector_element.name)
    surface_out = '{}_out'.format(detector_element.name)
    if not surface_in in particle.path.points or \
        not surface_out in particle.path.points:
        return

    #TODOCOLIN : check usage of private attributes
    in_point = particle.path.points[surface_in]
    out_point = particle.path.points[surface_out]
    phi_in = particle.path.phi(in_point.X(), in_point.Y())
    phi_out = particle.path.phi(out_point.X(), out_point.Y())
    t_scat = particle.path.time_at_phi((phi_in + phi_out) * 0.5)
    # compute p4_t = p4 at t_scat :
    p4_0 = particle.path.p4.Clone()
    p4tx = p4_0.X()*math.cos(particle.path.omega*t_scat)\
           + p4_0.Y()*math.sin(particle.path.omega*t_scat)
    p4ty =-p4_0.X()*math.sin(particle.path.omega*t_scat)\
           + p4_0.Y()*math.cos(particle.path.omega*t_scat)
    p4tz = p4_0.Z()
    p4tt = p4_0.T()
    p4_t = TLorentzVector(p4tx, p4ty, p4tz, p4tt)

    # now, p4t will be modified with respect to the multiple scattering
    # first one has to determine theta_0 the width of the gaussian :
    P = p4_t.Vect().Dot(p4_t.Vect().Unit())
    deltat = particle.path.time_at_phi(phi_out) - particle.path.time_at_phi(
        phi_in)
    x = abs(particle.path.path_length(deltat))
    X_0 = detector_element.material.x0

    theta_0 = 1.0 * 13.6e-3 / (1.0 * particle.path.speed / constants.c *
                               P) * abs(particle.path.charge)
    theta_0 *= (1.0 * x / X_0)**(1.0 / 2) * (1 +
                                             0.038 * math.log(1.0 * x / X_0))

    # now, make p4_t change due to scattering :
    theta_space = random.gauss(0, theta_0 * 2.0**(1.0 / 2))
    psi = constants.pi * random.uniform(0, 1)  #double checked
    p3i = p4_t.Vect().Clone()
    e_z = TVector3(0, 0, 1)
    #first rotation : theta, in the xy plane
    a = p3i.Cross(e_z)
    #this may change the sign, but randomly, as the sign of theta already is
    p4_t.Rotate(theta_space, a)
    #second rotation : psi (isotropic around initial direction)
    p4_t.Rotate(psi, p3i.Unit())

    # creating new helix, ref at scattering point :
    helix_new_t = Helix(field, particle.path.charge, p4_t,
                        particle.path.point_at_time(t_scat))

    # now, back to t=0
    p4sx = p4_t.X()*math.cos(-particle.path.omega*t_scat)\
           + p4_t.Y()*math.sin(-particle.path.omega*t_scat)
    p4sy =-p4_t.X()*math.sin(-particle.path.omega*t_scat)\
           + p4_t.Y()*math.cos(-particle.path.omega*t_scat)
    p4sz = p4_t.Z()
    p4st = p4_t.T()
    p4_scat = TLorentzVector(p4sx, p4sy, p4sz, p4st)

    # creating new helix, ref at new t0 point :
    helix_new_0 = Helix(field, particle.path.charge, p4_scat,
                        helix_new_t.point_at_time(-t_scat))

    # replacing the particle's path with the scatterd one :
    particle.set_path(helix_new_0, option='w')
Exemple #26
0
    ncut += 1
    hCutflow.Fill(ncut, evtwt)

    #------------------------------------------------------------------------
    #                          BASELINE CUTS
    #------------------------------------------------------------------------

    # store lep variables:
    primarylep = TLorentzVector(0.0, 0.0, 0.0, 0.0)
    for i in range(0, len(elelepcand)):
        if elelepcand[i].Pt() > primarylep.Pt():
            primarylep = elelepcand[i]
    for j in range(0, len(mulepcand)):
        if mulepcand[j].Pt() > primarylep.Pt():
            primarylep = mulepcand[j]
    lep_p3 = primarylep.Vect()

    # leading jet pt > 185
    leadjet = centjets[0]
    leadjetpt = leadjet.Pt()
    leadjeteta = leadjet.Eta()
    if leadjetpt <= 185: continue
    ncut += 1
    hCutflow.Fill(ncut, evtwt)

    # second leading jet pt > 50
    secondjet = centjets[1]
    secondjetpt = secondjet.Pt()
    secondjeteta = secondjet.Eta()
    if secondjetpt <= 50: continue
    ncut += 1
Exemple #27
0
    x    = mu_m + mu_p + g

    mu_m.Boost(-x.BoostVector());
    mu_p.Boost(-x.BoostVector());
    g.Boost   (-x.BoostVector());
    jpsi.Boost(-x.BoostVector());
    x.Boost   (-x.BoostVector());

    mu_m.Boost(-jpsi.BoostVector());
    mu_p.Boost(-jpsi.BoostVector());
    g.Boost   (-jpsi.BoostVector());

    # if ((jpsi.Vect().Mag()>tol) and (mu_p.Vect().Mag()>tol) and (mu_m.Vect().Mag()>tol) and (g.Vect().Mag()>tol) and (x.Vect().Mag()>0)):
    l_cosThetaStar.append(jpsi.CosTheta())

    cosTheta1 = jpsi.Vect().Dot(mu_p.Vect()) / ((jpsi.Vect().Mag())*(mu_p.Vect().Mag()));
    l_cosTheta1mu_p.append(cosTheta1)

    cosTheta1 = jpsi.Vect().Dot(mu_m.Vect()) / ((jpsi.Vect().Mag())*(mu_m.Vect().Mag()));
    l_cosTheta1mu_m.append(cosTheta1)

    M_mumu = (mu_m+mu_p).M()
    l_M_mumu.append(M_mumu)

    M_mumugamma = (mu_m+mu_p+g).M()
    l_M_mumugamma.append(M_mumugamma)

    tot_ev += 1

if not BATCH_MODE: sys.stdout.write("\nCompleted\n")
################################################################################
    #require exactly one lepton
    if nMedium + nmuMedium != 1: continue
    ncut += 1
    hCutflow.Fill(ncut, evtwt)

    # store lep variables:
    if nMedium == 1:
        lepP4.SetPtEtaPhiM(elelepcand[0].Pt(), elelepcand[0].Eta(),
                           elelepcand[0].Phi(), elelepcand[0].M())
    elif nmuMedium == 1:
        lepP4.SetPtEtaPhiM(mulepcand[0].Pt(), mulepcand[0].Eta(),
                           mulepcand[0].Phi(), mulepcand[0].M())
    else:
        continue
    lep_p3 = lepP4.Vect()

    # Pass 2D Isolation
    for j in jetsP4:
        dR = j.DeltaR(lepP4)
        jet_p3 = j.Vect()
        delPtRel = (lep_p3.Cross(jet_p3)).Mag() / jet_p3.Mag()
        hDR.Fill(dR, evtwt)
        hDelPtRel.Fill(delPtRel, evtwt)
        h2DdPtReldR.Fill(dR, delPtRel, evtwt)
        if dR < dRMin:
            nearestJetP4 = j
            dRMin = dR
            dPtRel = delPtRel
    # Store extra variables
    ptRel = nearestJetP4.Perp(lepP4.Vect())