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
Exemple #2
0
 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
Exemple #3
0
 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
Exemple #4
0
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
            ntuple=TNtupleD( treeName, 'flat ntuple for roofit', ':'.join(fillNames))
            print ' joint names ' + ':'.join(fillNames) + 'with size = {0}'.format(len(fillNames))

            hists = { fillName : TH1D(treeName+'_'+fillName, fillName, num[0], num[1], num[2]) for fillName, num in fillPars.iteritems() }
            for event in mytree:
                    nCand=event.candSize

                    for i in range(nCand):
                        tk1p4=TLorentzVector(event.tk1P1[i], event.tk1P2[i], event.tk1P3[i], event.tk1P0[i])
                        tk2p4=TLorentzVector(event.tk2P1[i], event.tk2P2[i], event.tk2P3[i], event.tk2P0[i])
                        pmup4=TLorentzVector(event.pmuP1[i], event.pmuP2[i], event.pmuP3[i], event.pmuP0[i])
                        nmup4=TLorentzVector(event.nmuP1[i], event.nmuP2[i], event.nmuP3[i], event.nmuP0[i])
                        mumup4=pmup4+nmup4
                        tktkp4=tk1p4+tk2p4

                        tk1p4.SetE((ptonMass*ptonMass+tk1p4.P()*tk1p4.P())**0.5)
                        tk2p4.SetE((kaonMass*kaonMass+tk2p4.P()*tk2p4.P())**0.5)
                        lbtkp4=tk1p4+tk2p4+pmup4+nmup4
                        tktkp4=tk1p4+tk2p4

                        tk1p4.SetE((kaonMass*kaonMass+tk1p4.P()*tk1p4.P())**0.5)
                        tk2p4.SetE((ptonMass*ptonMass+tk2p4.P()*tk2p4.P())**0.5)
                        lbtkbarp4=tk1p4+tk2p4+pmup4+nmup4
                        tktkbarp4=tk1p4+tk2p4

                        tk1p4.SetE((kaonMass*kaonMass+tk1p4.P()*tk1p4.P())**0.5)
                        tk2p4.SetE((kaonMass*kaonMass+tk2p4.P()*tk2p4.P())**0.5)
                        bsp4=tk1p4+tk2p4+pmup4+nmup4
                        phip4=tk1p4+tk2p4

                        tk1p4.SetE((kaonMass*kaonMass+tk1p4.P()*tk1p4.P())**0.5)
 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)
             qcount += 1
Exemple #7
0
for event in events:
    event.getByLabel(label, handle)
    candList = handle.product()
    encodedEffvalueList = handle.product()

    for cand in candList:
        mu1 = cand.daughter(0).daughter(0)
        mu2 = cand.daughter(0).daughter(1)
        tk1 = cand.daughter(1).daughter(0)
        tk2 = cand.daughter(1).daughter(1)
        tlmu1 = TLorentzVector(mu1.px(), mu1.py(), mu1.pz(), mu1.energy())
        tlmu2 = TLorentzVector(mu2.px(), mu2.py(), mu2.pz(), mu2.energy())
        tltk1 = TLorentzVector(tk1.px(), tk1.py(), tk1.pz(), tk1.energy())
        tltk2 = TLorentzVector(tk2.px(), tk2.py(), tk2.pz(), tk2.energy())
        tltk1.SetE((tltk1.P()**2 + 0.493677**2)**0.5)
        tltk2.SetE((tltk2.P()**2 + 0.9382720813**2)**0.5)
        reassignMass = (tlmu1 + tlmu2 + tltk1 + tltk2).Mag()
        distFromCent1 = abs(cand.mass() - 5.619)
        distFromCent2 = abs(reassignMass - 5.619)

        if distFromCent1 < 0.015 and distFromCent2 < 0.015:
            pass
        #elif distFromCent1<distFromCent2:
        #    hMass.Fill(cand.mass())
        #elif distFromCent1>distFromCent2:
        #    hMass.Fill(reassignMass)
        elif tk1.pt() > tk2.pt() and distFromCent1 < distFromCent2:
            hMass.Fill(cand.mass())
        elif tk1.pt() < tk2.pt() and distFromCent1 > distFromCent2:
            hMass.Fill(reassignMass)
 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'])
         q1.SetPz(e['particles'][i]['pz'])
Exemple #9
0
            continue

        if nCand > 1:
            continue
        for candIdx in range(nCand):
            tk1p4 = TLorentzVector(event.tk1P1[candIdx], event.tk1P2[candIdx],
                                   event.tk1P3[candIdx], event.tk1P0[candIdx])
            tk2p4 = TLorentzVector(event.tk2P1[candIdx], event.tk2P2[candIdx],
                                   event.tk2P3[candIdx], event.tk2P0[candIdx])
            pmup4 = TLorentzVector(event.pmuP1[candIdx], event.pmuP2[candIdx],
                                   event.pmuP3[candIdx], event.pmuP0[candIdx])
            nmup4 = TLorentzVector(event.nmuP1[candIdx], event.nmuP2[candIdx],
                                   event.nmuP3[candIdx], event.nmuP0[candIdx])
            for idx, name in enumerate(strs):
                if pMass[idx] < 0. and nMass[idx] < 0.:
                    tk1p4.SetE((tk1p4.P()**2 + pMass[idx]**2)**0.5)
                    tk2p4.SetE((tk2p4.P()**2 + nMass[idx]**2)**0.5)
                    interFakeComp = tk1p4 + tk2p4
                    fakeCompCand = interFakeComp + pmup4 + nmup4

                    h[idx][0].Fill(fakeCompCand.Mag())
                    h[idx][2].Fill(interFakeComp.Mag())

                    tk1p4.SetE((tk1p4.P()**2 + nMass[idx]**2)**0.5)
                    tk2p4.SetE((tk2p4.P()**2 + pMass[idx]**2)**0.5)

                    interFakeComp = tk1p4 + tk2p4
                    fakeCompCand = interFakeComp + pmup4 + nmup4
                    h[idx][1].Fill(fakeCompCand.Mag())
                    h[idx][3].Fill(interFakeComp.Mag())
                    continue