def getReweightingHistos(mapSample='dy53X', reweightToSample='flat'): reweightHistos = {} for map in allMaps: # for map in [h_HF_Plus]: t = map['type'] if not reweightHistos.has_key(t): reweightHistos[t] = {} for ptBin in ptBins: if not reweightHistos[t].has_key(tuple(ptBin)): reweightHistos[t][tuple(ptBin)] = {} name = map['name'] + '_pt_' + str(ptBin[0]) if ptBin[1] > 0: name += "_" + str(ptBin[1]) ifile = '/afs/hephy.at/user/s/schoefbeck/www/pngMetPhi/' + mapSample + '_pt_' + name + '.root' f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) ptb = canv.GetPrimitive('pt_' + map['name']).Clone(mapSample + '_pt_' + name) if reweightToSample.lower() != 'flat': ifile = '/afs/hephy.at/user/s/schoefbeck/www/pngMetPhi/' + reweightToSample + '_pt_' + name + '.root' f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) ptbRWT = canv.GetPrimitive('pt_' + map['name']).Clone( reweightToSample + '_pt_' + name) a = ptb.GetXaxis() etaBinning = [a.GetNbins(), a.GetXmin(), a.GetXmax()] for i in range(1, 1 + etaBinning[0]): h = ptb.ProjectionY(name + '_etaBin_' + str(i), i, i) integr = h.Integral() if integr > 0: h.Scale(h.GetNbinsX() / integr) # print i,name+'_etaBin_'+str(i),integr, h.GetNbinsX()/integr, h.GetBinContent(6) if reweightToSample.lower() != 'flat': hRWT = ptbRWT.ProjectionY(name + '_RWT_etaBin_' + str(i), i, i) integr = hRWT.Integral() if integr > 0: hRWT.Scale(hRWT.GetNbinsX() / integr) for b in range(0, 1 + h.GetNbinsX()): if h.GetBinContent(b) > 0: if reweightToSample.lower() != 'flat': # print name+'_etaBin_'+str(i), hRWT.GetBinContent(b), h.GetBinContent(b) h.SetBinContent( b, hRWT.GetBinContent(b) / h.GetBinContent(b)) else: # print name+'_etaBin_'+str(i), hRWT.GetBinContent(b), h.GetBinContent(b) h.SetBinContent(b, 1. / h.GetBinContent(b)) # print 'Now',i,name+'_etaBin_'+str(i), h.GetBinContent(6) reweightHistos[t][tuple(ptBin)][(a.GetBinLowEdge(i), a.GetBinUpEdge(i))] = h return reweightHistos
def getReweightingHistos(mapSample="dy53X", reweightToSample="flat"): reweightHistos = {} for map in allMaps: # for map in [h_HF_Plus]: t = map["type"] if not reweightHistos.has_key(t): reweightHistos[t] = {} for ptBin in ptBins: if not reweightHistos[t].has_key(tuple(ptBin)): reweightHistos[t][tuple(ptBin)] = {} name = map["name"] + "_pt_" + str(ptBin[0]) if ptBin[1] > 0: name += "_" + str(ptBin[1]) ifile = "/afs/hephy.at/user/s/schoefbeck/www/pngMetPhi/" + mapSample + "_pt_" + name + ".root" f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) ptb = canv.GetPrimitive("pt_" + map["name"]).Clone(mapSample + "_pt_" + name) if reweightToSample.lower() != "flat": ifile = "/afs/hephy.at/user/s/schoefbeck/www/pngMetPhi/" + reweightToSample + "_pt_" + name + ".root" f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) ptbRWT = canv.GetPrimitive("pt_" + map["name"]).Clone(reweightToSample + "_pt_" + name) a = ptb.GetXaxis() etaBinning = [a.GetNbins(), a.GetXmin(), a.GetXmax()] for i in range(1, 1 + etaBinning[0]): h = ptb.ProjectionY(name + "_etaBin_" + str(i), i, i) integr = h.Integral() if integr > 0: h.Scale(h.GetNbinsX() / integr) # print i,name+'_etaBin_'+str(i),integr, h.GetNbinsX()/integr, h.GetBinContent(6) if reweightToSample.lower() != "flat": hRWT = ptbRWT.ProjectionY(name + "_RWT_etaBin_" + str(i), i, i) integr = hRWT.Integral() if integr > 0: hRWT.Scale(hRWT.GetNbinsX() / integr) for b in range(0, 1 + h.GetNbinsX()): if h.GetBinContent(b) > 0: if reweightToSample.lower() != "flat": # print name+'_etaBin_'+str(i), hRWT.GetBinContent(b), h.GetBinContent(b) h.SetBinContent(b, hRWT.GetBinContent(b) / h.GetBinContent(b)) else: # print name+'_etaBin_'+str(i), hRWT.GetBinContent(b), h.GetBinContent(b) h.SetBinContent(b, 1.0 / h.GetBinContent(b)) # print 'Now',i,name+'_etaBin_'+str(i), h.GetBinContent(6) reweightHistos[t][tuple(ptBin)][(a.GetBinLowEdge(i), a.GetBinUpEdge(i))] = h return reweightHistos
egamma_HF_Minus['zoomRange'] = [-5,5] egamma_HF_Plus['zoomRange'] = [-5,5] egamma_HF_InnerMostRingsMinus['zoomRange'] = [-5,5] egamma_HF_InnerMostRingsPlus['zoomRange'] = [-5,5] h_HF['zoomRange'] = [-5,5] egamma_HF['zoomRange'] = [-5,5] makeN2Fit = [m['name'] for m in maps] #[ h, h0EndcapPlus, h0EndcapMinus, h_HF, h_HF_Minus, h_HF_Plus, h_HF_InnerMostRingsMinus, h_HF_InnerMostRingsPlus]] #makeN2Fit += [m['name'] for m in [ egamma_HF, egamma_HF_Minus, egamma_HF_Plus, egamma_HF_InnerMostRingsMinus, egamma_HF_InnerMostRingsPlus]] for map in maps: if map['name'] in makeN2Fit: fx = ROOT.TF1('fx', '[0]*x**2+[1]*x',*(map['fitRange'])) else: fx = ROOT.TF1('fx', '[0]*x',*(map['fitRange'])) px = getObjFromFile(options.infile, 'pfMEtMultCorrInfoWriter/pfMEtMultCorrInfoWriter_'+map['name'].replace('h_HF','hHF').replace('egamma_HF','egammaHF')+'_Px') px.Fit(fx, 'R') if map['name'] in makeN2Fit: fy = ROOT.TF1('fy', '[0]*x**2+[1]*x',*(map['fitRange'])) else: fy = ROOT.TF1('fy', '[0]*x',*(map['fitRange'])) py = getObjFromFile(options.infile, 'pfMEtMultCorrInfoWriter/pfMEtMultCorrInfoWriter_'+map['name'].replace('h_HF','hHF').replace('egamma_HF','egammaHF')+'_Py') py.Fit(fy,'R') result = {'fx':fx.Clone(),'fy':fy.Clone()} c1 = ROOT.TCanvas() ROOT.gStyle.SetOptStat(0) ROOT.gStyle.SetOptFit(0)
import ROOT from Workspace.HEPHYPythonTools.helpers import getObjFromFile ifile = '/afs/hephy.at/user/s/schoefbeck/www/pngT5LNu/T5Lnu_v5_refSelNoNJet_copy__met150_ht400_njets2-99_wPlusGenMass.root' f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) h = canv.GetPrimitive('XXX_Data').Clone('hist') print h.Integral() #f = ROOT.TF1('bw', '[0]*x/((x**2-[1]**2)**2+[1]**2*[2]**2)', 50.,400.) #f.SetParameter(0,10**7) #f.SetParameter(1,80.4) #f.SetParameter(2,1.) # #c1 = ROOT.TCanvas() #h.Fit('bw') #h.Draw() #c1.SetLogy() #f.Draw('same')
#map = h_HF_InnerMostRingsPlus map = egamma_HF_Plus #ptb = [3, 10] occ={} hpt={} for ptb in ptBins: eName = str(ptb[0]) if ptb[1]>0: eName+='_'+str(ptb[1]) ifile = '/afs/hephy.at/user/s/schoefbeck/www/pngMetPhi/'+options.sample+'_occ_'+map['name']+'_pt_'+eName+'.root' f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) occ[tuple(ptb)] = canv.GetPrimitive('occ_'+map['name']).Clone('occ_'+eName+'_'+map['name']) ifile = '/afs/hephy.at/user/s/schoefbeck/www/pngMetPhi/'+options.sample+'_pt_'+map['name']+'_pt_'+eName+'.root' f = ROOT.TFile(ifile) k = f.GetListOfKeys()[0].GetName() f.Close() canv = getObjFromFile(ifile, k) hpt[tuple(ptb)] = canv.GetPrimitive('pt_'+map['name']).Clone('pt_'+eName+'_'+map['name']) a = hpt[tuple(ptb)].GetXaxis() etaBinning = [a.GetNbins(), a.GetXmin(), a.GetXmax()] projOcc={} projPt={} for ptb in ptBins: projOcc[tuple(ptb)]={}
ntot = 0. from commons import label, categories, pfTypes occ = {} en = {} for i in range(100): ifile = '/data/schoef/convertedMETTuples_v1/Mu-DYJetsToLL-M50/histo_from' + str( i) + 'To' + str(i + 1) + '.root' c = ROOT.TChain('Events') c.Add(ifile) n = c.GetEntries() ntot += n for t in pfTypes: o = getObjFromFile(ifile, 'occ_' + t) e = getObjFromFile(ifile, 'en_' + t) o.Scale(n) e.Scale(n) if occ.has_key(t): occ[t].Add(o) en[t].Add(e) else: occ[t] = o.Clone() en[t] = o.Clone() del o del e for t in pfTypes: occ[t].Scale(1. / ntot) en[t].Scale(1. / ntot)
from Workspace.HEPHYPythonTools.helpers import getObjFromFile ntot=0. from commons import label, categories, pfTypes occ={} en={} for i in range(100): ifile = '/data/schoef/convertedMETTuples_v1/Mu-DYJetsToLL-M50/histo_from'+str(i)+'To'+str(i+1)+'.root' c = ROOT.TChain('Events') c.Add(ifile) n = c.GetEntries() ntot+=n for t in pfTypes: o = getObjFromFile(ifile, 'occ_'+t ) e = getObjFromFile( ifile, 'en_'+t) o.Scale(n) e.Scale(n) if occ.has_key(t): occ[t].Add(o) en[t].Add(e) else: occ[t] = o.Clone() en[t] = o.Clone() del o del e for t in pfTypes: occ[t].Scale(1./ntot)
egamma_HF_InnerMostRingsPlus['zoomRange'] = [-5, 5] h_HF['zoomRange'] = [-5, 5] egamma_HF['zoomRange'] = [-5, 5] makeN2Fit = [ m['name'] for m in maps ] #[ h, h0EndcapPlus, h0EndcapMinus, h_HF, h_HF_Minus, h_HF_Plus, h_HF_InnerMostRingsMinus, h_HF_InnerMostRingsPlus]] #makeN2Fit += [m['name'] for m in [ egamma_HF, egamma_HF_Minus, egamma_HF_Plus, egamma_HF_InnerMostRingsMinus, egamma_HF_InnerMostRingsPlus]] for map in maps: if map['name'] in makeN2Fit: fx = ROOT.TF1('fx', '[0]*x**2+[1]*x', *(map['fitRange'])) else: fx = ROOT.TF1('fx', '[0]*x', *(map['fitRange'])) px = getObjFromFile( options.infile, 'pfMEtMultCorrInfoWriter/pfMEtMultCorrInfoWriter_' + map['name'].replace('h_HF', 'hHF').replace('egamma_HF', 'egammaHF') + '_Px') px.Fit(fx, 'R') if map['name'] in makeN2Fit: fy = ROOT.TF1('fy', '[0]*x**2+[1]*x', *(map['fitRange'])) else: fy = ROOT.TF1('fy', '[0]*x', *(map['fitRange'])) py = getObjFromFile( options.infile, 'pfMEtMultCorrInfoWriter/pfMEtMultCorrInfoWriter_' + map['name'].replace('h_HF', 'hHF').replace('egamma_HF', 'egammaHF') + '_Py') py.Fit(fy, 'R') result = {'fx': fx.Clone(), 'fy': fy.Clone()}