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> TkVersion=<phase> outDir=<out_dir> colPal=<col_int> defRanges=<range_str> TkautoVersion= <tk_version_bool> savePNG=<png_bool> savePDF=<pdf_bool> do4sigCap=<4sig_bool> doDefRange=<drange_bool> doFullRange=<frange_bool> doFull=<full_bool> doPixel=<pixel_bool> doStrips=<strips_bool>
10 
11 Explanation:
12  - Mandatory arguments:
13  inFile=<file_path> path to root file containing geometry comparison tree "alignTree"
14  compAl=<c_alignment_name> name of alignment beeing compared (for title)
15  refAl=<r_alignment_name> name of reference alignment (for title)
16  - Optional arguments:
17  TkVersion=<phase> tracker version valid options: phase0, phase1
18  outDir=<out_dir> directory where to store the images
19  colPal=<col_int> color palette: 1 is rainbow palette, 2 is diverging color palette (blue to red)
20  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];"
21  TkautoVersion=<tk_version_bool> string boolean telling wheter or not to auto detect TkVersion (will override the TkVersion=<phase> selection)
22  savePNG=<png_bool> string boolean to save or not save as png
23  savePDF=<pdf_bool> string boolean to save or not save as pdf
24  do4sigCap=<4sig_bool> string boolean to plot 4sigma capped plots or not
25  doDefRange=<drange_bool> string boolean to plot default range capped plots or not
26  doFullRange=<frange_bool> string boolean to plot un-capped plots or not
27  doFull=<full_bool> string boolean to plot full detector or not
28  doPixel=<pixel_bool> string boolean to plot separate pixel detector or not
29  doStrips=<strips_bool> string boolean to plot separate strips detector or not
30 '''
31 
32 
33 print('*---------------------------------------*')
34 print('| GCP TkAlMap |')
35 print('*---------------------------------------*')
36 
37 #var_list = ['dr']
38 #var_list = ['dx', 'dy', 'dz']
39 var_list = ['dr', 'dx', 'dy', 'dz', 'rdphi', 'dphi', 'dalpha', 'dbeta', 'dgamma', 'du', 'dv', 'dw', 'da', 'db', 'dg']
40 var_ranges = {}
41 for var in var_list:
42  var_ranges[var] = [None, None]
43 
44 # Our own parser
45 print('Reading arguments')
46 arguments = sys.argv
47 al_ref = 'Reference Alignment'
48 al_comp = 'Compared Alignment'
49 out_dir = '.'
50 phase_str = ''
51 auto_tk_str = ''
52 palette_str = ''
53 range_str = ''
54 
55 save_png = False
56 save_pdf = True
57 do_4scap = False
58 do_drange = False
59 do_frange = True
60 do_full = True
61 do_pixel = False
62 do_strips = False
63 
64 save_png_str = ''
65 save_pdf_str = ''
66 do_4scap_str = ''
67 do_drange_str = ''
68 do_frange_str = ''
69 do_full_str = ''
70 do_pixel_str = ''
71 do_strips_str = ''
72 
73 for arg in arguments:
74  if 'inFile=' in arg : in_file = arg.replace('inFile=', '')
75  if 'refAl=' in arg : al_ref = arg.replace('refAl=', '')
76  if 'compAl=' in arg : al_comp = arg.replace('compAl=', '')
77  if 'outDir=' in arg : out_dir = arg.replace('outDir=', '')
78  if 'TkVersion='in arg : phase_str = arg.replace('TkVersion=', '')
79  if 'TkautoVersion='in arg: auto_tk_str = arg.replace('TkautoVersion=', '')
80  if 'colPal='in arg : palette_str = arg.replace('colPal=', '')
81  if 'defRanges=' in arg : range_str = arg.replace('defRanges=', '')
82  # Limit outputs
83  if 'savePNG=' in arg : save_png_str = arg.replace('savePNG=', '')
84  if 'savePDF=' in arg : save_pdf_str = arg.replace('savePDF=', '')
85  if 'do4sigCap=' in arg : do_4scap_str = arg.replace('do4sigCap=', '')
86  if 'doDefRange=' in arg : do_drange_str = arg.replace('doDefRange=', '')
87  if 'doFullRange=' in arg : do_frange_str = arg.replace('doFullRange=', '')
88  if 'doFull=' in arg : do_full_str = arg.replace('doFull=', '')
89  if 'doPixel=' in arg : do_pixel_str = arg.replace('doPixel=', '')
90  if 'doStrips=' in arg : do_strips_str = arg.replace('doStrips=', '')
91 
92 # Digest arguments
93 phase = 1
94 title = al_comp + ' - ' + al_ref
95 auto_tk = True
96 if 'FALSE' in auto_tk_str.upper(): auto_tk = False
97 if 'PHASE0' in phase_str.upper() : phase = 0
98 geometry_file = 'TkAlMapDesign_phase1_cfg.py'
99 if phase == 1: geometry_file = 'TkAlMapDesign_phase0_cfg.py'
100 palette = 2
101 if '1' in palette_str: palette = 1
102 
103 if 'TRUE' in save_png_str .upper(): save_png = True
104 if 'TRUE' in save_pdf_str .upper(): save_pdf = True
105 if 'TRUE' in do_4scap_str .upper(): do_4scap = True
106 if 'TRUE' in do_drange_str.upper(): do_drange = True
107 if 'TRUE' in do_frange_str.upper(): do_frange = True
108 if 'TRUE' in do_full_str .upper(): do_full = True
109 if 'TRUE' in do_pixel_str .upper(): do_pixel = True
110 if 'TRUE' in do_strips_str.upper(): do_strips = True
111 
112 if 'FALSE' in save_png_str .upper(): save_png = False
113 if 'FALSE' in save_pdf_str .upper(): save_pdf = False
114 if 'FALSE' in do_4scap_str .upper(): do_4scap = False
115 if 'FALSE' in do_drange_str.upper(): do_drange = False
116 if 'FALSE' in do_frange_str.upper(): do_frange = False
117 if 'FALSE' in do_full_str .upper(): do_full = False
118 if 'FALSE' in do_pixel_str .upper(): do_pixel = False
119 if 'FALSE' in do_strips_str.upper(): do_strips = False
120 
121 
122 range_str_splt = range_str.split(';')
123 for var_range_str in range_str_splt:
124  cur_var = var_range_str.split('=')[0]
125  if cur_var == '': continue
126  cur_range = eval(var_range_str.split('=')[1])
127  for var in var_ranges:
128  if var+'_range' == cur_var:
129  if cur_range[0] != -99999: var_ranges[var][0] = cur_range[0]
130  if cur_range[1] != -99999: var_ranges[var][1] = cur_range[1]
131  #max_val = float(var_range_str.split('=')[1].split(',')[0].replace('[', ''))
132  #min_val = float(var_range_str.split('=')[1].split(',')[1].replace(']', ''))
133 
134 print('Current setup:')
135 print(' - reference alingment : '+al_ref)
136 print(' - compared alingment : '+al_comp)
137 print(' - tracker version : phase '+str(phase))
138 print(' - auto detect tracker version : '+str(auto_tk))
139 print(' - color palette : '+str(palette))
140 print(' - input root file : '+in_file)
141 print(' - output directory : '+out_dir)
142 print(' - saving as png : '+str(save_png))
143 print(' - saving as pdf : '+str(save_pdf))
144 print('')
145 print('Active plots:')
146 print(' - plot 4 sigma capped values : '+str(do_4scap))
147 print(' - plot default range capped values : '+str(do_drange))
148 print(' - plot un-capped values : '+str(do_frange))
149 print(' - plot full detector : '+str(do_full))
150 print(' - plot pixel detector : '+str(do_pixel))
151 print(' - plot strips detector : '+str(do_strips))
152 print('')
153 print('Changed default ranges:')
154 for var in var_ranges:
155  if var_ranges[var][0] is None and var_ranges[var][1] is None: continue
156  prt_srt = ' - '+var+'\t: [ '
157  if var_ranges[var][0] is None: prt_srt += 'default'
158  else: prt_srt += str(var_ranges[var][0])
159  prt_srt += '\t, '
160  if var_ranges[var][1] is None: prt_srt += 'default'
161  else: prt_srt += str(var_ranges[var][1])
162  prt_srt += '\t]'
163  print(prt_srt)
164 
165 
166 # Load maps for different configurations
167 print('Loading maps')
168 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)
169 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)
170 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)
171 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)
172 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)
173 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)
174 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)
175 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)
176 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)
177 
178 ts_start = time.time()
179 for var in var_list:
180  print('----- Evaluating variable: '+var)
181  # Usual setup
182  if do_frange:
183  if do_full:
184  tmp_full = TkMap_full
185  tmp_full.set_var(var)
186  tmp_full.analyse()
187  if save_pdf: tmp_full.save(out_dir=out_dir)
188  if save_png: tmp_full.save(out_dir=out_dir, extension='png')
189  tmp_full.plot_variable_distribution(out_dir=out_dir)
190 
191  if do_pixel:
192  tmp_pixel = TkMap_pixel
193  tmp_pixel.set_var(var)
194  tmp_pixel.analyse()
195  if save_pdf: tmp_pixel.save(out_dir=out_dir)
196  if save_png: tmp_pixel.save(out_dir=out_dir, extension='png')
197  tmp_pixel.plot_variable_distribution(out_dir=out_dir)
198 
199  if do_strips:
200  tmp_strips = TkMap_strips
201  tmp_strips.set_var(var)
202  tmp_strips.analyse()
203  if save_pdf: tmp_strips.save(out_dir=out_dir)
204  if save_png: tmp_strips.save(out_dir=out_dir, extension='png')
205  tmp_strips.plot_variable_distribution(out_dir=out_dir)
206 
207  # 4 sigma capping
208  if do_4scap:
209  if do_full:
210  tmp_cap_full = TkMap_cap_full
211  tmp_cap_full.set_var(var)
212  tmp_cap_full.analyse()
213  if save_pdf: tmp_cap_full.save(out_dir=out_dir)
214  if save_png: tmp_cap_full.save(out_dir=out_dir, extension='png')
215 
216  if do_pixel:
217  tmp_cap_pixel = TkMap_cap_pixel
218  tmp_cap_pixel.set_var(var)
219  tmp_cap_pixel.analyse()
220  if save_pdf: tmp_cap_pixel.save(out_dir=out_dir)
221  if save_png: tmp_cap_pixel.save(out_dir=out_dir, extension='png')
222 
223  if do_strips:
224  tmp_cap_strips = TkMap_cap_strips
225  tmp_cap_strips.set_var(var)
226  tmp_cap_strips.analyse()
227  if save_pdf: tmp_cap_strips.save(out_dir=out_dir)
228  if save_png: tmp_cap_strips.save(out_dir=out_dir, extension='png')
229 
230  # default ranges
231  if do_drange:
232  if do_full:
233  tmp_drange_full = TkMap_drange_full
234  tmp_drange_full.set_var(var, var_ranges[var])
235  tmp_drange_full.analyse()
236  if save_pdf: tmp_drange_full.save(out_dir=out_dir)
237  if save_png: tmp_drange_full.save(out_dir=out_dir, extension='png')
238 
239  if do_pixel:
240  tmp_drange_pixel = TkMap_drange_pixel
241  tmp_drange_pixel.set_var(var, var_ranges[var])
242  tmp_drange_pixel.analyse()
243  if save_pdf: tmp_drange_pixel.save(out_dir=out_dir)
244  if save_png: tmp_drange_pixel.save(out_dir=out_dir, extension='png')
245 
246  if do_strips:
247  tmp_drange_strips = TkMap_drange_strips
248  tmp_drange_strips.set_var(var, var_ranges[var])
249  tmp_drange_strips.analyse()
250  if save_pdf: tmp_drange_strips.save(out_dir=out_dir)
251  if save_png: tmp_drange_strips.save(out_dir=out_dir, extension='png')
252 
253 TkMap_full.clean_up()
254 TkMap_pixel.clean_up()
255 TkMap_strips.clean_up()
256 TkMap_cap_full.clean_up()
257 TkMap_cap_pixel.clean_up()
258 TkMap_cap_strips.clean_up()
259 TkMap_drange_full.clean_up()
260 TkMap_drange_pixel.clean_up()
261 TkMap_drange_strips.clean_up()
262 
263 print('TOOK: '+str(time.time()-ts_start)+' s')
TkAlMap
Definition: TkAlMap.py:1
str
#define str(s)
Definition: TestProcessor.cc:51
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
pileupCalc.upper
upper
Definition: pileupCalc.py:214