Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:04

0001 #! /usr/bin/env python3
0002 
0003 from builtins import range
0004 import re,os,sys,shutil
0005 import optparse
0006 
0007 from mutypes import *
0008 
0009 execfile("plotscripts.py")
0010 
0011 ROOT.gROOT.SetBatch(1);
0012 
0013 ######################################################
0014 
0015 ######################################################
0016 # To parse commandline args
0017 
0018 usage='%prog [options]\n'+\
0019   'This script dumps muon alignment validation plots '+\
0020   '(see https://twiki.cern.ch/twiki/bin/viewauth/CMS/SWGuideMuonAlignValidationPlots) '+\
0021   'in web-friendly png format into a predefined directory structure '+\
0022   'and also (to be implemented) does some quality checks for these plots.\n'+\
0023   'Script uses output of the first and last iterations of muon alignment runs '+\
0024   'that should be located in inputDir+i1 and inputDir+iN directories (see options descriptions). '+\
0025   'Each of these directories should contain\ni#prefix+"_plotting.root"\ni#prefix+".root"\ni#prefix+"_report.py"\n'+\
0026   'files, where # = 1 or N.\n'+\
0027   'Output will be located in outputDir, which must exist. Plots from the first and last iterations '+\
0028   'will be in outputDir+"iter1" and outputDir+"iterN" respectively, and plots relevant for all iterations will '+\
0029   'reside in outputDir+"common/".\n'+\
0030   'For a first run a --createDirSructure option must be present. If this option is present for subsequent runs '+\
0031   'with the same outputDir, all previous results in "iter1", "iterN" and and "common" would be deleted!\n'+\
0032   'If neither --dt or --csc is present, plots for both systems will be created.\n'+\
0033   'Options must include either -a or any of the following: --map, --segdiff, --fit, --median'
0034 
0035 parser=optparse.OptionParser(usage)
0036 
0037 parser.add_option("-l", "--runLabel",
0038   help="[REQUIRED] label to use for a run",
0039   type="string",
0040   default='',
0041   dest="runLabel")
0042 
0043 parser.add_option("-i", "--inputDir",
0044   help="[REQUIRED] input directory: should contain directories with the first and the final iterations' results",
0045   type="string",
0046   default='',
0047   dest="inputDir")
0048 
0049 parser.add_option("--i1",
0050   help="[REQUIRED] directory with the alignment 1st iteration's results relative to inputDir",
0051   type="string",
0052   default='',
0053   dest="i1")
0054 
0055 parser.add_option("--iN",
0056   help="[REQUIRED] directory with the alignment last iteration's results relative to inputDir",
0057   type="string",
0058   default='',
0059   dest="iN")
0060 
0061 parser.add_option("--i1prefix",
0062   help="filename prefix for the alignment 1st iteration's results. If not provided, i1prefix = i1",
0063   type="string",
0064   default='',
0065   dest="i1prefix")
0066 
0067 parser.add_option("--iNprefix",
0068   help="filename prefix for the alignment last iteration's results. If not provided, iNprefix = iN",
0069   type="string",
0070   default='',
0071   dest="iNprefix")
0072 
0073 parser.add_option("-o", "--outputDir",
0074   help="output directory: all plots will be saved with relation to outputDir. If not provided, consider outputDir = inputDir",
0075   type="string",
0076   default='',
0077   dest="outputDir")
0078 
0079 parser.add_option("--createDirSructure",
0080   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!",
0081   action="store_true",
0082   default=False,
0083   dest="createDirSructure")
0084 
0085 parser.add_option("--dt",
0086   help="If it is present, but not --csc, DT only plots will be created",
0087   action="store_true",
0088   default=False,
0089   dest="dt")
0090 
0091 parser.add_option("--csc",
0092   help="If this is present, but not --dt, CSC only plots will be created",
0093   action="store_true",
0094   default=False,
0095   dest="csc")
0096 
0097 parser.add_option("-a","--all",
0098   help="If present, all types of plots will be created",
0099   action="store_true",
0100   default=False,
0101   dest="all")
0102 
0103 parser.add_option("--map",
0104   help="If present, map plots will be created",
0105   action="store_true",
0106   default=False,
0107   dest="map")
0108 
0109 parser.add_option("--segdiff",
0110   help="If present, segdiff plots will be created",
0111   action="store_true",
0112   default=False,
0113   dest="segdiff")
0114 
0115 parser.add_option("--curvature",
0116   help="If present, curvature plots will be created",
0117   action="store_true",
0118   default=False,
0119   dest="curvature")
0120 
0121 parser.add_option("--fit",
0122   help="If present, fit functions plots will be created",
0123   action="store_true",
0124   default=False,
0125   dest="fit")
0126 
0127 parser.add_option("--median",
0128   help="If present, median plots will be created",
0129   action="store_true",
0130   default=False,
0131   dest="median")
0132 
0133 parser.add_option("--diagnostic",
0134   help="If present, will run diagnostic checks",
0135   action="store_true",
0136   default=False,
0137   dest="diagnostic")
0138 
0139 parser.add_option("-v", "--verbose",
0140   help="Degree of debug info verbosity",
0141   type="int",
0142   default=0,
0143   dest="verbose")
0144 
0145 options,args=parser.parse_args()
0146 
0147 if options.runLabel=='' or options.inputDir=='' or options.i1=='' or options.iN=='':
0148     print("\nOne or more of REQUIRED options is missing!\n")
0149     parser.print_help()
0150     # See \n"+sys.argv[0]+" --help"
0151     sys.exit()
0152 
0153 outdir = options.outputDir
0154 if outdir=='': outdir = options.inputDir
0155 
0156 i1prefix = options.i1prefix
0157 if i1prefix=='' : i1prefix = options.i1
0158 
0159 iNprefix = options.iNprefix
0160 if iNprefix=='' : iNprefix = options.iN
0161 
0162 if not os.access(outdir,os.F_OK):
0163     print("\noutDir = "+outdir+"\ndoes not exist! Exiting...")
0164     sys.exit()
0165 
0166 # If neither --dt or --csc is present, plots for both systems will be created
0167 DO_DT  = False
0168 DO_CSC = False
0169 if options.dt or not ( options.dt or options.csc):
0170     DO_DT = True
0171 if options.csc or not ( options.dt or options.csc):
0172     DO_CSC = True
0173 
0174 if not (options.all or options.map or options.curvature or options.segdiff or options.fit or options.median or options.diagnostic):
0175     print("\nOptions must include either -a or any of the following: --map, --segdiff, --fit, --median, --diagnostic. Exiting...")
0176     sys.exit()
0177 
0178 SINGLE_ITERATION = False
0179 if i1prefix == iNprefix: SINGLE_ITERATION = True
0180 
0181 DO_MAP = False
0182 DO_SEGDIFF = False
0183 DO_CURVATURE = False
0184 DO_FIT = False
0185 DO_MEDIAN = False
0186 if options.map or options.all:
0187     DO_MAP = True
0188 if options.segdiff or options.all:
0189     DO_SEGDIFF = True
0190 if options.curvature or options.all:
0191     DO_CURVATURE = True
0192 if options.fit or options.all:
0193     DO_FIT = True
0194 if options.median or options.all:
0195     DO_MEDIAN = True
0196 
0197 DO_DIAGNOSTIC = options.diagnostic
0198 
0199 allOptions = "-l "+options.runLabel+" -i "+options.inputDir+" --i1 "+options.i1+" --iN "+options.iN
0200 if options.i1prefix !='': allOptions += " --i1prefix " + options.i1prefix
0201 if options.iNprefix !='': allOptions += " --iNprefix " + options.iNprefix
0202 allOptions += " -o "+options.outputDir
0203 if options.createDirSructure: allOptions += " --createDirSructure"
0204 if DO_DT: allOptions += " --dt"
0205 if DO_CSC: allOptions += " --csc"
0206 if options.all: allOptions += " -a"
0207 if options.map: allOptions += " --map"
0208 if options.segdiff: allOptions += " --segdiff"
0209 if options.curvature: allOptions += " --curvature"
0210 if options.fit: allOptions += " --fit"
0211 if options.median: allOptions += " --median"
0212 if options.diagnostic: allOptions += " --diagnostic"
0213 print(sys.argv[0]+" "+allOptions)
0214 
0215 
0216 QUICKTESTN=10000
0217 
0218 
0219 
0220 ######################################################
0221 
0222 # template for canvases list
0223 CANVASES_LIST_TEMPLATE = [
0224 ['Common',' ',
0225  ['medians distribution','medians.png']
0226 ],
0227 ['DT',' ',
0228  ['Wheel&Station: map of dxdz residual vs phi','map_DTvsphi_dxdz.png'],
0229  ['Wheel&Station: map of dydz residual vs phi','map_DTvsphi_dydz.png'],
0230  ['Wheel&Station: map of x residual vs phi','map_DTvsphi_x.png'],
0231  ['Wheel&Station: map of y residual vs phi','map_DTvsphi_y.png'],
0232  ['Station&Sector: map of dxdz residual vs z','map_DTvsz_dxdz.png'],
0233  ['Station&Sector: map of dydz residual vs z','map_DTvsz_dydz.png'],
0234  ['Station&Sector: map of x residual vs z','map_DTvsz_x.png'],
0235  ['Station&Sector: map of y residual vs z','map_DTvsz_y.png'],
0236  ['Station: map of dxdz residual vs z','map_DTvsz_all_dxdz.png'],
0237  ['Station: map of dydz residual vs z','map_DTvsz_all_dydz.png'],
0238  ['Station: map of x residual vs z','map_DTvsz_all_x.png'],
0239  ['Station: map of y residual vs z','map_DTvsz_all_y.png'],
0240  ['Wheel: segdiff in x residuals vs phi','segdifphi_dt13_resid.png'],
0241  ['Wheel: segdiff in dxdz residuals vs phi','segdifphi_dt13_slope.png'],
0242  ['Wheel: segdiff in y residuals vs phi','segdifphi_dt2_resid.png'],
0243  ['Wheel: segdiff in dydz residuals vs phi','segdifphi_dt2_slope.png'],
0244  ['Wheel: segdiff DT-CSC in x residuals vs phi','segdifphi_x_dt_csc_resid.png'],
0245  ['Chamber: segdiff in x residuals','segdif_dt13_resid.png'],
0246  ['Chamber: segdiff in dxdz residuals','segdif_dt13_slope.png'],
0247  ['Chamber: segdiff in y residuals','segdif_dt2_resid.png'],
0248  ['Chamber: segdiff in dydz residuals','segdif_dt2_slope.png'],
0249  ['Chamber: segdiff DT-CSC in x residuals','segdif_x_dt_csc_resid.png'],
0250  ['Chamber: residuals distributions','dt_bellcurves.png'],
0251  ['Chamber: residuals relations to misalignments','dt_polynomials.png'],
0252  ['Chamber: Delta x residuals vs. curvature','dt_curvature_deltax.png'],
0253  ['Chamber: Delta dxdz residuals vs. curvature','dt_curvature_deltadxdz.png'],
0254  ['Extras: Extra plots in a separate window','dt_extras.php']
0255 ],
0256 ['CSC',' ',
0257  ['Station&Ring: map of d(rphi)/dz residual vs phi','map_CSCvsphi_dxdz.png'],
0258  ['Station&Ring: map of rphi residual vs phi','map_CSCvsphi_x.png'],
0259  ['Station&Chamber: map of d(rphi)/dz residual vs r','map_CSCvsr_dxdz.png'],
0260  ['Station&Chamber: map of rphi residual vs r','map_CSCvsr_x.png'],
0261  ['Station: map of d(rphi)/dz residual vs r','map_CSCvsr_all_dxdz.png'],
0262  ['Station: map of rphi residual vs r','map_CSCvsr_all_x.png'],
0263  ['Station: segdiff in rphi residuals vs phi','segdifphi_csc_resid.png'],
0264  ['Station: segdiff in d(rphi)/dz residuals vs phi','segdifphi_csc_slope.png'],
0265  ['Chamber: segdiff in rphi residuals','segdif_csc_resid.png'],
0266  ['Chamber: segdiff in d(rphi)/dz residuals','segdif_csc_slope.png'],
0267  ['Chamber: residuals distributions','csc_bellcurves.png'],
0268  ['Chamber: residuals relations to misalignments','csc_polynomials.png'],
0269  #['Chamber: Delta rphi residuals vs. curvature','csc_curvature_x.png'],
0270  #['Chamber: Delta d(rphi)/dz residuals vs. curvature','csc_curvature_dxdz.png'],
0271  ['Extras: Extra plots in a separate window','csc_extras.php']
0272 ]
0273 ]
0274 
0275 
0276 ######################################################
0277 # functions definitions
0278 
0279 
0280 def isFileUnderDir(dir_name, file_name):
0281     '''Recursively looks for file named file_name under dir_name directory
0282     '''
0283     if not DO_DT and dir_name.find("MB")>-1:
0284         return False
0285     if not DO_CSC and dir_name.find("ME")>-1:
0286         return False
0287 
0288     for f in os.listdir(dir_name):
0289         dirfile = os.path.join(dir_name, f)
0290         if os.path.isfile(dirfile) and f==file_name:
0291             return True
0292         # recursively access file names in subdirectories
0293         elif os.path.isdir(dirfile):
0294             #print "Accessing directory:", dirfile
0295             if isFileUnderDir(dirfile, file_name): return True
0296     return False
0297 
0298 
0299 # to time saving of plots
0300 def saveAs(nm): 
0301     t1 = time.time()
0302     ddt[15] += 1
0303     c1.SaveAs(nm)
0304     tn = time.time()
0305     ddt[16] = 1./ddt[15]*((ddt[15]-1)*ddt[16] + tn-t1)
0306 
0307 
0308 def createDirectoryStructure(iteration_name):
0309 
0310     if not os.access(iteration_name,os.F_OK):
0311         os.mkdir(iteration_name)
0312 
0313     csc_basedir = iteration_name+'/'
0314     for endcap in CSC_TYPES:
0315         #print csc_basedir+endcap[0]
0316         shutil.rmtree(csc_basedir+endcap[0],True)
0317         os.mkdir(csc_basedir+endcap[0])
0318         for station in endcap[2]:
0319             #print csc_basedir+endcap[0]+'/'+station[1]
0320             os.mkdir(csc_basedir+endcap[0]+'/'+station[1])
0321             for ring in station[2]:
0322                 #print csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
0323                 os.mkdir(csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1])
0324                 for chamber in range(1,ring[2]+1):
0325                     schamber = "%02d" % chamber
0326                     #print csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
0327                     os.mkdir(csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber)
0328 
0329     dt_basedir = iteration_name+'/MB/'
0330     #print dt_basedir
0331     shutil.rmtree(dt_basedir,True)
0332     os.mkdir(dt_basedir)
0333     for wheel in DT_TYPES:
0334         #print dt_basedir+wheel[0]
0335         os.mkdir(dt_basedir+wheel[0])
0336         for station in wheel[2]:
0337             #print dt_basedir+wheel[0]+'/'+station[1]
0338             os.mkdir(dt_basedir+wheel[0]+'/'+station[1])
0339             for sector in range(1,station[2]+1):
0340                 ssector = "%02d" % sector
0341                 #print dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
0342                 os.mkdir(dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector)
0343 
0344     print(os.getcwd())
0345 
0346 ######################################################
0347 
0348 def doMapPlotsDT(dt_basedir, tfiles_plotting):
0349     """write DT map plots
0350 
0351    "DTvsphi_st%dwh%s" % (station, wheelletter):
0352 
0353     plots "integrated" over ALL SECTORS:
0354     of x, y, dxdz, dydz vs. phi (y and dydz only for stations 1-3)
0355     made for all (station,wheel) combinations
0356 
0357     Access interface may be arranged into station(1 .. 4) vs. wheel(-2 .. +2) map.
0358     It could be incorporated into a general DT chambers map (column1: wheel, column2: station,
0359     columns3-16 correspond to sector #) by making station numbers in column 2 clickable.
0360 
0361 
0362    "DTvsz_st%dsec%02d" % (station, sector)
0363 
0364     plots "integrated" over ALL WHEELS:
0365     of x, y, dxdz, dydz vs. z (y and dydz only for stations 1-3)
0366     made for all (station,sector) combinations
0367 
0368     Interface: may be arranged into station(1 .. 4) vs. sector(1 .. 14) map with sector range
0369     (1 .. 12) for stations 1-3.
0370     It could be incorporated into an EXTENDED general DT chambers map (extended by adding an
0371     identifier "ALL" in column1 for wheel number).
0372 
0373 
0374    "DTvsz_st%dsecALL" % (station)
0375 
0376     plots spanning in z over ALL WHEELS and "integrated" over all sectors:
0377     of x, y, dxdz, dydz vs. z (y and dydz only for stations 1-3)
0378     made for all stations
0379 
0380     Interface: may be arranged into station(1 .. 4) map 
0381     It could be incorporated into an EXTENDED general DT chambers map (extended by adding an
0382     identifier "ALL" in column1 for wheel number)."""
0383 
0384 
0385     for wheel in DT_TYPES:
0386         if wheel[1]=="ALL": continue
0387         for station in wheel[2]:
0388             pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'
0389             label = "DTvsphi_st%dwh%s" % (int(station[1]), wheelLetter(int(wheel[1])))
0390             htitle = "wheel %+d, station %s" % (int(wheel[1]), station[1])
0391             #mapplot(tfiles_plotting, label, "x", window=25., title=htitle, fitsawteeth=True,fitsine=True)
0392             mapplot(tfiles_plotting, label, "x", window=10., title=htitle, fitsine=True,fitpeaks=True,peaksbins=2)
0393             c1.SaveAs(pdir+'map_DTvsphi_x.png')
0394             #mapplot(tfiles_plotting, label, "dxdz", window=25., title=htitle, fitsawteeth=True,fitsine=True)
0395             mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle,peaksbins=2)
0396             c1.SaveAs(pdir+'map_DTvsphi_dxdz.png')
0397 
0398             if station[1]=='4': continue
0399             #mapplot(tfiles_plotting, label, "y", window=25., title=htitle, fitsawteeth=True,fitsine=True)
0400             mapplot(tfiles_plotting, label, "y", window=10., title=htitle,peaksbins=2)
0401             c1.SaveAs(pdir+'map_DTvsphi_y.png')
0402             #mapplot(tfiles_plotting, label, "dydz", window=25., title=htitle, fitsawteeth=True,fitsine=True)
0403             mapplot(tfiles_plotting, label, "dydz", window=10., title=htitle,peaksbins=2)
0404             c1.SaveAs(pdir+'map_DTvsphi_dydz.png')
0405 
0406 
0407     qcount=0
0408     for wheel in DT_TYPES:
0409         if wheel[1]!="ALL": continue
0410         for station in wheel[2]:
0411             for sector in range(1,station[2]+1):
0412                 if qcount>QUICKTESTN: break
0413                 qcount += 1
0414                 ssector = "%02d" % sector
0415                 pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
0416                 label = "DTvsz_st%ssec%s" % (station[1], ssector)
0417                 htitle = "station %s, sector %d" % (station[1], sector)
0418                 mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2)
0419                 c1.SaveAs(pdir+'map_DTvsz_x.png')
0420                 mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2)
0421                 c1.SaveAs(pdir+'map_DTvsz_dxdz.png')
0422 
0423                 if station[1]=='4': continue
0424                 mapplot(tfiles_plotting, label, "y", window=10., title=htitle, peaksbins=2)
0425                 c1.SaveAs(pdir+'map_DTvsz_y.png')
0426                 mapplot(tfiles_plotting, label, "dydz", window=10., title=htitle, peaksbins=2)
0427                 c1.SaveAs(pdir+'map_DTvsz_dydz.png')
0428 
0429     qcount=0
0430     for wheel in DT_TYPES:
0431         if wheel[1]!="ALL": continue
0432         for station in wheel[2]:
0433             if qcount>QUICKTESTN: break
0434             qcount += 1
0435             pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'
0436             label = "DTvsz_st%ssecALL" % (station[1])
0437             htitle = "station %s" % (station[1])
0438 
0439             print(label, end=' ') 
0440             mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2)
0441             c1.SaveAs(pdir+'map_DTvsz_all_x.png')
0442             mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2)
0443             c1.SaveAs(pdir+'map_DTvsz_all_dxdz.png')
0444 
0445             if station[1]=='4': continue
0446             mapplot(tfiles_plotting, label, "y", window=10., title=htitle, peaksbins=2)
0447             c1.SaveAs(pdir+'map_DTvsz_all_y.png')
0448             mapplot(tfiles_plotting, label, "dydz", window=10., title=htitle, peaksbins=2)
0449             c1.SaveAs(pdir+'map_DTvsz_all_dydz.png')
0450 
0451     saveTestResultsMap(options.runLabel)
0452 
0453 
0454 def doMapPlotsCSC(csc_basedir, tfiles_plotting):
0455     """write CSC map plots
0456 
0457    "CSCvsphi_me%s%d%d" % (endcap, station, ring)
0458 
0459     plots "integrated" over ALL SECTORS:
0460     of rphi, drphi/dz vs. phi
0461     made for all (endcap,station,ring) combinations
0462 
0463     Interface: may be arranged into two station(1 .. 4) vs. R(1 .. 4) maps for both endcaps
0464     with R range (1 .. 4) for stations 2-4
0465    It could be incorporated into a general CSC chambers map (column1: endcap, column2: station,
0466     column3: ring, columns4-40 correspond to chamber #) by making ring numbers in column 3
0467     clickable.
0468 
0469 
0470    "CSCvsr_me%s%dch%02d" % (endcap, station, chamberNumber)
0471 
0472     plots "integrated" over ALL RINGS:
0473     of rphi, drphi/dz vs. z
0474     made for all (endcap,station,chamber) combinations
0475 
0476     Interface: may be arranged into two station(1 .. 4) vs. chamber(1 .. 36) maps for both endcaps
0477     It could be incorporated into an EXTENDED general CSC chambers map (extended by adding an
0478     identifier "ALL" in column3 for ring number).
0479 
0480    "CSCvsr_me%s%dchALL" % (endcap, station)
0481 
0482     plots spanning over ALL RINGS along r and integrated over all SECTORS:
0483     of rphi, drphi/dz vs. z
0484     made for all (endcap,station) combinations
0485 
0486     Interface: may be arranged into two station(1 .. 4) maps for both endcaps
0487     It could be incorporated into an EXTENDED general CSC chambers map (extended by adding an
0488     identifier "ALL" in column3 for ring number)."""
0489 
0490     for endcap in CSC_TYPES:
0491         for station in endcap[2]:
0492             for ring in station[2]:
0493                 if ring[1]=="ALL": continue
0494                 pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'
0495                 label = "CSCvsphi_me%s%s%s" % (endcap[1], station[1], ring[1])
0496                 htitle = "%s%s/%s" % (endcap[0], station[1],ring[1])
0497                 mapplot(tfiles_plotting, label, "x", window=15., title=htitle, fitsine=True,fitpeaks=True, peaksbins=2)
0498                 #mapplot(tfiles_plotting, label, "x", window=15., title=htitle, fitsine=True)
0499                 c1.SaveAs(pdir+'map_CSCvsphi_x.png')
0500                 mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle, peaksbins=2)
0501                 c1.SaveAs(pdir+'map_CSCvsphi_dxdz.png')
0502 
0503     saveTestResultsMap(options.runLabel)
0504 
0505     qcount = 0
0506     for endcap in CSC_TYPES:
0507         for station in endcap[2]:
0508             for ring in station[2]:
0509                 if ring[1]!="ALL": continue
0510                 for chamber in range(1,ring[2]+1):
0511                     if qcount>QUICKTESTN: break
0512                     qcount += 1
0513                     schamber = "%02d" % chamber
0514                     pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber+'/'
0515                     label = "CSCvsr_me%s%sch%s" % (endcap[1], station[1], schamber)
0516                     htitle = "%s%s/ALL/%d" % (endcap[0], station[1],chamber)
0517                     mapplot(tfiles_plotting, label, "x", window=15., title=htitle, peaksbins=2)
0518                     c1.SaveAs(pdir+'map_CSCvsr_x.png')
0519                     mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle, peaksbins=2)
0520                     c1.SaveAs(pdir+'map_CSCvsr_dxdz.png')
0521 
0522     qcount = 0
0523     for endcap in CSC_TYPES:
0524         for station in endcap[2]:
0525             for ring in station[2]:
0526                 if ring[1]!="ALL": continue
0527                 if qcount>QUICKTESTN: break
0528                 qcount += 1
0529                 schamber = "%02d" % chamber
0530                 pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'
0531                 label = "CSCvsr_me%s%schALL" % (endcap[1], station[1])
0532                 htitle = "%s%s" % (endcap[0], station[1])
0533                 mapplot(tfiles_plotting, label, "x", window=10., title=htitle, peaksbins=2)
0534                 c1.SaveAs(pdir+'map_CSCvsr_all_x.png')
0535                 mapplot(tfiles_plotting, label, "dxdz", window=10., title=htitle, peaksbins=2)
0536                 c1.SaveAs(pdir+'map_CSCvsr_all_dxdz.png')
0537 
0538 
0539 
0540 def doCurvaturePlotsDT(dt_basedir, tfiles_plotting):
0541     """write DT curvature plots
0542 
0543     "wheel%s_sector%s" % (wheel, sector)
0544 
0545     wheel in "m2", "m1", "z", "p1", "p2"
0546     station 1 only!
0547     sector in "01", ..., "12"
0548 
0549     "param" may be one of 
0550       "deltax" (Delta x position residuals),
0551       "deltadxdz" (Delta (dx/dz) angular residuals),
0552       "curverr" (Delta x * d(Delta q/pT)/d(Delta x) = Delta q/pT in the absence of misalignment) - not necessary
0553 
0554     made for all (wheel,station=1,sector) combinations
0555 
0556     Interface: could be accesses through a general DT chambers map for station=1 chambers."""
0557 
0558     w_dict = {'-2':'m2', '-1':'m1', '0':'z', '1':'p1', '2':'p2'}
0559     qcount = 0
0560     for wheel in DT_TYPES:
0561         if wheel[1]=="ALL": continue
0562         #station = 1
0563         #station = wheel[2][0]
0564         for station in wheel[2]:
0565             print("curv in ", wheel[0]+'/'+station[1])
0566             for sector in range(1,station[2]+1):
0567                 #if sector>12: break
0568                 if qcount>QUICKTESTN: break
0569                 qcount += 1
0570                 ssector = "%02d" % sector
0571                 pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
0572                 label = "wheel%s_st%s_sector%s" % (w_dict[wheel[1]], station[1], ssector)
0573                 thetitle ="Wheel %s, station %s, sector %s" % (wheel[1], station[1], ssector)
0574                 curvatureplot(tfiles_plotting, label, "deltax", title=thetitle, window=10., fitline=True)
0575                 saveAs(pdir+'dt_curvature_deltax.png')
0576                 curvatureplot(tfiles_plotting, label, "deltadxdz", title=thetitle, window=10., fitline=True)
0577                 saveAs(pdir+'dt_curvature_deltadxdz.png')
0578 
0579 
0580 
0581 def doSegDiffPlotsDT(dt_basedir, tfiles_plotting, iter_reports):
0582     """write segment-difference plots for DT
0583 
0584    segdiff "dt13_resid" and "dt13_slope"
0585 
0586     set of plots of
0587     x vs qpt, x for positive, x for negative ("dt13_resid")
0588     dxdz vs qpt, dxdz for positive, dxdz for negative ("dt13_slope")
0589     done for MB1-MB2, MB2-MB3, and MB3-MB4 stations combinations with all possible (wheel, sector)
0590 
0591     Interface: could be accessed through a general DT chambers map, but only for chambers in
0592     stations 2-4 (e.g., station 2 would provide MB1-MB2 plots).
0593 
0594    segdiff "dt2_resid" and "dt2_slope"
0595 
0596     set of plots of
0597     y vs q/pt, y for positive, y for negative ("dt2_resid")
0598     dydz vs q/pt, dydz for positive, dydz for negative ("dt2_slope")
0599     done for MB1-MB2, MB2-MB3 stations combinations with all possible (wheel, sector)
0600 
0601     Interface: then the interface would still be a general DT map,
0602     but the info only available from station 2 & 3 chambers."""
0603 
0604     qcount = 0
0605     for iwheel in DT_TYPES:
0606         if iwheel[1]=="ALL": continue
0607         for istation in iwheel[2]:
0608             if istation[1]=="1": continue
0609             dstations = (int(istation[1])-1)*10 + int(istation[1])
0610             #print dstations
0611             for isector in range(1, istation[2] + 1):
0612                 if isector > 12: continue
0613                 if qcount>QUICKTESTN: break
0614                 qcount += 1
0615                 ssector = "%02d" % isector
0616                 pdir = dt_basedir + '/' + iwheel[0] + '/' + istation[1] + '/' + ssector + '/'
0617 
0618                 segdiff(tfiles_plotting, "dt13_resid", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
0619                 c1.SaveAs(pdir + 'segdif_dt13_resid.png')
0620                 segdiff(tfiles_plotting, "dt13_slope", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
0621                 c1.SaveAs(pdir + 'segdif_dt13_slope.png')
0622 
0623                 if istation[1] != '4':
0624                     segdiff(tfiles_plotting, "dt2_resid", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
0625                     c1.SaveAs(pdir + 'segdif_dt2_resid.png')
0626                     segdiff(tfiles_plotting, "dt2_slope", dstations, wheel=int(iwheel[1]), sector=isector, window=15.)
0627                     c1.SaveAs(pdir + 'segdif_dt2_slope.png')
0628 
0629     qcount = 0
0630     for iwheel in DT_TYPES:
0631         if iwheel[1]=="ALL": continue
0632         if abs(int(iwheel[1])) != 2: continue
0633         for istation in iwheel[2]:
0634             if istation[1]=="3": continue
0635             #print dstations
0636             for isector in range(1, istation[2] + 1):
0637                 ssector = "%02d" % isector
0638                 pdir = dt_basedir + '/' + iwheel[0] + '/' + istation[1] + '/' + ssector + '/'
0639                 if istation[1]=="1":
0640                     segdiff_xalign(tfiles_plotting, "x_dt1_csc", wheel=int(iwheel[1]), sector=isector, cscstations = "12")
0641                     c1.SaveAs(pdir + 'segdif_x_dt_csc_resid.png')
0642                 if istation[1]=="2":
0643                     segdiff_xalign(tfiles_plotting, "x_dt2_csc", wheel=int(iwheel[1]), sector=isector, cscstations = "1")
0644                     c1.SaveAs(pdir + 'segdif_x_dt_csc_resid.png')
0645 
0646     """segdiffvsphi "dt13_resid" and "dt13_slope"
0647 
0648   plot for a specific wheel #:
0649   x vs phi of pair ("dt13_resid")
0650   dxdz vs phi of pair ("dt13_slope")
0651   contains all three combinations of neighboring stations
0652   made for all possible wheel values
0653 
0654   Interface: could be accessed by clicking on wheel number under the "wheel" column
0655   in a general DT map
0656 
0657  segdiffvsphi "dt2_resid" and "dt2_slope"
0658 
0659   plot for a specific wheel #:
0660   y vs phi of pair ("dt2_resid")
0661   dydz vs phi of pair ("dt2_slope")
0662   contains both MB1-MB2 and MB2-MB3 combinations
0663   made for all possible wheel values
0664 
0665   Interface: could be accessed by clicking on wheel number under the "wheel" column
0666   in a general DT map"""
0667 
0668     if len(iter_reports)==0: return
0669 
0670     for iwheel in DT_TYPES:
0671         if iwheel[1]=="ALL": continue
0672         pdir = dt_basedir + '/' + iwheel[0] + '/'
0673         segdiffvsphi(tfiles_plotting, iter_reports, "dt13_resid", int(iwheel[1]), window=10.)#, excludesectors=(1,7))
0674         c1.SaveAs(pdir + 'segdifphi_dt13_resid.png')
0675         segdiffvsphi(tfiles_plotting, iter_reports, "dt13_slope", int(iwheel[1]), window=10.)#, excludesectors=(1,7))
0676         c1.SaveAs(pdir + 'segdifphi_dt13_slope.png')
0677         segdiffvsphi(tfiles_plotting, iter_reports, "dt2_resid", int(iwheel[1]), window=10.)#, excludesectors=(1,7))
0678         c1.SaveAs(pdir + 'segdifphi_dt2_resid.png')
0679         segdiffvsphi(tfiles_plotting, iter_reports, "dt2_slope", int(iwheel[1]), window=15.)#, excludesectors=(1,7))
0680         c1.SaveAs(pdir + 'segdifphi_dt2_slope.png')
0681 
0682     for iwheel in DT_TYPES:
0683         if iwheel[1]=="ALL": continue
0684         if abs(int(iwheel[1])) != 2: continue
0685         pdir = dt_basedir + '/' + iwheel[0] + '/'
0686         segdiffvsphi_xalign(tfiles_plotting, int(iwheel[1]), window=10.)
0687         c1.SaveAs(pdir + 'segdifphi_x_dt_csc_resid.png')
0688 
0689 
0690 def doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports):
0691     """write segment-difference plots for CSC
0692 
0693    segdiff "csc_resid" and "csc_slope"
0694 
0695     set of plots of
0696     rphi vs qpt, rphi for positive, rphi for negative ("csc_resid")
0697     drphidz vs qpt, drphidz for positive, drphidz for negative ("csc_slope")
0698     done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with
0699       endcap "m" or "p" 
0700       ring 1 or 2
0701       chamber 1-18 (r1) or 1-36 (r2)
0702     note: there's no ME3-ME4 plots for R2
0703 
0704     Interface: could be accessed through a general CSC chambers map, but only for chambers in
0705     stations 2-4 (e.g., station 2 would provide ME1-ME2 plots)."""
0706 
0707     qcount = 0
0708     for iendcap in CSC_TYPES:
0709         for istation in iendcap[2]:
0710             if istation[1]=="1": continue
0711             dstations = (int(istation[1])-1)*10 + int(istation[1])
0712             for iring in istation[2]:
0713                 if iring[1]=="ALL": continue
0714                 if istation[1]=="4" and iring[1]=="2": continue
0715                 for ichamber in range(1,iring[2]+1):
0716                     if qcount>QUICKTESTN: break
0717                     qcount += 1
0718                     schamber = "%02d" % ichamber
0719                     pdir = csc_basedir+'/'+iendcap[0]+'/'+istation[1]+'/'+iring[1]+'/'+schamber+'/'
0720                     segdiff(tfiles_plotting, "csc_resid", dstations, 
0721                             endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=15.)
0722                     c1.SaveAs(pdir + 'segdif_csc_resid.png')
0723                     segdiff(tfiles_plotting, "csc_slope", dstations, 
0724                             endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=15.)
0725                     c1.SaveAs(pdir + 'segdif_csc_slope.png')
0726 
0727     """segdiffvsphicsc "csc_resid" and "csc_slope"
0728 
0729   plot for a specific deltaME station differences:
0730   rphi vs phi of pair ("csc_resid")
0731   dxdz vs phi of pair ("csc_slope")
0732   contains plots for two (or one for ME4-ME3) rings
0733   done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with
0734     endcap "m" or "p" 
0735   
0736   Interface: could be accessed by clicking on ME station boxes, but only for stations 2-4 
0737   (e.g., station 2 would provide ME1-ME2 plots)."""
0738 
0739     qcount = 0
0740     for iendcap in CSC_TYPES:
0741         for istation in iendcap[2]:
0742             if istation[1]=="1": continue
0743             dstations = (int(istation[1])-1)*10 + int(istation[1])
0744             if qcount>QUICKTESTN: break
0745             qcount += 1
0746             pdir = csc_basedir+'/'+iendcap[0]+'/'+istation[1]+'/'
0747             segdiffvsphicsc(tfiles_plotting, "csc_resid", dstations, window=10., endcap=iendcap[1])
0748             c1.SaveAs(pdir + 'segdifphi_csc_resid.png')
0749             segdiffvsphicsc(tfiles_plotting, "csc_slope", dstations, window=10., endcap=iendcap[1])
0750             c1.SaveAs(pdir + 'segdifphi_csc_slope.png')
0751 
0752 
0753 def doFitFunctionsPlotsDT(dt_basedir, iter_tfile, iter_reports):
0754     """write fit functions plots for DT
0755 
0756    DT bellcurves and polynomials
0757 
0758     set of plots of bellcurves
0759       x, dxdz, x vs. dxdz (for all 4 stations)
0760       y, dydz, x vs. dxdz (only for stations 1-3?)
0761 
0762     set of plots of polynomials -- for stations 1-3 only??
0763       x vs. xpos,    x vs ypos,    x vs dxdz angle,    x vs dydz angle
0764       y vs. xpos,    y vs ypos,    y vs dxdz angle,    y vs dydz angle
0765       dxdz vs. xpos, dxdz vs ypos, dxdz vs dxdz angle, dxdz vs dydz angle
0766       dydz vs. xpos, dydz vs ypos, dydz vs dxdz angle, dydz vs dydz angle
0767 
0768     set of plots of polynomials -- for station 4 only??
0769       x vs. xpos,    x vs dxdz angle
0770       dxdz vs. xpos, dxdz vs dxdz angle
0771 
0772     made for all (wheel,station,sector) combinations
0773 
0774     Interface: could be accesses through a general DT chambers map."""
0775 
0776     qcount = 0
0777     clearDDT()
0778     for wheel in DT_TYPES:
0779         if wheel[1]=="ALL": continue
0780         for station in wheel[2]:
0781             print(wheel[0]+'/'+station[1])
0782             for sector in range(1,station[2]+1):
0783                 if qcount>QUICKTESTN: break
0784                 qcount += 1
0785                 ssector = "%02d" % sector
0786                 pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
0787                 label = "MBwh%sst%ssec%s" % (wheelLetter(int(wheel[1])),station[1],ssector)
0788                 bellcurves(iter_tfile, iter_reports, label, False)
0789                 #c1.SaveAs(pdir+'dt_bellcurves.png')
0790                 saveAs(pdir+'dt_bellcurves.png')
0791                 polynomials(iter_tfile, iter_reports, label, False)
0792                 #c1.SaveAs(pdir+'dt_polynomials.png')
0793                 saveAs(pdir+'dt_polynomials.png')
0794     #printDeltaTs()
0795 
0796 
0797 def doFitFunctionsPlotsCSC(csc_basedir, iter_tfile, iter_reports):
0798     """write fit functions plots for CSC
0799 
0800    CSC bellcurves and polynomials
0801 
0802     set of plots of bellcurves
0803       rphi, drphidz, rphi vs. drphidz
0804 
0805     set of plots of polynomials
0806       rphi vs. rphi pos,    rphi vs drphidz angle
0807       drphidz vs. rphi pos, drphidz vs drphidz angle
0808 
0809     made for all (endcap,station,ring,chamber) combinations
0810 
0811     Interface: could be accesses through a general CSC chambers map."""
0812 
0813     qcount = 0
0814     clearDDT()
0815     for endcap in CSC_TYPES:
0816         for station in endcap[2]:
0817             for ring in station[2]:
0818                 if ring[1]=="ALL": continue
0819                 print(endcap[0]+'/'+station[1]+'/'+ring[1])
0820                 for chamber in range(1,ring[2]+1):
0821                     if qcount>QUICKTESTN: break
0822                     qcount += 1
0823                     schamber = "%02d" % chamber
0824                     pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber+'/'
0825                     label = "ME%s%s%s_%s" % (endcap[1], station[1], ring[1], schamber)
0826                     bellcurves(iter_tfile, iter_reports, label, False)
0827                     #c1.SaveAs(pdir+'csc_bellcurves.png')
0828                     saveAs(pdir+'csc_bellcurves.png')
0829                     polynomials(iter_tfile, iter_reports, label, False)
0830                     #c1.SaveAs(pdir+'csc_polynomials.png')
0831                     saveAs(pdir+'csc_polynomials.png')
0832     #printDeltaTs()
0833 
0834 
0835 
0836 def doIterationPlots(iteration_directory, tfiles_plotting, iter_tfile, iter_reports):
0837     dt_basedir = iteration_directory+'/'+'MB'
0838     csc_basedir = iteration_directory+'/'
0839 
0840     if DO_DT and DO_MAP:
0841         doMapPlotsDT(dt_basedir, tfiles_plotting)
0842     if DO_CSC and DO_MAP:
0843         doMapPlotsCSC(csc_basedir, tfiles_plotting)
0844 
0845     if DO_DT and DO_CURVATURE:
0846         doCurvaturePlotsDT(dt_basedir, tfiles_plotting)
0847     #if DO_CSC and DO_CURVATURE:
0848     #  doCurvaturePlotsCSC(csc_basedir, tfiles_plotting)
0849 
0850     if DO_DT and DO_SEGDIFF:
0851         doSegDiffPlotsDT(dt_basedir, tfiles_plotting, iter_reports)
0852     if DO_CSC and DO_SEGDIFF:
0853         doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports)
0854 
0855     if DO_DT and DO_FIT:
0856         doFitFunctionsPlotsDT(dt_basedir, iter_tfile, iter_reports)
0857     if DO_CSC and DO_FIT:
0858         doFitFunctionsPlotsCSC(csc_basedir, iter_tfile, iter_reports)
0859 
0860 
0861 def createCanvasesList(fname="canvases_list.js"):
0862     '''Use CANVASES_LIST_TEMPLATE as a template to create a canvases list include for the browser.
0863        Write out only those canvases which have existing filename.png plots.
0864     '''
0865     CANVASES_LIST = []
0866     for scope in CANVASES_LIST_TEMPLATE:
0867         scope_entry = []
0868         if len(scope)>2:
0869             scope_entry = [scope[0],scope[1]]
0870             for canvas_entry in scope[2:]:
0871                 if isFileUnderDir("./",canvas_entry[1]):
0872                     scope_entry.append(canvas_entry)
0873         CANVASES_LIST.append(scope_entry)
0874 
0875     ff = open(fname,mode="w")
0876     print("var CANVASES_LIST = ", file=ff)
0877     json.dump(CANVASES_LIST,ff)
0878     ff.close()
0879 
0880 
0881 def createCanvasToIDList(fname="canvas2id_list.js"):
0882     '''Writes out a canvas-2-ids list include for the browser.
0883        Write out only those canvases which have existing filename.png plots.
0884        Returns: list of unique IDs that have existing filename.png plots.
0885     '''
0886     CANVAS2ID_LIST = []
0887     ID_LIST = []
0888     for scope in CANVASES_LIST_TEMPLATE:
0889         if len(scope)>2:
0890             for canvas_entry in scope[2:]:
0891                 ids = idsForFile("./",canvas_entry[1])
0892                 #  scope_entry.append(canvas_entry)
0893                 # uniquify:
0894                 set_ids = set(ids)
0895                 uids = list(set_ids)
0896                 ID_LIST.extend(uids)
0897                 print(canvas_entry, ":", len(uids), "ids")
0898                 if (len(uids)>0):
0899                     CANVAS2ID_LIST.append( (canvas_entry[1],uids) )
0900     #print CANVAS2ID_LIST
0901     CANVAS2ID_LIST_DICT = dict(CANVAS2ID_LIST)
0902     #print CANVAS2ID_LIST_DICT
0903     ff = open(fname,mode="w")
0904     print("var CANVAS2ID_LIST = ", file=ff)
0905     json.dump(CANVAS2ID_LIST_DICT,ff)
0906     ff.close()
0907     set_ids = set(ID_LIST)
0908     return list(set_ids)
0909 
0910 def idsForFile(dir_name, file_name):
0911     '''Recursively looks for file named file_name under dir_name directory
0912     and fill the list with dir names converted to IDs 
0913     '''
0914     id_list = []
0915     for f in os.listdir(dir_name):
0916         dirfile = os.path.join(dir_name, f)
0917         if os.path.isfile(dirfile) and f==file_name:
0918             if file_name[-4:]=='.php': id_list.append(dir_name+'/'+file_name)
0919             else:    id_list.append(dirToID(dir_name))
0920         # recursively access file names in subdirectories
0921         elif os.path.isdir(dirfile):
0922             #print "Accessing directory:", dirfile
0923             ids = idsForFile(dirfile, file_name)
0924             if (len(ids)>0): 
0925                 id_list.extend(ids)
0926     return id_list
0927 
0928 
0929 def dirToID(d):
0930     if d[-1]!='/': d += '/'
0931     dtn = d.find("/MB/")
0932     if dtn!=-1:
0933         return d[dtn+4:-1]
0934     cscn = d.find("/ME-/")
0935     if cscn!=-1:
0936         return 'ME-'+d[cscn+5:-1]
0937     cscn = d.find("/ME+/")
0938     if cscn!=-1:
0939         return 'ME+'+d[cscn+5:-1]
0940     return ''
0941 
0942 
0943 ############################################################################################################
0944 ############################################################################################################
0945 # main script
0946 
0947 # open input files:
0948 
0949 #basedir='/disks/sdb5/home_reloc/khotilov/db/cms/alignment'
0950 #iteration1 = "iteration_01"
0951 #iteration3 = "iteration_03"
0952 #iteration1 = "NOV4DT_PASS3noweight_TkHIP_01"
0953 #iteration3 = "NOV4DT_PASS3noweight_TkHIP_05"
0954 #os.chdir(options.inputDir)
0955 #iteration1 = options.i1
0956 #iteration3 = options.iN
0957 
0958 fname = options.inputDir+'/'+options.i1+'/'+i1prefix
0959 tfiles1_plotting = []
0960 iter1_tfile = None
0961 iter1_reports = []
0962 if not SINGLE_ITERATION:
0963     if (DO_MAP or DO_SEGDIFF or DO_CURVATURE) and not os.access(fname+"_plotting.root",os.F_OK):
0964         print("no file "+fname+"_plotting.root")
0965         sys.exit()
0966     if DO_FIT and not os.access(fname+".root",os.F_OK):
0967         print("no file "+fname+".root")
0968         sys.exit()
0969     if DO_MEDIAN and not os.access(fname+"_report.py",os.F_OK):
0970         print("no file "+fname+"_report.py")
0971         sys.exit()
0972     if DO_MAP or DO_SEGDIFF or DO_CURVATURE: tfiles1_plotting.append(ROOT.TFile(fname+"_plotting.root"))
0973     if os.access(fname+".root",os.F_OK):
0974         iter1_tfile = ROOT.TFile(fname+".root")
0975     if os.access(fname+"_report.py",os.F_OK):
0976         execfile(fname+"_report.py")
0977         iter1_reports = reports
0978 
0979 fname = options.inputDir+'/'+options.iN+'/'+iNprefix
0980 tfilesN_plotting = []
0981 iterN_tfile = None
0982 iterN_reports = []
0983 if (DO_MAP or DO_SEGDIFF or DO_CURVATURE) and not os.access(fname+"_plotting.root",os.F_OK):
0984     print("no file "+fname+"_plotting.root")
0985     sys.exit()
0986 if DO_FIT and not os.access(fname+".root",os.F_OK):
0987     print("no file "+fname+".root")
0988     sys.exit()
0989 if DO_MEDIAN and not os.access(fname+"_report.py",os.F_OK):
0990     print("no file "+fname+"_report.py")
0991     sys.exit()
0992 if DO_MAP or DO_SEGDIFF or DO_CURVATURE: tfilesN_plotting.append(ROOT.TFile(fname+"_plotting.root"))
0993 if os.access(fname+".root",os.F_OK):
0994     iterN_tfile = ROOT.TFile(fname+".root")
0995 if os.access(fname+"_report.py",os.F_OK):
0996     execfile(fname+"_report.py")
0997     iterN_reports = reports
0998 
0999 if DO_MAP:
1000     os.chdir(options.inputDir)
1001     phiedges2c()
1002 
1003 ######################################################
1004 # setup output:
1005 
1006 # cd to outputDIr
1007 os.chdir(options.outputDir)
1008 
1009 comdir = "common/"
1010 iteration1 = "iter1"
1011 iterationN = "iterN"
1012 
1013 # create directory structure
1014 if options.createDirSructure:
1015     print("WARNING: all existing results in "+options.outputDir+" will be deleted!")
1016     if not SINGLE_ITERATION: createDirectoryStructure(iteration1)
1017     createDirectoryStructure(iterationN)
1018     if not os.access(comdir,os.F_OK):
1019         os.mkdir(comdir)
1020 
1021 ######################################################
1022 # do drawing
1023 
1024 c1 = ROOT.TCanvas("c1","c1",800,600)
1025 
1026 set_palette("blues")
1027 
1028 print("--- ITERATION 1 ---")
1029 if not SINGLE_ITERATION: doIterationPlots(iteration1, tfiles1_plotting, iter1_tfile, iter1_reports)
1030 print("--- ITERATION N ---")
1031 doIterationPlots(iterationN, tfilesN_plotting, iterN_tfile, iterN_reports)
1032 
1033 if CPP_LOADED: ROOT.cleanUpHeap()
1034 
1035 # write distributions of medians plots
1036 
1037 if DO_MEDIAN:
1038     #plotmedians(iter1_reports, iterN_reports)
1039     plotmedians(iter1_reports, iterN_reports,binsx=100, windowx=10., binsy=100, windowy=10., binsdxdz=100, windowdxdz=10., binsdydz=100, windowdydz=10.)
1040     c1.SaveAs(comdir+'medians.png')
1041 
1042 # perform diagnostic
1043 if DO_DIAGNOSTIC:
1044     #if not SINGLE_ITERATION: doTests(iter1_reports,"mu_list_1.js","dqm_report_1.js",options.runLabel)
1045     createCanvasesList("canvases_list.js")
1046     pic_ids = createCanvasToIDList("canvas2id_list.js")
1047     doTests(iterN_reports, pic_ids, "mu_list.js","dqm_report.js",options.runLabel)