Exemplo n.º 1
0
    def process(self,**kwargs):
        print module_name

        tree  = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree,input)

        newbranches = ["H_jets", "W_jets"]

        self.clone(output,newbranches)
        H_jets    =   numpy.zeros(2, dtype=numpy.int32)
        W_jets  =   numpy.zeros(2, dtype=numpy.int32)
        self.otree.Branch('H_jets',         H_jets,         'H_jets[2]/I')
        self.otree.Branch('W_jets',         W_jets,         'W_jets[2]/I')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ',nentries 

        # avoid dots to go faster
        itree     = self.itree
        otree     = self.otree

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i%step == 0.:
                print i,'events processed :: ', nentries

            hpair = [-1,-1]
            wpair = [-1,-1]
            jets, b_scores = utils.get_jets_and_bscore(itree, self.ptmin_jet, self.debug)

            bjets = [(i, bscore) for i, bscore in enumerate(b_scores)
                    if bscore >= bTaggingWPs['deepCSV'][self.bWP]]

            print bjets

            if len(bjets) >= 2:
                # Take the indexes of the two jets with bigger bscore
                hpair = [j[0] for j in list(sorted(bjets, key=itemgetter(1), reverse=True))[:2]]
                
                if len(jets) >=4:
                    if self.mode == 0:
                        wpair = utils.nearest_mass_pair_notH(jets, 80.385, hpair)
                    elif self.mode == 1:
                        wpair = utils.max_pt_pair_notH(jets, hpair)   
                    elif self.mode == 2:
                        wpair = utils.min_deltaeta_pairs_notH(jets, hpair)

            H_jets[0], H_jets[1] = hpair 
            W_jets[0], W_jets[1] = wpair
                
            otree.Fill()
  
        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 2
0
    def process(self,**kwargs):
        print module_name

        tree  = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree,input)

        variables = {}
        self.clone(output,  vbs_branches["F"]+vbs_branches["I"])

        for br in vbs_branches["F"]:
            variables[br] = numpy.zeros(1, dtype=numpy.float32)
            self.otree.Branch(br, variables[br], "{}/F".format(br))
        for br in vbs_branches["I"]:
            variables[br] = numpy.zeros(1, dtype=numpy.int32)
            self.otree.Branch(br, variables[br], "{}/I".format(br))
       

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ',nentries 

        # avoid dots to go faster
        itree     = self.itree
        otree     = self.otree

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i%step == 0.:
                print i,'events processed :: ', nentries

            # Check if we have at least 4 jets with pt > ptmin
            # and VBSjets and Vjets are all associated
            if (not itree.std_vector_jet_pt[3] >= self.ptmin_jet) or  \
                -1 in itree.V_jets or -1 in itree.VBS_jets:
                for var in variables:
                    variables[var][0] = -9999
            else:
                if self.debug:
                    print "VBSjets", [i for i in itree.VBS_jets]
                    print "Vjets", [j for j in itree.V_jets]

                vjets = utils.get_jets_byindex(itree, itree.V_jets, self.ptmin_jet, self.debug)
                vbsjets = utils.get_jets_byindex(itree, itree.VBS_jets, self.ptmin_jet, self.debug)
                
                lepton = TLorentzVector()
                plep = itree.std_vector_lepton_pt[0] * cosh(itree.std_vector_lepton_eta[0])
                lepton.SetPtEtaPhiE(itree.std_vector_lepton_pt[0], itree.std_vector_lepton_eta[0],
                                    itree.std_vector_lepton_phi[0], plep)
                
                met = TLorentzVector()
                met.SetPtEtaPhiE(itree.metPfType1, 0., itree.metPfType1Phi, itree.metPfType1)

                other_jets_eta = []
                other_jets_pts = []
                for i, ( eta, pt) in enumerate(zip(itree.std_vector_jet_eta, itree.std_vector_jet_pt)):
                    if i not in itree.VBS_jets and i not in itree.V_jets and pt >=self.ptmin_jet and abs(eta)<10:
                        other_jets_eta.append(eta)
                        other_jets_pts.append(pt)
    
                output =  getVBSkinematics(vbsjets, vjets, lepton, met, 
                                            other_jets_eta, other_jets_pts, self.debug)

                if self.debug:
                    print output

                for vk, vvalue in variables.items():
                    vvalue[0] = output[vk]
                
            otree.Fill()
  
        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 3
0
    def process(self,**kwargs):
        print module_name

        tree  = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']
        self.connect(tree,input)

        newbranches = ["H_jets", "W_jets", "PartonJetMatchFlag"]

        self.clone(output,newbranches)
        
        H_jets    =   numpy.zeros(2, dtype=numpy.int32)
        W_jets  =   numpy.zeros(2, dtype=numpy.int32)
        PartonJetMatchFlag  =   numpy.zeros(1, dtype=numpy.int32)
        self.otree.Branch('H_jets',  H_jets,  'H_jets[2]_true/I')
        self.otree.Branch('W_jets',  W_jets,  'H_jets[2]_true/I')
        self.otree.Branch('PartonJetMatchFlag', PartonJetMatchFlag, 'PartonJetMatchFlag/I')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ',nentries 

        # avoid dots to go faster
        itree     = self.itree
        otree     = self.otree
        print "Matching radius:", self.radius

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i%step == 0.:
                print i,'events processed :: ', nentries
            hpair = [-1,-1]
            wpair = [-1,-1]

            partons, pids = utils.get_hard_partons(itree, self.debug)

            # first take the two bs 
            hpair = [i for i, p in enumerate(pids) if p in [5,-5]]
            
            
            #find the W jets
            if len(partons) >= 4: # and len(hpair) == 2:
                if self.mode == 0:
                    wpair = utils.nearest_mass_pair_notH(jets, 80.385, hpair)
                elif self.mode == 1:
                    wpair = utils.max_pt_pair_notH(jets, hpair)   
                elif self.mode == 2:
                    wpair = utils.min_deltaeta_pairs_notH(jets, hpair)
             
            # now associate partons and nearest jets
            jets = utils.get_jets(itree, self.debug)
            matchresult, flag = utils.associate_vectors(jets, partons, self.radius)
            PartonJetMatchFlag[0] = flag
                
            if flag == 0:
                # Save the truth association only if every parton is 
                # associated to a different jet
                for ip, iparton in enumerate(hpair):
                    H_jets[ip] = matchresult[0][iparton]
                for jp, jparton in enumerate(wpair):
                    W_jets[jp] = matchresult[0][jparton]
               
            otree.Fill()
  
        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 4
0
    def process(self, **kwargs):
        print module_name

        tree = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree, input)

        variables = {}
        self.clone(output, vbs_branches["F"] + vbs_branches["I"])

        for br in vbs_branches["F"]:
            variables[br] = numpy.zeros(1, dtype=numpy.float32)
            self.otree.Branch(br, variables[br], "{}/F".format(br))
        for br in vbs_branches["I"]:
            variables[br] = numpy.zeros(1, dtype=numpy.int32)
            self.otree.Branch(br, variables[br], "{}/I".format(br))

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ', nentries

        # avoid dots to go faster
        itree = self.itree
        otree = self.otree

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i % step == 0.:
                print i, 'events processed :: ', nentries

            # Check if we have at least 4 jets with pt > ptmin
            # and VBSjets and Vjets are all associated
            if (not itree.std_vector_jet_pt[3] >= self.ptmin_jet) or  \
                -1 in itree.V_jets or -1 in itree.VBS_jets:
                for var in variables:
                    variables[var][0] = -9999
            else:
                if self.debug:
                    print "VBSjets", [i for i in itree.VBS_jets]
                    print "Vjets", [j for j in itree.V_jets]

                vjets = utils.get_jets_byindex(itree, itree.V_jets,
                                               self.ptmin_jet, self.debug)
                vbsjets = utils.get_jets_byindex(itree, itree.VBS_jets,
                                                 self.ptmin_jet, self.debug)

                lepton = TLorentzVector()
                plep = itree.std_vector_lepton_pt[0] * cosh(
                    itree.std_vector_lepton_eta[0])
                lepton.SetPtEtaPhiE(itree.std_vector_lepton_pt[0],
                                    itree.std_vector_lepton_eta[0],
                                    itree.std_vector_lepton_phi[0], plep)

                met = TLorentzVector()
                met.SetPtEtaPhiE(itree.metPfType1, 0., itree.metPfType1Phi,
                                 itree.metPfType1)

                other_jets_eta = []
                other_jets_pts = []
                for i, (eta, pt) in enumerate(
                        zip(itree.std_vector_jet_eta,
                            itree.std_vector_jet_pt)):
                    if i not in itree.VBS_jets and i not in itree.V_jets and pt >= self.ptmin_jet and abs(
                            eta) < 10:
                        other_jets_eta.append(eta)
                        other_jets_pts.append(pt)

                output = getVBSkinematics(vbsjets, vjets, lepton, met,
                                          other_jets_eta, other_jets_pts,
                                          self.debug)

                if self.debug:
                    print output

                for vk, vvalue in variables.items():
                    vvalue[0] = output[vk]

            otree.Fill()

        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 5
0
    def process(self,**kwargs):
        print module_name

        tree  = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree,input)

        newbranches = ["hasTopGen", "V_jets", "VBS_jets", "PartonJetMatchFlag"]

        self.clone(output,newbranches)
        
        hasTopGen =   numpy.zeros(1, dtype=numpy.float32)
        V_jets    =   numpy.zeros(2, dtype=numpy.int32)
        VBS_jets  =   numpy.zeros(2, dtype=numpy.int32)
        PartonJetMatchFlag  =   numpy.zeros(1, dtype=numpy.int32)
        self.otree.Branch('hasTopGen',      hasTopGen,      'hasTopGen/F')
        self.otree.Branch('V_jets_true',    V_jets,         'V_jets_true[2]/I')
        self.otree.Branch('VBS_jets_true',   VBS_jets,       'VBS_jets_true[2]/I')
        self.otree.Branch('PartonJetMatchFlag', PartonJetMatchFlag, 'PartonJetMatchFlag/I')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ',nentries 

        # avoid dots to go faster
        itree     = self.itree
        otree     = self.otree

        print "Matching radius:", self.radius

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i%step == 0.:
                print i,'events processed :: ', nentries

            partons, pids = utils.get_hard_partons(itree, self.debug)

            # Exclude events with top in the partons
            if 6 in pids or -6 in pids:
                hasTopGen[0] = 1.
                PartonJetMatchFlag[0] = -1
            else:
                hasTopGen[0] = 0.
                # If the event doesn't have top we can extract
                # "true" partons from VBS processes

                # get the pair nearest  to W or Z mass
                vpair = utils.nearest_masses_pair(partons, [80.385, 91.1876])
                vbspair = [ip for ip in range(4) if not ip in vpair]

                # now associate partons and nearest jets
                jets = utils.get_jets(itree, self.ptmin_jet, self.debug)
                matchresult, flag = utils.associate_vectors(jets, partons, self.radius)

                PartonJetMatchFlag[0] = flag
                
                if flag == 0:
                    # Save the truth association only if every parton is 
                    # associated to a different jet
                    for ip, iparton in enumerate(vpair):
                        V_jets[ip] = matchresult[0][iparton]
                    for jp, jparton in enumerate(vbspair):
                        VBS_jets[jp] = matchresult[0][jparton]
               
            otree.Fill()
  
        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 6
0
    def process(self, **kwargs):
        print module_name

        tree = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']
        self.connect(tree, input)

        newbranches = ["H_jets", "W_jets", "PartonJetMatchFlag"]

        self.clone(output, newbranches)

        H_jets = numpy.zeros(2, dtype=numpy.int32)
        W_jets = numpy.zeros(2, dtype=numpy.int32)
        PartonJetMatchFlag = numpy.zeros(1, dtype=numpy.int32)
        self.otree.Branch('H_jets', H_jets, 'H_jets[2]_true/I')
        self.otree.Branch('W_jets', W_jets, 'H_jets[2]_true/I')
        self.otree.Branch('PartonJetMatchFlag', PartonJetMatchFlag,
                          'PartonJetMatchFlag/I')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ', nentries

        # avoid dots to go faster
        itree = self.itree
        otree = self.otree
        print "Matching radius:", self.radius

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i % step == 0.:
                print i, 'events processed :: ', nentries
            hpair = [-1, -1]
            wpair = [-1, -1]

            partons, pids = utils.get_hard_partons(itree, self.debug)

            # first take the two bs
            hpair = [i for i, p in enumerate(pids) if p in [5, -5]]

            #find the W jets
            if len(partons) >= 4:  # and len(hpair) == 2:
                if self.mode == 0:
                    wpair = utils.nearest_mass_pair_notH(jets, 80.385, hpair)
                elif self.mode == 1:
                    wpair = utils.max_pt_pair_notH(jets, hpair)
                elif self.mode == 2:
                    wpair = utils.min_deltaeta_pairs_notH(jets, hpair)

            # now associate partons and nearest jets
            jets = utils.get_jets(itree, self.debug)
            matchresult, flag = utils.associate_vectors(
                jets, partons, self.radius)
            PartonJetMatchFlag[0] = flag

            if flag == 0:
                # Save the truth association only if every parton is
                # associated to a different jet
                for ip, iparton in enumerate(hpair):
                    H_jets[ip] = matchresult[0][iparton]
                for jp, jparton in enumerate(wpair):
                    W_jets[jp] = matchresult[0][jparton]

            otree.Fill()

        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 7
0
    def process(self, **kwargs):
        print module_name

        tree = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree, input)

        newbranches = ["V_jets", "VBS_jets"]

        self.clone(output, newbranches)
        V_jets = numpy.zeros(2, dtype=numpy.int32)
        VBS_jets = numpy.zeros(2, dtype=numpy.int32)
        self.otree.Branch('V_jets', V_jets, 'V_jets[2]/I')
        self.otree.Branch('VBS_jets', VBS_jets, 'VBS_jets[2]/I')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ', nentries

        # avoid dots to go faster
        itree = self.itree
        otree = self.otree

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i % step == 0.:
                print i, 'events processed :: ', nentries

            jets = utils.get_jets(itree, self.ptmin_jet, self.debug)
            vpair = [-1, -1]
            vbspair = [-1, -1]

            if self.mode == 0:

                if len(jets) >= 2:
                    vpair = utils.nearest_masses_pair(jets, [80.385, 91.1876])

                    if len(jets) >= 4:
                        # Save pairs of (index, jet) for the next step
                        remaining_jets = [(i, j) for i, j in enumerate(jets)
                                          if i not in vpair]
                        # The result of the next step are indexes in the new collection of jets
                        vbspair_newindexes = utils.max_mjj_pair(
                            [rj[1] for rj in remaining_jets])
                        # going back to global index
                        vbspair = [
                            remaining_jets[i][0] for i in vbspair_newindexes
                        ]

                    elif self.debug:
                        print "Less than 4 jets available"

            elif self.mode == 1:

                if len(jets) >= 2:
                    vbspair = utils.max_mjj_pair(jets)

                    if len(jets) >= 4:
                        # Save pairs of (index, jet) for the next step
                        remaining_jets = [(i, j) for i, j in enumerate(jets)
                                          if i not in vbspair]
                        # The result of the next step are indexes in the new collection of jets
                        vpair_newindexes = utils.nearest_masses_pair(
                            [rj[1] for rj in remaining_jets],
                            [80.385, 91.1876])
                        # going back to global index
                        vpair = [
                            remaining_jets[i][0] for i in vpair_newindexes
                        ]

                    elif self.debug:
                        print "Less than 4 jets available"

            V_jets[0], V_jets[1] = vpair
            VBS_jets[0], VBS_jets[1] = vbspair

            otree.Fill()

        self.disconnect()
        print '- Eventloop completed'
Exemplo n.º 8
0
    def process(self,**kwargs):
        print module_name

        tree  = kwargs['tree']
        input = kwargs['input']
        output = kwargs['output']

        self.connect(tree,input)

        newbranches = ["V_jets", "VBS_jets"]

        self.clone(output,newbranches)
        V_jets    =   numpy.zeros(2, dtype=numpy.int32)
        VBS_jets  =   numpy.zeros(2, dtype=numpy.int32)
        self.otree.Branch('V_jets',         V_jets,         'V_jets[2]/I')
        self.otree.Branch('VBS_jets',       VBS_jets,       'VBS_jets[2]/I')

        nentries = self.itree.GetEntries()
        print 'Total number of entries: ',nentries 

        # avoid dots to go faster
        itree     = self.itree
        otree     = self.otree

        print '- Starting eventloop'
        step = 5000
        for i in xrange(nentries):
            itree.GetEntry(i)
            if i > 0 and i%step == 0.:
                print i,'events processed :: ', nentries

            jets = utils.get_jets(itree, self.ptmin_jet, self.debug)
            vpair   = [-1,-1]
            vbspair = [-1,-1]

            if self.mode == 0:
                
                if len(jets) >=2:
                    vpair = utils.nearest_masses_pair(jets, [80.385, 91.1876])
            
                    if len(jets) >=4:
                        # Save pairs of (index, jet) for the next step
                        remaining_jets = [(i,j) for i,j in enumerate(jets) if i not in vpair]
                        # The result of the next step are indexes in the new collection of jets
                        vbspair_newindexes = utils.max_mjj_pair([rj[1] for rj in remaining_jets])
                        # going back to global index 
                        vbspair = [remaining_jets[i][0] for i in vbspair_newindexes]
                                                                
                    elif self.debug:
                        print "Less than 4 jets available"

            elif self.mode == 1:

                if len(jets) >=2:
                    vbspair = utils.max_mjj_pair(jets)
            
                    if len(jets) >=4:
                        # Save pairs of (index, jet) for the next step
                        remaining_jets = [(i,j) for i,j in enumerate(jets) if i not in vbspair]
                        # The result of the next step are indexes in the new collection of jets
                        vpair_newindexes = utils.nearest_masses_pair([rj[1] for rj in remaining_jets], [80.385, 91.1876])
                        # going back to global index 
                        vpair = [remaining_jets[i][0] for i in vpair_newindexes]
                                                                
                    elif self.debug:
                        print "Less than 4 jets available"


            V_jets[0], V_jets[1] = vpair
            VBS_jets[0], VBS_jets[1] = vbspair

            otree.Fill()
  
        self.disconnect()
        print '- Eventloop completed'