CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
createTree.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 from __future__ import print_function
4 from builtins import range
5 import re,os,sys
6 import optparse
7 
8 # python 2.6 has json modue; <2.6 could use simplejson
9 try:
10  import json
11 except ImportError:
12  import simplejson as json
13 
14 from mutypes import *
15 
16 import pprint
17 pp = pprint.PrettyPrinter(indent=2)
18 
19 
20 NAME_TO_TITLE = {
21 "map_DTvsphi_dxdz.png" : "map of dxdz residual vs phi",
22 "map_DTvsphi_dydz.png" : "map of dydz residual vs phi",
23 "map_DTvsphi_x.png" : "map of x residual vs phi",
24 "map_DTvsphi_y.png" : "map of y residual vs phi",
25 "map_DTvsz_dxdz.png" : "map of dxdz residual vs z",
26 "map_DTvsz_dydz.png" : "map of dydz residual vs z",
27 "map_DTvsz_x.png" : "map of x residual vs z",
28 "map_DTvsz_y.png" : "map of y residual vs z",
29 "map_DTvsz_all_dxdz.png" : "map of dxdz residual vs z",
30 "map_DTvsz_all_dydz.png" : "map of dydz residual vs z",
31 "map_DTvsz_all_x.png" : "map of x residual vs z",
32 "map_DTvsz_all_y.png" : "map of y residual vs z",
33 "map_CSCvsphi_dxdz.png" : "map of d(rphi)/dz residual vs phi",
34 "map_CSCvsphi_x.png" : "map of rphi residual vs phi",
35 "map_CSCvsr_dxdz.png" : "map of d(rphi)/dz residual vs r",
36 "map_CSCvsr_x.png" : "map of rphi residual vs r",
37 "segdifphi_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals vs phi",
38 "segdifphi_dt13_resid.png" : "segdiff in x residuals vs phi",
39 "segdifphi_dt13_slope.png" : "segdiff in dxdz residuals vs phi",
40 "segdifphi_dt2_resid.png" : "segdiff in y residuals vs phi",
41 "segdifphi_dt2_slope.png" : "segdiff in dydz residuals vs phi",
42 "segdif_x_dt_csc_resid.png" : "segdiff DT-CSC in x residuals",
43 "segdif_dt13_resid.png" : "segdiff in x residuals",
44 "segdif_dt13_slope.png" : "segdiff in dxdz residuals",
45 "segdif_dt2_resid.png" : "segdiff in y residuals",
46 "segdif_dt2_slope.png" : "segdiff in dydz residuals",
47 "segdifphi_csc_resid.png" : "segdiff in rphi residuals vs phi",
48 "segdifphi_csc_slope.png" : "segdiff in d(rphi)/dz residuals vs phi",
49 "segdif_csc_resid.png" : "segdiff in rphi residuals",
50 "segdif_csc_slope.png" : "segdiff in d(rphi)/dz residuals",
51 "dt_bellcurves.png" : "residuals distributions",
52 "dt_polynomials.png" : "residuals relations to misalignments",
53 "csc_bellcurves.png" : "residuals distributions",
54 "csc_polynomials.png" : "residuals relations to misalignments",
55 'dt_curvature_deltax.png' : 'Delta x residuals vs. curvature',
56 'dt_curvature_deltadxdz.png' : 'Delta dxdz residuals vs. curvature',
57 "medians.png" : "medians distribution"
58 }
59 ######################################################
60 # functions definitions
61 
62 ######################################################
63 # To parse commandline args
64 
65 usage='%prog [options]\n'+\
66  'Creates a tree_items.js data file for a browsable JavaScript tree using results produced '+\
67  'by running alignment_validation_plots.py.'
68 
69 parser=optparse.OptionParser(usage)
70 
71 parser.add_option("-i", "--inputDir",
72  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",
73  type="string",
74  default='',
75  dest="inputDir")
76 
77 parser.add_option("-v", "--verbose",
78  help="Degree of debug info verbosity",
79  type="int",
80  default=0,
81  dest="verbose")
82 
83 options,args=parser.parse_args()
84 
85 if options.inputDir=='':
86  print("\nOne or more of REQUIRED options is missing!\n")
87  parser.print_help()
88  # See \n"+sys.argv[0]+" --help"
89  sys.exit()
90 
91 ######################################################
92 
93 
94 
95 ############################################################################################################
96 ############################################################################################################
97 # main script
98 
99 # create directory structure
100 
101 #basedir='/disks/sdb5/home_reloc/khotilov/db/cms/alignment'
102 #os.chdir(basedir)
103 os.chdir(options.inputDir)
104 
105 #iteration1 = "iteration_01"
106 #iteration3 = "iteration_03"
107 #iteration1 = "NOV4DT_PASS3noweight_TkHIP_01"
108 #iteration3 = "NOV4DT_PASS3noweight_TkHIP_05"
109 iteration1 = "iter1"
110 iterationN = "iterN"
111 comdir = "common/"
112 
113 ######################################################
114 # open root and py result files
115 
116 iteration_directory = iterationN
117 
118 
119 def parseDir(dir,label,it1="",itN=""):
120  """it1 and itN are the first and the last iterations' directory names
121  dir is some directory with the results from for the LAST
122  iteration, so it must contain a itN substring
123  label is a label for tree's folder for this directory"""
124  if len(itN)>0 and dir.find(itN)==-1:
125  print("directory ", dir, "has no ", itN, " in it!!")
126  return ["problem!!!",""]
127  res = [label,dir]
128  files = sorted(os.listdir(dir))
129  for f in files:
130  if re.match(".+\.png", f):
131  if len(it1)>0 and len(itN)>0:
132  lnN = [itN,dir+'/'+f]
133  dir1 = dir.replace(itN,it1)
134  if not os.access(dir1+'/'+f,os.F_OK):
135  print("WARNING: no ",dir1+'/'+f," file found!!!")
136  ln1 = [it1,dir1+'/'+f]
137  ln = [NAME_TO_TITLE[f],dir+'/'+f,ln1,lnN]
138  res.append(ln)
139  else:
140  ln = [NAME_TO_TITLE[f],dir+'/'+f]
141  #print ln
142  res.append(ln)
143  #pp.pprint(res)
144  return res
145 
146 
147 mytree = []
148 tree_level1 = ['test','']
149 
150 # DT
151 dt_basedir = iteration_directory+'/MB/'
152 tree_level2 = parseDir(dt_basedir,"MB",iteration1,iterationN)
153 for wheel in DT_TYPES:
154  dd = dt_basedir + wheel[0]
155  print(dd)
156  tree_level3 = parseDir(dd,wheel[0],iteration1,iterationN)
157  for station in wheel[2]:
158  dd = dt_basedir + wheel[0]+'/'+station[1]
159  print(dd)
160  tree_level4 = parseDir(dd,station[0],iteration1,iterationN)
161  for sector in range(1,station[2]+1):
162  ssector = "%02d" % sector
163  dd = dt_basedir+wheel[0]+'/'+station[1]+'/'+ssector
164  #print dd
165  tree_level5 = parseDir(dd,"%s/%d" % (station[0],sector),iteration1,iterationN)
166  if len(tree_level5) == 2: tree_level5.append(['none',''])
167  tree_level4.append(tree_level5)
168  if len(tree_level4) == 2: tree_level4.append(['none',''])
169  tree_level3.append(tree_level4)
170  if len(tree_level3) == 2: tree_level3.append(['none',''])
171  tree_level2.append(tree_level3)
172 if len(tree_level2) == 2: tree_level2.append(['none',''])
173 tree_level1.append(tree_level2)
174 
175 # CSC
176 csc_basedir = iteration_directory+'/'
177 for endcap in CSC_TYPES:
178  dd = csc_basedir+endcap[0]
179  print(dd)
180  tree_level2 = parseDir(dd,endcap[0],iteration1,iterationN)
181  for station in endcap[2]:
182  dd = csc_basedir+endcap[0]+'/'+station[1]
183  print(dd)
184  tree_level3 = parseDir(dd,station[0],iteration1,iterationN)
185  for ring in station[2]:
186  dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]
187  print(dd)
188  tree_level4 = parseDir(dd,"%s/%s" % (station[0],ring[1]),iteration1,iterationN)
189  for chamber in range(1,ring[2]+1):
190  schamber = "%02d" % chamber
191  dd = csc_basedir+endcap[0]+'/'+station[1]+'/'+ring[1]+'/'+schamber
192  #print dd
193  tree_level5 = parseDir(dd,"%s/%s/%d" % (station[0],ring[1],chamber),iteration1,iterationN)
194  tree_level4.append(tree_level5)
195  if len(tree_level4) == 2: tree_level4.append(['none',''])
196  tree_level3.append(tree_level4)
197  if len(tree_level3) == 2: tree_level3.append(['none',''])
198  tree_level2.append(tree_level3)
199  if len(tree_level2) == 2: tree_level2.append(['none',''])
200  tree_level1.append(tree_level2)
201 
202 # Common plots
203 common_basedir = comdir
204 tree_level2 = parseDir(common_basedir,"All")
205 tree_level1.append(tree_level2)
206 
207 
208 mytree.append(tree_level1)
209 print(" ")
210 #pp.pprint(mytree)
211 print()
212 
213 ff = open("tree_items.js",mode="w")
214 print("var TREE_ITEMS = ", file=ff)
215 json.dump(mytree,ff)
216 ff.close()
const uint16_t range(const Frame &aFrame)
def parseDir
Definition: createTree.py:119
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47