Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebin histograms when running mkPlot.py #250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ShapeAnalysis/python/PlotFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def makePlot(self, inputFile, outputDirPlots, variables, cuts, samples, plot, nu
for variableName, variable in self._variables.iteritems():
if 'cuts' in variable and cutName not in variable['cuts']:
continue
if 'tree' in variable:
continue

if type(fileIn) is not dict and not fileIn.GetDirectory(cutName+"/"+variableName):
continue
Expand Down Expand Up @@ -258,6 +260,8 @@ def makePlot(self, inputFile, outputDirPlots, variables, cuts, samples, plot, nu
if not histo: continue
print ' --> ', histo
print 'new_histo_' + sampleName + '_' + cutName + '_' + variableName
if self._rebin != 1:
histo.Rebin(self._rebin)
histos[sampleName] = histo.Clone('new_histo_' + sampleName + '_' + cutName + '_' + variableName)

#print " -> sampleName = ", sampleName, " --> ", histos[sampleName].GetTitle(), " --> ", histos[sampleName].GetName(), " --> ", histos[sampleName].GetNbinsX()
Expand Down Expand Up @@ -475,6 +479,8 @@ def makePlot(self, inputFile, outputDirPlots, variables, cuts, samples, plot, nu
histoVar = fileIn.Get(shapeNameVar)

if histoVar != None :
if self._rebin != 1:
histoVar.Rebin(self._rebin)
nuisanceHistos[ivar][nuisanceName] = histoVar
elif not self._SkipMissingNuisance :
print " This is bad, the nuisance ", nuisanceName, " is missing! You need to add it, maybe some jobs crashed?"
Expand Down Expand Up @@ -659,6 +665,8 @@ def makePlot(self, inputFile, outputDirPlots, variables, cuts, samples, plot, nu
if self._postFit == 'b':
tgrDataOverPF = tgrData.Clone("tgrDataOverPF") # use this for ratio with Post-Fit MC
histoPF = fileIn.Get(cutName+"/"+variableName+'/histo_total_postfit_b')
if (self._postFit == 'p' or self._postFit == 's' or self._postFit == 'b') and self._rebin != 1:
histoPF.Rebin(self._rebin)

# at this stage "thsBackground" and then "last" includes ALSO the signal
last = thsBackground.GetStack().Last()
Expand Down Expand Up @@ -724,6 +732,9 @@ def makePlot(self, inputFile, outputDirPlots, variables, cuts, samples, plot, nu
else:
histo_total = fileIn.Get(special_shapeName)

if histo_total and self._rebin != 1:
histo_total.Rebin(self._rebin)

if variable['divideByBinWidth'] == 1 and histo_total != None:
histo_total.Scale(1,"width")
print '--> histo_total = ', histo_total
Expand Down
5 changes: 5 additions & 0 deletions ShapeAnalysis/scripts/mkPlot.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@

parser.add_option('--parallelPlotting', dest='parallelPlotting', help='Plot each cut in parallel' , action='store_true', default=False)

parser.add_option('--rebin', dest='rebin', help='Rebin histograms before plotting', default=1, type=int);

# read default parsing options as well
hwwtools.addOptions(parser)
hwwtools.loadOptDefaults(parser)
Expand Down Expand Up @@ -118,6 +120,7 @@
print " NoPreliminary =", opt.NoPreliminary
print " RemoveAllMC =", opt.RemoveAllMC
print " parallelPlotting =", opt.parallelPlotting
print " rebin =", opt.rebin
print ""

opt.scaleToPlot = float(opt.scaleToPlot)
Expand Down Expand Up @@ -256,6 +259,8 @@ def launch_plot(inputFile, outputDirPlots, variables, cuts, samples, plot, nuisa
factory._preliminary = not opt.NoPreliminary
factory._removeAllMC = opt.RemoveAllMC

factory._rebin = opt.rebin

factory.makePlot(inputFile ,outputDirPlots, variables, cuts, samples, plot, nuisances, legend, groupPlot)


Expand Down