Exemple #1
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.initReaders(inputTree)  # initReaders must be called in beginFile
        #wrappedOutputTree.SetAutoSave()
        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)
        print "[jhchoi]self.out=", type(self.out)
        print "before,autosave=", self.out._tree.GetAutoSave()
        self.out._tree.SetAutoSave()
        print "after,autosave,=", self.out._tree.GetAutoSave()
        # New Branches
        self.out.branch('Lepton_RecoSF', 'F', lenVar='nLepton')
        self.out.branch('Lepton_RecoSF_Up', 'F', lenVar='nLepton')
        self.out.branch('Lepton_RecoSF_Down', 'F', lenVar='nLepton')

        self.wp_sf_pf = [
            '_IdIsoSF', '_IdIsoSF_Up', '_IdIsoSF_Down', '_IdIsoSF_Syst',
            '_TotSF', '_TotSF_Up', '_TotSF_Down'
        ]
        for wp in self.ElectronWP[self.cmssw]['TightObjWP']:
            for postfix in self.wp_sf_pf:
                self.out.branch('Lepton_tightElectron_' + wp + postfix,
                                'F',
                                lenVar='nLepton')
        for wp in self.MuonWP[self.cmssw]['TightObjWP']:
            for postfix in self.wp_sf_pf:
                self.out.branch('Lepton_tightMuon_' + wp + postfix,
                                'F',
                                lenVar='nLepton')
Exemple #2
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.jet_idx_name = ''

        self.out = mappedOutputTree(wrappedOutputTree, mapname=self._branch_map) 
        for var in self.angle_var:
            for obj in self.angle_obj:
                self.out.branch('MHlnjj_'+var+'_'+obj, 'F')
        for var in self.var:
            for obj in self.obj:
                self.out.branch('MHlnjj_'+var+'_'+obj, 'F')

        self.out.branch('MHlnjj_pt_l',     'F')
        self.out.branch('MHlnjj_pt_j1',    'F')
        self.out.branch('MHlnjj_pt_j2',    'F')

        self.out.branch('MHlnjj_eta_l',     'F')
        self.out.branch('MHlnjj_eta_j1',    'F')
        self.out.branch('MHlnjj_eta_j2',    'F')

        self.out.branch('MHlnjj_idx_j3',    'I')

        self.out.branch('MHlnjj_PTljj_D_PTmet',     'F')
        self.out.branch('MHlnjj_PTljj_D_Mlmetjj',   'F')
        self.out.branch('MHlnjj_MINPTlj_D_PTmet',   'F')
        self.out.branch('MHlnjj_MINPTlj_D_Mlmetjj', 'F')
        self.out.branch('MHlnjj_MAXPTlj_D_PTmet',   'F')
        self.out.branch('MHlnjj_MAXPTlj_D_Mlmetjj', 'F')
        self.out.branch('MHlnjj_MTljj_D_PTmet',     'F')
        self.out.branch('MHlnjj_MTljj_D_Mlmetjj',   'F')
Exemple #3
0
 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
     self.out = mappedOutputTree(wrappedOutputTree,
                                 mapname=self._branch_map)
     self.itree = inputTree
     for key in self.formulas.keys():
         self.formulas[key] = eval('lambda event:' + self.formulas[key])
         self.out.branch(key, 'F')
Exemple #4
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)
        self.newbranches = [
            'hm',
            'me_vbf_hsm',
            'me_vbf_hm',
            'me_vbf_hp',
            'me_vbf_hl',
            'me_vbf_mixhm',
            'me_vbf_mixhp',
            'me_wh_hsm',
            'me_wh_hm',
            'me_wh_hp',
            'me_wh_hl',
            'me_wh_mixhm',
            'me_wh_mixhp',
            'me_zh_hsm',
            'me_zh_hm',
            'me_zh_hp',
            'me_zh_hl',
            'me_zh_mixhm',
            'me_zh_mixhp',
            'me_qcd_hsm',
        ]

        for nameBranches in self.newbranches:
            self.out.branch(nameBranches, "F")
Exemple #5
0
 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
     self.out = mappedOutputTree(wrappedOutputTree,
                                 mapname=self._output_branch_map)
     # New Branches
     self.out.branch("BoostedWtagSF_nominal", "F")
     self.out.branch("BoostedWtagSF_up", "F")
     self.out.branch("BoostedWtagSF_down", "F")
Exemple #6
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.classifiers = []
        self.preprocessing = []
        for c, p in zip(["best_model_1.hdf5","best_model_0.hdf5"], ["fold0_keras_preprocessing_neutrino.pickle","fold1_keras_preprocessing_neutrino.pickle"]):
          self.classifiers.append(load_model(self.pathtotraining+c, custom_objects={'customLoss': self.customLoss}))
          self.preprocessing.append(pickle.load(open(self.pathtotraining+p, "rb")))

        self.out = mappedOutputTree(wrappedOutputTree, suffix= "_"+self._suffix)
        self.out.branch("DNN_mth", "F")
Exemple #7
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.initReaders(inputTree) # initReaders must be called in beginFile
        self.out = mappedOutputTree(wrappedOutputTree, mapname=self._branch_map)
        self.metCollections = {"Puppi":"PuppiMET"} # Name for branch and name of MET collection # "PF":"MET", 
        # New branches
        for MET in self.metCollections:
           for typ in Wlep_br:
              for var in Wlep_br[typ]:
                 if 'Wlep_' in var: self.out.branch("HM_"+var+"_"+MET, typ)

        #self.out.branch("IsWlepEvt", "I")
        self.out.branch("HM_Wlep_mt" , "F")
Exemple #8
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.classifiers = []
        self.preprocessing = []
        for c, p in zip(["best_model_1.hdf5", "best_model_0.hdf5"], [
                "fold0_keras_preprocessing_production.pickle",
                "fold1_keras_preprocessing_production.pickle"
        ]):
            self.classifiers.append(load_model(self.pathtotraining + c))
            self.preprocessing.append(
                pickle.load(open(self.pathtotraining + p, "rb")))

        self.out = mappedOutputTree(wrappedOutputTree,
                                    suffix="_" + self._suffix)
        self.out.branch("DNN_isVBF", "F")
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.classifiers = []
        self.preprocessing = []
        for c, p in zip(["best_model_1.hdf5", "best_model_0.hdf5"], [
                "fold0_keras_preprocessing_neutrinosemi.pickle",
                "fold1_keras_preprocessing_neutrinosemi.pickle"
        ]):
            self.classifiers.append(load_model(self.pathtotraining + c))
            self.preprocessing.append(
                pickle.load(open(self.pathtotraining + p, "rb")))

        suffix = "" if self._branch_map == "" else "_" + self._branch_map
        self.out = mappedOutputTree(wrappedOutputTree, suffix=suffix)
        self.out.branch("DNN_mth", "F")
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        # Using branchmap (Only JEs and Fatjet systematics change the pairing)
        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)

        # New Branches
        for key in pairing_strategies_resolved.keys():
            self.out.branch("VBS_jets_" + key, "I", n=2)
            self.out.branch("V_jets_" + key, "I", n=2)
        for key in pairing_strategies_fatjet.keys():
            self.out.branch("VBS_jets_" + key, "I", n=2)
            self.out.branch("V_jets_" + key, "I", n=2)
        # 0-boosted, 1-resolved (4jets)
        self.out.branch("VBS_category", "I")
Exemple #11
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.classifiers = []
        self.preprocessing = []
        for c, p in zip(["best_model_1.hdf5","best_model_0.hdf5"], ["fold0_keras_preprocessing_category.pickle","fold1_keras_preprocessing_category.pickle"]):
          self.classifiers.append(load_model(self.pathtotraining+c))
          self.preprocessing.append(pickle.load(open(self.pathtotraining+p, "rb")))

        self.out = mappedOutputTree(wrappedOutputTree, suffix= "_"+self._suffix)
        self.classes = ["WW", "ggH115_190", "ggH200_450", "ggH500_5000", "VBF115_190", "VBF200_450", "VBF500_5000", "other"]
        for cla in self.classes:
          self.out.branch("DNN_"+cla, "F")
        self.out.branch("DNN_categ", "I")
        self.out.branch("DNN_categ_maxscore", "I")
        self.out.branch("DNN_categ_difftosecond", "I")
Exemple #12
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):

        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)
        #self.out.branch('Whad_px','F')
        #self.out.branch('Whad_py','F')
        #self.out.branch('Whad_pz','F')
        #self.out.branch('Whad_E','F')

        self.out.branch(self.prefix + 'Whad_pt', 'F')
        self.out.branch(self.prefix + 'Whad_eta', 'F')
        self.out.branch(self.prefix + 'Whad_phi', 'F')
        self.out.branch(self.prefix + 'Whad_mass', 'F')

        self.out.branch(self.prefix + 'idx_j1', 'I')
        self.out.branch(self.prefix + 'idx_j2', 'I')
Exemple #13
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        #using suffix instead of mapname to save all branches with same suffix.
        suffix = "" if self._branch_map == "" else "_" + self._branch_map
        self.out = mappedOutputTree(wrappedOutputTree, suffix=suffix)

        # New Branches
        for typ, branches in vbs_vars.VBSjjlnu_branches.items():
            for var in branches:
                self.out.branch(var, typ)
        for vec_branch in vbs_vars.VBSjjlnu_vector_branches:
            if type(vec_branch["len"]) == str:
                self.out.branch(vec_branch["name"],
                                vec_branch["type"],
                                lenVar=vec_branch["len"])
            elif type(vec_branch["len"]) == int:
                self.out.branch(vec_branch["name"],
                                vec_branch["type"],
                                n=vec_branch["len"])
Exemple #14
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.initReaders() # initReaders must be called in beginFile
        self.out = mappedOutputTree(wrappedOutputTree, mapname=self._branch_map)
        
        if self.keepRunP:
           # Check if input tree indeed contains run_period
           #isThere = False
           #for br in wrappedOutputTree.GetListOfBranches():
           #   if br.GetName() == 'run_period': isThere = True
           #if not isThere: print("TrigMaker WARNING: Input tree does not contain the 'run_period' branch, while 'keepRunP' is True.")
           #else: 
           try: self.NewVar['I'].remove('run_period')
           except: pass
 
        for typ in self.NewVar:
           for name in self.NewVar[typ]:
              if 'TriggerEmulator' in name: self.out.branch(name, typ, 6)
              else:                         self.out.branch(name, typ)
Exemple #15
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)

        #New Branches ##For Event

        self.out.branch("HM_Flavlnjj", "I")

        self.out.branch("HM_IsBoosted", "O")
        self.out.branch("HM_IsResolved", "O")
        self.out.branch("HM_IsBTopTagged", "O")

        ##For Boosted Selection ##For FatJet
        self.list_WJetVar = [
            'pt', 'eta', 'phi', 'mass', 'tau21', 'WptOvHfatM', 'HlnFat_mass',
            'CFatJetIdx'
        ]
        self.suffix = '' if (
            self._branch_map == ''
            or 'fatjet' not in self._branch_map) else '_' + self._branch_map
        for myvar in self.list_WJetVar:
            self.out.branch("HM_CleanFatJetPassMBoosted_" + myvar,
                            'F',
                            lenVar='HM_nCleanFatJetPassMBoosted' + self.suffix)

        # For Boosted-like selection, not requiring tau21 cut
        self.out.branch("HM_idxWfat_noTau21Cut", "I")
        self.out.branch("HM_HlnFatMass_noTau21Cut", "F")

        self.out.branch("HM_WptOvHak4M", "F")
        self.out.branch("HM_Hlnjj_mass", "F")
        #self.out.branch("Wlep_mt" , "F")
        self.out.branch("HM_Hlnjj_mt", "F")

        self.out.branch("HM_vbfFat_jj_dEta", "F")
        self.out.branch("HM_vbfFat_jj_mass", "F")
        self.out.branch("HM_vbfjj_jj_dEta", "F")
        self.out.branch("HM_vbfjj_jj_mass", "F")

        self.out.branch("HM_largest_nonW_mjj", "F")

        self.out.branch("HM_IsVbfFat", "O")
        self.out.branch("HM_IsVbfjj", "O")
Exemple #16
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)
        self.newbranches = [
            'pfmetPhi_zh4l',
            'z0Mass_zh4l',
            'z0Pt_zh4l',
            'z1Mass_zh4l',
            'z1Pt_zh4l',
            'zaMass_zh4l',
            'zbMass_zh4l',
            'flagZ1SF_zh4l',
            'z0DeltaPhi_zh4l',
            'z1DeltaPhi_zh4l',
            'zaDeltaPhi_zh4l',
            'zbDeltaPhi_zh4l',
            'minDeltaPhi_zh4l',
            'z0DeltaR_zh4l',
            'z1DeltaR_zh4l',
            'zaDeltaR_zh4l',
            'zbDeltaR_zh4l',
            'lep1Mt_zh4l',
            'lep2Mt_zh4l',
            'lep3Mt_zh4l',
            'lep4Mt_zh4l',
            'minMt_zh4l',
            'z1Mt_zh4l',
            'mllll_zh4l',
            'chllll_zh4l',
            'z1dPhi_lep1MET_zh4l',
            'z1dPhi_lep2MET_zh4l',
            'z1mindPhi_lepMET_zh4l',
        ]

        for nameBranches in self.newbranches:
            self.out.branch(nameBranches, "F")
Exemple #17
0
 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
     self.out = mappedOutputTree(wrappedOutputTree,
                                 mapname=self._output_branch_map)
     if self._output_branch_map == "":
         # New Branches
         for typ in CleanFatJet_br:
             for var in CleanFatJet_br[typ]:
                 self.out.branch(var, typ, lenVar='nCleanFatJet')
         #vector of CleanJet idx not overlapping with Fatjets
         self.out.branch('CleanJetNotFat_jetIdx',
                         "I",
                         lenVar="nCleanJetNotFat")
         # Distance from the first FatJet
         self.out.branch('CleanJetNotFat_deltaR',
                         "F",
                         lenVar="nCleanJetNotFat")
     else:
         ##################
         #N.B little hack for lenVar with variation
         # New Branches
         for typ in CleanFatJet_br:
             for var in CleanFatJet_br[typ]:
                 self.out.branch(var,
                                 typ,
                                 lenVar='nCleanFatJet_' +
                                 self._output_branch_map)
         #vector of CleanJet idx not overlapping with Fatjets
         self.out.branch('CleanJetNotFat_jetIdx',
                         "I",
                         lenVar="nCleanJetNotFat_" +
                         self._output_branch_map)
         # Distance from the first FatJet
         self.out.branch('CleanJetNotFat_deltaR',
                         "F",
                         lenVar="nCleanJetNotFat_" +
                         self._output_branch_map)
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.initReaders(inputTree)  # initReaders must be called in beginFile
        self.out = mappedOutputTree(wrappedOutputTree,
                                    mapname=self._branch_map)

        # New Branches
        self.out.branch('Lepton_RecoSF', 'F', lenVar='nLepton')
        self.out.branch('Lepton_RecoSF_Up', 'F', lenVar='nLepton')
        self.out.branch('Lepton_RecoSF_Down', 'F', lenVar='nLepton')

        self.wp_sf_pf = [
            '_IdIsoSF', '_IdIsoSF_Up', '_IdIsoSF_Down', '_IdIsoSF_Syst',
            '_TotSF', '_TotSF_Up', '_TotSF_Down'
        ]
        for wp in self.ElectronWP[self.cmssw]['TightObjWP']:
            for postfix in self.wp_sf_pf:
                self.out.branch('Lepton_tightElectron_' + wp + postfix,
                                'F',
                                lenVar='nLepton')
        for wp in self.MuonWP[self.cmssw]['TightObjWP']:
            for postfix in self.wp_sf_pf:
                self.out.branch('Lepton_tightMuon_' + wp + postfix,
                                'F',
                                lenVar='nLepton')
Exemple #19
0
 def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
     self.out = mappedOutputTree(wrappedOutputTree,
                                 mapname=self._branch_map)
     self.itree = inputTree
     for iMva in self.mvaDic:
         self.out.branch(iMva, 'F')
Exemple #20
0
    def beginFile(self, inputFile, outputFile, inputTree, wrappedOutputTree):
        self.out = mappedOutputTree(wrappedOutputTree, mapname=self._branch_map)
        self.newbranches = [
           'mll',
           'dphill',
           'yll',
           'ptll',
           'pt1',
           'pt2',
           'mth',
           'mcoll',
           'mcollWW',
           'mTi',
           'mTe',
           'choiMass',
           'mR',
           'mT2',
           'channel',


           'drll',
           'dphilljet',
           'dphilljetjet',
           'dphilljetjet_cut',
           'dphillmet',
           'dphilmet',
           'dphilmet1',
           'dphilmet2',
           'mtw1',
           'mtw2',
           
           'mjj',
           'detajj',
           'njet',
          
           'mllWgSt',
           'drllWgSt',
           'mllThird',
           'mllOneThree',
           'mllTwoThree',
           'drllOneThree',
           'drllTwoThree',
           
           'dphijet1met',  
           'dphijet2met',  
           'dphijjmet',    
           'dphijjmet_cut',    
           'dphilep1jet1', 
           'dphilep1jet2', 
           'dphilep2jet1', 
           'dphilep2jet2',
           'mindetajl',
           'detall',
           'dphijj',
           'maxdphilepjj',
           'dphilep1jj',
           'dphilep2jj',
          
           'ht',
           'vht_pt',
           'vht_phi',
           
           'projpfmet',
           'dphiltkmet',
           'projtkmet',
           'mpmet',
           
           'pTWW',
           'pTHjj',

           'recoil',
           'jetpt1_cut',
           'jetpt2_cut',
           'dphilljet_cut',
           'dphijet1met_cut',
           'dphijet2met_cut',
           'PfMetDivSumMet',
           'upara',
           'uperp',
           'm2ljj20',
           'm2ljj30',
# for VBF training
           'ptTOT_cut',
           'mTOT_cut',
           'OLV1_cut',
           'OLV2_cut',
           'Ceta_cut',
#whss
           'mlljj20_whss',
           'mlljj30_whss',
           'WlepPt_whss',
           'WlepMt_whss'
          ]
        
        for nameBranches in self.newbranches :
          self.out.branch(nameBranches  ,  "F");