Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:28:18

0001 #!/usr/bin/env python3
0002 #____________________________________________________________
0003 #
0004 #  cuy
0005 #
0006 # A very simple way to make plots with ROOT via an XML file
0007 #
0008 # Francisco Yumiceva
0009 # yumiceva@fnal.gov
0010 #
0011 # Fermilab, 2008
0012 #
0013 # imported from UserCode/Yumiceva/cuy
0014 from __future__ import print_function
0015 #
0016 # modified by Adrien Caudron to create TGraphErrors for b-tag performance plots
0017 # UCLouvain, 2012 
0018 #_____________________________________________________________
0019 
0020 """
0021    cuy
0022 
0023     A very simple way to make plots with ROOT via an XML file.
0024 
0025    usage: %prog -x <XML configuration file>
0026    -b, --batch : run in batch mode without graphics.
0027    -c, --create  = CREATE: create XML configuration file from a ROOT file.
0028    -e, --example = EXAMPLE: generate an example xml file.
0029    -f, --flag    = FLAG: create a baneer
0030    -l, --list    = LIST: list of objects in the ROOT file. 
0031    -p, --prt     = PRT: print canvas in the format specified png, ps, eps, pdf, etc.
0032    -t, --tag     = TAG: tag name for XML configuration file.
0033    -v, --verbose : verbose output.
0034    -w, --wait : Pause script after plotting a new superposition of histograms.
0035    -x, --xml     = XML: xml configuration file.
0036    
0037    Francisco Yumiceva (yumiceva@fnal.gov)
0038    Fermilab 2008
0039    
0040 """
0041 
0042 
0043 import os, string, re, sys, math
0044 
0045 try:
0046     import ROOT
0047 except:
0048     print("\nCannot load PYROOT, make sure you have setup ROOT in the path")
0049     print("and pyroot library is also defined in the variable PYTHONPATH, try:\n")
0050     if (os.getenv("PYTHONPATH")):
0051         print(" setenv PYTHONPATH ${PYTHONPATH}:$ROOTSYS/lib\n")
0052     else:
0053         print(" setenv PYTHONPATH $ROOTSYS/lib\n")
0054     sys.exit()
0055 
0056 from ROOT import TFile
0057 from ROOT import TCanvas
0058 from ROOT import TLegend
0059 from ROOT import SetOwnership
0060 from ROOT import THStack
0061 from ROOT import TLatex
0062 from ROOT import TH1
0063 from ROOT import TH1F
0064 from ROOT import TGraphErrors
0065 from ROOT import TVectorD
0066 from ROOT import std
0067 
0068 from xml.sax import saxutils, make_parser, handler
0069 from xml.sax.handler import feature_namespaces
0070 
0071 import Inspector
0072 import Style
0073 
0074 #_______________OPTIONS________________
0075 import optparse
0076 
0077 USAGE = re.compile(r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
0078 
0079 def nonzero(self): # will become the nonzero method of optparse.Values
0080     "True if options were given"
0081     for v in self.__dict__.values():
0082         if v is not None: return True
0083     return False
0084 
0085 optparse.Values.__nonzero__ = nonzero # dynamically fix optparse.Values
0086 
0087 class ParsingError(Exception): pass
0088 
0089 optionstring=""
0090 
0091 def exit(msg=""):
0092     raise SystemExit(msg or optionstring.replace("%prog",sys.argv[0]))
0093 
0094 def parse(docstring, arglist=None):
0095     global optionstring
0096     optionstring = docstring
0097     match = USAGE.search(optionstring)
0098     if not match: raise ParsingError("Cannot find the option string")
0099     optlines = match.group(1).splitlines()
0100     try:
0101         p = optparse.OptionParser(optlines[0])
0102         for line in optlines[1:]:
0103             opt, help=line.split(':')[:2]
0104             short,long=opt.split(',')[:2]
0105             if '=' in opt:
0106                 action='store'
0107                 long=long.split('=')[0]
0108             else:
0109                 action='store_true'
0110             p.add_option(short.strip(),long.strip(),
0111                          action = action, help = help.strip())
0112     except (IndexError,ValueError):
0113         raise ParsingError("Cannot parse the option string correctly")
0114     return p.parse_args(arglist)
0115 
0116 #______________________________________________________________________
0117 
0118 class ValElement:
0119     def __init__(self):
0120         self.type = ""
0121         self.filename = ""
0122         self.release = ""
0123         self.histos = {}
0124         self.TH1s = {}
0125         self.weight = None
0126 
0127 class divideElement:
0128     def __init__(self):
0129         self.name = ""
0130         self.numerator = None
0131         self.denominator = None
0132 
0133 class plotElement:
0134     def __init__(self):
0135         self.name = ""
0136         self.title = ""
0137         self.color = ""
0138 
0139 class additionElement:
0140     def __init__(self):
0141         self.name = ""
0142         self.title = ""
0143         self.SetLogy = ""
0144         self.SetGrid = ""
0145         self.histos = []
0146         self.weight = []
0147 
0148 class superimposeElement:
0149     def __init__(self):
0150         self.name = ""
0151         self.title = ""
0152         self.SetLogy = ""
0153         self.SetGrid = ""
0154         self.histos = []
0155         self.color = []
0156         self.marker = []
0157         self.legend = []
0158         self.weight = []
0159         #self.flavour = []
0160 #**********************************
0161 class graphElement:
0162     def __init__(self):
0163         self.name = ""
0164         self.title = ""
0165         self.SetLogy = ""
0166         self.SetGrid = ""
0167         self.histos = []
0168         self.color = []
0169         self.marker = []
0170         self.legend = []
0171         self.weight = []
0172         self.flavour = []
0173 #**********************************
0174 
0175 class FindIssue(handler.ContentHandler):
0176     def __init__(self):
0177         self.data = {}
0178         self.divide = {}
0179         self.addition = {}
0180         self.superimpose = {}
0181         self.graph = {}
0182         self.tmpaddname = ""
0183         self.plot = {}
0184         self.size = 0
0185         self.atype = ""
0186         self.tmpsupername = ""
0187         self.tmpgraphname = ""
0188 
0189     def startElement(self, name, attrs):
0190         if name == 'validation':
0191             self.size = self.size + 1
0192             self.atype = attrs.get('type',None)
0193             self.data[self.atype] = ValElement()
0194             self.data[self.atype].type = attrs.get('type',None)
0195             self.data[self.atype].filename = attrs.get('file',None)
0196             self.data[self.atype].release = attrs.get('release',None)
0197             self.data[self.atype].weight = attrs.get('weight','')
0198         if name == 'TH1':
0199             self.data[self.atype].histos[attrs.get('name',None)] = attrs.get('source',None)
0200             #print attrs.get('name',None)
0201             #print attrs.get('source',None)
0202         if name == 'divide':
0203             aname = attrs.get('name',None)
0204             self.divide[aname] = divideElement()
0205             self.divide[aname].name = aname
0206             self.divide[aname].numerator = attrs.get('numerator',None)
0207             self.divide[aname].denominator = attrs.get('denominator',None)
0208             self.divide[aname].DivideOption = attrs.get('DivideOption',None)
0209             self.divide[aname].Option = attrs.get('Option',None)
0210         if name == 'addition':
0211             aname = attrs.get('name',None)
0212             self.addition[aname] = additionElement()
0213             self.tmpaddname = aname
0214             self.addition[aname].name = aname
0215             self.addition[aname].title = attrs.get('title',None)
0216             self.addition[aname].YTitle = attrs.get('YTitle',None)
0217             self.addition[aname].XTitle = attrs.get('XTitle',None)
0218             self.addition[aname].Option = attrs.get('Option',None)
0219             self.addition[aname].Weight = attrs.get('Wight',None)
0220             self.addition[aname].Normalize = attrs.get('Normalize',None)
0221             self.addition[aname].SetGrid = attrs.get('SetGrid',None)
0222         if name == 'additionItem':
0223             #print "in element: " + self.tmpsupername
0224             self.addition[self.tmpaddname].histos.append(attrs.get('name',None))
0225             self.addition[self.tmpaddname].weight.append(attrs.get('weight',None))
0226         if name == 'superimpose':
0227             aname = attrs.get('name',None)
0228             self.superimpose[aname] = superimposeElement()
0229             self.superimpose[aname].name = aname
0230             self.superimpose[aname].title = attrs.get('title',None)
0231             self.superimpose[aname].SetLogy = attrs.get('SetLogy',None)
0232             self.superimpose[aname].SetGrid = attrs.get('SetGrid',None)
0233             self.superimpose[aname].Normalize = attrs.get('Normalize',None)
0234             self.superimpose[aname].Stack     = attrs.get('Stack',None)
0235             self.superimpose[aname].YTitle = attrs.get('YTitle',None)
0236             self.superimpose[aname].XTitle = attrs.get('XTitle',None)
0237             self.superimpose[aname].projection = attrs.get('Projection',None)
0238             self.superimpose[aname].bin = attrs.get('bin',None)
0239             self.superimpose[aname].profile = attrs.get('Profile',None)
0240             self.superimpose[aname].Fill = attrs.get('Fill',None)
0241             self.superimpose[aname].Option = attrs.get('Option',None)
0242             self.superimpose[aname].Weight = attrs.get('Weight',None)
0243             self.superimpose[aname].Maximum = attrs.get('Maximum',None)
0244             self.superimpose[aname].Minimum = attrs.get('Minimum',None)
0245             self.superimpose[aname].Labels = attrs.get('Labels',None)
0246             self.superimpose[aname].Rebin = attrs.get('Rebin',None)
0247             self.tmpsupername = aname
0248         if name == 'graph':
0249             aname = attrs.get('name',None)
0250             self.graph[aname] = graphElement()
0251             self.graph[aname].name = aname
0252             self.graph[aname].title = attrs.get('title',None)
0253             self.graph[aname].SetLogy = attrs.get('SetLogy',None)
0254             self.graph[aname].SetGrid = attrs.get('SetGrid',None)
0255             self.graph[aname].Normalize = attrs.get('Normalize',None)
0256             self.graph[aname].Stack     = attrs.get('Stack',None)
0257             self.graph[aname].YTitle = attrs.get('YTitle',None)
0258             self.graph[aname].XTitle = attrs.get('XTitle',None)
0259             self.graph[aname].projection = attrs.get('Projection',None)
0260             self.graph[aname].bin = attrs.get('bin',None)
0261             self.graph[aname].profile = attrs.get('Profile',None)
0262             self.graph[aname].Fill = attrs.get('Fill',None)
0263             self.graph[aname].Option = attrs.get('Option',None)
0264             self.graph[aname].Weight = attrs.get('Weight',None)
0265             self.graph[aname].Maximum = attrs.get('Maximum',None)
0266             self.graph[aname].Minimum = attrs.get('Minimum',None)
0267             self.graph[aname].Labels = attrs.get('Labels',None)
0268             self.tmpgraphname = aname
0269         if name == 'superimposeItem':
0270             #print "in element: " + self.tmpsupername
0271             self.superimpose[self.tmpsupername].histos.append(attrs.get('name',None))
0272             self.superimpose[self.tmpsupername].color.append(attrs.get('color',None))
0273             self.superimpose[self.tmpsupername].marker.append(attrs.get('MarkerStyle',None))
0274             self.superimpose[self.tmpsupername].legend.append(attrs.get('legend',None))
0275             #self.superimpose[self.tmpsupername].flavour.append(attrs.get('flavour',None))
0276             #self.superimpose[self.tmpsupername].weight.append(attrs.get('weight',None))
0277         if name == 'graphItem':
0278             #print "in element: " + self.tmpsupername
0279             self.graph[self.tmpgraphname].histos.append(attrs.get('name',None))
0280             self.graph[self.tmpgraphname].color.append(attrs.get('color',None))
0281             self.graph[self.tmpgraphname].marker.append(attrs.get('MarkerStyle',None))
0282             self.graph[self.tmpgraphname].legend.append(attrs.get('legend',None))
0283             self.graph[self.tmpgraphname].flavour.append(attrs.get('flavour',None))
0284             #self.se[self.tmpsupername].weight.append(attrs.get('weight',None))
0285 
0286 
0287 
0288 if __name__ == '__main__':
0289 
0290 
0291 
0292     # style
0293     thestyle = Style.Style()
0294     thestyle.SetStyle()
0295 
0296     printCanvas = False
0297     printFormat = "png"
0298     printBanner = False
0299     Banner = "CMS Preliminary"
0300     verbose = False
0301 
0302     # check options
0303     option,args = parse(__doc__)
0304     if not args and not option: exit()
0305 
0306     if option.batch:
0307         ROOT.gROOT.SetBatch()
0308 
0309     if option.verbose:
0310         verbose = True
0311 
0312     if option.list:
0313         ins = Inspector.Inspector()
0314         ins.Verbose(True)
0315         ins.createXML(False)
0316         ins.SetFilename(option.list)
0317         ins.GetListObjects()
0318         sys.exit()
0319 
0320     if option.create:
0321         createXML = Inspector.Inspector()
0322         createXML.Verbose(False)
0323         createXML.createXML(True)
0324         if option.tag:
0325             createXML.SetTag(option.tag)
0326         createXML.SetFilename(option.create)
0327         createXML.GetListObjects()
0328         sys.exit()
0329 
0330     if not option.xml: exit()
0331     if option.prt: 
0332         printCanvas = True
0333         printFormat = option.prt
0334 
0335     if option.flag:
0336         printBanner = True
0337         Banner = option.flag
0338 
0339     # check xml file
0340     try:
0341         xmlfile = open(option.xml)
0342         xmlfile.close()
0343     except:
0344         print(" ERROR: xml file \"" + option.xml + "\" does not exist")
0345         sys.exit()
0346 
0347     # Create a parser
0348     parser = make_parser()
0349 
0350     # Tell the parser we are not interested in XML namespaces
0351     parser.setFeature(feature_namespaces, 0)
0352 
0353     # Create the handler
0354     dh = FindIssue()
0355 
0356     # Tell the parser to use our handler
0357     parser.setContentHandler(dh)
0358 
0359     # Parse the input
0360     parser.parse(option.xml)
0361 
0362     # list of canvas
0363     cv = {}
0364     afilelist = {}
0365     stacklist = {}
0366 
0367     # root output file
0368     outputroot = TFile("cuy.root","RECREATE")
0369 
0370     # new histograms
0371     newTH1list = []
0372 
0373     # extract histograms
0374     thedata = dh.data
0375 
0376     firstFilename = ''
0377 
0378     for ikey in thedata:
0379         if verbose : print("= Processing set called: " + ikey)
0380         afilename = thedata[ikey].filename
0381         if firstFilename == '':
0382             firstFilename = afilename
0383         arelease = ""
0384         if thedata[ikey].release != None:
0385             arelease = thedata[ikey].release
0386         if verbose : print("== filename: " + afilename)
0387         if verbose : print("== release:  " + arelease)
0388         if verbose : print("== weight:   " + thedata[ikey].weight)
0389         thehistos = thedata[ikey].histos
0390         afilelist[afilename] = TFile(afilename)
0391         if verbose : print("== get histograms: ")
0392         histonamekeys = thehistos.keys()
0393         for ihname in histonamekeys:
0394             if verbose : print("=== Histogram name: \""+ ihname + "\" source: \""+thehistos[ihname]+"\"")
0395             thedata[ikey].TH1s[ihname] = ROOT.gDirectory.Get(thehistos[ihname])
0396             #SetOwnership(thedata[ikey].TH1s[ihname], 0)
0397             # check if file exists
0398             print(thedata[ikey].TH1s[ihname].GetName())
0399 
0400 
0401     # plot superimpose histograms
0402     #afilelist['../outputLayer2_ttbarmuonic_all.root'].cd()
0403     afilelist[firstFilename].cd()
0404     #print thedata['ttbar'].TH1s['gen_eta'].GetEntries()
0405 
0406 
0407     theaddition = dh.addition
0408     if verbose : print("= Create addition histograms:")
0409 
0410     for ikey in theaddition:
0411         if verbose : print("== plot name: \""+theaddition[ikey].name+"\" title: \""+theaddition[ikey].title+"\"")
0412         listname = theaddition[ikey].histos
0413         listweight = theaddition[ikey].weight
0414 
0415         #create canvas
0416         cv[theaddition[ikey].name] = TCanvas(theaddition[ikey].name,theaddition[ikey].name,700,700)
0417 
0418         isFirst = True
0419         ihnameIt = 0
0420         for ihname in listname:
0421             aweight = 1
0422             if listweight[ihnameIt]:
0423             #if thedata[jkey].weight != None and theaddition[ikey].Weight == "true":
0424                 aweight = float(listweight[ihnameIt])
0425                 #aweight = float(thedata[jkey].weight)
0426             for jkey in thedata:
0427                 tmpkeys = thedata[jkey].histos.keys()
0428                 for tmpname in tmpkeys:
0429                     if tmpname == ihname:
0430                         ath = thedata[jkey].TH1s[tmpname]
0431                         if ath is None:
0432                             print("ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename)
0433                             exit(0)
0434                         if verbose : print("=== add histogram: "+ath.GetName() + " from " + thedata[jkey].filename + " mean = " + "%.2f" % round(ath.GetMean(),2) + " weight= " + str(aweight))
0435                         #ath.Print("all")
0436                         if isFirst:
0437                             newth = ath.Clone(theaddition[ikey].name)
0438                             newth.Sumw2()
0439                             if theaddition[ikey].Normalize == "true":
0440                                 newth.Scale(1/newth.Integral())
0441                             newth.Scale(aweight)
0442                             isFirst = False
0443                         else:
0444                             atmpth = ath.Clone()
0445                             atmpth.Sumw2()
0446                             if theaddition[ikey].Normalize == "true":
0447                                 atmpth.Scale(1/atmpth.Integral())
0448                             atmpth.Scale(aweight)
0449                             newth.Add( atmpth )
0450             ihnameIt = ihnameIt + 1
0451 
0452         if theaddition[ikey].XTitle != None:
0453             newth.SetXTitle(theaddition[ikey].XTitle)
0454         if theaddition[ikey].YTitle != None:
0455             newth.SetYTitle(theaddition[ikey].YTitle)
0456 
0457         if theaddition[ikey].Option:
0458             newth.Draw(theaddition[ikey].Option)
0459         else:
0460             newth.Draw()
0461 
0462         if theaddition[ikey].SetGrid == "true":
0463             cv[theaddition[ikey].name].SetGrid()
0464 
0465         cv[theaddition[ikey].name].Update()
0466 
0467         # add new histogram to the list
0468         newth.SetName(theaddition[ikey].name)
0469         newTH1list.append(newth.GetName())
0470         thedata[newth.GetName()] = ValElement()
0471         thedata[newth.GetName()].TH1s[newth.GetName()] = newth
0472         thedata[newth.GetName()].histos[newth.GetName()] = newth.GetName()
0473 
0474         # write new histograms to file
0475         outputroot.cd()
0476         newth.Write()
0477 
0478 
0479     if verbose : print("= Create ratio histograms:")
0480 
0481     thedivition = dh.divide
0482     for ikey in thedivition:
0483         if verbose : print("== plot name: \""+thedivition[ikey].name+"\" title: \""+"\"")
0484         numerator = thedivition[ikey].numerator
0485         denominator = thedivition[ikey].denominator
0486 
0487         #create canvas
0488         cv[thedivition[ikey].name] = TCanvas(thedivition[ikey].name,thedivition[ikey].name,700,700)
0489 
0490         for jkey in thedata:
0491             tmpkeys = thedata[jkey].histos.keys()
0492             for tmpname in tmpkeys:
0493                 if tmpname == numerator:
0494                     numeratorth = thedata[jkey].TH1s[tmpname]
0495                     if numeratorth is None:
0496                         print("ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename)
0497                         exit(0)
0498                         #print "=== numerator histogram: "+numeratorth.GetName() + " from " + thedata[jkey].filename + " mean = " + "%.2f" % round(numeratorth.GetMean(),2) + " weight= " + str(aweight)
0499 
0500                 if tmpname == denominator:
0501                     denominatorth = thedata[jkey].TH1s[tmpname]
0502                     if denominatorth is None:
0503                         print("ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename)
0504                         exit(0)
0505                         #print "=== denominator histogram: "+denominatorth.GetName() + " from " + thedata[jkey].filename + " mean = " + "%.2f" % round(denominatorth.GetMean(),2) + " weight= " + str(aweight)
0506 
0507 
0508 
0509         numeratorth.Sumw2()
0510         denominatorth.Sumw2()
0511         newth = numeratorth.Clone()
0512         newth.Clear()
0513         if thedivition[ikey].DivideOption is None:
0514             newth.Divide(numeratorth,denominatorth)
0515         else:
0516             newth.Divide(numeratorth,denominatorth,1.,1.,thedivition[ikey].DivideOption)
0517 #   if theaddition[ikey].XTitle != None:
0518 #       newth.SetXTitle(theaddition[ikey].XTitle)
0519 #   if theaddition[ikey].YTitle != None:
0520 #       newth.SetYTitle(theaddition[ikey].YTitle)
0521 
0522         if thedivition[ikey].Option:
0523             newth.Draw(thedivition[ikey].Option)
0524         else:
0525             newth.Draw()
0526 
0527         cv[thedivition[ikey].name].Update()
0528 
0529 
0530         # pause
0531         if option.wait:
0532             raw_input( 'Press ENTER to continue\n ' )
0533 
0534         # add new histogram to the list
0535         newth.SetName(thedivition[ikey].name)
0536         newTH1list.append(newth.GetName())
0537         thedata[newth.GetName()] = ValElement()
0538         thedata[newth.GetName()].TH1s[newth.GetName()] = newth
0539         thedata[newth.GetName()].histos[newth.GetName()] = newth.GetName()
0540 
0541         # write new histograms to file
0542         outputroot.cd()
0543         newth.Write()
0544 
0545 
0546     thesuper = dh.superimpose
0547     if verbose : print("= Create superimpose histograms:")
0548     for ikey in thesuper:
0549         if verbose : print("== plot name: \""+thesuper[ikey].name+"\" title: \""+thesuper[ikey].title+"\"")
0550         listname = thesuper[ikey].histos
0551         listcolor = thesuper[ikey].color
0552         listmarker = thesuper[ikey].marker
0553         listlegend = thesuper[ikey].legend
0554         #listweight = thesuper[ikey].weight
0555         dolegend = False
0556         for il in listlegend:
0557             if il==None: dolegend = False
0558         if verbose : print("dolegend = " +str(dolegend))
0559         doNormalize = False
0560         doRebin=thesuper[ikey].Rebin
0561         if doRebin is not None :
0562             doRebin=int(doRebin)
0563             if verbose : print("Rebin is ", doRebin)
0564         if thesuper[ikey].Normalize == "true":
0565             doNormalize = True
0566             if verbose : print("normalize = " +str(doNormalize))
0567         projectAxis = "no"
0568         projectBin = -1 #all
0569         if thesuper[ikey].projection == "x": projectAxis = "x"
0570         if thesuper[ikey].projection == "y": projectAxis = "y"
0571         if thesuper[ikey].bin != None: projectBin = thesuper[ikey].bin
0572         profileAxis = "no"
0573         if thesuper[ikey].profile == "x": profileAxis = "x"
0574         if thesuper[ikey].profile == "y": profileAxis = "y"
0575         doFill = False
0576         if thesuper[ikey].Fill == "true": doFill = True
0577         if verbose : print("fill option:"+ doFill)
0578         #create canvas
0579         cv[thesuper[ikey].name] = TCanvas(thesuper[ikey].name,thesuper[ikey].title,700,700)
0580         #legend
0581         aleg = TLegend(0.6,0.4,0.8,0.6)
0582         SetOwnership( aleg, 0 ) 
0583         aleg.SetMargin(0.12)
0584         aleg.SetTextSize(0.035)
0585         aleg.SetFillColor(10)
0586         aleg.SetBorderSize(0)
0587 
0588         isFirst = 1
0589         ii = 0
0590 
0591         stacklist[thesuper[ikey].name] = THStack("astack"+thesuper[ikey].name,thesuper[ikey].title)
0592         astack = stacklist[thesuper[ikey].name]
0593         for ihname in listname:
0594 
0595             for jkey in thedata:
0596                 tmpkeys = thedata[jkey].histos.keys()
0597 
0598                 for tmpname in tmpkeys:
0599 
0600                     if tmpname == ihname:
0601                         ath = thedata[jkey].TH1s[tmpname]
0602                         if ath is None:
0603                             print("ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename)
0604                             exit(0)
0605                         if verbose : print("=== superimpose histogram: "+ath.GetName() + " mean = " + "%.2f" % round(ath.GetMean(),2))
0606                         # project 2D histogram if requested
0607                         if projectAxis == "x":
0608                             if projectBin == -1:
0609                                 newthpx = ath.ProjectionX(ath.GetName()+"_px",0,-1,"e")
0610                             else:
0611                                 newthpx = ath.ProjectionX(ath.GetName()+"_px",int(projectBin),int(projectBin),"e")
0612                             newth = newthpx.Clone()
0613                         if projectAxis == "y":
0614                             if projectBin == -1:
0615                                 newthpy = ath.ProjectionY(ath.GetName()+"_py",0,-1,"e")
0616                             else:
0617                                 newthpx = ath.ProjectionY(ath.GetName()+"_py",int(projectBin),int(projectBin),"e")
0618                             newth = newthpy.Clone()
0619                         if profileAxis == "x":
0620                             newthpx = ath.ProfileX(ath.GetName()+"_px",0,-1,"e")
0621                             newth = newthpx.Clone()
0622                         if profileAxis == "y":
0623                             newthpy = ath.ProfileY(ath.GetName()+"_py",0,-1,"e")
0624                             newth = newthpy.Clone()
0625 
0626                         # get weight
0627                         aweight = 1
0628                         if thedata[jkey].weight != None and thesuper[ikey].Weight=="true":
0629                             aweight = float( thedata[jkey].weight )
0630                         if verbose: print(" with weight = " + str(aweight))
0631                         #if listweight[ii]:
0632                          #   aweight = float( listweight[ii] )
0633 
0634                         # clone original histogram
0635                         if projectAxis == "no" and profileAxis == "no" :newth = ath.Clone()
0636 
0637                         if doRebin is not None and doRebin>0 :
0638                             newth.Rebin(doRebin)
0639 
0640                         newth.Sumw2()
0641                         newth.Scale(aweight)
0642 
0643                         # check if we have color
0644                         if not listcolor[ii]:
0645                             listcolor[ii] = 1
0646 
0647                         newth.SetLineColor(int(listcolor[ii]))
0648                         newth.SetMarkerColor(int(listcolor[ii]))
0649 
0650                         if doFill: newth.SetFillColor(int(listcolor[ii]))
0651 
0652                         if listmarker[ii] != None:
0653                             newth.SetMarkerStyle(int(listmarker[ii]))
0654                         # normalize
0655                         if doNormalize:
0656                             newth.Scale(1./newth.Integral())
0657                         #print "   "+listlegend[ii]
0658 
0659                         if thesuper[ikey].Labels != None:
0660                             thelabels = thesuper[ikey].Labels.split(',')
0661                             ib = 1
0662                             #print thelabels
0663 
0664                             for ilabel in thelabels:
0665                                 newth.GetXaxis().SetBinLabel(ib,ilabel)
0666                                 #if ib==1:
0667                                     #newth.GetXaxis().SetBinLabel(ib,"")
0668                                 #newth.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
0669                                 ib += 1
0670                             #if aweight==0.0081:
0671                         #   newth.SetBinContent(1, newth.GetBinContent(1) / 0.28756)
0672                          #   if aweight==0.0883:
0673                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.01953)
0674                             #if aweight==0.0731:
0675                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.0367)
0676                             #if aweight==0.4003:
0677                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.5683)
0678                             #if aweight==0.003:
0679                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.21173)
0680                             #if aweight==0.0027:
0681                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
0682                             #if aweight==0.0034:
0683                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
0684 
0685 
0686                         # stack histograms
0687                         if doFill:
0688                             if thesuper[ikey].XTitle != None:
0689                                 newth.SetXTitle("")
0690                             astack.Add(newth,"HIST")
0691                         elif thesuper[ikey].Option:
0692                             astack.Add(newth,thesuper[ikey].Option)
0693                         else:
0694                             #newth.Fit("landau")
0695                             astack.Add(newth)
0696 
0697                         astack.SetTitle(thesuper[ikey].title)
0698 
0699                         if isFirst==1:
0700                             newth.GetPainter().PaintStat(ROOT.gStyle.GetOptStat(),0);
0701                             isFirst=0
0702                             tmpsumth = newth.Clone()
0703                         else:
0704                             tmpsumth.Add(newth)
0705                         #    newth.SetTitle(thesuper[ikey].title)
0706                         #    if thesuper[ikey].YTitle != None:
0707                         #   newth.SetYTitle(thesuper[ikey].YTitle)
0708                         #    newth.Draw()
0709                         #    isFirst=0
0710                         #else:
0711                         #    newth.Draw("same")
0712                         if dolegend and doFill: 
0713                             aleg.AddEntry(newth,listlegend[ii],"F")
0714                         elif dolegend:
0715                             aleg.AddEntry(newth,listlegend[ii],"P")
0716 
0717                         newth.SetName(tmpname)
0718                         outputroot.cd()
0719                         newth.Write()
0720             ii = ii + 1
0721 
0722 
0723         if thesuper[ikey].Maximum != None:
0724             astack.SetMaximum( float(thesuper[ikey].Maximum) )
0725         if thesuper[ikey].Minimum != None:
0726             astack.SetMinimum( float(thesuper[ikey].Minimum) )
0727         if thesuper[ikey].Stack == "true":
0728             astack.Draw()
0729         if thesuper[ikey].Stack == "false" or thesuper[ikey].Stack == None:
0730             astack.Draw()
0731             astack.Draw("nostack")
0732         if thesuper[ikey].XTitle != None:
0733             astack.GetHistogram().SetXTitle(thesuper[ikey].XTitle)
0734         if thesuper[ikey].YTitle != None:
0735             astack.GetHistogram().SetYTitle(thesuper[ikey].YTitle)
0736         if doFill:
0737             astack.Draw("sameaxis")
0738 
0739 
0740         #thelabels = []
0741         #if thesuper[ikey].Labels != None:
0742         #    thelabels = thesuper[ikey].Labels.split(',')
0743         #    ib = 1
0744         #    print thelabels
0745 
0746          #   for ilabel in thelabels:
0747         #   astack.GetXaxis().SetBinLabel(ib,ilabel)
0748                 #astack.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
0749                 #ib += 1
0750         #    astack.Draw()
0751         #    astack.Draw("sameaxis")
0752 
0753         if dolegend: 
0754             aleg.Draw()
0755         if thesuper[ikey].SetLogy == "true":
0756             cv[thesuper[ikey].name].SetLogy()
0757         if thesuper[ikey].SetGrid == "true":
0758             cv[thesuper[ikey].name].SetGrid()
0759 
0760         # test smearing
0761         #rn = ROOT.TRandom(12345)
0762         #for iibin in range(0,tmpsumth.GetNbinsX()):
0763         #    tmpsumth.SetBinContent(iibin, rn.Poisson(tmpsumth.GetBinContent(iibin)) )
0764         #    if tmpsumth.GetBinContent(iibin) == 0:
0765         #   tmpsumth.SetBinError(iibin, 0 )
0766         #    else:
0767         #   tmpsumth.SetBinError(iibin, 1/math.sqrt(tmpsumth.GetBinContent(iibin)) )
0768 
0769         #tmpsumth.Draw("same E1")
0770 
0771 
0772         if printBanner:
0773             tex = TLatex(0.35,0.95,Banner)
0774             tex.SetNDC()
0775             tex.SetTextSize(0.05)
0776             tex.Draw()
0777 
0778         cv[thesuper[ikey].name].Update()
0779         #cv[thesuper[ikey].name].Print("test.png")
0780 
0781         # pause
0782         if option.wait:
0783             raw_input( 'Press ENTER to continue\n ' )
0784 
0785 
0786 
0787 #**********************************************************************
0788 
0789 
0790     thegraph = dh.graph
0791     if verbose : print("= Create graph histograms:")
0792     for ikey in thegraph:
0793         if verbose : print("== plot name: \""+thegraph[ikey].name+"\" title: \""+thegraph[ikey].title+"\"")
0794         listname = thegraph[ikey].histos
0795         listcolor = thegraph[ikey].color
0796         listmarker = thegraph[ikey].marker
0797         listlegend = thegraph[ikey].legend
0798         listflavour = thegraph[ikey].flavour
0799         #listweight = thegraph[ikey].weight
0800         dolegend = False
0801         for il in listlegend:
0802             if il==None: dolegend = False
0803         if verbose : print("dolegend = " +str(dolegend))
0804         doNormalize = False
0805         if thegraph[ikey].Normalize == "true":
0806             doNormalize = True
0807             if verbose : print("normalize = " +str(doNormalize))
0808         projectAxis = "no"
0809         projectBin = -1 #all
0810         if thegraph[ikey].projection == "x": projectAxis = "x"
0811         if thegraph[ikey].projection == "y": projectAxis = "y"
0812         if thegraph[ikey].bin != None: projectBin = thegraph[ikey].bin
0813         profileAxis = "no"
0814         if thegraph[ikey].profile == "x": profileAxis = "x"
0815         if thegraph[ikey].profile == "y": profileAxis = "y"
0816         doFill = False
0817         if thegraph[ikey].Fill == "true": doFill = True
0818         if verbose : print("fill option:"+ doFill)
0819         #create canvas
0820         cv[thegraph[ikey].name] = TCanvas(thegraph[ikey].name,thegraph[ikey].title,700,700)
0821         #legend
0822         aleg = TLegend(0.6,0.4,0.8,0.6)
0823         SetOwnership( aleg, 0 )
0824         aleg.SetMargin(0.12)
0825         aleg.SetTextSize(0.035)
0826         aleg.SetFillColor(10)
0827         aleg.SetBorderSize(0)
0828 
0829         isFirst = 1
0830         ii = 0
0831 
0832         stacklist[thegraph[ikey].name] = THStack("astack"+thegraph[ikey].name,thegraph[ikey].title)
0833         astack = stacklist[thegraph[ikey].name]
0834         xVal_val = TVectorD()
0835         yVal_val = TVectorD()
0836         yBin_val = std.vector(int)()
0837         xErr_val = TVectorD()
0838         yErr_val = TVectorD()
0839         zVal_val = TVectorD()
0840         zErr_val = TVectorD()
0841         nVal_val = 0
0842 
0843         xVal_ref = TVectorD()
0844         yVal_ref = TVectorD()
0845         yBin_ref = std.vector(int)()
0846         xErr_ref = TVectorD()
0847         yErr_ref = TVectorD()
0848         zVal_ref = TVectorD()
0849         zErr_ref = TVectorD()
0850         nVal_ref = 0
0851 
0852         RangeMax = 0.005
0853         RangeMin = 0.9
0854 
0855         for ihname in listname:
0856 
0857             for jkey in thedata:
0858                 tmpkeys = thedata[jkey].histos.keys()
0859 
0860                 for tmpname in tmpkeys:
0861 
0862                     if tmpname == ihname:
0863 
0864                         ath = thedata[jkey].TH1s[tmpname]
0865                         if ath is None:
0866                             print("ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename)
0867                             exit(0)
0868                         if verbose : print("=== graph histogram: "+ath.GetName() + " mean = " + "%.2f" % round(ath.GetMean(),2))
0869                         #print listflavour[ii]
0870                         if listflavour[ii] == "5":
0871                             #print "iiiiiiiiiii" 
0872                             nBinB = 200 #ath.GetNbinsX()
0873                             BinWidth = (0.01+ath.GetMaximum())/nBinB
0874                             BMid = 0.005+BinWidth/2
0875                             Err = BinWidth
0876                             for iBinB in range(1,nBinB+1):
0877                                 #BinWidth = (0.01+ath.GetMaximum())/200 #ath.GetBinWidth(iBinB)
0878                                 BMid = BMid+Err #BinWidth #ath.GetBinCenter(iBinB)
0879                                 #newh = TH1(ath)
0880                                 nAthBin = ath.GetNbinsX()-2
0881                                 #newh = TH1(ath)
0882                                 maxInHisto = ath.GetMaximum()
0883                                 minInHisto = ath.GetMinimum()
0884                                 #print minInHisto
0885                                 yClosestInit = 0
0886                                 iBinClosestInit = 0
0887                                 if BMid <= maxInHisto : yClosestInit = maxInHisto + 1
0888                                 else : yClosestInit = minInHisto - 1.0
0889                                 iBinClosest = iBinClosestInit
0890                                 yClosest    = yClosestInit
0891                                 for iAthBin in range(1,nAthBin+1):
0892                                     yBin = ath.GetBinContent(iAthBin)
0893                                     dif1 = BMid-yBin
0894                                     if dif1 < 0 : dif1 = yBin-BMid
0895                                     dif2 = yClosest-BMid
0896                                     if dif2 < 0 : dif2 = BMid-yClosest
0897                                     if dif1 < dif2:
0898                                         yClosest = yBin
0899                                         iBinClosest = iAthBin
0900                                 min = BMid-Err/2 
0901                                 max = BMid+Err/2
0902                                 #print iBinClosest
0903                                 if yClosest < min or  yClosest > max:
0904                                     iBinClosest = 0
0905                                     #print "iji"
0906                                 if iBinClosest > 0 and listmarker[ii] == "8":
0907                                     #print "hhhhhhhhhhhhhhhh"
0908                                     nVal_ref = nVal_ref+1
0909                                     xVal_ref.ResizeTo(nVal_ref)
0910                                     #yBin_ref.ResizeTo(nVal_ref)
0911                                     xErr_ref.ResizeTo(nVal_ref)
0912                                     xVal_ref[nVal_ref-1] = BMid
0913                                     yBin_ref.push_back(iBinClosest)
0914                                     xErr_ref[nVal_ref-1] = ath.GetBinError ( iBinClosest )
0915                                     Err = xErr_ref[nVal_ref-1]
0916                                     if Err < BinWidth : Err = BinWidth
0917                                 elif iBinClosest > 0:
0918                                     nVal_val = nVal_val+1
0919                                     xVal_val.ResizeTo(nVal_val)
0920                                     #yBin_val.ResizeTo(nVal_val)
0921                                     xErr_val.ResizeTo(nVal_val)
0922                                     xVal_val[nVal_val-1] = BMid
0923                                     yBin_val.push_back(iBinClosest)
0924                                     xErr_val[nVal_val-1] = ath.GetBinError ( iBinClosest )
0925                                     Err = xErr_val[nVal_val-1]
0926                                     if Err < BinWidth : Err = BinWidth
0927                         elif listflavour[ii] == "4" and listmarker[ii] == "8":
0928                             yVal_ref.ResizeTo(nVal_ref)
0929                             yErr_ref.ResizeTo(nVal_ref)
0930                             for iVal in range(0,nVal_ref):                                
0931                                 yVal_ref[iVal] = ath.GetBinContent (yBin_ref[iVal])
0932                                 if yVal_ref[iVal] > RangeMax : RangeMax = yVal_ref[iVal]
0933                                 yErr_ref[iVal] = ath.GetBinError (yBin_ref[iVal])
0934                         elif listflavour[ii] == "4":
0935                             yVal_val.ResizeTo(nVal_val)
0936                             yErr_val.ResizeTo(nVal_val)
0937                             for iVal in range(0,nVal_val):                                
0938                                 yVal_val[iVal] = ath.GetBinContent (yBin_val[iVal])
0939                                 yErr_val[iVal] = ath.GetBinError (yBin_val[iVal])
0940                         elif listmarker[ii] == "8":
0941                             zVal_ref.ResizeTo(nVal_ref)
0942                             zErr_ref.ResizeTo(nVal_ref)
0943                             for iVal in range(0,nVal_ref):                                
0944                                 zVal_ref[iVal] = ath.GetBinContent (yBin_ref[iVal])
0945                                 zErr_ref[iVal] = ath.GetBinError (yBin_ref[iVal])
0946                                 if zVal_ref[iVal] < RangeMin : RangeMin = zVal_ref[iVal]
0947                         else:
0948                             zVal_val.ResizeTo(nVal_val)
0949                             zErr_val.ResizeTo(nVal_val)
0950                             for iVal in range(0,nVal_val):
0951                                 zVal_val[iVal] = ath.GetBinContent (yBin_val[iVal])
0952                                 zErr_val[iVal] = ath.GetBinError (yBin_val[iVal])
0953             ii = ii + 1
0954 
0955         #print xVal_ref.GetNoElements()
0956         #print yVal_ref.GetNrows()
0957         #print xErr_ref.GetNrows()
0958         #print yErr_ref.GetNrows()
0959 
0960         #graphs = std.vector(TGraphErrors)()
0961         graphs = [TGraphErrors(xVal_ref,yVal_ref,xErr_ref,yErr_ref),
0962         TGraphErrors(xVal_ref,zVal_ref,xErr_ref,zErr_ref),
0963         TGraphErrors(xVal_val,yVal_val,xErr_val,yErr_val),
0964         TGraphErrors(xVal_val,zVal_val,xErr_val,zErr_val)]
0965         ii = 0
0966 
0967 
0968 
0969         for ii in range(0,4):
0970 
0971                         # project 2D histogram if requested
0972                         #if projectAxis == "x":
0973                         #    if projectBin == -1:
0974                         #       newthpx = ath.ProjectionX(ath.GetName()+"_px",0,-1,"e")
0975                         #    else:
0976                         #       newthpx = ath.ProjectionX(ath.GetName()+"_px",int(projectBin),int(projectBin),"e")
0977                         #    newth = newthpx.Clone()
0978                         #if projectAxis == "y":
0979                         #    if projectBin == -1:
0980                         #       newthpy = ath.ProjectionY(ath.GetName()+"_py",0,-1,"e")
0981                         #    else:
0982                         #       newthpx = ath.ProjectionY(ath.GetName()+"_py",int(projectBin),int(projectBin),"e")
0983                         #    newth = newthpy.Clone()
0984                         #if profileAxis == "x":
0985                         #    newthpx = ath.ProfileX(ath.GetName()+"_px",0,-1,"e")
0986                         #    newth = newthpx.Clone()
0987                         #if profileAxis == "y":
0988                         #    newthpy = ath.ProfileY(ath.GetName()+"_py",0,-1,"e")
0989                         #    newth = newthpy.Clone()
0990 
0991                         # get weight
0992             aweight = 1
0993             #if thedata[jkey].weight != None and thegraph[ikey].Weight=="true":
0994             #    aweight = float( thedata[jkey].weight )
0995             #if verbose: print " with weight = " + str(aweight)
0996             #if listweight[ii]:
0997                          #   aweight = float( listweight[ii] )
0998 
0999             # clone original histogram
1000             #if projectAxis == "no" and profileAxis == "no" :newth = ath.Clone()
1001 
1002             #newth.Sumw2()
1003             #newth.Scale(aweight)
1004 
1005             # check if we have color
1006             #if not listcolor[ii]:
1007             #    listcolor[ii] = 1
1008 
1009             col = 2
1010             mark = 22
1011             if ii == 0 or ii == 2:
1012                 col = 1
1013             if ii == 0 or ii == 1:
1014                 mark = 8
1015 
1016             graphs[ii].SetLineColor(col)
1017             graphs[ii].SetMarkerStyle(mark)
1018             graphs[ii].SetMarkerColor(col)
1019             graphs[ii].SetTitle(thegraph[ikey].title)
1020             #if doFill: newth.SetFillColor(int(listcolor[ii]))
1021 
1022             #if listmarker[ii] != None:
1023             #    newth.SetMarkerStyle(int(listmarker[ii]))
1024             # normalize
1025             #if doNormalize:
1026             #    newth.Scale(1./newth.Integral())
1027             #print "   "+listlegend[ii]
1028 
1029             #if thegraph[ikey].Labels != None:
1030             #    thelabels = thesuper[ikey].Labels.split(',')
1031                          #   ib = 1
1032                 #print thelabels
1033 
1034                          #   for ilabel in thelabels:
1035                          #       newth.GetXaxis().SetBinLabel(ib,ilabel)
1036                 #if ib==1:
1037                                     #newth.GetXaxis().SetBinLabel(ib,"")
1038                 #newth.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
1039               #      ib += 1
1040                 #if aweight==0.0081:
1041             #       newth.SetBinContent(1, newth.GetBinContent(1) / 0.28756)
1042                          #   if aweight==0.0883:
1043                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.01953)
1044                 #if aweight==0.0731:
1045                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.0367)
1046                 #if aweight==0.4003:
1047                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.5683)
1048                 #if aweight==0.003:
1049                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.21173)
1050                 #if aweight==0.0027:
1051                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
1052                 #if aweight==0.0034:
1053                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
1054 
1055 
1056             # stack histograms
1057             #if doFill:
1058                          #   if thegraph[ikey].XTitle != None:
1059             #        newth.SetXTitle("")
1060             #    astack.Add(newth,"HIST")
1061             #elif thegraph[ikey].Option:
1062             #    astack.Add(newth,thegraph[ikey].Option)
1063             #else:
1064                 #newth.Fit("landau")
1065             #    astack.Add(newth)
1066 
1067             #astack.SetTitle(thegraph[ikey].title)
1068 
1069             if isFirst==1:
1070                 #graphs[ii].GetPainter().PaintStat(ROOT.gStyle.GetOptStat(),0);
1071                 isFirst=0
1072                 #tmpsumth = graphs[ii].Clone()
1073             #else:
1074             #    tmpsumth.Add(graphs[ii])
1075             #    newth.SetTitle(thesuper[ikey].title)
1076             #    if thesuper[ikey].YTitle != None:
1077             #       newth.SetYTitle(thesuper[ikey].YTitle)
1078             #    newth.Draw()
1079             #    isFirst=0
1080             #else:
1081             #    newth.Draw("same")
1082             #if dolegend and doFill:
1083             #    aleg.AddEntry(newth,listlegend[ii],"F")
1084             #elif dolegend:
1085             #    aleg.AddEntry(newth,listlegend[ii],"P")
1086 
1087             #graphs[ii].SetName(tmpname)
1088             #if ii == 0 : graphs[ii].Draw()
1089             #else : graphs[ii].Draw("same")
1090             outputroot.cd()
1091             graphs[ii].Write()
1092             ii = ii + 1
1093 
1094 
1095         #if thegraph[ikey].Maximum != None:
1096         #    graphs[0].SetMaximum( float(thegraph[ikey].Maximum) )
1097         #if thegraph[ikey].Minimum != None:
1098         #    graphs[0].SetMinimum( float(thegraph[ikey].Minimum) )
1099         #if thegraph[ikey].Stack == "true":
1100         #    astack.Draw()
1101         #if thegraph[ikey].Stack == "false" or thegraph[ikey].Stack == None:
1102         #    astack.Draw()
1103         #    astack.Draw("nostack")
1104         if thegraph[ikey].XTitle != None:
1105             graphs[0].GetHistogram().SetXTitle(thegraph[ikey].XTitle)
1106         if thegraph[ikey].YTitle != None:
1107             graphs[0].GetHistogram().SetYTitle(thegraph[ikey].YTitle)
1108         #if doFill:
1109         #    astack.Draw("sameaxis")
1110         if RangeMax > 0.5 : RangeMax = 1.5
1111         if RangeMax < 0.5 : RangeMax = RangeMax + 0.05
1112         #RangeMax = 1.1
1113         RangeMin = RangeMin - 0.5*RangeMin
1114         #print RangeMax
1115         #print RangeMin
1116         if RangeMin < 0.00001 : RangeMin = 0.00005
1117         graphs[0].GetYaxis().SetRangeUser(RangeMin,RangeMax)
1118 
1119         #thelabels = []
1120         #if thesuper[ikey].Labels != None:
1121         #    thelabels = thesuper[ikey].Labels.split(',')
1122         #    ib = 1
1123         #    print thelabels
1124 
1125          #   for ilabel in thelabels:
1126         #       astack.GetXaxis().SetBinLabel(ib,ilabel)
1127                 #astack.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
1128                 #ib += 1
1129         #    astack.Draw()
1130         #    astack.Draw("sameaxis")
1131 
1132         #h = TH1F()
1133         #h.Draw()
1134         graphs[0].Draw("AP")
1135         graphs[1].Draw("sameP")
1136         graphs[2].Draw("sameP")
1137         graphs[3].Draw("sameP")
1138         if dolegend:
1139             aleg.Draw()
1140         if thegraph[ikey].SetLogy == "true":
1141             cv[thegraph[ikey].name].SetLogy()
1142         if thegraph[ikey].SetGrid == "true":
1143             cv[thegraph[ikey].name].SetGrid()
1144 
1145         # test smearing
1146         #rn = ROOT.TRandom(12345)
1147         #for iibin in range(0,tmpsumth.GetNbinsX()):
1148         #    tmpsumth.SetBinContent(iibin, rn.Poisson(tmpsumth.GetBinContent(iibin)) )
1149         #    if tmpsumth.GetBinContent(iibin) == 0:
1150         #       tmpsumth.SetBinError(iibin, 0 )
1151         #    else:
1152         #       tmpsumth.SetBinError(iibin, 1/math.sqrt(tmpsumth.GetBinContent(iibin)) )
1153 
1154         #tmpsumth.Draw("same E1")
1155 
1156 
1157         if printBanner:
1158             tex = TLatex(0.35,0.95,Banner)
1159             tex.SetNDC()
1160             tex.SetTextSize(0.05)
1161             tex.Draw()
1162 
1163         cv[thegraph[ikey].name].Update()
1164         save = thegraph[ikey].name
1165         cv[thegraph[ikey].name].Print(save + ".gif")#Print("test.png")
1166 
1167         # pause
1168         if option.wait:
1169             raw_input( 'Press ENTER to continue\n ' )
1170 
1171 
1172 #*********************************************************************
1173 
1174 
1175     if printCanvas:
1176 
1177         for ikey in theaddition:
1178             cv[theaddition[ikey].name].Print(theaddition[ikey].name + "." + printFormat)
1179         for ikey in thesuper:
1180             cv[thesuper[ikey].name].Print(thesuper[ikey].name + "." + printFormat)
1181         for ikey in thegraph:
1182             cv[thegraph[ikey].name].Print(thegraph[ikey].name + "notgood." + printFormat)
1183 
1184 
1185     #outputroot.Write()
1186     #outputroot.Close()
1187 
1188 #    if not option.wait:
1189     rep = ''
1190     while not rep in [ 'q', 'Q', '.q', 'qq' 'p']:
1191         rep = raw_input( '\nenter: ["q",".q" to quit] ["p" or "print" to print all canvas]: ' )
1192         if 0<len(rep):
1193             if rep=='quit': rep = 'q'
1194             if rep=='p' or rep=='print':
1195                 for ikey in theaddition:
1196                     cv[theaddition[ikey].name].Print(theaddition[ikey].name + "." + printFormat)
1197                 for ikey in thesuper:
1198                     cv[thesuper[ikey].name].Print(thesuper[ikey].name + "." + printFormat) 
1199                 for ikey in thegraph:
1200                     cv[thegraph[ikey].name].Print(thegraph[ikey].name + "." + printFormat)
1201 
1202