CMS 3D CMS Logo

runGCPTkAlMap.py
Go to the documentation of this file.
1 import sys
2 import copy
3 import time
4 from Alignment.OfflineValidation.TkAlMap import TkAlMap
5 
6 '''
7 Script for plotting TkAlMaps
8 How to run:
9  python runGCPTkAlMap.py -b inFile=<file_path> compAl=<c_alignment_name> refAl=<r_alignment_name> savePNG=<png_bool> TkVersion=<phase> outDir=<out_dir> colPal=<col_int> defRanges=<range_str> TkautoVersion= <tk_version_bool>
10 
11 Explanation:
12  inFile=<file_path> path to root file containing geometry comparison tree "alignTree"
13  compAl=<c_alignment_name> name of alignment beeing compared (for title)
14  refAl=<r_alignment_name> name of reference alignment (for title)
15  savePNG=<png_bool> string boolean to save or not save as png
16  TkVersion=<phase> tracker version valid options: phase0, phase1
17  outDir=<out_dir> directory where to store the images
18  colPal=<col_int> color palette: 1 is rainbow palette, 2 is diverging color palette (blue to red)
19  defRanges=<range_str> string containing changes to default range in format "<var>_range=[<min>,<max>];<var2>_..." example: "dr_range=[-10,10];rdphi_range=[-2.02,120];"
20  TkautoVersion=<tk_version_bool> string boolean telling wheter or not to auto detect TkVersion (will override the TkVersion=<phase> selection)
21 '''
22 
23 
24 print('*---------------------------------------*')
25 print('| GCP TkAlMap |')
26 print('*---------------------------------------*')
27 
28 var_list = ['dr']
29 #var_list = ['dx', 'dy', 'dz']
30 #var_list = ['dr', 'dx', 'dy', 'dz', 'rdphi', 'dphi', 'dalpha', 'dbeta', 'dgamma', 'du', 'dv', 'dw', 'da', 'db', 'dg']
31 var_ranges = {}
32 for var in var_list:
33  var_ranges[var] = [None, None]
34 
35 # Our own parser
36 print('Reading arguments')
37 arguments = sys.argv
38 al_ref = 'Reference Alignment'
39 al_comp = 'Compared Alignment'
40 out_dir = '.'
41 save_png = False
42 save_png_str = ''
43 phase_str = ''
44 auto_tk_str = ''
45 palette_str = ''
46 range_str = ''
47 for arg in arguments:
48  if 'inFile=' in arg : in_file = arg.replace('inFile=', '')
49  if 'refAl=' in arg : al_ref = arg.replace('refAl=', '')
50  if 'compAl=' in arg : al_comp = arg.replace('compAl=', '')
51  if 'outDir=' in arg : out_dir = arg.replace('outDir=', '')
52  if 'savePNG=' in arg : save_png_str = arg.replace('savePNG=', '')
53  if 'TkVersion='in arg : phase_str = arg.replace('TkVersion=', '')
54  if 'TkautoVersion='in arg: auto_tk_str = arg.replace('TkautoVersion=', '')
55  if 'colPal='in arg : palette_str = arg.replace('colPal=', '')
56  if 'defRanges=' in arg : range_str = arg.replace('defRanges=', '')
57 
58 # Digest arguments
59 phase = 1
60 title = al_comp + ' - ' + al_ref
61 if 'TRUE' in save_png_str.upper(): save_png = True
62 auto_tk = True
63 if 'FALSE' in auto_tk_str.upper(): auto_tk = False
64 if 'PHASE0' in phase_str.upper() : phase = 0
65 geometry_file = 'TkAlMapDesign_phase1_cfg.py'
66 if phase == 1: geometry_file = 'TkAlMapDesign_phase0_cfg.py'
67 palette = 2
68 if '1' in palette_str: palette = 1
69 
70 range_str_splt = range_str.split(';')
71 for var_range_str in range_str_splt:
72  cur_var = var_range_str.split('=')[0]
73  if cur_var == '': continue
74  cur_range = eval(var_range_str.split('=')[1])
75  for var in var_ranges:
76  if var+'_range' == cur_var:
77  if cur_range[0] != -99999: var_ranges[var][0] = cur_range[0]
78  if cur_range[1] != -99999: var_ranges[var][1] = cur_range[1]
79  #max_val = float(var_range_str.split('=')[1].split(',')[0].replace('[', ''))
80  #min_val = float(var_range_str.split('=')[1].split(',')[1].replace(']', ''))
81 
82 print('Current setup:')
83 print(' - reference alingment : '+al_ref)
84 print(' - compared alingment : '+al_comp)
85 print(' - tracker version : phase '+str(phase))
86 print(' - auto detect tracker version : '+str(auto_tk))
87 print(' - saving as png : '+str(save_png))
88 print(' - color palette : '+str(palette))
89 print(' - input root file : '+in_file)
90 print(' - output directory : '+out_dir)
91 print('')
92 print('Changed default ranges:')
93 for var in var_ranges:
94  if var_ranges[var][0] is None and var_ranges[var][1] is None: continue
95  prt_srt = ' - '+var+'\t: [ '
96  if var_ranges[var][0] is None: prt_srt += 'default'
97  else: prt_srt += str(var_ranges[var][0])
98  prt_srt += '\t, '
99  if var_ranges[var][1] is None: prt_srt += 'default'
100  else: prt_srt += str(var_ranges[var][1])
101  prt_srt += '\t]'
102  print(prt_srt)
103 
104 
105 # Load maps for different configurations
106 print('Loading maps')
107 TkMap_full = TkAlMap('test', title, in_file, use_default_range=False, two_sigma_cap=False, GEO_file=geometry_file, tracker='full', palette=palette, check_tracker=auto_tk)
108 TkMap_pixel = TkAlMap('test', title, in_file, use_default_range=False, two_sigma_cap=False, GEO_file=geometry_file, tracker='pixel', palette=palette, check_tracker=auto_tk)
109 TkMap_strips = TkAlMap('test', title, in_file, use_default_range=False, two_sigma_cap=False, GEO_file=geometry_file, tracker='strips', palette=palette, check_tracker=auto_tk)
110 TkMap_cap_full = TkAlMap('test', title, in_file, use_default_range=False, two_sigma_cap=True, GEO_file=geometry_file, tracker='full', palette=palette, check_tracker=auto_tk)
111 TkMap_cap_pixel = TkAlMap('test', title, in_file, use_default_range=False, two_sigma_cap=True, GEO_file=geometry_file, tracker='pixel', palette=palette, check_tracker=auto_tk)
112 TkMap_cap_strips = TkAlMap('test', title, in_file, use_default_range=False, two_sigma_cap=True, GEO_file=geometry_file, tracker='strips', palette=palette, check_tracker=auto_tk)
113 TkMap_drange_full = TkAlMap('test', title, in_file, use_default_range=True, two_sigma_cap=False, GEO_file=geometry_file, tracker='full', palette=palette, check_tracker=auto_tk)
114 TkMap_drange_pixel = TkAlMap('test', title, in_file, use_default_range=True, two_sigma_cap=False, GEO_file=geometry_file, tracker='pixel', palette=palette, check_tracker=auto_tk)
115 TkMap_drange_strips = TkAlMap('test', title, in_file, use_default_range=True, two_sigma_cap=False, GEO_file=geometry_file, tracker='strips', palette=palette, check_tracker=auto_tk)
116 
117 ts_start = time.time()
118 for var in var_list:
119  print('----- Evaluating variable: '+var)
120  # Usual setup
121  tmp_full = TkMap_full
122  tmp_full.set_var(var)
123  tmp_full.analyse()
124  tmp_full.save(out_dir=out_dir)
125  if save_png: tmp_full.save(out_dir=out_dir, extension='png')
126  tmp_full.plot_variable_distribution(out_dir=out_dir)
127 
128  tmp_pixel = TkMap_pixel
129  tmp_pixel.set_var(var)
130  tmp_pixel.analyse()
131  tmp_pixel.save(out_dir=out_dir)
132  if save_png: tmp_pixel.save(out_dir=out_dir, extension='png')
133  tmp_pixel.plot_variable_distribution(out_dir=out_dir)
134 
135  tmp_strips = TkMap_strips
136  tmp_strips.set_var(var)
137  tmp_strips.analyse()
138  tmp_strips.save(out_dir=out_dir)
139  if save_png: tmp_strips.save(out_dir=out_dir, extension='png')
140  tmp_strips.plot_variable_distribution(out_dir=out_dir)
141 
142  # 4 sigma capping
143  tmp_cap_full = TkMap_cap_full
144  tmp_cap_full.set_var(var)
145  tmp_cap_full.analyse()
146  tmp_cap_full.save(out_dir=out_dir)
147  if save_png: tmp_cap_full.save(out_dir=out_dir, extension='png')
148 
149  tmp_cap_pixel = TkMap_cap_pixel
150  tmp_cap_pixel.set_var(var)
151  tmp_cap_pixel.analyse()
152  tmp_cap_pixel.save(out_dir=out_dir)
153  if save_png: tmp_cap_pixel.save(out_dir=out_dir, extension='png')
154 
155  tmp_cap_strips = TkMap_cap_strips
156  tmp_cap_strips.set_var(var)
157  tmp_cap_strips.analyse()
158  tmp_cap_strips.save(out_dir=out_dir)
159  if save_png: tmp_cap_strips.save(out_dir=out_dir, extension='png')
160 
161  # default ranges
162  tmp_drange_full = TkMap_drange_full
163  tmp_drange_full.set_var(var, var_ranges[var])
164  tmp_drange_full.analyse()
165  tmp_drange_full.save(out_dir=out_dir)
166  if save_png: tmp_drange_full.save(out_dir=out_dir, extension='png')
167 
168  tmp_drange_pixel = TkMap_drange_pixel
169  tmp_drange_pixel.set_var(var, var_ranges[var])
170  tmp_drange_pixel.analyse()
171  tmp_drange_pixel.save(out_dir=out_dir)
172  if save_png: tmp_drange_pixel.save(out_dir=out_dir, extension='png')
173 
174  tmp_drange_strips = TkMap_drange_strips
175  tmp_drange_strips.set_var(var, var_ranges[var])
176  tmp_drange_strips.analyse()
177  tmp_drange_strips.save(out_dir=out_dir)
178  if save_png: tmp_drange_strips.save(out_dir=out_dir, extension='png')
179 
180 TkMap_full.clean_up()
181 TkMap_pixel.clean_up()
182 TkMap_strips.clean_up()
183 TkMap_cap_full.clean_up()
184 TkMap_cap_pixel.clean_up()
185 TkMap_cap_strips.clean_up()
186 TkMap_drange_full.clean_up()
187 TkMap_drange_pixel.clean_up()
188 TkMap_drange_strips.clean_up()
189 
190 print('TOOK: '+str(time.time()-ts_start)+' s')
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)