def __init__(self, cfg): self.fileMu = ROOT.TFile(getFullPath(cfg.muon)) self.histMuZ1ee = self.fileMu.Get("eff_Z1ee_plus_muon") self.histMuUpZ1ee = self.fileMu.Get("effUp_Z1ee_plus_muon") self.histMuDownZ1ee = self.fileMu.Get("effDwn_Z1ee_plus_muon") self.weightMuZ1ee = WeightCalculator(self.histMuZ1ee) self.weightMuUpZ1ee = WeightCalculator(self.histMuUpZ1ee) self.weightMuDwnZ1ee = WeightCalculator(self.histMuDownZ1ee) self.histMuZ1mm = self.fileMu.Get("eff_Z1mumu_plus_muon") self.histMuUpZ1mm = self.fileMu.Get("effUp_Z1mumu_plus_muon") self.histMuDownZ1mm = self.fileMu.Get("effDwn_Z1mumu_plus_muon") self.weightMuZ1mm = WeightCalculator(self.histMuZ1mm) self.weightMuUpZ1mm = WeightCalculator(self.histMuUpZ1mm) self.weightMuDwnZ1mm = WeightCalculator(self.histMuDownZ1mm) self.fileEle = ROOT.TFile(getFullPath(cfg.electron)) self.histEleZ1ee = self.fileEle.Get("eff_Z1ee_plus_electron") self.histEleUpZ1ee = self.fileEle.Get("effUp_Z1ee_plus_electron") self.histEleDownZ1ee = self.fileEle.Get("effDwn_Z1ee_plus_electron") self.weightEleZ1ee = WeightCalculator(self.histEleZ1ee) self.weightEleUpZ1ee = WeightCalculator(self.histEleUpZ1ee) self.weightEleDwnZ1ee = WeightCalculator(self.histEleDownZ1ee) self.histEleZ1mm = self.fileEle.Get("eff_Z1mumu_plus_electron") self.histEleUpZ1mm = self.fileEle.Get("effUp_Z1mumu_plus_electron") self.histEleDownZ1mm = self.fileEle.Get("effDwn_Z1mumu_plus_electron") self.weightEleZ1mm = WeightCalculator(self.histEleZ1mm) self.weightEleUpZ1mm = WeightCalculator(self.histEleUpZ1mm) self.weightEleDwnZ1mm = WeightCalculator(self.histEleDownZ1mm) self.name = cfg.name
def __init__(self,cfg): self.fileMu = ROOT.TFile(getFullPath(cfg.muon)) self.histMuZ1ee = self.fileMu.Get("eff_Z1ee_plus_muon") self.histMuUpZ1ee = self.fileMu.Get("effUp_Z1ee_plus_muon") self.histMuDownZ1ee = self.fileMu.Get("effDwn_Z1ee_plus_muon") self.weightMuZ1ee = WeightCalculator(self.histMuZ1ee) self.weightMuUpZ1ee = WeightCalculator(self.histMuUpZ1ee) self.weightMuDwnZ1ee = WeightCalculator(self.histMuDownZ1ee) self.histMuZ1mm = self.fileMu.Get("eff_Z1mumu_plus_muon") self.histMuUpZ1mm = self.fileMu.Get("effUp_Z1mumu_plus_muon") self.histMuDownZ1mm = self.fileMu.Get("effDwn_Z1mumu_plus_muon") self.weightMuZ1mm = WeightCalculator(self.histMuZ1mm) self.weightMuUpZ1mm = WeightCalculator(self.histMuUpZ1mm) self.weightMuDwnZ1mm = WeightCalculator(self.histMuDownZ1mm) self.fileEle = ROOT.TFile(getFullPath(cfg.electron)) self.histEleZ1ee = self.fileEle.Get("eff_Z1ee_plus_electron") self.histEleUpZ1ee = self.fileEle.Get("effUp_Z1ee_plus_electron") self.histEleDownZ1ee = self.fileEle.Get("effDwn_Z1ee_plus_electron") self.weightEleZ1ee = WeightCalculator(self.histEleZ1ee) self.weightEleUpZ1ee = WeightCalculator(self.histEleUpZ1ee) self.weightEleDwnZ1ee = WeightCalculator(self.histEleDownZ1ee) self.histEleZ1mm = self.fileEle.Get("eff_Z1mumu_plus_electron") self.histEleUpZ1mm = self.fileEle.Get("effUp_Z1mumu_plus_electron") self.histEleDownZ1mm = self.fileEle.Get("effDwn_Z1mumu_plus_electron") self.weightEleZ1mm = WeightCalculator(self.histEleZ1mm) self.weightEleUpZ1mm = WeightCalculator(self.histEleUpZ1mm) self.weightEleDwnZ1mm = WeightCalculator(self.histEleDownZ1mm) self.name = cfg.name
def __init__(self, cfg): self.fileMu = ROOT.TFile(getFullPath(cfg.muonFile)) self.histMu = self.fileMu.Get(cfg.muonHisto) self.fileEle = ROOT.TFile(getFullPath(cfg.eleFile)) self.histEle = self.fileEle.Get(cfg.eleHisto) self.name = cfg.name self.weightMu = WeightCalculator(self.histMu) self.weightEle = WeightCalculator(self.histEle)
def __init__(self,cfg): self.fileMu = ROOT.TFile(getFullPath(cfg.muonFile)) self.histMu = self.fileMu.Get(cfg.muonHisto) self.fileEle = ROOT.TFile(getFullPath(cfg.eleFile)) self.histEle = self.fileEle.Get(cfg.eleHisto) self.name = cfg.name self.weightMu = WeightCalculator(self.histMu) self.weightEle = WeightCalculator(self.histEle)
def __init__(self,finalstate,prod,period,category = 'inc'): self.channel=finalstate self.period=period self.prod=prod self.category=category self.MH = ROOT.RooRealVar('MH','HiggsMass',125) self.width = ROOT.RooRealVar('width','HiggsWidthScale',1.0) # self.massVar='H_Mass'+'_'+finalstate+'_'+period+'_'+category self.massVar='H_Mass' self.mass = ROOT.RooRealVar(self.massVar,'HiggsMass',100,1000) self.lowMass=160 #systematics self.scale_mu = ROOT.RooRealVar("CMS_scale_m","",1.0,0,2.) self.scale_ele = ROOT.RooRealVar("CMS_scale_e","",1.0,0,2.) self.res_mu = ROOT.RooRealVar("CMS_res_m","",0.0,-1,1.) self.res_ele = ROOT.RooRealVar("CMS_res_e","",0.0,-1,1.) self.lowmass=160 self.corrFactors=[] #initialize theory self.theory = HiggsTheory(getFullPath('data/YR_'+period+'.json')) if finalstate in ['MuMu','EleEle']: self.brStr ='eeee' else: self.brStr ='eemumu'
def __init__(self, comp): f = open(getFullPath('data/lineshapeWeights.json')) data = json.load(f) name = comp.name self.method = lambda x: 1 if comp.isMC: if comp.dataset.find('7TeV') > -1: period = '7TeV' else: period = '8TeV' mass = '' for char in comp.name: if char in ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']: mass += char if len(mass) > 2: if int(mass) > 399 and mass in data[period]: dictionary = data[period][mass] self.g = ROOT.TGraph() i = 0 for key in sorted(dictionary, lambda x, y: int(float(x))): self.g.SetPoint(i, float(key), float(dictionary[key]['final'])) i = i + 1 self.method = self.getWeight
def __init__(self,comp): f=open(getFullPath('data/lineshapeWeights.json')) data=json.load(f) name=comp.name self.method=lambda x: 1 if comp.isMC: if comp.dataset.find('7TeV')>-1: period='7TeV' else: period='8TeV' mass='' for char in comp.name: if char in ['1','2','3','4','5','6','7','8','9','0']: mass+=char if len(mass)>2: if int(mass)>399 and mass in data[period]: dictionary =data[period][mass] self.g=ROOT.TGraph() i=0 for key in sorted(dictionary,lambda x,y:int(float(x))): self.g.SetPoint(i,float(key),float(dictionary[key]['final'])) i=i+1 self.method =self.getWeight
def __init__(self,isData = True,doComponents = True,scaleErrors = True ): self.is44X = cmsswIs44X() self.doComponents = doComponents if scaleErrors: self.rootfile = ROOT.TFile(getFullPath('data/ebe_scalefactors.root')) if self.is44X: if isData: self.muonHisto = self.rootfile.Get('mu_reco42x') self.eleHisto = self.rootfile.Get('el_reco42x') else: self.muonHisto = self.rootfile.Get('mu_mc42x') self.eleHisto = self.rootfile.Get('el_mc42x') else: if isData: self.muonHisto = self.rootfile.Get('mu_reco53x') self.eleHisto = self.rootfile.Get('el_reco53x') else: self.muonHisto = self.rootfile.Get('mu_mc53x') self.eleHisto = self.rootfile.Get('el_mc53x')
def __init__(self): self.data=dict() self.data['7TeV'] = dict() self.data['8TeV']=dict() self.data['lumi']={'7TeV':5050., '8TeV': 19790.} self.data['lumiErr']={'7TeV':0.022, '8TeV': 0.044} self.data['ZZTo4mu']={'8TeV':0.07691,'7TeV':0.06609} self.data['ZZTo4e']={'8TeV':0.07691,'7TeV':0.06609} self.data['ZZTo4tau']={'8TeV':0.07691,'7TeV':0.06609} self.data['ZZTo2e2mu']={'8TeV':0.1767,'7TeV':0.152} self.data['ZZTo2e2tau']={'8TeV':0.1767,'7TeV':0.152} self.data['ZZTo2mu2tau']={'8TeV':0.1767,'7TeV':0.152} self.data['GluGluToZZTo4L']={'8TeV':0.0048,'7TeV':0.00174} self.data['GluGluToZZTo2L2L']={'8TeV':0.01203, '7TeV':0.00348} self.data['higgsXS'] = {'7TeV':HiggsTheory(getFullPath('data/YR_7TeV.json')), '8TeV':HiggsTheory(getFullPath('data/YR_8TeV.json'))} self.data['finalState']={'4mu':'&&abs(H_Z1_leg1_PdgId)==13 && abs(H_Z2_leg1_PdgId)==13','4e':'&&abs(H_Z1_leg1_PdgId)==11 && abs(H_Z2_leg1_PdgId)==11','2e2mu':'&&abs(H_Z1_leg1_PdgId)!=abs(H_Z2_leg1_PdgId)'} self.data['higgsProduction']={'GluGluToH':'GGH','VBF':'VBF','ZH':'ZH','WH':'WH','TTbarH':'TTH'} self.data['filterEff']={'GluGluToH':1,'VBF':1,'ZH':0.028,'WH':0.0105,'TTbarH':0.0296}
def __init__(self, isData=True, doComponents=True, scaleErrors=True): self.is44X = cmsswIs44X() self.doComponents = doComponents if scaleErrors: self.rootfile = ROOT.TFile( getFullPath('data/ebe_scalefactors.root')) if self.is44X: if isData: self.muonHisto = self.rootfile.Get('mu_reco42x') self.eleHisto = self.rootfile.Get('el_reco42x') else: self.muonHisto = self.rootfile.Get('mu_mc42x') self.eleHisto = self.rootfile.Get('el_mc42x') else: if isData: self.muonHisto = self.rootfile.Get('mu_reco53x') self.eleHisto = self.rootfile.Get('el_reco53x') else: self.muonHisto = self.rootfile.Get('mu_mc53x') self.eleHisto = self.rootfile.Get('el_mc53x')
def __init__(self,finalstate,cuts,masses,prod,period): #make pdfs if os.path.exists(finalstate+'_'+period+'.json'): self.fpjson=open(finalstate+'_'+period+'.json') self.data = json.load(self.fpjson) else: self.data=dict() if 'shape' not in self.data: self.data['shape']=dict() self.theory = HiggsTheory(getFullPath('data/YR_'+period+'.json')) self.graph_m0 = ROOT.TGraphErrors() self.graph_sigma = ROOT.TGraphErrors() self.graph_alphaL = ROOT.TGraphErrors() self.graph_alphaR = ROOT.TGraphErrors() self.graph_nL = ROOT.TGraphErrors() self.graph_nR = ROOT.TGraphErrors() self.finalstate=finalstate self.period=period for i,mass in enumerate(masses): self.w = ROOT.RooWorkspace('w') self.pdfFactory = PDFFactory(self.w) # self.w.factory('H_Mass[125,70,800]') plotter = TreePlotter("All_"+period+"/"+prod+str(mass)+".root","FourLeptonTreeProducer/tree",'1') #data MC corrections plotter.addCorrectionFactor('eventWeight','eventWeight',0.0,'lnN') plotter.addCorrectionFactor('vertexWeight','vertexWeight',0.0,'lnN') plotter.addCorrectionFactor('eff','H_eff',0.0,'lnN') #define final state separation here finalStateCut=cuts if finalstate=='MuMu': finalStateCut+='&&abs(H_Z1_leg1_PdgId)==13&&abs(H_Z2_leg1_PdgId)==13' if finalstate=='EleEle': finalStateCut+='&&abs(H_Z1_leg1_PdgId)==11&&abs(H_Z2_leg1_PdgId)==11' if finalstate=='MuEle': finalStateCut+='&&abs(H_Z1_leg1_PdgId)!=abs(H_Z2_leg1_PdgId)' #make weighted dataset theory = self.theory.getInterp(mass) width=float(theory['width']) data,obs = plotter.makeDataSet('H_Mass',finalStateCut,[mass-50-3*width],[mass+50+5*width],"data_obs",500000) getattr(self.w,'import')(data) #make pdf if mass<=160.: self.pdfFactory.makeDCB('pdf'+finalstate+str(mass),'H_Mass',mass,finalstate) self.w.var('CMS_scale_m').setConstant(1) self.w.var('CMS_scale_e').setConstant(1) self.w.var('CMS_res_m').setConstant(1) self.w.var('CMS_res_e').setConstant(1) self.w.var('m0').setVal(mass+(26.5702) + (-0.692027*mass) + (0.00680888*mass*mass) + (-3.24132e-05*mass*mass*mass) + (7.37704e-08*mass*mass*mass*mass) + (-6.37514e-11*mass*mass*mass*mass*mass)) else: if mass<399: self.pdfFactory.makeBW('pdfBW'+finalstate+str(mass),'H_Mass') self.w.var('width').setConstant(1) else: self.pdfFactory.makeBWHighMass('pdfBW'+finalstate+str(mass),'H_Mass') self.w.var('MH').setVal(float(mass)) self.w.var('MH').setConstant(1) self.pdfFactory.makeDCB('pdfRes'+finalstate+str(mass),'H_Mass',0.0,finalstate) self.w.var('CMS_scale_m').setConstant(1) self.w.var('CMS_scale_e').setConstant(1) self.w.var('CMS_res_m').setConstant(1) self.w.var('CMS_res_e').setConstant(1) self.pdfFactory.makeConvolution('pdf'+finalstate+str(mass),'H_Mass','pdfBW'+finalstate+str(mass),'pdfRes'+finalstate+str(mass)) self.w.var('m0').setVal((26.5702) + (-0.692027*mass) + (0.00680888*mass*mass) + (-3.24132e-05*mass*mass*mass) + (7.37704e-08*mass*mass*mass*mass) + (-6.37514e-11*mass*mass*mass*mass*mass)) #set defaults self.w.var('alphaL').setVal((-21.6016) + (0.602213*mass) + (-0.00620193*mass*mass) + (3.03257e-05*mass*mass*mass) + (-7.05553e-08*mass*mass*mass*mass) + (6.28615e-11*mass*mass*mass*mass*mass)) self.w.var('alphaR').setVal((110.088) + (-2.74006*mass) + (0.0263436*mass*mass) + (-0.000120005*mass*mass*mass) + (2.59845e-07*mass*mass*mass*mass) + (-2.1514e-10*mass*mass*mass*mass*mass)) self.w.var('nL').setVal((-261.056) + (5.8594*mass) + (-0.047926*mass*mass) + (0.000186032*mass*mass*mass) + (-3.48259e-07*mass*mass*mass*mass) + (2.53758e-10*mass*mass*mass*mass*mass)) self.w.var('sigma').setVal((-42.9661) + (1.16387*mass) + (-0.0116153*mass*mass) + (5.54285e-05*mass*mass*mass) + (-1.25301e-07*mass*mass*mass*mass) + (1.07428e-10*mass*mass*mass*mass*mass)) result = self.w.pdf('pdf'+finalstate+str(mass)).fitTo(self.w.data('data_obs'),ROOT.RooFit.SumW2Error(1),ROOT.RooFit.Save(1),ROOT.RooFit.Minimizer("Minuit2")) c=ROOT.TCanvas('c') c.cd() frame=self.w.var('H_Mass').frame() self.w.data('data_obs').plotOn(frame) self.w.pdf('pdf'+finalstate+str(mass)).plotOn(frame) frame.Draw() c.SaveAs('validation_pdf'+finalstate+str(mass)+'_'+period+'.png') self.data['shape'][mass]=dict() for param in self.pdfFactory.params: self.data['shape'][mass][param]=dict() self.data['shape'][mass][param]['value']=self.w.var(param).getVal() self.data['shape'][mass][param]['error']=self.w.var(param).getError() getattr(self,'graph_'+param).SetPoint(i,float(mass),self.w.var(param).getVal()) getattr(self,'graph_'+param).SetPointError(i,0.0,self.w.var(param).getError()) self.fit() self.save()
#Load all plotter scripts import sys from CMGTools.HToZZTo4Leptons.macros.plotters.StackPlotter import * from CMGTools.HToZZTo4Leptons.macros.plotters.TreePlotter import * from CMGTools.HToZZTo4Leptons.macros.plotters.MergedPlotter import * from CMGTools.HToZZTo4Leptons.macros.plotters.HZZFakeRatePlotter import * from CMGTools.HToZZTo4Leptons.macros.plotters.HZZFakeRatePlotterBoth import * from CMGTools.HToZZTo4Leptons.macros.plotters.HZZSignalParamPlotter import * from CMGTools.HToZZTo4Leptons.macros.plotters.HZZBkgParamPlotter import * from CMGTools.HToZZTo4Leptons.tools.fullPath import getFullPath ROOT.gROOT.ProcessLine(".x "+getFullPath("python/macros/tdrstyle.C")) class PlotterSetup(object): def __init__(self): self.data=dict() self.data['7TeV'] = dict() self.data['8TeV']=dict() self.data['lumi']={'7TeV':5050., '8TeV': 19790.} self.data['lumiErr']={'7TeV':0.022, '8TeV': 0.044} self.data['ZZTo4mu']={'8TeV':0.07691,'7TeV':0.06609} self.data['ZZTo4e']={'8TeV':0.07691,'7TeV':0.06609} self.data['ZZTo4tau']={'8TeV':0.07691,'7TeV':0.06609} self.data['ZZTo2e2mu']={'8TeV':0.1767,'7TeV':0.152} self.data['ZZTo2e2tau']={'8TeV':0.1767,'7TeV':0.152} self.data['ZZTo2mu2tau']={'8TeV':0.1767,'7TeV':0.152}
triggersMC_ee = [ 'HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v*', 'HLT_TripleEle10_CaloIdL_TrkIdVL_v*' ] triggersMC_mue = [ 'HLT_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v*', 'HLT_TripleEle10_CaloIdL_TrkIdVL_v*', "HLT_Mu17_Mu8_v*", "HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_v*", "HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_v*" ] json = '/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions11//7TeV/Reprocessing/Cert_160404-180252_7TeV_ReRecoNov08_Collisions11_JSON_v2.txt' kreator = ComponentCreator() mcSamples = kreator.makeMCComponentFromList( getFullPath('data/samples_MC_7TeV.txt'), suffix, userName, filePattern, triggersMC_mue) dataSamples = kreator.makeDataComponentFromList( getFullPath('data/samples_DATA_7TeV.txt'), suffix, userName, filePattern, json, triggers_mumu, triggers_ee, triggers_mue) dataDir = os.environ['CMSSW_BASE'] + "/src/CMGTools/HToZZTo4Leptons/data" from CMGTools.HToZZTo4Leptons.setup.FakeRates import * from CMGTools.HToZZTo4Leptons.setup.Efficiencies import * #Define splitting for comp in mcSamples: comp.isMC = True comp.isData = False comp.splitFactor = 10
"HLT_Ele15_Ele8_Ele5_CaloIdL_TrkIdVL_v*", "HLT_Mu17_Mu8_v*", "HLT_Mu17_TkMu8_v*", "HLT_Mu8_Ele17_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v*", "HLT_Mu17_Ele8_CaloIdT_CaloIsoVL_TrkIdVL_TrkIsoVL_v*" ] json='/afs/cern.ch/cms/CAF/CMSCOMM/COMM_DQM/certification/Collisions12/8TeV/Reprocessing/Cert_190456-208686_8TeV_22Jan2013ReReco_Collisions12_JSON.txt' #-----------MC--------------- kreator = ComponentCreator() mcSamples =kreator.makeMCComponentFromList(getFullPath('data/samples_MC_8TeV.txt'),suffix,userName,filePattern,triggersMC_mue) dataSamples =kreator.makeDataComponentFromList(getFullPath('data/samples_DATA_8TeV.txt'),suffix,userName,filePattern,json,triggers_mumu,triggers_ee,triggers_mue) dataDir = os.environ['CMSSW_BASE']+"/src/CMGTools/HToZZTo4Leptons/data" #Define splitting for comp in mcSamples: comp.isMC = True comp.isData = False comp.splitFactor =20 comp.puFileMC=dataDir+"/puProfile_Summer12_53X.root" comp.puFileData=dataDir+"/puProfile_Data12.root" comp.efficiency = eff2012 comp.fakeRates=fakeRates2012