#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") for var,graph in graphs.iteritems(): if var=='yield': continue value,error=fitter.fetch(var) graph.SetPoint(N,mass,value) graph.SetPointError(N,0.0,error)
#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)]) fitter.projection("model", "data", "x", "debugJJ_" + str(mass) + ".png") for var, graph in graphs.iteritems(): value, error = fitter.fetch(var) graph.SetPoint(N, mass, value) graph.SetPointError(N, 0.0, error) N = N + 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') histo = plotter.drawTH1(options.mvv,options.cut,"1",500,options.min,options.max) yieldgraph.SetPoint(N,mass,histo.Integral()*options.BR) N=N+1 func = ROOT.TF1("func",options.function,0,13000) yieldgraph.Fit(func) parameterization={'yield':returnString(func)} f=open(options.output+".json","w") json.dump(parameterization,f) f.close()
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) yieldgraph.Fit(func) parameterization = {'yield': returnString(func)} f = open(options.output + ".json", "w") json.dump(parameterization, f) f.close()
#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']) fitter.signalResonance('model', 'MVV') fitter.w.var("MH").setVal(mass) histo = plotter.drawTH1(options.mvv, options.cut, "1", 1000, 0, 8000) fitter.importBinnedData(histo, ['MVV'], 'data') fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(0)]) fitter.fit('model', 'data', [ROOT.RooFit.SumW2Error(0)]) fitter.projection("model", "data", "MVV", "debugVV_" + str(mass) + ".root") for var, graph in graphs.iteritems(): value, error = fitter.fetch(var) graph.SetPoint(N, mass, value) graph.SetPointError(N, 0.0, error) N = N + 1 F = ROOT.TFile(options.output, "RECREATE")
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)]) fitter.fit('model','data',[ROOT.RooFit.SumW2Error(0)])#,ROOT.RooFit.Range(1000,8000)]) # fitter.fit('model','data',[ROOT.RooFit.SumW2Error(0)])#,ROOT.RooFit.Range(1000,8000)]) #fitter.projection("model","data","MVV","debugVV_"+options.output+"_"+str(mass)+".root") fitter.projection("model","data","MVV","debugVV_"+options.output+"_"+str(mass)+".png","M_{jj} (GeV)",mass) fitter.w.Print() for var,graph in graphs.iteritems(): value,error=fitter.fetch(var) graph.SetPoint(N,mass,value) graph.SetPointError(N,0.0,error)
fitter.jetResonance('model','x') else: fitter.jetResonanceNOEXP('model','x') if options.fixPars!="1": fixedPars =options.fixPars.split(',') for par in fixedPars: parVal = par.split(':') if len(parVal) > 1: fitter.w.var(parVal[0]).setVal(float(parVal[1])) fitter.w.var(parVal[0]).setConstant(1) # fitter.w.var("MH").setVal(mass) histo = plotter.drawTH1(options.mvv,options.cut,"1",int((options.maxi-options.mini)/4),options.mini,options.maxi) 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)]) fitter.projection("model","data","x","debugJ"+leg+"_"+options.output+"_"+str(mass)+".png") for var,graph in graphs.iteritems(): value,error=fitter.fetch(var) graph.SetPoint(N,mass,value) graph.SetPointError(N,0.0,error) N=N+1 F=ROOT.TFile(options.output,"RECREATE") F.cd()