4 from Alignment.OfflineValidation.TkAlMap
import TkAlMap
7 Script for plotting TkAlMaps
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>
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)
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
33 print(
'*---------------------------------------*')
34 print(
'| GCP TkAlMap |')
35 print(
'*---------------------------------------*')
39 var_list = [
'dr',
'dx',
'dy',
'dz',
'rdphi',
'dphi',
'dalpha',
'dbeta',
'dgamma',
'du',
'dv',
'dw',
'da',
'db',
'dg']
42 var_ranges[var] = [
None,
None]
45 print(
'Reading arguments')
47 al_ref =
'Reference Alignment'
48 al_comp =
'Compared Alignment'
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=',
'')
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=',
'')
94 title = al_comp +
' - ' + al_ref
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'
101 if '1' in palette_str: palette = 1
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
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
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]
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))
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))
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])
160 if var_ranges[var][1]
is None: prt_srt +=
'default'
161 else: prt_srt +=
str(var_ranges[var][1])
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)
178 ts_start = time.time()
180 print(
'----- Evaluating variable: '+var)
184 tmp_full = TkMap_full
185 tmp_full.set_var(var)
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)
192 tmp_pixel = TkMap_pixel
193 tmp_pixel.set_var(var)
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)
200 tmp_strips = TkMap_strips
201 tmp_strips.set_var(var)
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)
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')
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')
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')
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')
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')
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')
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()
263 print(
'TOOK: '+
str(time.time()-ts_start)+
' s')