def getPlotters(samples, isData=False, corr="1"): sampleTypes = samples.split(',') plotters = [] for filename in os.listdir('samples'): for sampleType in sampleTypes: if filename.find(sampleType) != -1: fnameParts = filename.split('.') fname = fnameParts[0] ext = fnameParts[1] if ext.find("root") == -1: continue print 'Adding file', fname plotters.append( TreePlotter('samples/' + fname + '.root', 'tree')) if not isData: plotters[-1].setupFromFile('samples/' + fname + '.pck') plotters[-1].addCorrectionFactor('xsec', 'tree') plotters[-1].addCorrectionFactor('genWeight', 'tree') plotters[-1].addCorrectionFactor('puWeight', 'tree') plotters[-1].addCorrectionFactor('lnujj_sf', 'tree') plotters[-1].addCorrectionFactor('truth_genTop_weight', 'tree') plotters[-1].addCorrectionFactor(corr, 'flat') return plotters
def __init__(self, directory, filenames, isData): self.dataPlotters = [] sampleTypes = filenames.split(',') for filename in os.listdir(directory): for sampleType in sampleTypes: if filename.find(sampleType) != -1: fnameParts = filename.split('.') fname = fnameParts[0] ext = fnameParts[1] if ext.find("root") == -1: continue self.dataPlotters.append( TreePlotter(directory + '/' + fname + '.root', 'tree')) if not isData: self.dataPlotters[-1].setupFromFile(directory + '/' + fname + '.pck') self.dataPlotters[-1].addCorrectionFactor( 'xsec', 'tree') self.dataPlotters[-1].addCorrectionFactor( 'genWeight', 'tree') self.dataPlotters[-1].addCorrectionFactor( 'puWeight', 'tree') self.plotter = MergedPlotter(self.dataPlotters)
samples[mass] = fname print 'found', filename, 'mass', str(mass) scaleFactors = options.scaleFactors.split(',') #Now we have the samples: Sort the masses and run the fits N = 0 Fhists = ROOT.TFile("massHISTOS_" + options.output, "RECREATE") for mass in sorted(samples.keys()): print 'fitting', str(mass) plotter = TreePlotter(args[0] + '/' + samples[mass] + '.root', 'tree') plotter.addCorrectionFactor('genWeight', 'tree') plotter.addCorrectionFactor('puWeight', 'tree') if options.scaleFactors != '': for s in scaleFactors: plotter.addCorrectionFactor(s, 'tree') fitter = Fitter(['MVV']) fitter.signalResonanceCBGaus('model', 'MVV', mass) if options.fixPars != "1": fixedPars = options.fixPars.split(',') print fixedPars for par in fixedPars: parVal = par.split(':') if len(parVal) > 1: fitter.w.var(parVal[0]).setVal(float(parVal[1]))
samples[mass] = fname print 'found',filename,'mass',str(mass) #Now we have the samples: Sort the masses and run the fits N=0 for mass in sorted(samples.keys()): if mass<999: continue print 'fitting',str(mass) plotter=TreePlotter(args[0]+'/'+samples[mass]+'.root','tree') plotter.setupFromFile(args[0]+'/'+samples[mass]+'.pck') plotter.addCorrectionFactor('genWeight','tree') plotter.addCorrectionFactor('xsec','tree') plotter.addCorrectionFactor('puWeight','tree') fitter=Fitter(['m','M']) fitter.signal2D('model',options.boson) fitter.w.var("MH").setVal(mass) histo = plotter.drawTH2(options.mjj+":"+options.mvv,options.cutShape,"1",500,0,13000,120,60,140) histoYield = plotter.drawTH2(options.mjj+":"+options.mvv,options.cutYield,"1",130,0,13000,100,25,165) fitter.importBinnedData(histo,['M','m'],'data') fitter.fit('model','data',[ROOT.RooFit.SumW2Error(1)])
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters = [] for sample in [ "WJetsToLNu_HT1200to2500", "WJetsToLNu_HT2500toInf", "WJetsToLNu_HT400to600", "WJetsToLNu_HT600to800", "WJetsToLNu_HT800to1200", 'WJetsToLNu_HT100to200', 'WJetsToLNu_HT200to400' ]: wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree')) wjPlotters[-1].setupFromFile('samples/' + sample + '.pck') wjPlotters[-1].addCorrectionFactor('xsec', 'tree') wjPlotters[-1].addCorrectionFactor('genWeight', 'tree') wjPlotters[-1].addCorrectionFactor('puWeight', 'tree') WJets = MergedPlotter(wjPlotters) tt = TreePlotter('samples/TTJets.root', 'tree') tt.setupFromFile('samples/TTJets.pck') tt.addCorrectionFactor('xsec', 'tree') tt.addCorrectionFactor('genWeight', 'tree') tt.addCorrectionFactor('puWeight', 'tree') #create the Z+jets plotters
ext = fnameParts[1] if ext.find("root") == -1: continue mass = float(fname.split('_')[-1]) samples[mass] = fname print 'found', filename, 'mass', str(mass) #Now we have the samples: Sort the masses and run the fits N = 0 for mass in sorted(samples.keys()): print 'fitting', str(mass) plotter = TreePlotter(args[0] + '/' + samples[mass] + '.root', 'tree') plotter.setupFromFile(args[0] + '/' + samples[mass] + '.pck') plotter.addCorrectionFactor('genWeight', 'tree') plotter.addCorrectionFactor('xsec', 'tree') plotter.addCorrectionFactor('puWeight', 'tree') fitter = Fitter(['m', 'M']) fitter.signal2D('model', options.boson) fitter.w.var("MH").setVal(mass) histo = plotter.drawTH2(options.mjj + ":" + options.mvv, options.cutShape, "1", 500, 0, 13000, 120, 25, 165) histoYield = plotter.drawTH2(options.mjj + ":" + options.mvv, options.cutYield, "1", 130, 0, 13000, 100, 25, 165) fitter.importBinnedData(histo, ['M', 'm'], 'data')
def getPlotters(samples, sampleDir, isData=False, corr="1"): sampleTypes = samples.split(',') plotters = [] pcuts = [] filelist = [] if sampleDir == 'ntuples': filelist = [ g for flist in [[(path + '/' + f) for f in os.listdir(sampleDir + '/' + path)] for path in os.listdir(sampleDir)] for g in flist ] else: filelist = os.listdir(sampleDir) for filename in filelist: for sampleType in sampleTypes: if filename.find(sampleType) != -1: fnameParts = filename.split('.') fname = fnameParts[0] ext = fnameParts[1] if ext.find("root") == -1: continue fpath = sampleDir + '/' + fname print 'Adding file', fpath plotters.append(TreePlotter(fpath + '.root', 'tree')) ## Fix for cuts and weights for which the branches differ between years: if "ntuples2016" in fpath: pcuts.append( '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight' ) elif "ntuples2017" in fpath: pcuts.append( '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight' ) elif "ntuples2018" in fpath: pcuts.append( '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET)') else: sys.exit("Year not found, aborting.") if not isData: plotters[-1].setupFromFile(fpath + '.pck') plotters[-1].addCorrectionFactor('xsec', 'tree') plotters[-1].addCorrectionFactor('genWeight', 'tree') plotters[-1].addCorrectionFactor('puWeight', 'tree') plotters[-1].addCorrectionFactor('truth_genTop_weight', 'branch') ##plotters[-1].addCorrectionFactor('lnujj_sfWV','branch') ##plotters[-1].addCorrectionFactor('lnujj_btagWeight','branch') plotters[-1].addCorrectionFactor(corr, 'flat') #''' ## remove the Madgraph background NLO k-factors if REMOVEBKGDKFAC: if fname.find("WJetsToLNu_HT") != -1: wjetsAntiKFactor = 1. / 1.21 plotters[-1].addCorrectionFactor( wjetsAntiKFactor, 'flat') print ' reweighting ' + fpath + ' ' + str( wjetsAntiKFactor) elif fname.find("DYJetsToLL_M50_HT") != -1: dyAntiKFactor = 1. / 1.23 plotters[-1].addCorrectionFactor( dyAntiKFactor, 'flat') print ' reweighting ' + fpath + ' ' + str( dyAntiKFactor) #''' #''' ## rescale the W+jets yields (the current factors were computed from 30 < mjet < 50 GeV, on top of the NLO k-factors) if RESCALEWJETS: if fname.find("WJetsToLNu_HT") != -1: wjetsFactor = 1. if "ntuples2016" in fpath: wjetsFactor = 1.022 elif "ntuples2017" in fpath: wjetsFactor = 0.926 elif "ntuples2018" in fpath: wjetsFactor = 0.860 plotters[-1].addCorrectionFactor( wjetsFactor, 'flat') print ' reweighting ' + fpath + ' ' + str( wjetsFactor) #''' return MergedPlotter(plotters, pcuts)
ext = fnameParts[1] if ext.find("root") == -1: continue mass = float(fname.split('_')[-1]) samples[mass] = fname print 'found', filename, 'mass', str(mass) #Now we have the samples: Sort the masses and run the fits N = 0 for mass in sorted(samples.keys()): print 'fitting', str(mass) plotter = TreePlotter(args[0] + '/' + samples[mass] + '.root', 'tree') # plotter.setupFromFile(args[0]+'/'+samples[mass]+'.pck') plotter.addCorrectionFactor('genWeight', 'tree') # plotter.addCorrectionFactor('xsec','tree') plotter.addCorrectionFactor('puWeight', 'tree') fitter = Fitter(['x']) fitter.jetResonance('model', 'x') # fitter.w.var("MH").setVal(mass) histo = plotter.drawTH1(options.mvv, options.cut, "1", 40, 40, 160) fitter.importBinnedData(histo, ['x'], 'data') fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(0)]) fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(0), ROOT.RooFit.Minos(1)])
ext = fnameParts[1] if ext.find("root") == -1: continue mass = float(fname.split('_')[-1]) samples[mass] = fname print 'found', filename, 'mass', str(mass) #Now we have the samples: Sort the masses and run the fits N = 0 for mass in sorted(samples.keys()): print 'fitting', str(mass) plotter = TreePlotter(args[0] + '/' + samples[mass] + '.root', 'tree') # plotter.setupFromFile(args[0]+'/'+samples[mass]+'.pck') plotter.addCorrectionFactor('genWeight', 'tree') # plotter.addCorrectionFactor('xsec','tree') plotter.addCorrectionFactor('puWeight', 'tree') fitter = Fitter(['MVV', 'MJJ']) fitter.signal2D('model', ['MVV', 'MJJ']) fitter.w.var("MH").setVal(mass) histo = plotter.drawTH2(options.mjj + ':' + options.mvv, options.cut, "1", 500, 0, 6000, 100, options.minMJJ, options.maxMJJ) fitter.importBinnedData(histo, ['MVV', 'MJJ'], 'data') fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(0)]) fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(0)])
name = fname.split('_')[0] samples[name] = fname print 'found', filename sigmas = [] params = {} NRes = [0, 0] NnonRes = [0, 0] legs = ["l1", "l2"] plotters = [] for name in samples.keys(): plotters.append( TreePlotter(args[0] + '/' + samples[name] + '.root', 'tree')) plotters[-1].setupFromFile(args[0] + '/' + samples[name] + '.pck') plotters[-1].addCorrectionFactor('xsec', 'tree') plotters[-1].addCorrectionFactor('genWeight', 'tree') plotters[-1].addCorrectionFactor('puWeight', 'tree') corrFactor = options.corrFactorW if samples[name].find('Z') != -1: corrFactor = options.corrFactorZ plotters[-1].addCorrectionFactor(corrFactor, 'flat') plotter = MergedPlotter(plotters) print 'Fitting Mjet:' for leg in legs:
mass = float(fname.split('_')[-1]) if mass < options.minMass: continue samples[mass] = fname print 'found', filename, 'mass', str(mass) #Now we have the samples: Sort the masses and run the fits N = 0 for mass in sorted(samples.keys()): print 'fitting', str(mass) plotter = TreePlotter(args[0] + '/' + samples[mass] + '.root', 'tree') plotter.setupFromFile(args[0] + '/' + samples[mass] + '.pck') plotter.addCorrectionFactor('genWeight', 'tree') plotter.addCorrectionFactor('xsec', 'tree') plotter.addCorrectionFactor('puWeight', 'tree') histo = plotter.drawTH1( options.mvv, options.cut + '*(jj_LV_mass>%f&&jj_LV_mass<%f)' % (mass * 0.8, mass * 1.2), "1", 500, options.min, options.max) err = ROOT.Double(0) integral = histo.IntegralAndError(1, histo.GetNbinsX(), err) yieldgraph.SetPoint(N, mass, integral * options.BR) yieldgraph.SetPointError(N, 0.0, err * options.BR) N = N + 1 func = ROOT.TF1("func", options.function, 0, 13000)
from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters=[] for sample in ['WJetsToLNu_HT100to200','WJetsToLNu_HT200to400','WJetsToLNu_HT400to600','WJetsToLNu_HT600toInf']: wjPlotters.append(TreePlotter('samples/'+sample+'.root','tree')) wjPlotters[-1].setupFromFile('samples/'+sample+'.pck') wjPlotters[-1].addCorrectionFactor('xsec','xsec',0.0,'lnN') wjPlotters[-1].addCorrectionFactor('genWeight','genWeight',0.0,'lnN') WJets = MergedPlotter(wjPlotters) WJets.setFillProperties(1001,ROOT.kAzure-9) RSGWWLNuQQ = TreePlotter('samples/RSGravToWWToLNQQ_kMpl01_2500.root','tree') RSGWWLNuQQ.setupFromFile('samples/RSGravToWWToLNQQ_kMpl01_2500.pck') RSGWWLNuQQ.setFillProperties(0,ROOT.kWhite) RSGWWLNuQQ.setLineProperties(1,ROOT.kOrange+10,3) RSGWWLNuQQ.addCorrectionFactor('xsec',0.001,0.0,'lnN') #Stack vvStack = StackPlotter() vvStack.addPlotter(WJets,"W+jets","W+Jets","background") vvStack.addPlotter(RSGWWLNuQQ,"RSG2000","RSGWW #rightarrow l#nu QQ","signal")
samples[mass] = fname print 'found',filename,'mass',str(mass) scaleFactors=options.scaleFactors.split(',') #Now we have the samples: Sort the masses and run the fits N=0 for mass in sorted(samples.keys()): if mass>6000: continue print 'fitting',str(mass) plotter=TreePlotter(args[0]+'/'+samples[mass]+'.root','tree') plotter.addCorrectionFactor('genWeight','tree') plotter.addCorrectionFactor('puWeight','tree') if options.scaleFactors!='': for s in scaleFactors: plotter.addCorrectionFactor(s,'tree') fitter=Fitter(['MVV']) fitter.signalResonanceCBGaus('model','MVV',mass) fitter.w.var("MH").setVal(mass) histo = plotter.drawTH1(options.mvv,options.cut+"*(jj_LV_mass>%f&&jj_LV_mass<%f)"%(0.8*mass,1.2*mass),"1",140,700,8000) fitter.importBinnedData(histo,['MVV'],'data') fitter.fit('model','data',[ROOT.RooFit.SumW2Error(0)])#,ROOT.RooFit.Range(1000,8000)])
if mass < options.minMX or mass > options.maxMX: continue samples[mass] = fname print 'found',filename,'mass',str(mass) leg = options.mvv.split('_')[1] #Now we have the samples: Sort the masses and run the fits N=0 for mass in sorted(samples.keys()): print 'fitting',str(mass) plotter=TreePlotter(args[0]+'/'+samples[mass]+'.root','tree') # plotter.setupFromFile(args[0]+'/'+samples[mass]+'.pck') plotter.addCorrectionFactor('genWeight','tree') # plotter.addCorrectionFactor('xsec','tree') plotter.addCorrectionFactor('puWeight','tree') fitter=Fitter(['x']) if options.doExp==1: fitter.jetResonance('model','x') else: fitter.jetResonanceNOEXP('model','x') if options.fixPars!="1": fixedPars =options.fixPars.split(',')
lumi_13TeV = "12.9 fb^{-1}" lumi_sqrtS = "13 TeV" # used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string) iPeriod = 4 iPos = 11 #create the W+jets plotters wjPlotters = [] for sample in [ "WJetsToLNu_HT1200to2500", "WJetsToLNu_HT2500toInf", "WJetsToLNu_HT400to600", "WJetsToLNu_HT600to800", "WJetsToLNu_HT800to1200", 'WJetsToLNu_HT100to200', 'WJetsToLNu_HT200to400' ]: #for sample in ["WJetsToLNu_HT1200to2500","WJetsToLNu_HT2500toInf","WJetsToLNu_HT400to600","WJetsToLNu_HT600to800","WJetsToLNu_HT800to1200",'WJetsToLNu_HT100to200','WJetsToLNu_HT200to400']: wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree')) wjPlotters[-1].setupFromFile('samples/' + sample + '.pck') wjPlotters[-1].addCorrectionFactor('xsec', 'tree') wjPlotters[-1].addCorrectionFactor('genWeight', 'tree') wjPlotters[-1].addCorrectionFactor('puWeight', 'tree') # wjPlotters[-1].addCorrectionFactor('0.82','flat') WJets = MergedPlotter(wjPlotters) ttO = TreePlotter('samples/TTJets.root', 'tree') ttO.setupFromFile('samples/TTJets.pck') ttO.addCorrectionFactor('xsec', 'tree') ttO.addCorrectionFactor('genWeight', 'tree') ttO.addCorrectionFactor('puWeight', 'tree') ttO.addCorrectionFactor( '(!(lnujj_l2_mergedVTruth==1&&lnujj_l2_nearestBDRTruth>0.8))', 'tree')
def loadSignalNtuples(samples, sampleDir, minMX, maxMX, corr=1.): sampleTypes = samples.split(',') plotters = {} pcuts = {} filelist = [] if sampleDir == 'ntuples': filelist = [ g for flist in [[(path + '/' + f) for f in os.listdir(sampleDir + '/' + path)] for path in os.listdir(sampleDir)] for g in flist ] else: filelist = os.listdir(sampleDir) for filename in filelist: for sampleType in sampleTypes: if filename.find(sampleType) != -1: fnameParts = filename.split('.') fname = fnameParts[0] ext = fnameParts[1] if ext.find("root") == -1: continue fpath = sampleDir + '/' + fname mass = float(fname.split('_')[-1]) if mass < minMX or mass > maxMX: continue if not mass in plotters.keys(): plotters[mass] = [] pcuts[mass] = [] plotters[mass].append(TreePlotter(fpath + '.root', 'tree')) ## Fix for cuts and weights for which the branches differ between years: if "ntuples2016" in fpath: pcuts[mass].append( '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight' ) elif "ntuples2017" in fpath: pcuts[mass].append( '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET||HLT_PHOTON)*L1PrefireWeight' ) elif "ntuples2018" in fpath: pcuts[mass].append( '(HLT_MU||HLT_ELE||HLT_ISOMU||HLT_ISOELE||HLT_MET)') else: sys.exit("Year not found, aborting.") plotters[mass][-1].setupFromFile(fpath + '.pck') plotters[mass][-1].addCorrectionFactor('xsec', 'tree') plotters[mass][-1].addCorrectionFactor('genWeight', 'tree') plotters[mass][-1].addCorrectionFactor('puWeight', 'tree') #plotters[mass][-1].addCorrectionFactor('lnujj_sfWV','branch') #plotters[mass][-1].addCorrectionFactor('lnujj_btagWeight','branch') plotters[mass][-1].addCorrectionFactor(corr, 'flat') plotters[mass][-1].filename = fname print 'found', fpath, 'mass', str(mass) mergedplotters = {} for mass in sorted(plotters.keys()): if len(plotters[mass]) != ( 1, (3, 2)['Wprime_VBF_Wh_Wlephinc_narrow' in samples] )[sampleDir == 'ntuples']: ##FIXME: rechange when 2017 VBFWH is ready continue mergedplotters[mass] = MergedPlotter(plotters[mass], pcuts[mass]) return mergedplotters
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters = [] for sample in [ 'WJetsToLNu_HT100to200', 'WJetsToLNu_HT200to400', 'WJetsToLNu_HT400to600', 'WJetsToLNu_HT600toInf' ]: wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree')) wjPlotters[-1].setupFromFile('samples/' + sample + '.pck') wjPlotters[-1].addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN') WJets = MergedPlotter(wjPlotters) WJets.setFillProperties(1001, ROOT.kAzure - 9) RSGWWLNuQQ = TreePlotter('samples/RSGravToWWToLNQQ_2000.root', 'tree') RSGWWLNuQQ.setupFromFile('samples/RSGravToWWToLNQQ_2000.pck') RSGWWLNuQQ.setFillProperties(0, ROOT.kWhite) RSGWWLNuQQ.setLineProperties(1, ROOT.kOrange + 10, 3) #RSGWWLNuQQ..addCorrectionFactor('xsec',0.001,0.0,'lnN') #Stack vvStack = StackPlotter() vvStack.addPlotter(WJets, "W+jets", "W+Jets", "background") vvStack.addPlotter(RSGWWLNuQQ, "RSG2000", "RSGWW #rightarrow l#nu QQ",
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters=[] for sample in ["WJetsToLNu_HT1200to2500","WJetsToLNu_HT2500toInf","WJetsToLNu_HT400to600","WJetsToLNu_HT600to800","WJetsToLNu_HT800to1200",'WJetsToLNu_HT100to200','WJetsToLNu_HT200to400']: wjPlotters.append(TreePlotter('samples/'+sample+'.root','tree')) wjPlotters[-1].setupFromFile('samples/'+sample+'.pck') wjPlotters[-1].addCorrectionFactor('xsec','tree') wjPlotters[-1].addCorrectionFactor('genWeight','tree') wjPlotters[-1].addCorrectionFactor('puWeight','tree') WJets = MergedPlotter(wjPlotters) tt=TreePlotter('samples/TTJets.root','tree') tt.setupFromFile('samples/TTJets.pck') tt.addCorrectionFactor('xsec','tree') tt.addCorrectionFactor('genWeight','tree') tt.addCorrectionFactor('puWeight','tree') #create the Z+jets plotters
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter ROOT.gROOT.ProcessLine('.x tdrstyle.C') w = TreePlotter('samples/W.root','tree') w.addCorrectionFactor('xsec','xsec',0.0,'lnN') w.addCorrectionFactor('mc','l_mcPt>0',0.0,'lnN') w.setFillProperties(0,ROOT.kWhite) w.setLineProperties(1,ROOT.kOrange+10,3) qcd = TreePlotter('samples/W.root','tree') qcd.addCorrectionFactor('xsec','xsec',0.0,'lnN') qcd.addCorrectionFactor('mc','l_mcPt==0',0.0,'lnN') qcd.setFillProperties(3003,ROOT.kBlue) qcd.setLineProperties(1,ROOT.kBlue,3) #Stack lStack = StackPlotter() lStack.addPlotter(qcd,"QCD","Non prompt","background") lStack.addPlotter(w,"Prompt_leptons","Prompt","signal")
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters=[] WJets = TreePlotter('samples/WJetsToLNu_50ns.root','tree') WJets.setupFromFile('samples/WJetsToLNu_50ns.pck') WJets.addCorrectionFactor('xsec','xsec',0.0,'lnN') WJets.addCorrectionFactor('genWeight','genWeight',0.0,'lnN') WJets.setFillProperties(1001,ROOT.kAzure-9) TTJets = TreePlotter('samples/TTJets_50ns.root','tree') TTJets.setupFromFile('samples/TTJets_50ns.pck') TTJets.addCorrectionFactor('xsec','xsec',0.0,'lnN') TTJets.addCorrectionFactor('genWeight','genWeight',0.0,'lnN') TTJets.setFillProperties(1001,ROOT.kGreen-5) qcdPlotters=[] for sample in [ "QCD_Pt1000to1400_50ns","QCD_Pt120to170_50ns","QCD_Pt1400to1800_50ns","QCD_Pt170to300_50ns","QCD_Pt1800to2400_50ns","QCD_Pt2400to3200_50ns","QCD_Pt300to470_50ns","QCD_Pt3200_50ns","QCD_Pt470to600_50ns","QCD_Pt600to800_50ns","QCD_Pt800to1000_50ns","QCD_Pt80to120_50ns"
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters = [] WJets = TreePlotter('samples/WJetsToLNu_50ns.root', 'tree') WJets.setupFromFile('samples/WJetsToLNu_50ns.pck') WJets.addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN') WJets.addCorrectionFactor('genWeight', 'genWeight', 0.0, 'lnN') WJets.setFillProperties(1001, ROOT.kAzure - 9) TTJets = TreePlotter('samples/TTJets_50ns.root', 'tree') TTJets.setupFromFile('samples/TTJets_50ns.pck') TTJets.addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN') TTJets.addCorrectionFactor('genWeight', 'genWeight', 0.0, 'lnN') TTJets.setFillProperties(1001, ROOT.kGreen - 5) qcdPlotters = [] for sample in [ "QCD_Pt1000to1400_50ns", "QCD_Pt120to170_50ns", "QCD_Pt1400to1800_50ns", "QCD_Pt170to300_50ns", "QCD_Pt1800to2400_50ns", "QCD_Pt2400to3200_50ns", "QCD_Pt300to470_50ns", "QCD_Pt3200_50ns", "QCD_Pt470to600_50ns", "QCD_Pt600to800_50ns", "QCD_Pt800to1000_50ns", "QCD_Pt80to120_50ns" ]: qcdPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree'))
sampleTypes=options.samples.split(',') dataPlotters=[] for filename in os.listdir(args[0]): for sampleType in sampleTypes: if filename.find(sampleType)!=-1: fnameParts=filename.split('.') fname=fnameParts[0] ext=fnameParts[1] if ext.find("root") ==-1: continue dataPlotters.append(TreePlotter(args[0]+'/'+fname+'.root','tree')) dataPlotters[-1].setupFromFile(args[0]+'/'+fname+'.pck') dataPlotters[-1].addCorrectionFactor('xsec','tree') dataPlotters[-1].addCorrectionFactor('genWeight','tree') dataPlotters[-1].addCorrectionFactor('puWeight','tree') sigmas=[] for d in dataPlotters: sigmas.append(d.tree.GetMaximum("xsec")/d.weightinv) sigmaW=max(sigmas) for p in dataPlotters: p.addCorrectionFactor(1.0/sigmaW,'flat') data=MergedPlotter(dataPlotters)
while mass<5000: fitter=Fitter(['MVV']) fitter.signalResonance('model','MVV') fitter.w.factory("MH[0,20000]") for var in ['MEAN','SIGMA' #Now we have the samples: Sort the masses and run the fits N=0 for mass in sorted(samples.keys()): print 'fitting',str(mass) plotter=TreePlotter(args[0]+'/'+samples[mass]+'.root','tree') plotter.setupFromFile(args[0]+'/'+samples[mass]+'.pck') plotter.addCorrectionFactor('genWeight','tree') plotter.addCorrectionFactor('xsec','tree') plotter.addCorrectionFactor('puWeight','tree') fitter.w.var("MH").setVal(mass) histo = plotter.drawTH1(options.mvv,options.cut,"1",500,0,13000) fitter.importBinnedData(histo,['MVV'],'data') fitter.fit('model','data',[ROOT.RooFit.SumW2Error(0)]) events=histo.Integral()*options.BR graphs['yield'].SetPoint(N,mass,events) fitter.projection("model","data","MVV","debugVV_"+str(mass)+".root")
samples = {} sampleTypes = options.samples.split(',') dataPlotters = [] for filename in os.listdir(args[0]): for sampleType in sampleTypes: if filename.find(sampleType) != -1: fnameParts = filename.split('.') fname = fnameParts[0] ext = fnameParts[1] if ext.find("root") == -1: continue dataPlotters.append( TreePlotter(args[0] + '/' + fname + '.root', 'tree')) dataPlotters[-1].setupFromFile(args[0] + '/' + fname + '.pck') dataPlotters[-1].addCorrectionFactor('xsec', 'tree') dataPlotters[-1].addCorrectionFactor('genWeight', 'tree') dataPlotters[-1].addCorrectionFactor('puWeight', 'tree') data = MergedPlotter(dataPlotters) graphs = runFits(data, options) f = ROOT.TFile(options.output + ".root", "RECREATE") f.cd() for i, g in enumerate(graphs): g.Write("p" + str(i)) f.Close()
import ROOT from CMGTools.VVResonances.plotting.TreePlotter import TreePlotter from CMGTools.VVResonances.plotting.MergedPlotter import MergedPlotter from CMGTools.VVResonances.plotting.StackPlotter import StackPlotter #create the W+jets plotters wjPlotters = [] for sample in [ 'WJetsToLNu_HT100to200', 'WJetsToLNu_HT200to400', 'WJetsToLNu_HT400to600', 'WJetsToLNu_HT600toInf' ]: wjPlotters.append(TreePlotter('samples/' + sample + '.root', 'tree')) wjPlotters[-1].setupFromFile('samples/' + sample + '.pck') wjPlotters[-1].addCorrectionFactor('xsec', 'xsec', 0.0, 'lnN') wjPlotters[-1].addCorrectionFactor('genWeight', 'genWeight', 0.0, 'lnN') WJets = MergedPlotter(wjPlotters) WJets.setFillProperties(1001, ROOT.kAzure - 9) RSGWWLNuQQ = TreePlotter('samples/RSGravToWWToLNQQ_kMpl01_2500.root', 'tree') RSGWWLNuQQ.setupFromFile('samples/RSGravToWWToLNQQ_kMpl01_2500.pck') RSGWWLNuQQ.setFillProperties(0, ROOT.kWhite) RSGWWLNuQQ.setLineProperties(1, ROOT.kOrange + 10, 3) RSGWWLNuQQ.addCorrectionFactor('xsec', 0.001, 0.0, 'lnN') #Stack vvStack = StackPlotter() vvStack.addPlotter(WJets, "W+jets", "W+Jets", "background")