CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
alignmentValidation.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 import re,os,sys,shutil
4 import optparse
5 
6 from mutypes import *
7 
8 execfile("plotscripts.py")
9 
10 ROOT.gROOT.SetBatch(1);
11 
12 ######################################################
13 
14 ######################################################
15 # To parse commandline args
16 
17 usage='%prog [options]\n'+\
18  'This script dumps muon alignment validation plots '+\
19  '(see https://twiki.cern.ch/twiki/bin/viewauth/CMS/SWGuideMuonAlignValidationPlots) '+\
20  'in web-friendly png format into a predefined directory structure '+\
21  'and also (to be implemented) does some quality checks for these plots.\n'+\
22  'Script uses output of the first and last iterations of muon alignment runs '+\
23  'that should be located in inputDir+i1 and inputDir+iN directories (see options descriptions). '+\
24  'Each of these directories should contain\ni#prefix+"_plotting.root"\ni#prefix+".root"\ni#prefix+"_report.py"\n'+\
25  'files, where # = 1 or N.\n'+\
26  'Output will be located in outputDir, which must exist. Plots from the first and last iterations '+\
27  'will be in outputDir+"iter1" and outputDir+"iterN" respectively, and plots relevant for all iterations will '+\
28  'reside in outputDir+"common/".\n'+\
29  'For a first run a --createDirSructure option must be present. If this option is present for subsequent runs '+\
30  'with the same outputDir, all previous results in "iter1", "iterN" and and "common" would be deleted!\n'+\
31  'If neither --dt or --csc is present, plots for both systems will be created.\n'+\
32  'Options must include either -a or any of the following: --map, --segdiff, --fit, --median'
33 
34 parser=optparse.OptionParser(usage)
35 
36 parser.add_option("-l", "--runLabel",
37  help="[REQUIRED] label to use for a run",
38  type="string",
39  default='',
40  dest="runLabel")
41 
42 parser.add_option("-i", "--inputDir",
43  help="[REQUIRED] input directory: should contain directories with the first and the final iterations' results",
44  type="string",
45  default='',
46  dest="inputDir")
47 
48 parser.add_option("--i1",
49  help="[REQUIRED] directory with the alignment 1st iteration's results relative to inputDir",
50  type="string",
51  default='',
52  dest="i1")
53 
54 parser.add_option("--iN",
55  help="[REQUIRED] directory with the alignment last iteration's results relative to inputDir",
56  type="string",
57  default='',
58  dest="iN")
59 
60 parser.add_option("--i1prefix",
61  help="filename prefix for the alignment 1st iteration's results. If not provided, i1prefix = i1",
62  type="string",
63  default='',
64  dest="i1prefix")
65 
66 parser.add_option("--iNprefix",
67  help="filename prefix for the alignment last iteration's results. If not provided, iNprefix = iN",
68  type="string",
69  default='',
70  dest="iNprefix")
71 
72 parser.add_option("-o", "--outputDir",
73  help="output directory: all plots will be saved with relation to outputDir. If not provided, consider outputDir = inputDir",
74  type="string",
75  default='',
76  dest="outputDir")
77 
78 parser.add_option("--createDirSructure",
79  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!",
80  action="store_true",
81  default=False,
82  dest="createDirSructure")
83 
84 parser.add_option("--dt",
85  help="If it is present, but not --csc, DT only plots will be created",
86  action="store_true",
87  default=False,
88  dest="dt")
89 
90 parser.add_option("--csc",
91  help="If this is present, but not --dt, CSC only plots will be created",
92  action="store_true",
93  default=False,
94  dest="csc")
95 
96 parser.add_option("-a","--all",
97  help="If present, all types of plots will be created",
98  action="store_true",
99  default=False,
100  dest="all")
101 
102 parser.add_option("--map",
103  help="If present, map plots will be created",
104  action="store_true",
105  default=False,
106  dest="map")
107 
108 parser.add_option("--segdiff",
109  help="If present, segdiff plots will be created",
110  action="store_true",
111  default=False,
112  dest="segdiff")
113 
114 parser.add_option("--curvature",
115  help="If present, curvature plots will be created",
116  action="store_true",
117  default=False,
118  dest="curvature")
119 
120 parser.add_option("--fit",
121  help="If present, fit functions plots will be created",
122  action="store_true",
123  default=False,
124  dest="fit")
125 
126 parser.add_option("--median",
127  help="If present, median plots will be created",
128  action="store_true",
129  default=False,
130  dest="median")
131 
132 parser.add_option("--diagnostic",
133  help="If present, will run diagnostic checks",
134  action="store_true",
135  default=False,
136  dest="diagnostic")
137 
138 parser.add_option("-v", "--verbose",
139  help="Degree of debug info verbosity",
140  type="int",
141  default=0,
142  dest="verbose")
143 
144 options,args=parser.parse_args()
145 
146 if options.runLabel=='' or options.inputDir=='' or options.i1=='' or options.iN=='':
147  print "\nOne or more of REQUIRED options is missing!\n"
148  parser.print_help()
149  # See \n"+sys.argv[0]+" --help"
150  sys.exit()
151 
152 outdir = options.outputDir
153 if outdir=='': outdir = options.inputDir
154 
155 i1prefix = options.i1prefix
156 if i1prefix=='' : i1prefix = options.i1
157 
158 iNprefix = options.iNprefix
159 if iNprefix=='' : iNprefix = options.iN
160 
161 if not os.access(outdir,os.F_OK):
162  print "\noutDir = "+outdir+"\ndoes not exist! Exiting..."
163  sys.exit()
164 
165 # If neither --dt or --csc is present, plots for both systems will be created
166 DO_DT = False
167 DO_CSC = False
168 if options.dt or not ( options.dt or options.csc):
169  DO_DT = True
170 if options.csc or not ( options.dt or options.csc):
171  DO_CSC = True
172 
173 if not (options.all or options.map or options.curvature or options.segdiff or options.fit or options.median or options.diagnostic):
174  print "\nOptions must include either -a or any of the following: --map, --segdiff, --fit, --median, --diagnostic. Exiting..."
175  sys.exit()
176 
177 SINGLE_ITERATION = False
178 if i1prefix == iNprefix: SINGLE_ITERATION = True
179 
180 DO_MAP = False
181 DO_SEGDIFF = False
182 DO_CURVATURE = False
183 DO_FIT = False
184 DO_MEDIAN = False
185 if options.map or options.all:
186  DO_MAP = True
187 if options.segdiff or options.all:
188  DO_SEGDIFF = True
189 if options.curvature or options.all:
190  DO_CURVATURE = True
191 if options.fit or options.all:
192  DO_FIT = True
193 if options.median or options.all:
194  DO_MEDIAN = True
195 
196 DO_DIAGNOSTIC = options.diagnostic
197 
198 allOptions = "-l "+options.runLabel+" -i "+options.inputDir+" --i1 "+options.i1+" --iN "+options.iN
199 if options.i1prefix !='': allOptions += " --i1prefix " + options.i1prefix
200 if options.iNprefix !='': allOptions += " --iNprefix " + options.iNprefix
201 allOptions += " -o "+options.outputDir
202 if options.createDirSructure: allOptions += " --createDirSructure"
203 if DO_DT: allOptions += " --dt"
204 if DO_CSC: allOptions += " --csc"
205 if options.all: allOptions += " -a"
206 if options.map: allOptions += " --map"
207 if options.segdiff: allOptions += " --segdiff"
208 if options.curvature: allOptions += " --curvature"
209 if options.fit: allOptions += " --fit"
210 if options.median: allOptions += " --median"
211 if options.diagnostic: allOptions += " --diagnostic"
212 print sys.argv[0]+" "+allOptions
213 
214 
215 QUICKTESTN=10000
216 
217 
218 
219 ######################################################
220 
221 # template for canvases list
222 CANVASES_LIST_TEMPLATE = [
223 ['Common',' ',
224  ['medians distribution','medians.png']
225 ],
226 ['DT',' ',
227  ['Wheel&Station: map of dxdz residual vs phi','map_DTvsphi_dxdz.png'],
228  ['Wheel&Station: map of dydz residual vs phi','map_DTvsphi_dydz.png'],
229  ['Wheel&Station: map of x residual vs phi','map_DTvsphi_x.png'],
230  ['Wheel&Station: map of y residual vs phi','map_DTvsphi_y.png'],
231  ['Station&Sector: map of dxdz residual vs z','map_DTvsz_dxdz.png'],
232  ['Station&Sector: map of dydz residual vs z','map_DTvsz_dydz.png'],
233  ['Station&Sector: map of x residual vs z','map_DTvsz_x.png'],
234  ['Station&Sector: map of y residual vs z','map_DTvsz_y.png'],
235  ['Wheel: segdiff in x residuals vs phi','segdifphi_dt13_resid.png'],
236  ['Wheel: segdiff in dxdz residuals vs phi','segdifphi_dt13_slope.png'],
237  ['Wheel: segdiff in y residuals vs phi','segdifphi_dt2_resid.png'],
238  ['Wheel: segdiff in dydz residuals vs phi','segdifphi_dt2_slope.png'],
239  ['Chamber: segdiff in x residuals','segdif_dt13_resid.png'],
240  ['Chamber: segdiff in dxdz residuals','segdif_dt13_slope.png'],
241  ['Chamber: segdiff in y residuals','segdif_dt2_resid.png'],
242  ['Chamber: segdiff in dydz residuals','segdif_dt2_slope.png'],
243  ['Chamber: residuals distributions','dt_bellcurves.png'],
244  ['Chamber: residuals relations to misalignments','dt_polynomials.png'],
245  ['Chamber: Delta x residuals vs. curvature','dt_curvature_deltax.png'],
246  ['Chamber: Delta dxdz residuals vs. curvature','dt_curvature_deltadxdz.png']
247 ],
248 ['CSC',' ',
249  ['Station&Ring: map of d(rphi)/dz residual vs phi','map_CSCvsphi_dxdz.png'],
250  ['Station&Ring: map of rphi residual vs phi','map_CSCvsphi_x.png'],
251  ['Station&Chamber: map of d(rphi)/dz residual vs r','map_CSCvsr_dxdz.png'],
252  ['Station&Chamber: map of rphi residual vs r','map_CSCvsr_x.png'],
253  ['Chamber: segdiff in rphi residuals','segdif_csc_resid.png'],
254  ['Chamber: segdiff in d(rphi)/dz residuals','segdif_csc_slope.png'],
255  ['Chamber: residuals distributions','csc_bellcurves.png'],
256  ['Chamber: residuals relations to misalignments','csc_polynomials.png']
257 ]
258 ]
259 
260 
261 ######################################################
262 # functions definitions
263 
264 
265 def isFileUnderDir(dir_name, file_name):
266  '''Recursively looks for file named file_name under dir_name directory
267  '''
268  if not DO_DT and dir_name.find("MB")>-1:
269  return False
270  if not DO_CSC and dir_name.find("ME")>-1:
271  return False
272 
273  for f in os.listdir(dir_name):
274  dirfile = os.path.join(dir_name, f)
275  if os.path.isfile(dirfile) and f==file_name:
276  return True
277  # recursively access file names in subdirectories
278  elif os.path.isdir(dirfile):
279  #print "Accessing directory:", dirfile
280  if isFileUnderDir(dirfile, file_name): return True
281  return False
282 
283 
284 # to time saving of plots
285 def saveAs(nm):
286  t1 = time.time()
287  ddt[15] += 1
288  c1.SaveAs(nm)
289  tn = time.time()
290  ddt[16] = 1./ddt[15]*((ddt[15]-1)*ddt[16] + tn-t1)
291 
292 
293 def createDirectoryStructure(iteration_name):
294 
295  if not os.access(iteration_name,os.F_OK):
296  os.mkdir(iteration_name)
297 
298  csc_basedir = iteration_name+'/'
299  for endcap in CSC_TYPES:
300  #print csc_basedir+endcap[0]
301  shutil.rmtree(csc_basedir+endcap[0],True)
302  os.mkdir(csc_basedir+endcap[0])
303  for station in endcap[2]:
304  #print csc_basedir+endcap[0]+'/'+station[1]
305  os.mkdir(csc_basedir+endcap[0]+'/'+station[1])
306  for ring in station[2]:
307  #print csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
308  os.mkdir(csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1])
309  for chamber in range(1,ring[2]+1):
310  schamber = "%02d" % chamber
311  #print csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
312  os.mkdir(csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber)
313 
314  dt_basedir = iteration_name+'/MB/'
315  #print dt_basedir
316  shutil.rmtree(dt_basedir,True)
317  os.mkdir(dt_basedir)
318  for wheel in DT_TYPES:
319  #print dt_basedir+wheel[0]
320  os.mkdir(dt_basedir+wheel[0])
321  for station in wheel[2]:
322  #print dt_basedir+wheel[0]+'/'+station[1]
323  os.mkdir(dt_basedir+wheel[0]+'/'+station[1])
324  for sector in range(1,station[2]+1):
325  ssector = "%02d" % sector
326  #print dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
327  os.mkdir(dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector)
328 
329  print os.getcwd()
330 
331 ######################################################
332 
333 def doMapPlotsDT(dt_basedir, tfiles_plotting):
334  """write DT map plots
335 
336  "DTvsphi_st%dwh%s" % (station, wheelletter):
337 
338  plots "integrated" over ALL SECTORS:
339  of x, y, dxdz, dydz vs. phi (y and dydz only for stations 1-3)
340  made for all (station,wheel) combinations
341 
342  Access interface may be arranged into station(1 .. 4) vs. wheel(-2 .. +2) map.
343  It could be incorporated into a general DT chambers map (column1: wheel, column2: station,
344  columns3-16 correspond to sector #) by making station numbers in column 2 clickable.
345 
346 
347  "DTvsz_st%dsec%02d" % (station, sector)
348 
349  plots "integrated" over ALL WHEELS:
350  of x, y, dxdz, dydz vs. z (y and dydz only for stations 1-3)
351  made for all (station,sector) combinations
352 
353  Interface: may be arranged into station(1 .. 4) vs. sector(1 .. 14) map with sector range
354  (1 .. 12) for stations 1-3.
355  It could be incorporated into an EXTENDED general DT chambers map (extended by adding an
356  identifier "ALL" in column1 for wheel number)."""
357 
358  for wheel in DT_TYPES:
359  if wheel[1]=="ALL": continue
360  for station in wheel[2]:
361  pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'
362  label = "DTvsphi_st%dwh%s" % (int(station[1]), wheelLetter(int(wheel[1])))
363  htitle = "wheel %+d, station %s" % (int(wheel[1]), station[1])
364  mapplot(tfiles_plotting, label, "x", window=15., title=htitle, fitsawteeth=True,fitsine=True)
365  c1.SaveAs(pdir+'map_DTvsphi_x.png')
366  #mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle, fitsawteeth=True,fitsine=True)
367  mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle)
368  c1.SaveAs(pdir+'map_DTvsphi_dxdz.png')
369 
370  if station[1]=='4': continue
371  #mapplot(tfiles_plotting, label, "y", window=15., title=htitle, fitsawteeth=True,fitsine=True)
372  mapplot(tfiles_plotting, label, "y", window=15., title=htitle)
373  c1.SaveAs(pdir+'map_DTvsphi_y.png')
374  #mapplot(tfiles_plotting, label, "dydz", window=15., title=htitle, fitsawteeth=True,fitsine=True)
375  mapplot(tfiles_plotting, label, "dydz", window=15., title=htitle)
376  c1.SaveAs(pdir+'map_DTvsphi_dydz.png')
377 
378  qcount=0
379  for wheel in DT_TYPES:
380  if wheel[1]!="ALL": continue
381  for station in wheel[2]:
382  for sector in range(1,station[2]+1):
383  if qcount>QUICKTESTN: break
384  qcount += 1
385  ssector = "%02d" % sector
386  pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
387  label = "DTvsz_st%ssec%s" % (station[1], ssector)
388  htitle = "station %s, sector %d" % (station[1], sector)
389  mapplot(tfiles_plotting, label, "x", window=15., title=htitle)
390  c1.SaveAs(pdir+'map_DTvsz_x.png')
391  mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle)
392  c1.SaveAs(pdir+'map_DTvsz_dxdz.png')
393 
394  if station[1]=='4': continue
395  mapplot(tfiles_plotting, label, "y", window=15., title=htitle)
396  c1.SaveAs(pdir+'map_DTvsz_y.png')
397  mapplot(tfiles_plotting, label, "dydz", window=15., title=htitle)
398  c1.SaveAs(pdir+'map_DTvsz_dydz.png')
399 
400  saveTestResultsMap(options.runLabel)
401 
402 
403 def doMapPlotsCSC(csc_basedir, tfiles_plotting):
404  """write CSC map plots
405 
406  "CSCvsphi_me%s%d%d" % (endcap, station, ring)
407 
408  plots "integrated" over ALL SECTORS:
409  of rphi, drphi/dz vs. phi
410  made for all (endcap,station,ring) combinations
411 
412  Interface: may be arranged into two station(1 .. 4) vs. R(1 .. 4) maps for both endcaps
413  with R range (1 .. 4) for stations 2-4
414  It could be incorporated into a general CSC chambers map (column1: endcap, column2: station,
415  column3: ring, columns4-40 correspond to chamber #) by making ring numbers in column 3
416  clickable.
417 
418 
419  "CSCvsr_me%s%dch%02d" % (endcap, station, chamberNumber)
420 
421  plots "integrated" over ALL RINGS:
422  of rphi, drphi/dz vs. z
423  made for all (endcap,station,chamber) combinations
424 
425  Interface: may be arranged into two station(1 .. 4) vs. chamber(1 .. 36) maps for both endcaps
426  It could be incorporated into an EXTENDED general CSC chambers map (extended by adding an
427  identifier "ALL" in column3 for ring number)."""
428 
429  for endcap in CSC_TYPES:
430  for station in endcap[2]:
431  for ring in station[2]:
432  if ring[1]=="ALL": continue
433  pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'
434  label = "CSCvsphi_me%s%s%s" % (endcap[1], station[1], ring[1])
435  htitle = "%s%s/%s" % (endcap[0], station[1],ring[1])
436  mapplot(tfiles_plotting, label, "x", window=15., title=htitle, fitsine=True)
437  c1.SaveAs(pdir+'map_CSCvsphi_x.png')
438  mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle)
439  c1.SaveAs(pdir+'map_CSCvsphi_dxdz.png')
440 
441  saveTestResultsMap(options.runLabel)
442 
443  qcount = 0
444  for endcap in CSC_TYPES:
445  for station in endcap[2]:
446  for ring in station[2]:
447  if ring[1]!="ALL": continue
448  for chamber in range(1,ring[2]+1):
449  if qcount>QUICKTESTN: break
450  qcount += 1
451  schamber = "%02d" % chamber
452  pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber+'/'
453  label = "CSCvsr_me%s%sch%s" % (endcap[1], station[1], schamber)
454  htitle = "%s%s/ALL/%d" % (endcap[0], station[1],chamber)
455  mapplot(tfiles_plotting, label, "x", window=15., title=htitle)
456  c1.SaveAs(pdir+'map_CSCvsr_x.png')
457  mapplot(tfiles_plotting, label, "dxdz", window=15., title=htitle)
458  c1.SaveAs(pdir+'map_CSCvsr_dxdz.png')
459 
460 
461 def doCurvaturePlotsDT(dt_basedir, tfiles_plotting):
462  """write DT curvature plots
463 
464  "wheel%s_sector%s" % (wheel, sector)
465 
466  wheel in "m2", "m1", "z", "p1", "p2"
467  station 1 only!
468  sector in "01", ..., "12"
469 
470  "param" may be one of
471  "deltax" (Delta x position residuals),
472  "deltadxdz" (Delta (dx/dz) angular residuals),
473  "curverr" (Delta x * d(Delta q/pT)/d(Delta x) = Delta q/pT in the absence of misalignment) - not necessary
474 
475  made for all (wheel,station=1,sector) combinations
476 
477  Interface: could be accesses through a general DT chambers map for station=1 chambers."""
478 
479  w_dict = {'-2':'m2', '-1':'m1', '0':'z', '1':'p1', '2':'p2'}
480  qcount = 0
481  for wheel in DT_TYPES:
482  if wheel[1]=="ALL": continue
483  #station = 1
484  station = wheel[2][0]
485  print wheel[0]+'/'+station[1]
486  for sector in range(1,station[2]+1):
487  if sector>12: break
488  if qcount>QUICKTESTN: break
489  qcount += 1
490  ssector = "%02d" % sector
491  pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
492  label = "wheel%s_sector%s" % (w_dict[wheel[1]], ssector)
493  thetitle ="Wheel %s, sector %s" % (wheel[1], ssector)
494  curvatureplot(tfiles_plotting, label, "deltax", title=thetitle, window=15., fitline=True)
495  saveAs(pdir+'dt_curvature_deltax.png')
496  curvatureplot(tfiles_plotting, label, "deltadxdz", title=thetitle, window=15., fitline=True)
497  saveAs(pdir+'dt_curvature_deltadxdz.png')
498 
499 
500 def doSegDiffPlotsDT(dt_basedir, tfiles_plotting, iter_reports):
501  """write segment-difference plots for DT
502 
503  segdiff "dt13_resid" and "dt13_slope"
504 
505  set of plots of
506  x vs qpt, x for positive, x for negative ("dt13_resid")
507  dxdz vs qpt, dxdz for positive, dxdz for negative ("dt13_slope")
508  done for MB1-MB2, MB2-MB3, and MB3-MB4 stations combinations with all possible (wheel, sector)
509 
510  Interface: could be accessed through a general DT chambers map, but only for chambers in
511  stations 2-4 (e.g., station 2 would provide MB1-MB2 plots).
512 
513  segdiff "dt2_resid" and "dt2_slope"
514 
515  set of plots of
516  y vs q/pt, y for positive, y for negative ("dt2_resid")
517  dydz vs q/pt, dydz for positive, dydz for negative ("dt2_slope")
518  done for MB1-MB2, MB2-MB3 stations combinations with all possible (wheel, sector)
519 
520  Interface: then the interface would still be a general DT map,
521  but the info only available from station 2 & 3 chambers."""
522 
523  qcount = 0
524  for iwheel in DT_TYPES:
525  if iwheel[1]=="ALL": continue
526  for istation in iwheel[2]:
527  if istation[1]=="1": continue
528  dstations = (int(istation[1])-1)*10 + int(istation[1])
529  #print dstations
530  for isector in range(1, istation[2] + 1):
531  if isector > 12: continue
532  if qcount>QUICKTESTN: break
533  qcount += 1
534  ssector = "%02d" % isector
535  pdir = dt_basedir + '/' + iwheel[0] + '/' + istation[1] + '/' + ssector + '/'
536 
537  segdiff(tfiles_plotting, "dt13_resid", dstations, wheel=int(iwheel[1]), sector=isector, window=10.)
538  c1.SaveAs(pdir + 'segdif_dt13_resid.png')
539  segdiff(tfiles_plotting, "dt13_slope", dstations, wheel=int(iwheel[1]), sector=isector, window=10.)
540  c1.SaveAs(pdir + 'segdif_dt13_slope.png')
541 
542  if istation[1] == '4': continue
543  segdiff(tfiles_plotting, "dt2_resid", dstations, wheel=int(iwheel[1]), sector=isector, window=10.)
544  c1.SaveAs(pdir + 'segdif_dt2_resid.png')
545  segdiff(tfiles_plotting, "dt2_slope", dstations, wheel=int(iwheel[1]), sector=isector, window=10.)
546  c1.SaveAs(pdir + 'segdif_dt2_slope.png')
547 
548  """segdiffvsphi "dt13_resid" and "dt13_slope"
549 
550  plot for a specific wheel #:
551  x vs phi of pair ("dt13_resid")
552  dxdz vs phi of pair ("dt13_slope")
553  contains all three combinations of neighboring stations
554  made for all possible wheel values
555 
556  Interface: could be accessed by clicking on wheel number under the "wheel" column
557  in a general DT map
558 
559  segdiffvsphi "dt2_resid" and "dt2_slope"
560 
561  plot for a specific wheel #:
562  y vs phi of pair ("dt2_resid")
563  dydz vs phi of pair ("dt2_slope")
564  contains both MB1-MB2 and MB2-MB3 combinations
565  made for all possible wheel values
566 
567  Interface: could be accessed by clicking on wheel number under the "wheel" column
568  in a general DT map"""
569 
570  if len(iter_reports)==0: return
571 
572  for iwheel in DT_TYPES:
573  if iwheel[1]=="ALL": continue
574  pdir = dt_basedir + '/' + iwheel[0] + '/'
575  segdiffvsphi(tfiles_plotting, iter_reports, "dt13_resid", int(iwheel[1]), window=15., excludesectors=(1,7))
576  c1.SaveAs(pdir + 'segdifphi_dt13_resid.png')
577  segdiffvsphi(tfiles_plotting, iter_reports, "dt13_slope", int(iwheel[1]), window=15., excludesectors=(1,7))
578  c1.SaveAs(pdir + 'segdifphi_dt13_slope.png')
579  segdiffvsphi(tfiles_plotting, iter_reports, "dt2_resid", int(iwheel[1]), window=15., excludesectors=(1,7))
580  c1.SaveAs(pdir + 'segdifphi_dt2_resid.png')
581  segdiffvsphi(tfiles_plotting, iter_reports, "dt2_slope", int(iwheel[1]), window=15., excludesectors=(1,7))
582  c1.SaveAs(pdir + 'segdifphi_dt2_slope.png')
583 
584 
585 def doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports):
586  """write segment-difference plots for CSC
587 
588  segdiff "csc_resid" and "csc_slope"
589 
590  set of plots of
591  rphi vs qpt, rphi for positive, rphi for negative ("csc_resid")
592  drphidz vs qpt, drphidz for positive, drphidz for negative ("csc_slope")
593  done for ME1-ME2, ME2-ME3, and ME3-ME4 stations combinations with
594  endcap "m" or "p"
595  ring 1 or 2
596  chamber 1-18 (r1) or 1-36 (r2)
597  note: there's no ME3-ME4 plots for R2
598 
599  Interface: could be accessed through a general CSC chambers map, but only for chambers in
600  stations 2-4 (e.g., station 2 would provide ME1-ME2 plots)."""
601 
602  qcount = 0
603  for iendcap in CSC_TYPES:
604  for istation in iendcap[2]:
605  if istation[1]=="1": continue
606  dstations = (int(istation[1])-1)*10 + int(istation[1])
607  for iring in istation[2]:
608  if iring[1]=="ALL": continue
609  if istation[1]=="4" and iring[1]=="2": continue
610  for ichamber in range(1,iring[2]+1):
611  if qcount>QUICKTESTN: break
612  qcount += 1
613  schamber = "%02d" % ichamber
614  pdir = csc_basedir+'/'+iendcap[0]+'/'+istation[1]+'/'+iring[1]+'/'+schamber+'/'
615  segdiff(tfiles_plotting, "csc_resid", dstations,
616  endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=10.)
617  c1.SaveAs(pdir + 'segdif_csc_resid.png')
618  segdiff(tfiles_plotting, "csc_slope", dstations,
619  endcap=iendcap[1], ring=int(iring[1]), chamber=ichamber, window=10.)
620  c1.SaveAs(pdir + 'segdif_csc_slope.png')
621 
622 
623 def doFitFunctionsPlotsDT(dt_basedir, iter_tfile, iter_reports):
624  """write fit functions plots for DT
625 
626  DT bellcurves and polynomials
627 
628  set of plots of bellcurves
629  x, dxdz, x vs. dxdz (for all 4 stations)
630  y, dydz, x vs. dxdz (only for stations 1-3?)
631 
632  set of plots of polynomials -- for stations 1-3 only??
633  x vs. xpos, x vs ypos, x vs dxdz angle, x vs dydz angle
634  y vs. xpos, y vs ypos, y vs dxdz angle, y vs dydz angle
635  dxdz vs. xpos, dxdz vs ypos, dxdz vs dxdz angle, dxdz vs dydz angle
636  dydz vs. xpos, dydz vs ypos, dydz vs dxdz angle, dydz vs dydz angle
637 
638  set of plots of polynomials -- for station 4 only??
639  x vs. xpos, x vs dxdz angle
640  dxdz vs. xpos, dxdz vs dxdz angle
641 
642  made for all (wheel,station,sector) combinations
643 
644  Interface: could be accesses through a general DT chambers map."""
645 
646  qcount = 0
647  clearDDT()
648  for wheel in DT_TYPES:
649  if wheel[1]=="ALL": continue
650  for station in wheel[2]:
651  print wheel[0]+'/'+station[1]
652  for sector in range(1,station[2]+1):
653  if qcount>QUICKTESTN: break
654  qcount += 1
655  ssector = "%02d" % sector
656  pdir = dt_basedir+'/'+wheel[0]+'/'+station[1]+'/'+ssector+'/'
657  label = "MBwh%sst%ssec%s" % (wheelLetter(int(wheel[1])),station[1],ssector)
658  bellcurves(iter_tfile, iter_reports, label, False)
659  #c1.SaveAs(pdir+'dt_bellcurves.png')
660  saveAs(pdir+'dt_bellcurves.png')
661  polynomials(iter_tfile, iter_reports, label, False)
662  #c1.SaveAs(pdir+'dt_polynomials.png')
663  saveAs(pdir+'dt_polynomials.png')
664  #printDeltaTs()
665 
666 
667 def doFitFunctionsPlotsCSC(csc_basedir, iter_tfile, iter_reports):
668  """write fit functions plots for CSC
669 
670  CSC bellcurves and polynomials
671 
672  set of plots of bellcurves
673  rphi, drphidz, rphi vs. drphidz
674 
675  set of plots of polynomials
676  rphi vs. rphi pos, rphi vs drphidz angle
677  drphidz vs. rphi pos, drphidz vs drphidz angle
678 
679  made for all (endcap,station,ring,chamber) combinations
680 
681  Interface: could be accesses through a general CSC chambers map."""
682 
683  qcount = 0
684  clearDDT()
685  for endcap in CSC_TYPES:
686  for station in endcap[2]:
687  for ring in station[2]:
688  if ring[1]=="ALL": continue
689  print endcap[0]+'/'+station[1]+'/'+ring[1]
690  for chamber in range(1,ring[2]+1):
691  if qcount>QUICKTESTN: break
692  qcount += 1
693  schamber = "%02d" % chamber
694  pdir = csc_basedir+'/'+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber+'/'
695  label = "ME%s%s%s_%s" % (endcap[1], station[1], ring[1], schamber)
696  bellcurves(iter_tfile, iter_reports, label, False)
697  #c1.SaveAs(pdir+'csc_bellcurves.png')
698  saveAs(pdir+'csc_bellcurves.png')
699  polynomials(iter_tfile, iter_reports, label, False)
700  #c1.SaveAs(pdir+'csc_polynomials.png')
701  saveAs(pdir+'csc_polynomials.png')
702  #printDeltaTs()
703 
704 
705 
706 def doIterationPlots(iteration_directory, tfiles_plotting, iter_tfile, iter_reports):
707  dt_basedir = iteration_directory+'/'+'MB'
708  csc_basedir = iteration_directory+'/'
709 
710  if DO_DT and DO_MAP:
711  doMapPlotsDT(dt_basedir, tfiles_plotting)
712  if DO_CSC and DO_MAP:
713  doMapPlotsCSC(csc_basedir, tfiles_plotting)
714 
715  if DO_DT and DO_CURVATURE:
716  doCurvaturePlotsDT(dt_basedir, tfiles_plotting)
717  #if DO_CSC and DO_CURVATURE:
718  # doCurvaturePlotsCSC(csc_basedir, tfiles_plotting)
719 
720  if DO_DT and DO_SEGDIFF:
721  doSegDiffPlotsDT(dt_basedir, tfiles_plotting, iter_reports)
722  if DO_CSC and DO_SEGDIFF:
723  doSegDiffPlotsCSC(csc_basedir, tfiles_plotting, iter_reports)
724 
725  if DO_DT and DO_FIT:
726  doFitFunctionsPlotsDT(dt_basedir, iter_tfile, iter_reports)
727  if DO_CSC and DO_FIT:
728  doFitFunctionsPlotsCSC(csc_basedir, iter_tfile, iter_reports)
729 
730 
731 def createCanvasesList(fname="canvases_list.js"):
732  '''Use CANVASES_LIST_TEMPLATE as a template to create a canvases list include for the browser.
733  Write out only those canvases which have existing filename.png plots.
734  '''
735  CANVASES_LIST = []
736  for scope in CANVASES_LIST_TEMPLATE:
737  scope_entry = []
738  if len(scope)>2:
739  scope_entry = [scope[0],scope[1]]
740  for canvas_entry in scope[2:]:
741  if isFileUnderDir("./",canvas_entry[1]):
742  scope_entry.append(canvas_entry)
743  CANVASES_LIST.append(scope_entry)
744 
745  ff = open(fname,mode="w")
746  print >>ff, "var CANVASES_LIST = "
747  json.dump(CANVASES_LIST,ff)
748  ff.close()
749 
750 
751 def createCanvasToIDList(fname="canvas2id_list.js"):
752  '''Create a canvas-to-ids list include for the browser.
753  Write out only those canvases which have existing filename.png plots.
754  '''
755  CANVAS2ID_LIST = []
756  for scope in CANVASES_LIST_TEMPLATE:
757  if len(scope)>2:
758  for canvas_entry in scope[2:]:
759  ids = idsForFile("./",canvas_entry[1])
760  # scope_entry.append(canvas_entry)
761  # uniquify:
762  set_ids = set(ids)
763  uids = list(set_ids)
764  print canvas_entry, ":", len(uids), "ids"
765  if (len(uids)>0):
766  CANVAS2ID_LIST.append( (canvas_entry[1],uids) )
767  #print CANVAS2ID_LIST
768  CANVAS2ID_LIST_DICT = dict(CANVAS2ID_LIST)
769  #print CANVAS2ID_LIST_DICT
770  ff = open(fname,mode="w")
771  print >>ff, "var CANVAS2ID_LIST = "
772  json.dump(CANVAS2ID_LIST_DICT,ff)
773  ff.close()
774 
775 def idsForFile(dir_name, file_name):
776  '''Recursively looks for file named file_name under dir_name directory
777  and fill the list with dir names converted to IDs
778  '''
779  id_list = []
780  for f in os.listdir(dir_name):
781  dirfile = os.path.join(dir_name, f)
782  if os.path.isfile(dirfile) and f==file_name:
783  id_list.append(dirToID(dir_name))
784  # recursively access file names in subdirectories
785  elif os.path.isdir(dirfile):
786  #print "Accessing directory:", dirfile
787  ids = idsForFile(dirfile, file_name)
788  if (len(ids)>0):
789  id_list.extend(ids)
790  return id_list
791 
792 
793 def dirToID(d):
794  if d[-1]!='/': d += '/'
795  dtn = d.find("/MB/")
796  if dtn!=-1:
797  return d[dtn+4:-1]
798  cscn = d.find("/ME-/")
799  if cscn!=-1:
800  return 'ME-'+d[cscn+4:-1]
801  cscn = d.find("/ME+/")
802  if cscn!=-1:
803  return 'ME+'+d[cscn+4:-1]
804  return ''
805 
806 
807 ############################################################################################################
808 ############################################################################################################
809 # main script
810 
811 # open input files:
812 
813 #basedir='/disks/sdb5/home_reloc/khotilov/db/cms/alignment'
814 #iteration1 = "iteration_01"
815 #iteration3 = "iteration_03"
816 #iteration1 = "NOV4DT_PASS3noweight_TkHIP_01"
817 #iteration3 = "NOV4DT_PASS3noweight_TkHIP_05"
818 #os.chdir(options.inputDir)
819 #iteration1 = options.i1
820 #iteration3 = options.iN
821 
822 fname = options.inputDir+'/'+options.i1+'/'+i1prefix
823 tfiles1_plotting = []
824 iter1_tfile = None
825 iter1_reports = []
826 if not SINGLE_ITERATION:
827  if (DO_MAP or DO_SEGDIFF or DO_CURVATURE) and not os.access(fname+"_plotting.root",os.F_OK):
828  print "no file "+fname+"_plotting.root"
829  sys.exit()
830  if DO_FIT and not os.access(fname+".root",os.F_OK):
831  print "no file "+fname+".root"
832  sys.exit()
833  if DO_MEDIAN and not os.access(fname+"_report.py",os.F_OK):
834  print "no file "+fname+"_report.py"
835  sys.exit()
836  if DO_MAP or DO_SEGDIFF or DO_CURVATURE: tfiles1_plotting.append(ROOT.TFile(fname+"_plotting.root"))
837  if os.access(fname+".root",os.F_OK):
838  iter1_tfile = ROOT.TFile(fname+".root")
839  if os.access(fname+"_report.py",os.F_OK):
840  execfile(fname+"_report.py")
841  iter1_reports = reports
842 
843 fname = options.inputDir+'/'+options.iN+'/'+iNprefix
844 tfilesN_plotting = []
845 iterN_tfile = None
846 iterN_reports = []
847 if (DO_MAP or DO_SEGDIFF or DO_CURVATURE) and not os.access(fname+"_plotting.root",os.F_OK):
848  print "no file "+fname+"_plotting.root"
849  sys.exit()
850 if DO_FIT and not os.access(fname+".root",os.F_OK):
851  print "no file "+fname+".root"
852  sys.exit()
853 if DO_MEDIAN and not os.access(fname+"_report.py",os.F_OK):
854  print "no file "+fname+"_report.py"
855  sys.exit()
856 if DO_MAP or DO_SEGDIFF or DO_CURVATURE: tfilesN_plotting.append(ROOT.TFile(fname+"_plotting.root"))
857 if os.access(fname+".root",os.F_OK):
858  iterN_tfile = ROOT.TFile(fname+".root")
859 if os.access(fname+"_report.py",os.F_OK):
860  execfile(fname+"_report.py")
861  iterN_reports = reports
862 
863 if DO_MAP:
864  os.chdir(options.inputDir)
865  phiedges2c()
866 
867 ######################################################
868 # setup output:
869 
870 # cd to outputDIr
871 os.chdir(options.outputDir)
872 
873 comdir = "common/"
874 iteration1 = "iter1"
875 iterationN = "iterN"
876 
877 # create directory structure
878 if options.createDirSructure:
879  print "WARNING: all existing results in "+options.outputDir+" will be deleted!"
880  if not SINGLE_ITERATION: createDirectoryStructure(iteration1)
881  createDirectoryStructure(iterationN)
882  if not os.access(comdir,os.F_OK):
883  os.mkdir(comdir)
884 
885 ######################################################
886 # do drawing
887 
888 c1 = ROOT.TCanvas("c1","c1",800,600)
889 
890 set_palette("blues")
891 
892 if not SINGLE_ITERATION: doIterationPlots(iteration1, tfiles1_plotting, iter1_tfile, iter1_reports)
893 doIterationPlots(iterationN, tfilesN_plotting, iterN_tfile, iterN_reports)
894 
895 if CPP_LOADED: ROOT.cleanUpHeap()
896 
897 # write distributions of medians plots
898 
899 if DO_MEDIAN:
900  plotmedians(iter1_reports, iterN_reports)
901  c1.SaveAs(comdir+'medians.png')
902 
903 # perform diagnostic
904 if DO_DIAGNOSTIC:
905  #if not SINGLE_ITERATION: doTests(iter1_reports,"mu_list_1.js","dqm_report_1.js",options.runLabel)
906  doTests(iterN_reports,"mu_list.js","dqm_report.js",options.runLabel)
907  createCanvasesList("canvases_list.js")
908  createCanvasToIDList("canvas2id_list.js")
def wheelLetter
Definition: plotscripts.py:34
def saveTestResultsMap
def isFileUnderDir
functions definitions
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run