CMS 3D CMS Logo

plot_hgcal_utils.py
Go to the documentation of this file.
1 from __future__ import print_function
2 from ROOT import TStyle, kWhite, kTRUE
3 from ROOT import gROOT, gStyle
4 from ROOT import kGray, kAzure, kMagenta, kOrange, kWhite
5 from ROOT import kRed, kBlue, kGreen, kPink, kYellow
6 from ROOT import TLine, TLatex, TColor
7 
8 from collections import namedtuple, OrderedDict
9 from math import sin, cos, tan, atan, exp, pi
10 from array import array
11 
12 from Validation.Geometry.plot_utils import Plot_params
13 
14 plots = {}
15 plots.setdefault('x_vs_eta', Plot_params(10, '#eta', 'x/X_{0}', 0.0, 2.575, -4.0, 4.0, '', 0, 0., 0., 0, 1))
16 plots.setdefault('x_vs_phi', Plot_params(20, '#varphi [rad]', 'x/X_{0}', 0.0, 6.2, -4.0, 4.0, '', 0, 0., 0., 0, 1))
17 plots.setdefault('x_vs_R', Plot_params(40, 'R [cm]', 'x/X_{0}', 0.0, 70.0, 0.0, 1200.0, '', 0, 0., 0., 0, 1))
18 plots.setdefault('l_vs_eta', Plot_params(10010, '#eta', 'x/#lambda_{I}', 0.0, 0.73, -4.0, 4.0, '', 0, 0., 0., 0, 1))
19 plots.setdefault('l_vs_phi', Plot_params(10020, '#varphi [rad]', 'x/#lambda_{I}', 0.0, 1.2, -4.0, 4.0, '', 0, 0., 0., 0, 1))
20 plots.setdefault('l_vs_R', Plot_params(10040, 'R [cm]', 'x/#lambda_{I}', 0.0, 7.5, 0.0, 1200.0, '', 0, 0., 0., 0, 1))
21 plots.setdefault('x_vs_eta_vs_phi', Plot_params(30, '#eta', '#varphi', 0., 0., 0., 0., 'x/X_{0}', 0, -1., -1., 0, 1))
22 plots.setdefault('l_vs_eta_vs_phi', Plot_params(10030, '#eta', '#varphi', 0., 0., 0., 0., 'x/#lambda_{I}', 0, -1, -1, 0, 1))
23 plots.setdefault('x_vs_z_vs_Rsum', Plot_params(50, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '#Sigmax/X_{0}', 1, -1., -1., 0, 0))
24 plots.setdefault('x_vs_z_vs_Rsumcos', Plot_params(52, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '#Sigmax/X_{0}', 1, -1., -1., 0, 0))
25 #plots.setdefault('x_vs_z_vs_R', Plot_params(60, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '1/X_{0}', 1, -1., -1., 0, 0))
26 plots.setdefault('x_vs_z_vs_Rloc', Plot_params(70, 'z [mm]', 'R [mm]', 0., 0., 0., 0., 'x/X_{0}', 1, -1., -1., 0, 0))
27 plots.setdefault('x_vs_z_vs_Rloccos', Plot_params(72, 'z [mm]', 'R [mm]', 0., 0., 0., 0., 'x/X_{0}', 1, -1., -1., 0, 0))
28 plots.setdefault('l_vs_z_vs_Rsum', Plot_params(10050, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '#Sigmax/#lambda_{I}', 1, -1., -1., 0, 0))
29 plots.setdefault('l_vs_z_vs_Rsumcos', Plot_params(10052, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '#Sigmax/#lambda_{I}', 1, -1., -1., 0, 0))
30 plots.setdefault('l_vs_z_vs_R', Plot_params(10060, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '1/#lambda_{I}', 1, -1., -1., 0, 0))
31 plots.setdefault('l_vs_z_vs_Rloc', Plot_params(10070, 'z [mm]', 'R [mm]', 0., 0., 0., 0., 'x/#lambda_{I}', 1, -1., -1., 0, 0))
32 plots.setdefault('l_vs_z_vs_Rloccos', Plot_params(10072, 'z [mm]', 'R [mm]', 0., 0., 0., 0., 'x/#lambda_{I}', 1, -1., -1., 0, 0))
33 plots.setdefault('x_over_l_vs_eta', Plot_params(10, '#eta', '(x/X_{0})/(x/#lambda_{I})', 0., 0., 0., 0., '', 0, -1, -1, 0, 0))
34 plots.setdefault('x_over_l_vs_phi', Plot_params(20, '#varphi [rad]', '(x/X_{0})/(x/#lambda_{I})', 0., 0., 0., 0., '', 0, -1, -1, 0, 0))
35 
36 # Conversion name from the label (key) to the components in CMSSW/Geometry
37 _LABELS2COMPS = {'HGCal': 'HGCal',
38  'HGCalEE': 'HGCalEE',
39  'HGCalHE': ['HGCalHEsil', 'HGCalHEmix']
40  }
41 
42 # Compounds are used to stick together different part of the HGCal
43 # detector, so that their cumulative material description can be
44 # derived. The key name can be generic, while the names in the
45 # associated list must be such that an appropriate material
46 # description file, in ROOT format, is present while producing the
47 # cumulative plot. A missing element will invalidate the full
48 # procedure.
49 COMPOUNDS = OrderedDict()
50 COMPOUNDS["HGCal"] = ["HGCal"]
51 COMPOUNDS["HGCalEE"] = ["HGCalEE"]
52 COMPOUNDS["HGCalHE"] = ["HGCalHEsil", "HGCalHEmix"]
53 
54 
55 # The DETECTORS must be the single component of the HGCal for which
56 # the user can ask for the corresponding material description.
57 DETECTORS = OrderedDict()
58 DETECTORS["HGCal"] = kAzure-5
59 DETECTORS["HGCalEE"] = kAzure-9
60 DETECTORS["HGCalHE"] = kOrange-2
61 
62 # sDETS are the label of the HGCal elements in the Reconstruction
63 # geometry. They are all used to derive the reconstruction material
64 # profile to be compared to the one obtained directly from the
65 # simulation. A missing key in the real reconstruction geometry is not
66 # a problem, since this will imply that the corresponding plotting
67 # routine will skip that missing part. For this reason this map can be
68 # made as inclusive as possible with respect to the many
69 # reconstruction geometries in CMSSW.
70 sDETS = OrderedDict()
71 sDETS["HGCalEE"] = kRed
72 sDETS["HGCalHEsil"] = kBlue
73 sDETS["HGCalHEmix"] = kGreen
74 #sDETS[""] = kYellow
75 #sDETS[""] = kOrange
76 #sDETS[""] = kPink
77 
78 # hist_label_to_num contains the logical names of the HGCal detector
79 # that holds material. They are therefore not aware of which detector
80 # they belong to, but they are stored in specific plots in all the
81 # mat*root files produced. The numbering of the plots is identical
82 # across all files.
83 hist_label_to_num = OrderedDict()
84 hist_label_to_num['COP'] = [100, 2, 'Copper'] # Index first, color second, legend label third
85 hist_label_to_num['SCI'] = [200, 3, 'Scintillator']
86 hist_label_to_num['CAB'] = [300, 4, 'Cables']
87 hist_label_to_num['MNE'] = [400, 5, 'HGC_G10-FR4']
88 hist_label_to_num['SIL'] = [500, 6, 'Silicon']
89 hist_label_to_num['OTH'] = [600, 7, 'Other']
90 hist_label_to_num['AIR'] = [700, 8, 'Air']
91 hist_label_to_num['SST'] = [800, 9, 'Stainless Steel']
92 hist_label_to_num['WCU'] = [900, 28, 'WCu']
93 hist_label_to_num['LEA'] = [1000, 12, 'Lead']
94 hist_label_to_num['EPX'] = [1100, 46, 'Epoxy']
95 hist_label_to_num['KAP'] = [1200, 49, 'Kapton']
96 hist_label_to_num['ALU'] = [1300, 33, 'Aluminium']
97 
98 def TwikiPrintout(plotname, label, zoom):
99  """The plots in the twiki are already too much and to avoid mistakes
100  we will try to automatize the procedure
101  """
102 
103  #Twiki will strip out spaces
104  label = label.replace(" ", "_")
105 
106  zoomstring = ""
107 
108  if zoom == "all":
109  zoomstring = ""
110  zoomtitle = "in all HGCal"
111  zoomdir = "%s/" % label
112  elif zoom == "zplus":
113  zoomstring = "_ZplusZoom"
114  zoomtitle = "in Z+ endcap of HGCal"
115  zoomdir = "%s/ZPlusZoom/" % label
116  elif zoom == "zminus":
117  zoomstring = "_ZminusZoom"
118  zoomtitle = "in Z- endcap of HGCal"
119  zoomdir = "%s/ZMinusZoom/" % label
120  else :
121  print("WRONG OPTION")
122 
123 
124  #Here for the hide button
125  if plotname == "x_vs_z_vs_Rsum":
126  print("%%TWISTY{ mode=\"div\" showlink=\"Click to see the %s plots %s \" hidelink=\"Hide %s %s\" showimgright=\"%%ICONURLPATH{toggleopen-small}%%\" hideimgright=\"%%ICONURLPATH{toggleclose-small}%%\"}%%" % (label,zoomtitle, label, zoomtitle))
127 
128  if "Rsum" in plotname and "x_vs" in plotname and not "cos" in plotname:
129  print("| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the mean value of the material budget in units of radiation length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the accumulated material budget as seen by the track, as the track travels throughout the detector.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring))
130 
131  if "Rsum" in plotname and "l_vs" in plotname and not "cos" in plotname:
132  print("| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the mean value of the material budget in units of interaction length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the accumulated material budget as seen by the track, as the track travels throughout the detector.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring))
133 
134  if "Rsumcos" in plotname and "x_vs" in plotname:
135  print("| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the mean value of the material budget in units of radiation length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the orthogonal accumulated material budget, that is cos(theta) what the track sees.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring))
136 
137  if "Rsumcos" in plotname and "l_vs" in plotname:
138  print("| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the mean value of the material budget in units of interaction length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the orthogonal accumulated material budget, that is cos(theta) what the track sees.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring))
139 
140  if "Rloc" in plotname and "x_vs" in plotname and not "cos" in plotname:
141  print("| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the local mean value of the material budget in units of radiation length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the local material budget as seen by the track, as the track travels throughout the detector.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring))
142 
143  if "Rloc" in plotname and "l_vs" in plotname and not "cos" in plotname:
144  print("| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the local mean value of the material budget in units of interaction length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the local material budget as seen by the track, as the track travels throughout the detector.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring))
145 
146  #Here again for the closing of the hide button
147  if plotname == "l_vs_z_vs_Rloc":
148  print("%ENDTWISTY%")
149 
150  """
151  I won't put the local cos plots for now, only the sum cos above
152  if "Rloccos" in plotname and "x_vs" in plotname:
153  print "| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the local mean value of the material budget in units of radiation length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the orthogonal accumulated material budget, that is cos(theta) what the track sees.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring)
154 
155  if "Rloccos" in plotname and "l_vs" in plotname:
156  print "| <img alt=\"HGCal_%s%s%s.png\" height=\"300\" width=\"550\" src=\"http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.png\" /> | The plot on the left shows the 2D profile histogram for *%s* %s that displays the local mean value of the material budget in units of interaction length in each R-z cell. R-z cell is 1 cm x 1 mm. The plot depicts the orthogonal accumulated material budget, that is cos(theta) what the track sees.[[http://apsallid.web.cern.ch/apsallid/HGCalMaterial/%sHGCal_%s%s%s.pdf][Click to enlarge plot]] |" % (plotname,label,zoomstring,zoomdir,plotname,label,zoomstring, label, zoomtitle,zoomdir,plotname,label,zoomstring)
157  """
158 
160  NRGBs = 7
161  NCont = 100
162  ncolors = array('i', [])
163  gStyle.SetNumberContours(NCont);
164  stops = [ 0.00, 0.10, 0.25, 0.45, 0.60, 0.75, 1.00 ]
165  red = [ 1.00, 0.00, 0.00, 0.00, 0.97, 0.97, 0.10 ]
166  green = [ 1.00, 0.97, 0.30, 0.40, 0.97, 0.00, 0.00 ]
167  blue = [ 1.00, 0.97, 0.97, 0.00, 0.00, 0.00, 0.00 ]
168  stopsArray = array('d', stops)
169  redArray = array('d', red)
170  greenArray = array('d', green)
171  blueArray = array('d', blue)
172  first_color_number = TColor.CreateGradientColorTable(NRGBs, stopsArray, redArray, greenArray, blueArray, NCont);
173  gStyle.SetNumberContours(NCont)
174 
175 
176  palsize = NCont
177  palette = []
178  for i in range(palsize):
179  palette.append(first_color_number+i)
180  palarray = array('i',palette)
181 
182  gStyle.SetPalette(palsize,palarray)
183 
184 
185 #In MeV/mm
186 dEdx = OrderedDict()
187 #--------
188 #Some elements necessary to build our materials
189 dEdx['Fe'] = 1.143
190 dEdx['Mn'] = 1.062
191 dEdx['Cr'] = 1.046
192 dEdx['Ni'] = 1.307
193 dEdx['C'] = 0.3952
194 dEdx['0'] = 0. # 2.398E-04 -> essentially zero
195 dEdx['H'] = 0. #3.437E-05 -> essentially zero
196 dEdx['Br'] = 0. #9.814E-04 -> essentially zero
197 dEdx['W'] = 2.210
198 dEdx['Al'] = 0.4358
199 #--------
200 
201 dEdx['Copper'] = 1.257
202 #http://cmslxr.fnal.gov/source/Geometry/CMSCommonData/data/materials.xml#1996
203 dEdx['H_Scintillator'] = 0.91512109*dEdx['C'] + 0.084878906*dEdx['H']
204 dEdx['Silicon'] = 0.3876
205 #http://cmslxr.fnal.gov/source/Geometry/CMSCommonData/data/materials.xml#2730
206 dEdx['HGC_G10-FR4'] = 0.18077359*dEdx['Silicon'] + 0.4056325*dEdx['0'] + 0.27804208*dEdx['C'] + 0.068442752*dEdx['H'] + 0.067109079*dEdx['Br']
207 dEdx['Other'] = 0.
208 #http://cmslxr.fnal.gov/source/Geometry/CMSCommonData/data/materials.xml#0290
209 dEdx['Air'] = 0.
210 #http://cmslxr.fnal.gov/source/Geometry/CMSCommonData/data/materials.xml#3692
211 dEdx['StainlessSteel'] = 0.6996*dEdx['Fe']+0.01*dEdx['Mn']+0.19*dEdx['Cr']+0.1*dEdx['Ni']+0.0004*dEdx['C'];
212 #http://cmslxr.fnal.gov/source/Geometry/CMSCommonData/data/materials.xml#0568
213 dEdx['WCu'] = 0.75*dEdx['W']+0.25*dEdx['Copper']
214 #--------
215 dEdx['Lead'] = 1.274 #Pb
216 dEdx['Epoxy'] = 0.53539691*dEdx['C'] + 0.13179314*dEdx['H'] + 0.33280996*dEdx['0']
217 dEdx['Kapton'] = 0.59985105*dEdx['C'] + 0.080541353*dEdx['H'] + 0.31960759*dEdx['0']
218 #Composition of cable as Sunanda uses them is here:
219 #http://cmslxr.fnal.gov/source/Geometry/CMSCommonData/data/materials.xml#2841
220 dEdx['Cables'] = 0.586*dEdx['Copper'] + 0.259*dEdx['C'] + 0.138*dEdx['0'] + 0.017*dEdx['H']
221 
222 #In mm
223 MatXo = OrderedDict()
224 MatXo['Copper'] = 14.3559
225 MatXo['H_Scintillator'] = 425.393
226 MatXo['Cables'] = 66.722
227 MatXo['HGC_G10-FR4'] = 175.056
228 MatXo['Silicon'] = 93.6762
229 MatXo['Other'] = 0.
230 MatXo['Air'] = 301522.
231 MatXo['StainlessSteel'] = 17.3555
232 MatXo['WCu'] = 5.1225
233 MatXo['Lead'] = 5.6118
234 MatXo['Epoxy'] = 315.901
235 MatXo['Kapton'] = 365.309
236 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
def TwikiPrintout(plotname, label, zoom)