コード例 #1
0
ファイル: Bjetscaling.py プロジェクト: JanikvA/missE
    def process(self, event):
        #sqrts = self.cfg_ana.sqrts
        sqrts = 240.
        #sqrts = random.gauss(240.,240.*0.0012)
        #sqrts = random.gauss(240.,10.)
        jets = getattr(event, self.cfg_ana.input_jets)
        misenergy = getattr(event, self.cfg_ana.misenergy)
        #        solving the equation

        vis_p4 = TLorentzVector(0, 0, 0, 0)
        for jet in jets:
            vis_p4 += jet.p4()
        vis = Recoil(0, 0, vis_p4, 1)
        #         m=m_Z constrain
        a = vis.e() * sqrts / (vis.m()**2)
        b = a**2 - (sqrts**2 - 91.**2) / (vis.m()**2)

        #      sf stands for scaling factor

        if b < 0:
            sf = 1
            setattr(event, self.cfg_ana.det, 1)
        else:
            #sf2 corresponds to the solution where the missing energy is negative therefore sf is the scaling factor that makes sense from a physics pov.
            sf = a - math.sqrt(b)
            sf2 = a + math.sqrt(b)
            setattr(event, self.cfg_ana.det, 2)

######test
#visscaled1=TLorentzVector(0,0,0,0)
#visscaled2=TLorentzVector(0,0,0,0)
#for jet in jets:
#    visscaled1+=jet.p4()*sf
#    visscaled2+=jet.p4()*sf2
#cms=TLorentzVector(0,0,0,240)
#v1=cms-visscaled1
#v2=cms-visscaled2
#print v1.E(),v2.E()

        setattr(event, self.cfg_ana.scalingfac, sf)

        setattr(event, self.cfg_ana.scalingfac2, sf2)

        scale_factors = [sf] * 2
        output = []
        for jet, factor in zip(jets, scale_factors):
            # the jets should not be deepcopied
            # as they are heavy objects containing
            # in particular a list of consistuent particles
            scaled_jet = copy.copy(jet)
            scaled_jet._tlv = copy.deepcopy(jet._tlv)
            scaled_jet._tlv *= factor
            output.append(scaled_jet)

        setattr(event, self.cfg_ana.output_jets, output)
コード例 #2
0
    def process(self, event):
        leptons = getattr(event, self.cfg_ana.leptons)
        jets = getattr(event, self.cfg_ana.jets)
        sqrts = self.cfg_ana.sqrts
        w_mass = self.cfg_ana.w_mass
        top_mass = self.cfg_ana.top_mass

        jets_p4 = []
        btags = []
        for jet in jets:
            jets_p4.append(jet.p4())
            btags.append(jet.logbtag)

        if len(leptons) == 0:
            event.success = -1
        else:
            myTopConstrainer = topConstrainer(jets_p4, btags, leptons[0].p4(), sqrts, w_mass, top_mass)
            succeded, chi2 = myTopConstrainer.rescale(1E-4)

            if succeded:
                pRec = myTopConstrainer.p_ini
                tophadRec = Particle(top_pdgid, top_charge, (pRec[0]+pRec[1]+pRec[2]) )
                whadRec = Particle(w_pdgid, w_charge, (pRec[0]+pRec[1]) )
                toplepRec = Particle(top_pdgid, top_charge, (pRec[3]+pRec[4]+pRec[5]) )
                wlepRec = Particle(w_pdgid, w_charge, (pRec[4]+pRec[5]) )
                missingMassRec = Particle( 0, 0, pRec[5] )

                pFit = myTopConstrainer.p_out
                tophadFit = Particle(top_pdgid, top_charge, (pFit[0]+pFit[1]+pFit[2]) )
                whadFit = Particle(w_pdgid, w_charge, (pFit[0]+pFit[1]) )
                toplepFit = Particle(top_pdgid, top_charge, (pFit[3]+pFit[4]+pFit[5]) )
                wlepFit = Particle(w_pdgid, w_charge, (pFit[4]+pFit[5]) )
                missingMassFit = Particle( 0, 0, pFit[5] )

                chi2_tophadRec = ( (tophadRec.m() - self.cfg_ana.tophadRec_m) / self.cfg_ana.tophadRec_w )**2
                chi2_whadRec = ( (whadRec.m() - self.cfg_ana.whadRec_m) / self.cfg_ana.whadRec_w )**2
                chi2_toplepRec = ( (toplepRec.m() - self.cfg_ana.toplepRec_m) / self.cfg_ana.toplepRec_w )**2
                chi2_wlepRec = ( (wlepRec.m() - self.cfg_ana.wlepRec_m) / self.cfg_ana.wlepRec_w )**2
                chi2_top_constrainer = chi2_tophadRec + chi2_whadRec + chi2_toplepRec + chi2_wlepRec

                setattr(event, 'success', 1)
                setattr(event, 'chi2_algorithm', chi2)

                setattr(event, 'tophadRec', tophadRec)
                setattr(event, 'whadRec', whadRec)
                setattr(event, 'toplepRec', toplepRec)
                setattr(event, 'wlepRec', wlepRec)
                setattr(event, 'missingMassRec', missingMassRec)
                setattr(event, 'tophadFit', tophadFit)
                setattr(event, 'whadFit', whadFit)
                setattr(event, 'toplepFit', toplepFit)
                setattr(event, 'wlepFit', wlepFit)
                setattr(event, 'missingMassFit', missingMassFit)

                setattr(event, 'chi2_tophadRec', chi2_tophadRec)
                setattr(event, 'chi2_whadRec', chi2_whadRec)
                setattr(event, 'chi2_toplepRec', chi2_toplepRec)
                setattr(event, 'chi2_wlepRec', chi2_wlepRec)

                setattr(event, 'chi2_top_constrainer', chi2_top_constrainer)

            else:
                event.success = 0