def __init__(self, fname, **kwargs): kwargs['channel'] = 'etau' super(ModuleETau,self).__init__(fname,**kwargs) self.out = TreeProducerETau(fname,self) # TRIGGERS jsonfile = os.path.join(datadir,"trigger/tau_triggers_%d.json"%(self.year)) self.trigger = TrigObjMatcher(jsonfile,trigger='SingleElectron',isdata=self.isdata) self.eleCutPt = self.trigger.ptmins[0] self.tauCutPt = 20 self.eleCutEta = 2.3 self.tauCutEta = 2.3 # CORRECTIONS if self.ismc: self.eleSFs = ElectronSFs(year=self.year) # electron id/iso/trigger SFs self.tesTool = TauESTool(tauSFVersion[self.year]) # real tau energy scale corrections self.fesTool = TauFESTool(tauSFVersion[self.year]) # e -> tau fake energy scale self.tauSFs = TauIDSFTool(tauSFVersion[self.year],'DeepTau2017v2p1VSjet','Tight') self.etfSFs = TauIDSFTool(tauSFVersion[self.year],'DeepTau2017v2p1VSe', 'VLoose') self.mtfSFs = TauIDSFTool(tauSFVersion[self.year],'DeepTau2017v2p1VSmu', 'Tight') # CUTFLOW self.out.cutflow.addcut('none', "no cut" ) self.out.cutflow.addcut('trig', "trigger" ) self.out.cutflow.addcut('electron', "electron" ) self.out.cutflow.addcut('tau', "tau" ) self.out.cutflow.addcut('pair', "pair" ) self.out.cutflow.addcut('weight', "no cut, weighted", 15 ) self.out.cutflow.addcut('weight_no0PU', "no cut, weighted, PU>0", 16 ) # use for normalization
def __init__(self, year, algorithm, wp_iso, wp_e, wp_mu): self.sftool_iso = TauIDSFTool(YEARLIB[year], ISOLIB[algorithm], WPLIB[wp_iso]) self.sftool_e = TauIDSFTool( YEARLIB[year], ELIB[getCorrespondingLightLepDiscr(algorithm)[0]], WPLIB[wp_e]) self.sftool_mu = TauIDSFTool( YEARLIB[year], MULIB[getCorrespondingLightLepDiscr(algorithm)[1]], WPLIB[wp_mu])
def __init__(self, fname, **kwargs): kwargs['channel'] = 'mutau' super(ModuleMuTau, self).__init__(fname, **kwargs) self.out = TreeProducerMuTau(fname, self) # TRIGGERS if self.year == 2016: self.trigger = lambda e: e.HLT_IsoMu22 or e.HLT_IsoMu22_eta2p1 or e.HLT_IsoTkMu22 or e.HLT_IsoTkMu22_eta2p1 #or e.HLT_IsoMu19_eta2p1_LooseIsoPFTau20_SingleL1 self.muonCutPt = lambda e: 23 self.muonCutEta = lambda e: 2.4 if e.HLT_IsoMu22 or e.HLT_IsoTkMu22 else 2.1 elif self.year == 2017: self.trigger = lambda e: e.HLT_IsoMu24 or e.HLT_IsoMu27 #or e.HLT_IsoMu20_eta2p1_LooseChargedIsoPFTau27_eta2p1_CrossL1 self.muonCutPt = lambda e: 25 if e.HLT_IsoMu24 else 28 self.muonCutEta = lambda e: 2.4 else: self.trigger = lambda e: e.HLT_IsoMu24 or e.HLT_IsoMu27 #or e.HLT_IsoMu20_eta2p1_LooseChargedIsoPFTau27_eta2p1_CrossL1 self.muonCutPt = lambda e: 25 self.muonCutEta = lambda e: 2.4 self.tauCutPt = 20 self.tauCutEta = 2.3 # CORRECTIONS if self.ismc: self.muSFs = MuonSFs( era=self.era, verb=self.verbosity) # muon id/iso/trigger SFs self.tesTool = TauESTool( tauSFVersion[self.year]) # real tau energy scale corrections self.fesTool = TauFESTool( tauSFVersion[self.year]) # for mu -> tau fake negligible self.tauSFs = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSjet', 'Tight') self.etfSFs = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSe', 'VLoose') self.mtfSFs = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSmu', 'Tight') # CUTFLOW self.out.cutflow.addcut('none', "no cut") self.out.cutflow.addcut('trig', "trigger") self.out.cutflow.addcut('muon', "muon") self.out.cutflow.addcut('tau', "tau") self.out.cutflow.addcut('pair', "pair") self.out.cutflow.addcut('weight', "no cut, weighted", 15) self.out.cutflow.addcut('weight_no0PU', "no cut, weighted, PU>0", 16) # use for normalization
def __init__(self, fname, **kwargs): kwargs['channel'] = 'mutau' super(ModuleTauTau, self).__init__(fname, **kwargs) self.out = TreeProducerTauTau(fname, self) # TRIGGERS jsonfile = os.path.join(datadir, "trigger/tau_triggers_%d.json" % (self.year)) self.trigger = TrigObjMatcher(jsonfile, trigger='ditau', isdata=self.isdata) self.tauCutPt = 40 self.tauCutEta = 2.1 # CORRECTIONS if self.ismc: self.trigTool = TauTriggerSFs('tautau', 'Medium', year=self.year) self.trigTool_tight = TauTriggerSFs('tautau', 'Tight', year=self.year) self.tesTool = TauESTool( tauSFVersion[self.year]) # real tau energy scale self.fesTool = TauFESTool( tauSFVersion[self.year]) # e -> tau fake energy scale self.tauSFs = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSjet', 'Medium', dm=True) self.tauSFs_tight = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSjet', 'Tight', dm=True) self.etfSFs = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSe', 'VVLoose') self.mtfSFs = TauIDSFTool(tauSFVersion[self.year], 'DeepTau2017v2p1VSmu', 'Loose') # CUTFLOW self.out.cutflow.addcut('none', "no cut") self.out.cutflow.addcut('trig', "trigger") self.out.cutflow.addcut('tau', "tau") self.out.cutflow.addcut('pair', "ditau pair") self.out.cutflow.addcut('weight', "no cut, weighted", 15) self.out.cutflow.addcut('weight_no0PU', "no cut, weighted, PU>0", 16) # use for normalization
def printSFTable(year,id,wp,vs='pt',emb=False,otherVSlepWP=False): assert vs in ['pt','dm','eta'], "'vs' argument should be pt', 'dm' or 'eta'!" dm = (vs=='dm') if emb and 'VSjet' not in id: print("SFs for ID '%s' not available for embedded samples. Skipping..."%id) return sftool = TauIDSFTool(year,id,wp,dm=dm,emb=emb,otherVSlepWP=otherVSlepWP) if vs=='pt': ptvals = [10,20,21,25,26,30,31,35,40,50,70,100,200,500,600,700,800,1000,1500,2000,] print(">>> ") print(">>> SF for %s WP of %s in %s"%(wp,green(id),year)) print(">>> ") print(">>> %10s"%('var \ pt')+''.join("%9.1f"%pt for pt in ptvals)) print(">>> %10s"%("central") +''.join("%9.5f"%sftool.getSFvsPT(pt,5) for pt in ptvals)) print(">>> %10s"%("up") +''.join("%9.5f"%sftool.getSFvsPT(pt,5,'Up') for pt in ptvals)) print(">>> %10s"%("down") +''.join("%9.5f"%sftool.getSFvsPT(pt,5,'Down') for pt in ptvals)) print(">>> ") ###sftool.getSFvsDM(25,1,5) # results in an error ###sftool.getSFvsEta(1.5,1,5) # results in an error elif vs=='dm': dmvals = [0,1,5,6,10,11] for pt in [25,50]: print(">>> ") print(">>> SF for %s WP of %s in %s with pT = %s GeV"%(wp,green(id),year,pt)) print(">>> ") print(">>> %10s"%('var \ DM')+''.join("%9d"%dm for dm in dmvals)) print(">>> %10s"%("central") +''.join("%9.5f"%sftool.getSFvsDM(pt,dm,5) for dm in dmvals)) print(">>> %10s"%("up") +''.join("%9.5f"%sftool.getSFvsDM(pt,dm,5,'Up') for dm in dmvals)) print(">>> %10s"%("down") +''.join("%9.5f"%sftool.getSFvsDM(pt,dm,5,'Down') for dm in dmvals)) print(">>> ") ###sftool.getSFvsPT(pt,5) # results in an error ###sftool.getSFvsEta(1.5,1,5) # results in an error elif vs=='eta': if emb: print("vsEta binned SFs not available for embedded samples. Skipping...") return etavals = [0,0.2,0.5,1.0,1.5,2.0,2.2,2.3,2.4] for genmatch in [1,2]: print(">>> ") print(">>> SF for %s WP of %s in %s with genmatch %d"%(wp,green(id),year,genmatch)) print(">>> ") print(">>> %10s"%('var \ eta')+''.join("%9.3f"%eta for eta in etavals)) print(">>> %10s"%("central") +''.join("%9.5f"%sftool.getSFvsEta(eta,genmatch) for eta in etavals)) print(">>> %10s"%("up") +''.join("%9.5f"%sftool.getSFvsEta(eta,genmatch,'Up') for eta in etavals)) print(">>> %10s"%("down") +''.join("%9.5f"%sftool.getSFvsEta(eta,genmatch,'Down') for eta in etavals)) print(">>> ")
def printSFTable(year,id,wp,vs='pt'): assert vs in ['pt','dm','eta'], "'vs' argument should be pt', 'dm' or 'eta'!" dm = (vs=='dm') sftool = TauIDSFTool(year,id,wp,dm=dm) if vs=='pt': ptvals = [10,20,21,25,26,30,31,35,40,50,70,100,200,500,600,700,800,1000,1500,2000,] print ">>> " print ">>> SF for %s WP of %s in %s"%(wp,id,year) print ">>> " print ">>> %10s"%('var \ pt')+''.join("%9.1f"%pt for pt in ptvals) print ">>> %10s"%("central") +''.join("%9.5f"%sftool.getSFvsPT(pt,5) for pt in ptvals) print ">>> %10s"%("up") +''.join("%9.5f"%sftool.getSFvsPT(pt,5,'Up') for pt in ptvals) print ">>> %10s"%("down") +''.join("%9.5f"%sftool.getSFvsPT(pt,5,'Down') for pt in ptvals) print ">>> " ###sftool.getSFvsDM(25,1,5) # results in an error ###sftool.getSFvsEta(1.5,1,5) # results in an error elif vs=='dm': dmvals = [0,1,5,6,10,11] for pt in [25,50]: print ">>> " print ">>> SF for %s WP of %s in %s with pT = %s GeV"%(wp,id,year,pt) print ">>> " print ">>> %10s"%('var \ DM')+''.join("%9d"%dm for dm in dmvals) print ">>> %10s"%("central") +''.join("%9.5f"%sftool.getSFvsDM(pt,dm,5) for dm in dmvals) print ">>> %10s"%("up") +''.join("%9.5f"%sftool.getSFvsDM(pt,dm,5,'Up') for dm in dmvals) print ">>> %10s"%("down") +''.join("%9.5f"%sftool.getSFvsDM(pt,dm,5,'Down') for dm in dmvals) print ">>> " ###sftool.getSFvsPT(pt,5) # results in an error ###sftool.getSFvsEta(1.5,1,5) # results in an error elif vs=='eta': etavals = [0,0.2,0.5,1.0,1.5,2.0,2.2,2.3,2.4] for genmatch in [1,2]: print ">>> " print ">>> SF for %s WP of %s in %s with genmatch %d"%(wp,id,year,genmatch) print ">>> " print ">>> %10s"%('var \ eta')+''.join("%9.3f"%eta for eta in etavals) print ">>> %10s"%("central") +''.join("%9.5f"%sftool.getSFvsEta(eta,genmatch) for eta in etavals) print ">>> %10s"%("up") +''.join("%9.5f"%sftool.getSFvsEta(eta,genmatch,'Up') for eta in etavals) print ">>> %10s"%("down") +''.join("%9.5f"%sftool.getSFvsEta(eta,genmatch,'Down') for eta in etavals) print ">>> "
def AddFinalWeights(FileToRun, args): print("") print("Creating final weights branch for: " + FileToRun) print("") CheckFile = ROOT.TFile(FileToRun) #make the name easier to understand FileName = FileToRun[FileToRun.rfind("/") + 1:] #Need cross section weighting. Check for it try: CheckFile.mt_Selected.CrossSectionWeighting except: print("Failed to find cross section weightings. Adding them...") AddCrossSectionWeightings.AddCrossSectionWeightings(FileToRun, args) try: CheckFile.mt_Selected.ZPTWeighting except: print("Failed to find ZPT Weights. Adding them...") AddZPTReweighting.Apply2016ZPTReweighting(FileToRun, args) if FileName != "Data.root" and FileName != "Embedded.root": try: CheckFile.mt_Selected.PileupWeight except: print("Failed to find pileup weights. Adding them...") AddPileupWeightings.AddPileupWeightings(FileToRun, args) try: CheckFile.mt_Selected.MuAndTriggerSF except: print("Failed to find muon scale factors. Adding them...") AddKITMuAndTriggerSFs.AddKITMuAndTriggerSFs(FileToRun, args) CheckFile.Close() ReweightFile = ROOT.TFile(FileToRun, "UPDATE") #we create different weights for different shapes. FinalWeighting = array('f', [0]) FinalWeighting_ZPT_DOWN = array('f', [0]) FinalWeighting_ZPT_UP = array('f', [0]) FinalWeighting_TOP_UP = array('f', [0]) FinalWeighting_TOP_DOWN = array('f', [0]) TheBranch = ReweightFile.mt_Selected.Branch('FinalWeighting', FinalWeighting, 'FinalWeighitng/F') TheBranch_ZPT_DOWN = ReweightFile.mt_Selected.Branch( 'FinalWeighting_ZPT_DOWN', FinalWeighting_ZPT_DOWN, 'FinalWeighitng_ZPT_DOWN/F') TheBranch_ZPT_UP = ReweightFile.mt_Selected.Branch( 'FinalWeighting_ZPT_UP', FinalWeighting_ZPT_UP, 'FinalWeighting_ZPT_UP/F') TheBranch_TOP_UP = ReweightFile.mt_Selected.Branch( 'FinalWeighting_TOP_UP', FinalWeighting_TOP_UP, 'FinalWeighting_TOP_UP/F') TheBranch_TOP_DOWN = ReweightFile.mt_Selected.Branch( 'FinalWeighting_TOP_DOWN', FinalWeighting_TOP_DOWN, 'FinalWeighting_TOP_DOWN/F') tauSFTool = TauIDSFTool(2016, "DeepTau2017v2p1", 'Medium') for i in tqdm(range(ReweightFile.mt_Selected.GetEntries())): ReweightFile.mt_Selected.GetEntry(i) MuVector = ROOT.TLorentzVector() TauVector = ROOT.TLorentzVector() MuVector.SetPtEtaPhiM(ReweightFile.mt_Selected.pt_1, ReweightFile.mt_Selected.eta_1, ReweightFile.mt_Selected.phi_1, ReweightFile.mt_Selected.m_1) TauVector.SetPtEtaPhiM(ReweightFile.mt_Selected.pt_2, ReweightFile.mt_Selected.eta_2, ReweightFile.mt_Selected.phi_2, ReweightFile.mt_Selected.m_2) Weight = ReweightFile.mt_Selected.CrossSectionWeighting #cross section #if not a data file, pileup reweight it if (not args.DisablePileupWeighting and FileName != "Data.root" and FileName != "Embedded.root"): Weight = Weight * ReweightFile.mt_Selected.PileupWeight #possible overlap on trigger SFs? if (not args.DisableMuAndTriggerSFs and FileName != "Data.root" and FileName != "Embedded.root"): Weight = Weight * ReweightFile.mt_Selected.MuAndTriggerSF if FileName != "Embedded.root" and FileName != "Data.root": Weight = Weight * tauSFTool.getSFvsPT(TauVector.Pt()) #mu->tau FR Sf's if not args.DisableEtaWeighting: if (ReweightFile.mt_Selected.gen_match_2 == 2 or ReweightFile.mt_Selected.gen_match_2 == 4): if (abs(TauVector.Eta()) < 0.4): Weight = Weight * 1.47 elif (abs(TauVector.Eta()) < 0.8): Weight = Weight * 1.55 elif (abs(TauVector.Eta()) < 1.2): Weight = Weight * 1.33 elif (abs(TauVector.Eta()) < 1.7): Weight = Weight * 1.72 elif (abs(TauVector.Eta()) < 2.3): Weight = Weight * 2.50 elif (ReweightFile.mt_Selected.gen_match_2 == 1 or ReweightFile.mt_Selected.gen_match_2 == 3): if (abs(TauVector.Eta()) < 1.460): Weight = Weight * 1.21 elif (abs(TauVector.Eta()) >= 1.559): Weight = Weight * 1.38 #Top PT Reweighting if not args.DisableTopReweighting: TopFactor = 1.0 if (FileName == "TT.root"): pttop1 = ReweightFile.mt_Selected.pt_top1 if pttop1 > 400: pttop1 = 400 pttop2 = ReweightFile.mt_Selected.pt_top2 if pttop2 > 400: pttop2 = 400 topfactor = math.sqrt( math.exp(0.0615 - 0.0005 * pttop1) * math.exp(0.0615 - 0.0005 * pttop2)) Weight_TOP_UP = Weight * (2.0 * (topfactor - 1.0) + 1.0) Weight_TOP_DOWN = Weight Weight = Weight * TopFactor #ZPT Weighting if not args.DisableZPTWeighting: Weight_ZPT_DOWN = Weight * ReweightFile.mt_Selected.ZPTWeighting_DOWN Weight_ZPT_UP = Weight * ReweightFile.mt_Selected.ZPTWeighting_UP Weight = Weight * ReweightFile.mt_Selected.ZPTWeighting if FileName == "Data.root": Weight = 1.0 FinalWeighting[0] = Weight if not args.DisableZPTWeighting: FinalWeighting_ZPT_DOWN[0] = Weight_ZPT_DOWN FinalWeighting_ZPT_UP[0] = Weight_ZPT_UP if not args.DisableTopReweighting and (FileName == "TT.root"): FinalWeighting_TOP_UP[0] = Weight_TOP_UP FinalWeighting_TOP_DOWN[0] = Weight_TOP_DOWN TheBranch.Fill() if not args.DisableZPTWeighting: TheBranch_ZPT_DOWN.Fill() TheBranch_ZPT_UP.Fill() if not args.DisableTopReweighting and (FileName == "TT.root"): TheBranch_TOP_UP.Fill() TheBranch_TOP_DOWN.Fill() ReweightFile.cd() ReweightFile.mt_Selected.Write('', ROOT.TObject.kOverwrite) ReweightFile.Write() ReweightFile.Close()
def __init__(self, era, muonSelectionTag="Loose", electronSelectionTag="Veto", photonSelectionTag="Loose", tauSelectionTag="Medium"): self.era = era self.muonSelectionTag = muonSelectionTag self.electronSelectionTag = electronSelectionTag self.photonSelectionTag = photonSelectionTag self.tauSelectionTag = tauSelectionTag #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Muon ~~~~~ # Only looseID miniIso SF existed for 2016 mu_f = [] mu_h = [] if self.era == "2016": mu_f += [ "Muon_IDScaleFactor_wSys_%sGH.root" % self.era, "Muon_LooseID_MiniIso0p2SF_2016.root" ] mu_h += [ "NUM_%sID_DEN_genTracks_eta_pt" % self.muonSelectionTag, "SF" ] if self.era == "2017": mu_f += [ "Muon_IDScaleFactor_wSys_%s.root" % self.era, "Muon_%sID_MiniIso0p2SF_%s.root" % (self.muonSelectionTag, self.era) ] mu_h += [ "NUM_%sID_DEN_genTracks_pt_abseta" % self.muonSelectionTag, "TnP_MC_NUM_MiniIso02Cut_DEN_%sID_PAR_pt_eta" % self.muonSelectionTag ] elif self.era == "2018": ## SUSY recommend to use the 2017 Data/FullSim SFs for MiniIso also ## for 2018, as no changes are expected and these SFs are very close to 1. mu_f += [ "Muon_IDScaleFactor_wSys_%s.root" % self.era, "Muon_%sID_MiniIso0p2SF_%s.root" % (self.muonSelectionTag, "2017") ] mu_h += [ "NUM_%sID_DEN_TrackerMuons_pt_abseta" % self.muonSelectionTag, "TnP_MC_NUM_MiniIso02Cut_DEN_%sID_PAR_pt_eta" % self.muonSelectionTag ] #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Electron ~~~~~ if self.era == "2016": el_f = [ "Electron_GT20GeV_RecoSF_2017v2ID_Run%s.root" % self.era, "Electron_LT20GeV_RecoSF_2017v2ID_Run%s.root" % self.era, "Electron_SUSYScaleFactors_2017v2ID_Run%s.root" % self.era, "Electron_SUSYScaleFactors_2017v2ID_Run%s.root" % self.era ] el_h = [ "EGamma_SF2D", "EGamma_SF2D", "Run%s_CutBased%sNoIso94XV2" % (self.era, self.electronSelectionTag), "Run%s_Mini" % self.era ] elif self.era == "2017": el_f = [ "Electron_GT20GeV_RecoSF_2017v2ID_Run%s.root" % self.era, "Electron_LT20GeV_RecoSF_2017v2ID_Run%s.root" % self.era, "Electron_SUSYScaleFactors_2017v2ID_Run%s.root" % self.era, "Electron_SUSYScaleFactors_2017v2ID_Run%s.root" % self.era ] el_h = [ "EGamma_SF2D", "EGamma_SF2D", "Run%s_CutBased%sNoIso94XV2" % (self.era, self.electronSelectionTag), "Run%s_MVAVLooseTightIP2DMini" % self.era ] elif self.era == "2018": el_f = [ "Electron_GT10GeV_RecoSF_2017v2ID_Run%s.root" % self.era, "Electron_SUSYScaleFactors_2017v2ID_Run%s.root" % self.era, "Electron_SUSYScaleFactors_2017v2ID_Run%s.root" % self.era ] el_h = [ "EGamma_SF2D", "Run%s_CutBased%sNoIso94XV2" % (self.era, self.electronSelectionTag), "Run%s_Mini" % self.era ] #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Photon ~~~~~ # The production used 2016v2 ID for 2016 photon if self.era == "2016": pho_f = [ "Photon_%s_80XCutbased_%s.root" % (self.photonSelectionTag, self.era) ] pho_h = ["EGamma_SF2D"] else: pho_f = [ "Photon_%s_2017v2Cutbased_%s.root" % (self.photonSelectionTag, self.era) ] pho_h = ["EGamma_SF2D"] # In addition to ID scale factors, analysis using it should # apply the electron veto scale factors if self.era == "2016": eleveto_f = ["ElectronVeto_ScaleFactors_80X_2016.root"] eleveto_h = ["Scaling_Factors_HasPix_R9 Inclusive"] else: eleveto_f = ["ElectronVeto_PixelSeed_ScaleFactors_2017.root"] eleveto_h = ["%s_ID" % self.photonSelectionTag] #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Tau ~~~~~ # Update to new TauPOG era mapping self.TauPOGEraMap = { "2016": "2016Legacy", "2017": "2017ReReco", "2018": "2018ReReco", } self.tauSFTool = TauIDSFTool(self.TauPOGEraMap[self.era], 'MVAoldDM2017v2', self.tauSelectionTag) mu_f = [ "%s/src/PhysicsTools/NanoSUSYTools/data/leptonSF/" % os.environ['CMSSW_BASE'] + f for f in mu_f ] el_f = [ "%s/src/PhysicsTools/NanoSUSYTools/data/leptonSF/" % os.environ['CMSSW_BASE'] + f for f in el_f ] pho_f = [ "%s/src/PhysicsTools/NanoSUSYTools/data/leptonSF/" % os.environ['CMSSW_BASE'] + f for f in pho_f ] eleveto_f = [ "%s/src/PhysicsTools/NanoSUSYTools/data/leptonSF/" % os.environ['CMSSW_BASE'] + f for f in eleveto_f ] self.mu_f = ROOT.std.vector(str)(len(mu_f)) self.mu_h = ROOT.std.vector(str)(len(mu_f)) for i in range(len(mu_f)): self.mu_f[i] = mu_f[i] self.mu_h[i] = mu_h[i] self.el_f = ROOT.std.vector(str)(len(el_f)) self.el_h = ROOT.std.vector(str)(len(el_f)) for i in range(len(el_f)): self.el_f[i] = el_f[i] self.el_h[i] = el_h[i] self.pho_f = ROOT.std.vector(str)(len(pho_f)) self.pho_h = ROOT.std.vector(str)(len(pho_f)) for i in range(len(pho_f)): self.pho_f[i] = pho_f[i] self.pho_h[i] = pho_h[i] self.eleveto_f = ROOT.std.vector(str)(len(eleveto_f)) self.eleveto_h = ROOT.std.vector(str)(len(eleveto_f)) for i in range(len(eleveto_f)): self.eleveto_f[i] = eleveto_f[i] self.eleveto_h[i] = eleveto_h[i] for library in [ "libCondFormatsJetMETObjects", "libPhysicsToolsNanoAODTools" ]: if library not in ROOT.gSystem.GetLibraries(): print("Load Library '%s'" % library) ROOT.gSystem.Load(library)
import ROOT from Configurations.Weights.WeightDefinition import Weight as Weight from TauPOG.TauIDSFs.TauIDSFTool import TauIDSFTool import TauIDFunctions tauIDWeight_2016 = Weight() tauIDWeight_2016.name = 'TauIDWeight' tauIDWeight_2016.SFTool = TauIDSFTool("2016Legacy","DeepTau2017v2p1VSjet",'Medium') tauIDWeight_2016.CalculateWeight = TauIDFunctions.CalculateTauIDWeight tauIDWeight_2016.hasUpDownUncertainties = True tauIDWeight_2016.uncertaintyVariationList = [ "TauID_pT0to35_UP", "TauID_pT0to35_DOWN", "TauID_pT35to40_UP", "TauID_pT35to40_DOWN", "TauID_pTgt40_UP", "TauID_pTgt40_DOWN", ] tauIDWeight_2016.InitUncertaintyVariations() tauIDWeight_2016.uncertaintyVariationFunctions = { "TauID_pT0to35_UP": TauIDFunctions.CalculateTauIDWeight_pT0to35_UP, "TauID_pT0to35_DOWN": TauIDFunctions.CalculateTauIDWeight_pT0to35_DOWN, "TauID_pT35to40_UP": TauIDFunctions.CalculateTauIDWeight_pT35to40_UP, "TauID_pT35to40_DOWN": TauIDFunctions.CalculateTauIDWeight_pT35to40_DOWN, "TauID_pTgt40_UP": TauIDFunctions.CalculateTauIDWeight_pTgt40_UP, "TauID_pTgt40_DOWN": TauIDFunctions.CalculateTauIDWeight_pTgt40_DOWN, } tauIDWeight_2017 = Weight() tauIDWeight_2017.name = 'TauIDWeight' tauIDWeight_2017.SFTool = TauIDSFTool("2017ReReco",'DeepTau2017v2p1VSjet','Medium')
def AddFinalWeights(FileToRun, args): print("") print("Creating final weights branch for " + FileToRun) print("") CheckFile = ROOT.TFile(FileToRun) FileName = FileToRun[FileToRun.rfind("/") + 1:] print(FileName) try: CheckFile.mt_Selected.CrossSectionWeighting except: print("Failed to find cross section weightings. Adding them...") AddCrossSectionWeightings.AddCrossSectionWeightings(FileToRun, args) try: CheckFile.mt_Selected.ZPTWeighting except: print("Failed to find ZPT weights. Adding them...") AddZPTReweighting.ApplyZPTReweighting(FileToRun, args) if FileName != "Data.root" and FileName != "Embedded.root": try: CheckFile.mt_Selected.PileupWeight except: print("Failed to find pileup weights. Adding them...") AddPileupWeightings.AddPileupWeightings(FileToRun, args) try: CheckFile.mt_Selected.MuAndTriggerSF except: print("Failed to find mu scale factors. Adding them...") AddKITMuAndTriggerSFs.AddKITMuAndTriggerSFs(FileToRun, args) CheckFile.Close() ReweightFile = ROOT.TFile(FileToRun, "UPDATE") FinalWeighting = array('f', [0]) FinalWeighting_ZPT_DOWN = array('f', [0]) FinalWeighting_ZPT_UP = array('f', [0]) FinalWeighting_TOP_UP = array('f', [0]) FinalWeighting_TOP_DOWN = array('f', [0]) TheBranch = ReweightFile.mt_Selected.Branch('FinalWeighting', FinalWeighting, 'FinalWeighitng/F') TheBranch_ZPT_DOWN = ReweightFile.mt_Selected.Branch( 'FinalWeighting_ZPT_DOWN', FinalWeighting_ZPT_DOWN, 'FinalWeighitng_ZPT_DOWN/F') TheBranch_ZPT_UP = ReweightFile.mt_Selected.Branch( 'FinalWeighting_ZPT_UP', FinalWeighting_ZPT_UP, 'FinalWeighting_ZPT_UP/F') TheBranch_TOP_UP = ReweightFile.mt_Selected.Branch( 'FinalWeighting_TOP_UP', FinalWeighting_TOP_UP, 'FinalWeighting_TOP_UP/F') TheBranch_TOP_DOWN = ReweightFile.mt_Selected.Branch( 'FinalWeighting_TOP_DOWN', FinalWeighting_TOP_DOWN, 'FinalWeighting_TOP_DOWN/F') #get the embedded weighting file. ScaleFactorFile = ROOT.TFile( "/data/aloeliger/CMSSW_9_4_0/src/LegacyCorrectionsWorkspace/output/htt_scalefactors_legacy_2018.root" ) #ScaleFactorFile = ROOT.TFile("/data/aloeliger/CMSSW_9_4_0/src/SMHTTAnalysis/NtuplePolishing/Weightings/htt_scalefactors_v18_2.root") ScaleFactorWorkspace = ScaleFactorFile.w print("Adding the final weighting...") Embedded_XTrg_MuLegWeight = 0.0 Embedded_XTrg_TauLegWeight = 0.0 X_Trg_Events = 0.0 tauSFTool = TauIDSFTool("2018ReReco", "DeepTau2017v2p1VSjet", 'Medium') for i in tqdm(range(ReweightFile.mt_Selected.GetEntries())): ReweightFile.mt_Selected.GetEntry(i) TauVector = ROOT.TLorentzVector() TauVector.SetPtEtaPhiM(ReweightFile.mt_Selected.pt_2, ReweightFile.mt_Selected.eta_2, ReweightFile.mt_Selected.phi_2, ReweightFile.mt_Selected.m_2) MuVector = ROOT.TLorentzVector() MuVector.SetPtEtaPhiM(ReweightFile.mt_Selected.pt_1, ReweightFile.mt_Selected.eta_1, ReweightFile.mt_Selected.phi_1, ReweightFile.mt_Selected.m_1) MetVector = ROOT.TLorentzVector() MetVector.SetPtEtaPhiM(ReweightFile.mt_Selected.met, 0.0, ReweightFile.mt_Selected.metphi, 0.0) #all we have for 2018 so far is cross section and pileup weight #we're just using 2017 Tau ID SF temporarily Weight = ReweightFile.mt_Selected.CrossSectionWeighting if (not args.DisablePileupWeighting and FileName != "Data.root" and FileName != "Embedded.root"): Weight = Weight * ReweightFile.mt_Selected.PileupWeight Weight = Weight * ReweightFile.mt_Selected.bweight # add in the btagging weight to MCs if (not args.DisableMuSFs and FileName != "Data.root" and FileName != "Embedded.root"): Weight = Weight * ReweightFile.mt_Selected.MuAndTriggerSF if (FileName != "Data.root" and FileName != "Embedded.root"): #Weight = Weight * 0.90 #0.90 tight tau ID Weight = Weight * tauSFTool.getSFvsPT(TauVector.Pt()) # elif FileName == "Embedded.root": Weight = Weight * 0.88 if not args.DisableEtaWeighting: if (ReweightFile.mt_Selected.gen_match_2 == 2 or ReweightFile.mt_Selected.gen_match_2 == 4): if (abs(TauVector.Eta()) < 0.4): Weight = Weight * 1.28 elif (abs(TauVector.Eta()) < 0.8): Weight = Weight * 1.2 elif (abs(TauVector.Eta()) < 1.2): Weight = Weight * 1.08 elif (abs(TauVector.Eta()) < 1.7): Weight = Weight * 1.0 elif (abs(TauVector.Eta()) < 2.3): Weight = Weight * 2.3 Trigger24 = ReweightFile.mt_Selected.Trigger24 Trigger27 = ReweightFile.mt_Selected.Trigger27 Trigger2027 = ReweightFile.mt_Selected.Trigger2027 if not args.DisableEmbeddingReconstructionWeighting: if (FileName == "Embedded.root"): if ReweightFile.mt_Selected.l2_decayMode == 0: Weight = Weight * 0.975 elif ReweightFile.mt_Selected.l2_decayMode == 1: Weight = Weight * 0.975 * 1.051 elif ReweightFile.mt_Selected.l2_decayMode == 10: Weight = Weight * 0.975 * 0.975 * 0.975 ScaleFactorWorkspace.var("m_pt").setVal(MuVector.Pt()) ScaleFactorWorkspace.var("m_eta").setVal(MuVector.Eta()) ScaleFactorWorkspace.var("gt_pt").setVal(MuVector.Pt()) ScaleFactorWorkspace.var("gt_eta").setVal(MuVector.Eta()) ScaleFactorWorkspace.var("gt1_pt").setVal(MuVector.Pt()) ScaleFactorWorkspace.var("gt1_eta").setVal(MuVector.Eta()) ScaleFactorWorkspace.var("gt2_pt").setVal(TauVector.Pt()) ScaleFactorWorkspace.var("gt2_eta").setVal(TauVector.Eta()) ScaleFactorWorkspace.var("m_iso").setVal( ReweightFile.mt_Selected.iso_1) ScaleFactorWorkspace.var("t_pt").setVal(TauVector.Pt()) Weight = Weight * ScaleFactorWorkspace.function( "m_sel_trg_ratio").getVal() Weight = Weight * ScaleFactorWorkspace.function( "m_sel_idEmb_ratio").getVal() ScaleFactorWorkspace.var("gt_pt").setVal(TauVector.Pt()) ScaleFactorWorkspace.var("gt_eta").setVal(TauVector.Eta()) Weight = Weight * ScaleFactorWorkspace.function( "m_sel_idEmb_ratio").getVal() Weight = Weight * ScaleFactorWorkspace.function( "m_iso_binned_embed_kit_ratio").getVal() Weight = Weight * ScaleFactorWorkspace.function( "m_id_embed_kit_ratio").getVal() if (Trigger24 or Trigger27): Weight = Weight * ScaleFactorWorkspace.function( "m_trg24_27_embed_kit_ratio").getVal() elif (Trigger2027): X_Trg_Events += 1.0 Embedded_XTrg_MuLegWeight += ScaleFactorWorkspace.function( "m_trg_binned_20_embed_ratio").getVal() Weight = Weight * ScaleFactorWorkspace.function( "m_trg_binned_20_embed_ratio").getVal( ) #This weight causes huge problems #Weight = Weight*ScaleFactorWorkspace.function("mt_emb_LooseChargedIsoPFTau27_kit_ratio").getVal() Embedded_XTrg_TauLegWeight += ScaleFactorWorkspace.function( "mt_emb_LooseChargedIsoPFTau27_tight_kit_ratio" ).getVal() Weight = Weight * ScaleFactorWorkspace.function( "mt_emb_LooseChargedIsoPFTau27_tight_kit_ratio" ).getVal() else: print( "Something weird went through our trigger definitions." ) #top pt reweighting if not args.DisableTopReweighting: TopFactor = 1.0 if (FileName == "TTToHadronic.root" or FileName == "TTToSemiLeptonic.root" or FileName == "TTTo2L2Nu.root"): pttop1 = ReweightFile.mt_Selected.pt_top1 if pttop1 > 400: pttop1 = 400 pttop2 = ReweightFile.mt_Selected.pt_top2 if pttop2 > 400: pttop2 = 400 topfactor = math.sqrt( math.exp(0.0615 - 0.0005 * pttop1) * math.exp(0.0615 - 0.0005 * pttop2)) Weight_TOP_UP = Weight * (2.0 * (topfactor - 1.0) + 1.0) Weight_TOP_DOWN = Weight Weight = Weight * TopFactor if not args.DisableZPTWeighting: Weight_ZPT_DOWN = Weight * ReweightFile.mt_Selected.ZPTWeighting_DOWN Weight_ZPT_UP = Weight * ReweightFile.mt_Selected.ZPTWeighting_UP Weight = Weight * ReweightFile.mt_Selected.ZPTWeighting #ALWAYS if FileName == "Data.root": Weight = 1.0 FinalWeighting[0] = Weight if not args.DisableZPTWeighting: FinalWeighting_ZPT_DOWN[0] = Weight_ZPT_DOWN FinalWeighting_ZPT_UP[0] = Weight_ZPT_UP if not args.DisableTopReweighting and ( FileName == "TTToHadronic.root" or FileName == "TTToSemiLeptonic.root" or FileName == "TTTo2L2Nu.root"): FinalWeighting_TOP_UP[0] = Weight_TOP_UP FinalWeighting_TOP_DOWN[0] = Weight_TOP_DOWN TheBranch.Fill() if not args.DisableZPTWeighting: TheBranch_ZPT_DOWN.Fill() TheBranch_ZPT_UP.Fill() if not args.DisableTopReweighting and ( FileName == "TTToHadronic.root" or FileName == "TTToSemiLeptonic.root" or FileName == "TTTo2L2Nu.root"): TheBranch_TOP_UP.Fill() TheBranch_TOP_DOWN.Fill() if FileName == "Embedded.root": Embedded_XTrg_MuLegWeight = Embedded_XTrg_MuLegWeight / X_Trg_Events Embedded_XTrg_TauLegWeight = Embedded_XTrg_TauLegWeight / X_Trg_Events print("Embedded X trg mu leg weight (avg): " + str(Embedded_XTrg_MuLegWeight)) print("Embedded X trg tau leg weight (avg): " + str(Embedded_XTrg_TauLegWeight)) ReweightFile.cd() ReweightFile.mt_Selected.Write('', ROOT.TObject.kOverwrite) ReweightFile.Write() ReweightFile.Close()
import ROOT import math ROOT.PyConfig.IgnoreCommandLineOptions = True from PhysicsTools.NanoAODTools.postprocessing.framework.datamodel import Collection from PhysicsTools.NanoAODTools.postprocessing.framework.eventloop import Module from TauPOG.TauIDSFs.TauIDSFTool import TauIDSFTool tauSFTool_jet = TauIDSFTool('2018ReReco', 'DeepTau2017v2p1VSjet', 'VVTight') tauSFTool_ele = TauIDSFTool('2018ReReco', 'DeepTau2017v2p1VSe', 'VVTight') tauSFTool_muo = TauIDSFTool('2018ReReco', 'DeepTau2017v2p1VSmu', 'Tight') from TauPOG.TauIDSFs.TauIDSFTool import TauESTool testool_jet = TauESTool('2018ReReco', 'DeepTau2017v2p1VSjet') from TauPOG.TauIDSFs.TauIDSFTool import TauFESTool testool_ele = TauFESTool('2018ReReco', 'DeepTau2017v2p1VSe') from MuonPOG.MuonSFs.MuonSFTool import MuonSFTool muonSFTool = MuonSFTool() from PhysicsTools.NanoAODTools.postprocessing.tools import deltaR class ZMuTauProducer(Module): def __init__(self, isMC_): self.isMC__ = isMC_ pass def beginJob(self): pass def endJob(self):
def AddFinalWeights(FileToRun, args): print("") print("Creating final weights branch for: " + FileToRun) print("") CheckFile = ROOT.TFile(FileToRun) #make the name easier to understand FileName = FileToRun[FileToRun.rfind("/") + 1:] #Need cross section weighting. Check for it try: CheckFile.mt_Selected.CrossSectionWeighting except: print("Failed to find cross section weightings. Adding them...") AddCrossSectionWeightings.AddCrossSectionWeightings(FileToRun, args) try: CheckFile.mt_Selected.ZPTWeighting except: print("Failed to find ZPT Weights. Adding them...") AddZPTReweighting.ApplyZPTReweighting(FileToRun, args) #Pileup weight everything that isn't data if FileName != "Data.root" and FileName != "Embedded.root": try: CheckFile.mt_Selected.PileupWeight except: print("Failed to find pileup weights. Adding them...") AddPileupWeightings.AddPileupWeightings(FileToRun, args) try: CheckFile.mt_Selected.MuAndTriggerSF except: print("Failed to find muon scale factors. Adding them...") AddKITMuAndTriggerSFs.AddKITMuAndTriggerSFs(FileToRun, args) #try: # CheckFile.mt_Selected.TriggerSF #except: # print("Failed to find MC trigger scale factors. Adding them...") # AddMCTriggerScaleFactors.AddMCTriggerScaleFactors(FileToRun,args) #we actually need to reload the file and the tree now, because it may have changed CheckFile.Close() ReweightFile = ROOT.TFile(FileToRun, "UPDATE") #we create different weights for different shapes. FinalWeighting = array('f', [0]) FinalWeighting_ZPT_DOWN = array('f', [0]) FinalWeighting_ZPT_UP = array('f', [0]) FinalWeighting_TOP_UP = array('f', [0]) FinalWeighting_TOP_DOWN = array('f', [0]) TheBranch = ReweightFile.mt_Selected.Branch('FinalWeighting', FinalWeighting, 'FinalWeighitng/F') TheBranch_ZPT_DOWN = ReweightFile.mt_Selected.Branch( 'FinalWeighting_ZPT_DOWN', FinalWeighting_ZPT_DOWN, 'FinalWeighitng_ZPT_DOWN/F') TheBranch_ZPT_UP = ReweightFile.mt_Selected.Branch( 'FinalWeighting_ZPT_UP', FinalWeighting_ZPT_UP, 'FinalWeighting_ZPT_UP/F') TheBranch_TOP_UP = ReweightFile.mt_Selected.Branch( 'FinalWeighting_TOP_UP', FinalWeighting_TOP_UP, 'FinalWeighting_TOP_UP/F') TheBranch_TOP_DOWN = ReweightFile.mt_Selected.Branch( 'FinalWeighting_TOP_DOWN', FinalWeighting_TOP_DOWN, 'FinalWeighting_TOP_DOWN/F') FirstScaleFactorFile = ROOT.TFile( "/data/aloeliger/CMSSW_9_4_0/src/SMHTTAnalysis/NtuplePolishing/Weightings/CorrectionsWorkspace/htt_scalefactors_v17_6.root" ) FirstWorkSpace = FirstScaleFactorFile.w SecondScaleFactorFile = ROOT.TFile( "/data/aloeliger/CMSSW_9_4_0/src/SMHTTAnalysis/NtuplePolishing/Weightings/htt_scalefactors_2017_v2.root" ) SecondWorkSpace = SecondScaleFactorFile.w print("Adding the final weighting...") tauSFTool = TauIDSFTool("2017ReReco", "DeepTau2017v2p1VSjet", 'Medium') for i in tqdm(range(ReweightFile.mt_Selected.GetEntries())): ReweightFile.mt_Selected.GetEntry(i) MuVector = ROOT.TLorentzVector() TauVector = ROOT.TLorentzVector() MuVector.SetPtEtaPhiM(ReweightFile.mt_Selected.pt_1, ReweightFile.mt_Selected.eta_1, ReweightFile.mt_Selected.phi_1, ReweightFile.mt_Selected.m_1) TauVector.SetPtEtaPhiM(ReweightFile.mt_Selected.pt_2, ReweightFile.mt_Selected.eta_2, ReweightFile.mt_Selected.phi_2, ReweightFile.mt_Selected.m_2) Weight = ReweightFile.mt_Selected.CrossSectionWeighting #cross section #if not a data file, pileup reweight it if (not args.DisablePileupWeighting and FileName != "Data.root" and FileName != "Embedded.root"): Weight = Weight * ReweightFile.mt_Selected.PileupWeight #possible overlap on trigger SFs? if (not args.DisableMuAndTriggerSFs and FileName != "Data.root" and FileName != "Embedded.root"): Weight = Weight * ReweightFile.mt_Selected.MuAndTriggerSF #Tau ID weighting if FileName != "Embedded.root" and FileName != "Data.root": Weight = Weight * tauSFTool.getSFvsPT(TauVector.Pt()) elif FileName == "Embedded.root": Weight = Weight * 0.97 #mu to tau fake SFs if not args.DisableEtaWeighting: if (ReweightFile.mt_Selected.gen_match_2 == 2 or ReweightFile.mt_Selected.gen_match_2 == 4): if (abs(TauVector.Eta()) < 0.4): Weight = Weight * 1.17 elif (abs(TauVector.Eta()) < 0.8): Weight = Weight * 1.29 elif (abs(TauVector.Eta()) < 1.2): Weight = Weight * 1.14 elif (abs(TauVector.Eta()) < 1.7): Weight = Weight * 0.93 elif (abs(TauVector.Eta()) < 2.3): Weight = Weight * 1.61 elif (ReweightFile.mt_Selected.gen_match_2 == 1 or ReweightFile.mt_Selected.gen_match_2 == 3): if (abs(TauVector.Eta()) < 1.460): Weight = Weight * 1.09 elif (abs(TauVector.Eta()) >= 1.559): Weight = Weight * 1.19 Trigger24 = (ReweightFile.mt_Selected.passMu24 and ReweightFile.mt_Selected.matchMu24_1 and ReweightFile.mt_Selected.filterMu24_1 and ReweightFile.mt_Selected.pt_1 > 25.0) Trigger27 = (ReweightFile.mt_Selected.passMu27 and ReweightFile.mt_Selected.matchMu27_1 and ReweightFile.mt_Selected.filterMu27_1 and ReweightFile.mt_Selected.pt_1 > 25.0) Trigger2027 = (ReweightFile.mt_Selected.passMu20Tau27 and ReweightFile.mt_Selected.matchMu20Tau27_1 and ReweightFile.mt_Selected.filterMu20Tau27_1 and ReweightFile.mt_Selected.filterMu20Tau27_2 and ReweightFile.mt_Selected.pt_1 > 21 and ReweightFile.mt_Selected.pt_2 > 31 and ReweightFile.mt_Selected.pt_1 < 25 and abs(ReweightFile.mt_Selected.eta_1) < 2.1 and abs(ReweightFile.mt_Selected.eta_2) < 2.1) #no tau trigger matching in embedded if (FileName == "Embedded.root"): Trigger2027 = ( #ReweightFile.mt_Selected.passMu20Tau27 #and ReweightFile.mt_Selected.matchMu20Tau27_1 #and ReweightFile.mt_Selected.filterMu20Tau27_1 #and ReweightFile.mt_Selected.pt_1 > 21 and ReweightFile.mt_Selected.pt_2 > 31 ReweightFile.mt_Selected.pt_1 > 21 and ReweightFile.mt_Selected.pt_2 > 31 and ReweightFile.mt_Selected.pt_1 < 25 and abs(ReweightFile.mt_Selected.eta_1) < 2.1 and abs(ReweightFile.mt_Selected.eta_2 < 2.1)) #Embedded trigger whatever if not args.DisableEmbeddingReconstructionWeighting: if (FileName == "Embedded.root"): if ReweightFile.mt_Selected.l2_decayMode == 0: Weight = Weight * 0.975 elif ReweightFile.mt_Selected.l2_decayMode == 1: Weight = Weight * 0.975 * 1.051 elif ReweightFile.mt_Selected.l2_decayMode == 10: Weight = Weight * 0.975 * 0.975 * 0.975 FirstWorkSpace.var("m_pt").setVal(MuVector.Pt()) FirstWorkSpace.var("m_eta").setVal(MuVector.Eta()) FirstWorkSpace.var("gt_pt").setVal(MuVector.Pt()) FirstWorkSpace.var("gt_eta").setVal(MuVector.Eta()) FirstWorkSpace.var("gt1_pt").setVal(MuVector.Pt()) FirstWorkSpace.var("gt1_eta").setVal(MuVector.Eta()) FirstWorkSpace.var("gt2_pt").setVal(TauVector.Pt()) FirstWorkSpace.var("gt2_eta").setVal(TauVector.Eta()) FirstWorkSpace.var("m_iso").setVal( ReweightFile.mt_Selected.iso_1) FirstWorkSpace.var("t_pt").setVal(TauVector.Pt()) Weight = Weight * FirstWorkSpace.function( "m_sel_trg_ratio").getVal() Weight = Weight * FirstWorkSpace.function( "m_sel_idEmb_ratio").getVal() FirstWorkSpace.var("gt_pt").setVal(TauVector.Pt()) FirstWorkSpace.var("gt_eta").setVal(TauVector.Eta()) Weight = Weight * FirstWorkSpace.function( "m_sel_idEmb_ratio").getVal() Weight = Weight * FirstWorkSpace.function( "m_iso_binned_embed_kit_ratio").getVal() Weight = Weight * FirstWorkSpace.function( "m_id_embed_kit_ratio").getVal() if (Trigger24 or Trigger27): Weight = Weight * FirstWorkSpace.function( "m_trg24_27_embed_kit_ratio").getVal() else: Weight = Weight * FirstWorkSpace.function( "m_trg_MuTau_Mu20Leg_kit_ratio_embed").getVal() Weight = Weight * FirstWorkSpace.function( "mt_emb_LooseChargedIsoPFTau27_kit_ratio").getVal() #Top pT reweighting if not args.DisableTopReweighting: TopFactor = 1.0 if (FileName == "TTToHadronic.root" or FileName == "TTToSemiLeptonic.root" or FileName == "TTTo2L2Nu.root"): pttop1 = ReweightFile.mt_Selected.pt_top1 if pttop1 > 400: pttop1 = 400 pttop2 = ReweightFile.mt_Selected.pt_top2 if pttop2 > 400: pttop2 = 400 topfactor = math.sqrt( math.exp(0.0615 - 0.0005 * pttop1) * math.exp(0.0615 - 0.0005 * pttop2)) Weight_TOP_UP = Weight * (2.0 * (topfactor - 1.0) + 1.0) Weight_TOP_DOWN = Weight Weight = Weight * TopFactor #ZPT Weighting if not args.DisableZPTWeighting: Weight_ZPT_DOWN = Weight * ReweightFile.mt_Selected.ZPTWeighting_DOWN Weight_ZPT_UP = Weight * ReweightFile.mt_Selected.ZPTWeighting_UP Weight = Weight * ReweightFile.mt_Selected.ZPTWeighting #MC Trigger Scale Factors #if (not args.DisableMCTriggerSFs and not(FileName == "Data.root" or FileName == "Embedded.root")): # Weight = Weight * ReweightFile.mt_Selected.TriggerSF #ALWAYS if FileName == "Data.root": Weight = 1.0 FinalWeighting[0] = Weight if not args.DisableZPTWeighting: FinalWeighting_ZPT_DOWN[0] = Weight_ZPT_DOWN FinalWeighting_ZPT_UP[0] = Weight_ZPT_UP if not args.DisableTopReweighting and ( FileName == "TTToHadronic.root" or FileName == "TTToSemiLeptonic.root" or FileName == "TTTo2L2Nu.root"): FinalWeighting_TOP_UP[0] = Weight_TOP_UP FinalWeighting_TOP_DOWN[0] = Weight_TOP_DOWN TheBranch.Fill() if not args.DisableZPTWeighting: TheBranch_ZPT_DOWN.Fill() TheBranch_ZPT_UP.Fill() if not args.DisableTopReweighting and ( FileName == "TTToHadronic.root" or FileName == "TTToSemiLeptonic.root" or FileName == "TTTo2L2Nu.root"): TheBranch_TOP_UP.Fill() TheBranch_TOP_DOWN.Fill() ReweightFile.cd() ReweightFile.mt_Selected.Write('', ROOT.TObject.kOverwrite) ReweightFile.Write() ReweightFile.Close()
from Configurations.Weights.WeightDefinition import Weight as Weight from TauPOG.TauIDSFs.TauIDSFTool import TauIDSFTool def CalculateTauFakeRateWeight(self, theTree): tauVector = ROOT.TLorentzVector() tauVector.SetPtEtaPhiM(theTree.pt_1, theTree.eta_1, theTree.phi_1, theTree.m_1) self.value[0] = self.eleSFTool.getSFvsEta( tauVector.Eta(), theTree.gen_match_2) * self.muSFTool.getSFvsEta( tauVector.Eta(), theTree.gen_match_2) tauFakeRateWeight_2016 = Weight() tauFakeRateWeight_2016.name = 'TauFakeRateWeight' tauFakeRateWeight_2016.eleSFTool = TauIDSFTool("2016Legacy", 'antiEleMVA6', 'VLoose') tauFakeRateWeight_2016.muSFTool = TauIDSFTool("2016Legacy", 'antiMu3', 'Tight') tauFakeRateWeight_2016.CalculateWeight = CalculateTauFakeRateWeight tauFakeRateWeight_2017 = Weight() tauFakeRateWeight_2017.name = 'TauFakeRateWeight' tauFakeRateWeight_2017.eleSFTool = TauIDSFTool("2017ReReco", 'antiEleMVA6', 'VLoose') tauFakeRateWeight_2017.muSFTool = TauIDSFTool("2017ReReco", 'antiMu3', 'Tight') tauFakeRateWeight_2017.CalculateWeight = CalculateTauFakeRateWeight tauFakeRateWeight_2018 = Weight() tauFakeRateWeight_2018.name = 'TauFakeRateWeight' tauFakeRateWeight_2018.eleSFTool = TauIDSFTool("2018ReReco", 'antiEleMVA6', 'VLoose') tauFakeRateWeight_2018.muSFTool = TauIDSFTool("2018ReReco", 'antiMu3', 'Tight')