CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/Validation/RecoB/scripts/cuy.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #____________________________________________________________
00003 #
00004 #  cuy
00005 #
00006 # A very simple way to make plots with ROOT via an XML file
00007 #
00008 # Francisco Yumiceva
00009 # yumiceva@fnal.gov
00010 #
00011 # Fermilab, 2008
00012 #
00013 # imported from UserCode/Yumiceva/cuy
00014 #
00015 # modified by Adrien Caudron to create TGraphErrors for b-tag performance plots
00016 # UCLouvain, 2012 
00017 #_____________________________________________________________
00018 
00019 """
00020    cuy
00021 
00022     A very simple way to make plots with ROOT via an XML file.
00023 
00024    usage: %prog -x <XML configuration file>
00025    -b, --batch : run in batch mode without graphics.
00026    -c, --create  = CREATE: create XML configuration file from a ROOT file.
00027    -e, --example = EXAMPLE: generate an example xml file.
00028    -f, --flag    = FLAG: create a baneer
00029    -l, --list    = LIST: list of objects in the ROOT file. 
00030    -p, --prt     = PRT: print canvas in the format specified png, ps, eps, pdf, etc.
00031    -t, --tag     = TAG: tag name for XML configuration file.
00032    -v, --verbose : verbose output.
00033    -w, --wait : Pause script after plotting a new superposition of histograms.
00034    -x, --xml     = XML: xml configuration file.
00035    
00036    Francisco Yumiceva (yumiceva@fnal.gov)
00037    Fermilab 2008
00038    
00039 """
00040 
00041 
00042 import os, string, re, sys, math
00043 
00044 try:
00045     import ROOT
00046 except:
00047     print "\nCannot load PYROOT, make sure you have setup ROOT in the path"
00048     print "and pyroot library is also defined in the variable PYTHONPATH, try:\n"
00049     if (os.getenv("PYTHONPATH")):
00050         print " setenv PYTHONPATH ${PYTHONPATH}:$ROOTSYS/lib\n"
00051     else:
00052         print " setenv PYTHONPATH $ROOTSYS/lib\n"
00053     sys.exit()
00054 
00055 from ROOT import TFile
00056 from ROOT import TCanvas
00057 from ROOT import TLegend
00058 from ROOT import SetOwnership
00059 from ROOT import THStack
00060 from ROOT import TLatex
00061 from ROOT import TH1
00062 from ROOT import TH1F
00063 from ROOT import TGraphErrors
00064 from ROOT import TVectorD
00065 from ROOT import std
00066 
00067 from xml.sax import saxutils, make_parser, handler
00068 from xml.sax.handler import feature_namespaces
00069 
00070 import Inspector
00071 import Style
00072 
00073 #_______________OPTIONS________________
00074 import optparse
00075 
00076 USAGE = re.compile(r'(?s)\s*usage: (.*?)(\n[ \t]*\n|$)')
00077 
00078 def nonzero(self): # will become the nonzero method of optparse.Values
00079     "True if options were given"
00080     for v in self.__dict__.itervalues():
00081         if v is not None: return True
00082     return False
00083 
00084 optparse.Values.__nonzero__ = nonzero # dynamically fix optparse.Values
00085 
00086 class ParsingError(Exception): pass
00087 
00088 optionstring=""
00089 
00090 def exit(msg=""):
00091     raise SystemExit(msg or optionstring.replace("%prog",sys.argv[0]))
00092 
00093 def parse(docstring, arglist=None):
00094     global optionstring
00095     optionstring = docstring
00096     match = USAGE.search(optionstring)
00097     if not match: raise ParsingError("Cannot find the option string")
00098     optlines = match.group(1).splitlines()
00099     try:
00100         p = optparse.OptionParser(optlines[0])
00101         for line in optlines[1:]:
00102             opt, help=line.split(':')[:2]
00103             short,long=opt.split(',')[:2]
00104             if '=' in opt:
00105                 action='store'
00106                 long=long.split('=')[0]
00107             else:
00108                 action='store_true'
00109             p.add_option(short.strip(),long.strip(),
00110                          action = action, help = help.strip())
00111     except (IndexError,ValueError):
00112         raise ParsingError("Cannot parse the option string correctly")
00113     return p.parse_args(arglist)
00114 
00115 #______________________________________________________________________
00116 
00117 class ValElement:
00118     def __init__(self):
00119         self.type = ""
00120         self.filename = ""
00121         self.release = ""
00122         self.histos = {}
00123         self.TH1s = {}
00124         self.weight = None
00125 
00126 class divideElement:
00127     def __init__(self):
00128         self.name = ""
00129         self.numerator = None
00130         self.denominator = None
00131 
00132 class plotElement:
00133     def __init__(self):
00134         self.name = ""
00135         self.title = ""
00136         self.color = ""
00137 
00138 class additionElement:
00139     def __init__(self):
00140         self.name = ""
00141         self.title = ""
00142         self.SetLogy = ""
00143         self.SetGrid = ""
00144         self.histos = []
00145         self.weight = []
00146         
00147 class superimposeElement:
00148     def __init__(self):
00149         self.name = ""
00150         self.title = ""
00151         self.SetLogy = ""
00152         self.SetGrid = ""
00153         self.histos = []
00154         self.color = []
00155         self.marker = []
00156         self.legend = []
00157         self.weight = []
00158         #self.flavour = []
00159 #**********************************
00160 class graphElement:
00161     def __init__(self):
00162         self.name = ""
00163         self.title = ""
00164         self.SetLogy = ""
00165         self.SetGrid = ""
00166         self.histos = []
00167         self.color = []
00168         self.marker = []
00169         self.legend = []
00170         self.weight = []
00171         self.flavour = []
00172 #**********************************
00173 
00174 class FindIssue(handler.ContentHandler):
00175     def __init__(self):
00176         self.data = {}
00177         self.divide = {}
00178         self.addition = {}
00179         self.superimpose = {}
00180         self.graph = {}
00181         self.tmpaddname = ""
00182         self.plot = {}
00183         self.size = 0
00184         self.atype = ""
00185         self.tmpsupername = ""
00186         self.tmpgraphname = ""
00187 
00188     def startElement(self, name, attrs):
00189         if name == 'validation':
00190             self.size = self.size + 1
00191             self.atype = attrs.get('type',None)
00192             self.data[self.atype] = ValElement()
00193             self.data[self.atype].type = attrs.get('type',None)
00194             self.data[self.atype].filename = attrs.get('file',None)
00195             self.data[self.atype].release = attrs.get('release',None)
00196             self.data[self.atype].weight = attrs.get('weight','')
00197         if name == 'TH1':
00198             self.data[self.atype].histos[attrs.get('name',None)] = attrs.get('source',None)
00199             #print attrs.get('name',None)
00200             #print attrs.get('source',None)
00201         if name == 'divide':
00202             aname = attrs.get('name',None)
00203             self.divide[aname] = divideElement()
00204             self.divide[aname].name = aname
00205             self.divide[aname].numerator = attrs.get('numerator',None)
00206             self.divide[aname].denominator = attrs.get('denominator',None)
00207             self.divide[aname].DivideOption = attrs.get('DivideOption',None)
00208             self.divide[aname].Option = attrs.get('Option',None)
00209         if name == 'addition':
00210             aname = attrs.get('name',None)
00211             self.addition[aname] = additionElement()
00212             self.tmpaddname = aname
00213             self.addition[aname].name = aname
00214             self.addition[aname].title = attrs.get('title',None)
00215             self.addition[aname].YTitle = attrs.get('YTitle',None)
00216             self.addition[aname].XTitle = attrs.get('XTitle',None)
00217             self.addition[aname].Option = attrs.get('Option',None)
00218             self.addition[aname].Weight = attrs.get('Wight',None)
00219             self.addition[aname].Normalize = attrs.get('Normalize',None)
00220             self.addition[aname].SetGrid = attrs.get('SetGrid',None)
00221         if name == 'additionItem':
00222             #print "in element: " + self.tmpsupername
00223             self.addition[self.tmpaddname].histos.append(attrs.get('name',None))
00224             self.addition[self.tmpaddname].weight.append(attrs.get('weight',None))
00225         if name == 'superimpose':
00226             aname = attrs.get('name',None)
00227             self.superimpose[aname] = superimposeElement()
00228             self.superimpose[aname].name = aname
00229             self.superimpose[aname].title = attrs.get('title',None)
00230             self.superimpose[aname].SetLogy = attrs.get('SetLogy',None)
00231             self.superimpose[aname].SetGrid = attrs.get('SetGrid',None)
00232             self.superimpose[aname].Normalize = attrs.get('Normalize',None)
00233             self.superimpose[aname].Stack     = attrs.get('Stack',None)
00234             self.superimpose[aname].YTitle = attrs.get('YTitle',None)
00235             self.superimpose[aname].XTitle = attrs.get('XTitle',None)
00236             self.superimpose[aname].projection = attrs.get('Projection',None)
00237             self.superimpose[aname].bin = attrs.get('bin',None)
00238             self.superimpose[aname].profile = attrs.get('Profile',None)
00239             self.superimpose[aname].Fill = attrs.get('Fill',None)
00240             self.superimpose[aname].Option = attrs.get('Option',None)
00241             self.superimpose[aname].Weight = attrs.get('Weight',None)
00242             self.superimpose[aname].Maximum = attrs.get('Maximum',None)
00243             self.superimpose[aname].Minimum = attrs.get('Minimum',None)
00244             self.superimpose[aname].Labels = attrs.get('Labels',None)
00245             self.superimpose[aname].Rebin = attrs.get('Rebin',None)
00246             self.tmpsupername = aname
00247         if name == 'graph':
00248             aname = attrs.get('name',None)
00249             self.graph[aname] = graphElement()
00250             self.graph[aname].name = aname
00251             self.graph[aname].title = attrs.get('title',None)
00252             self.graph[aname].SetLogy = attrs.get('SetLogy',None)
00253             self.graph[aname].SetGrid = attrs.get('SetGrid',None)
00254             self.graph[aname].Normalize = attrs.get('Normalize',None)
00255             self.graph[aname].Stack     = attrs.get('Stack',None)
00256             self.graph[aname].YTitle = attrs.get('YTitle',None)
00257             self.graph[aname].XTitle = attrs.get('XTitle',None)
00258             self.graph[aname].projection = attrs.get('Projection',None)
00259             self.graph[aname].bin = attrs.get('bin',None)
00260             self.graph[aname].profile = attrs.get('Profile',None)
00261             self.graph[aname].Fill = attrs.get('Fill',None)
00262             self.graph[aname].Option = attrs.get('Option',None)
00263             self.graph[aname].Weight = attrs.get('Weight',None)
00264             self.graph[aname].Maximum = attrs.get('Maximum',None)
00265             self.graph[aname].Minimum = attrs.get('Minimum',None)
00266             self.graph[aname].Labels = attrs.get('Labels',None)
00267             self.tmpgraphname = aname
00268         if name == 'superimposeItem':
00269             #print "in element: " + self.tmpsupername
00270             self.superimpose[self.tmpsupername].histos.append(attrs.get('name',None))
00271             self.superimpose[self.tmpsupername].color.append(attrs.get('color',None))
00272             self.superimpose[self.tmpsupername].marker.append(attrs.get('MarkerStyle',None))
00273             self.superimpose[self.tmpsupername].legend.append(attrs.get('legend',None))
00274             #self.superimpose[self.tmpsupername].flavour.append(attrs.get('flavour',None))
00275             #self.superimpose[self.tmpsupername].weight.append(attrs.get('weight',None))
00276         if name == 'graphItem':
00277             #print "in element: " + self.tmpsupername
00278             self.graph[self.tmpgraphname].histos.append(attrs.get('name',None))
00279             self.graph[self.tmpgraphname].color.append(attrs.get('color',None))
00280             self.graph[self.tmpgraphname].marker.append(attrs.get('MarkerStyle',None))
00281             self.graph[self.tmpgraphname].legend.append(attrs.get('legend',None))
00282             self.graph[self.tmpgraphname].flavour.append(attrs.get('flavour',None))
00283             #self.se[self.tmpsupername].weight.append(attrs.get('weight',None))
00284 
00285 
00286 
00287 if __name__ == '__main__':
00288 
00289 
00290 
00291     # style
00292     thestyle = Style.Style()
00293     thestyle.SetStyle()
00294 
00295     printCanvas = False
00296     printFormat = "png"
00297     printBanner = False
00298     Banner = "CMS Preliminary"
00299     verbose = False
00300 
00301     # check options
00302     option,args = parse(__doc__)
00303     if not args and not option: exit()
00304 
00305     if option.batch:
00306         ROOT.gROOT.SetBatch()
00307 
00308     if option.verbose:
00309         verbose = True
00310 
00311     if option.list:
00312         ins = Inspector.Inspector()
00313         ins.Verbose(True)
00314         ins.createXML(False)
00315         ins.SetFilename(option.list)
00316         ins.GetListObjects()
00317         sys.exit()
00318 
00319     if option.create:
00320         createXML = Inspector.Inspector()
00321         createXML.Verbose(False)
00322         createXML.createXML(True)
00323         if option.tag:
00324             createXML.SetTag(option.tag)
00325         createXML.SetFilename(option.create)
00326         createXML.GetListObjects()
00327         sys.exit()
00328 
00329     if not option.xml: exit()
00330     if option.prt: 
00331         printCanvas = True
00332         printFormat = option.prt
00333 
00334     if option.flag:
00335         printBanner = True
00336         Banner = option.flag
00337 
00338     # check xml file
00339     try:
00340         xmlfile = open(option.xml)
00341         xmlfile.close()
00342     except:
00343         print " ERROR: xml file \"" + option.xml + "\" does not exist"
00344         sys.exit()
00345     
00346     # Create a parser
00347     parser = make_parser()
00348 
00349     # Tell the parser we are not interested in XML namespaces
00350     parser.setFeature(feature_namespaces, 0)
00351 
00352     # Create the handler
00353     dh = FindIssue()
00354 
00355     # Tell the parser to use our handler
00356     parser.setContentHandler(dh)
00357 
00358     # Parse the input
00359     parser.parse(option.xml)
00360 
00361     # list of canvas
00362     cv = {}
00363     afilelist = {}
00364     stacklist = {}
00365 
00366     # root output file
00367     outputroot = TFile("cuy.root","RECREATE")
00368 
00369     # new histograms
00370     newTH1list = []
00371 
00372     # extract histograms
00373     thedata = dh.data
00374 
00375     firstFilename = ''
00376 
00377     for ikey in thedata:
00378         if verbose : print "= Processing set called: " + ikey
00379         afilename = thedata[ikey].filename
00380         if firstFilename == '':
00381             firstFilename = afilename
00382         arelease = ""
00383         if thedata[ikey].release != None:
00384             arelease = thedata[ikey].release
00385         if verbose : print "== filename: " + afilename
00386         if verbose : print "== release:  " + arelease
00387         if verbose : print "== weight:   " + thedata[ikey].weight
00388         thehistos = thedata[ikey].histos
00389         afilelist[afilename] = TFile(afilename)
00390         if verbose : print "== get histograms: "
00391         histonamekeys = thehistos.keys()
00392         for ihname in histonamekeys:
00393             if verbose : print "=== Histogram name: \""+ ihname + "\" source: \""+thehistos[ihname]+"\""
00394             thedata[ikey].TH1s[ihname] = ROOT.gDirectory.Get(thehistos[ihname])
00395             #SetOwnership(thedata[ikey].TH1s[ihname], 0)
00396             # check if file exists
00397             print thedata[ikey].TH1s[ihname].GetName()
00398             
00399 
00400     # plot superimpose histograms
00401     #afilelist['../outputLayer2_ttbarmuonic_all.root'].cd()
00402     afilelist[firstFilename].cd()
00403     #print thedata['ttbar'].TH1s['gen_eta'].GetEntries()
00404 
00405 
00406     theaddition = dh.addition
00407     if verbose : print "= Create addition histograms:"
00408     
00409     for ikey in theaddition:
00410         if verbose : print "== plot name: \""+theaddition[ikey].name+"\" title: \""+theaddition[ikey].title+"\""
00411         listname = theaddition[ikey].histos
00412         listweight = theaddition[ikey].weight
00413 
00414         #create canvas
00415         cv[theaddition[ikey].name] = TCanvas(theaddition[ikey].name,theaddition[ikey].name,700,700)
00416 
00417         isFirst = True
00418         ihnameIt = 0
00419         for ihname in listname:
00420             aweight = 1
00421             if listweight[ihnameIt]:
00422             #if thedata[jkey].weight != None and theaddition[ikey].Weight == "true":
00423                 aweight = float(listweight[ihnameIt])
00424                 #aweight = float(thedata[jkey].weight)
00425             for jkey in thedata:
00426                 tmpkeys = thedata[jkey].histos.keys()
00427                 for tmpname in tmpkeys:
00428                     if tmpname == ihname:
00429                         ath = thedata[jkey].TH1s[tmpname]
00430                         if ath is None:
00431                             print "ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename
00432                             exit(0)
00433                         if verbose : print "=== add histogram: "+ath.GetName() + " from " + thedata[jkey].filename + " mean = " + "%.2f" % round(ath.GetMean(),2) + " weight= " + str(aweight)
00434                         #ath.Print("all")
00435                         if isFirst:
00436                             newth = ath.Clone(theaddition[ikey].name)
00437                             newth.Sumw2()
00438                             if theaddition[ikey].Normalize == "true":
00439                                 newth.Scale(1/newth.Integral())
00440                             newth.Scale(aweight)
00441                             isFirst = False
00442                         else:
00443                             atmpth = ath.Clone()
00444                             atmpth.Sumw2()
00445                             if theaddition[ikey].Normalize == "true":
00446                                 atmpth.Scale(1/atmpth.Integral())
00447                             atmpth.Scale(aweight)
00448                             newth.Add( atmpth )
00449             ihnameIt = ihnameIt + 1
00450 
00451         if theaddition[ikey].XTitle != None:
00452             newth.SetXTitle(theaddition[ikey].XTitle)
00453         if theaddition[ikey].YTitle != None:
00454             newth.SetYTitle(theaddition[ikey].YTitle)
00455 
00456         if theaddition[ikey].Option:
00457             newth.Draw(theaddition[ikey].Option)
00458         else:
00459             newth.Draw()
00460 
00461         if theaddition[ikey].SetGrid == "true":
00462             cv[theaddition[ikey].name].SetGrid()
00463         
00464         cv[theaddition[ikey].name].Update()
00465 
00466         # add new histogram to the list
00467         newth.SetName(theaddition[ikey].name)
00468         newTH1list.append(newth.GetName())
00469         thedata[newth.GetName()] = ValElement()
00470         thedata[newth.GetName()].TH1s[newth.GetName()] = newth
00471         thedata[newth.GetName()].histos[newth.GetName()] = newth.GetName()
00472 
00473         # write new histograms to file
00474         outputroot.cd()
00475         newth.Write()
00476         
00477     
00478     if verbose : print "= Create ratio histograms:"
00479     
00480     thedivition = dh.divide
00481     for ikey in thedivition:
00482         if verbose : print "== plot name: \""+thedivition[ikey].name+"\" title: \""+"\""
00483         numerator = thedivition[ikey].numerator
00484         denominator = thedivition[ikey].denominator
00485 
00486         #create canvas
00487         cv[thedivition[ikey].name] = TCanvas(thedivition[ikey].name,thedivition[ikey].name,700,700)
00488 
00489         for jkey in thedata:
00490             tmpkeys = thedata[jkey].histos.keys()
00491             for tmpname in tmpkeys:
00492                 if tmpname == numerator:
00493                     numeratorth = thedata[jkey].TH1s[tmpname]
00494                     if numeratorth is None:
00495                         print "ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename
00496                         exit(0)
00497                         #print "=== numerator histogram: "+numeratorth.GetName() + " from " + thedata[jkey].filename + " mean = " + "%.2f" % round(numeratorth.GetMean(),2) + " weight= " + str(aweight)
00498 
00499                 if tmpname == denominator:
00500                     denominatorth = thedata[jkey].TH1s[tmpname]
00501                     if denominatorth is None:
00502                         print "ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename
00503                         exit(0)
00504                         #print "=== denominator histogram: "+denominatorth.GetName() + " from " + thedata[jkey].filename + " mean = " + "%.2f" % round(denominatorth.GetMean(),2) + " weight= " + str(aweight)
00505 
00506 
00507         
00508         numeratorth.Sumw2()
00509         denominatorth.Sumw2()
00510         newth = numeratorth.Clone()
00511         newth.Clear()
00512         if thedivition[ikey].DivideOption is None:
00513             newth.Divide(numeratorth,denominatorth)
00514         else:
00515             newth.Divide(numeratorth,denominatorth,1.,1.,thedivition[ikey].DivideOption)
00516 #       if theaddition[ikey].XTitle != None:
00517 #           newth.SetXTitle(theaddition[ikey].XTitle)
00518 #       if theaddition[ikey].YTitle != None:
00519 #           newth.SetYTitle(theaddition[ikey].YTitle)
00520 
00521         if thedivition[ikey].Option:
00522             newth.Draw(thedivition[ikey].Option)
00523         else:
00524             newth.Draw()
00525 
00526         cv[thedivition[ikey].name].Update()
00527         
00528         
00529         # pause
00530         if option.wait:
00531             raw_input( 'Press ENTER to continue\n ' )
00532 
00533         # add new histogram to the list
00534         newth.SetName(thedivition[ikey].name)
00535         newTH1list.append(newth.GetName())
00536         thedata[newth.GetName()] = ValElement()
00537         thedata[newth.GetName()].TH1s[newth.GetName()] = newth
00538         thedata[newth.GetName()].histos[newth.GetName()] = newth.GetName()
00539         
00540         # write new histograms to file
00541         outputroot.cd()
00542         newth.Write()
00543 
00544 
00545     thesuper = dh.superimpose
00546     if verbose : print "= Create superimpose histograms:"
00547     for ikey in thesuper:
00548         if verbose : print "== plot name: \""+thesuper[ikey].name+"\" title: \""+thesuper[ikey].title+"\""
00549         listname = thesuper[ikey].histos
00550         listcolor = thesuper[ikey].color
00551         listmarker = thesuper[ikey].marker
00552         listlegend = thesuper[ikey].legend
00553         #listweight = thesuper[ikey].weight
00554         dolegend = False
00555         for il in listlegend:
00556             if il==None: dolegend = False
00557         if verbose : print "dolegend = " +str(dolegend)
00558         doNormalize = False
00559         doRebin=thesuper[ikey].Rebin
00560         if doRebin is not None :
00561             doRebin=int(doRebin)
00562             if verbose : print "Rebin is ", doRebin
00563         if thesuper[ikey].Normalize == "true":
00564             doNormalize = True
00565             if verbose : print "normalize = " +str(doNormalize)
00566         projectAxis = "no"
00567         projectBin = -1 #all
00568         if thesuper[ikey].projection == "x": projectAxis = "x"
00569         if thesuper[ikey].projection == "y": projectAxis = "y"
00570         if thesuper[ikey].bin != None: projectBin = thesuper[ikey].bin
00571         profileAxis = "no"
00572         if thesuper[ikey].profile == "x": profileAxis = "x"
00573         if thesuper[ikey].profile == "y": profileAxis = "y"
00574         doFill = False
00575         if thesuper[ikey].Fill == "true": doFill = True
00576         if verbose : print "fill option:"+ doFill
00577         #create canvas
00578         cv[thesuper[ikey].name] = TCanvas(thesuper[ikey].name,thesuper[ikey].title,700,700)
00579         #legend
00580         aleg = TLegend(0.6,0.4,0.8,0.6)
00581         SetOwnership( aleg, 0 ) 
00582         aleg.SetMargin(0.12)
00583         aleg.SetTextSize(0.035)
00584         aleg.SetFillColor(10)
00585         aleg.SetBorderSize(0)
00586 
00587         isFirst = 1
00588         ii = 0
00589 
00590         stacklist[thesuper[ikey].name] = THStack("astack"+thesuper[ikey].name,thesuper[ikey].title)
00591         astack = stacklist[thesuper[ikey].name]
00592         for ihname in listname:
00593         
00594             for jkey in thedata:
00595                 tmpkeys = thedata[jkey].histos.keys()
00596                 
00597                 for tmpname in tmpkeys:
00598                 
00599                     if tmpname == ihname:
00600                         ath = thedata[jkey].TH1s[tmpname]
00601                         if ath is None:
00602                             print "ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename
00603                             exit(0)
00604                         if verbose : print "=== superimpose histogram: "+ath.GetName() + " mean = " + "%.2f" % round(ath.GetMean(),2)
00605                         # project 2D histogram if requested
00606                         if projectAxis == "x":
00607                             if projectBin == -1:
00608                                 newthpx = ath.ProjectionX(ath.GetName()+"_px",0,-1,"e")
00609                             else:
00610                                 newthpx = ath.ProjectionX(ath.GetName()+"_px",int(projectBin),int(projectBin),"e")
00611                             newth = newthpx.Clone()
00612                         if projectAxis == "y":
00613                             if projectBin == -1:
00614                                 newthpy = ath.ProjectionY(ath.GetName()+"_py",0,-1,"e")
00615                             else:
00616                                 newthpx = ath.ProjectionY(ath.GetName()+"_py",int(projectBin),int(projectBin),"e")
00617                             newth = newthpy.Clone()
00618                         if profileAxis == "x":
00619                             newthpx = ath.ProfileX(ath.GetName()+"_px",0,-1,"e")
00620                             newth = newthpx.Clone()
00621                         if profileAxis == "y":
00622                             newthpy = ath.ProfileY(ath.GetName()+"_py",0,-1,"e")
00623                             newth = newthpy.Clone()
00624 
00625                         # get weight
00626                         aweight = 1
00627                         if thedata[jkey].weight != None and thesuper[ikey].Weight=="true":
00628                             aweight = float( thedata[jkey].weight )
00629                         if verbose: print " with weight = " + str(aweight)
00630                         #if listweight[ii]:
00631                          #   aweight = float( listweight[ii] )
00632 
00633                         # clone original histogram
00634                         if projectAxis == "no" and profileAxis == "no" :newth = ath.Clone()
00635 
00636                         if doRebin is not None and doRebin>0 :
00637                             newth.Rebin(doRebin)
00638 
00639                         newth.Sumw2()
00640                         newth.Scale(aweight)
00641                         
00642                         # check if we have color
00643                         if not listcolor[ii]:
00644                             listcolor[ii] = 1
00645                         
00646                         newth.SetLineColor(int(listcolor[ii]))
00647                         newth.SetMarkerColor(int(listcolor[ii]))
00648                         
00649                         if doFill: newth.SetFillColor(int(listcolor[ii]))
00650 
00651                         if listmarker[ii] != None:
00652                             newth.SetMarkerStyle(int(listmarker[ii]))
00653                         # normalize
00654                         if doNormalize:
00655                             newth.Scale(1./newth.Integral())
00656                         #print "   "+listlegend[ii]
00657                         
00658                         if thesuper[ikey].Labels != None:
00659                             thelabels = thesuper[ikey].Labels.split(',')
00660                             ib = 1
00661                             #print thelabels
00662 
00663                             for ilabel in thelabels:
00664                                 newth.GetXaxis().SetBinLabel(ib,ilabel)
00665                                 #if ib==1:
00666                                     #newth.GetXaxis().SetBinLabel(ib,"")
00667                                 #newth.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
00668                                 ib += 1
00669                             #if aweight==0.0081:
00670                         #       newth.SetBinContent(1, newth.GetBinContent(1) / 0.28756)
00671                          #   if aweight==0.0883:
00672                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.01953)
00673                             #if aweight==0.0731:
00674                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.0367)
00675                             #if aweight==0.4003:
00676                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.5683)
00677                             #if aweight==0.003:
00678                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.21173)
00679                             #if aweight==0.0027:
00680                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
00681                             #if aweight==0.0034:
00682                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
00683 
00684 
00685                         # stack histograms
00686                         if doFill:
00687                             if thesuper[ikey].XTitle != None:
00688                                 newth.SetXTitle("")
00689                             astack.Add(newth,"HIST")
00690                         elif thesuper[ikey].Option:
00691                             astack.Add(newth,thesuper[ikey].Option)
00692                         else:
00693                             #newth.Fit("landau")
00694                             astack.Add(newth)
00695                             
00696                         astack.SetTitle(thesuper[ikey].title)
00697                         
00698                         if isFirst==1:
00699                             newth.GetPainter().PaintStat(ROOT.gStyle.GetOptStat(),0);
00700                             isFirst=0
00701                             tmpsumth = newth.Clone()
00702                         else:
00703                             tmpsumth.Add(newth)
00704                         #    newth.SetTitle(thesuper[ikey].title)
00705                         #    if thesuper[ikey].YTitle != None:
00706                         #       newth.SetYTitle(thesuper[ikey].YTitle)
00707                         #    newth.Draw()
00708                         #    isFirst=0
00709                         #else:
00710                         #    newth.Draw("same")
00711                         if dolegend and doFill: 
00712                             aleg.AddEntry(newth,listlegend[ii],"F")
00713                         elif dolegend:
00714                             aleg.AddEntry(newth,listlegend[ii],"P")
00715                         
00716                         newth.SetName(tmpname)
00717                         outputroot.cd()
00718                         newth.Write()
00719             ii = ii + 1
00720 
00721         
00722         if thesuper[ikey].Maximum != None:
00723             astack.SetMaximum( float(thesuper[ikey].Maximum) )
00724         if thesuper[ikey].Minimum != None:
00725             astack.SetMinimum( float(thesuper[ikey].Minimum) )
00726         if thesuper[ikey].Stack == "true":
00727             astack.Draw()
00728         if thesuper[ikey].Stack == "false" or thesuper[ikey].Stack == None:
00729             astack.Draw()
00730             astack.Draw("nostack")
00731         if thesuper[ikey].XTitle != None:
00732             astack.GetHistogram().SetXTitle(thesuper[ikey].XTitle)
00733         if thesuper[ikey].YTitle != None:
00734             astack.GetHistogram().SetYTitle(thesuper[ikey].YTitle)
00735         if doFill:
00736             astack.Draw("sameaxis")
00737 
00738         
00739         #thelabels = []
00740         #if thesuper[ikey].Labels != None:
00741         #    thelabels = thesuper[ikey].Labels.split(',')
00742         #    ib = 1
00743         #    print thelabels
00744 
00745          #   for ilabel in thelabels:
00746         #       astack.GetXaxis().SetBinLabel(ib,ilabel)
00747                 #astack.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
00748                 #ib += 1
00749         #    astack.Draw()
00750         #    astack.Draw("sameaxis")
00751 
00752         if dolegend: 
00753             aleg.Draw()
00754         if thesuper[ikey].SetLogy == "true":
00755             cv[thesuper[ikey].name].SetLogy()
00756         if thesuper[ikey].SetGrid == "true":
00757             cv[thesuper[ikey].name].SetGrid()
00758         
00759         # test smearing
00760         #rn = ROOT.TRandom(12345)
00761         #for iibin in range(0,tmpsumth.GetNbinsX()):
00762         #    tmpsumth.SetBinContent(iibin, rn.Poisson(tmpsumth.GetBinContent(iibin)) )
00763         #    if tmpsumth.GetBinContent(iibin) == 0:
00764         #       tmpsumth.SetBinError(iibin, 0 )
00765         #    else:
00766         #       tmpsumth.SetBinError(iibin, 1/math.sqrt(tmpsumth.GetBinContent(iibin)) )
00767                         
00768         #tmpsumth.Draw("same E1")
00769 
00770         
00771         if printBanner:
00772             tex = TLatex(0.35,0.95,Banner)
00773             tex.SetNDC()
00774             tex.SetTextSize(0.05)
00775             tex.Draw()
00776         
00777         cv[thesuper[ikey].name].Update()
00778         #cv[thesuper[ikey].name].Print("test.png")
00779         
00780         # pause
00781         if option.wait:
00782             raw_input( 'Press ENTER to continue\n ' )
00783 
00784 
00785 
00786 #**********************************************************************
00787 
00788 
00789     thegraph = dh.graph
00790     if verbose : print "= Create graph histograms:"
00791     for ikey in thegraph:
00792         if verbose : print "== plot name: \""+thegraph[ikey].name+"\" title: \""+thegraph[ikey].title+"\""
00793         listname = thegraph[ikey].histos
00794         listcolor = thegraph[ikey].color
00795         listmarker = thegraph[ikey].marker
00796         listlegend = thegraph[ikey].legend
00797         listflavour = thegraph[ikey].flavour
00798         #listweight = thegraph[ikey].weight
00799         dolegend = False
00800         for il in listlegend:
00801             if il==None: dolegend = False
00802         if verbose : print "dolegend = " +str(dolegend)
00803         doNormalize = False
00804         if thegraph[ikey].Normalize == "true":
00805             doNormalize = True
00806             if verbose : print "normalize = " +str(doNormalize)
00807         projectAxis = "no"
00808         projectBin = -1 #all
00809         if thegraph[ikey].projection == "x": projectAxis = "x"
00810         if thegraph[ikey].projection == "y": projectAxis = "y"
00811         if thegraph[ikey].bin != None: projectBin = thegraph[ikey].bin
00812         profileAxis = "no"
00813         if thegraph[ikey].profile == "x": profileAxis = "x"
00814         if thegraph[ikey].profile == "y": profileAxis = "y"
00815         doFill = False
00816         if thegraph[ikey].Fill == "true": doFill = True
00817         if verbose : print "fill option:"+ doFill
00818         #create canvas
00819         cv[thegraph[ikey].name] = TCanvas(thegraph[ikey].name,thegraph[ikey].title,700,700)
00820         #legend
00821         aleg = TLegend(0.6,0.4,0.8,0.6)
00822         SetOwnership( aleg, 0 )
00823         aleg.SetMargin(0.12)
00824         aleg.SetTextSize(0.035)
00825         aleg.SetFillColor(10)
00826         aleg.SetBorderSize(0)
00827 
00828         isFirst = 1
00829         ii = 0
00830 
00831         stacklist[thegraph[ikey].name] = THStack("astack"+thegraph[ikey].name,thegraph[ikey].title)
00832         astack = stacklist[thegraph[ikey].name]
00833         xVal_val = TVectorD()
00834         yVal_val = TVectorD()
00835         yBin_val = std.vector(int)()
00836         xErr_val = TVectorD()
00837         yErr_val = TVectorD()
00838         zVal_val = TVectorD()
00839         zErr_val = TVectorD()
00840         nVal_val = 0
00841         
00842         xVal_ref = TVectorD()
00843         yVal_ref = TVectorD()
00844         yBin_ref = std.vector(int)()
00845         xErr_ref = TVectorD()
00846         yErr_ref = TVectorD()
00847         zVal_ref = TVectorD()
00848         zErr_ref = TVectorD()
00849         nVal_ref = 0
00850 
00851         RangeMax = 0.005
00852         RangeMin = 0.9
00853         
00854         for ihname in listname:
00855              
00856             for jkey in thedata:
00857                 tmpkeys = thedata[jkey].histos.keys()
00858                         
00859                 for tmpname in tmpkeys:
00860                     
00861                     if tmpname == ihname:
00862                         
00863                         ath = thedata[jkey].TH1s[tmpname]
00864                         if ath is None:
00865                             print "ERROR: histogram name \""+tmpname+"\" does not exist in file "+thedata[jkey].filename
00866                             exit(0)
00867                         if verbose : print "=== graph histogram: "+ath.GetName() + " mean = " + "%.2f" % round(ath.GetMean(),2)
00868                         #print listflavour[ii]
00869                         if listflavour[ii] == "5":
00870                             #print "iiiiiiiiiii" 
00871                             nBinB = 200 #ath.GetNbinsX()
00872                             BinWidth = (0.01+ath.GetMaximum())/nBinB
00873                             BMid = 0.005+BinWidth/2
00874                             Err = BinWidth
00875                             for iBinB in range(1,nBinB+1):
00876                                #BinWidth = (0.01+ath.GetMaximum())/200 #ath.GetBinWidth(iBinB)
00877                                BMid = BMid+Err #BinWidth #ath.GetBinCenter(iBinB)
00878                                #newh = TH1(ath)
00879                                nAthBin = ath.GetNbinsX()-2
00880                                #newh = TH1(ath)
00881                                maxInHisto = ath.GetMaximum()
00882                                minInHisto = ath.GetMinimum()
00883                                #print minInHisto
00884                                yClosestInit = 0
00885                                iBinClosestInit = 0
00886                                if BMid <= maxInHisto : yClosestInit = maxInHisto + 1
00887                                else : yClosestInit = minInHisto - 1.0
00888                                iBinClosest = iBinClosestInit
00889                                yClosest    = yClosestInit
00890                                for iAthBin in range(1,nAthBin+1):
00891                                    yBin = ath.GetBinContent(iAthBin)
00892                                    dif1 = BMid-yBin
00893                                    if dif1 < 0 : dif1 = yBin-BMid
00894                                    dif2 = yClosest-BMid
00895                                    if dif2 < 0 : dif2 = BMid-yClosest
00896                                    if dif1 < dif2:
00897                                       yClosest = yBin
00898                                       iBinClosest = iAthBin
00899                                min = BMid-Err/2 
00900                                max = BMid+Err/2
00901                                #print iBinClosest
00902                                if yClosest < min or  yClosest > max:
00903                                        iBinClosest = 0
00904                                        #print "iji"
00905                                if iBinClosest > 0 and listmarker[ii] == "8":
00906                                    #print "hhhhhhhhhhhhhhhh"
00907                                    nVal_ref = nVal_ref+1
00908                                    xVal_ref.ResizeTo(nVal_ref)
00909                                    #yBin_ref.ResizeTo(nVal_ref)
00910                                    xErr_ref.ResizeTo(nVal_ref)
00911                                    xVal_ref[nVal_ref-1] = BMid
00912                                    yBin_ref.push_back(iBinClosest)
00913                                    xErr_ref[nVal_ref-1] = ath.GetBinError ( iBinClosest )
00914                                    Err = xErr_ref[nVal_ref-1]
00915                                    if Err < BinWidth : Err = BinWidth
00916                                elif iBinClosest > 0:
00917                                    nVal_val = nVal_val+1
00918                                    xVal_val.ResizeTo(nVal_val)
00919                                    #yBin_val.ResizeTo(nVal_val)
00920                                    xErr_val.ResizeTo(nVal_val)
00921                                    xVal_val[nVal_val-1] = BMid
00922                                    yBin_val.push_back(iBinClosest)
00923                                    xErr_val[nVal_val-1] = ath.GetBinError ( iBinClosest )
00924                                    Err = xErr_val[nVal_val-1]
00925                                    if Err < BinWidth : Err = BinWidth
00926                         elif listflavour[ii] == "4" and listmarker[ii] == "8":
00927                             yVal_ref.ResizeTo(nVal_ref)
00928                             yErr_ref.ResizeTo(nVal_ref)
00929                             for iVal in range(0,nVal_ref):                                
00930                                 yVal_ref[iVal] = ath.GetBinContent (yBin_ref[iVal])
00931                                 if yVal_ref[iVal] > RangeMax : RangeMax = yVal_ref[iVal]
00932                                 yErr_ref[iVal] = ath.GetBinError (yBin_ref[iVal])
00933                         elif listflavour[ii] == "4":
00934                             yVal_val.ResizeTo(nVal_val)
00935                             yErr_val.ResizeTo(nVal_val)
00936                             for iVal in range(0,nVal_val):                                
00937                                 yVal_val[iVal] = ath.GetBinContent (yBin_val[iVal])
00938                                 yErr_val[iVal] = ath.GetBinError (yBin_val[iVal])
00939                         elif listmarker[ii] == "8":
00940                             zVal_ref.ResizeTo(nVal_ref)
00941                             zErr_ref.ResizeTo(nVal_ref)
00942                             for iVal in range(0,nVal_ref):                                
00943                                 zVal_ref[iVal] = ath.GetBinContent (yBin_ref[iVal])
00944                                 zErr_ref[iVal] = ath.GetBinError (yBin_ref[iVal])
00945                                 if zVal_ref[iVal] < RangeMin : RangeMin = zVal_ref[iVal]
00946                         else:
00947                             zVal_val.ResizeTo(nVal_val)
00948                             zErr_val.ResizeTo(nVal_val)
00949                             for iVal in range(0,nVal_val):
00950                                 zVal_val[iVal] = ath.GetBinContent (yBin_val[iVal])
00951                                 zErr_val[iVal] = ath.GetBinError (yBin_val[iVal])
00952             ii = ii + 1
00953 
00954         #print xVal_ref.GetNoElements()
00955         #print yVal_ref.GetNrows()
00956         #print xErr_ref.GetNrows()
00957         #print yErr_ref.GetNrows()
00958         
00959         #graphs = std.vector(TGraphErrors)()
00960         graphs = [TGraphErrors(xVal_ref,yVal_ref,xErr_ref,yErr_ref),
00961         TGraphErrors(xVal_ref,zVal_ref,xErr_ref,zErr_ref),
00962         TGraphErrors(xVal_val,yVal_val,xErr_val,yErr_val),
00963         TGraphErrors(xVal_val,zVal_val,xErr_val,zErr_val)]
00964         ii = 0
00965 
00966 
00967  
00968         for ii in range(0,4):
00969 
00970                         # project 2D histogram if requested
00971                         #if projectAxis == "x":
00972                         #    if projectBin == -1:
00973                         #       newthpx = ath.ProjectionX(ath.GetName()+"_px",0,-1,"e")
00974                         #    else:
00975                         #       newthpx = ath.ProjectionX(ath.GetName()+"_px",int(projectBin),int(projectBin),"e")
00976                         #    newth = newthpx.Clone()
00977                         #if projectAxis == "y":
00978                         #    if projectBin == -1:
00979                         #       newthpy = ath.ProjectionY(ath.GetName()+"_py",0,-1,"e")
00980                         #    else:
00981                         #       newthpx = ath.ProjectionY(ath.GetName()+"_py",int(projectBin),int(projectBin),"e")
00982                         #    newth = newthpy.Clone()
00983                         #if profileAxis == "x":
00984                         #    newthpx = ath.ProfileX(ath.GetName()+"_px",0,-1,"e")
00985                         #    newth = newthpx.Clone()
00986                         #if profileAxis == "y":
00987                         #    newthpy = ath.ProfileY(ath.GetName()+"_py",0,-1,"e")
00988                         #    newth = newthpy.Clone()
00989 
00990                         # get weight
00991                         aweight = 1
00992                         #if thedata[jkey].weight != None and thegraph[ikey].Weight=="true":
00993                         #    aweight = float( thedata[jkey].weight )
00994                         #if verbose: print " with weight = " + str(aweight)
00995                         #if listweight[ii]:
00996                          #   aweight = float( listweight[ii] )
00997 
00998                         # clone original histogram
00999                         #if projectAxis == "no" and profileAxis == "no" :newth = ath.Clone()
01000 
01001                         #newth.Sumw2()
01002                         #newth.Scale(aweight)
01003 
01004                         # check if we have color
01005                         #if not listcolor[ii]:
01006                         #    listcolor[ii] = 1
01007 
01008                         col = 2
01009                         mark = 22
01010                         if ii == 0 or ii == 2:
01011                                 col = 1
01012                         if ii == 0 or ii == 1:
01013                             mark = 8
01014                                 
01015                         graphs[ii].SetLineColor(col)
01016                         graphs[ii].SetMarkerStyle(mark)
01017                         graphs[ii].SetMarkerColor(col)
01018                         graphs[ii].SetTitle(thegraph[ikey].title)
01019                         #if doFill: newth.SetFillColor(int(listcolor[ii]))
01020 
01021                         #if listmarker[ii] != None:
01022                         #    newth.SetMarkerStyle(int(listmarker[ii]))
01023                         # normalize
01024                         #if doNormalize:
01025                         #    newth.Scale(1./newth.Integral())
01026                         #print "   "+listlegend[ii]
01027 
01028                         #if thegraph[ikey].Labels != None:
01029                         #    thelabels = thesuper[ikey].Labels.split(',')
01030                          #   ib = 1
01031                             #print thelabels
01032 
01033                          #   for ilabel in thelabels:
01034                          #       newth.GetXaxis().SetBinLabel(ib,ilabel)
01035                                 #if ib==1:
01036                                     #newth.GetXaxis().SetBinLabel(ib,"")
01037                                 #newth.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
01038                           #      ib += 1
01039                             #if aweight==0.0081:
01040                         #       newth.SetBinContent(1, newth.GetBinContent(1) / 0.28756)
01041                          #   if aweight==0.0883:
01042                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.01953)
01043                             #if aweight==0.0731:
01044                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.0367)
01045                             #if aweight==0.4003:
01046                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.5683)
01047                             #if aweight==0.003:
01048                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.21173)
01049                             #if aweight==0.0027:
01050                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
01051                             #if aweight==0.0034:
01052                                 #newth.SetBinContent(1, newth.GetBinContent(1) / 0.26394)
01053 
01054 
01055                         # stack histograms
01056                         #if doFill:
01057                          #   if thegraph[ikey].XTitle != None:
01058                         #        newth.SetXTitle("")
01059                         #    astack.Add(newth,"HIST")
01060                         #elif thegraph[ikey].Option:
01061                         #    astack.Add(newth,thegraph[ikey].Option)
01062                         #else:
01063                             #newth.Fit("landau")
01064                         #    astack.Add(newth)
01065 
01066                         #astack.SetTitle(thegraph[ikey].title)
01067 
01068                         if isFirst==1:
01069                             #graphs[ii].GetPainter().PaintStat(ROOT.gStyle.GetOptStat(),0);
01070                             isFirst=0
01071                             #tmpsumth = graphs[ii].Clone()
01072                         #else:
01073                         #    tmpsumth.Add(graphs[ii])
01074                         #    newth.SetTitle(thesuper[ikey].title)
01075                         #    if thesuper[ikey].YTitle != None:
01076                         #       newth.SetYTitle(thesuper[ikey].YTitle)
01077                         #    newth.Draw()
01078                         #    isFirst=0
01079                         #else:
01080                         #    newth.Draw("same")
01081                         #if dolegend and doFill:
01082                         #    aleg.AddEntry(newth,listlegend[ii],"F")
01083                         #elif dolegend:
01084                         #    aleg.AddEntry(newth,listlegend[ii],"P")
01085 
01086                         #graphs[ii].SetName(tmpname)
01087                         #if ii == 0 : graphs[ii].Draw()
01088                         #else : graphs[ii].Draw("same")
01089                         outputroot.cd()
01090                         graphs[ii].Write()
01091                         ii = ii + 1
01092 
01093 
01094         #if thegraph[ikey].Maximum != None:
01095         #    graphs[0].SetMaximum( float(thegraph[ikey].Maximum) )
01096         #if thegraph[ikey].Minimum != None:
01097         #    graphs[0].SetMinimum( float(thegraph[ikey].Minimum) )
01098         #if thegraph[ikey].Stack == "true":
01099         #    astack.Draw()
01100         #if thegraph[ikey].Stack == "false" or thegraph[ikey].Stack == None:
01101         #    astack.Draw()
01102         #    astack.Draw("nostack")
01103         if thegraph[ikey].XTitle != None:
01104             graphs[0].GetHistogram().SetXTitle(thegraph[ikey].XTitle)
01105         if thegraph[ikey].YTitle != None:
01106             graphs[0].GetHistogram().SetYTitle(thegraph[ikey].YTitle)
01107         #if doFill:
01108         #    astack.Draw("sameaxis")
01109         if RangeMax > 0.5 : RangeMax = 1.5
01110         if RangeMax < 0.5 : RangeMax = RangeMax + 0.05
01111         #RangeMax = 1.1
01112         RangeMin = RangeMin - 0.5*RangeMin
01113         #print RangeMax
01114         #print RangeMin
01115         if RangeMin < 0.00001 : RangeMin = 0.00005
01116         graphs[0].GetYaxis().SetRangeUser(RangeMin,RangeMax)
01117    
01118         #thelabels = []
01119         #if thesuper[ikey].Labels != None:
01120         #    thelabels = thesuper[ikey].Labels.split(',')
01121         #    ib = 1
01122         #    print thelabels
01123 
01124          #   for ilabel in thelabels:
01125         #       astack.GetXaxis().SetBinLabel(ib,ilabel)
01126                 #astack.GetHistogram().GetXaxis().SetBinLabel(ib,ilabel)
01127                 #ib += 1
01128         #    astack.Draw()
01129         #    astack.Draw("sameaxis")
01130 
01131         #h = TH1F()
01132         #h.Draw()
01133         graphs[0].Draw("AP")
01134         graphs[1].Draw("sameP")
01135         graphs[2].Draw("sameP")
01136         graphs[3].Draw("sameP")
01137         if dolegend:
01138             aleg.Draw()
01139         if thegraph[ikey].SetLogy == "true":
01140             cv[thegraph[ikey].name].SetLogy()
01141         if thegraph[ikey].SetGrid == "true":
01142             cv[thegraph[ikey].name].SetGrid()
01143 
01144         # test smearing
01145         #rn = ROOT.TRandom(12345)
01146         #for iibin in range(0,tmpsumth.GetNbinsX()):
01147         #    tmpsumth.SetBinContent(iibin, rn.Poisson(tmpsumth.GetBinContent(iibin)) )
01148         #    if tmpsumth.GetBinContent(iibin) == 0:
01149         #       tmpsumth.SetBinError(iibin, 0 )
01150         #    else:
01151         #       tmpsumth.SetBinError(iibin, 1/math.sqrt(tmpsumth.GetBinContent(iibin)) )
01152 
01153         #tmpsumth.Draw("same E1")
01154 
01155 
01156         if printBanner:
01157             tex = TLatex(0.35,0.95,Banner)
01158             tex.SetNDC()
01159             tex.SetTextSize(0.05)
01160             tex.Draw()
01161 
01162         cv[thegraph[ikey].name].Update()
01163         save = thegraph[ikey].name
01164         cv[thegraph[ikey].name].Print(save + ".gif")#Print("test.png")
01165 
01166         # pause
01167         if option.wait:
01168             raw_input( 'Press ENTER to continue\n ' )
01169 
01170 
01171 #*********************************************************************
01172 
01173     
01174     if printCanvas:
01175         
01176         for ikey in theaddition:
01177             cv[theaddition[ikey].name].Print(theaddition[ikey].name + "." + printFormat)
01178         for ikey in thesuper:
01179             cv[thesuper[ikey].name].Print(thesuper[ikey].name + "." + printFormat)
01180         for ikey in thegraph:
01181             cv[thegraph[ikey].name].Print(thegraph[ikey].name + "notgood." + printFormat)
01182         
01183     
01184     #outputroot.Write()
01185     #outputroot.Close()
01186 
01187 #    if not option.wait:
01188     rep = ''
01189     while not rep in [ 'q', 'Q', '.q', 'qq' 'p']:
01190         rep = raw_input( '\nenter: ["q",".q" to quit] ["p" or "print" to print all canvas]: ' )
01191         if 0<len(rep):
01192             if rep=='quit': rep = 'q'
01193             if rep=='p' or rep=='print':
01194                 for ikey in theaddition:
01195                     cv[theaddition[ikey].name].Print(theaddition[ikey].name + "." + printFormat)
01196                 for ikey in thesuper:
01197                     cv[thesuper[ikey].name].Print(thesuper[ikey].name + "." + printFormat) 
01198                 for ikey in thegraph:
01199                     cv[thegraph[ikey].name].Print(thegraph[ikey].name + "." + printFormat)
01200                                         
01201