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