CMS 3D CMS Logo

plot_utils.py
Go to the documentation of this file.
1 from ROOT import TStyle, kWhite, kTRUE
2 from ROOT import kGray, kAzure, kMagenta, kOrange, kWhite
3 from ROOT import kRed, kBlue, kGreen, kPink, kYellow
4 from ROOT import TLine, TLatex
5 
6 from collections import namedtuple, OrderedDict
7 from math import sin, cos, tan, atan, exp, pi
8 
9 Plot_params = namedtuple('Params',
10  ['plotNumber',
11  'abscissa', 'ordinate',
12  'ymin', 'ymax',
13  'xmin', 'xmax',
14  'quotaName', 'iDrawEta',
15  'histoMin', 'histoMax',
16  'zLog', 'iRebin'])
17 plots = {}
18 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))
19 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))
20 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))
21 plots.setdefault('l_vs_eta', Plot_params(1010, '#eta', 'x/#lambda_{0}', 0.0, 0.73, -4.0, 4.0, '', 0, 0., 0., 0, 1))
22 plots.setdefault('l_vs_phi', Plot_params(1020, '#varphi [rad]', 'x/#lambda_{0}', 0.0, 1.2, -4.0, 4.0, '', 0, 0., 0., 0, 1))
23 plots.setdefault('l_vs_R', Plot_params(1040, '#R [cm]', 'x/#lambda_{0}', 0.0, 7.5, 0.0, 1200.0, '', 0, 0., 0., 0, 1))
24 plots.setdefault('x_vs_eta_vs_phi', Plot_params(30, '#eta', '#varphi', -3.2, 3.2, -5.0, 5.0, 'x/X_{0}', 0, -1., -1., 0, 1))
25 plots.setdefault('l_vs_eta_vs_phi', Plot_params(1030, '#eta', '#varphi', -3.2, 3.2, -5.0, 5.0, 'x/#lambda_{0}', 0, -1, -1, 0, 1))
26 plots.setdefault('x_vs_z_vs_Rsum', Plot_params(50, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '#Sigmax/X_{0}', 1, 0., 2.5, 0, 0))
27 plots.setdefault('x_vs_z_vs_R', Plot_params(60, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '1/X_{0}', 1, 0.00001, 0.01, 1, 0))
28 plots.setdefault('l_vs_z_vs_Rsum', Plot_params(1050, 'z [mm]', 'R [mm]', 0., 0., 0., 0., '#Sigmax/#lambda_{0}', 1, 0., 1., 0, 0))
29 plots.setdefault('l_vs_z_vs_R', Plot_params(1060, 'z [mm]', 'R [mm]', 0., 1400., -3500., 3500., '1/#lambda_{0}', 1, 0.001, 0.9, 1, 0))
30 plots.setdefault('l_vs_z_vs_R_geocomp', Plot_params(1060, 'z [mm]', 'R [mm]', 0., 1400., -3500., 3500., '1/#lambda_{0}', 1, 0.001, 0.9, 0, 0))
31 # x_over_l_vs_eta is not extracted from the ROOT file
32 # but generated from 10 and 1010 in MaterialBudget.py
33 plots.setdefault('x_over_l_vs_eta', Plot_params(10, '#eta', '(#frac{x}{X_{0}})/(#frac{x}{#lambda_{0}})', 0., 0., 0., 0., '', 0, -1, -1, 0, 0))
34 # same goes with x_over_l_vs_phi 20/1020
35 plots.setdefault('x_over_l_vs_phi', Plot_params(20, '#varphi [rad]', '(#frac{x}{X_{0}})/(#frac{x}{#lambda_{0}})', 0., 0., 0., 0., '', 0, -1, -1, 0, 0))
36 
37 # Conversion name from the label (key) to the components in CMSSW/Geometry
38 _LABELS2COMPS = {'BeamPipe': 'BEAM',
39  'Tracker': 'Tracker',
40  'Pixel': ['PixelBarrel', 'PixelForwardZplus', 'PixelForwardZminus'],
41  'PixBar': 'PixelBarrel',
42  'PixFwd': ['PixelForwardZplus', 'PixelForwardZminus', 'PixelForward'],
43  'PixFwdMinus': 'PixelForwardZminus',
44  'PixFwdPlus': 'PixelForwardZplus',
45  'TIB': 'TIB',
46  'TOB': 'TOB',
47  'TIDB': 'TIDB',
48  'TIDF': 'TIDF',
49  'TEC': 'TEC',
50  'InnerServices': ['TIBTIDServicesF', 'TIBTIDServicesB'],
51  'TkStrct': ['TrackerOuterCylinder', 'TrackerBulkhead'],
52  'Phase2PixelBarrel': 'Phase2PixelBarrel',
53  'Phase2OTBarrel': 'Phase2OTBarrel',
54  'Phase2PixelEndcap': 'Phase2PixelEndcap',
55  'Phase2OTForward': 'Phase2OTForward'}
56 
57 # Compounds are used to stick together different part of the Tracker
58 # detector, so that their cumulative material description can be
59 # derived. The key name can be generic, while the names in the
60 # associated list must be such that an appropriate material
61 # description file, in ROOT format, is present while producing the
62 # cumulative plot. A missing element will invalidate the full
63 # procedure.
64 COMPOUNDS = OrderedDict()
65 COMPOUNDS["Tracker"] = ["Tracker"]
66 COMPOUNDS["TrackerSum"] = ["TIB", "TIDF", "TIDB",
67  "BeamPipe", "InnerServices",
68  "TOB", "TEC",
69  "TkStruct",
70  "PixBar", "PixFwdPlus", "PixFwdMinus"]
71 COMPOUNDS["TrackerSumPhaseII"] = ["BeamPipe",
72  "Phase2PixelBarrel",
73  "Phase2OTBarrel", "Phase2OTForward",
74  "Phase2PixelEndcap"]
75 COMPOUNDS["Pixel"] = ["PixBar", "PixFwdMinus", "PixFwdPlus"]
76 COMPOUNDS["Strip"] = ["TIB", "TIDF", "TIDB", "InnerServices", "TOB", "TEC"]
77 COMPOUNDS["InnerTracker"] = ["TIB", "TIDF", "TIDB", "InnerServices"]
78 
79 # The DETECTORS must be the single component of the tracker for which
80 # the user can ask for the corresponding material description.
81 DETECTORS = OrderedDict()
82 DETECTORS["BeamPipe"] = kGray+2
83 DETECTORS["InnerServices"] = kGreen+2
84 DETECTORS["PixBar"] = kAzure-5
85 DETECTORS["Phase1PixelBarrel"] = kAzure-5
86 DETECTORS["Phase2PixelBarrel"] = kAzure-5
87 DETECTORS["PixFwdPlus"] = kAzure-9
88 DETECTORS["PixFwdMinus"] = kAzure-9
89 DETECTORS["Phase2PixelEndcap"] = kAzure-9
90 DETECTORS["Phase2OTBarrel"] = kMagenta-2
91 DETECTORS["Phase2OTForward"] = kOrange-2
92 DETECTORS["TIB"] = kMagenta-6
93 DETECTORS["TIDF"] = kMagenta+2
94 DETECTORS["TIDB"] = kMagenta+2
95 DETECTORS["TOB"] = kOrange+10
96 DETECTORS["TEC"] = kOrange-2
97 
98 # sDETS are the label of the Tracker elements in the Reconstruction
99 # geometry. They are all used to derive the reconstruction material
100 # profile to be compared to the one obtained directly from the
101 # simulation. A missing key in the real reconstruction geometry is not
102 # a problem, since this will imply that the corresponding plotting
103 # routine will skip that missing part. For this reason this map can be
104 # made as inclusive as possible with respect to the many
105 # reconstruction geometries in CMSSW.
106 sDETS = OrderedDict()
107 sDETS["PXB"] = kRed
108 sDETS["PXF"] = kBlue
109 sDETS["TIB"] = kGreen
110 sDETS["TID"] = kYellow
111 sDETS["TOB"] = kOrange
112 sDETS["TEC"] = kPink
113 
114 # hist_label_to_num contains the logical names of the Tracker detector
115 # that holds material. They are therefore not aware of which detector
116 # they belong to, but they are stored in specific plots in all the
117 # mat*root files produced. The numbering of the plots is identical
118 # across all files.
119 hist_label_to_num = OrderedDict()
120 hist_label_to_num['SUM'] = [0, kGreen+1, 'Total']
121 hist_label_to_num['SUP'] = [100, 13, 'Support'] # [Index , color, legend label]
122 hist_label_to_num['SEN'] = [200, 27, 'Sensitive']
123 hist_label_to_num['CAB'] = [300, 46, 'Cables']
124 hist_label_to_num['COL'] = [400, 38, 'Cooling']
125 hist_label_to_num['ELE'] = [500, 30, 'Electronics']
126 hist_label_to_num['OTH'] = [600, 42, 'Other']
127 hist_label_to_num['AIR'] = [700, 29, 'Air']
128 
130  """Function to setup a TDR-like style"""
131 
132  tdrStyle = TStyle("tdrStyle","Style for P-TDR")
133 
134  # For the canvas:
135  tdrStyle.SetCanvasBorderMode(0)
136  tdrStyle.SetCanvasColor(kWhite)
137  tdrStyle.SetCanvasDefH(600) #Height of canvas
138  tdrStyle.SetCanvasDefW(600) #Width of canvas
139  tdrStyle.SetCanvasDefX(0) #Position on screen
140  tdrStyle.SetCanvasDefY(0)
141 
142  # For the Pad:
143  tdrStyle.SetPadBorderMode(0)
144  tdrStyle.SetPadColor(kWhite)
145  tdrStyle.SetPadGridX(False)
146  tdrStyle.SetPadGridY(False)
147  tdrStyle.SetGridColor(kWhite)
148  tdrStyle.SetGridStyle(3)
149  tdrStyle.SetGridWidth(1)
150  tdrStyle.SetPadTickX(True)
151  tdrStyle.SetPadTickY(True)
152 
153  # For the frame:
154  tdrStyle.SetFrameBorderMode(0)
155  tdrStyle.SetFrameBorderSize(1)
156  tdrStyle.SetFrameFillColor(0)
157  tdrStyle.SetFrameFillStyle(0)
158  tdrStyle.SetFrameLineColor(1)
159  tdrStyle.SetFrameLineStyle(1)
160  tdrStyle.SetFrameLineWidth(0)
161 
162  # For the histo:
163  tdrStyle.SetHistLineColor(1)
164  tdrStyle.SetHistLineStyle(0)
165  tdrStyle.SetHistLineWidth(1)
166  tdrStyle.SetEndErrorSize(1)
167  #tdrStyle.SetErrorX(0.)
168  tdrStyle.SetMarkerStyle(20)
169 
170  #For the fit/function:
171  tdrStyle.SetOptFit(0)
172  tdrStyle.SetFitFormat("5.4g")
173  tdrStyle.SetFuncColor(2)
174  tdrStyle.SetFuncStyle(1)
175  tdrStyle.SetFuncWidth(1)
176 
177  #For the date:
178  tdrStyle.SetOptDate(0)
179 
180  # For the statistics box:
181  tdrStyle.SetOptFile(0)
182  tdrStyle.SetOptStat(0); # To display the mean and RMS: SetOptStat("mr")
183  tdrStyle.SetStatColor(kWhite)
184  tdrStyle.SetStatFont(42)
185  tdrStyle.SetStatFontSize(0.025)
186  tdrStyle.SetStatTextColor(1)
187  tdrStyle.SetStatFormat("6.4g")
188  tdrStyle.SetStatBorderSize(1)
189  tdrStyle.SetStatH(0.1)
190  tdrStyle.SetStatW(0.15)
191 
192  # Margins:
193  tdrStyle.SetPadTopMargin(0.05)
194  tdrStyle.SetPadBottomMargin(0.1)
195  tdrStyle.SetPadLeftMargin(0.12)
196  tdrStyle.SetPadRightMargin(0.05)
197 
198  # For the Global title:
199  tdrStyle.SetOptTitle(1)
200  tdrStyle.SetTitleFont(42)
201  tdrStyle.SetTitleColor(1)
202  tdrStyle.SetTitleTextColor(1)
203  tdrStyle.SetTitleFillColor(10)
204  tdrStyle.SetTitleFontSize(0.0525)
205  tdrStyle.SetTitleH(0); # Set the height of the title box
206  tdrStyle.SetTitleW(0); # Set the width of the title box
207  tdrStyle.SetTitleX(0.5); # Set the position of the title box
208  tdrStyle.SetTitleY(1.0); # Set the position of the title box
209  tdrStyle.SetTitleStyle(1001);
210  tdrStyle.SetTitleBorderSize(0);
211  tdrStyle.SetTitleAlign(23)
212 
213  # For the axis titles:
214  tdrStyle.SetTitleColor(1, "XYZ")
215  tdrStyle.SetTitleFont(42, "XYZ")
216  tdrStyle.SetTitleSize(0.05, "XY")
217  tdrStyle.SetTitleSize(0.035, "Z")
218  tdrStyle.SetTitleXOffset(1.0)
219  tdrStyle.SetTitleYOffset(1.0)
220 
221  # For the axis labels:
222  tdrStyle.SetLabelColor(1, "XYZ")
223  tdrStyle.SetLabelFont(42, "XYZ")
224  tdrStyle.SetLabelOffset(5e-3, "XYZ")
225  tdrStyle.SetLabelSize(0.03, "XYZ")
226 
227  # For the axis:
228  tdrStyle.SetAxisColor(1, "XYZ")
229  tdrStyle.SetStripDecimals(kTRUE)
230  tdrStyle.SetTickLength(0.03, "XYZ")
231  tdrStyle.SetNdivisions(510, "XYZ")
232  tdrStyle.SetPadTickX(1) # To get tick marks on the opposite side of the frame
233  tdrStyle.SetPadTickY(1)
234 
235  # Change for log plots:
236  tdrStyle.SetOptLogx(0)
237  tdrStyle.SetOptLogy(0)
238  tdrStyle.SetOptLogz(0)
239 
240  # Miscellaneous
241  tdrStyle.SetLegendBorderSize(0)
242 
243  # Postscript options:
244  tdrStyle.SetPaperSize(20.,20.)
245 
246  tdrStyle.cd()
247 
249  """Function to draw the eta.
250 
251  Function to draw the eta references on top of an already existing
252  TCanvas. The lines and labels drawn are collected inside a list and
253  the list is returned to the user to extend the live of the objects
254  contained, otherwise no lines and labels will be drawn, since they
255  will be garbage-collected as soon as this function returns.
256  """
257 
258  # Add eta labels
259  keep_alive = []
260  etas = [ 0.2*i for i in range(-17,18) ]
261 
262  etax = 2850.
263  etay = 1240.
264  lineL = 110.
265  offT = 10.
266 
267  for ieta in etas:
268  th = 2*atan(exp(-ieta))
269  talign = 21
270 
271  #IP
272  lineh = TLine(-20.,0.,20.,0.)
273  lineh.Draw()
274  linev = TLine(0.,-10.,0.,10.)
275  linev.Draw()
276  keep_alive.append(lineh)
277  keep_alive.append(linev)
278 
279  x1 = 0
280  y1 = 0
281  if ieta>-1.6 and ieta<1.6:
282  x1 = etay/tan(th)
283  y1 = etay
284  elif ieta <=-1.6:
285  x1 = -etax
286  y1 = -etax*tan(th)
287  talign = 11
288  elif ieta>=1.6:
289  x1 = etax
290  y1 = etax*tan(th)
291  talign = 31
292  x2 = x1+lineL*cos(th)
293  y2 = y1+lineL*sin(th)
294  xt = x2
295  yt = y2+offT
296 
297  line1 = TLine(x1,y1,x2,y2)
298  line1.Draw()
299  keep_alive.append(line1)
300 
301  text = "%3.1f" % ieta
302  t1 = TLatex(xt, yt, '%s' % ('#eta = 0' if ieta == 0 else text))
303  t1.SetTextSize(0.03)
304  t1.SetTextAlign(talign)
305  t1.Draw()
306  keep_alive.append(t1)
307  return keep_alive
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
funct::sin
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
funct::cos
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
plot_utils.drawEtaValues
def drawEtaValues()
Definition: plot_utils.py:248
funct::tan
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
plot_utils.Plot_params
Plot_params
Definition: plot_utils.py:9
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
plot_utils.setTDRStyle
def setTDRStyle()
Definition: plot_utils.py:129