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')
crossSectionWeighting = 2.2306 elif theTree.numGenJets == 4: crossSectionWeighting = 2.0336 if self.year == "2018": if self.sample == "DY": crossSectionWeighting = 3.6299 if theTree.numGenJets == 1: crossSectionWeighting = 0.6304 elif theTree.numGenJets == 2: crossSectionWeighting = 0.5521 elif theTree.numGenJets == 3: crossSectionWeighting = 0.6008 elif theTree.numGenJets == 4: crossSectionWeighting = 0.8315 if self.sample == "W": crossSectionWeighting = 51.8119 if theTree.numGenJets == 1: crossSectionWeighting = 10.8902 elif theTree.numGenJets == 2: crossSectionWeighting = 5.268 elif theTree.numGenJets == 3: crossSectionWeighting = 3.121 elif theTree.numGenJets == 4: crossSectionWeighting = 3.0367 crossSectionWeighting = crossSectionWeighting * theTree.genweight self.value[0] = crossSectionWeighting crossSectionWeight = Weight() crossSectionWeight.name = 'CrossSectionWeighting' crossSectionWeight.CalculateWeight = CalculateCrossSectionWeight
self.MuIDIsoFile.w.var("m_pt").setVal(muVector.Pt()) self.MuIDIsoFile.w.var("m_iso").setVal(theTree.iso_1) self.MuIDIsoFile.w.var("m_eta").setVal(abs(muVector.Eta())) self.value[0] = self.MuIDIsoFile.w.function( "m_idiso_binned_kit_ratio").getVal() def CalculateMuIDIsoUsingDesyFactor(self, theTree): muVector = ROOT.TLorentzVector() muVector.SetPtEtaPhiM(theTree.pt_1, theTree.eta_1, theTree.phi_1, theTree.m_1) self.value[0] = self.scaleFactor.GetScaleFactor(muVector.Pt(), muVector.Eta()) muIDIsoWeight_2016 = Weight() muIDIsoWeight_2016.name = 'MuIDIso' muIDIsoWeight_2016.MuIDIsoFile = ROOT.TFile.Open( localWeightDataPath + 'htt_scalefactors_legacy_2016.root') muIDIsoWeight_2016.scaleFactor = DESYScaleFactor( localWeightDataPath + 'Muon_Run2016_legacy_IdIso.root') muIDIsoWeight_2016.CalculateWeight = CalculateMuIDIsoUsingDesyFactor muIDIsoWeight_2017 = Weight() muIDIsoWeight_2017.name = 'MuIDIso' muIDIsoWeight_2017.MuIDIsoFile = ROOT.TFile.Open( localWeightDataPath + 'htt_scalefactors_legacy_2017.root') muIDIsoWeight_2017.scaleFactor = DESYScaleFactor( localWeightDataPath + 'Muon_IdIso_IsoLt0.15_eff_RerecoFall17.root') muIDIsoWeight_2017.CalculateWeight = CalculateMuIDIsoUsingDesyFactor
import ROOT from Configurations.Weights.WeightDefinition import Weight as Weight def CalculatebTaggingWeight(self, theTree): self.value[0] = theTree.bweight bTaggingWeight = Weight() bTaggingWeight.name = 'bTaggingWeight' bTaggingWeight.CalculateWeight = CalculatebTaggingWeight
import ROOT 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',
import ROOT from Configurations.Weights.WeightDefinition import Weight as Weight from TauAnalysisTools.TauTriggerSFs.getTauTriggerSFs import getTauTriggerSFs from Configurations.Weights import localWeightDataPath import TriggerFunctions2016 import TriggerFunctions2017 import TriggerFunctions2018 triggerWeight_2016 = Weight() triggerWeight_2016.name = 'TriggerSF' triggerWeight_2016.TriggerSFFile = ROOT.TFile.Open( localWeightDataPath + "htt_scalefactors_legacy_2016.root") triggerWeight_2016.DESYTriggerSFFile = ROOT.TFile.Open( localWeightDataPath + "Muon_Run2016_legacy_IsoMu22.root") triggerWeight_2016.tauSFs = getTauTriggerSFs('mutau', 2016, 'tight', 'MVAv2') triggerWeight_2016.CalculateWeight = TriggerFunctions2016.CalculateTriggerWeight2016 triggerWeight_2016.hasUpDownUncertainties = True triggerWeight_2016.uncertaintyVariationList = [ "Trigger22_UP", "Trigger22_DOWN", "Trigger1920_UP", "Trigger1920_DOWN" ] triggerWeight_2016.InitUncertaintyVariations() triggerWeight_2016.uncertaintyVariationFunctions = { "Trigger22_UP": TriggerFunctions2016.CalculateTriggerWeight2016_Trigger22_UP, "Trigger22_DOWN": TriggerFunctions2016.CalculateTriggerWeight2016_Trigger22_DOWN, "Trigger1920_UP": TriggerFunctions2016.CalculateTriggerWeight2016_Trigger1920_UP, "Trigger1920_DOWN": TriggerFunctions2016.CalculateTriggerWeight2016_Trigger1920_DOWN, }
from Configurations.Weights.WeightDefinition import Weight def CalculateTopPtWeight(self,theTree): pttop1 = theTree.pt_top1 if pttop1 > 400: pttop1 = 400 pttop2 = theTree.pt_top2 if pttop2 > 400: pttop2 = 400 topfactor = math.sqrt(math.exp(0.0615-0.0005*pttop1)*math.exp(0.0615-0.0005*pttop2)) self.value[0] = topfactor def CalculateTopPtWeightUp(self,theTree,uncert): self.uncertaintyVariationArrays[uncert][0] = 2.0 * (self.value[0] - 1.0) + 1.0 def CalculateTopPtWeightDown(self,theTree,uncert): self.uncertaintyVariationArrays[uncert][0] = 1.0 topPtWeight = Weight() topPtWeight.name = 'TopPtWeight' topPtWeight.hasUpDownUncertainties = True topPtWeight.CalculateWeight = CalculateTopPtWeight topPtWeight.uncertaintyVariationList = [ "TopPt_UP", "TopPt_DOWN" ] topPtWeight.InitUncertaintyVariations() topPtWeight.uncertaintyVariationFunctions={ "TopPt_UP": CalculateTopPtWeightUp, "TopPt_DOWN": CalculateTopPtWeightDown }
import ROOT from Configurations.Weights.WeightDefinition import Weight as Weight def CalculatePrefiringWeighting(self, theTree): self.value[0] = theTree.prefiring_weight def CalculatePrefiringWeightingUp(self, theTree, uncert): self.uncertaintyVariationArrays[uncert][0] = theTree.prefiring_weight_up def CalculatePrefiringWeightingDown(self, theTree, uncert): self.uncertaintyVariationArrays[uncert][0] = theTree.prefiring_weight_down PrefiringWeighting = Weight() PrefiringWeighting.name = 'PrefiringWeighting' PrefiringWeighting.CalculateWeight = CalculatePrefiringWeighting PrefiringWeighting.hasUpDownUncertainties = True PrefiringWeighting.uncertaintyVariationList = [ "PrefiringWeighting_UP", "PrefiringWeighting_DOWN", ] PrefiringWeighting.InitUncertaintyVariations() PrefiringWeighting.uncertaintyVariationFunctions = { "PrefiringWeighting_UP": CalculatePrefiringWeightingUp, "PrefiringWeighting_DOWN": CalculatePrefiringWeightingDown, }
import ROOT from Configurations.Weights.WeightDefinition import Weight as Weight from Configurations.Weights import localWeightDataPath def CreateZPTWeight(self,theTree): self.ZPTFile.w.var("z_gen_mass").setVal(theTree.genM) self.ZPTFile.w.var("z_gen_pt").setVal(theTree.genpT) self.value[0] = self.ZPTFile.w.function("zptmass_weight_nom").getVal() def CreateZPTUpWeight(self,theTree,uncert): self.uncertaintyVariationArrays[uncert][0] = 1.1*self.value[0] def CreateZPTDownWeight(self,theTree,uncert): self.uncertaintyVariationArrays[uncert][0] = 0.9*self.value[0] ZPTWeight_2018 = Weight() ZPTWeight_2018.name = 'ZPTWeighting' ZPTWeight_2018.hasUpDownUncertainties = True ZPTWeight_2018.ZPTFile = ROOT.TFile.Open(localWeightDataPath+"htt_scalefactors_legacy_2018.root") ZPTWeight_2018.CalculateWeight = CreateZPTWeight ZPTWeight_2018.uncertaintyVariationList = [ "ZPT_UP", "ZPT_DOWN" ] ZPTWeight_2018.InitUncertaintyVariations() ZPTWeight_2018.uncertaintyVariationFunctions={ "ZPT_UP": CreateZPTUpWeight, "ZPT_DOWN": CreateZPTDownWeight } ZPTWeight_2017 = Weight()
import ROOT from Configurations.Weights.WeightDefinition import Weight as Weight from Configurations.Weights import localWeightDataPath def CalculateMuTrackingWeight(self, theTree): self.muTrackingFile.w.var("m_eta").setVal(theTree.eta_1) self.value[0] = self.muTrackingFile.w.function("m_trk_ratio").getVal() muTrackingWeight_2016 = Weight() muTrackingWeight_2016.name = 'MuTrackingWeight' muTrackingWeight_2016.muTrackingFile = ROOT.TFile.Open( localWeightDataPath + "htt_scalefactors_legacy_2016.root") muTrackingWeight_2016.CalculateWeight = CalculateMuTrackingWeight muTrackingWeight_2017 = Weight() muTrackingWeight_2017.name = 'MuTrackingWeight' muTrackingWeight_2017.muTrackingFile = ROOT.TFile.Open( localWeightDataPath + "htt_scalefactors_legacy_2017.root") muTrackingWeight_2017.CalculateWeight = CalculateMuTrackingWeight muTrackingWeight_2018 = Weight() muTrackingWeight_2018.name = 'MuTrackingWeight' muTrackingWeight_2018.muTrackingFile = ROOT.TFile.Open( localWeightDataPath + "htt_scalefactors_legacy_2018.root") muTrackingWeight_2018.CalculateWeight = CalculateMuTrackingWeight
elif self.year == "2016" or self.year == "2018": self.MCHisto = self.Pileup_MC_File.Get("pileup") self.DataHisto = self.Pileup_Data_File.Get("pileup") self.theWeightsHisto = self.DataHisto.Clone() self.theWeightsHisto.Scale(1.0 / self.theWeightsHisto.Integral()) self.MCHisto.Scale(1.0 / self.MCHisto.Integral()) self.theWeightsHisto.Divide(self.MCHisto) def CalculatePileupWeighting(self, theTree): self.value[0] = self.theWeightsHisto.GetBinContent( self.theWeightsHisto.FindBin(theTree.npu)) pileupWeight_2016 = Weight() pileupWeight_2016.name = 'PileupWeighting' pileupWeight_2016.Pileup_MC_File = ROOT.TFile.Open( localWeightDataPath + "MC_Moriond17_PU25ns_V1.root") pileupWeight_2016.Pileup_Data_File = ROOT.TFile.Open( localWeightDataPath + "Data_Pileup_2016_271036-284044_80bins.root") pileupWeight_2016.InitPileupWeightings = InitPileupWeightings pileupWeight_2016.CalculateWeight = CalculatePileupWeighting pileupWeight_2017 = Weight() pileupWeight_2017.name = 'PileupWeighting' pileupWeight_2017.Pileup_MC_File = ROOT.TFile.Open( localWeightDataPath + "pu_distributions_mc_2017.root") pileupWeight_2017.Pileup_Data_File = ROOT.TFile.Open( localWeightDataPath + "pu_distributions_data_2017.root") pileupWeight_2017.InitPileupWeightings = InitPileupWeightings