示例#1
0
    def validateMomenta(self, jet, tolerance=.01):
        """
        Checks if the jetmomentum is the sum of the constituent momenta.
        """
        v = TLorentzVector(0, 0, 0, 0)
        for comp in jet.constituents.values():
            for ptc in comp:
                v += ptc.p4()

        ret = True

        if abs(jet.pt() - v.Pt()) > tolerance:
            print 'pt unequal: ', jet.pt() - v.Pt()
            ret = False

        if abs(jet.theta() - v.Theta()) > tolerance:
            print 'theta unequal: ', jet.theta() - v.Theta()
            ret = False

        if abs(jet.eta() - v.Eta()) > tolerance:
            print 'eta unequal', jet.eta() - v.Eta()
            ret = False

        if abs(jet.phi() - v.Phi()) > tolerance:
            print 'phi unequal: ', jet.phi() - v.Phi()
            ret = False

        if abs(jet.m() - v.M()) > tolerance:
            print 'mass unequal: ', jet.m() - v.M()
            ret = False

        return ret
示例#2
0
def getHiggsMass(entry, tName, debug):
    # we are looping over jets, each has the information of Pt, Eta, Phi, E
    # they are available at different calibration stages:
    # Nominal, OneMu, PtRecoBukin, PtRecoGauss, Regression
    # we also know what is the correct simulated information: Parton
    # we want to compare the different calibrations and see which one
    # models better the Higgs boson mass
    # all Pt, E, M are in GeV
    # Higgs -> bb, meaning the b1 and b2 in this tree
    # let's see how we get a variable from the tree

    # jet 1
    # >>> b1 <<<
    b1_Opt_Pt, b1_Opt_Eta, b1_Opt_Phi, b1_Opt_E = getSpecificData(entry=entry,
                                                                  tName=tName,
                                                                  bVal="b1",
                                                                  debug=debug)
    b1_Opt_tlv = TLorentzVector()
    b1_Opt_tlv.SetPtEtaPhiE(b1_Opt_Pt, b1_Opt_Eta, b1_Opt_Phi, b1_Opt_E)
    b1_Opt_M = b1_Opt_tlv.M()
    if debug:
        print "b1_%s_M" % (tName), b1_Opt_M

    # jet 2
    # >>> b2 <<<
    b2_Opt_Pt, b2_Opt_Eta, b2_Opt_Phi, b2_Opt_E = getSpecificData(entry=entry,
                                                                  tName=tName,
                                                                  bVal="b2",
                                                                  debug=debug)
    b2_Opt_tlv = TLorentzVector()
    b2_Opt_tlv.SetPtEtaPhiE(b2_Opt_Pt, b2_Opt_Eta, b2_Opt_Phi, b2_Opt_E)
    b2_Opt_M = b2_Opt_tlv.M()
    if debug:
        print "b2_%s_M" % (tName), b2_Opt_M

    # Higgs boson candidate decaying to b1 and b2
    # TLorentzVector is the sum of the two TLorentzVectors
    Higgs_Opt_tlv = b1_Opt_tlv + b2_Opt_tlv
    Higgs_Opt_Pt = Higgs_Opt_tlv.Pt()
    Higgs_Opt_Eta = Higgs_Opt_tlv.Eta()
    Higgs_Opt_Phi = Higgs_Opt_tlv.Phi()
    Higgs_Opt_E = Higgs_Opt_tlv.E()
    if debug:
        print "Higgs_%s_Pt" % (tName), Higgs_Opt_Pt
        print "Higgs_%s_Eta" % (tName), Higgs_Opt_Eta
        print "Higgs_%s_Phi" % (tName), Higgs_Opt_Phi
        print "Higgs_&s_E" % (tName), Higgs_Opt_E
    Higgs_Opt_M = Higgs_Opt_tlv.M()
    if debug:
        print "Higgs_%s_M" % (tName), Higgs_Opt_M
    # the mass should be 125, but when measured we get a distribution around 125

    return Higgs_Opt_M
示例#3
0
def M_miss(parts):
	# here parts is visible parts - FOR LEPTON COLLIDERS HERE!
	# p=initial[0].p4+initial[1].p4
	p=TLorentzVector(0,0,0,settings.globDict['Energy'])	# px,py,pz,E
	for part in parts:
		p=p-part.P4()
	return p.M()
示例#4
0
    def invMass(self, leptons, types):
        if (len(leptons) != len(types)):
            self.msg.warning('invMass len(leptons)!=len(types) %i != %i' %
                             (len(leptons), len(types)))
            return -9999.

        result = TLorentzVector(0, 0, 0, 0)

        for iLept in range(len(leptons)):
            fourMomentum = TLorentzVector()
            # Electron: calculate 4-momentum based on cluster energy and track direction
            # Muon: use 4-momentum of the muon object
            if types[iLept] == "e":
                if leptons[iLept].cluster() and leptons[iLept].trackParticle():
                    fourMomentum.SetPtEtaPhiE(leptons[iLept].cluster().e()/math.cosh(leptons[iLept].trackParticle().eta()), \
                                              leptons[iLept].trackParticle().eta(), \
                                              leptons[iLept].trackParticle().phi(), \
                                              leptons[iLept].cluster().e())
                else:
                    fourMomentum.SetPtEtaPhiE(leptons[iLept].et(),
                                              leptons[iLept].eta(),
                                              leptons[iLept].phi(),
                                              leptons[iLept].e())
            else:
                fourMomentum.SetPtEtaPhiE(leptons[iLept].pt(),
                                          leptons[iLept].eta(),
                                          leptons[iLept].phi(),
                                          leptons[iLept].e())
            result = result + fourMomentum

        #print "total TLV is ", result.Px(),result.Py(),result.Pz(),result.E()
        return result.M()
def make_LHEparticle(p, id=None):
    if id != None:
        fv = TLorentzVector()

        try:
            m = p.Mass
        except AttributeError:
            m = 0

        try:
            pT = p.PT
        except AttributeError:
            pT = p.MET

        fv.SetPtEtaPhiM(pT, p.Eta, p.Phi, m)

        try:
            status = p.Status
        except AttributeError:
            status = 1

        _dict={'id':id,'status':status,\
                          'mother1':0,'mother2':0,'color1':0,'color2':0,\
                          'px':fv.Px(),'py':fv.Py(),'pz':fv.Pz(),'e':fv.Energy(),'m':fv.M(),'lifetime':0,'spin':0}
        lhepart = lhef.LHEParticle(**_dict)
        return lhepart
    else:
        print("id must be specified")
        pass
def M_miss(Energy,parts):
	# here parts is visible parts
	#p=initial[0].p4+initial[1].p4
	p=TLorentzVector(0,0,0,Energy)	# px,py,pz,E
	for part in parts:
		p=p-part.P4()
	return p.M()
示例#7
0
def InvMass(obj1, obj2 = 0, obj3 = 0):
  ''' Invariant mass of two objects '''
  if isinstance(obj1, list):
    ob = TLorentzVector(obj1[0].p)
    for o in obj1[1:]: ob+=o.p
    return ob.M()
  elif obj3 == 0: return (obj1.p+obj2.p).M() if not isinstance(obj1, TLorentzVector) else (obj1+obj2).M()
  else:           return (obj1.p+obj2.p+obj3.p).M() if not isinstance(obj1, TLorentzVector) else (obj1+obj2+ob3).M()
示例#8
0
def fill_mass_hist(collection, hist, norm_factor=1.0):
    v = TLorentzVector()
    for p in collection:
        if isinstance(p, TLorentzVector):
            v += p
        else:
            v += p.P4()
    hist.Fill(v.M() / norm_factor)
示例#9
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())
示例#10
0
def Return_Top(jet, id_csv, metPhi):

    masses = [-1000, -1000, -1000, -1000, -1000, -1000]

    b_tmp = TLorentzVector()
    b_tmp.SetPtEtaPhiE(jet[id_csv][0], jet[id_csv][1], jet[id_csv][2],
                       jet[id_csv][3])
    jet_nob = list(jet)
    jet_nob.pop(id_csv)

    j1dR_tmp = TLorentzVector()
    j1dR_tmp.SetPtEtaPhiE(0, 0, 0, 0)
    j2dR_tmp = TLorentzVector()
    j2dR_tmp.SetPtEtaPhiE(0, 0, 0, 0)

    a = list(combinations(jet_nob, 2))
    min_DeltaR = 1000

    for x in a:

        if x[0][0] < -5 or x[1][0] < -5: continue
        if x[0][1] < -5 or x[1][1] < -5: continue

        if (math.sqrt(
                math.pow((x[0][0] - x[1][0]), 2) +
                math.pow((x[0][1] - x[1][1]), 2)) < min_DeltaR):
            j1dR_tmp.SetPtEtaPhiE(x[0][0], x[0][1], x[0][2], x[0][3])
            j2dR_tmp.SetPtEtaPhiE(x[1][0], x[1][1], x[1][2], x[1][3])

    topdR_tmp = TLorentzVector()
    topdR_tmp = j1dR_tmp + j2dR_tmp + b_tmp

    WdR_tmp = TLorentzVector()
    WdR_tmp = j1dR_tmp + j2dR_tmp

    masses[0] = topdR_tmp.M()
    masses[1] = WdR_tmp.M()

    masses[2] = math.fabs(DeltaPhi(WdR_tmp.Phi(), b_tmp.Phi()))
    masses[3] = math.fabs(DeltaPhi(topdR_tmp.Phi(), b_tmp.Phi()))
    masses[4] = math.fabs(DeltaPhi(WdR_tmp.Phi(), metPhi))
    masses[5] = math.fabs(DeltaPhi(topdR_tmp.Phi(), metPhi))

    return masses
示例#11
0
    def read(self, iev):

        #read a given event

        if iev >= self.nev: return False

        self.tree.GetEntry(iev)

        #initialize event variables
        self.epos = 0.
        self.eneg = 0.

        self.npos = 0
        self.nneg = 0

        self.is_XnXn = False
        self.is_Cen = True

        vec = TLorentzVector()

        #particle loop
        for imc in xrange(self.particles.GetEntriesFast()):
            part = self.particles.At(imc)

            #central electron and positron
            if TMath.Abs(part.GetPdgCode()) == 11:
                if TMath.Abs(part.Eta()) > self.aeta_max: self.is_Cen = False
                #if part.P() < self.p_min: self.is_Cen = False
                pv = TLorentzVector()
                part.Momentum(pv)
                vec += pv

            #select the neutrons
            if part.GetPdgCode() != 2112: continue

            #energy at positive and negative rapidity
            if part.Eta() > 0:
                self.epos += part.Energy()
                self.npos += 1
            else:
                self.eneg += part.Energy()
                self.nneg += 1

        #particle loop

        #flag for XnXn event
        if self.npos > 0 and self.nneg > 0: self.is_XnXn = True

        #J/psi kinematics
        self.pT = vec.Pt()
        self.y = vec.Rapidity()
        self.m = vec.M()

        return True
示例#12
0
    def process(self, event):
        zed = getattr(event, self.cfg_ana.zeds)[0]
        particles = getattr(event, self.cfg_ana.particles)
        photons = [ptc for ptc in particles if ptc.pdgid() == 22]
        area = self.cfg_ana.area
        # sort photons according to distance to one of the leptons
        sorted_photons = []
        for photon in photons:
            if not area.is_inside(zed.leg1(), photon) and \
               not area.is_inside(zed.leg2(), photon):
                continue
            dr2_1 = deltaR2(photon, zed.leg1())
            dr2_2 = deltaR2(photon, zed.leg2())
            mindr2 = dr2_2
            leg = 1
            if dr2_1 < dr2_2:
                mindr2 = dr2_1
                leg = 0
            sorted_photons.append( (mindr2, leg, photon) )
            # print mindr2
            # print photon
            # pprint.pprint(zed.legs)
            # print
        sorted_photons.sort()
##        pprint.pprint(zed.legs)
##        pprint.pprint(sorted_photons)
##        print
        # loop on sorted photons and append to Z while Z mass
        # improved
        mz = 91.1876
        oldmass = zed.m()
        newzed = None
        for dummy, leg, photon in sorted_photons:
            # print photon
            newp4 = TLorentzVector(zed.p4())
            newp4 += photon.p4()
            newmass = newp4.M()
            # print oldmass, newmass
            if abs(newmass - mz) < abs(oldmass-mz):
                # print 'adding photon'
                if newzed is None:
                    if hasattr(self.cfg_ana, 'output'):
                        newzed = copy.deepcopy(zed)
                    else:
                        newzed = zed
                newzed._tlv = newp4
                newzed.legs[leg]._tlv += photon.p4()
                oldmass = newmass
                # need to change leg iso
        if hasattr(self.cfg_ana, 'output'):
            if newzed is None:
                newzed = zed
            setattr(event, self.cfg_ana.output, [newzed])
示例#13
0
def shiftMET():
    """Test function to see how one can apply a shift to the MET."""
    print ">>> create TLVs..."

    shift = 1.05  # 5%

    jet1 = TLorentzVector()
    jet2 = TLorentzVector()
    met = TLorentzVector()
    jet1.SetPtEtaPhiM(40.0, 1.5, 0.0, 4.0)
    jet2.SetPtEtaPhiM(30.0, -2.5, 1.5, 10.0)
    met.SetPtEtaPhiM(45.0, 0.0, -2.3, 0.0)
    printTLV(jet1, jet2, met, names=["tlv1", "tlv2", "met"], header=True)

    # SHIFT JET ENERGY
    jet1_shift = TLorentzVector()
    jet1_shift.SetPtEtaPhiM(shift * jet1.Pt(), jet1.Eta(), jet1.Phi(),
                            shift * jet1.M())
    jet2_shift = TLorentzVector()
    jet2_shift.SetPtEtaPhiM(shift * jet2.Pt(), jet2.Eta(), jet2.Phi(),
                            shift * jet2.M())
    #jet1_shift2 = shift*jet1
    #jet2_shift2 = shift*jet2
    printTLV(jet1_shift, jet2_shift, names=["jet1_shift", "jet2_shift"])

    # SHIFT MET
    dtlv = TLorentzVector()
    dtlv += (jet1 - jet1_shift)
    dtlv += (jet2 - jet2_shift)
    printTLV(dtlv, names=["dtlv"])

    met_shift1 = met - dtlv
    met_shift2 = TLorentzVector()
    met_shift2.SetPtEtaPhiM(met_shift1.Pt(), 0, met_shift1.Phi(), 0)

    printTLV(met_shift1, met_shift2, names=["met_shift1", "met_shift2"])
示例#14
0
def jet(entry, jetid, calibid):
    Pt = getattr(entry, "%s_%s_Pt" % (jetid, calibid))
    Eta = getattr(entry, "%s_%s_Eta" % (jetid, calibid))
    Phi = getattr(entry, "%s_%s_Phi" % (jetid, calibid))
    E = getattr(entry, "%s_%s_E" % (jetid, calibid))
    if debug:
        print "%s_%s_Pt", Pt % (jetid, calibid)
        print "%s_%s_Eta", Eta % (jetid, calibid)
        print "%s_%s_Phi", Phi % (jetid, calibid)
        print "%s_%s_E", E % (jetid, calibid)
    tlv = TLorentzVector()
    tlv.SetPtEtaPhiE(Pt, Eta, Phi, E)
    M = tlv.M()
    if debug:
        print "%s_%s_M", M % (jetid, calibid)
    return tlv, M
示例#15
0
文件: root.py 项目: Lenni/Studium
def main():

    #Aufgabenteil b)

    # initialisiere TLorentzVector-Objekt und setze Pt, eta, phi und M. Damit ist der Vierervektor vollstaendig bestimmt
    c_ = TLorentzVector()
    c_.SetPtEtaPhiM(99.83, 0.332, -2.45, 0)

    s = TLorentzVector()
    s.SetPtEtaPhiM(22.08, 0.137, 2.215, 0)

    ny = TLorentzVector()
    ny.SetPtEtaPhiM(44.73, 0, -2.472, 0)

    mu = TLorentzVector()
    mu.SetPtEtaPhiM(65.58, 1.08, -0.851, 0)

    wp = ny + mu

    # Addiere zwei Vierervektoren
    wm = c_ + s

    b = TLorentzVector()
    b_ = TLorentzVector()

    b_.SetPtEtaPhiM(74.01, 1.379, 0.494, 0)

    b.SetPtEtaPhiM(65.34, -0.228, 1.340, 0)

    t_ = wm + b_
    t = wp + b

    # Ausgabe der invarianten Masse eines Vierervektors
    print("Masse Anti-Top: " + str(t_.M()))
    print("Masse Top: " + str(t.M()))
    print(t_)

    # Aufgabenteil c)

    s = t + t_

    rapidity = 1 / 2 * math.log((s.E() + s.Pt()) / (s.E() - s.Pt()))

    print(s.M())
    print(s.Pt())
    print(s.E())
    print(rapidity)
示例#16
0
 def GeneratePrimaries(self, anEvent):
     global debug, nevTot
     t_0 = time.time()
     npart = 0
     while npart == 0:
         myPythia.GenerateEvent()
         nevTot += 1
         myTimer['pythia'] += time.time() - t_0
         # pythia interaction happens at 0,0,0
         #x = rnr.Uniform(-3.,3.)
         #y = rnr.Uniform(-3.,3.)
         # leave this smearing for later
         # create new primaries and set them to the vertex
         particles = myPythia.GetListOfParticles()
         z = rnr.Exp(10 * cm) - 50. * m  # tungsten interaction length
         ztarget = G4ThreeVector(0 * cm, 0 * cm, z)
         vertex = G4PrimaryVertex(ztarget, 0.)
         v = TLorentzVector()
         for p in particles:
             if p.GetStatusCode() != 1: continue
             pid = p.GetPdgCode()
             if tauOnly and abs(pid) != 16: continue
             mkey = p.GetMother(0) + 1
             mother = myPythia.GetParticle(mkey)
             if JpsiMainly and abs(
                     pid) != 13 and mother.GetPdgCode() != 443:
                 continue
             qed = pid in qedlist  # use cut only for photons, leptons/neutrinos, protons and neutrons
             p.Momentum(v)
             Ekin = (v.E() - v.M())
             if Ekin * GeV < ecut and (qed or allPart): continue
             G4particle = G4PrimaryParticle(pid)
             G4particle.Set4Momentum(v.Px() * GeV,
                                     v.Py() * GeV,
                                     v.Pz() * GeV,
                                     v.E() * GeV)
             # store mother ID
             curPid = p.GetPdgCode() + 10000  # make it positive
             moPid = mother.GetPdgCode() + 10000
             w = curPid + moPid * 100000
             G4particle.SetWeight(w)
             vertex.SetPrimary(G4particle)
             npart += 1
     # if debug: myPythia.EventListing()
     anEvent.AddPrimaryVertex(vertex)
     if debug: print 'new event at ', ztarget.z / m
     myTimer['geant4_conv'] += time.time() - t_0
示例#17
0
def Jets(jet, calib, entry):

    name = jet + "_" + calib + "_"
    Ptname = name + "Pt"
    Etaname = name + "Eta"
    Phiname = name + "Phi"
    Ename = name + "E"

    b_Pt = getattr(entry, Ptname)
    b_Eta = getattr(entry, Etaname)
    b_Phi = getattr(entry, Phiname)
    b_E = getattr(entry, Ename)

    b_tlv = TLorentzVector()
    b_tlv.SetPtEtaPhiE(b_Pt, b_Eta, b_Phi, b_E)
    b_M = b_tlv.M()

    return b_tlv
示例#18
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
示例#19
0
def TagVars(collections):
  results=[]; Et_ratio=[]; Dphi=[]; projB=[]; DzTagMuK=[]; DzTagMuL1=[]; 
  DzTagMuL2=[]; 
  tracks=collections[0]
  Bcands=collections[2]
  trgmuons=(collections[1])
  trgmuon_vec=TLorentzVector()
  trgmuon_vec.SetPtEtaPhiM(0,0,0,0)
  trgmuon_vz=-99
  for trgmuon in trgmuons:
    if not getattr(trgmuon,"isTriggering"): 
       continue;
    trgmuon_vec.SetPtEtaPhiM(getattr(trgmuon,"pt"),getattr(trgmuon,"eta"),getattr(trgmuon,"phi"),0.105)
    trgmuon_vz=getattr(trgmuon,"vz")
    break
  if trgmuon_vec.M()==0:
    result=[[0], [0], [0], [0], [0], [0]]
    return result
  sum_track_vec=trgmuon_vec;
  sum_track=trgmuon_vec.Pt();
  for track  in tracks:
    track_vec=TLorentzVector();
    track_vec.SetPtEtaPhiM(getattr(track,"pt"),getattr(track,"eta"),getattr(track,"phi"),0.139)
    if trgmuon_vec.DrEtaPhi(track_vec)>0.4: 
       continue
    sum_track_vec=sum_track_vec+track_vec;
    sum_track+=track_vec.Pt()

  for Bcand in Bcands:
    Bcand_vec=TLorentzVector();
    Bcand_vec.SetPtEtaPhiM(getattr(Bcand,"fit_pt"),getattr(Bcand,"fit_eta"),getattr(Bcand,"fit_phi"),getattr(Bcand,"fit_mass"))
    if sum_track>0:
      Et_ratio.append(Bcand_vec.Et()/sum_track)
    else:
      Et_ratio.append(0)
    Dphi.append(Bcand_vec.DeltaPhi(sum_track_vec))
    projB.append(Bcand_vec*sum_track_vec)   
    DzTagMuK.append( abs(trgmuon_vz-getattr(Bcand,"kVz")) )
    DzTagMuL1.append( abs(trgmuon_vz-getattr(Bcand,"l1Vz")) ) 
    DzTagMuL2.append( abs(trgmuon_vz-getattr(Bcand,"l2Vz")) )
    
 
  result=[Et_ratio, Dphi, projB, DzTagMuL1, DzTagMuL2, DzTagMuK]
  return result
 def processFatJets(self, jets):
     i = 0
     
     for item in jets:
         jetp4 = item.P4()
         softDrop = TLorentzVector() 
         softDrop = item.SoftDroppedJet
         self.fatjet_pt                     [i] = jetp4.Pt()
         self.fatjet_eta                    [i] = jetp4.Eta()
         self.fatjet_phi                    [i] = jetp4.Phi()
         self.fatjet_mass                   [i] = jetp4.M()
         self.fatjet_tau1                   [i] = item.Tau[0]            
         self.fatjet_tau2                   [i] = item.Tau[1]            
         self.fatjet_tau3                   [i] = item.Tau[2]            
         self.fatjet_tau4                   [i] = item.Tau[3]            
         self.fatjet_msoftdrop              [i] = softDrop.M()      
     
         i += 1
     self.fatjet_size[0] = i
示例#21
0
def TagVarsMC(collections):
  results=[]; Et_ratio=-99.; Dphi=-99.; projB=-99.
  tracks=collections[0]
  trgmuons=collections[1]
  recoB_pt=collections[2]
  recoB_eta=collections[3]
  recoB_phi=collections[4]
  recoB_mass=collections[5]
  recoE1_vz=collections[6]
  recoE2_vz=collections[7]
  recoK_vz=collections[8]
  trgmuon_vec=TLorentzVector()
  trgmuon_vec.SetPtEtaPhiM(0,0,0,0)
  for trgmuon in trgmuons:
    if getattr(trgmuon,"isTriggering")==0:
       continue
    trgmuon_vec.SetPtEtaPhiM(getattr(trgmuon,"pt"),getattr(trgmuon,"eta"),getattr(trgmuon,"phi"),0.105)
    break
  if trgmuon_vec.M()==0:
    result=[-99.,-99.,-99.,-99.,-99.,-99.]
    return result 
  sum_track_vec=trgmuon_vec;
  sum_track=trgmuon_vec.Pt();
  trgmuon_vz=getattr(trgmuon,"vz")
  for track  in tracks:
    track_vec=TLorentzVector();
    track_vec.SetPtEtaPhiM(getattr(track,"pt"),getattr(track,"eta"),getattr(track,"phi"),0.139)
    if trgmuon_vec.DrEtaPhi(track_vec)>0.4: 
       continue
    sum_track_vec=sum_track_vec+track_vec;
    sum_track+=track_vec.Pt()

  recoB_vec=TLorentzVector();
  recoB_vec.SetPtEtaPhiM(recoB_pt,recoB_eta,recoB_phi,recoB_mass)
  if sum_track>0:
    Et_ratio=recoB_vec.Et()/sum_track
  else:
    Et_ratio=0
  Dphi=recoB_vec.DeltaPhi(sum_track_vec)
  projB=recoB_vec*sum_track_vec
  result=[Et_ratio,Dphi,projB,abs(trgmuon_vz-recoE1_vz),abs(trgmuon_vz-recoE2_vz),abs(trgmuon_vz-recoK_vz)]
  return result
示例#22
0
def get_tlv(entry,b,scale,debug):
    if debug:
        print "get_tlv() for b",b," for scale",scale
    # jet 1
    prefix=b+"_"+scale+"_"
    Pt=getattr(entry,prefix+"Pt")
    Eta=getattr(entry,prefix+"Eta")
    Phi=getattr(entry,prefix+"Phi")
    E=getattr(entry,prefix+"E")
    if debug:
        print "Pt",Pt
        print "Eta",Eta
        print "Phi",Phi
        print "E",E
    tlv=TLorentzVector()
    tlv.SetPtEtaPhiE(Pt,Eta,Phi,E)
    M=tlv.M()
    if debug:
        print "M",M
    return tlv
示例#23
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
示例#24
0
def getGenZleptonPair(event,
                      muons=True,
                      electrons=True,
                      leptonPtCut=20,
                      leptonEtaCut=2.4):
    # get gen electrons and muons
    genElectrons = []
    genMuons = []
    for genPart in event.genParticles:
        if electrons and abs(genPart.pdgId()) == 11 and genPart.status(
        ) == 1 and genPart.pt() > leptonPtCut and abs(
                genPart.eta()) < leptonEtaCut:
            genElectrons.append(genPart)
        if muons and abs(genPart.pdgId()) == 13 and genPart.status(
        ) == 1 and genPart.pt() > leptonPtCut and abs(
                genPart.eta()) < leptonEtaCut:
            genMuons.append(genPart)
    # build pairs
    genZCandidates = []
    for lpair in itertools.chain(itertools.combinations(genElectrons, 2),
                                 itertools.combinations(genMuons, 2)):
        lepton1 = lpair[0]
        lepton2 = lpair[1]
        if lepton1.charge() != lepton2.charge():
            genZcandidate=TLorentzVector(lepton1.px(),lepton1.py(),lepton1.pz(),lepton1.energy()) + \
                          TLorentzVector(lepton2.px(),lepton2.py(),lepton2.pz(),lepton2.energy())
            if 76 <= genZcandidate.M() <= 106:
                genZCandidates.append((genZcandidate, lepton1, lepton2))
    # find best option based on the mass
    def massDiff(z):
        return abs(z[0].M() - 91.1876)

    if len(genZCandidates) > 0:
        return min(genZCandidates, key=massDiff)[1:]
    else:
        return None
示例#25
0
data['E_measure'] = np.sqrt(data.Px_measure**2 + data.Py_measure**2 +
                            data.Pz_measure**2)

num_bins = 75
fig = plt.figure(num=None,
                 figsize=(11, 8.5),
                 dpi=200,
                 facecolor='w',
                 edgecolor='k')

mom = 0
phi_mass = []
temp = TLorentzVector(0, 0, 0, 0)
for index, row in data.iterrows():
    if row.ID == 333:
        if temp.M() != 0 and temp.M() < 1.2:
            phi_mass.append(temp.M())
        temp.SetPxPyPzE(0, 0, 0, 0)
        mom = row['event']
    elif np.abs(row.ID) == 321 and row.mother == mom:
        temp = temp + TLorentzVector(row.Px, row.Py, row.Pz, row.E)

mass_sum = np.array(phi_mass)

n, bins, patches = plt.hist(mass_sum,
                            num_bins,
                            histtype=u'stepfilled',
                            facecolor='b',
                            alpha=0.5)

mom = 0
示例#26
0
def getVBSkin_resolved(vbsjets,
                       vjets,
                       lepton,
                       met,
                       reco_neutrino,
                       other_jets,
                       other_jets_ind,
                       debug=False):
    output = getDefault()
    # variables extraction
    total_vbs = TLorentzVector(0, 0, 0, 0)
    vbs_etas = []
    vbs_phis = []
    vbs_pts = []
    vbs_Es = []
    for i, j in enumerate(vbsjets):
        total_vbs += j
        vbs_etas.append(j.Eta())
        vbs_phis.append(j.Phi())
        vbs_pts.append(j.Pt())
        vbs_Es.append(j.E())
    if debug:
        print "VBS pts", vbs_pts
        print "VBS etas", vbs_etas
    deltaeta_vbs = abs(vbs_etas[0] - vbs_etas[1])
    mean_eta_vbs = sum(vbs_etas) / 2
    output["vbs_0_pt"] = vbs_pts[0]
    output["vbs_1_pt"] = vbs_pts[1]
    output["vbs_0_eta"] = abs(vbs_etas[0])
    output["vbs_1_eta"] = abs(vbs_etas[1])
    output["vbs_0_phi"] = abs(vbs_phis[0])
    output["vbs_1_phi"] = abs(vbs_phis[1])
    output["vbs_0_E"] = abs(vbs_Es[0])
    output["vbs_1_E"] = abs(vbs_Es[1])
    output["mjj_vbs"] = total_vbs.M()
    output["deltaeta_vbs"] = deltaeta_vbs
    output["deltaphi_vbs"] = abs(vbsjets[0].DeltaPhi(vbsjets[1]))
    output["deltaR_vbs"] = vbsjets[0].DrEtaPhi(vbsjets[1])

    total_vjet = TLorentzVector(0, 0, 0, 0)
    vjet_etas = []
    vjet_phis = []
    vjet_pts = []
    vjet_Es = []
    for i, j in enumerate(vjets):
        total_vjet += j
        vjet_etas.append(j.Eta())
        vjet_phis.append(j.Phi())
        vjet_pts.append(j.Pt())
        vjet_Es.append(j.E())
    if debug:
        print "Vjet pts", vjet_pts
        print "Vjet etas", vjet_etas
    output["vjet_0_pt"] = vjet_pts[0]
    output["vjet_1_pt"] = vjet_pts[1]
    output["vjet_0_eta"] = abs(vjet_etas[0])
    output["vjet_1_eta"] = abs(vjet_etas[1])
    output["vjet_0_phi"] = abs(vjet_phis[0])
    output["vjet_1_phi"] = abs(vjet_phis[1])
    output["vjet_0_E"] = abs(vjet_Es[0])
    output["vjet_1_E"] = abs(vjet_Es[1])
    output["mjj_vjet"] = total_vjet.M()
    output["deltaphi_vjet"] = abs(vjets[0].DeltaPhi(vjets[1]))
    output["deltaeta_vjet"] = abs(vjet_etas[0] - vjet_etas[1])
    output["deltaR_vjet"] = vjets[0].DrEtaPhi(vjets[1])

    output["recoMET"] = reco_neutrino.Pt()
    output["recoMET_pz"] = reco_neutrino.Pz()
    output["deltaphi_lep_nu"] = abs(lepton.DeltaPhi(reco_neutrino))
    output["deltaeta_lep_nu"] = abs(lepton.Eta() - reco_neutrino.Eta())
    output["deltaR_lep_nu"] = lepton.DrEtaPhi(reco_neutrino)
    # Delta Phi with lepton
    output["deltaphi_lep_vbs_0"] = abs(lepton.DeltaPhi(vbsjets[0]))
    output["deltaphi_lep_vbs_1"] = abs(lepton.DeltaPhi(vbsjets[1]))
    output["deltaphi_lep_vjet_0"] = abs(lepton.DeltaPhi(vjets[0]))
    output["deltaphi_lep_vjet_1"] = abs(lepton.DeltaPhi(vjets[1]))
    # Delta Eta with lepton
    output["deltaeta_lep_vbs_0"] = abs(lepton.Eta() - vbs_etas[0])
    output["deltaeta_lep_vbs_1"] = abs(lepton.Eta() - vbs_etas[1])
    output["deltaeta_lep_vjet_0"] = abs(lepton.Eta() - vjet_etas[0])
    output["deltaeta_lep_vjet_1"] = abs(lepton.Eta() - vjet_etas[1])
    # Look for nearest vbs jet from lepton
    output["deltaR_lep_vbs"] = min(
        [lepton.DrEtaPhi(vbsjets[0]),
         lepton.DrEtaPhi(vbsjets[1])])
    output["deltaR_lep_vjet"] = min(
        [lepton.DrEtaPhi(vjets[0]),
         lepton.DrEtaPhi(vjets[1])])
    # Zeppenfeld variables
    if deltaeta_vbs != 0:
        output["Zvjets_0"] = (vjet_etas[0] - mean_eta_vbs) / deltaeta_vbs
        output["Zvjets_1"] = (vjet_etas[1] - mean_eta_vbs) / deltaeta_vbs
        output["Zlep"] = (lepton.Eta() - mean_eta_vbs) / deltaeta_vbs
    #R variables
    ptvbs01 = vbsjets[0].Pt() * vbsjets[1].Pt()
    output["Rvjets_0"] = (lepton.Pt() * vjets[0].Pt()) / ptvbs01
    output["Rvjets_1"] = (lepton.Pt() * vjets[1].Pt()) / ptvbs01
    #Asymmetry
    output["Asym_vbs"] = (vbs_pts[0] - vbs_pts[1]) / sum(vbs_pts)
    output["Asym_vjet"] = (vjet_pts[0] - vjet_pts[1]) / sum(vjet_pts)
    #WW variables
    w_lep = lepton + reco_neutrino
    w_had = vjets[0] + vjets[1]
    w_lep_t = w_lep.Vect()
    w_lep_t.SetZ(0)
    w_had_t = w_had.Vect()
    w_had_t.SetZ(0)
    ww_vec = w_lep + w_had
    output["w_lep_pt"] = w_lep.Pt()
    output["Mw_lep"] = w_lep.M()
    #output["Mtw_lep"] = w_lep_t.M()
    output["Mtw_lep"] = sqrt(2 * lepton.Pt() * met.Pt() *
                             (1 - cos(lepton.DeltaPhi(met))))

    output["Mww"] = ww_vec.M()
    output["R_ww"] = (w_lep.Pt() * w_lep.Pt()) / ptvbs01
    output["R_mw"] = ww_vec.M() / ptvbs01
    output["A_ww"] = (w_lep_t + w_had_t).Pt() / (w_lep.Pt() + w_had.Pt())
    #Centrality
    eta_ww = (w_lep.Eta() + w_had.Eta()) / 2
    if deltaeta_vbs != 0.:
        output["Centr_vbs"] = abs(vbs_etas[0] - eta_ww -
                                  vbs_etas[1]) / deltaeta_vbs
    deltaeta_plus = max(vbs_etas) - max([w_lep.Eta(), w_had.Eta()])
    deltaeta_minus = min([w_lep.Eta(), w_had.Eta()]) - min(vbs_etas)
    output["Centr_ww"] = min([deltaeta_plus, deltaeta_minus])
    #Lepton projection
    lep_vec_t = lepton.Vect()
    lep_vec_t.SetZ(0)
    output["Lep_proj"] = (w_lep_t * lep_vec_t) / w_lep.Pt()
    output["Lep_projw"] = (w_lep_t * lep_vec_t) / (lepton.Pt() * w_lep.Pt())
    # Ht and number of jets with Pt> 20
    # using uncut jets
    Njets = len(other_jets)
    N_jets_forward = 0
    N_jets_central = 0
    for oj in other_jets:
        j_eta, j_pt = oj.Eta(), oj.Pt()
        # Looking only to jets != vbs & vjets
        if deltaeta_vbs != 0.:
            Z = abs((j_eta - mean_eta_vbs) / deltaeta_vbs)
            if Z > 0.5:
                N_jets_forward += 1
            else:
                N_jets_central += 1

    output["N_jets"] = Njets
    output["N_jets_central"] = N_jets_central
    output["N_jets_forward"] = N_jets_forward
    output["other_jets_index"] = other_jets_ind
    return output
示例#27
0
def save(f_in, t, cms, mode):
    m_runNo = array('i', [0])
    m_evtNo = array('i', [0])
    m_indexmc = array('i', [0])
    m_trkidx = array('i', 100 * [0])
    m_motheridx = array('i', 100 * [0])
    m_motherid = array('i', 100 * [0])
    m_pdgid = array('i', 100 * [0])
    m_D0_mode = array('d', [0])
    m_D0_type = array('d', [0])
    m_D0_charge = array('i', [0])
    m_D0_charm = array('d', [0])
    m_D0_numofchildren = array('d', [0])
    m_D0_mass = array('d', [0])
    m_p_D0 = array('d', [0])
    m_E_D0 = array('d', [0])
    m_n_D0trks = array('i', [0])
    m_n_D0shws = array('i', [0])
    m_Dm_mode = array('d', [0])
    m_Dm_type = array('d', [0])
    m_Dm_charge = array('i', [0])
    m_Dm_charm = array('d', [0])
    m_Dm_numofchildren = array('d', [0])
    m_Dm_mass = array('d', [0])
    m_p_Dm = array('d', [0])
    m_E_Dm = array('d', [0])
    m_n_Dmtrks = array('i', [0])
    m_n_Dmshws = array('i', [0])
    m_chi2_4c = array('d', [0.])
    m_chi2_vf = array('d', [0.])
    m_m_D0 = array('d', [0])
    m_m_Dm = array('d', [0])
    m_chi2_6c = array('d', [0.])
    m_m_D0Dm = array('d', [0])
    m_m_D0pip = array('d', [0])
    m_m_Dmpip = array('d', [0])
    m_rm_D0pip = array('d', [0])
    m_rm_Dmpip = array('d', [0])
    m_p4_D0 = array('d', 4 * [0])
    m_p4_Dm = array('d', 4 * [0])
    m_p4_pip = array('d', 4 * [0])
    m_Rxy_D0trks = array('d', 10 * [999.])
    m_Rz_D0trks = array('d', 10 * [999.])
    m_cos_D0trks = array('d', 10 * [999.])
    m_E_D0shws = array('d', 10 * [999.])
    m_dang_D0shws = array('d', 10 * [999.])
    m_module_D0shws = array('d', 10 * [999.])
    m_T_D0shws = array('d', 10 * [999.])
    m_Rxy_Dmtrks = array('d', 10 * [999.])
    m_Rz_Dmtrks = array('d', 10 * [999.])
    m_cos_Dmtrks = array('d', 10 * [999.])
    m_E_Dmshws = array('d', 10 * [999.])
    m_dang_Dmshws = array('d', 10 * [999.])
    m_module_Dmshws = array('d', 10 * [999.])
    m_T_Dmshws = array('d', 10 * [999.])
    m_Rxy_pip = array('d', [999.])
    m_Rz_pip = array('d', [999.])
    m_cos_pip = array('d', [999.])
    m_n_pi0 = array('i', [0])
    m_n_othershws = array('i', [0])
    m_matched_D0trks = array('i', [999])
    m_matched_D0shws = array('i', [999])
    m_matched_Dmtrks = array('i', [999])
    m_matched_Dmshws = array('i', [999])
    m_matched_pip = array('i', [999])
    m_m_delta = array('d', [0])
    m_p_pip = array('d', [0])
    m_chi2_svf_D0 = array('d', [999.])
    m_ctau_svf_D0 = array('d', [999.])
    m_L_svf_D0 = array('d', [999.])
    m_Lerr_svf_D0 = array('d', [999.])
    m_Lxy_svf_D0 = array('d', [999.])
    m_chi2_svf_Dm = array('d', [999.])
    m_ctau_svf_Dm = array('d', [999.])
    m_L_svf_Dm = array('d', [999.])
    m_Lerr_svf_Dm = array('d', [999.])
    m_Lxy_svf_Dm = array('d', [999.])
    t.Branch('runNo', m_runNo, 'm_runNo/I')
    t.Branch('evtNo', m_evtNo, 'm_evtNo/I')
    t.Branch('indexmc', m_indexmc, 'indexmc/I')
    t.Branch('trkidx', m_trkidx, 'trkidx[100]/I')
    t.Branch('motheridx', m_motheridx, 'motheridx[100]/I')
    t.Branch('motherid', m_motherid, 'motherid[100]/I')
    t.Branch('pdgid', m_pdgid, 'pdgid[100]/I')
    t.Branch('D0_mode', m_D0_mode, 'm_D0_mode/D')
    t.Branch('D0_type', m_D0_type, 'm_D0_type/D')
    t.Branch('D0_charge', m_D0_charge, 'm_D0_charge/I')
    t.Branch('D0_charm', m_D0_charm, 'm_D0_charm/D')
    t.Branch('D0_numofchildren', m_D0_numofchildren, 'm_D0_numofchildren/D')
    t.Branch('D0_mass', m_D0_mass, 'm_D0_mass/D')
    t.Branch('p_D0', m_p_D0, 'm_p_D0/D')
    t.Branch('E_D0', m_E_D0, 'm_E_D0/D')
    t.Branch('n_D0trks', m_n_D0trks, 'm_n_D0trks/D')
    t.Branch('n_D0shws', m_n_D0shws, 'm_n_D0shws/D')
    t.Branch('Dm_mode', m_Dm_mode, 'm_Dm_mode/D')
    t.Branch('Dm_type', m_Dm_type, 'm_Dm_type/D')
    t.Branch('Dm_charge', m_Dm_charge, 'm_Dm_charge/I')
    t.Branch('Dm_charm', m_Dm_charm, 'm_Dm_charm/D')
    t.Branch('Dm_numofchildren', m_Dm_numofchildren, 'm_Dm_numofchildren/D')
    t.Branch('Dm_mass', m_Dm_mass, 'm_Dm_mass/D')
    t.Branch('p_Dm', m_p_Dm, 'm_p_Dm/D')
    t.Branch('E_Dm', m_E_Dm, 'm_E_Dm/D')
    t.Branch('n_Dmtrks', m_n_Dmtrks, 'm_n_Dmtrks/D')
    t.Branch('n_Dmshws', m_n_Dmshws, 'm_n_Dmshws/D')
    t.Branch('chi2_4c', m_chi2_4c, 'm_chi2_4c/D')
    t.Branch('chi2_vf', m_chi2_vf, 'm_chi2_vf/D')
    t.Branch('m_D0', m_m_D0, 'm_m_D0/D')
    t.Branch('m_Dm', m_m_Dm, 'm_m_Dm/D')
    t.Branch('chi2_6c', m_chi2_6c, 'm_chi2_6c/D')
    t.Branch('m_D0Dm', m_m_D0Dm, 'm_m_D0Dm/D')
    t.Branch('m_D0pip', m_m_D0pip, 'm_m_D0pip/D')
    t.Branch('m_Dmpip', m_m_Dmpip, 'm_m_Dmpip/D')
    t.Branch('rm_D0pip', m_rm_D0pip, 'm_rm_D0pip/D')
    t.Branch('rm_Dmpip', m_rm_Dmpip, 'm_rm_Dmpip/D')
    t.Branch('p4_D0', m_p4_D0, 'm_p4_D0[4]/D')
    t.Branch('p4_Dm', m_p4_Dm, 'm_p4_Dm[4]/D')
    t.Branch('p4_pip', m_p4_pip, 'm_p4_pip[4]/D')
    t.Branch('Rxy_D0trks', m_Rxy_D0trks, 'm_Rxy_D0trks[10]/D')
    t.Branch('Rz_D0trks', m_Rz_D0trks, 'm_Rz_D0trks[10]/D')
    t.Branch('cos_D0trks', m_cos_D0trks, 'm_cos_D0trks[10]/D')
    t.Branch('E_D0shws', m_E_D0shws, 'm_E_D0shws[10]/D')
    t.Branch('dang_D0shws', m_dang_D0shws, 'm_dang_D0shws[10]/D')
    t.Branch('module_D0shws', m_module_D0shws, 'm_module_D0shws[10]/D')
    t.Branch('T_D0shws', m_T_D0shws, 'm_T_D0shws[10]/D')
    t.Branch('Rxy_Dmtrks', m_Rxy_Dmtrks, 'm_Rxy_Dmtrks[10]/D')
    t.Branch('Rz_Dmtrks', m_Rz_Dmtrks, 'm_Rz_Dmtrks[10]/D')
    t.Branch('cos_Dmtrks', m_cos_Dmtrks, 'm_cos_Dmtrks[10]/D')
    t.Branch('E_Dmshws', m_E_Dmshws, 'm_E_Dmshws[10]/D')
    t.Branch('dang_Dmshws', m_dang_Dmshws, 'm_dang_Dmshws[10]/D')
    t.Branch('module_Dmshws', m_module_Dmshws, 'm_module_Dmshws[10]/D')
    t.Branch('T_Dmshws', m_T_Dmshws, 'm_T_Dmshws[10]/D')
    t.Branch('Rxy_pip', m_Rxy_pip, 'm_Rxy_pip/D')
    t.Branch('Rz_pip', m_Rz_pip, 'm_Rz_pip/D')
    t.Branch('cos_pip', m_cos_pip, 'm_cos_pip/D')
    t.Branch('n_pi0', m_n_pi0, 'm_n_pi0/I')
    t.Branch('n_othershws', m_n_othershws, 'm_n_othershws/I')
    t.Branch('matched_D0trks', m_matched_D0trks, 'm_matched_D0trks/I')
    t.Branch('matched_D0shws', m_matched_D0shws, 'm_matched_D0shws/I')
    t.Branch('matched_Dmtrks', m_matched_Dmtrks, 'm_matched_Dmtrks/I')
    t.Branch('matched_Dmshws', m_matched_Dmshws, 'm_matched_Dmshws/I')
    t.Branch('matched_pip', m_matched_pip, 'm_matched_pip/I')
    t.Branch('m_delta', m_m_delta, 'm_m_delta/D')
    t.Branch('p_pip', m_p_pip, 'm_p_pip/D')
    t.Branch('chi2_svf_D0', m_chi2_svf_D0, 'm_chi2_svf_D0/D')
    t.Branch('ctau_svf_D0', m_ctau_svf_D0, 'm_ctau_svf_D0/D')
    t.Branch('L_svf_D0', m_L_svf_D0, 'm_L_svf_D0/D')
    t.Branch('Lerr_svf_D0', m_Lerr_svf_D0, 'm_Lerr_svf_D0/D')
    t.Branch('Lxy_svf_D0', m_Lxy_svf_D0, 'm_Lxy_svf_D0/D')
    t.Branch('chi2_svf_Dm', m_chi2_svf_Dm, 'm_chi2_svf_Dm/D')
    t.Branch('ctau_svf_Dm', m_ctau_svf_Dm, 'm_ctau_svf_Dm/D')
    t.Branch('L_svf_Dm', m_L_svf_Dm, 'm_L_svf_Dm/D')
    t.Branch('Lerr_svf_Dm', m_Lerr_svf_Dm, 'm_Lerr_svf_Dm/D')
    t.Branch('Lxy_svf_Dm', m_Lxy_svf_Dm, 'm_Lxy_svf_Dm/D')
    M_Dm = 1.86965
    M_D0 = 1.86483
    if mode == 'signal': t_dtd = f_in.Get('DTD_signal')
    if mode == 'side1_low': t_dtd = f_in.Get('DTD_side1_low')
    if mode == 'side1_up': t_dtd = f_in.Get('DTD_side1_up')
    if mode == 'side2_low': t_dtd = f_in.Get('DTD_side2_low')
    if mode == 'side2_up': t_dtd = f_in.Get('DTD_side2_up')
    if mode == 'side3_low': t_dtd = f_in.Get('DTD_side3_low')
    if mode == 'side3_up': t_dtd = f_in.Get('DTD_side3_up')
    if mode == 'side4_low': t_dtd = f_in.Get('DTD_side4_low')
    if mode == 'side4_up': t_dtd = f_in.Get('DTD_side4_up')
    nentries = t_dtd.GetEntries()
    for ientry in range(nentries):
        t_dtd.GetEntry(ientry)
        if t_dtd.D0_mode != 0 and t_dtd.D0_mode != 1 and t_dtd.D0_mode != 3:
            continue
        if t_dtd.Dm_mode != 200 and t_dtd.Dm_mode != 201 and t_dtd.Dm_mode != 202 and t_dtd.Dm_mode != 203 and t_dtd.Dm_mode != 204:
            continue
        ppip_raw = TLorentzVector(0, 0, 0, 0)
        ppip_raw.SetPxPyPzE(t_dtd.rawp4_tagPi[0], t_dtd.rawp4_tagPi[1],
                            t_dtd.rawp4_tagPi[2], t_dtd.rawp4_tagPi[3])
        E_Dm = 0
        pDm_raw = TLorentzVector(0, 0, 0, 0)
        m_matched_Dmtrks[0] = 1
        for iTrk in range(t_dtd.n_Dmtrks):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_dtd.rawp4_Dmtrks[iTrk * 8 + 0],
                                  t_dtd.rawp4_Dmtrks[iTrk * 8 + 1],
                                  t_dtd.rawp4_Dmtrks[iTrk * 8 + 2],
                                  t_dtd.rawp4_Dmtrks[iTrk * 8 + 3])
            pDm_raw += ptrack_raw
            E_Dm += t_dtd.rawp4_Dmtrks[iTrk * 8 + 3]
            if not t_dtd.rawp4_Dmtrks[iTrk * 8 + 6] == 1:
                m_matched_Dmtrks[0] = 0
        if t_dtd.n_Dmshws == 0: m_matched_Dmshws[0] = 0
        else: m_matched_Dmshws[0] = 1
        for iShw in range(t_dtd.n_Dmshws):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_dtd.rawp4_Dmshws[iShw * 6 + 0],
                                   t_dtd.rawp4_Dmshws[iShw * 6 + 1],
                                   t_dtd.rawp4_Dmshws[iShw * 6 + 2],
                                   t_dtd.rawp4_Dmshws[iShw * 6 + 3])
            pDm_raw += pshower_raw
            E_Dm += t_dtd.rawp4_Dmshws[iShw * 6 + 3]
            if not t_dtd.rawp4_Dmshws[iShw * 6 + 4] == 1:
                m_matched_Dmshws[0] = 0
        E_D0 = 0
        pD0_raw = TLorentzVector(0, 0, 0, 0)
        m_matched_D0trks[0] = 1
        for iTrk in range(t_dtd.n_D0trks):
            ptrack_raw = TLorentzVector(0, 0, 0, 0)
            ptrack_raw.SetPxPyPzE(t_dtd.rawp4_D0trks[iTrk * 8 + 0],
                                  t_dtd.rawp4_D0trks[iTrk * 8 + 1],
                                  t_dtd.rawp4_D0trks[iTrk * 8 + 2],
                                  t_dtd.rawp4_D0trks[iTrk * 8 + 3])
            pD0_raw += ptrack_raw
            E_D0 += t_dtd.rawp4_D0trks[iTrk * 8 + 3]
            if not t_dtd.rawp4_D0trks[iTrk * 8 + 6] == 1:
                m_matched_D0trks[0] = 0
        if t_dtd.n_D0shws == 0: m_matched_D0shws[0] = 0
        else: m_matched_D0shws[0] = 1
        for iShw in range(t_dtd.n_D0shws):
            pshower_raw = TLorentzVector(0, 0, 0, 0)
            pshower_raw.SetPxPyPzE(t_dtd.rawp4_D0shws[iShw * 6 + 0],
                                   t_dtd.rawp4_D0shws[iShw * 6 + 1],
                                   t_dtd.rawp4_D0shws[iShw * 6 + 2],
                                   t_dtd.rawp4_D0shws[iShw * 6 + 3])
            pD0_raw += pshower_raw
            E_D0 += t_dtd.rawp4_D0shws[iShw * 6 + 3]
            if not t_dtd.rawp4_D0shws[iShw * 6 + 4] == 1:
                m_matched_D0shws[0] = 0
        m_matched_pip[0] = 1
        if not t_dtd.rawp4_tagPi[4] == 1:
            m_matched_pip[0] = 0
        pD0_4c = TLorentzVector(0, 0, 0, 0)
        pDm_4c = TLorentzVector(0, 0, 0, 0)
        ppip_4c = TLorentzVector(0, 0, 0, 0)
        ppip_raw = TLorentzVector(0, 0, 0, 0)
        ppip_raw.SetPxPyPzE(t_dtd.rawp4_tagPi[0], t_dtd.rawp4_tagPi[1],
                            t_dtd.rawp4_tagPi[2], t_dtd.rawp4_tagPi[3])
        pD0_4c.SetPxPyPzE(t_dtd.p4_D0_4c[0], t_dtd.p4_D0_4c[1],
                          t_dtd.p4_D0_4c[2], t_dtd.p4_D0_4c[3])
        pDm_4c.SetPxPyPzE(t_dtd.p4_Dm_4c[0], t_dtd.p4_Dm_4c[1],
                          t_dtd.p4_Dm_4c[2], t_dtd.p4_Dm_4c[3])
        ppip_4c.SetPxPyPzE(t_dtd.p4_pip_4c[0], t_dtd.p4_pip_4c[1],
                           t_dtd.p4_pip_4c[2], t_dtd.p4_pip_4c[3])
        m_runNo[0] = t_dtd.runNo
        m_evtNo[0] = t_dtd.evtNo
        m_indexmc[0] = t_dtd.indexmc
        for i in range(t_dtd.indexmc):
            m_motheridx[i] = t_dtd.motheridx[i]
            m_motherid[i] = t_dtd.motherid[i]
            m_pdgid[i] = t_dtd.pdgid[i]
            m_trkidx[i] = t_dtd.trkidx[i]
        m_D0_mode[0] = t_dtd.D0_mode
        m_D0_type[0] = t_dtd.D0_type
        m_D0_charge[0] = t_dtd.D0_dcharge
        m_D0_charm[0] = t_dtd.D0_charm
        m_D0_numofchildren[0] = t_dtd.D0_numofchildren
        m_D0_mass[0] = t_dtd.D0_mass
        m_p_D0[0] = pD0_raw.P()
        m_E_D0[0] = E_D0
        m_n_D0trks[0] = t_dtd.n_D0trks
        m_n_D0shws[0] = t_dtd.n_D0shws
        m_Dm_mode[0] = t_dtd.Dm_mode
        m_Dm_type[0] = t_dtd.Dm_type
        m_Dm_charge[0] = t_dtd.Dm_dcharge
        m_Dm_charm[0] = t_dtd.Dm_charm
        m_Dm_numofchildren[0] = t_dtd.Dm_numofchildren
        m_Dm_mass[0] = t_dtd.Dm_mass
        m_p_Dm[0] = pDm_raw.P()
        m_E_Dm[0] = E_Dm
        m_n_Dmtrks[0] = t_dtd.n_Dmtrks
        m_n_Dmshws[0] = t_dtd.n_Dmshws
        m_chi2_4c[0] = t_dtd.chisq_4c
        m_m_D0[0] = pD0_4c.M()
        m_m_Dm[0] = pDm_4c.M()
        m_rm_D0pip[0] = (cms - pD0_4c - ppip_4c).M()
        m_rm_Dmpip[0] = (cms - pDm_4c - ppip_4c).M()
        for i in range(4):
            m_p4_D0[i] = t_dtd.p4_D0_6c[i]
            m_p4_Dm[i] = t_dtd.p4_Dm_6c[i]
            m_p4_pip[i] = t_dtd.p4_pip_6c[i]
        m_Rxy_pip[0] = t_dtd.vtx_tagPi[0]
        m_Rz_pip[0] = t_dtd.vtx_tagPi[1]
        m_cos_pip[0] = t_dtd.vtx_tagPi[2]
        for itrk in xrange(t_dtd.n_D0trks):
            m_Rxy_D0trks[itrk] = abs(t_dtd.vtx_D0trks[itrk * 3 + 0])
            m_Rz_D0trks[itrk] = abs(t_dtd.vtx_D0trks[itrk * 3 + 1])
            m_cos_D0trks[itrk] = abs(t_dtd.vtx_D0trks[itrk * 3 + 2])
        for ishw in xrange(t_dtd.n_D0shws):
            m_E_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 0])
            m_dang_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 3])
            m_module_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 4])
            m_T_D0shws[ishw] = abs(t_dtd.vtx_D0shws[ishw * 6 + 5])
        for itrk in xrange(t_dtd.n_Dmtrks):
            m_Rxy_Dmtrks[itrk] = abs(t_dtd.vtx_Dmtrks[itrk * 3 + 0])
            m_Rz_Dmtrks[itrk] = abs(t_dtd.vtx_Dmtrks[itrk * 3 + 1])
            m_cos_Dmtrks[itrk] = abs(t_dtd.vtx_Dmtrks[itrk * 3 + 2])
        for ishw in xrange(t_dtd.n_Dmshws):
            m_E_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 0])
            m_dang_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 3])
            m_module_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 4])
            m_T_Dmshws[ishw] = abs(t_dtd.vtx_Dmshws[ishw * 6 + 5])
        m_n_pi0[0] = t_dtd.n_pi0
        shw_status = True
        n_othershws = 0
        for iShw in range(t_dtd.n_othershws):
            if abs(t_dtd.vtx_othershws[iShw * 6 + 3]) < 10.:
                shw_status = False
            if t_dtd.vtx_othershws[iShw * 6 +
                                   5] < 0. or t_dtd.vtx_othershws[iShw * 6 +
                                                                  5] > 14:
                shw_status = False
            if t_dtd.vtx_othershws[iShw * 6 +
                                   4] == 1 and t_dtd.vtx_othershws[iShw * 6 +
                                                                   0] < 0.025:
                shw_status = False
            if (t_dtd.vtx_othershws[iShw * 6 + 4] == 0
                    or t_dtd.vtx_othershws[iShw * 6 + 4]
                    == 2) and t_dtd.vtx_othershws[iShw * 6 + 0] < 0.05:
                shw_status = False
            if shw_status:
                n_othershws += 1
        m_n_othershws[0] = n_othershws
        D0_W = width('D0')
        Dm_W = width('Dm')
        D0_signal_low = 1.86483 - D0_W / 2.
        D0_signal_up = 1.86483 + D0_W / 2.
        D0_sidebandlow_up = D0_signal_low - D0_W
        D0_sidebandlow_low = D0_signal_low - 2. * D0_W
        D0_sidebandup_low = D0_signal_up + D0_W
        D0_sidebandup_up = D0_signal_up + 2. * D0_W
        Dm_signal_low = 1.86965 - Dm_W / 2.
        Dm_signal_up = 1.86965 + Dm_W / 2.
        Dm_sidebandlow_up = Dm_signal_low - Dm_W
        Dm_sidebandlow_low = Dm_signal_low - 2. * Dm_W
        Dm_sidebandup_low = Dm_signal_up + Dm_W
        Dm_sidebandup_up = Dm_signal_up + 2. * Dm_W
        if mode == 'signal':
            M_D0 = (D0_signal_low + D0_signal_up) / 2.
            M_Dm = (Dm_signal_low + Dm_signal_up) / 2.
        if mode == 'side1_low':
            M_D0 = (D0_signal_low + D0_signal_up) / 2.
            M_Dm = (Dm_sidebandlow_low + Dm_sidebandlow_up) / 2.
        if mode == 'side1_up':
            M_D0 = (D0_signal_low + D0_signal_up) / 2.
            M_Dm = (Dm_sidebandup_low + Dm_sidebandup_up) / 2.
        if mode == 'side2_low':
            M_D0 = (D0_sidebandlow_low + D0_sidebandlow_up) / 2.
            M_Dm = (Dm_signal_low + Dm_signal_up) / 2.
        if mode == 'side2_up':
            M_D0 = (D0_sidebandup_low + D0_sidebandup_up) / 2.
            M_Dm = (Dm_signal_low + Dm_signal_up) / 2.
        if mode == 'side3_low':
            M_D0 = (D0_sidebandlow_low + D0_sidebandlow_up) / 2.
            M_Dm = (Dm_sidebandlow_low + Dm_sidebandlow_up) / 2.
        if mode == 'side3_up':
            M_D0 = (D0_sidebandlow_low + D0_sidebandlow_up) / 2.
            M_Dm = (Dm_sidebandup_low + Dm_sidebandup_up) / 2.
        if mode == 'side4_low':
            M_D0 = (D0_sidebandup_low + D0_sidebandup_up) / 2.
            M_Dm = (Dm_sidebandlow_low + Dm_sidebandlow_up) / 2.
        if mode == 'side4_up':
            M_D0 = (D0_sidebandup_low + D0_sidebandup_up) / 2.
            M_Dm = (Dm_sidebandup_low + Dm_sidebandup_up) / 2.
        m_m_delta[0] = abs(t_dtd.D0_mass - M_D0) + abs(t_dtd.Dm_mass - M_Dm)
        pD0_6c = TLorentzVector(0, 0, 0, 0)
        pDm_6c = TLorentzVector(0, 0, 0, 0)
        ppip_6c = TLorentzVector(0, 0, 0, 0)
        pD0_6c.SetPxPyPzE(t_dtd.p4_D0_6c[0], t_dtd.p4_D0_6c[1],
                          t_dtd.p4_D0_6c[2], t_dtd.p4_D0_6c[3])
        pDm_6c.SetPxPyPzE(t_dtd.p4_Dm_6c[0], t_dtd.p4_Dm_6c[1],
                          t_dtd.p4_Dm_6c[2], t_dtd.p4_Dm_6c[3])
        ppip_6c.SetPxPyPzE(t_dtd.p4_pip_6c[0], t_dtd.p4_pip_6c[1],
                           t_dtd.p4_pip_6c[2], t_dtd.p4_pip_6c[3])
        m_chi2_6c[0] = t_dtd.chisq_6c
        m_chi2_vf[0] = t_dtd.chisq_vf
        m_m_D0Dm[0] = (pD0_6c + pDm_6c).M()
        m_m_D0pip[0] = (pD0_6c + ppip_6c).M()
        m_m_Dmpip[0] = (pDm_6c + ppip_6c).M()
        m_p_pip[0] = ppip_raw.P()
        m_chi2_svf_D0[0] = t_dtd.chisq_svf_D0
        m_ctau_svf_D0[0] = t_dtd.ctau_svf_D0
        m_L_svf_D0[0] = t_dtd.L_svf_D0
        m_Lerr_svf_D0[0] = t_dtd.Lerr_svf_D0
        m_Lxy_svf_D0[0] = sqrt((t_dtd.vtx[0] - t_dtd.cp_D0[0])**2 +
                               (t_dtd.vtx[1] - t_dtd.cp_D0[1])**2)
        m_chi2_svf_Dm[0] = t_dtd.chisq_svf_Dm
        m_ctau_svf_Dm[0] = t_dtd.ctau_svf_Dm
        m_L_svf_Dm[0] = t_dtd.L_svf_Dm
        m_Lerr_svf_Dm[0] = t_dtd.Lerr_svf_Dm
        m_Lxy_svf_Dm[0] = sqrt((t_dtd.vtx[0] - t_dtd.cp_Dm[0])**2 +
                               (t_dtd.vtx[1] - t_dtd.cp_Dm[1])**2)
        t.Fill()
示例#28
0
def readTree(fileName, outputfileName):
    # open file
    file = TFile(fileName, "READ")
    if not file.IsOpen():
        print("File", fileName, "does not exist. WILL ABORT!!!")
        assert (False)
    # open tree
    tree = file.Get(treeName)
    if tree == None:
        print("tree", treeName, "doesn't exist in file", fileName,
              ". WILL ABORT!!!")
        assert (False)
    # determine how many entries to run on
    nrEntries = tree.GetEntries()
    print("Number of Entries", nrEntries)
    if desiredNrEntries < 0 or desiredNrEntries > nrEntries:
        actualNrEntries = nrEntries
    else:
        actualNrEntries = desiredNrEntries
    if debug:
        print("We will run over", actualNrEntries, "entries.")

    # we create a file to store histograms
    outputfile = TFile(outputfileName, "RECREATE")

    hist_Higgs_Nominal_M = TH1F("Higgs_Nominal_M", "Higgs_Nominal_M", 40, 48.5,
                                168.5)
    hist_Higgs_OneMu_M = TH1F("Higgs_OneMu_M", "Higgs_OneMu_M", 40, 48.5,
                              168.5)
    hist_Higgs_PtRecoGauss_M = TH1F("Higgs_PtRecoGauss_M",
                                    "Higgs_PtRecoGauss_M", 40, 48.5, 168.5)
    hist_Higgs_PtRecoBukin_M = TH1F("Higgs_PtRecoBukin_M",
                                    "Higgs_PtRecoBukin_M", 40, 48.5, 168.5)
    hist_Higgs_Parton_M = TH1F("Higgs_Parton_M", "Higgs_Parton_M", 40, 48.5,
                               168.5)
    hist_Higgs_AllMuNu_M = TH1F("Higgs_AllMuNu_M", "Higgs_AllMuNu_M", 40, 48.5,
                                168.5)
    hist_Higgs_TruthWZ_M = TH1F("Higgs_TruthWZ_M", "Higgs_TruthWZ_M", 40, 48.5,
                                168.5)
    hist_Higgs_AllMu_M = TH1F("Higgs_AllMu_M", "Higgs_AllMu_M", 40, 48.5,
                              168.5)
    hist_Higgs_Regression_M = TH1F("Higgs_Regression_M", "Higgs_Regression_M",
                                   40, 48.5, 168.5)
    hist_Higgs_OneMuNu_M = TH1F("Higgs_OneMuNu_M", "Higgs_OneMuNu_M", 40, 48.5,
                                168.5)

    # run over the entries of the tree
    # unlike in C++, no need to define the branches in advance
    for i, entry in enumerate(tree):
        if i >= actualNrEntries:
            continue
        if debug or i % 1000 == 0:
            print("******* new entry", i, " **********")

        # we are looping over jets, each has the information of Pt, Eta, Phi, E
        # they are available at different calibration stages:
        # Nominal, OneMu, PtRecoBukin, PtRecoGauss, Regression
        # we also know what is the correct simulated information: Parton
        # we want to compare the different calibrations and see which one
        # models better the Higgs boson mass
        # all Pt, E, M are in GeV
        # Higgs -> bb, meaning the b1 and b2 in this tree
        # let's see how we get a variable from the tree
        # jet 1
        b1_Nominal_Pt = getattr(entry, "b1_Nominal_Pt")
        b1_Nominal_Eta = getattr(entry, "b1_Nominal_Eta")
        b1_Nominal_Phi = getattr(entry, "b1_Nominal_Phi")
        b1_Nominal_E = getattr(entry, "b1_Nominal_E")

        b1_OneMu_Pt = getattr(entry, "b1_OneMu_Pt")
        b1_OneMu_Eta = getattr(entry, "b1_OneMu_Eta")
        b1_OneMu_Phi = getattr(entry, "b1_OneMu_Phi")
        b1_OneMu_E = getattr(entry, "b1_OneMu_E")

        b1_PtRecoGauss_Pt = getattr(entry, "b1_PtRecoGauss_Pt")
        b1_PtRecoGauss_Eta = getattr(entry, "b1_PtRecoGauss_Eta")
        b1_PtRecoGauss_Phi = getattr(entry, "b1_PtRecoGauss_Phi")
        b1_PtRecoGauss_E = getattr(entry, "b1_PtRecoGauss_E")

        b1_PtRecoBukin_Pt = getattr(entry, "b1_PtRecoBukin_Pt")
        b1_PtRecoBukin_Eta = getattr(entry, "b1_PtRecoBukin_Eta")
        b1_PtRecoBukin_Phi = getattr(entry, "b1_PtRecoBukin_Phi")
        b1_PtRecoBukin_E = getattr(entry, "b1_PtRecoBukin_E")

        b1_Parton_Pt = getattr(entry, "b1_Parton_Pt")
        b1_Parton_Eta = getattr(entry, "b1_Parton_Eta")
        b1_Parton_Phi = getattr(entry, "b1_Parton_Phi")
        b1_Parton_E = getattr(entry, "b1_Parton_E")

        b1_AllMuNu_Pt = getattr(entry, "b1_AllMuNu_Pt")
        b1_AllMuNu_Eta = getattr(entry, "b1_AllMuNu_Eta")
        b1_AllMuNu_Phi = getattr(entry, "b1_AllMuNu_Phi")
        b1_AllMuNu_E = getattr(entry, "b1_AllMuNu_E")

        b1_TruthWZ_Pt = getattr(entry, "b1_TruthWZ_Pt")
        b1_TruthWZ_Eta = getattr(entry, "b1_TruthWZ_Eta")
        b1_TruthWZ_Phi = getattr(entry, "b1_TruthWZ_Phi")
        b1_TruthWZ_E = getattr(entry, "b1_TruthWZ_E")

        b1_AllMu_Pt = getattr(entry, "b1_AllMu_Pt")
        b1_AllMu_Eta = getattr(entry, "b1_AllMu_Eta")
        b1_AllMu_Phi = getattr(entry, "b1_AllMu_Phi")
        b1_AllMu_E = getattr(entry, "b1_AllMu_E")

        b1_Regression_Pt = getattr(entry, "b1_Regression_Pt")
        b1_Regression_Eta = getattr(entry, "b1_Regression_Eta")
        b1_Regression_Phi = getattr(entry, "b1_Regression_Phi")
        b1_Regression_E = getattr(entry, "b1_Regression_E")

        b1_OneMuNu_Pt = getattr(entry, "b1_OneMuNu_Pt")
        b1_OneMuNu_Eta = getattr(entry, "b1_OneMuNu_Eta")
        b1_OneMuNu_Phi = getattr(entry, "b1_OneMuNu_Phi")
        b1_OneMuNu_E = getattr(entry, "b1_OneMuNu_E")

        if debug:
            print("b1_Nominal_Pt", b1_Nominal_Pt)
            print("b1_Nominal_Eta", b1_Nominal_Eta)
            print("b1_Nominal_Phi", b1_Nominal_Phi)
            print("b1_Nominal_E", b1_Nominal_E)

        b1_Nominal_tlv = TLorentzVector()
        b1_Nominal_tlv.SetPtEtaPhiE(b1_Nominal_Pt, b1_Nominal_Eta,
                                    b1_Nominal_Phi, b1_Nominal_E)
        b1_Nominal_M = b1_Nominal_tlv.M()

        b1_OneMu_tlv = TLorentzVector()
        b1_OneMu_tlv.SetPtEtaPhiE(b1_OneMu_Pt, b1_OneMu_Eta, b1_OneMu_Phi,
                                  b1_OneMu_E)
        b1_OneMu_M = b1_OneMu_tlv.M()

        b1_PtRecoGauss_tlv = TLorentzVector()
        b1_PtRecoGauss_tlv.SetPtEtaPhiE(b1_PtRecoGauss_Pt, b1_PtRecoGauss_Eta,
                                        b1_PtRecoGauss_Phi, b1_PtRecoGauss_E)
        b1_PtRecoGauss_M = b1_PtRecoGauss_tlv.M()

        b1_PtRecoBukin_tlv = TLorentzVector()
        b1_PtRecoBukin_tlv.SetPtEtaPhiE(b1_PtRecoBukin_Pt, b1_PtRecoBukin_Eta,
                                        b1_PtRecoBukin_Phi, b1_PtRecoBukin_E)
        b1_PtRecoBukin_M = b1_PtRecoBukin_tlv.M()

        b1_Parton_tlv = TLorentzVector()
        b1_Parton_tlv.SetPtEtaPhiE(b1_Parton_Pt, b1_Parton_Eta, b1_Parton_Phi,
                                   b1_Parton_E)
        b1_Parton_M = b1_PtRecoGauss_tlv.M()

        b1_AllMuNu_tlv = TLorentzVector()
        b1_AllMuNu_tlv.SetPtEtaPhiE(b1_AllMuNu_Pt, b1_AllMuNu_Eta,
                                    b1_AllMuNu_Phi, b1_AllMuNu_E)
        b1_AllMuNu_M = b1_PtRecoGauss_tlv.M()

        b1_TruthWZ_tlv = TLorentzVector()
        b1_TruthWZ_tlv.SetPtEtaPhiE(b1_TruthWZ_Pt, b1_TruthWZ_Eta,
                                    b1_TruthWZ_Phi, b1_TruthWZ_E)
        b1_TruthWZ_M = b1_TruthWZ_tlv.M()

        b1_AllMu_tlv = TLorentzVector()
        b1_AllMu_tlv.SetPtEtaPhiE(b1_AllMu_Pt, b1_AllMu_Eta, b1_AllMu_Phi,
                                  b1_AllMu_E)
        b1_AllMu_M = b1_PtRecoGauss_tlv.M()

        b1_Regression_tlv = TLorentzVector()
        b1_Regression_tlv.SetPtEtaPhiE(b1_Regression_Pt, b1_Regression_Eta,
                                       b1_Regression_Phi, b1_Regression_E)
        b1_Regression_M = b1_PtRecoGauss_tlv.M()

        b1_OneMuNu_tlv = TLorentzVector()
        b1_OneMuNu_tlv.SetPtEtaPhiE(b1_OneMuNu_Pt, b1_OneMuNu_Eta,
                                    b1_OneMuNu_Phi, b1_OneMuNu_E)
        b1_OneMuNu_M = b1_PtRecoGauss_tlv.M()

        if debug:
            print("b1_Nominal_M", b1_Nominal_M)

        # jet 2
        b2_Nominal_Pt = getattr(entry, "b2_Nominal_Pt")
        b2_Nominal_Eta = getattr(entry, "b2_Nominal_Eta")
        b2_Nominal_Phi = getattr(entry, "b2_Nominal_Phi")
        b2_Nominal_E = getattr(entry, "b2_Nominal_E")

        b2_OneMu_Pt = getattr(entry, "b2_OneMu_Pt")
        b2_OneMu_Eta = getattr(entry, "b2_OneMu_Eta")
        b2_OneMu_Phi = getattr(entry, "b2_OneMu_Phi")
        b2_OneMu_E = getattr(entry, "b2_OneMu_E")

        b2_PtRecoGauss_Pt = getattr(entry, "b2_PtRecoGauss_Pt")
        b2_PtRecoGauss_Eta = getattr(entry, "b2_PtRecoGauss_Eta")
        b2_PtRecoGauss_Phi = getattr(entry, "b2_PtRecoGauss_Phi")
        b2_PtRecoGauss_E = getattr(entry, "b2_PtRecoGauss_E")

        b2_PtRecoBukin_Pt = getattr(entry, "b2_PtRecoBukin_Pt")
        b2_PtRecoBukin_Eta = getattr(entry, "b2_PtRecoBukin_Eta")
        b2_PtRecoBukin_Phi = getattr(entry, "b2_PtRecoBukin_Phi")
        b2_PtRecoBukin_E = getattr(entry, "b2_PtRecoBukin_E")

        b2_Parton_Pt = getattr(entry, "b2_Parton_Pt")
        b2_Parton_Eta = getattr(entry, "b2_Parton_Eta")
        b2_Parton_Phi = getattr(entry, "b2_Parton_Phi")
        b2_Parton_E = getattr(entry, "b2_Parton_E")

        b2_AllMuNu_Pt = getattr(entry, "b2_AllMuNu_Pt")
        b2_AllMuNu_Eta = getattr(entry, "b2_AllMuNu_Eta")
        b2_AllMuNu_Phi = getattr(entry, "b2_AllMuNu_Phi")
        b2_AllMuNu_E = getattr(entry, "b2_AllMuNu_E")

        b2_TruthWZ_Pt = getattr(entry, "b2_TruthWZ_Pt")
        b2_TruthWZ_Eta = getattr(entry, "b2_TruthWZ_Eta")
        b2_TruthWZ_Phi = getattr(entry, "b2_TruthWZ_Phi")
        b2_TruthWZ_E = getattr(entry, "b2_TruthWZ_E")

        b2_AllMu_Pt = getattr(entry, "b2_AllMu_Pt")
        b2_AllMu_Eta = getattr(entry, "b2_AllMu_Eta")
        b2_AllMu_Phi = getattr(entry, "b2_AllMu_Phi")
        b2_AllMu_E = getattr(entry, "b2_AllMu_E")

        b2_Regression_Pt = getattr(entry, "b2_Regression_Pt")
        b2_Regression_Eta = getattr(entry, "b2_Regression_Eta")
        b2_Regression_Phi = getattr(entry, "b2_Regression_Phi")
        b2_Regression_E = getattr(entry, "b2_Regression_E")

        b2_OneMuNu_Pt = getattr(entry, "b2_OneMuNu_Pt")
        b2_OneMuNu_Eta = getattr(entry, "b2_OneMuNu_Eta")
        b2_OneMuNu_Phi = getattr(entry, "b2_OneMuNu_Phi")
        b2_OneMuNu_E = getattr(entry, "b2_OneMuNu_E")

        if debug:
            print("b2_Nominal_Pt", b2_Nominal_Pt)
            print("b2_Nominal_Eta", b2_Nominal_Eta)
            print("b2_Nominal_Phi", b2_Nominal_Phi)
            print("b2_Nominal_E", b2_Nominal_E)

        b2_Nominal_tlv = TLorentzVector()
        b2_Nominal_tlv.SetPtEtaPhiE(b2_Nominal_Pt, b2_Nominal_Eta,
                                    b2_Nominal_Phi, b2_Nominal_E)
        b2_Nominal_M = b2_Nominal_tlv.M()

        b2_OneMu_tlv = TLorentzVector()
        b2_OneMu_tlv.SetPtEtaPhiE(b2_OneMu_Pt, b2_OneMu_Eta, b2_OneMu_Phi,
                                  b2_OneMu_E)
        b2_OneMu_M = b2_OneMu_tlv.M()

        b2_PtRecoGauss_tlv = TLorentzVector()
        b2_PtRecoGauss_tlv.SetPtEtaPhiE(b2_PtRecoGauss_Pt, b2_PtRecoGauss_Eta,
                                        b2_PtRecoGauss_Phi, b2_PtRecoGauss_E)
        b2_PtRecoGauss_M = b2_PtRecoGauss_tlv.M()

        b2_PtRecoBukin_tlv = TLorentzVector()
        b2_PtRecoBukin_tlv.SetPtEtaPhiE(b2_PtRecoBukin_Pt, b2_PtRecoBukin_Eta,
                                        b2_PtRecoBukin_Phi, b2_PtRecoBukin_E)
        b2_PtRecoBukin_M = b2_PtRecoBukin_tlv.M()

        b2_Parton_tlv = TLorentzVector()
        b2_Parton_tlv.SetPtEtaPhiE(b2_Parton_Pt, b2_Parton_Eta, b2_Parton_Phi,
                                   b2_Parton_E)
        b2_Parton_M = b2_PtRecoGauss_tlv.M()

        b2_AllMuNu_tlv = TLorentzVector()
        b2_AllMuNu_tlv.SetPtEtaPhiE(b2_AllMuNu_Pt, b2_AllMuNu_Eta,
                                    b2_AllMuNu_Phi, b2_AllMuNu_E)
        b2_AllMuNu_M = b2_PtRecoGauss_tlv.M()

        b2_TruthWZ_tlv = TLorentzVector()
        b2_TruthWZ_tlv.SetPtEtaPhiE(b2_TruthWZ_Pt, b2_TruthWZ_Eta,
                                    b2_TruthWZ_Phi, b2_TruthWZ_E)
        b2_TruthWZ_M = b2_TruthWZ_tlv.M()

        b2_AllMu_tlv = TLorentzVector()
        b2_AllMu_tlv.SetPtEtaPhiE(b2_AllMu_Pt, b2_AllMu_Eta, b2_AllMu_Phi,
                                  b2_AllMu_E)
        b2_AllMu_M = b2_PtRecoGauss_tlv.M()

        b2_Regression_tlv = TLorentzVector()
        b2_Regression_tlv.SetPtEtaPhiE(b2_Regression_Pt, b2_Regression_Eta,
                                       b2_Regression_Phi, b2_Regression_E)
        b2_Regression_M = b2_PtRecoGauss_tlv.M()

        b2_OneMuNu_tlv = TLorentzVector()
        b2_OneMuNu_tlv.SetPtEtaPhiE(b2_OneMuNu_Pt, b2_OneMuNu_Eta,
                                    b2_OneMuNu_Phi, b2_OneMuNu_E)
        b2_OneMuNu_M = b2_PtRecoGauss_tlv.M()

        if debug:
            print("b2_Nominal_M", b2_Nominal_M)
        # Higgs boson candidate decaying to b1 and b2
        # TLorentzVector is the sum of the two TLorentzVectors
        Higgs_Nominal_tlv = b1_Nominal_tlv + b2_Nominal_tlv
        Higgs_Nominal_Pt = Higgs_Nominal_tlv.Pt()
        Higgs_Nominal_Eta = Higgs_Nominal_tlv.Eta()
        Higgs_Nominal_Phi = Higgs_Nominal_tlv.Phi()
        Higgs_Nominal_E = Higgs_Nominal_tlv.E()
        Higgs_OneMu_tlv = b1_OneMu_tlv + b2_OneMu_tlv
        Higgs_OneMu_Pt = Higgs_OneMu_tlv.Pt()
        Higgs_OneMu_Eta = Higgs_OneMu_tlv.Eta()
        Higgs_OneMu_Phi = Higgs_OneMu_tlv.Phi()
        Higgs_OneMu_E = Higgs_OneMu_tlv.E()

        Higgs_PtRecoGauss_tlv = b1_PtRecoGauss_tlv + b2_PtRecoGauss_tlv
        Higgs_PtRecoBukin_tlv = b1_PtRecoBukin_tlv + b2_PtRecoBukin_tlv
        Higgs_Parton_tlv = b1_Parton_tlv + b2_Parton_tlv
        Higgs_AllMuNu_tlv = b1_AllMuNu_tlv + b2_AllMuNu_tlv
        Higgs_TruthWZ_tlv = b1_TruthWZ_tlv + b2_TruthWZ_tlv
        Higgs_AllMu_tlv = b1_AllMu_tlv + b2_AllMu_tlv
        Higgs_Regression_tlv = b1_Regression_tlv + b2_Regression_tlv
        Higgs_OneMuNu_tlv = b1_OneMuNu_tlv + b2_OneMuNu_tlv

        if debug:
            print("Higgs_Nominal_Pt", Higgs_Nominal_Pt)
            print("Higgs_Nominal_Eta", Higgs_Nominal_Eta)
            print("Higgs_Nominal_Phi", Higgs_Nominal_Phi)
            print("Higgs_Nominal_E", Higgs_Nominal_E)
        Higgs_Nominal_M = Higgs_Nominal_tlv.M()
        Higgs_OneMu_M = Higgs_OneMu_tlv.M()
        Higgs_PtRecoGauss_M = Higgs_PtRecoGauss_tlv.M()
        Higgs_PtRecoBukin_M = Higgs_PtRecoBukin_tlv.M()
        Higgs_Parton_M = Higgs_Parton_tlv.M()
        Higgs_AllMuNu_M = Higgs_AllMuNu_tlv.M()
        Higgs_TruthWZ_M = Higgs_TruthWZ_tlv.M()
        Higgs_AllMu_M = Higgs_AllMu_tlv.M()
        Higgs_Regression_M = Higgs_Regression_tlv.M()
        Higgs_OneMuNu_M = Higgs_OneMuNu_tlv.M()
        if debug:
            print("Higgs_Nominal_M", Higgs_Nominal_M)
        # the mass should be 125, but when measured we get a distribution around 125
        # we store that in a histogram
        hist_Higgs_Nominal_M.Fill(Higgs_Nominal_M)
        hist_Higgs_OneMu_M.Fill(Higgs_OneMu_M)
        hist_Higgs_PtRecoGauss_M.Fill(Higgs_PtRecoGauss_M)
        hist_Higgs_PtRecoBukin_M.Fill(Higgs_PtRecoBukin_M)
        hist_Higgs_Parton_M.Fill(Higgs_Parton_M)
        hist_Higgs_AllMuNu_M.Fill(Higgs_AllMuNu_M)
        hist_Higgs_TruthWZ_M.Fill(Higgs_TruthWZ_M)
        hist_Higgs_AllMu_M.Fill(Higgs_AllMu_M)
        hist_Higgs_Regression_M.Fill(Higgs_Regression_M)
        hist_Higgs_OneMuNu_M.Fill(Higgs_OneMuNu_M)
    # done loop over all the entries in the tree
    outputfile.Write()
    outputfile.Close()
示例#29
0
def total_mass(pvecs):
    '''Get the total mass from the dict of p vectors.'''
    pvec = TLorentzVector()
    for vec in pvecs.values():
        pvec += vec
    return pvec.M()
示例#30
0
def getVBSkin_boosted(vbsjets, fatjet, lepton, met, other_jets, debug=False):
    output = getDefault()
    # variables extraction
    total_vbs = TLorentzVector(0, 0, 0, 0)
    vbs_etas = []
    vbs_phis = []
    vbs_pts = []
    for i, j in enumerate(vbsjets):
        total_vbs += j
        vbs_etas.append(j.Eta())
        vbs_phis.append(j.Phi())
        vbs_pts.append(j.Pt())
    if debug:
        print "VBS pts", vbs_pts
        print "VBS etas", vbs_etas
    deltaeta_vbs = abs(vbs_etas[0] - vbs_etas[1])
    mean_eta_vbs = sum(vbs_etas) / 2
    output["vbs_pt_high"] = vbs_pts[0]
    output["vbs_pt_low"] = vbs_pts[1]
    output["mjj_vbs"] = total_vbs.M()
    output["deltaeta_vbs"] = deltaeta_vbs
    output["deltaphi_vbs"] = abs(vbsjets[0].DeltaPhi(vbsjets[1]))
    output["deltaR_vbs"] = vbsjets[0].DrEtaPhi(vbsjets[1])
    output["vbs_etaprod"] = vbs_etas[0] * vbs_etas[1]
    output["vbs_eta_high"] = abs(vbs_etas[0])
    output["vbs_eta_low"] = abs(vbs_etas[1])

    total_vjet = fatjet
    vjet_etas = [fatjet.Eta(), -999.]
    vjet_phis = [fatjet.Phi(), -999.]
    vjet_pts = [fatjet.Pt(), -999.]
    if debug:
        print "Vjet pts", vjet_pts
        print "Vjet etas", vjet_etas
    output["vjet_pt_high"] = vjet_pts[0]
    output["vjet_pt_low"] = vjet_pts[1]
    output["mjj_vjet"] = total_vjet.M()
    output["vjet_eta_high"] = abs(vjet_etas[0])

    nu_vec = RecoNeutrino.reconstruct_neutrino(lepton, met, mode="central")
    nu_vec_nearlep = RecoNeutrino.reconstruct_neutrino(lepton,
                                                       met,
                                                       mode="pz_lep")
    output["recoMET"] = nu_vec.Pt()
    output["recoMET_pz"] = nu_vec.Pz()
    output["recoMET_nearlep"] = nu_vec_nearlep.Pt()
    output["recoMET_pz_nearlep"] = nu_vec_nearlep.Pz()
    output["deltaphi_lep_nu"] = abs(lepton.DeltaPhi(nu_vec))
    output["deltaeta_lep_nu"] = abs(lepton.Eta() - nu_vec.Eta())
    output["deltaR_lep_nu"] = lepton.DrEtaPhi(nu_vec)
    # Delta Phi with lepton
    output["deltaphi_lep_vbs_high"] = abs(lepton.DeltaPhi(vbsjets[0]))
    output["deltaphi_lep_vbs_low"] = abs(lepton.DeltaPhi(vbsjets[1]))
    output["deltaphi_lep_vjet_high"] = abs(lepton.DeltaPhi(fatjet))
    # Delta Eta with lepton
    output["deltaeta_lep_vbs_high"] = abs(lepton.Eta() - vbs_etas[0])
    output["deltaeta_lep_vbs_low"] = abs(lepton.Eta() - vbs_etas[1])
    output["deltaeta_lep_vjet_high"] = abs(lepton.Eta() - vjet_etas[0])
    # Look for nearest vbs jet from lepton
    output["deltaR_lep_vbs"] = min(
        [lepton.DrEtaPhi(vbsjets[0]),
         lepton.DrEtaPhi(vbsjets[1])])
    output["deltaR_lep_vjet"] = lepton.DrEtaPhi(fatjet)
    # Zeppenfeld variables
    if deltaeta_vbs != 0.:
        output["Zvjets_high"] = (vjet_etas[0] - mean_eta_vbs) / deltaeta_vbs
        output["Zlep"] = (lepton.Eta() - mean_eta_vbs) / deltaeta_vbs
    #R variables
    ptvbs12 = vbsjets[0].Pt() * vbsjets[1].Pt()
    output["Rvjets_high"] = (lepton.Pt() * fatjet.Pt()) / ptvbs12
    #Asymmetry
    output["Asym_vbs"] = (vbs_pts[0] - vbs_pts[1]) / sum(vbs_pts)
    #WW variables
    w_lep = lepton + nu_vec
    w_had = fatjet
    w_lep_t = w_lep.Vect()
    w_lep_t.SetZ(0)
    w_had_t = w_had.Vect()
    w_had_t.SetZ(0)
    ww_vec = w_lep + w_had
    output["w_lep_pt"] = w_lep.Pt()
    output["Mw_lep"] = w_lep.M()
    #output["Mtw_lep"] = w_lep_t.M()
    output["Mtw_lep"] = sqrt(2 * lepton.Pt() * met.Pt() *
                             (1 - cos(lepton.DeltaPhi(met))))
    output["Mww"] = ww_vec.M()
    output["R_ww"] = (w_lep.Pt() * w_lep.Pt()) / ptvbs12
    output["R_mw"] = ww_vec.M() / ptvbs12
    output["A_ww"] = (w_lep_t + w_had_t).Pt() / (w_lep.Pt() + w_had.Pt())
    #Centrality
    eta_ww = (w_lep.Eta() + w_had.Eta()) / 2
    if deltaeta_vbs != 0.:
        output["Centr_vbs"] = abs(vbs_etas[0] - eta_ww -
                                  vbs_etas[1]) / deltaeta_vbs
    deltaeta_plus = max(vbs_etas) - max([w_lep.Eta(), w_had.Eta()])
    deltaeta_minus = min([w_lep.Eta(), w_had.Eta()]) - min(vbs_etas)
    output["Centr_ww"] = min([deltaeta_plus, deltaeta_minus])
    #Lepton projection
    lep_vec_t = lepton.Vect()
    lep_vec_t.SetZ(0)
    output["Lep_proj"] = (w_lep_t * lep_vec_t) / w_lep.Pt()
    output["Lep_projw"] = (w_lep_t * lep_vec_t) / (lepton.Pt() * w_lep.Pt())
    # Ht and number of jets with Pt> 20
    # using uncut jets
    Njets = len(other_jets)
    N_jets_forward = 0
    N_jets_central = 0
    Ht = 0.
    for oj in other_jets:
        j_eta, j_pt = oj.Eta(), oj.Pt()
        # Looking only to jets != vbs & vjets
        if deltaeta_vbs != 0.:
            Z = abs((j_eta - mean_eta_vbs) / deltaeta_vbs)
            if Z > 0.5:
                N_jets_forward += 1
            else:
                N_jets_central += 1
        # Ht totale
        Ht += j_pt
    # Add vbs and vjet to Ht
    for jet in chain(vbsjets, [fatjet]):
        Ht += jet.Pt()

    output["N_jets"] = Njets
    output["N_jets_central"] = N_jets_central
    output["N_jets_forward"] = N_jets_forward
    output["Ht"] = Ht
    return output