Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:37

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