CMS 3D CMS Logo

GCPpyPlots.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 import sys
3 argv = sys.argv
4 sys.argv = argv[:1]
5 
6 import os
7 import json
8 import yaml
9 import copy
10 import ROOT
11 import argparse
12 
13 from Alignment.OfflineValidation.TkAlMap import TkAlMap
14 
15 def parser():
16  sys.argv = argv
17  parser = argparse.ArgumentParser(description = "run the python plots for the AllInOneTool validations", formatter_class=argparse.RawTextHelpFormatter)
18  parser.add_argument("config", metavar='config', type=str, action="store", help="GCP AllInOneTool config (json/yaml format)")
19  parser.add_argument("-b", "--batch", action = "store_true", help ="Batch mode")
20 
21  sys.argv.append( '-b' )
22  ROOT.gROOT.SetBatch()
23  return parser.parse_args()
24 
25 def TkAlMap_plots(config):
26  root_file = str(config['output']) + '/GCPtree.root'
27  destination = str(config['output'])
28  plot_dir = destination + '/TkAlMaps'
29 
30  com_vs_ref = config['alignments']['comp']['title'] + ' vs ' + config['alignments']['ref']['title']
31  iov_vs_iov = str(config['validation']['IOVcomp']) + ' - ' + str(config['validation']['IOVref'])
32  title = '#splitline{'+com_vs_ref+'}{'+iov_vs_iov+'}'
33 
34  if not os.path.isdir(plot_dir): os.mkdir(plot_dir)
35 
36  plot_png = False
37  if 'plotPng' in config['validation']['GCP']:
38  plot_png = config['validation']['GCP']['plotPng']
39 
40  palette = 2 #1 is rainbow palette, 2 is diverging color palette (blue to red)
41 
42  var_list = ['dr', 'dx', 'dy', 'dz', 'rdphi', 'dphi'] #, 'dalpha', 'dbeta', 'dgamma', 'du', 'dv', 'dw', 'da', 'db', 'dg']
43  TkMap_pixel = TkAlMap(
44  'dummy_var', title, root_file,
45  use_default_range=True, two_sigma_cap=False,
46  tracker='pixel',
47  palette=palette, check_tracker=True
48  )
49  TkMap_strips = TkAlMap(
50  'dummy_var', title, root_file,
51  use_default_range=True, two_sigma_cap=False,
52  tracker='strips',
53  palette=palette, check_tracker=True
54  )
55 
56  for var in var_list:
57  print(' --- Creating maps for variable: '+var)
58  var_range = [None, None]
59  if var+'_min' in config['validation']['GCP']: var_range[0] = float(config['validation']['GCP'][var+'_min'])
60  if var+'_max' in config['validation']['GCP']: var_range[1] = float(config['validation']['GCP'][var+'_max'])
61 
62  TkMap_pixel.set_var(var, var_range=var_range)
63  TkMap_pixel.analyse()
64  TkMap_pixel.save(out_dir=plot_dir)
65  if plot_png: TkMap_pixel.save(out_dir=plot_dir, extension='png')
66  TkMap_pixel.plot_variable_distribution(out_dir=plot_dir)
67 
68  TkMap_strips.set_var(var)
69  TkMap_strips.analyse()
70  TkMap_strips.save(out_dir=plot_dir)
71  if plot_png: TkMap_strips.save(out_dir=plot_dir, extension='png')
72  TkMap_strips.plot_variable_distribution(out_dir=plot_dir)
73 
74 if __name__ == '__main__':
75 
76  args = parser()
77 
78  with open(args.config, "r") as configFile:
79  if args.config.split(".")[-1] == "json":
80  config = json.load(configFile)
81 
82  elif args.config.split(".")[-1] == "yaml":
83  config = yaml.load(configFile, Loader=yaml.Loader)
84 
85  else:
86  raise Exception("Unknown config extension '{}'. Please use json/yaml format!".format(args.config.split(".")[-1]))
87 
88  print(' ----- TkAlMaps -----')
89  TkAlMap_plots(config)
90 
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47
def parser()
Definition: GCPpyPlots.py:15
def TkAlMap_plots(config)
Definition: GCPpyPlots.py:25
#define str(s)