Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-03-03 02:23:12

0001 #! /usr/bin/env python3
0002 
0003 from __future__ import print_function
0004 from builtins import range
0005 import re,os,sys
0006 import optparse
0007 
0008 # python 2.6 has json modue; <2.6 could use simplejson
0009 try:
0010   import json
0011 except ImportError:
0012   import simplejson as json
0013 
0014 from mutypes import * 
0015 
0016 import pprint
0017 pp = pprint.PrettyPrinter(indent=2)
0018 
0019 
0020 NAME_TO_TITLE = {
0021 "map_DTvsphi_dxdz.png" : "map of dxdz residual vs phi",
0022 "map_DTvsphi_dydz.png" : "map of dydz residual vs phi",
0023 "map_DTvsphi_x.png" : "map of x residual vs phi",
0024 "map_DTvsphi_y.png" : "map of y residual vs phi",
0025 "map_DTvsz_dxdz.png" : "map of dxdz residual vs z",
0026 "map_DTvsz_dydz.png" : "map of dydz residual vs z",
0027 "map_DTvsz_x.png" : "map of x residual vs z",
0028 "map_DTvsz_y.png" : "map of y residual vs z",
0029 "map_DTvsz_all_dxdz.png" : "map of dxdz residual vs z",
0030 "map_DTvsz_all_dydz.png" : "map of dydz residual vs z",
0031 "map_DTvsz_all_x.png" : "map of x residual vs z",
0032 "map_DTvsz_all_y.png" : "map of y residual vs z",
0033 "map_CSCvsphi_dxdz.png" : "map of d(rphi)/dz residual vs phi",
0034 "map_CSCvsphi_x.png" : "map of rphi residual vs phi",
0035 "map_CSCvsr_dxdz.png" : "map of d(rphi)/dz residual vs r",
0036 "map_CSCvsr_x.png" : "map of rphi residual vs r",
0037 "segdifphi_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals vs phi",
0038 "segdifphi_dt13_resid.png" : "segdiff in x residuals vs phi",
0039 "segdifphi_dt13_slope.png" : "segdiff in dxdz residuals vs phi",
0040 "segdifphi_dt2_resid.png" : "segdiff in y residuals vs phi",
0041 "segdifphi_dt2_slope.png" : "segdiff in dydz residuals vs phi",
0042 "segdif_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals",
0043 "segdif_dt13_resid.png" : "segdiff in x residuals",
0044 "segdif_dt13_slope.png" : "segdiff in dxdz residuals",
0045 "segdif_dt2_resid.png" : "segdiff in y residuals",
0046 "segdif_dt2_slope.png" : "segdiff in dydz residuals",
0047 "segdifphi_csc_resid.png" : "segdiff in rphi residuals vs phi",
0048 "segdifphi_csc_slope.png" : "segdiff in d(rphi)/dz residuals vs phi",
0049 "segdif_csc_resid.png" : "segdiff in rphi residuals",
0050 "segdif_csc_slope.png" : "segdiff in d(rphi)/dz residuals",
0051 "dt_bellcurves.png" : "residuals distributions",
0052 "dt_polynomials.png" : "residuals relations to misalignments",
0053 "csc_bellcurves.png" : "residuals distributions",
0054 "csc_polynomials.png" : "residuals relations to misalignments",
0055 'dt_curvature_deltax.png' : 'Delta x residuals vs. curvature',
0056 'dt_curvature_deltadxdz.png' : 'Delta dxdz residuals vs. curvature',
0057 "medians.png" : "medians distribution"
0058 }
0059 ######################################################
0060 # functions definitions
0061 
0062 ######################################################
0063 # To parse commandline args
0064 
0065 usage='%prog [options]\n'+\
0066   'Creates a tree_items.js data file for a browsable JavaScript tree using results produced '+\
0067   'by running alignment_validation_plots.py.'
0068 
0069 parser=optparse.OptionParser(usage)
0070 
0071 parser.add_option("-i", "--inputDir",
0072   help="[REQUIRED] input directory: should contain 'iter1', 'iterN' and 'common' directories filled with alignment_validation_plots.py. The resulting tree_items.js is also dumped into this directory",
0073   type="string",
0074   default='',
0075   dest="inputDir")
0076 
0077 parser.add_option("-v", "--verbose",
0078   help="Degree of debug info verbosity",
0079   type="int",
0080   default=0,
0081   dest="verbose")
0082 
0083 options,args=parser.parse_args()
0084 
0085 if options.inputDir=='':
0086   print("\nOne or more of REQUIRED options is missing!\n")
0087   parser.print_help()
0088   # See \n"+sys.argv[0]+" --help"
0089   sys.exit()
0090 
0091 ######################################################
0092 
0093 
0094 
0095 ############################################################################################################
0096 ############################################################################################################
0097 # main script
0098 
0099 # create directory structure
0100 
0101 #basedir='/disks/sdb5/home_reloc/khotilov/db/cms/alignment'
0102 #os.chdir(basedir)
0103 os.chdir(options.inputDir)
0104 
0105 #iteration1 = "iteration_01"
0106 #iteration3 = "iteration_03"
0107 #iteration1 = "NOV4DT_PASS3noweight_TkHIP_01"
0108 #iteration3 = "NOV4DT_PASS3noweight_TkHIP_05"
0109 iteration1 = "iter1"
0110 iterationN = "iterN"
0111 comdir = "common/"
0112 
0113 ######################################################
0114 # open root and py result files
0115 
0116 iteration_directory = iterationN
0117 
0118 
0119 def parseDir(dir,label,it1="",itN=""):
0120   """it1 and itN   are the first and the last iterations' directory names
0121      dir           is some directory with the results from for the LAST 
0122                    iteration, so it must contain a itN substring 
0123      label         is a label for tree's folder for this directory"""
0124   if len(itN)>0 and dir.find(itN)==-1:
0125     print("directory ", dir, "has no ", itN, " in it!!")
0126     return ["problem!!!",""]
0127   res = [label,dir]
0128   files = sorted(os.listdir(dir))
0129   for f in files:
0130     if re.match(".+\.png", f):
0131       if len(it1)>0 and len(itN)>0:
0132         lnN = [itN,dir+'/'+f]
0133         dir1 = dir.replace(itN,it1)
0134         if not os.access(dir1+'/'+f,os.F_OK):
0135           print("WARNING: no ",dir1+'/'+f," file found!!!")
0136         ln1 = [it1,dir1+'/'+f]
0137         ln = [NAME_TO_TITLE[f],dir+'/'+f,ln1,lnN]
0138         res.append(ln)
0139       else:
0140         ln = [NAME_TO_TITLE[f],dir+'/'+f]
0141         #print ln
0142         res.append(ln)
0143   #pp.pprint(res)
0144   return res
0145 
0146 
0147 mytree = []
0148 tree_level1 = ['test','']
0149 
0150 # DT
0151 dt_basedir = iteration_directory+'/MB/'
0152 tree_level2 = parseDir(dt_basedir,"MB",iteration1,iterationN)
0153 for wheel in DT_TYPES:
0154   dd = dt_basedir + wheel[0]
0155   print(dd)
0156   tree_level3 = parseDir(dd,wheel[0],iteration1,iterationN)
0157   for station in wheel[2]:
0158     dd = dt_basedir + wheel[0]+'/'+station[1]
0159     print(dd) 
0160     tree_level4 = parseDir(dd,station[0],iteration1,iterationN)
0161     for sector in range(1,station[2]+1):
0162       ssector = "%02d" % sector
0163       dd = dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
0164       #print dd
0165       tree_level5 = parseDir(dd,"%s/%d" % (station[0],sector),iteration1,iterationN)
0166       if len(tree_level5) == 2: tree_level5.append(['none',''])
0167       tree_level4.append(tree_level5)
0168     if len(tree_level4) == 2: tree_level4.append(['none',''])
0169     tree_level3.append(tree_level4)
0170   if len(tree_level3) == 2: tree_level3.append(['none',''])
0171   tree_level2.append(tree_level3)
0172 if len(tree_level2) == 2: tree_level2.append(['none',''])
0173 tree_level1.append(tree_level2)
0174 
0175 # CSC
0176 csc_basedir = iteration_directory+'/'
0177 for endcap in CSC_TYPES:
0178   dd = csc_basedir+endcap[0]
0179   print(dd)
0180   tree_level2 = parseDir(dd,endcap[0],iteration1,iterationN)
0181   for station in endcap[2]:
0182     dd = csc_basedir+endcap[0]+'/'+station[1]
0183     print(dd)
0184     tree_level3 = parseDir(dd,station[0],iteration1,iterationN)
0185     for ring in station[2]:
0186       dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
0187       print(dd)
0188       tree_level4 = parseDir(dd,"%s/%s" % (station[0],ring[1]),iteration1,iterationN)
0189       for chamber in range(1,ring[2]+1):
0190         schamber = "%02d" % chamber
0191         dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
0192         #print dd
0193         tree_level5 = parseDir(dd,"%s/%s/%d" % (station[0],ring[1],chamber),iteration1,iterationN)
0194         tree_level4.append(tree_level5)
0195       if len(tree_level4) == 2: tree_level4.append(['none',''])
0196       tree_level3.append(tree_level4)
0197     if len(tree_level3) == 2: tree_level3.append(['none',''])
0198     tree_level2.append(tree_level3)
0199   if len(tree_level2) == 2: tree_level2.append(['none',''])
0200   tree_level1.append(tree_level2)
0201 
0202 # Common plots
0203 common_basedir = comdir
0204 tree_level2 = parseDir(common_basedir,"All")
0205 tree_level1.append(tree_level2)
0206 
0207 
0208 mytree.append(tree_level1)
0209 print(" ")
0210 #pp.pprint(mytree)
0211 print()
0212 
0213 ff = open("tree_items.js",mode="w")
0214 print("var TREE_ITEMS = ", file=ff)
0215 json.dump(mytree,ff)
0216 ff.close()