示例#1
0
    def __init__(self, leg1, leg2, pdgid, status=3, sort_by_pt=False, mass1=-1, mass2=-1): 
        '''
        Parameters (stored as attributes):
        leg1,2 : first and second leg.
        pdgid  : pdg code of the resonance
        status : status code of the resonance
        '''
        if isinstance(leg1.physObj, ROOT.pat.PackedCandidate): leg1 = PhysicsObject(ROOT.pat.PackedCandidate(leg1.physObj))
        if isinstance(leg2.physObj, ROOT.pat.PackedCandidate): leg2 = PhysicsObject(ROOT.pat.PackedCandidate(leg2.physObj))

        if sort_by_pt:
            self.leg1 = leg1 if leg1.pt() >= leg2.pt() else leg2 
            self.leg2 = leg2 if leg1.pt() >= leg2.pt() else leg1
        else:
            self.leg1 = leg1 
            self.leg2 = leg2 
        if mass1>0: self.leg1.setMass(mass1)
        if mass2>0: self.leg2.setMass(mass2)
        self._p4 = leg1.p4() + leg2.p4()
        self._charge = leg1.charge() + leg2.charge()
        self._pdgid = pdgid
        self._status = status
示例#2
0
    def process(self, event):
 
        run = event.input.eventAuxiliary().id().run()
        lumi = event.input.eventAuxiliary().id().luminosityBlock()
        eventId = event.input.eventAuxiliary().id().event()
        
        self.readCollections( event.input )
        
        # Will need who for jet calibration later
        rho =  self.handles["rho"].product()[0]

        ######## 
        # Softdrop Fatjets + NSubjettiness
        ########

        for fj_name in ["ca15softdropz2b1"]:

            if self.skip_ca15 and ("ca15" in fj_name):
                continue
                
            # Set the four-vector
            setattr(event, fj_name, map(PhysicsObject, self.handles[fj_name].product()))

            # N-Subjettiness
            tau1 = self.handles[fj_name+'tau1'].product()
            tau2 = self.handles[fj_name+'tau2'].product()
            tau3 = self.handles[fj_name+'tau3'].product()

            # Loop over jets                        
            for ij, jet in enumerate(getattr(event, fj_name)):

                # Fill N-Subjettiness
                jet.tau1 = tau1.get(ij)
                jet.tau2 = tau2.get(ij)
                jet.tau3 = tau3.get(ij)
                                    
            # end of loop over jets



                                                                
        ######## 
        # Groomed Uncalibrated Fatjets
        ########

        for fj_name in ['ca15trimmed', 'ca15softdrop', 'ca15pruned']:            
                setattr(event, fj_name, map(PhysicsObject, self.handles[fj_name].product()))

#
#        ######## 
#        # Groomed Fatjets to calibrate
#        ########
#
#        pruned_cal_jets = []
#
#        for groomed_fj in self.handles['ak08pruned'].product():                        
#
#            # We need the closest ungroomed fatjet to get the JEC:            
#            # - Make a list of pairs: deltaR(ungroomed fj, groomed fj) for all ungroomed fatjets
#            # - Sort by deltaR
#            # - And take the minimum
#            
#            if len(getattr(event, "ak08")):
#                closest_ung_fj_and_dr = sorted(
#                    [(ung_fj, deltaR2(ung_fj, groomed_fj)) for ung_fj in getattr(event, "ak08")], 
#                    key=lambda x:x[1])[0]
#            else:
#                print "WARNING: No ungroomed fatjets found in event with groomed fatjet. Skipping"
#                continue
#
#            # Use the jet cone size for matching
#            minimal_dr_groomed_ungroomed = 0.8
#            if closest_ung_fj_and_dr[1] > minimal_dr_groomed_ungroomed:
#                print "WARNING: No ungroomed fatjet found close to groomed fatjet. Skipping"
#                continue
#
#            ungroomed_jet = Jet(closest_ung_fj_and_dr[0])        
#
#            c = self.jetReCalibratorAK8L2L3.getCorrection(ungroomed_jet, rho)
#
#                        
#            # Need to do a deep-copy. Otherwise the original jet will be modified
#            cal_groomed_fj = PhysicsObject(groomed_fj).__copy__() 
#            cal_groomed_fj.scaleEnergy(c)
#            
#            pruned_cal_jets.append(cal_groomed_fj)
#
#        setattr(event, 'ak08prunedcal', pruned_cal_jets)
#
            
        ######## 
        # Subjets 
        ########

        for fj_name in ['ca15pruned']:

            if self.skip_ca15 and ("ca15" in fj_name):
                continue

            setattr(event, fj_name + "subjets", map(PhysicsObject, self.handles[fj_name+"subjets"].product()))
            
            newtags =  self.handles[fj_name+'subjetbtag'].product()
            for i in xrange(0,len(newtags)) :
                for j in getattr(event, fj_name+"subjets"):
                    if  j.physObj == newtags.key(i).get():
                        j.btag = newtags.value(i)


        ######## 
        # HEPTopTagger
        ########

        if not self.skip_ca15:
            candJets = self.handles['httCandJets'].product()
            candInfos = self.handles['httCandInfos'].product()

            event.httCandidates = map(PhysicsObject, candJets) 
            sjbtags = self.handles['httSubjetBtags'].product()

            for i in xrange(0, len(candJets)):            

                event.httCandidates[i].fRec = candInfos[i].properties().fRec
                event.httCandidates[i].Ropt = candInfos[i].properties().Ropt
                event.httCandidates[i].RoptCalc = candInfos[i].properties().RoptCalc
                event.httCandidates[i].ptForRoptCalc = candInfos[i].properties().ptForRoptCalc

                # HTT return the subjet-pair closest to the W-mass as W-subjets
                # Could be improved by b-tagging if we run into a problem
                [sj_w1, sj_w2, sj_nonw] = [con.__deref__() for con in candJets[i].getJetConstituents() if not con.isNull()]

                # Calibrate the subjets: W1
                sj_w1_uncal = Jet(sj_w1)        
                c = self.jetReCalibratorAK4.getCorrection(sj_w1_uncal, rho, isHttSubjet=True)            
                sj_w1_cal = PhysicsObject(sj_w1).__copy__() 
                sj_w1_cal.scaleEnergy(c)


                # Calibrate the subjets: W2
                sj_w2_uncal = Jet(sj_w2)        
                c = self.jetReCalibratorAK4.getCorrection(sj_w2_uncal, rho, isHttSubjet=True)            
                sj_w2_cal = PhysicsObject(sj_w2).__copy__() 
                sj_w2_cal.scaleEnergy(c)

                # Calibrate the subjets: NonW
                sj_nonw_uncal = Jet(sj_nonw)        
                c = self.jetReCalibratorAK4.getCorrection(sj_nonw_uncal, rho, isHttSubjet=True)            
                sj_nonw_cal = PhysicsObject(sj_nonw).__copy__() 
                sj_nonw_cal.scaleEnergy(c)



                # Make TLVs so we can add them and get the top quark
                # candidate                
                tlv_sj_w1_cal   = ROOT.TLorentzVector()
                tlv_sj_w2_cal   = ROOT.TLorentzVector()
                tlv_sj_nonw_cal = ROOT.TLorentzVector()

                tlv_sj_w1_cal.SetPtEtaPhiM(sj_w1_cal.pt(),
                                           sj_w1_cal.eta(),
                                           sj_w1_cal.phi(),
                                           sj_w1_cal.mass())
                tlv_sj_w2_cal.SetPtEtaPhiM(sj_w2_cal.pt(),
                                           sj_w2_cal.eta(),
                                           sj_w2_cal.phi(),
                                           sj_w2_cal.mass())
                tlv_sj_nonw_cal.SetPtEtaPhiM(sj_nonw_cal.pt(),
                                             sj_nonw_cal.eta(),
                                             sj_nonw_cal.phi(),
                                             sj_nonw_cal.mass())
                
                tlv_top_cal =  tlv_sj_w1_cal + tlv_sj_w2_cal + tlv_sj_nonw_cal

                # Store calibrated top candidate variables
                event.httCandidates[i].ptcal    = tlv_top_cal.Pt()
                event.httCandidates[i].etacal   = tlv_top_cal.Eta()
                event.httCandidates[i].phical   = tlv_top_cal.Phi()
                event.httCandidates[i].masscal  = tlv_top_cal.M()
                                            
                # Store SJ W1 Variables
                event.httCandidates[i].sjW1ptcal   = sj_w1_cal.pt()
                event.httCandidates[i].sjW1masscal = sj_w1_cal.mass()
                event.httCandidates[i].sjW1pt      = sj_w1.pt()
                event.httCandidates[i].sjW1eta     = sj_w1.eta()
                event.httCandidates[i].sjW1phi     = sj_w1.phi()
                event.httCandidates[i].sjW1mass    = sj_w1.mass()

                # Get the correct b-tag
                for ib in xrange(0, len(sjbtags)) :
                    if  sj_w1 == sjbtags.key(ib).get():
                        event.httCandidates[i].sjW1btag = sjbtags.value(ib)

                # Store SJ W2 Variables
                event.httCandidates[i].sjW2ptcal   = sj_w2_cal.pt()
                event.httCandidates[i].sjW2masscal = sj_w2_cal.mass()
                event.httCandidates[i].sjW2pt      = sj_w2.pt()  
                event.httCandidates[i].sjW2eta     = sj_w2.eta() 
                event.httCandidates[i].sjW2phi     = sj_w2.phi() 
                event.httCandidates[i].sjW2mass    = sj_w2.mass()

                # Get the correct b-tag
                for ib in xrange(0, len(sjbtags)) :
                    if  sj_w2 == sjbtags.key(ib).get():
                        event.httCandidates[i].sjW2btag = sjbtags.value(ib)

                # Store SJ Non W Variables
                event.httCandidates[i].sjNonWptcal   = sj_nonw_cal.pt()  
                event.httCandidates[i].sjNonWmasscal = sj_nonw_cal.mass()  
                event.httCandidates[i].sjNonWpt      = sj_nonw.pt()  
                event.httCandidates[i].sjNonWeta     = sj_nonw.eta() 
                event.httCandidates[i].sjNonWphi     = sj_nonw.phi() 
                event.httCandidates[i].sjNonWmass    = sj_nonw.mass()

                # Get the correct b-tag
                for ib in xrange(0, len(sjbtags)) :
                    if  sj_nonw == sjbtags.key(ib).get():
                        event.httCandidates[i].sjNonWbtag = sjbtags.value(ib)

        ######## 
        # AK8 Jets from MiniAOD + Subjet btags
        ########

        setattr(event, "ak08", map(PhysicsObject, self.handles["ak08"].product()))
        setattr(event, "ak08softdropsubjets", map(PhysicsObject, self.handles["ak08softdropsubjets"].product()))

        do_calc_bb = False
        # Calc BB tag  
        # -- if there is a HTT candidate and at least one lepton
        if len(event.selectedLeptons):
            for cand in event.httCandidates:
                if cand.fRec < 0.2 and cand.mass() > 100 and cand.mass() < 200:
                    do_calc_bb = True                
        # -- or if there are at least two fatjets with pT > 250 GeV and the scalar sum of the jet pTs is > 600
        fj_pt250 = [j for j in event.ak08 if j.pt() > 250]
        if len(fj_pt250) >= 2 and sum([j.pt() for j in fj_pt250]) > 600:
            do_calc_bb = True            
                
        # bb-tag Output
        newtags =  self.handles['ak08bbtag'].product()

        # Loop over jets                        
        for ij, jet in enumerate(getattr(event, "ak08")):

            # Fill bb-tag
            for i in xrange(len(newtags)) :
                if jet.physObj == newtags.key(i).get():
                    jet.bbtag = newtags.value(i)
		corr = self.jetReCalibratorAK8L2L3.getCorrection(Jet(jet),rho)
                jet.mprunedcorr= jet.userFloat("ak8PFJetsCHSPrunedMass")*corr	
		jet.JEC_L2L3 = corr
		jet.JEC_L1L2L3 = self.jetReCalibratorAK8L1L2L3.getCorrection(Jet(jet),rho)


            # bb-tag Inputs
            muonTagInfos = self.handles['ak08muonTagInfos'].product()[ij]
            elecTagInfos = self.handles['ak08elecTagInfos'].product()[ij]
            ipTagInfo    = self.handles['ak08ipTagInfos'].product()[ij]
            svTagInfo    = self.handles['ak08svTagInfos'].product()[ij]

            orig_jet = self.handles["ak08"].product()[ij]

            if do_calc_bb:
                calcBBTagVariables(jet, 
                                   orig_jet,
                                   muonTagInfos, 
                                   elecTagInfos, 
                                   ipTagInfo, 
                                   svTagInfo,
                                   njettiness_08,
                                   maxSVDeltaRToJet = 0.7,)
            else:
                calcBBTagVariables_dummy(jet)

        # end of loop over jets

        ######## 
        # Ungroomed Fatjets + NSubjettiness + Hbb Tagging
        ########

        for prefix in ["ca15"]:

            if self.skip_ca15 and ("ca15" in prefix):
                continue

            # N-Subjettiness
            tau1 = self.handles[prefix+'tau1'].product()
            tau2 = self.handles[prefix+'tau2'].product()
            tau3 = self.handles[prefix+'tau3'].product()

            # bb-tag Output
            newtags =  self.handles[prefix+'bbtag'].product()
                
            # Four Vector
            setattr(event, prefix+"ungroomed", map(PhysicsObject, self.handles[prefix+'ungroomed'].product()))

            # Loop over jets                        
            for ij, jet in enumerate(getattr(event, prefix+"ungroomed")):

                # Fill N-Subjettiness
                jet.tau1 = tau1.get(ij)
                jet.tau2 = tau2.get(ij)
                jet.tau3 = tau3.get(ij)

                # Fill bb-tag
                for i in xrange(len(newtags)) :
                    if jet.physObj == newtags.key(i).get():
                        jet.bbtag = newtags.value(i)

                # bb-tag Inputs
                muonTagInfos = self.handles['ca15muonTagInfos'].product()[ij]
                elecTagInfos = self.handles['ca15elecTagInfos'].product()[ij]
                ipTagInfo    = self.handles['ca15ipTagInfos'].product()[ij]
                svTagInfo    = self.handles['ca15svTagInfos'].product()[ij]

                orig_jet = self.handles[prefix+'ungroomed'].product()[ij]

                if do_calc_bb:
                    calcBBTagVariables(jet, 
                                       orig_jet,
                                       muonTagInfos, 
                                       elecTagInfos, 
                                       ipTagInfo, 
                                       svTagInfo,
                                       njettiness_15,
                                       maxSVDeltaRToJet = 1.3)
                else:
                    calcBBTagVariables_dummy(jet)

                                    
            # end of loop over jets


            



        return True
示例#3
0
    def process(self, event):

        run = event.input.eventAuxiliary().id().run()
        lumi = event.input.eventAuxiliary().id().luminosityBlock()
        eventId = event.input.eventAuxiliary().id().event()

        self.readCollections(event.input)

        # Will need who for jet calibration later
        rho = self.handles["rho"].product()[0]

        ########
        # AK8 Jets from MiniAOD + Subjet btags
        ########

        setattr(event, "ak08",
                map(PhysicsObject, self.handles["ak08"].product()))

        setattr(
            event, "ak0softdropsubjets",
            map(PhysicsObject, self.handles["ak08softdropsubjets"].product()))

        # bb-tag Output
        newtags = self.handles['ak08bbtag'].product()

        # Loop over jets
        for ij, jet in enumerate(getattr(event, "ak08")):

            # Fill bb-tag
            for i in xrange(len(newtags)):
                if jet.physObj == newtags.key(i).get():
                    jet.bbtag = newtags.value(i)
                corr = self.jetReCalibratorAK8L2L3.getCorrection(Jet(jet), rho)
                jet.mprunedcorr = jet.userFloat(
                    "ak8PFJetsCHSPrunedMass") * corr
                jet.JEC_L2L3 = corr
                jet.JEC_L1L2L3 = self.jetReCalibratorAK8L1L2L3.getCorrection(
                    Jet(jet), rho)

            # bb-tag Inputs
            muonTagInfos = self.handles['ak08muonTagInfos'].product()[ij]
            elecTagInfos = self.handles['ak08elecTagInfos'].product()[ij]
            ipTagInfo = self.handles['ak08ipTagInfos'].product()[ij]
            svTagInfo = self.handles['ak08svTagInfos'].product()[ij]

            calcBBTagVariables(
                jet,
                muonTagInfos,
                elecTagInfos,
                ipTagInfo,
                svTagInfo,
                njettiness_08,
                maxSVDeltaRToJet=0.7,
            )

        # end of loop over jets

        ########
        # Ungroomed Fatjets + NSubjettiness + Hbb Tagging
        ########

        for prefix in ["ca15"]:

            if self.skip_ca15 and ("ca15" in prefix):
                continue

            # N-Subjettiness
            tau1 = self.handles[prefix + 'tau1'].product()
            tau2 = self.handles[prefix + 'tau2'].product()
            tau3 = self.handles[prefix + 'tau3'].product()

            # bb-tag Output
            newtags = self.handles[prefix + 'bbtag'].product()

            # Four Vector
            setattr(
                event, prefix + "ungroomed",
                map(PhysicsObject,
                    self.handles[prefix + 'ungroomed'].product()))

            # Loop over jets
            for ij, jet in enumerate(getattr(event, prefix + "ungroomed")):

                # Fill N-Subjettiness
                jet.tau1 = tau1.get(ij)
                jet.tau2 = tau2.get(ij)
                jet.tau3 = tau3.get(ij)

                # Fill bb-tag
                for i in xrange(len(newtags)):
                    if jet.physObj == newtags.key(i).get():
                        jet.bbtag = newtags.value(i)

                # bb-tag Inputs
                muonTagInfos = self.handles['ca15muonTagInfos'].product()[ij]
                elecTagInfos = self.handles['ca15elecTagInfos'].product()[ij]
                ipTagInfo = self.handles['ca15ipTagInfos'].product()[ij]
                svTagInfo = self.handles['ca15svTagInfos'].product()[ij]

                calcBBTagVariables(jet,
                                   muonTagInfos,
                                   elecTagInfos,
                                   ipTagInfo,
                                   svTagInfo,
                                   njettiness_15,
                                   maxSVDeltaRToJet=1.3)

            # end of loop over jets

        ########
        # Softdrop Fatjets + NSubjettiness
        ########

        for fj_name in ["ca15softdropz2b1"]:

            if self.skip_ca15 and ("ca15" in fj_name):
                continue

            # Set the four-vector
            setattr(event, fj_name,
                    map(PhysicsObject, self.handles[fj_name].product()))

            # N-Subjettiness
            tau1 = self.handles[fj_name + 'tau1'].product()
            tau2 = self.handles[fj_name + 'tau2'].product()
            tau3 = self.handles[fj_name + 'tau3'].product()

            # Loop over jets
            for ij, jet in enumerate(getattr(event, fj_name)):

                # Fill N-Subjettiness
                jet.tau1 = tau1.get(ij)
                jet.tau2 = tau2.get(ij)
                jet.tau3 = tau3.get(ij)

            # end of loop over jets

        ########
        # Groomed Uncalibrated Fatjets
        ########

        for fj_name in [
                'ak08pruned', 'ca15trimmed', 'ca15softdrop', 'ca15pruned'
        ]:
            setattr(event, fj_name,
                    map(PhysicsObject, self.handles[fj_name].product()))

        ########
        # Groomed Fatjets to calibrate
        ########

        pruned_cal_jets = []

        for groomed_fj in self.handles['ak08pruned'].product():

            # We need the closest ungroomed fatjet to get the JEC:
            # - Make a list of pairs: deltaR(ungroomed fj, groomed fj) for all ungroomed fatjets
            # - Sort by deltaR
            # - And take the minimum

            if len(getattr(event, "ak08")):
                closest_ung_fj_and_dr = sorted(
                    [(ung_fj, deltaR2(ung_fj, groomed_fj))
                     for ung_fj in getattr(event, "ak08")],
                    key=lambda x: x[1])[0]
            else:
                print "WARNING: No ungroomed fatjets found in event with groomed fatjet. Skipping"
                continue

            # Use the jet cone size for matching
            minimal_dr_groomed_ungroomed = 0.8
            if closest_ung_fj_and_dr[1] > minimal_dr_groomed_ungroomed:
                print "WARNING: No ungroomed fatjet found close to groomed fatjet. Skipping"
                continue

            ungroomed_jet = Jet(closest_ung_fj_and_dr[0])

            c = self.jetReCalibratorAK8L2L3.getCorrection(ungroomed_jet, rho)

            # Need to do a deep-copy. Otherwise the original jet will be modified
            cal_groomed_fj = PhysicsObject(groomed_fj).__copy__()
            cal_groomed_fj.scaleEnergy(c)

            pruned_cal_jets.append(cal_groomed_fj)

        setattr(event, 'ak08prunedcal', pruned_cal_jets)

        ########
        # Subjets
        ########

        for fj_name in ['ak08pruned', 'ca15pruned']:

            if self.skip_ca15 and ("ca15" in fj_name):
                continue

            setattr(
                event, fj_name + "subjets",
                map(PhysicsObject,
                    self.handles[fj_name + "subjets"].product()))

            newtags = self.handles[fj_name + 'subjetbtag'].product()
            for i in xrange(0, len(newtags)):
                for j in getattr(event, fj_name + "subjets"):
                    if j.physObj == newtags.key(i).get():
                        j.btag = newtags.value(i)

        ########
        # HEPTopTagger
        ########

        if not self.skip_ca15:
            candJets = self.handles['httCandJets'].product()
            candInfos = self.handles['httCandInfos'].product()

            event.httCandidates = map(PhysicsObject, candJets)
            sjbtags = self.handles['httSubjetBtags'].product()

            for i in xrange(0, len(candJets)):

                event.httCandidates[i].fRec = candInfos[i].properties().fRec
                event.httCandidates[i].Ropt = candInfos[i].properties().Ropt
                event.httCandidates[i].RoptCalc = candInfos[i].properties(
                ).RoptCalc
                event.httCandidates[i].ptForRoptCalc = candInfos[i].properties(
                ).ptForRoptCalc

                # HTT return the subjet-pair closest to the W-mass as W-subjets
                # Could be improved by b-tagging if we run into a problem
                [sj_w1, sj_w2, sj_nonw] = [
                    con.__deref__()
                    for con in candJets[i].getJetConstituents()
                    if not con.isNull()
                ]

                # Calibrate the subjets: W1
                sj_w1_uncal = Jet(sj_w1)
                c = self.jetReCalibratorAK4.getCorrection(sj_w1_uncal,
                                                          rho,
                                                          isHttSubjet=True)
                sj_w1_cal = PhysicsObject(sj_w1).__copy__()
                sj_w1_cal.scaleEnergy(c)

                # Calibrate the subjets: W2
                sj_w2_uncal = Jet(sj_w2)
                c = self.jetReCalibratorAK4.getCorrection(sj_w2_uncal,
                                                          rho,
                                                          isHttSubjet=True)
                sj_w2_cal = PhysicsObject(sj_w2).__copy__()
                sj_w2_cal.scaleEnergy(c)

                # Calibrate the subjets: NonW
                sj_nonw_uncal = Jet(sj_nonw)
                c = self.jetReCalibratorAK4.getCorrection(sj_nonw_uncal,
                                                          rho,
                                                          isHttSubjet=True)
                sj_nonw_cal = PhysicsObject(sj_nonw).__copy__()
                sj_nonw_cal.scaleEnergy(c)

                # Make TLVs so we can add them and get the top quark
                # candidate
                tlv_sj_w1_cal = ROOT.TLorentzVector()
                tlv_sj_w2_cal = ROOT.TLorentzVector()
                tlv_sj_nonw_cal = ROOT.TLorentzVector()

                tlv_sj_w1_cal.SetPtEtaPhiM(sj_w1_cal.pt(), sj_w1_cal.eta(),
                                           sj_w1_cal.phi(), sj_w1_cal.mass())
                tlv_sj_w2_cal.SetPtEtaPhiM(sj_w2_cal.pt(), sj_w2_cal.eta(),
                                           sj_w2_cal.phi(), sj_w2_cal.mass())
                tlv_sj_nonw_cal.SetPtEtaPhiM(sj_nonw_cal.pt(),
                                             sj_nonw_cal.eta(),
                                             sj_nonw_cal.phi(),
                                             sj_nonw_cal.mass())

                tlv_top_cal = tlv_sj_w1_cal + tlv_sj_w2_cal + tlv_sj_nonw_cal

                # Store calibrated top candidate variables
                event.httCandidates[i].ptcal = tlv_top_cal.Pt()
                event.httCandidates[i].etacal = tlv_top_cal.Eta()
                event.httCandidates[i].phical = tlv_top_cal.Phi()
                event.httCandidates[i].masscal = tlv_top_cal.M()

                # Store SJ W1 Variables
                event.httCandidates[i].sjW1ptcal = sj_w1_cal.pt()
                event.httCandidates[i].sjW1masscal = sj_w1_cal.mass()
                event.httCandidates[i].sjW1pt = sj_w1.pt()
                event.httCandidates[i].sjW1eta = sj_w1.eta()
                event.httCandidates[i].sjW1phi = sj_w1.phi()
                event.httCandidates[i].sjW1mass = sj_w1.mass()

                # Get the correct b-tag
                for ib in xrange(0, len(sjbtags)):
                    if sj_w1 == sjbtags.key(ib).get():
                        event.httCandidates[i].sjW1btag = sjbtags.value(ib)

                # Store SJ W2 Variables
                event.httCandidates[i].sjW2ptcal = sj_w2_cal.pt()
                event.httCandidates[i].sjW2masscal = sj_w2_cal.mass()
                event.httCandidates[i].sjW2pt = sj_w2.pt()
                event.httCandidates[i].sjW2eta = sj_w2.eta()
                event.httCandidates[i].sjW2phi = sj_w2.phi()
                event.httCandidates[i].sjW2mass = sj_w2.mass()

                # Get the correct b-tag
                for ib in xrange(0, len(sjbtags)):
                    if sj_w2 == sjbtags.key(ib).get():
                        event.httCandidates[i].sjW2btag = sjbtags.value(ib)

                # Store SJ Non W Variables
                event.httCandidates[i].sjNonWptcal = sj_nonw_cal.pt()
                event.httCandidates[i].sjNonWmasscal = sj_nonw_cal.mass()
                event.httCandidates[i].sjNonWpt = sj_nonw.pt()
                event.httCandidates[i].sjNonWeta = sj_nonw.eta()
                event.httCandidates[i].sjNonWphi = sj_nonw.phi()
                event.httCandidates[i].sjNonWmass = sj_nonw.mass()

                # Get the correct b-tag
                for ib in xrange(0, len(sjbtags)):
                    if sj_nonw == sjbtags.key(ib).get():
                        event.httCandidates[i].sjNonWbtag = sjbtags.value(ib)

        return True