CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Alignment/MuonAlignmentAlgorithms/scripts/alignmentValidation.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 import re,os,sys,shutil
00004 import optparse
00005 
00006 from mutypes import *
00007 
00008 execfile("plotscripts.py")
00009 
00010 ROOT.gROOT.SetBatch(1);
00011 
00012 ######################################################
00013 
00014 ######################################################
00015 # To parse commandline args
00016 
00017 usage='%prog [options]\n'+\
00018   'This script dumps muon alignment validation plots '+\
00019   '(see https://twiki.cern.ch/twiki/bin/viewauth/CMS/SWGuideMuonAlignValidationPlots) '+\
00020   'in web-friendly png format into a predefined directory structure '+\
00021   'and also (to be implemented) does some quality checks for these plots.\n'+\
00022   'Script uses output of the first and last iterations of muon alignment runs '+\
00023   'that should be located in inputDir+i1 and inputDir+iN directories (see options descriptions). '+\
00024   'Each of these directories should contain\ni#prefix+"_plotting.root"\ni#prefix+".root"\ni#prefix+"_report.py"\n'+\
00025   'files, where # = 1 or N.\n'+\
00026   'Output will be located in outputDir, which must exist. Plots from the first and last iterations '+\
00027   'will be in outputDir+"iter1" and outputDir+"iterN" respectively, and plots relevant for all iterations will '+\
00028   'reside in outputDir+"common/".\n'+\
00029   'For a first run a --createDirSructure option must be present. If this option is present for subsequent runs '+\
00030   'with the same outputDir, all previous results in "iter1", "iterN" and and "common" would be deleted!\n'+\
00031   'If neither --dt or --csc is present, plots for both systems will be created.\n'+\
00032   'Options must include either -a or any of the following: --map, --segdiff, --fit, --median'
00033 
00034 parser=optparse.OptionParser(usage)
00035 
00036 parser.add_option("-l", "--runLabel",
00037   help="[REQUIRED] label to use for a run",
00038   type="string",
00039   default='',
00040   dest="runLabel")
00041 
00042 parser.add_option("-i", "--inputDir",
00043   help="[REQUIRED] input directory: should contain directories with the first and the final iterations' results",
00044   type="string",
00045   default='',
00046   dest="inputDir")
00047 
00048 parser.add_option("--i1",
00049   help="[REQUIRED] directory with the alignment 1st iteration's results relative to inputDir",
00050   type="string",
00051   default='',
00052   dest="i1")
00053 
00054 parser.add_option("--iN",
00055   help="[REQUIRED] directory with the alignment last iteration's results relative to inputDir",
00056   type="string",
00057   default='',
00058   dest="iN")
00059 
00060 parser.add_option("--i1prefix",
00061   help="filename prefix for the alignment 1st iteration's results. If not provided, i1prefix = i1",
00062   type="string",
00063   default='',
00064   dest="i1prefix")
00065 
00066 parser.add_option("--iNprefix",
00067   help="filename prefix for the alignment last iteration's results. If not provided, iNprefix = iN",
00068   type="string",
00069   default='',
00070   dest="iNprefix")
00071 
00072 parser.add_option("-o", "--outputDir",
00073   help="output directory: all plots will be saved with relation to outputDir. If not provided, consider outputDir = inputDir",
00074   type="string",
00075   default='',
00076   dest="outputDir")
00077 
00078 parser.add_option("--createDirSructure",
00079   help="If present, new directory structure for storing plots will be first created for each iteration at outputDir+i1 and outputDir+iN. WARNING: this will delete any existing results!",
00080   action="store_true",
00081   default=False,
00082   dest="createDirSructure")
00083 
00084 parser.add_option("--dt",
00085   help="If it is present, but not --csc, DT only plots will be created",
00086   action="store_true",
00087   default=False,
00088   dest="dt")
00089 
00090 parser.add_option("--csc",
00091   help="If this is present, but not --dt, CSC only plots will be created",
00092   action="store_true",
00093   default=False,
00094   dest="csc")
00095 
00096 parser.add_option("-a","--all",
00097   help="If present, all types of plots will be created",
00098   action="store_true",
00099   default=False,
00100   dest="all")
00101 
00102 parser.add_option("--map",
00103   help="If present, map plots will be created",
00104   action="store_true",
00105   default=False,
00106   dest="map")
00107 
00108 parser.add_option("--segdiff",
00109   help="If present, segdiff plots will be created",
00110   action="store_true",
00111   default=False,
00112   dest="segdiff")
00113 
00114 parser.add_option("--curvature",
00115   help="If present, curvature plots will be created",
00116   action="store_true",
00117   default=False,
00118   dest="curvature")
00119 
00120 parser.add_option("--fit",
00121   help="If present, fit functions plots will be created",
00122   action="store_true",
00123   default=False,
00124   dest="fit")
00125 
00126 parser.add_option("--median",
00127   help="If present, median plots will be created",
00128   action="store_true",
00129   default=False,
00130   dest="median")
00131 
00132 parser.add_option("--diagnostic",
00133   help="If present, will run diagnostic checks",
00134   action="store_true",
00135   default=False,
00136   dest="diagnostic")
00137 
00138 parser.add_option("-v", "--verbose",
00139   help="Degree of debug info verbosity",
00140   type="int",
00141   default=0,
00142   dest="verbose")
00143 
00144 options,args=parser.parse_args()
00145 
00146 if options.runLabel=='' or options.inputDir=='' or options.i1=='' or options.iN=='':
00147   print "\nOne or more of REQUIRED options is missing!\n"
00148   parser.print_help()
00149   # See \n"+sys.argv[0]+" --help"
00150   sys.exit()
00151 
00152 outdir = options.outputDir
00153 if outdir=='': outdir = options.inputDir
00154 
00155 i1prefix = options.i1prefix
00156 if i1prefix=='' : i1prefix = options.i1
00157 
00158 iNprefix = options.iNprefix
00159 if iNprefix=='' : iNprefix = options.iN
00160 
00161 if not os.access(outdir,os.F_OK):
00162   print "\noutDir = "+outdir+"\ndoes not exist! Exiting..."
00163   sys.exit()
00164 
00165 # If neither --dt or --csc is present, plots for both systems will be created
00166 DO_DT  = False
00167 DO_CSC = False
00168 if options.dt or not ( options.dt or options.csc):
00169   DO_DT = True
00170 if options.csc or not ( options.dt or options.csc):
00171   DO_CSC = True
00172 
00173 if not (options.all or options.map or options.curvature or options.segdiff or options.fit or options.median or options.diagnostic):
00174   print "\nOptions must include either -a or any of the following: --map, --segdiff, --fit, --median, --diagnostic. Exiting..."
00175   sys.exit()
00176 
00177 SINGLE_ITERATION = False
00178 if i1prefix == iNprefix: SINGLE_ITERATION = True
00179 
00180 DO_MAP = False
00181 DO_SEGDIFF = False
00182 DO_CURVATURE = False
00183 DO_FIT = False
00184 DO_MEDIAN = False
00185 if options.map or options.all:
00186   DO_MAP = True
00187 if options.segdiff or options.all:
00188   DO_SEGDIFF = True
00189 if options.curvature or options.all:
00190   DO_CURVATURE = True
00191 if options.fit or options.all:
00192   DO_FIT = True
00193 if options.median or options.all:
00194   DO_MEDIAN = True
00195 
00196 DO_DIAGNOSTIC = options.diagnostic
00197 
00198 allOptions = "-l "+options.runLabel+" -i "+options.inputDir+" --i1 "+options.i1+" --iN "+options.iN
00199 if options.i1prefix !='': allOptions += " --i1prefix " + options.i1prefix
00200 if options.iNprefix !='': allOptions += " --iNprefix " + options.iNprefix
00201 allOptions += " -o "+options.outputDir
00202 if options.createDirSructure: allOptions += " --createDirSructure"
00203 if DO_DT: allOptions += " --dt"
00204 if DO_CSC: allOptions += " --csc"
00205 if options.all: allOptions += " -a"
00206 if options.map: allOptions += " --map"
00207 if options.segdiff: allOptions += " --segdiff"
00208 if options.curvature: allOptions += " --curvature"
00209 if options.fit: allOptions += " --fit"
00210 if options.median: allOptions += " --median"
00211 if options.diagnostic: allOptions += " --diagnostic"
00212 print sys.argv[0]+" "+allOptions
00213 
00214 
00215 QUICKTESTN=10000
00216 
00217 
00218 
00219 ######################################################
00220 
00221 # template for canvases list
00222 CANVASES_LIST_TEMPLATE = [
00223 ['Common',' ',
00224  ['medians distribution','medians.png']
00225 ],
00226 ['DT',' ',
00227  ['Wheel&Station: map of dxdz residual vs phi','map_DTvsphi_dxdz.png'],
00228  ['Wheel&Station: map of dydz residual vs phi','map_DTvsphi_dydz.png'],
00229  ['Wheel&Station: map of x residual vs phi','map_DTvsphi_x.png'],
00230  ['Wheel&Station: map of y residual vs phi','map_DTvsphi_y.png'],
00231  ['Station&Sector: map of dxdz residual vs z','map_DTvsz_dxdz.png'],
00232  ['Station&Sector: map of dydz residual vs z','map_DTvsz_dydz.png'],
00233  ['Station&Sector: map of x residual vs z','map_DTvsz_x.png'],
00234  ['Station&Sector: map of y residual vs z','map_DTvsz_y.png'],
00235  ['Station: map of dxdz residual vs z','map_DTvsz_all_dxdz.png'],
00236  ['Station: map of dydz residual vs z','map_DTvsz_all_dydz.png'],
00237  ['Station: map of x residual vs z','map_DTvsz_all_x.png'],
00238  ['Station: map of y residual vs z','map_DTvsz_all_y.png'],
00239  ['Wheel: segdiff in x residuals vs phi','segdifphi_dt13_resid.png'],
00240  ['Wheel: segdiff in dxdz residuals vs phi','segdifphi_dt13_slope.png'],
00241  ['Wheel: segdiff in y residuals vs phi','segdifphi_dt2_resid.png'],
00242  ['Wheel: segdiff in dydz residuals vs phi','segdifphi_dt2_slope.png'],
00243  ['Wheel: segdiff DT-CSC in x residuals vs phi','segdifphi_x_dt_csc_resid.png'],
00244  ['Chamber: segdiff in x residuals','segdif_dt13_resid.png'],
00245  ['Chamber: segdiff in dxdz residuals','segdif_dt13_slope.png'],
00246  ['Chamber: segdiff in y residuals','segdif_dt2_resid.png'],
00247  ['Chamber: segdiff in dydz residuals','segdif_dt2_slope.png'],
00248  ['Chamber: segdiff DT-CSC in x residuals','segdif_x_dt_csc_resid.png'],
00249  ['Chamber: residuals distributions','dt_bellcurves.png'],
00250  ['Chamber: residuals relations to misalignments','dt_polynomials.png'],
00251  ['Chamber: Delta x residuals vs. curvature','dt_curvature_deltax.png'],
00252  ['Chamber: Delta dxdz residuals vs. curvature','dt_curvature_deltadxdz.png'],
00253  ['Extras: Extra plots in a separate window','dt_extras.php']
00254 ],
00255 ['CSC',' ',
00256  ['Station&Ring: map of d(rphi)/dz residual vs phi','map_CSCvsphi_dxdz.png'],
00257  ['Station&Ring: map of rphi residual vs phi','map_CSCvsphi_x.png'],
00258  ['Station&Chamber: map of d(rphi)/dz residual vs r','map_CSCvsr_dxdz.png'],
00259  ['Station&Chamber: map of rphi residual vs r','map_CSCvsr_x.png'],
00260  ['Station: map of d(rphi)/dz residual vs r','map_CSCvsr_all_dxdz.png'],
00261  ['Station: map of rphi residual vs r','map_CSCvsr_all_x.png'],
00262  ['Station: segdiff in rphi residuals vs phi','segdifphi_csc_resid.png'],
00263  ['Station: segdiff in d(rphi)/dz residuals vs phi','segdifphi_csc_slope.png'],
00264  ['Chamber: segdiff in rphi residuals','segdif_csc_resid.png'],
00265  ['Chamber: segdiff in d(rphi)/dz residuals','segdif_csc_slope.png'],
00266  ['Chamber: residuals distributions','csc_bellcurves.png'],
00267  ['Chamber: residuals relations to misalignments','csc_polynomials.png'],
00268  #['Chamber: Delta rphi residuals vs. curvature','csc_curvature_x.png'],
00269  #['Chamber: Delta d(rphi)/dz residuals vs. curvature','csc_curvature_dxdz.png'],
00270  ['Extras: Extra plots in a separate window','csc_extras.php']
00271 ]
00272 ]
00273 
00274 
00275 ######################################################
00276 # functions definitions
00277 
00278 
00279 def isFileUnderDir(dir_name, file_name):
00280   '''Recursively looks for file named file_name under dir_name directory
00281   '''
00282   if not DO_DT and dir_name.find("MB")>-1:
00283     return False
00284   if not DO_CSC and dir_name.find("ME")>-1:
00285     return False
00286   
00287   for f in os.listdir(dir_name):
00288     dirfile = os.path.join(dir_name, f)
00289     if os.path.isfile(dirfile) and f==file_name:
00290       return True
00291     # recursively access file names in subdirectories
00292     elif os.path.isdir(dirfile):
00293       #print "Accessing directory:", dirfile
00294       if isFileUnderDir(dirfile, file_name): return True
00295   return False
00296 
00297 
00298 # to time saving of plots
00299 def saveAs(nm): 
00300   t1 = time.time()
00301   ddt[15] += 1
00302   c1.SaveAs(nm)
00303   tn = time.time()
00304   ddt[16] = 1./ddt[15]*((ddt[15]-1)*ddt[16] + tn-t1)
00305 
00306 
00307 def createDirectoryStructure(iteration_name):
00308   
00309   if not os.access(iteration_name,os.F_OK):
00310     os.mkdir(iteration_name)
00311 
00312   csc_basedir = iteration_name+'/'
00313   for endcap in CSC_TYPES:
00314     #print csc_basedir+endcap[0]
00315     shutil.rmtree(csc_basedir+endcap[0],True)
00316     os.mkdir(csc_basedir+endcap[0])
00317     for station in endcap[2]:
00318       #print csc_basedir+endcap[0]+'/'+station[1]
00319       os.mkdir(csc_basedir+endcap[0]+'/'+station[1])
00320       for ring in station[2]:
00321         #print csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
00322         os.mkdir(csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1])
00323         for chamber in range(1,ring[2]+1):
00324           schamber = "%02d" % chamber
00325           #print csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
00326           os.mkdir(csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber)
00327 
00328   dt_basedir = iteration_name+'/MB/'
00329   #print dt_basedir
00330   shutil.rmtree(dt_basedir,True)
00331   os.mkdir(dt_basedir)
00332   for wheel in DT_TYPES:
00333     #print dt_basedir+wheel[0]
00334     os.mkdir(dt_basedir+wheel[0])
00335     for station in wheel[2]:
00336       #print dt_basedir+wheel[0]+'/'+station[1]
00337       os.mkdir(dt_basedir+wheel[0]+'/'+station[1])
00338       for sector in range(1,station[2]+1):
00339         ssector = "%02d" % sector
00340         #print dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
00341         os.mkdir(dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector)
00342 
00343   print os.getcwd()
00344 
00345 ######################################################
00346 
00347 def doMapPlotsDT(dt_basedir, tfiles_plotting):
00348   """write DT map plots
00349 
00350  "DTvsphi_st%dwh%s" % (station, wheelletter):
00351 
00352   plots "integrated" over ALL SECTORS:
00353   of x, y, dxdz, dydz vs. phi (y and dydz only for stations 1-3)
00354   made for all (station,wheel) combinations
00355 
00356   Access interface may be arranged into station(1 .. 4) vs. wheel(-2 .. +2) map.
00357   It could be incorporated into a general DT chambers map (column1: wheel, column2: station,
00358   columns3-16 correspond to sector #) by making station numbers in column 2 clickable.
00359   
00360 
00361  "DTvsz_st%dsec%02d" % (station, sector)
00362 
00363   plots "integrated" over ALL WHEELS:
00364   of x, y, dxdz, dydz vs. z (y and dydz only for stations 1-3)
00365   made for all (station,sector) combinations
00366 
00367   Interface: may be arranged into station(1 .. 4) vs. sector(1 .. 14) map with sector range
00368   (1 .. 12) for stations 1-3.
00369   It could be incorporated into an EXTENDED general DT chambers map (extended by adding an
00370   identifier "ALL" in column1 for wheel number).
00371 
00372 
00373  "DTvsz_st%dsecALL" % (station)
00374 
00375   plots spanning in z over ALL WHEELS and "integrated" over all sectors:
00376   of x, y, dxdz, dydz vs. z (y and dydz only for stations 1-3)
00377   made for all stations
00378 
00379   Interface: may be arranged into station(1 .. 4) map 
00380   It could be incorporated into an EXTENDED general DT chambers map (extended by adding an
00381   identifier "ALL" in column1 for wheel number)."""
00382   
00383   
00384   for wheel in DT_TYPES:
00385     if wheel[1]=="ALL": continue
00386     for station in wheel[2]:
00387       pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'
00388       label = "DTvsphi_st%dwh%s" % (int(station[1]), wheelLetter(int(wheel[1])))
00389       htitle = "wheel %+d, station %s" % (int(wheel[1]), station[1])
00390       #mapplot(tfiles_plotting, label, "x", window=25., title=htitle, fitsawteeth=True,fitsine=True)
00391       mapplot(tfiles_plotting, label, "x", window=10., title=htitle, fitsine=True,fitpeaks=True,peaksbins=2)
00392       c1.SaveAs(pdir+'map_DTvsphi_x.png')
00393       #mapplot(tfiles_plotting, label, "dxdz", window=25., title=htitle, fitsawteeth=True,fitsine=True)
00394       mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle,peaksbins=2)
00395       c1.SaveAs(pdir+'map_DTvsphi_dxdz.png')
00396 
00397       if station[1]=='4': continue
00398       #mapplot(tfiles_plotting, label, "y", window=25., title=htitle, fitsawteeth=True,fitsine=True)
00399       mapplot(tfiles_plotting, label, "y", window=10., title=htitle,peaksbins=2)
00400       c1.SaveAs(pdir+'map_DTvsphi_y.png')
00401       #mapplot(tfiles_plotting, label, "dydz", window=25., title=htitle, fitsawteeth=True,fitsine=True)
00402       mapplot(tfiles_plotting, label, "dydz", window=10., title=htitle,peaksbins=2)
00403       c1.SaveAs(pdir+'map_DTvsphi_dydz.png')
00404 
00405   
00406   qcount=0
00407   for wheel in DT_TYPES:
00408     if wheel[1]!="ALL": continue
00409     for station in wheel[2]:
00410       for sector in range(1,station[2]+1):
00411         if qcount>QUICKTESTN: break
00412         qcount += 1
00413         ssector = "%02d" % sector
00414         pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
00415         label = "DTvsz_st%ssec%s" % (station[1], ssector)
00416         htitle = "station %s, sector %d" % (station[1], sector)
00417         mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2)
00418         c1.SaveAs(pdir+'map_DTvsz_x.png')
00419         mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2)
00420         c1.SaveAs(pdir+'map_DTvsz_dxdz.png')
00421         
00422         if station[1]=='4': continue
00423         mapplot(tfiles_plotting, label, "y", window=10., title=htitle, peaksbins=2)
00424         c1.SaveAs(pdir+'map_DTvsz_y.png')
00425         mapplot(tfiles_plotting, label, "dydz", window=10., title=htitle, peaksbins=2)
00426         c1.SaveAs(pdir+'map_DTvsz_dydz.png')
00427   
00428   qcount=0
00429   for wheel in DT_TYPES:
00430     if wheel[1]!="ALL": continue
00431     for station in wheel[2]:
00432       if qcount>QUICKTESTN: break
00433       qcount += 1
00434       pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'
00435       label = "DTvsz_st%ssecALL" % (station[1])
00436       htitle = "station %s" % (station[1])
00437       
00438       print label, 
00439       mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2)
00440       c1.SaveAs(pdir+'map_DTvsz_all_x.png')
00441       mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2)
00442       c1.SaveAs(pdir+'map_DTvsz_all_dxdz.png')
00443       
00444       if station[1]=='4': continue
00445       mapplot(tfiles_plotting, label, "y", window=10., title=htitle, peaksbins=2)
00446       c1.SaveAs(pdir+'map_DTvsz_all_y.png')
00447       mapplot(tfiles_plotting, label, "dydz", window=10., title=htitle, peaksbins=2)
00448       c1.SaveAs(pdir+'map_DTvsz_all_dydz.png')
00449 
00450   saveTestResultsMap(options.runLabel)
00451 
00452 
00453 def doMapPlotsCSC(csc_basedir, tfiles_plotting):
00454   """write CSC map plots
00455 
00456  "CSCvsphi_me%s%d%d" % (endcap, station, ring)
00457 
00458   plots "integrated" over ALL SECTORS:
00459   of rphi, drphi/dz vs. phi
00460   made for all (endcap,station,ring) combinations
00461 
00462   Interface: may be arranged into two station(1 .. 4) vs. R(1 .. 4) maps for both endcaps
00463   with R range (1 .. 4) for stations 2-4
00464  It could be incorporated into a general CSC chambers map (column1: endcap, column2: station,
00465   column3: ring, columns4-40 correspond to chamber #) by making ring numbers in column 3
00466   clickable.
00467 
00468 
00469  "CSCvsr_me%s%dch%02d" % (endcap, station, chamberNumber)
00470 
00471   plots "integrated" over ALL RINGS:
00472   of rphi, drphi/dz vs. z
00473   made for all (endcap,station,chamber) combinations
00474 
00475   Interface: may be arranged into two station(1 .. 4) vs. chamber(1 .. 36) maps for both endcaps
00476   It could be incorporated into an EXTENDED general CSC chambers map (extended by adding an
00477   identifier "ALL" in column3 for ring number).
00478   
00479  "CSCvsr_me%s%dchALL" % (endcap, station)
00480 
00481   plots spanning over ALL RINGS along r and integrated over all SECTORS:
00482   of rphi, drphi/dz vs. z
00483   made for all (endcap,station) combinations
00484 
00485   Interface: may be arranged into two station(1 .. 4) maps for both endcaps
00486   It could be incorporated into an EXTENDED general CSC chambers map (extended by adding an
00487   identifier "ALL" in column3 for ring number)."""
00488 
00489   for endcap in CSC_TYPES:
00490     for station in endcap[2]:
00491       for ring in station[2]:
00492         if ring[1]=="ALL": continue
00493         pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'
00494         label = "CSCvsphi_me%s%s%s" % (endcap[1], station[1], ring[1])
00495         htitle = "%s%s/%s" % (endcap[0], station[1],ring[1])
00496         mapplot(tfiles_plotting, label, "x", window=15., title=htitle, fitsine=True,fitpeaks=True, peaksbins=2)
00497         #mapplot(tfiles_plotting, label, "x", window=15., title=htitle, fitsine=True)
00498         c1.SaveAs(pdir+'map_CSCvsphi_x.png')
00499         mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle, peaksbins=2)
00500         c1.SaveAs(pdir+'map_CSCvsphi_dxdz.png')
00501 
00502   saveTestResultsMap(options.runLabel)
00503 
00504   qcount = 0
00505   for endcap in CSC_TYPES:
00506     for station in endcap[2]:
00507       for ring in station[2]:
00508         if ring[1]!="ALL": continue
00509         for chamber in range(1,ring[2]+1):
00510           if qcount>QUICKTESTN: break
00511           qcount += 1
00512           schamber = "%02d" % chamber
00513           pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber+'/'
00514           label = "CSCvsr_me%s%sch%s" % (endcap[1], station[1], schamber)
00515           htitle = "%s%s/ALL/%d" % (endcap[0], station[1],chamber)
00516           mapplot(tfiles_plotting, label, "x", window=15., title=htitle, peaksbins=2)
00517           c1.SaveAs(pdir+'map_CSCvsr_x.png')
00518           mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle, peaksbins=2)
00519           c1.SaveAs(pdir+'map_CSCvsr_dxdz.png')
00520 
00521   qcount = 0
00522   for endcap in CSC_TYPES:
00523     for station in endcap[2]:
00524       for ring in station[2]:
00525         if ring[1]!="ALL": continue
00526         if qcount>QUICKTESTN: break
00527         qcount += 1
00528         schamber = "%02d" % chamber
00529         pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'
00530         label = "CSCvsr_me%s%schALL" % (endcap[1], station[1])
00531         htitle = "%s%s" % (endcap[0], station[1])
00532         mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2)
00533         c1.SaveAs(pdir+'map_CSCvsr_all_x.png')
00534         mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2)
00535         c1.SaveAs(pdir+'map_CSCvsr_all_dxdz.png')
00536 
00537 
00538 
00539 def doCurvaturePlotsDT(dt_basedir, tfiles_plotting):
00540   """write DT curvature plots
00541 
00542   "wheel%s_sector%s" % (wheel, sector)
00543 
00544   wheel in "m2", "m1", "z", "p1", "p2"
00545   station 1 only!
00546   sector in "01", ..., "12"
00547 
00548   "param" may be one of 
00549     "deltax" (Delta x position residuals),
00550     "deltadxdz" (Delta (dx/dz) angular residuals),
00551     "curverr" (Delta x * d(Delta q/pT)/d(Delta x) = Delta q/pT in the absence of misalignment) - not necessary
00552 
00553   made for all (wheel,station=1,sector) combinations
00554 
00555   Interface: could be accesses through a general DT chambers map for station=1 chambers."""
00556   
00557   w_dict = {'-2':'m2', '-1':'m1', '0':'z', '1':'p1', '2':'p2'}
00558   qcount = 0
00559   for wheel in DT_TYPES:
00560     if wheel[1]=="ALL": continue
00561     #station = 1
00562     #station = wheel[2][0]
00563     for station in wheel[2]:
00564       print "curv in ", wheel[0]+'/'+station[1]
00565       for sector in range(1,station[2]+1):
00566         #if sector>12: break
00567         if qcount>QUICKTESTN: break
00568         qcount += 1
00569         ssector = "%02d" % sector
00570         pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
00571         label = "wheel%s_st%s_sector%s" % (w_dict[wheel[1]], station[1], ssector)
00572         thetitle ="Wheel %s, station %s, sector %s" % (wheel[1], station[1], ssector)
00573         curvatureplot(tfiles_plotting, label, "deltax", title=thetitle, window=10., fitline=True)
00574         saveAs(pdir+'dt_curvature_deltax.png')
00575         curvatureplot(tfiles_plotting, label, "deltadxdz", title=thetitle, window=10., fitline=True)
00576         saveAs(pdir+'dt_curvature_deltadxdz.png')
00577 
00578 
00579 
00580 def doSegDiffPlotsDT(dt_basedir, tfiles_plotting, iter_reports):
00581   """write segment-difference plots for DT
00582 
00583  segdiff "dt13_resid" and "dt13_slope"
00584 
00585   set of plots of
00586   x vs qpt, x for positive, x for negative ("dt13_resid")
00587   dxdz vs qpt, dxdz for positive, dxdz for negative ("dt13_slope")
00588   done for MB1-MB2, MB2-MB3, and MB3-MB4 stations combinations with all possible (wheel, sector)
00589 
00590   Interface: could be accessed through a general DT chambers map, but only for chambers in
00591   stations 2-4 (e.g., station 2 would provide MB1-MB2 plots).
00592 
00593  segdiff "dt2_resid" and "dt2_slope"
00594 
00595   set of plots of
00596   y vs q/pt, y for positive, y for negative ("dt2_resid")
00597   dydz vs q/pt, dydz for positive, dydz for negative ("dt2_slope")
00598   done for MB1-MB2, MB2-MB3 stations combinations with all possible (wheel, sector)
00599 
00600   Interface: then the interface would still be a general DT map,
00601   but the info only available from station 2 & 3 chambers."""
00602 
00603   qcount = 0
00604   for iwheel in DT_TYPES:
00605     if iwheel[1]=="ALL": continue
00606     for istation in iwheel[2]:
00607       if istation[1]=="1": continue
00608       dstations = (int(istation[1])-1)*10 + int(istation[1])
00609       #print dstations
00610       for isector in range(1, istation[2] + 1):
00611         if isector > 12: continue
00612         if qcount>QUICKTESTN: break
00613         qcount += 1
00614         ssector = "%02d" % isector
00615         pdir = dt_basedir + '/' + iwheel[0] + '/' + istation[1] + '/' + ssector + '/'
00616         
00617         segdiff(tfiles_plotting, "dt13_resid", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
00618         c1.SaveAs(pdir + 'segdif_dt13_resid.png')
00619         segdiff(tfiles_plotting, "dt13_slope", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
00620         c1.SaveAs(pdir + 'segdif_dt13_slope.png')
00621         
00622         if istation[1] != '4':
00623           segdiff(tfiles_plotting, "dt2_resid", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
00624           c1.SaveAs(pdir + 'segdif_dt2_resid.png')
00625           segdiff(tfiles_plotting, "dt2_slope", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
00626           c1.SaveAs(pdir + 'segdif_dt2_slope.png')
00627         
00628   qcount = 0
00629   for iwheel in DT_TYPES:
00630     if iwheel[1]=="ALL": continue
00631     if abs(int(iwheel[1])) != 2: continue
00632     for istation in iwheel[2]:
00633       if istation[1]=="3": continue
00634       #print dstations
00635       for isector in range(1, istation[2] + 1):
00636         ssector = "%02d" % isector
00637         pdir = dt_basedir + '/' + iwheel[0] + '/' + istation[1] + '/' + ssector + '/'
00638         if istation[1]=="1":
00639           segdiff_xalign(tfiles_plotting, "x_dt1_csc", wheel=int(iwheel[1]), sector=isector, cscstations = "12")
00640           c1.SaveAs(pdir + 'segdif_x_dt_csc_resid.png')
00641         if istation[1]=="2":
00642           segdiff_xalign(tfiles_plotting, "x_dt2_csc", wheel=int(iwheel[1]), sector=isector, cscstations = "1")
00643           c1.SaveAs(pdir + 'segdif_x_dt_csc_resid.png')
00644 
00645   """segdiffvsphi "dt13_resid" and "dt13_slope"
00646 
00647   plot for a specific wheel #:
00648   x vs phi of pair ("dt13_resid")
00649   dxdz vs phi of pair ("dt13_slope")
00650   contains all three combinations of neighboring stations
00651   made for all possible wheel values
00652 
00653   Interface: could be accessed by clicking on wheel number under the "wheel" column
00654   in a general DT map
00655 
00656  segdiffvsphi "dt2_resid" and "dt2_slope"
00657 
00658   plot for a specific wheel #:
00659   y vs phi of pair ("dt2_resid")
00660   dydz vs phi of pair ("dt2_slope")
00661   contains both MB1-MB2 and MB2-MB3 combinations
00662   made for all possible wheel values
00663 
00664   Interface: could be accessed by clicking on wheel number under the "wheel" column
00665   in a general DT map"""
00666 
00667   if len(iter_reports)==0: return
00668   
00669   for iwheel in DT_TYPES:
00670     if iwheel[1]=="ALL": continue
00671     pdir = dt_basedir + '/' + iwheel[0] + '/'
00672     segdiffvsphi(tfiles_plotting, iter_reports, "dt13_resid", int(iwheel[1]), window=10.)#, excludesectors=(1,7))
00673     c1.SaveAs(pdir + 'segdifphi_dt13_resid.png')
00674     segdiffvsphi(tfiles_plotting, iter_reports, "dt13_slope", int(iwheel[1]), window=10.)#, excludesectors=(1,7))
00675     c1.SaveAs(pdir + 'segdifphi_dt13_slope.png')
00676     segdiffvsphi(tfiles_plotting, iter_reports, "dt2_resid", int(iwheel[1]), window=10.)#, excludesectors=(1,7))
00677     c1.SaveAs(pdir + 'segdifphi_dt2_resid.png')
00678     segdiffvsphi(tfiles_plotting, iter_reports, "dt2_slope", int(iwheel[1]), window=15.)#, excludesectors=(1,7))
00679     c1.SaveAs(pdir + 'segdifphi_dt2_slope.png')
00680 
00681   for iwheel in DT_TYPES:
00682     if iwheel[1]=="ALL": continue
00683     if abs(int(iwheel[1])) != 2: continue
00684     pdir = dt_basedir + '/' + iwheel[0] + '/'
00685     segdiffvsphi_xalign(tfiles_plotting, int(iwheel[1]), window=10.)
00686     c1.SaveAs(pdir + 'segdifphi_x_dt_csc_resid.png')
00687 
00688 
00689 def doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports):
00690   """write segment-difference plots for CSC
00691  
00692  segdiff "csc_resid" and "csc_slope"
00693 
00694   set of plots of
00695   rphi vs qpt, rphi for positive, rphi for negative ("csc_resid")
00696   drphidz vs qpt, drphidz for positive, drphidz for negative ("csc_slope")
00697   done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with
00698     endcap "m" or "p" 
00699     ring 1 or 2
00700     chamber 1-18 (r1) or 1-36 (r2)
00701   note: there's no ME3-ME4 plots for R2
00702   
00703   Interface: could be accessed through a general CSC chambers map, but only for chambers in
00704   stations 2-4 (e.g., station 2 would provide ME1-ME2 plots)."""
00705 
00706   qcount = 0
00707   for iendcap in CSC_TYPES:
00708     for istation in iendcap[2]:
00709       if istation[1]=="1": continue
00710       dstations = (int(istation[1])-1)*10 + int(istation[1])
00711       for iring in istation[2]:
00712         if iring[1]=="ALL": continue
00713         if istation[1]=="4" and iring[1]=="2": continue
00714         for ichamber in range(1,iring[2]+1):
00715           if qcount>QUICKTESTN: break
00716           qcount += 1
00717           schamber = "%02d" % ichamber
00718           pdir = csc_basedir+'/'+iendcap[0]+'/'+istation[1]+'/'+iring[1]+'/'+schamber+'/'
00719           segdiff(tfiles_plotting, "csc_resid", dstations, 
00720                   endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=15.)
00721           c1.SaveAs(pdir + 'segdif_csc_resid.png')
00722           segdiff(tfiles_plotting, "csc_slope", dstations, 
00723                   endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=15.)
00724           c1.SaveAs(pdir + 'segdif_csc_slope.png')
00725 
00726   """segdiffvsphicsc "csc_resid" and "csc_slope"
00727 
00728   plot for a specific deltaME station differences:
00729   rphi vs phi of pair ("csc_resid")
00730   dxdz vs phi of pair ("csc_slope")
00731   contains plots for two (or one for ME4-ME3) rings
00732   done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with
00733     endcap "m" or "p" 
00734   
00735   Interface: could be accessed by clicking on ME station boxes, but only for stations 2-4 
00736   (e.g., station 2 would provide ME1-ME2 plots)."""
00737 
00738   qcount = 0
00739   for iendcap in CSC_TYPES:
00740     for istation in iendcap[2]:
00741       if istation[1]=="1": continue
00742       dstations = (int(istation[1])-1)*10 + int(istation[1])
00743       if qcount>QUICKTESTN: break
00744       qcount += 1
00745       pdir = csc_basedir+'/'+iendcap[0]+'/'+istation[1]+'/'
00746       segdiffvsphicsc(tfiles_plotting, "csc_resid", dstations, window=10., endcap=iendcap[1])
00747       c1.SaveAs(pdir + 'segdifphi_csc_resid.png')
00748       segdiffvsphicsc(tfiles_plotting, "csc_slope", dstations, window=10., endcap=iendcap[1])
00749       c1.SaveAs(pdir + 'segdifphi_csc_slope.png')
00750 
00751 
00752 def doFitFunctionsPlotsDT(dt_basedir, iter_tfile, iter_reports):
00753   """write fit functions plots for DT
00754 
00755  DT bellcurves and polynomials
00756 
00757   set of plots of bellcurves
00758     x, dxdz, x vs. dxdz (for all 4 stations)
00759     y, dydz, x vs. dxdz (only for stations 1-3?)
00760 
00761   set of plots of polynomials -- for stations 1-3 only??
00762     x vs. xpos,    x vs ypos,    x vs dxdz angle,    x vs dydz angle
00763     y vs. xpos,    y vs ypos,    y vs dxdz angle,    y vs dydz angle
00764     dxdz vs. xpos, dxdz vs ypos, dxdz vs dxdz angle, dxdz vs dydz angle
00765     dydz vs. xpos, dydz vs ypos, dydz vs dxdz angle, dydz vs dydz angle
00766 
00767   set of plots of polynomials -- for station 4 only??
00768     x vs. xpos,    x vs dxdz angle
00769     dxdz vs. xpos, dxdz vs dxdz angle
00770 
00771   made for all (wheel,station,sector) combinations
00772 
00773   Interface: could be accesses through a general DT chambers map."""
00774 
00775   qcount = 0
00776   clearDDT()
00777   for wheel in DT_TYPES:
00778     if wheel[1]=="ALL": continue
00779     for station in wheel[2]:
00780       print wheel[0]+'/'+station[1]
00781       for sector in range(1,station[2]+1):
00782         if qcount>QUICKTESTN: break
00783         qcount += 1
00784         ssector = "%02d" % sector
00785         pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
00786         label = "MBwh%sst%ssec%s" % (wheelLetter(int(wheel[1])),station[1],ssector)
00787         bellcurves(iter_tfile, iter_reports, label, False)
00788         #c1.SaveAs(pdir+'dt_bellcurves.png')
00789         saveAs(pdir+'dt_bellcurves.png')
00790         polynomials(iter_tfile, iter_reports, label, False)
00791         #c1.SaveAs(pdir+'dt_polynomials.png')
00792         saveAs(pdir+'dt_polynomials.png')
00793   #printDeltaTs()
00794 
00795 
00796 def doFitFunctionsPlotsCSC(csc_basedir, iter_tfile, iter_reports):
00797   """write fit functions plots for CSC
00798 
00799  CSC bellcurves and polynomials
00800 
00801   set of plots of bellcurves
00802     rphi, drphidz, rphi vs. drphidz
00803 
00804   set of plots of polynomials
00805     rphi vs. rphi pos,    rphi vs drphidz angle
00806     drphidz vs. rphi pos, drphidz vs drphidz angle
00807 
00808   made for all (endcap,station,ring,chamber) combinations
00809 
00810   Interface: could be accesses through a general CSC chambers map."""
00811 
00812   qcount = 0
00813   clearDDT()
00814   for endcap in CSC_TYPES:
00815     for station in endcap[2]:
00816       for ring in station[2]:
00817         if ring[1]=="ALL": continue
00818         print endcap[0]+'/'+station[1]+'/'+ring[1]
00819         for chamber in range(1,ring[2]+1):
00820           if qcount>QUICKTESTN: break
00821           qcount += 1
00822           schamber = "%02d" % chamber
00823           pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber+'/'
00824           label = "ME%s%s%s_%s" % (endcap[1], station[1], ring[1], schamber)
00825           bellcurves(iter_tfile, iter_reports, label, False)
00826           #c1.SaveAs(pdir+'csc_bellcurves.png')
00827           saveAs(pdir+'csc_bellcurves.png')
00828           polynomials(iter_tfile, iter_reports, label, False)
00829           #c1.SaveAs(pdir+'csc_polynomials.png')
00830           saveAs(pdir+'csc_polynomials.png')
00831   #printDeltaTs()
00832 
00833 
00834 
00835 def doIterationPlots(iteration_directory, tfiles_plotting, iter_tfile, iter_reports):
00836   dt_basedir = iteration_directory+'/'+'MB'
00837   csc_basedir = iteration_directory+'/'
00838 
00839   if DO_DT and DO_MAP:
00840     doMapPlotsDT(dt_basedir, tfiles_plotting)
00841   if DO_CSC and DO_MAP:
00842     doMapPlotsCSC(csc_basedir, tfiles_plotting)
00843 
00844   if DO_DT and DO_CURVATURE:
00845     doCurvaturePlotsDT(dt_basedir, tfiles_plotting)
00846   #if DO_CSC and DO_CURVATURE:
00847   #  doCurvaturePlotsCSC(csc_basedir, tfiles_plotting)
00848 
00849   if DO_DT and DO_SEGDIFF:
00850     doSegDiffPlotsDT(dt_basedir, tfiles_plotting, iter_reports)
00851   if DO_CSC and DO_SEGDIFF:
00852     doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports)
00853 
00854   if DO_DT and DO_FIT:
00855     doFitFunctionsPlotsDT(dt_basedir, iter_tfile, iter_reports)
00856   if DO_CSC and DO_FIT:
00857     doFitFunctionsPlotsCSC(csc_basedir, iter_tfile, iter_reports)
00858 
00859 
00860 def createCanvasesList(fname="canvases_list.js"):
00861   '''Use CANVASES_LIST_TEMPLATE as a template to create a canvases list include for the browser.
00862      Write out only those canvases which have existing filename.png plots.
00863   '''
00864   CANVASES_LIST = []
00865   for scope in CANVASES_LIST_TEMPLATE:
00866     scope_entry = []
00867     if len(scope)>2:
00868       scope_entry = [scope[0],scope[1]]
00869       for canvas_entry in scope[2:]:
00870         if isFileUnderDir("./",canvas_entry[1]):
00871           scope_entry.append(canvas_entry)
00872     CANVASES_LIST.append(scope_entry)
00873 
00874   ff = open(fname,mode="w")
00875   print >>ff, "var CANVASES_LIST = "
00876   json.dump(CANVASES_LIST,ff)
00877   ff.close()
00878 
00879 
00880 def createCanvasToIDList(fname="canvas2id_list.js"):
00881   '''Writes out a canvas-2-ids list include for the browser.
00882      Write out only those canvases which have existing filename.png plots.
00883      Returns: list of unique IDs that have existing filename.png plots.
00884   '''
00885   CANVAS2ID_LIST = []
00886   ID_LIST = []
00887   for scope in CANVASES_LIST_TEMPLATE:
00888     if len(scope)>2:
00889       for canvas_entry in scope[2:]:
00890         ids = idsForFile("./",canvas_entry[1])
00891         #  scope_entry.append(canvas_entry)
00892         # uniquify:
00893         set_ids = set(ids)
00894         uids = list(set_ids)
00895         ID_LIST.extend(uids)
00896         print canvas_entry, ":", len(uids), "ids"
00897         if (len(uids)>0):
00898           CANVAS2ID_LIST.append( (canvas_entry[1],uids) )
00899   #print CANVAS2ID_LIST
00900   CANVAS2ID_LIST_DICT = dict(CANVAS2ID_LIST)
00901   #print CANVAS2ID_LIST_DICT
00902   ff = open(fname,mode="w")
00903   print >>ff, "var CANVAS2ID_LIST = "
00904   json.dump(CANVAS2ID_LIST_DICT,ff)
00905   ff.close()
00906   set_ids = set(ID_LIST)
00907   return list(set_ids)
00908 
00909 def idsForFile(dir_name, file_name):
00910   '''Recursively looks for file named file_name under dir_name directory
00911   and fill the list with dir names converted to IDs 
00912   '''
00913   id_list = []
00914   for f in os.listdir(dir_name):
00915     dirfile = os.path.join(dir_name, f)
00916     if os.path.isfile(dirfile) and f==file_name:
00917       if file_name[-4:]=='.php': id_list.append(dir_name+'/'+file_name)
00918       else:    id_list.append(dirToID(dir_name))
00919     # recursively access file names in subdirectories
00920     elif os.path.isdir(dirfile):
00921       #print "Accessing directory:", dirfile
00922       ids = idsForFile(dirfile, file_name)
00923       if (len(ids)>0): 
00924         id_list.extend(ids)
00925   return id_list
00926 
00927 
00928 def dirToID(d):
00929   if d[-1]!='/': d += '/'
00930   dtn = d.find("/MB/")
00931   if dtn!=-1:
00932     return d[dtn+4:-1]
00933   cscn = d.find("/ME-/")
00934   if cscn!=-1:
00935     return 'ME-'+d[cscn+5:-1]
00936   cscn = d.find("/ME+/")
00937   if cscn!=-1:
00938     return 'ME+'+d[cscn+5:-1]
00939   return ''
00940 
00941 
00942 ############################################################################################################
00943 ############################################################################################################
00944 # main script
00945 
00946 # open input files:
00947 
00948 #basedir='/disks/sdb5/home_reloc/khotilov/db/cms/alignment'
00949 #iteration1 = "iteration_01"
00950 #iteration3 = "iteration_03"
00951 #iteration1 = "NOV4DT_PASS3noweight_TkHIP_01"
00952 #iteration3 = "NOV4DT_PASS3noweight_TkHIP_05"
00953 #os.chdir(options.inputDir)
00954 #iteration1 = options.i1
00955 #iteration3 = options.iN
00956 
00957 fname = options.inputDir+'/'+options.i1+'/'+i1prefix
00958 tfiles1_plotting = []
00959 iter1_tfile = None
00960 iter1_reports = []
00961 if not SINGLE_ITERATION:
00962   if (DO_MAP or DO_SEGDIFF or DO_CURVATURE) and not os.access(fname+"_plotting.root",os.F_OK):
00963     print "no file "+fname+"_plotting.root"
00964     sys.exit()
00965   if DO_FIT and not os.access(fname+".root",os.F_OK):
00966     print "no file "+fname+".root"
00967     sys.exit()
00968   if DO_MEDIAN and not os.access(fname+"_report.py",os.F_OK):
00969     print "no file "+fname+"_report.py"
00970     sys.exit()
00971   if DO_MAP or DO_SEGDIFF or DO_CURVATURE: tfiles1_plotting.append(ROOT.TFile(fname+"_plotting.root"))
00972   if os.access(fname+".root",os.F_OK):
00973     iter1_tfile = ROOT.TFile(fname+".root")
00974   if os.access(fname+"_report.py",os.F_OK):
00975     execfile(fname+"_report.py")
00976     iter1_reports = reports
00977 
00978 fname = options.inputDir+'/'+options.iN+'/'+iNprefix
00979 tfilesN_plotting = []
00980 iterN_tfile = None
00981 iterN_reports = []
00982 if (DO_MAP or DO_SEGDIFF or DO_CURVATURE) and not os.access(fname+"_plotting.root",os.F_OK):
00983   print "no file "+fname+"_plotting.root"
00984   sys.exit()
00985 if DO_FIT and not os.access(fname+".root",os.F_OK):
00986   print "no file "+fname+".root"
00987   sys.exit()
00988 if DO_MEDIAN and not os.access(fname+"_report.py",os.F_OK):
00989   print "no file "+fname+"_report.py"
00990   sys.exit()
00991 if DO_MAP or DO_SEGDIFF or DO_CURVATURE: tfilesN_plotting.append(ROOT.TFile(fname+"_plotting.root"))
00992 if os.access(fname+".root",os.F_OK):
00993   iterN_tfile = ROOT.TFile(fname+".root")
00994 if os.access(fname+"_report.py",os.F_OK):
00995   execfile(fname+"_report.py")
00996   iterN_reports = reports
00997 
00998 if DO_MAP:
00999   os.chdir(options.inputDir)
01000   phiedges2c()
01001 
01002 ######################################################
01003 # setup output:
01004 
01005 # cd to outputDIr
01006 os.chdir(options.outputDir)
01007 
01008 comdir = "common/"
01009 iteration1 = "iter1"
01010 iterationN = "iterN"
01011 
01012 # create directory structure
01013 if options.createDirSructure:
01014   print "WARNING: all existing results in "+options.outputDir+" will be deleted!"
01015   if not SINGLE_ITERATION: createDirectoryStructure(iteration1)
01016   createDirectoryStructure(iterationN)
01017   if not os.access(comdir,os.F_OK):
01018     os.mkdir(comdir)
01019 
01020 ######################################################
01021 # do drawing
01022 
01023 c1 = ROOT.TCanvas("c1","c1",800,600)
01024 
01025 set_palette("blues")
01026 
01027 print "--- ITERATION 1 ---"
01028 if not SINGLE_ITERATION: doIterationPlots(iteration1, tfiles1_plotting, iter1_tfile, iter1_reports)
01029 print "--- ITERATION N ---"
01030 doIterationPlots(iterationN, tfilesN_plotting, iterN_tfile, iterN_reports)
01031 
01032 if CPP_LOADED: ROOT.cleanUpHeap()
01033 
01034 # write distributions of medians plots
01035 
01036 if DO_MEDIAN:
01037   #plotmedians(iter1_reports, iterN_reports)
01038   plotmedians(iter1_reports, iterN_reports,binsx=100, windowx=10., binsy=100, windowy=10., binsdxdz=100, windowdxdz=10., binsdydz=100, windowdydz=10.)
01039   c1.SaveAs(comdir+'medians.png')
01040 
01041 # perform diagnostic
01042 if DO_DIAGNOSTIC:
01043   #if not SINGLE_ITERATION: doTests(iter1_reports,"mu_list_1.js","dqm_report_1.js",options.runLabel)
01044   createCanvasesList("canvases_list.js")
01045   pic_ids = createCanvasToIDList("canvas2id_list.js")
01046   doTests(iterN_reports, pic_ids, "mu_list.js","dqm_report.js",options.runLabel)