Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:57:12

0001 import sys
0002 import copy
0003 import time
0004 from Alignment.OfflineValidation.TkAlMap import TkAlMap
0005 
0006 '''
0007 Script for plotting TkAlMaps
0008 How to run:
0009     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>
0010 
0011 Explanation:
0012  - Mandatory arguments:
0013     inFile=<file_path>                 path to root file containing geometry comparison tree "alignTree"
0014     compAl=<c_alignment_name>          name of alignment beeing compared (for title)
0015     refAl=<r_alignment_name>           name of reference alignment (for title)
0016  - Optional arguments:
0017     TkVersion=<phase>                  tracker version valid options: phase0, phase1
0018     outDir=<out_dir>                   directory where to store the images
0019     colPal=<col_int>                   color palette: 1 is rainbow palette, 2 is diverging color palette (blue to red)
0020     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];"
0021     TkautoVersion=<tk_version_bool>    string boolean telling wheter or not to auto detect TkVersion (will override the TkVersion=<phase> selection)
0022     savePNG=<png_bool>                 string boolean to save or not save as png
0023     savePDF=<pdf_bool>                 string boolean to save or not save as pdf
0024     do4sigCap=<4sig_bool>              string boolean to plot 4sigma capped plots or not   
0025     doDefRange=<drange_bool>           string boolean to plot default range capped plots or not 
0026     doFullRange=<frange_bool>          string boolean to plot un-capped plots or not
0027     doFull=<full_bool>                 string boolean to plot full detector or not
0028     doPixel=<pixel_bool>               string boolean to plot separate pixel detector or not
0029     doStrips=<strips_bool>             string boolean to plot separate strips detector or not
0030 '''
0031 
0032 
0033 print('*---------------------------------------*')
0034 print('|             GCP TkAlMap               |')
0035 print('*---------------------------------------*')
0036 
0037 #var_list = ['dr']
0038 #var_list = ['dx', 'dy', 'dz']
0039 var_list = ['dr', 'dx', 'dy', 'dz', 'rdphi', 'dphi', 'dalpha', 'dbeta', 'dgamma', 'du', 'dv', 'dw', 'da', 'db', 'dg']
0040 var_ranges = {}
0041 for var in var_list:
0042     var_ranges[var] = [None, None]
0043 
0044 # Our own parser
0045 print('Reading arguments')
0046 arguments = sys.argv
0047 al_ref = 'Reference Alignment'
0048 al_comp = 'Compared Alignment'
0049 out_dir = '.'
0050 phase_str = ''
0051 auto_tk_str = ''
0052 palette_str = ''
0053 range_str = ''
0054 
0055 save_png  = False
0056 save_pdf  = True
0057 do_4scap  = False
0058 do_drange = False
0059 do_frange = True
0060 do_full   = True
0061 do_pixel  = False
0062 do_strips = False
0063 
0064 save_png_str  = ''
0065 save_pdf_str  = ''
0066 do_4scap_str  = ''
0067 do_drange_str = ''
0068 do_frange_str = ''
0069 do_full_str   = ''
0070 do_pixel_str  = ''
0071 do_strips_str = ''
0072 
0073 for arg in arguments:
0074     if 'inFile=' in arg      : in_file      = arg.replace('inFile=', '')
0075     if 'refAl=' in arg       : al_ref       = arg.replace('refAl=', '')
0076     if 'compAl=' in arg      : al_comp      = arg.replace('compAl=', '')
0077     if 'outDir=' in arg      : out_dir      = arg.replace('outDir=', '')
0078     if 'TkVersion='in arg    : phase_str    = arg.replace('TkVersion=', '')
0079     if 'TkautoVersion='in arg: auto_tk_str  = arg.replace('TkautoVersion=', '')
0080     if 'colPal='in arg       : palette_str  = arg.replace('colPal=', '')
0081     if 'defRanges=' in arg   : range_str    = arg.replace('defRanges=', '')
0082     # Limit outputs
0083     if 'savePNG=' in arg     : save_png_str    = arg.replace('savePNG=', '')
0084     if 'savePDF=' in arg     : save_pdf_str    = arg.replace('savePDF=', '')
0085     if 'do4sigCap=' in arg   : do_4scap_str    = arg.replace('do4sigCap=', '')
0086     if 'doDefRange=' in arg  : do_drange_str   = arg.replace('doDefRange=', '')
0087     if 'doFullRange=' in arg : do_frange_str   = arg.replace('doFullRange=', '')
0088     if 'doFull=' in arg      : do_full_str     = arg.replace('doFull=', '')
0089     if 'doPixel=' in arg     : do_pixel_str    = arg.replace('doPixel=', '')
0090     if 'doStrips=' in arg    : do_strips_str   = arg.replace('doStrips=', '')
0091 
0092 # Digest arguments
0093 phase = 1
0094 title = al_comp + ' - ' + al_ref
0095 auto_tk = True
0096 if 'FALSE' in auto_tk_str.upper(): auto_tk = False
0097 if 'PHASE0' in phase_str.upper() : phase = 0
0098 geometry_file = 'TkAlMapDesign_phase1_cfg.py'
0099 if phase == 1: geometry_file = 'TkAlMapDesign_phase0_cfg.py'
0100 palette = 2
0101 if '1' in palette_str: palette = 1
0102 
0103 if 'TRUE' in save_png_str .upper(): save_png  = True 
0104 if 'TRUE' in save_pdf_str .upper(): save_pdf  = True 
0105 if 'TRUE' in do_4scap_str .upper(): do_4scap  = True 
0106 if 'TRUE' in do_drange_str.upper(): do_drange = True 
0107 if 'TRUE' in do_frange_str.upper(): do_frange = True 
0108 if 'TRUE' in do_full_str  .upper(): do_full   = True 
0109 if 'TRUE' in do_pixel_str .upper(): do_pixel  = True 
0110 if 'TRUE' in do_strips_str.upper(): do_strips = True 
0111 
0112 if 'FALSE' in save_png_str .upper(): save_png  = False 
0113 if 'FALSE' in save_pdf_str .upper(): save_pdf  = False 
0114 if 'FALSE' in do_4scap_str .upper(): do_4scap  = False 
0115 if 'FALSE' in do_drange_str.upper(): do_drange = False 
0116 if 'FALSE' in do_frange_str.upper(): do_frange = False 
0117 if 'FALSE' in do_full_str  .upper(): do_full   = False 
0118 if 'FALSE' in do_pixel_str .upper(): do_pixel  = False 
0119 if 'FALSE' in do_strips_str.upper(): do_strips = False 
0120 
0121 
0122 range_str_splt = range_str.split(';')
0123 for var_range_str in range_str_splt:
0124     cur_var = var_range_str.split('=')[0]
0125     if cur_var == '': continue
0126     cur_range = eval(var_range_str.split('=')[1])
0127     for var in var_ranges:
0128         if var+'_range' == cur_var:
0129             if cur_range[0] != -99999: var_ranges[var][0] = cur_range[0]
0130             if cur_range[1] != -99999: var_ranges[var][1] = cur_range[1]
0131     #max_val = float(var_range_str.split('=')[1].split(',')[0].replace('[', '')) 
0132     #min_val = float(var_range_str.split('=')[1].split(',')[1].replace(']', '')) 
0133 
0134 print('Current setup:')
0135 print(' - reference alingment              : '+al_ref)
0136 print(' - compared alingment               : '+al_comp)
0137 print(' - tracker version                  : phase '+str(phase))
0138 print(' - auto detect tracker version      : '+str(auto_tk))
0139 print(' - color palette                    : '+str(palette))
0140 print(' - input root file                  : '+in_file)
0141 print(' - output directory                 : '+out_dir)
0142 print(' - saving as png                    : '+str(save_png))
0143 print(' - saving as pdf                    : '+str(save_pdf))
0144 print('')
0145 print('Active plots:')
0146 print(' - plot 4 sigma capped values       : '+str(do_4scap))
0147 print(' - plot default range capped values : '+str(do_drange))
0148 print(' - plot un-capped values            : '+str(do_frange))
0149 print(' - plot full detector               : '+str(do_full))
0150 print(' - plot pixel detector              : '+str(do_pixel))
0151 print(' - plot strips detector             : '+str(do_strips))
0152 print('')
0153 print('Changed default ranges:')
0154 for var in var_ranges:
0155     if var_ranges[var][0] is None and var_ranges[var][1] is None: continue
0156     prt_srt = ' - '+var+'\t: [ '
0157     if var_ranges[var][0] is None: prt_srt += 'default'
0158     else: prt_srt += str(var_ranges[var][0])
0159     prt_srt += '\t, '
0160     if var_ranges[var][1] is None: prt_srt += 'default'
0161     else: prt_srt += str(var_ranges[var][1])
0162     prt_srt += '\t]'
0163     print(prt_srt)
0164   
0165 
0166 # Load maps for different configurations
0167 print('Loading maps')
0168 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)
0169 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)
0170 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)
0171 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)
0172 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)
0173 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)
0174 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)
0175 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)
0176 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)
0177 
0178 ts_start = time.time()
0179 for var in var_list:
0180     print('----- Evaluating variable: '+var)
0181     # Usual setup
0182     if do_frange:
0183         if do_full:
0184             tmp_full = TkMap_full
0185             tmp_full.set_var(var)
0186             tmp_full.analyse()  
0187             if save_pdf: tmp_full.save(out_dir=out_dir)  
0188             if save_png: tmp_full.save(out_dir=out_dir, extension='png')  
0189             tmp_full.plot_variable_distribution(out_dir=out_dir)
0190 
0191         if do_pixel:
0192             tmp_pixel = TkMap_pixel
0193             tmp_pixel.set_var(var)
0194             tmp_pixel.analyse()  
0195             if save_pdf: tmp_pixel.save(out_dir=out_dir)  
0196             if save_png: tmp_pixel.save(out_dir=out_dir, extension='png')  
0197             tmp_pixel.plot_variable_distribution(out_dir=out_dir)
0198 
0199         if do_strips:
0200             tmp_strips = TkMap_strips
0201             tmp_strips.set_var(var)
0202             tmp_strips.analyse()  
0203             if save_pdf: tmp_strips.save(out_dir=out_dir)  
0204             if save_png: tmp_strips.save(out_dir=out_dir, extension='png')  
0205             tmp_strips.plot_variable_distribution(out_dir=out_dir)
0206 
0207     # 4 sigma capping
0208     if do_4scap:
0209         if do_full:
0210             tmp_cap_full = TkMap_cap_full
0211             tmp_cap_full.set_var(var)
0212             tmp_cap_full.analyse()  
0213             if save_pdf: tmp_cap_full.save(out_dir=out_dir)  
0214             if save_png: tmp_cap_full.save(out_dir=out_dir, extension='png')  
0215 
0216         if do_pixel:
0217             tmp_cap_pixel = TkMap_cap_pixel
0218             tmp_cap_pixel.set_var(var)
0219             tmp_cap_pixel.analyse()  
0220             if save_pdf: tmp_cap_pixel.save(out_dir=out_dir)  
0221             if save_png: tmp_cap_pixel.save(out_dir=out_dir, extension='png')  
0222 
0223         if do_strips:
0224             tmp_cap_strips = TkMap_cap_strips
0225             tmp_cap_strips.set_var(var)
0226             tmp_cap_strips.analyse()  
0227             if save_pdf: tmp_cap_strips.save(out_dir=out_dir)
0228             if save_png: tmp_cap_strips.save(out_dir=out_dir, extension='png')  
0229 
0230     # default ranges
0231     if do_drange:
0232         if do_full:
0233             tmp_drange_full = TkMap_drange_full
0234             tmp_drange_full.set_var(var, var_ranges[var])
0235             tmp_drange_full.analyse()  
0236             if save_pdf: tmp_drange_full.save(out_dir=out_dir)  
0237             if save_png: tmp_drange_full.save(out_dir=out_dir, extension='png')  
0238 
0239         if do_pixel:
0240             tmp_drange_pixel = TkMap_drange_pixel
0241             tmp_drange_pixel.set_var(var, var_ranges[var])
0242             tmp_drange_pixel.analyse()  
0243             if save_pdf: tmp_drange_pixel.save(out_dir=out_dir)  
0244             if save_png: tmp_drange_pixel.save(out_dir=out_dir, extension='png')  
0245 
0246         if do_strips:
0247             tmp_drange_strips = TkMap_drange_strips
0248             tmp_drange_strips.set_var(var, var_ranges[var])
0249             tmp_drange_strips.analyse()  
0250             if save_pdf: tmp_drange_strips.save(out_dir=out_dir)
0251             if save_png: tmp_drange_strips.save(out_dir=out_dir, extension='png')  
0252 
0253 TkMap_full.clean_up()         
0254 TkMap_pixel.clean_up()        
0255 TkMap_strips.clean_up()       
0256 TkMap_cap_full.clean_up()     
0257 TkMap_cap_pixel.clean_up()    
0258 TkMap_cap_strips.clean_up()   
0259 TkMap_drange_full.clean_up()  
0260 TkMap_drange_pixel.clean_up() 
0261 TkMap_drange_strips.clean_up()
0262 
0263 print('TOOK: '+str(time.time()-ts_start)+' s')