CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
plotscripts.py
Go to the documentation of this file.
1 import ROOT, array, os, re, random
2 from math import *
3 import time
4 import pickle
5 
6 # python 2.6 has json modue; <2.6 could use simplejson
7 try:
8  import json
9 except ImportError:
10  import simplejson as json
11 
12 # my common muon types structures
13 from mutypes import *
14 
15 CPP_LOADED = False
16 
17 # containers for test results for map plots
18 MAP_RESULTS_SAWTOOTH = {}
19 MAP_RESULTS_FITSIN = {}
20 MAP_RESULTS_BINS = {}
21 
22 # general container for all test results
23 TEST_RESULTS = {}
24 
25 #############################################################
26 # Convenience functions
27 
28 def wheelm2only(dt, wheel, station, sector): return dt == "DT" and wheel == -2
29 def wheelm1only(dt, wheel, station, sector): return dt == "DT" and wheel == -1
30 def wheel0only(dt, wheel, station, sector): return dt == "DT" and wheel == 0
31 def wheelp1only(dt, wheel, station, sector): return dt == "DT" and wheel == 1
32 def wheelp2only(dt, wheel, station, sector): return dt == "DT" and wheel == 2
33 
34 def wheelLetter(wheel):
35  if wheel == -2: return "A"
36  elif wheel == -1: return "B"
37  elif wheel == 0: return "C"
38  elif wheel == +1: return "D"
39  elif wheel == +2: return "E"
40  else: raise Exception
41 
42 def wheelNumber(wheell):
43  if wheell == "A": return -2
44  elif wheell == "B": return -1
45  elif wheell == "C": return 0
46  elif wheell == "D": return 1
47  elif wheell == "E": return 2
48  else: raise Exception
49 
50 def mean(xlist):
51  s, n = 0., 0.
52  for x in xlist:
53  s += x
54  n += 1.
55  return s/n
56 
57 def rms(xlist):
58  s2, n = 0., 0.
59  for x in xlist:
60  s2 += x**2
61  n += 1.
62  return sqrt(s2/n)
63 
64 def stdev(xlist):
65  s, s2, n = 0., 0., 0.
66  for x in xlist:
67  s += x
68  s2 += x**2
69  n += 1.
70  return sqrt(s2/n - (s/n)**2)
71 
72 def wmean(xlist):
73  s, w = 0., 0.
74  for x, e in xlist:
75  if e > 0.:
76  wi = 1./e**2
77  s += x*wi
78  w += wi
79  return s/w, sqrt(1./w)
80 
81 #############################################################
82 
83 tdrStyle = None
85  global tdrStyle
86  tdrStyle = ROOT.TStyle("tdrStyle","Style for P-TDR")
87 # For the canvas:
88  tdrStyle.SetCanvasBorderMode(0)
89  tdrStyle.SetCanvasColor(ROOT.kWhite)
90  tdrStyle.SetCanvasDefH(600) #Height of canvas
91  tdrStyle.SetCanvasDefW(600) #Width of canvas
92  tdrStyle.SetCanvasDefX(0) #POsition on screen
93  tdrStyle.SetCanvasDefY(0)
94 
95 # For the Pad:
96  tdrStyle.SetPadBorderMode(0)
97  # tdrStyle.SetPadBorderSize(Width_t size = 1)
98  tdrStyle.SetPadColor(ROOT.kWhite)
99  tdrStyle.SetPadGridX(False)
100  tdrStyle.SetPadGridY(False)
101  tdrStyle.SetGridColor(0)
102  tdrStyle.SetGridStyle(3)
103  tdrStyle.SetGridWidth(1)
104 
105 # For the frame:
106  tdrStyle.SetFrameBorderMode(0)
107  tdrStyle.SetFrameBorderSize(1)
108  tdrStyle.SetFrameFillColor(0)
109  tdrStyle.SetFrameFillStyle(0)
110  tdrStyle.SetFrameLineColor(1)
111  tdrStyle.SetFrameLineStyle(1)
112  tdrStyle.SetFrameLineWidth(1)
113 
114 # For the histo:
115  # tdrStyle.SetHistFillColor(1)
116  # tdrStyle.SetHistFillStyle(0)
117  tdrStyle.SetHistLineColor(1)
118  tdrStyle.SetHistLineStyle(0)
119  tdrStyle.SetHistLineWidth(1)
120  # tdrStyle.SetLegoInnerR(Float_t rad = 0.5)
121  # tdrStyle.SetNumberContours(Int_t number = 20)
122 
123  tdrStyle.SetEndErrorSize(2)
124 # tdrStyle.SetErrorMarker(20)
125  tdrStyle.SetErrorX(0.)
126 
127  tdrStyle.SetMarkerStyle(20)
128 
129 #For the fit/function:
130  tdrStyle.SetOptFit(1)
131  tdrStyle.SetFitFormat("5.4g")
132  tdrStyle.SetFuncColor(2)
133  tdrStyle.SetFuncStyle(1)
134  tdrStyle.SetFuncWidth(1)
135 
136 #For the date:
137  tdrStyle.SetOptDate(0)
138  # tdrStyle.SetDateX(Float_t x = 0.01)
139  # tdrStyle.SetDateY(Float_t y = 0.01)
140 
141 # For the statistics box:
142  tdrStyle.SetOptFile(0)
143  tdrStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr")
144  tdrStyle.SetStatColor(ROOT.kWhite)
145  tdrStyle.SetStatFont(42)
146  tdrStyle.SetStatFontSize(0.025)
147  tdrStyle.SetStatTextColor(1)
148  tdrStyle.SetStatFormat("6.4g")
149  tdrStyle.SetStatBorderSize(1)
150  tdrStyle.SetStatH(0.1)
151  tdrStyle.SetStatW(0.15)
152  # tdrStyle.SetStatStyle(Style_t style = 1001)
153  # tdrStyle.SetStatX(Float_t x = 0)
154  # tdrStyle.SetStatY(Float_t y = 0)
155 
156 # Margins:
157  tdrStyle.SetPadTopMargin(0.05)
158  tdrStyle.SetPadBottomMargin(0.13)
159  tdrStyle.SetPadLeftMargin(0.13)
160  tdrStyle.SetPadRightMargin(0.05)
161 
162 # For the Global title:
163  tdrStyle.SetOptTitle(0)
164  tdrStyle.SetTitleFont(42)
165  tdrStyle.SetTitleColor(1)
166  tdrStyle.SetTitleTextColor(1)
167  tdrStyle.SetTitleFillColor(10)
168  tdrStyle.SetTitleFontSize(0.05)
169  # tdrStyle.SetTitleH(0) # Set the height of the title box
170  # tdrStyle.SetTitleW(0) # Set the width of the title box
171  # tdrStyle.SetTitleX(0) # Set the position of the title box
172  # tdrStyle.SetTitleY(0.985) # Set the position of the title box
173  # tdrStyle.SetTitleStyle(Style_t style = 1001)
174  # tdrStyle.SetTitleBorderSize(2)
175 
176 # For the axis titles:
177  tdrStyle.SetTitleColor(1, "XYZ")
178  tdrStyle.SetTitleFont(42, "XYZ")
179  tdrStyle.SetTitleSize(0.06, "XYZ")
180  # tdrStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
181  # tdrStyle.SetTitleYSize(Float_t size = 0.02)
182  tdrStyle.SetTitleXOffset(0.9)
183  tdrStyle.SetTitleYOffset(1.05)
184  # tdrStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset
185 
186 # For the axis labels:
187  tdrStyle.SetLabelColor(1, "XYZ")
188  tdrStyle.SetLabelFont(42, "XYZ")
189  tdrStyle.SetLabelOffset(0.007, "XYZ")
190  tdrStyle.SetLabelSize(0.05, "XYZ")
191 
192 # For the axis:
193  tdrStyle.SetAxisColor(1, "XYZ")
194  tdrStyle.SetStripDecimals(True)
195  tdrStyle.SetTickLength(0.03, "XYZ")
196  tdrStyle.SetNdivisions(510, "XYZ")
197  tdrStyle.SetPadTickX(1) # To get tick marks on the opposite side of the frame
198  tdrStyle.SetPadTickY(1)
199 
200 # Change for log plots:
201  tdrStyle.SetOptLogx(0)
202  tdrStyle.SetOptLogy(0)
203  tdrStyle.SetOptLogz(0)
204 
205 # Postscript options:
206  tdrStyle.SetPaperSize(20.,20.)
207  # tdrStyle.SetLineScalePS(Float_t scale = 3)
208  # tdrStyle.SetLineStyleString(Int_t i, const char* text)
209  # tdrStyle.SetHeaderPS(const char* header)
210  # tdrStyle.SetTitlePS(const char* pstitle)
211 
212  # tdrStyle.SetBarOffset(Float_t baroff = 0.5)
213  # tdrStyle.SetBarWidth(Float_t barwidth = 0.5)
214  # tdrStyle.SetPaintTextFormat(const char* format = "g")
215  # tdrStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0)
216  # tdrStyle.SetTimeOffset(Double_t toffset)
217  # tdrStyle.SetHistMinimumZero(True)
218 
219  tdrStyle.cd()
220 
221 setTDRStyle()
222 
223 def set_palette(name=None, ncontours=999):
224  """Set a color palette from a given RGB list
225  stops, red, green and blue should all be lists of the same length
226  see set_decent_colors for an example"""
227 
228  if name == "halfgray":
229  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
230  red = map(lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
231  green = map(lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
232  blue = map(lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
233  elif name == "gray":
234  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
235  red = [1.00, 0.84, 0.61, 0.34, 0.00]
236  green = [1.00, 0.84, 0.61, 0.34, 0.00]
237  blue = [1.00, 0.84, 0.61, 0.34, 0.00]
238  elif name == "blues":
239  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
240  red = [1.00, 0.84, 0.61, 0.34, 0.00]
241  green = [1.00, 0.84, 0.61, 0.34, 0.00]
242  blue = [1.00, 1.00, 1.00, 1.00, 1.00]
243  elif name == "reds":
244  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
245  red = [1.00, 1.00, 1.00, 1.00, 1.00]
246  green = [1.00, 0.84, 0.61, 0.34, 0.00]
247  blue = [1.00, 0.84, 0.61, 0.34, 0.00]
248  elif name == "antigray":
249  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
250  red = [1.00, 0.84, 0.61, 0.34, 0.00]
251  green = [1.00, 0.84, 0.61, 0.34, 0.00]
252  blue = [1.00, 0.84, 0.61, 0.34, 0.00]
253  red.reverse()
254  green.reverse()
255  blue.reverse()
256  elif name == "fire":
257  stops = [0.00, 0.20, 0.80, 1.00]
258  red = [1.00, 1.00, 1.00, 0.50]
259  green = [1.00, 1.00, 0.00, 0.00]
260  blue = [0.20, 0.00, 0.00, 0.00]
261  elif name == "antifire":
262  stops = [0.00, 0.20, 0.80, 1.00]
263  red = [0.50, 1.00, 1.00, 1.00]
264  green = [0.00, 0.00, 1.00, 1.00]
265  blue = [0.00, 0.00, 0.00, 0.20]
266  else:
267  # default palette, looks cool
268  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
269  red = [0.00, 0.00, 0.87, 1.00, 0.51]
270  green = [0.00, 0.81, 1.00, 0.20, 0.00]
271  blue = [0.51, 1.00, 0.12, 0.00, 0.00]
272 
273  s = array.array('d', stops)
274  r = array.array('d', red)
275  g = array.array('d', green)
276  b = array.array('d', blue)
277 
278  npoints = len(s)
279  ROOT.TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
280  ROOT.gStyle.SetNumberContours(ncontours)
281 
282 set_palette()
283 
284 ######################################################################################################
285 ## sector phi edges in: me11 me12 me13 me14 me21 me22 me31 me32 me41 me42 mb1 mb2 mb3 mb4
286 ## index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
287 phiedges = [
288  [0.087266462599716474, 0.26179938550504211, 0.43633230751381297, 0.61086524309298951, 0.78539818789089832, 0.95993106410343132,
289  1.13446400890134, 1.3089969444805165, 1.4835298664892873, 1.6580627893946129, 1.8325957122999386, 2.0071286343087094,
290  2.1816615698878858, 2.3561945146857948, 2.5307273908983277, 2.7052603356962366, 2.8797932712754131, 3.0543261932841839,
291  -3.0543261909900767, -2.8797932680847511, -2.7052603460759803, -2.5307274104968038, -2.3561944656988949, -2.181661589486362,
292  -2.0071286446884531, -1.8325957091092766, -1.6580627871005058, -1.4835298641951802, -1.3089969412898546, -1.1344640192810838,
293  -0.95993108370190716, -0.78539813890399834, -0.61086526269146535, -0.43633231789355653, -0.26179938231437999, -0.087266460305609153],
294  [0.087266462599716474, 0.26179938297741073, 0.43633231700542385, 0.61086526005981812, 0.78539815872971441, 0.95993109326461523,
295  1.1344639919345114, 1.3089969349889057, 1.4835298690169187, 1.6580627893946129, 1.8325957097723073, 2.0071286438003204,
296  2.1816615868547147, 2.3561944855246111, 2.5307274200595118, 2.7052603187294082, 2.879793261783802, 3.0543261958118153,
297  -3.0543261909900767, -2.8797932706123825, -2.7052603365843693, -2.5307273935299754, -2.356194494860079, -2.1816615603251783,
298  -2.0071286616552819, -1.8325957186008877, -1.6580627845728746, -1.4835298641951802, -1.308996943817486, -1.1344640097894729,
299  -0.95993106673507855, -0.78539816806518226, -0.61086523353028144, -0.43633233486038514, -0.26179939180599088, -0.087266457777977771],
300  [0.087266462599716474, 0.26179938235213535, 0.43633230952414037, 0.61086523916470359, 0.78539817763669606, 0.95993107435763347,
301  1.1344640128296259, 1.3089969424701891, 1.4835298696421941, 1.6580627893946129, 1.832595709147032, 2.0071286363190368,
302  2.1816615659596001, 2.3561945044315924, 2.53072740115253, 2.7052603396245227, 2.8797932692650856, 3.0543261964370907,
303  -3.0543261909900767, -2.8797932712376579, -2.7052603440656529, -2.53072741442509, -2.3561944759530973, -2.1816615792321596,
304  -2.0071286407601674, -1.8325957111196041, -1.6580627839475992, -1.4835298641951802, -1.3089969444427614, -1.1344640172707563,
305  -0.95993108763019308, -0.7853981491582005, -0.61086525243726308, -0.43633231396527061, -0.2617993843247074, -0.087266457152702412],
306  [0.087266462599716474, 0.26179938550504211, 0.43633230751381297, 0.61086524309298951, 0.78539818789089832, 0.95993106410343132,
307  1.13446400890134, 1.3089969444805165, 1.4835298664892873, 1.6580627893946129, 1.8325957122999386, 2.0071286343087094,
308  2.1816615698878858, 2.3561945146857948, 2.5307273908983277, 2.7052603356962366, 2.8797932712754131, 3.0543261932841839,
309  -3.0543261909900767, -2.8797932680847511, -2.7052603460759803, -2.5307274104968038, -2.3561944656988949, -2.181661589486362,
310  -2.0071286446884531, -1.8325957091092766, -1.6580627871005058, -1.4835298641951802, -1.3089969412898546, -1.1344640192810838,
311  -0.95993108370190716, -0.78539813890399834, -0.61086526269146535, -0.43633231789355653, -0.26179938231437999, -0.087266460305609153],
312  [0.26179938481428705, 0.6108652193791777, 0.95993108859688125, 1.3089969578145848, 1.6580627923794755, 2.0071286538798305,
313  2.356194498693418, 2.7052603320901376, 3.0543261769037247, -2.8797932687755066, -2.5307274342106156, -2.1816615649929121,
314  -1.8325956957752083, -1.4835298612103178, -1.1344639997099626, -0.78539815489637521, -0.43633232149965551, -0.087266476686068212],
315  [0.087266462599716474, 0.26179938871066555, 0.43633231557670243, 0.61086524129631259, 0.785398172964478, 0.95993107902985153,
316  1.1344640106980168, 1.308996936417627, 1.483529863283664, 1.6580627893946129, 1.8325957155055621, 2.0071286423715993,
317  2.1816615680912093, 2.3561944997593747, 2.5307274058247482, 2.7052603374929136, 2.8797932632125236, 3.0543261900785605,
318  -3.0543261909900767, -2.8797932648791278, -2.7052603380130908, -2.5307274122934809, -2.3561944806253154, -2.1816615745599419,
319  -2.0071286428917765, -1.8325957171721663, -1.6580627903061294, -1.4835298641951802, -1.3089969380842312, -1.1344640112181943,
320  -0.95993108549858397, -0.78539815383041856, -0.61086524776504503, -0.43633231609687961, -0.26179939037726946, -0.087266463511232586],
321  [0.26179938498198485, 0.61086523665761272, 0.95993108859688125, 1.3089969405361499, 1.6580627922117777, 2.0071286313120122,
322  2.3561944778405319, 2.7052603529430232, 3.0543261994715434, -2.8797932686078087, -2.530727416932181, -2.1816615649929121,
323  -1.8325957130536434, -1.4835298613780155, -1.1344640222777811, -0.78539817574926085, -0.43633230064676976, -0.087266454118249653],
324  [0.087266462599716474, 0.26179938871066555, 0.43633231557670243, 0.61086524129631259, 0.785398172964478, 0.95993107902985153,
325  1.1344640106980168, 1.308996936417627, 1.483529863283664, 1.6580627893946129, 1.8325957155055621, 2.0071286423715993,
326  2.1816615680912093, 2.3561944997593747, 2.5307274058247482, 2.7052603374929136, 2.8797932632125236, 3.0543261900785605,
327  -3.0543261909900767, -2.8797932648791278, -2.7052603380130908, -2.5307274122934809, -2.3561944806253154, -2.1816615745599419,
328  -2.0071286428917765, -1.8325957171721663, -1.6580627903061294, -1.4835298641951802, -1.3089969380842312, -1.1344640112181943,
329  -0.95993108549858397, -0.78539815383041856, -0.61086524776504503, -0.43633231609687961, -0.26179939037726946, -0.087266463511232586],
330  [0.26179938879942166, 0.61086525092924071, 0.95993108859688125, 1.3089969262645218, 1.6580627883943408, 2.0071286288299772,
331  2.3561945088997609, 2.7052603218837943, 3.0543262019535784, -2.8797932647903717, -2.5307274026605526, -2.1816615649929121,
332  -1.8325957273252713, -1.4835298651954525, -1.1344640247598159, -0.785398144690032, -0.43633233170599861, -0.087266451636214853],
333  [0.087266462599716474, 0.26179938871066555, 0.43633231557670243, 0.61086524129631259, 0.785398172964478, 0.95993107902985153,
334  1.1344640106980168, 1.308996936417627, 1.483529863283664, 1.6580627893946129, 1.8325957155055621, 2.0071286423715993,
335  2.1816615680912093, 2.3561944997593747, 2.5307274058247482, 2.7052603374929136, 2.8797932632125236, 3.0543261900785605,
336  -3.0543261909900767, -2.8797932648791278, -2.7052603380130908, -2.5307274122934809, -2.3561944806253154, -2.1816615745599419,
337  -2.0071286428917765, -1.8325957171721663, -1.6580627903061294, -1.4835298641951802, -1.3089969380842312, -1.1344640112181943,
338  -0.95993108549858397, -0.78539815383041856, -0.61086524776504503, -0.43633231609687961, -0.26179939037726946, -0.087266463511232586],
339  [0.35228048120123945, 0.87587781482541827, 1.3994776462193192, 1.923076807996136, 2.4466741416203148, 2.970273973014216,
340  -2.7893121723885534, -2.2657148387643748, -1.7421150073704739, -1.2185158455936571, -0.69491851196947851, -0.17131868057557731],
341  [0.22000706229660855, 0.74360690430428489, 1.267204926935573, 1.7908033890915052, 2.3144032310991816, 2.8380012537304697,
342  -2.9215855912931841, -2.3979857492855081, -1.8743877266542202, -1.3507892644982882, -0.82718942249061178, -0.30359139985932365],
343  [0.29751957124275596, 0.82111826253905784, 1.3447162969496083, 1.8683158980376524, 2.3919145893339548, 2.915512623744505,
344  -2.844073082347037, -2.3204743910507353, -1.7968763566401849, -1.2732767555521407, -0.74967806425583894, -0.22608002984528835],
345  [3.0136655290752188, -2.7530905195097337, -2.2922883025568734, -1.9222915077192773, -1.5707963267948966, -1.2193011458705159,
346  -0.84930435103291968, -0.38850213408005951, 0.127927124514574, 0.65152597487624719, 1.1322596819239259, 1.5707963267948966,
347  2.0093329716658674, 2.4900666787135459]]
348 
350  lines = []
351  for ed in phiedges[:]:
352  ed.sort()
353  #print ed
354  ed.extend([999 for n in range(0,37-len(ed))])
355  lines.append('{' + ', '.join(map(str, ed)) + '}')
356  #print lines
357  res = ', '.join(lines)
358  ff = open("phiedges_export.h",mode="w")
359  print>>ff,'double phiedges[14][37] = {' + res + '};'
360  ff.close()
361 
363  def __init__(self, name):
364  self.name = name
365  self.edges = (phiedges[stationIndex(name)])[:]
366  self.ed = sorted(self.edges)
367  # add some padding to the end
368  self.ed.append(pi+1.)
369  self.n = len(self.edges)
370  def __call__(self, xx, par):
371  # wrap x in the most negative phi sector into positive phi
372  x = xx[0]
373  if x < self.ed[0]: x += 2*pi
374  # locate sector
375  for i in range(0,self.n):
376  if x <= self.ed[i]: continue
377  if x > self.ed[i+1]: continue
378  return par[i*2] + par[i*2+1]*(x - self.ed[i])
379  return 0
380  def pp(self):
381  print self.name, self.n
382  print self.edges
383  print self.ed
384 
385 
386 def stationIndex(name):
387  if ("MB" in name or "ME" in name):
388  # assume the name is ID
389  pa = idToPostalAddress(name)
390  if pa is None: return None
391  if pa[0]=="CSC":
392  if pa[2]==1 and pa[3]==1: return 0
393  if pa[2]==1 and pa[3]==1: return 1
394  if pa[2]==1 and pa[3]==1: return 2
395  if pa[2]==1 and pa[3]==1: return 3
396  if pa[2]==1 and pa[3]==1: return 4
397  if pa[2]==1 and pa[3]==1: return 5
398  if pa[2]==1 and pa[3]==1: return 6
399  if pa[2]==1 and pa[3]==1: return 7
400  if pa[2]==1 and pa[3]==1: return 8
401  if pa[2]==1 and pa[3]==1: return 9
402  if pa[0]=="DT":
403  if pa[2]==1: return 10
404  if pa[2]==2: return 11
405  if pa[2]==3: return 12
406  if pa[2]==2: return 13
407  else:
408  if ("mem11" in name or "mep11" in name): return 0
409  if ("mem12" in name or "mep12" in name): return 1
410  if ("mem13" in name or "mep13" in name): return 2
411  if ("mem14" in name or "mep14" in name): return 3
412  if ("mem21" in name or "mep21" in name): return 4
413  if ("mem22" in name or "mep22" in name): return 5
414  if ("mem31" in name or "mep31" in name): return 6
415  if ("mem32" in name or "mep32" in name): return 7
416  if ("mem41" in name or "mep41" in name): return 8
417  if ("mem42" in name or "mep42" in name): return 9
418  if ("st1" in name): return 10
419  if ("st2" in name): return 11
420  if ("st3" in name): return 12
421  if ("st4" in name): return 13
422 
423 
424 
425 def philines(name, window, abscissa):
426  global philine_tlines, philine_labels
427  philine_tlines = []
428  edges = phiedges[stationIndex(name)]
429  #print name, len(edges)
430  for phi in edges:
431  if abscissa is None or abscissa[0] < phi < abscissa[1]:
432  philine_tlines.append(ROOT.TLine(phi, -window, phi, window))
433  philine_tlines[-1].SetLineStyle(2)
434  philine_tlines[-1].Draw()
435  if "st" in name: # DT labels
436  philine_labels = []
437  edges = edges[:]
438  edges.sort()
439  if "st4" in name:
440  labels = [" 7", " 8", " 9", "14", "10", "11", "12", " 1", " 2", " 3", "13", " 4", " 5", " 6"]
441  else:
442  labels = [" 8", " 9", "10", "11", "12", " 1", " 2", " 3", " 4", " 5", " 6"]
443  edges = edges[1:]
444  for phi, label in zip(edges, labels):
445  littlebit = 0.
446  if label in (" 7", " 9", "14", "10", "11"): littlebit = 0.05
447  philine_labels.append(ROOT.TText(phi-0.35+littlebit, -0.9*window, label))
448  philine_labels[-1].Draw()
449  philine_labels.append(ROOT.TText(-2.9, -0.75*window, "Sector:"))
450  philine_labels[-1].Draw()
451 
452 def zlines(window, abscissa):
453  global zline_tlines
454  zline_tlines = []
455  for z in -401.625, -133.875, 133.875, 401.625:
456  if abscissa is None or abscissa[0] < z < abscissa[1]:
457  zline_tlines.append(ROOT.TLine(z, -window, z, window))
458  zline_tlines[-1].SetLineStyle(2)
459  zline_tlines[-1].Draw()
460  zline_labels = []
461  zline_labels.append(ROOT.TText(-550, -0.9*window, "-2"))
462  zline_labels.append(ROOT.TText(-300, -0.9*window, "-1"))
463  zline_labels.append(ROOT.TText(-10, -0.9*window, "0"))
464  zline_labels.append(ROOT.TText(250, -0.9*window, "+1"))
465  zline_labels.append(ROOT.TText(500, -0.9*window, "+2"))
466  for z in zline_labels: z.Draw()
467  zline_labels.append(ROOT.TText(-600, -0.75*window, "Wheel:")); zline_labels[-1].Draw()
468 
469 def rlines(disk, window, abscissa):
470  global rline_tlines
471  rline_tlines = []
472  if disk == 1: rl = [150., 270., 480.]
473  else: rl = [350.]
474  for r in rl:
475  if abscissa is None or abscissa[0] < r < abscissa[1]:
476  rline_tlines.append(ROOT.TLine(r, -window, r, window))
477  rline_tlines[-1].SetLineStyle(2)
478  rline_tlines[-1].Draw()
479 
480 ######################################################################################################
481 
482 def DBMC(database, reports, window=10., selection=None, phi=False,
483  color=ROOT.kBlue-8, style=1, bins=50, normalized=False, getvalues=False, name=""):
484  return DBdiff(database, None, reports, None, window, selection, phi, color, style, bins, normalized, getvalues, name)
485 
486 def DBdiff(database1, database2, reports1, reports2, window=10., selection=None, phi=False, color=ROOT.kBlue-8,
487  style=1, bins=50, normalized=False, getvalues=False, name="tmp"):
488  tdrStyle.SetOptStat("emrou")
489  tdrStyle.SetStatW(0.40)
490 
491  if phi:
492  hx = ROOT.TH1F("%s_phi" % name, "", bins, -window, window)
493  else:
494  hx = ROOT.TH1F("%s_x" % name, "", bins, -window, window)
495  hy = ROOT.TH1F("%s_y" % name, "", bins, -window, window)
496  hz = ROOT.TH1F("%s_z" % name, "", bins, -window, window)
497  hphix = ROOT.TH1F("%s_phix" % name, "", bins, -window, window)
498  hphiy = ROOT.TH1F("%s_phiy" % name, "", bins, -window, window)
499  hphiz = ROOT.TH1F("%s_phiz" % name, "", bins, -window, window)
500 
501  for r1 in reports1:
502  if selection is None or (selection.func_code.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
503  if reports2 is None:
504  r2 = Report(r1.chamberId, r1.postal_address, r1.name)
505  r2.add_parameters(ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.),
506  ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.), 0., 0., 0., 0.)
507  else:
508  found = False
509  for r2 in reports2:
510  if r1.postal_address == r2.postal_address:
511  found = True
512  break
513  if not found: continue
514 
515  found = False
516  if r1.postal_address[0] == "DT":
517  if r1.postal_address[1:] in database1.dt:
518  found = True
519  db1 = database1.dt[r1.postal_address[1:]]
520  if database2 is None:
521  db2 = DTAlignable()
522  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
523  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
524  else:
525  db2 = database2.dt[r1.postal_address[1:]]
526  else:
527  if r1.postal_address[1:] in database1.csc:
528  found = True
529  db1 = database1.csc[r1.postal_address[1:]]
530  if database2 is None:
531  db2 = CSCAlignable()
532  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
533  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
534  else:
535  db2 = database2.csc[r1.postal_address[1:]]
536 
537  if found and r1.status == "PASS" and r2.status == "PASS":
538  if r1.deltax is not None and r2.deltax is not None and r1.deltax.error is not None and \
539  r2.deltax.error is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
540  if normalized:
541  fill = (db1.x - db2.x)/sqrt(r1.deltax.error**2 + r2.deltax.error**2) * signConventions[r1.postal_address][0]
542  else:
543  if phi:
544  fill = (db1.x - db2.x)/signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0]
545  else:
546  fill = (db1.x - db2.x) * 10. * signConventions[r1.postal_address][0]
547  hx.Fill(fill)
548  if getvalues not in (False, None):
549  getvalues["x"].append((fill, 10. * sqrt(r1.deltax.error**2 + r2.deltax.error**2)))
550 
551  if r1.deltay is not None and r2.deltay is not None and r1.deltay.error is not None and \
552  r2.deltay.error is not None and (r1.deltay.error**2 + r2.deltay.error**2) > 0.:
553  if normalized:
554  fill = (db1.y - db2.y)/sqrt(r1.deltay.error**2 + r2.deltay.error**2) * signConventions[r1.postal_address][1]
555  else:
556  fill = (db1.y - db2.y) * 10. * signConventions[r1.postal_address][1]
557  hy.Fill(fill)
558  if getvalues not in (False, None):
559  getvalues["y"].append((fill, 10. * sqrt(r1.deltay.error**2 + r2.deltay.error**2)))
560 
561  if r1.deltaz is not None and r2.deltaz is not None and r1.deltaz.error is not None and \
562  r2.deltaz.error is not None and (r1.deltaz.error**2 + r2.deltaz.error**2) > 0.:
563  if normalized:
564  fill = (db1.z - db2.z)/sqrt(r1.deltaz.error**2 + r2.deltaz.error**2) * signConventions[r1.postal_address][2]
565  else:
566  fill = (db1.z - db2.z) * 10. * signConventions[r1.postal_address][2]
567  hz.Fill(fill)
568  if getvalues not in (False, None):
569  getvalues["z"].append((fill, 10. * sqrt(r1.deltaz.error**2 + r2.deltaz.error**2)))
570 
571  if r1.deltaphix is not None and r2.deltaphix is not None and r1.deltaphix.error is not None and \
572  r2.deltaphix.error is not None and (r1.deltaphix.error**2 + r2.deltaphix.error**2) > 0.:
573  if normalized:
574  fill = (db1.phix - db2.phix)/sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)
575  else:
576  fill = (db1.phix - db2.phix) * 1000.
577  hphix.Fill(fill)
578  if getvalues not in (False, None):
579  getvalues["phix"].append((fill, 10. * sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)))
580 
581  if r1.deltaphiy is not None and r2.deltaphiy is not None and r1.deltaphiy.error is not None and \
582  r2.deltaphiy.error is not None and (r1.deltaphiy.error**2 + r2.deltaphiy.error**2) > 0.:
583  if normalized:
584  fill = (db1.phiy - db2.phiy)/sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)
585  else:
586  fill = (db1.phiy - db2.phiy) * 1000.
587  hphiy.Fill(fill)
588  if getvalues not in (False, None):
589  getvalues["phiy"].append((fill, 10. * sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)))
590 
591  if r1.deltaphiz is not None and r2.deltaphiz is not None and r1.deltaphiz.error is not None and \
592  r2.deltaphiz.error is not None and (r1.deltaphiz.error**2 + r2.deltaphiz.error**2) > 0.:
593  if normalized:
594  fill = (db1.phiz - db2.phiz)/sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)
595  else:
596  fill = (db1.phiz - db2.phiz) * 1000.
597  hphiz.Fill(fill)
598  if getvalues not in (False, None):
599  getvalues["phiz"].append((fill, 10. * sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)))
600 
601  if not normalized:
602  if phi:
603  hx.SetXTitle("#delta_{#phi} position (mrad)")
604  else:
605  hx.SetXTitle("#delta_{x'} (mm)")
606  hy.SetXTitle("#delta_{y'} (mm)")
607  hz.SetXTitle("#delta_{z'} (mm)")
608  hphix.SetXTitle("#delta_{#phi_{x}} (mrad)")
609  hphiy.SetXTitle("#delta_{#phi_{y}} (mrad)")
610  hphiz.SetXTitle("#delta_{#phi_{z}} (mrad)")
611  else:
612  if phi:
613  hx.SetXTitle("#delta_{#phi}/#sigma_{#phi} position")
614  else:
615  hx.SetXTitle("#delta_{x'}/#sigma_{x'}")
616  hy.SetXTitle("#delta_{y'}/#sigma_{y'}")
617  hz.SetXTitle("#delta_{z'}/#sigma_{z'}")
618  hphix.SetXTitle("#delta_{#phi_{x}}/#sigma_{#phi_{x}}")
619  hphiy.SetXTitle("#delta_{#phi_{y}}/#sigma_{#phi_{y}}")
620  hphiz.SetXTitle("#delta_{#phi_{z}}/#sigma_{#phi_{z}}")
621 
622  for h in hx, hy, hz, hphix, hphiy, hphiz:
623  h.GetXaxis().CenterTitle()
624  h.GetYaxis().CenterTitle()
625  h.SetFillColor(color)
626  h.SetLineStyle(style)
627 
628  if normalized:
629  fx = ROOT.TF1("fx", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hx.GetEntries()*2.*window/bins), -window, window)
630  fy = ROOT.TF1("fy", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hy.GetEntries()*2.*window/bins), -window, window)
631  fz = ROOT.TF1("fz", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hz.GetEntries()*2.*window/bins), -window, window)
632  fphix = ROOT.TF1("fphix", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphix.GetEntries()*2.*window/bins), -window, window)
633  fphiy = ROOT.TF1("fphiy", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphiy.GetEntries()*2.*window/bins), -window, window)
634  fphiz = ROOT.TF1("fphiz", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphiz.GetEntries()*2.*window/bins), -window, window)
635  for f in fx, fy, fz, fphix, fphiy, fphiz:
636  f.SetLineWidth(2)
637  f.SetLineColor(ROOT.kBlue)
638  for h, f in (hx, fx), (hy, fy), (hz, fz), (hphix, fphix), (hphiy, fphiy), (hphiz, fphiz):
639  h.SetAxisRange(0, 1.1*max(h.GetMaximum(), f.GetMaximum()), "Y")
640  c1.Clear()
641  c1.Divide(3, 2)
642  c1.GetPad(1).cd(); hx.Draw(); fx.Draw("same")
643  c1.GetPad(2).cd(); hy.Draw(); fy.Draw("same")
644  c1.GetPad(3).cd(); hz.Draw(); fz.Draw("same")
645  c1.GetPad(4).cd(); hphix.Draw(); fphix.Draw("same")
646  c1.GetPad(5).cd(); hphiy.Draw(); fphiy.Draw("same")
647  c1.GetPad(6).cd(); hphiz.Draw(); fphiz.Draw("same")
648  return hx, hy, hz, hphix, hphiy, hphiz, fx, fy, fz, fphix, fphiy, fphiz
649  else:
650  c1.Clear()
651  c1.Divide(3, 2)
652  c1.GetPad(1).cd(); hx.Draw()
653  c1.GetPad(2).cd(); hy.Draw()
654  c1.GetPad(3).cd(); hz.Draw()
655  c1.GetPad(4).cd(); hphix.Draw()
656  c1.GetPad(5).cd(); hphiy.Draw()
657  c1.GetPad(6).cd(); hphiz.Draw()
658  return hx, hy, hz, hphix, hphiy, hphiz
659 
660 def DBMCVersus(quantity, versus, database, reports, window=10., selection=None, color=ROOT.kBlack):
661  return DBdiffVersus(quantity, versus, database, None, reports, None, window, selection, color)
662 
663 def DBdiffVersus(quantity, versus, database1, database2, reports1, reports2, windwselection=None, color=ROOT.kBlack):
664  tdrStyle.SetOptStat("")
665 
666  domain = []
667  values = []
668  errors = []
669 
670  for r1 in reports1:
671  if selection is None or (selection.func_code.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
672  if reports2 is None:
673  r2 = Report(r1.chamberId, r1.postal_address, r1.name)
674  r2.add_parameters(ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.),
675  ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.), 0., 0., 0.)
676  else:
677  found = False
678  for r2 in reports2:
679  if r1.postal_address == r2.postal_address:
680  found = True
681  break
682  if not found: continue
683 
684  found = False
685  if r1.postal_address[0] == "DT":
686  if r1.postal_address[1:] in database1.dt:
687  found = True
688  db1 = database1.dt[r1.postal_address[1:]]
689  if database2 is None:
690  db2 = DTAlignable()
691  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
692  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
693  else:
694  db2 = database2.dt[r1.postal_address[1:]]
695  else:
696  if r1.postal_address[1:] in database1.csc:
697  found = True
698  db1 = database1.csc[r1.postal_address[1:]]
699  if database2 is None:
700  db2 = CSCAlignable()
701  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
702  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
703  else:
704  db2 = database2.csc[r1.postal_address[1:]]
705 
706  if found and r1.status == "PASS" and r2.status == "PASS":
707  okay = False
708 
709  if quantity == "phi":
710  if r1.deltax is not None and r2.deltax is not None and r1.deltax.error is not None and \
711  r2.deltax.error is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
712  okay = True
713  values.append((db1.x - db2.x)/
714  signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0])
715  errors.append((r1.deltax.error**2 + r2.deltax.error**2)/
716  signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0])
717 
718  elif quantity == "x":
719  if r1.deltax is not None and r2.deltax is not None and r1.deltax.error is not None and \
720  r2.deltax.error is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
721  okay = True
722  values.append((db1.x - db2.x) * 10. * signConventions[r1.postal_address][0])
723  errors.append((r1.deltax.error**2 + r2.deltax.error**2) * 10. * signConventions[r1.postal_address][0])
724 
725  elif quantity == "y":
726  if r1.deltay is not None and r2.deltay is not None and r1.deltay.error is not None and \
727  r2.deltay.error is not None and (r1.deltay.error**2 + r2.deltay.error**2) > 0.:
728  okay = True
729  values.append((db1.y - db2.y) * 10. * signConventions[r1.postal_address][1])
730  errors.append((r1.deltay.error**2 + r2.deltay.error**2) * 10. * signConventions[r1.postal_address][1])
731 
732  elif quantity == "z":
733  if r1.deltaz is not None and r2.deltaz is not None and r1.deltaz.error is not None and \
734  r2.deltaz.error is not None and (r1.deltaz.error**2 + r2.deltaz.error**2) > 0.:
735  okay = True
736  values.append((db1.z - db2.z) * 10. * signConventions[r1.postal_address][2])
737  errors.append((r1.deltaz.error**2 + r2.deltaz.error**2) * 10. * signConventions[r1.postal_address][2])
738 
739  elif quantity == "phix":
740  if r1.deltaphix is not None and r2.deltaphix is not None and r1.deltaphix.error is not None and \
741  r2.deltaphix.error is not None and (r1.deltaphix.error**2 + r2.deltaphix.error**2) > 0.:
742  okay = True
743  values.append((db1.phix - db2.phix) * 1000.)
744  errors.append((r1.deltaphix.error**2 + r2.deltaphix.error**2) * 1000.)
745 
746  elif quantity == "phiy":
747  if r1.deltaphiy is not None and r2.deltaphiy is not None and r1.deltaphiy.error is not None and \
748  r2.deltaphiy.error is not None and (r1.deltaphiy.error**2 + r2.deltaphiy.error**2) > 0.:
749  okay = True
750  values.append((db1.phiy - db2.phiy) * 1000.)
751  errors.append((r1.deltaphiy.error**2 + r2.deltaphiy.error**2) * 1000.)
752 
753  elif quantity == "phiz":
754  if r1.deltaphiz is not None and r2.deltaphiz is not None and r1.deltaphiz.error is not None and \
755  r2.deltaphiz.error is not None and (r1.deltaphiz.error**2 + r2.deltaphiz.error**2) > 0.:
756  okay = True
757  values.append((db1.phiz - db2.phiz) * 1000.)
758  errors.append((r1.deltaphiz.error**2 + r2.deltaphiz.error**2) * 1000.)
759 
760  else: raise Exception
761 
762  if okay:
763  if versus == "r": domain.append(signConventions[r1.postal_address][3])
764  elif versus == "phi": domain.append(signConventions[r1.postal_address][4])
765  elif versus == "z": domain.append(signConventions[r1.postal_address][5])
766  else: raise Exception
767 
768  if versus == "r":
769  bkgndhist = ROOT.TH1F("bkgndhist", "", 100, 0., 800.)
770  bkgndhist.SetXTitle("R (cm)")
771  elif versus == "phi":
772  bkgndhist = ROOT.TH1F("bkgndhist", "", 100, -pi, pi)
773  bkgndhist.SetXTitle("#phi (rad)")
774  elif versus == "z":
775  bkgndhist = ROOT.TH1F("bkgndhist", "", 100, -1100., 1100.)
776  bkgndhist.SetXTitle("z (cm)")
777  bkgndhist.GetXaxis().CenterTitle()
778 
779  bkgndhist.SetAxisRange(-window, window, "Y")
780  if quantity == "phi": bkgndhist.SetYTitle("#delta_{#phi} position (mrad)")
781  elif quantity == "x": bkgndhist.SetYTitle("#delta_{x'} (mm)")
782  elif quantity == "y": bkgndhist.SetYTitle("#delta_{y'} (mm)")
783  elif quantity == "z": bkgndhist.SetYTitle("#delta_{z'} (mm)")
784  elif quantity == "phix": bkgndhist.SetYTitle("#delta_{#phi_{x}} (mrad)")
785  elif quantity == "phiy": bkgndhist.SetYTitle("#delta_{#phi_{y}} (mrad)")
786  elif quantity == "phiz": bkgndhist.SetYTitle("#delta_{#phi_{z}} (mrad)")
787  else: raise Exception
788  bkgndhist.GetYaxis().CenterTitle()
789 
790  if len(domain) == 0:
791  tgraph = ROOT.TGraphErrors(0)
792  else:
793  tgraph = ROOT.TGraphErrors(len(domain), array.array("d", domain), array.array("d", values),
794  array.array("d", [0.]*len(domain)), array.array("d", errors))
795  tgraph.SetMarkerColor(color)
796  tgraph.SetLineColor(color)
797 
798  bkgndhist.Draw()
799  if tgraph.GetN() > 0: tgraph.Draw("p")
800  return bkgndhist, tgraph, domain, values, errors
801 
802 ######################################################################################################
803 
805  # only len==9 ids can correspond to valid postal address
806  if len(id)!=9: return None
807  if id[0:2]=="MB":
808  #print id
809  pa = ("DT", int(id[2:4]), int(id[5]), int(id[7:9]))
810  #print pa
811  if pa[1]<-2 or pa[1]>2: return None
812  if pa[2]>4: return None
813  if pa[3]<1 or pa[3]>14 or (pa[3]==4 and pa[3]>12): return None
814  return pa
815  elif id[0:2]=="ME":
816  if id[2]=="+": ec=1
817  elif id[2]=="-": ec=2
818  else: return None
819  pa = ("CSC", ec, int(id[3]), int(id[5]), int(id[7:9]))
820  if pa[2]<1 or pa[2]>4: return None
821  if pa[3]<1 or pa[3]>4 or (pa[2]>1 and pa[3]>2): return None
822  if pa[4]<1 or pa[4]>36 or (pa[2]>1 and pa[3]==1 and pa[4]>18): return None
823  return pa
824  else: return None
825 
826 
827 def postalAddressToId(postal_address):
828  if postal_address[0] == "DT":
829  wheel, station, sector = postal_address[1:]
830  w = "%+d"%wheel
831  if w=="+0": w = "-0"
832  return "MB%s/%d/%02d" % (w, station, sector)
833  elif postal_address[0] == "CSC":
834  endcap, station, ring, chamber = postal_address[1:]
835  if endcap != 1: station = -1 * abs(station)
836  return "ME%+d/%d/%02d" % (station, ring, chamber)
837 
838 
839 def nameToId(name):
840  if name[0:2] == "MB":
841  wh = name[4]
842  if wh == "A": w = "-2"
843  elif wh == "B": w = "-1"
844  elif wh == "C": w = "-0"
845  elif wh == "D": w = "+1"
846  elif wh == "E": w = "+2"
847  else: return ""
848  station = name[7]
849  sector = name[11:13]
850  return "MB%s/%s/%s" % (w, station, sector)
851  elif name[0:2] == "ME":
852  if name[2]=="p": endcap = "+"
853  elif name[2]=="m": endcap = "-"
854  else: return ""
855  station = name[3]
856  ring = name[4]
857  chamber = name[6:8]
858  return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
859  return None
860 
861 
862 def availableCellsDT(reports):
863  dts = []
864  # DT wheels
865  for iwheel in DT_TYPES:
866  if iwheel[1]=="ALL": continue
867  dts.append(iwheel[0])
868  # DT wheel & station
869  for wheel in DT_TYPES:
870  if wheel[1]=="ALL": continue
871  for station in wheel[2]:
872  dts.append(wheel[0]+'/'+station[1])
873  # DT station & sector
874  for wheel in DT_TYPES:
875  if wheel[1]!="ALL": continue
876  for station in wheel[2]:
877  for sector in range(1,station[2]+1):
878  ssector = "%02d" % sector
879  dts.append(wheel[0]+'/'+station[1]+'/'+ssector)
880  # DT chambers
881  for wheel in DT_TYPES:
882  if wheel[1]=="ALL": continue
883  for station in wheel[2]:
884  for sector in range(1,station[2]+1):
885  ssector = "%02d" % sector
886  label = "MBwh%sst%ssec%s" % (wheelLetter(int(wheel[1])),station[1],ssector)
887  if len(reports)==0:
888  # no reports case: do not include chambers
889  #dts.append(wheel[0]+'/'+station[1]+'/'+ssector)
890  continue
891  found = False
892  for r in reports:
893  if r.name == label:
894  found = True
895  break
896  if not found: continue
897  if r.status == "TOOFEWHITS" and r.posNum+r.negNum==0: continue
898  if r.status == "NOFIT": continue
899  dts.append(wheel[0]+'/'+station[1]+'/'+ssector)
900  return dts
901 
902 
903 def availableCellsCSC(reports):
904  cscs = []
905  # CSC station & ring
906  for endcap in CSC_TYPES:
907  for station in endcap[2]:
908  for ring in station[2]:
909  if ring[1]=="ALL": continue
910  #label = "CSCvsphi_me%s%s%s" % (endcap[1], station[1], ring[1])
911  cscs.append("%s%s/%s" % (endcap[0], station[1],ring[1]))
912  # CSC station and chamber
913  for endcap in CSC_TYPES:
914  for station in endcap[2]:
915  for ring in station[2]:
916  if ring[1]!="ALL": continue
917  for chamber in range(1,ring[2]+1):
918  #label = "CSCvsr_me%s%sch%02d" % (endcap[1], station[1], chamber)
919  cscs.append("%s%s/ALL/%02d" % (endcap[0], station[1],chamber))
920  # CSC chambers
921  for endcap in CSC_TYPES:
922  for station in endcap[2]:
923  for ring in station[2]:
924  if ring[1]=="ALL": continue
925  for chamber in range(1,ring[2]+1):
926  # exclude non instrumented ME4/2
927  if station[1]=="4" and ring[1]=="2":
928  if endcap[1]=="m": continue
929  if chamber<9 or chamber>13: continue
930  schamber = "%02d" % chamber
931  label = "ME%s%s%s_%s" % (endcap[1], station[1], ring[1], schamber)
932  if len(reports)==0:
933  # no reports case: do not include chambers
934  #cscs.append(endcap[0]+station[1]+'/'+ring[1]+'/'+schamber)
935  continue
936  found = False
937  for r in reports:
938  if r.name == label:
939  found = True
940  break
941  if not found: continue
942  if r.status == "TOOFEWHITS" and r.posNum+r.negNum==0: continue
943  if r.status == "NOFIT": continue
944  cscs.append(endcap[0]+station[1]+'/'+ring[1]+'/'+schamber)
945  return cscs
946 
947 
948 DQM_SEVERITY = [
949  {"idx":0, "name": "NONE", "color": "lightgreen", "hex":"#90EE90"},
950  {"idx":1, "name": "LOWSTAT05", "color": "lightgreen", "hex":"#96D953"},
951  {"idx":2, "name": "LOWSTAT075", "color": "lightgreen", "hex":"#94E26F"},
952  {"idx":3, "name": "LOWSTAT1", "color": "yellowgreen", "hex":"#9ACD32"},
953  {"idx":4, "name": "LOWSTAT", "color": "yellow", "hex":"#FFFF00"},
954  {"idx":5, "name": "TOLERABLE", "color": "lightpink", "hex":"#FFB6C1"},
955  {"idx":6, "name": "SEVERE", "color": "orange", "hex":"#FFA500"},
956  {"idx":7, "name": "CRITICAL", "color": "red", "hex":"#FF0000"}];
957 
958 
959 def addToTestResults(c,res):
960  if len(res)>0:
961  if TEST_RESULTS.has_key(c): TEST_RESULTS[c].extend(res)
962  else: TEST_RESULTS[c] = res
963 
964 
965 def testEntry(testID,scope,descr,severity):
966  s = 0
967  for sev in DQM_SEVERITY:
968  if sev["name"]==severity: s = sev["idx"]
969  return {"testID":testID,"scope":scope,"descr":descr,"severity":s}
970 
971 
973  if abs(x[1])==0.: return 0.
974  pull = abs(x[0])/abs(x[1])
975  if pull <= 5: return 0.
976  else: return pull
977 
978 
980  n = len(x)
981  res = []
982  dr = []
983  #print x
984  #print sx
985  for i in range(1,n+1):
986  x1 = x[i-1]
987  sx1 = sx[i-1]
988  x2 = x[0]
989  sx2 = sx[0]
990  if i<n:
991  x2 = x[i]
992  sx2 = sx[i]
993  sig1 = sqrt( (sx1[0]-sx1[1])**2 + x1[1]**2 )
994  sig2 = sqrt( (sx2[0]-sx2[1])**2 + x2[1]**2 )
995  df = abs(x1[0]-x2[0]) - 3*( sig1 + sig2 )
996  #df = abs(sx1[1]-sx2[0]) - 5*(abs(x1[1]) + abs(x2[1]))
997  #print i, df, '= abs(',sx1[1],'-',sx2[0],')-5*(abs(',x1[1],')+abs(',x2[1],'))'
998  dr.append(df)
999  if df > 0: res.append(i)
1000  #print dr
1001  #print res
1002  return res
1003 
1004 
1005 def doTestsForReport(cells,reports):
1006  for c in cells:
1007  # can a cell be converted to a chamber postal address?
1008  postal_address = idToPostalAddress(c)
1009  if not postal_address: continue
1010 
1011  # is this chamber in _report?
1012  found = False
1013  for r in reports:
1014  if r.postal_address == postal_address:
1015  found = True
1016  break
1017  if not found: continue
1018 
1019  # chamber's tests result
1020  res = []
1021  scope = postal_address[0]
1022 
1023  # noting could be done if fitting fails
1024  if r.status == "FAIL" or r.status == "MINUITFAIL":
1025  res.append(testEntry("FAILURE",scope,r.status+" failure","CRITICAL"))
1026  addToTestResults(c,res)
1027  continue
1028 
1029  # noting could be done if TOOFEWHITS
1030  nseg = r.posNum + r.negNum
1031  if r.status == "TOOFEWHITS" and nseg>0:
1032  res.append(testEntry("LOW_STAT",scope,"low stat, #segments=%d"%nseg,"LOWSTAT"))
1033  addToTestResults(c,res)
1034  continue
1035 
1036  # set shades of light green according to sidma(dx)
1037  sdx = 10.*r.deltax.error
1038  if sdx>0.5:
1039  if sdx<0.75: res.append(testEntry("LOW_STAT_DDX05",scope,"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),"LOWSTAT05"))
1040  elif sdx<1.: res.append(testEntry("LOW_STAT_DDX075",scope,"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),"LOWSTAT075"))
1041  else: res.append(testEntry("LOW_STAT_DDX1",scope,"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),"LOWSTAT1"))
1042 
1043  # check chi2
1044  if r.redchi2 > 2.5:
1045  res.append(testEntry("BIG_CHI2",scope,"chi2=%f>2.5" % r.redchi2,"TOLERABLE"))
1046 
1047  # check medians
1048  medx, meddx = 10.*r.median_x, 1000.*r.median_dxdz
1049  #medy, meddy = 10.*r.median_y, 1000.*r.median_dydz
1050  if medx>2: res.append(testEntry("BIG_MED_X",scope,"median dx=%f>2 mm"%medx,"SEVERE"))
1051  #if medy>3: res.append(testEntry("BIG_MED_Y",scope,"median dy=%f>3 mm"%medy,"SEVERE"))
1052  if meddx>2: res.append(testEntry("BIG_MED_DXDZ",scope,"median d(dx/dz)=%f>2 mrad"%meddx,"SEVERE"))
1053  #if meddy>3: res.append(testEntry("BIG_MED_DYDZ",scope,"median d(dy/dz)=%f>3 mrad"%meddy,"SEVERE"))
1054 
1055  # check residuals far from zero
1056  isDTst4 = False
1057  if postal_address[0] == "DT" and postal_address[2]==4: isDTst4 = True
1058  dx, dy, dpy, dpz = 10.*r.deltax.value, 0., 1000.*r.deltaphiy.value, 1000.*r.deltaphiz.value
1059  if not isDTst4: dy = 10.*r.deltay.value
1060  if dx>0.2: res.append(testEntry("BIG_LAST_ITR_DX",scope,"dx=%f>0.2 mm"%dx,"CRITICAL"))
1061  if dy>0.2: res.append(testEntry("BIG_LAST_ITR_DY",scope,"dy=%f>0.2 mm"%dy,"CRITICAL"))
1062  if dpy>0.2: res.append(testEntry("BIG_LAST_ITR_DPHIY",scope,"dphiy=%f>0.2 mrad"%dpy,"CRITICAL"))
1063  if dpz>0.2: res.append(testEntry("BIG_LAST_ITR_DPHIZ",scope,"dphiz=%f>0.2 mrad"%dpz,"CRITICAL"))
1064  #if ddx>0.03: res.append(testEntry("BIG_DX",scope,"dphix=%f>0.03 mrad"%ddx,"CRITICAL"))
1065 
1066  addToTestResults(c,res)
1067 
1068 
1070  for c in cells:
1071  res = []
1072 
1073  scope = "zzz"
1074  if c[0:2]=="MB": scope = "DT"
1075  if c[0:2]=="ME": scope = "CSC"
1076  if scope == "zzz":
1077  print "strange cell ID: ", c
1078  return None
1079 
1080  if MAP_RESULTS_FITSIN.has_key(c):
1081  t = MAP_RESULTS_FITSIN[c]
1082  t_a = testZeroWithin5Sigma(t['a'])
1083  t_s = testZeroWithin5Sigma(t['sin'])
1084  t_c = testZeroWithin5Sigma(t['cos'])
1085  if t_a+t_s+t_c >0:
1086  descr = "map fitsin 5 sigma away from 0; pulls : a=%.2f sin=%.2f, cos=%.2f" % (t_a,t_s,t_c)
1087  res.append(testEntry("MAP_FITSIN",scope,descr,"SEVERE"))
1088 
1089  if MAP_RESULTS_SAWTOOTH.has_key(c):
1090  t = MAP_RESULTS_SAWTOOTH[c]
1091 
1092  t_a = testDeltaWithin5Sigma(t['a'],t['da'])
1093  if len(t_a)>0:
1094  descr = "map discontinuities: %s" % ",".join(map(str,t_a))
1095  res.append(testEntry("MAP_DISCONTIN",scope,descr,"SEVERE"))
1096 
1097  t_b = map(testZeroWithin5Sigma, t['b'])
1098  t_bi = []
1099  for i in range(0,len(t_b)):
1100  if t_b[i]>0: t_bi.append(i+1)
1101  if len(t_bi)>0:
1102  descr = "map sawteeth: %s" % ",".join(map(str,t_bi))
1103  res.append(testEntry("MAP_SAWTEETH",scope,descr,"TOLERABLE"))
1104 
1105  addToTestResults(c,res)
1106 
1107 
1108 def saveTestResultsMap(run_name):
1109  if len(MAP_RESULTS_SAWTOOTH)+len(MAP_RESULTS_FITSIN)==0: return None
1110  ff = open("tmp_test_results_map__%s.pkl" % run_name, "wb")
1111  pickle.dump(MAP_RESULTS_SAWTOOTH, ff)
1112  pickle.dump(MAP_RESULTS_FITSIN, ff)
1113  ff.close()
1114 
1115 
1116 def loadTestResultsMap(run_name):
1117  print "tmp_test_results_map__%s.pkl" % run_name, os.access("tmp_test_results_map__%s.pkl" % run_name,os.F_OK)
1118  if not os.access("tmp_test_results_map__%s.pkl" % run_name,os.F_OK): return None
1119  global MAP_RESULTS_FITSIN, MAP_RESULTS_SAWTOOTH
1120  ff = open("tmp_test_results_map__%s.pkl" % run_name, "rb")
1121  MAP_RESULTS_SAWTOOTH = pickle.load(ff)
1122  MAP_RESULTS_FITSIN = pickle.load(ff)
1123  ff.close()
1124  #execfile("tmp_test_results_map__%s.py" % run_name)
1125  #print 'asasas', MAP_RESULTS_FITSIN
1126  return True
1127 
1128 def writeDQMReport(fname_dqm, run_name):
1129  tests = []
1130  for c in TEST_RESULTS:
1131  tests.append({"objID":c, "name":c, "list":TEST_RESULTS[c]})
1132  lt = time.localtime(time.time())
1133  lts = "%04d-%02d-%02d %02d:%02d:%02d %s" % (lt[0], lt[1], lt[2], lt[3], lt[4], lt[5], time.tzname[1])
1134  dqm_report = {"run":run_name, "genDate": lts, "report":tests}
1135  ff = open(fname_dqm,mode="w")
1136  print >>ff, "var DQM_REPORT = "
1137  json.dump(dqm_report,ff)
1138  #print >>ff, "];"
1139  ff.close()
1140 
1141 
1142 def doTests(reports,fname_base, fname_dqm, run_name):
1143  # find available baseline
1144  dts = availableCellsDT(reports)
1145  cscs = availableCellsCSC(reports)
1146  mulist = ['Run: '+run_name,['ALL',['MU']],['DT',dts],['CSC',cscs]]
1147  ff = open(fname_base,mode="w")
1148  print >>ff, "var MU_LIST = ["
1149  json.dump(mulist,ff)
1150  print >>ff, "];"
1151  ff.close()
1152 
1153  doTestsForReport(dts,reports)
1154  doTestsForReport(cscs,reports)
1155 
1156  loadTestResultsMap(run_name)
1157  doTestsForMapPlots(dts)
1158  doTestsForMapPlots(cscs)
1159 
1160  writeDQMReport(fname_dqm, run_name)
1161 
1162 
1163 ######################################################################################################
1164 
1165 def plotmedians(reports1, reports2, selection=None, binsx=50, windowx=3., ceilingx=None, binsy=50, windowy=3.,
1166  ceilingy=None, binsdxdz=50, windowdxdz=3., ceilingdxdz=None, binsdydz=50, windowdydz=3., ceilingdydz=None,
1167  r1text=" before", r2text=" after", which="median"):
1168  tdrStyle.SetOptStat("emrou")
1169  tdrStyle.SetStatW(0.40)
1170  tdrStyle.SetStatFontSize(0.05)
1171 
1172  global hmediandxdz_after, hmediandxdz_aftercopy, hmediandxdz_before, hmediandxdz_beforecopy, \
1173  hmediandydz_after, hmediandydz_aftercopy, hmediandydz_before, hmediandydz_beforecopy, \
1174  hmedianx_after, hmedianx_aftercopy, hmedianx_before, hmedianx_beforecopy, \
1175  hmediany_after, hmediany_aftercopy, hmediany_before, hmediany_beforecopy, tlegend
1176 
1177  hmedianx_before = ROOT.TH1F("hmedianx_before", "", binsx, -windowx, windowx)
1178  hmediany_before = ROOT.TH1F("hmediany_before", "", binsy, -windowy, windowy)
1179  hmediandxdz_before = ROOT.TH1F("hmediandxdz_before", "", binsdxdz, -windowdxdz, windowdxdz)
1180  hmediandydz_before = ROOT.TH1F("hmediandydz_before", "", binsdydz, -windowdydz, windowdydz)
1181  hmedianx_after = ROOT.TH1F("hmedianx_after", "", binsx, -windowx, windowx)
1182  hmediany_after = ROOT.TH1F("hmediany_after", "", binsy, -windowy, windowy)
1183  hmediandxdz_after = ROOT.TH1F("hmediandxdz_after", "", binsdxdz, -windowdxdz, windowdxdz)
1184  hmediandydz_after = ROOT.TH1F("hmediandydz_after", "", binsdydz, -windowdydz, windowdydz)
1185 
1186  if which == "median":
1187  whichx = whichy = whichdxdz = whichdydz = "median"
1188  elif which == "bigmean":
1189  whichx = "mean30"
1190  whichy = "mean30"
1191  whichdxdz = "mean20"
1192  whichdydz = "mean50"
1193  elif which == "mean":
1194  whichx = "mean15"
1195  whichy = "mean15"
1196  whichdxdz = "mean10"
1197  whichdydz = "mean25"
1198  elif which == "bigwmean":
1199  whichx = "wmean30"
1200  whichy = "wmean30"
1201  whichdxdz = "wmean20"
1202  whichdydz = "wmean50"
1203  elif which == "wmean":
1204  whichx = "wmean15"
1205  whichy = "wmean15"
1206  whichdxdz = "wmean10"
1207  whichdydz = "wmean25"
1208  elif which == "bigstdev":
1209  whichx = "stdev30"
1210  whichy = "stdev30"
1211  whichdxdz = "stdev20"
1212  whichdydz = "stdev50"
1213  elif which == "stdev":
1214  whichx = "stdev15"
1215  whichy = "stdev15"
1216  whichdxdz = "stdev10"
1217  whichdydz = "stdev25"
1218  else:
1219  raise Exception, which + " not recognized"
1220 
1221  for r1 in reports1:
1222  if selection is None or (selection.func_code.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
1223  found = False
1224  for r2 in reports2:
1225  if r1.postal_address == r2.postal_address:
1226  found = True
1227  break
1228  if not found: continue
1229 
1230  if r1.status == "PASS" and r2.status == "PASS":
1231  hmedianx_before.Fill(10.*eval("r1.%s_x" % whichx))
1232  hmediandxdz_before.Fill(1000.*eval("r1.%s_dxdz" % whichdxdz))
1233  hmedianx_after.Fill(10.*eval("r2.%s_x" % whichx))
1234  hmediandxdz_after.Fill(1000.*eval("r2.%s_dxdz" % whichdxdz))
1235 
1236  if r1.median_y is not None:
1237  hmediany_before.Fill(10.*eval("r1.%s_y" % whichy))
1238  hmediandydz_before.Fill(1000.*eval("r1.%s_dydz" % whichdydz))
1239  hmediany_after.Fill(10.*eval("r2.%s_y" % whichy))
1240  hmediandydz_after.Fill(1000.*eval("r2.%s_dydz" % whichdydz))
1241 
1242  hmedianx_beforecopy = hmedianx_before.Clone()
1243  hmediany_beforecopy = hmediany_before.Clone()
1244  hmediandxdz_beforecopy = hmediandxdz_before.Clone()
1245  hmediandydz_beforecopy = hmediandydz_before.Clone()
1246  hmedianx_beforecopy.SetLineStyle(2)
1247  hmediany_beforecopy.SetLineStyle(2)
1248  hmediandxdz_beforecopy.SetLineStyle(2)
1249  hmediandydz_beforecopy.SetLineStyle(2)
1250 
1251  hmedianx_before.SetFillColor(ROOT.kMagenta+2)
1252  hmediany_before.SetFillColor(ROOT.kMagenta+2)
1253  hmediandxdz_before.SetFillColor(ROOT.kMagenta+2)
1254  hmediandydz_before.SetFillColor(ROOT.kMagenta+2)
1255  hmedianx_after.SetFillColor(ROOT.kYellow)
1256  hmediany_after.SetFillColor(ROOT.kYellow)
1257  hmediandxdz_after.SetFillColor(ROOT.kYellow)
1258  hmediandydz_after.SetFillColor(ROOT.kYellow)
1259 
1260  hmedianx_aftercopy = hmedianx_after.Clone()
1261  hmediany_aftercopy = hmediany_after.Clone()
1262  hmediandxdz_aftercopy = hmediandxdz_after.Clone()
1263  hmediandydz_aftercopy = hmediandydz_after.Clone()
1264  hmedianx_aftercopy.GetXaxis().SetLabelColor(ROOT.kWhite)
1265  hmediany_aftercopy.GetXaxis().SetLabelColor(ROOT.kWhite)
1266  hmediandxdz_aftercopy.GetXaxis().SetLabelColor(ROOT.kWhite)
1267  hmediandydz_aftercopy.GetXaxis().SetLabelColor(ROOT.kWhite)
1268  hmedianx_aftercopy.GetYaxis().SetLabelColor(ROOT.kWhite)
1269  hmediany_aftercopy.GetYaxis().SetLabelColor(ROOT.kWhite)
1270  hmediandxdz_aftercopy.GetYaxis().SetLabelColor(ROOT.kWhite)
1271  hmediandydz_aftercopy.GetYaxis().SetLabelColor(ROOT.kWhite)
1272 
1273  hmedianx_after.SetXTitle("median(#Deltax) (mm)")
1274  hmediany_after.SetXTitle("median(#Deltay) (mm)")
1275  hmediandxdz_after.SetXTitle("median(#Deltadx/dz) (mrad)")
1276  hmediandydz_after.SetXTitle("median(#Deltadydz) (mrad)")
1277  hmedianx_after.GetXaxis().CenterTitle()
1278  hmediany_after.GetXaxis().CenterTitle()
1279  hmediandxdz_after.GetXaxis().CenterTitle()
1280  hmediandydz_after.GetXaxis().CenterTitle()
1281 
1282  if ceilingx is not None: hmedianx_aftercopy.SetAxisRange(0., ceilingx, "Y")
1283  if ceilingy is not None: hmediany_aftercopy.SetAxisRange(0., ceilingy, "Y")
1284  if ceilingdxdz is not None: hmediandxdz_aftercopy.SetAxisRange(0., ceilingdxdz, "Y")
1285  if ceilingdydz is not None: hmediandydz_aftercopy.SetAxisRange(0., ceilingdydz, "Y")
1286 
1287  c1.Clear()
1288  c1.Divide(2, 2)
1289 
1290  c1.GetPad(1).cd()
1291  hmedianx_aftercopy.Draw()
1292  hmedianx_before.Draw("same")
1293  hmedianx_after.Draw("same")
1294  hmedianx_beforecopy.Draw("same")
1295  hmedianx_after.Draw("axissame")
1296 
1297  tlegend = ROOT.TLegend(0.17, 0.75-0.05, 0.45+0.05, 0.9)
1298  tlegend.SetFillColor(ROOT.kWhite)
1299  tlegend.SetBorderSize(0)
1300  tlegend.AddEntry(hmedianx_after, r2text, "f")
1301  tlegend.AddEntry(hmedianx_before, r1text, "f")
1302  tlegend.Draw()
1303 
1304  c1.GetPad(2).cd()
1305  hmediandxdz_aftercopy.Draw()
1306  hmediandxdz_before.Draw("same")
1307  hmediandxdz_after.Draw("same")
1308  hmediandxdz_beforecopy.Draw("same")
1309  hmediandxdz_after.Draw("axissame")
1310 
1311  c1.GetPad(3).cd()
1312  hmediany_aftercopy.Draw()
1313  hmediany_before.Draw("same")
1314  hmediany_after.Draw("same")
1315  hmediany_beforecopy.Draw("same")
1316  hmediany_after.Draw("axissame")
1317 
1318  c1.GetPad(4).cd()
1319  hmediandydz_aftercopy.Draw()
1320  hmediandydz_before.Draw("same")
1321  hmediandydz_after.Draw("same")
1322  hmediandydz_beforecopy.Draw("same")
1323  hmediandydz_after.Draw("axissame")
1324 
1325  return hmediandxdz_after, hmediandxdz_aftercopy, hmediandxdz_before, hmediandxdz_beforecopy, \
1326  hmediandydz_after, hmediandydz_aftercopy, hmediandydz_before, hmediandydz_beforecopy, \
1327  hmedianx_after, hmedianx_aftercopy, hmedianx_before, hmedianx_beforecopy, \
1328  hmediany_after, hmediany_aftercopy, hmediany_before, hmediany_beforecopy, tlegend
1329 
1330 ######################################################################################################
1331 
1332 def mapplot(tfiles, name, param, mode="from2d", window=40., abscissa=None, title="",
1333  widebins=False, fitsine=False, fitline=False, reset_palette=False, fitsawteeth=False):
1334  tdrStyle.SetOptTitle(1)
1335  tdrStyle.SetTitleBorderSize(0)
1336  tdrStyle.SetOptStat(0)
1337  #tdrStyle.SetOptStat("emrou")
1338  tdrStyle.SetOptFit(0)
1339  tdrStyle.SetTitleFontSize(0.05)
1340  tdrStyle.SetPadRightMargin(0.1) # to see the pallete labels on the left
1341 
1342  c1.Clear()
1343  c1.ResetAttPad()
1344 
1345  if reset_palette: set_palette("blues")
1346  global hist, hist2d, hist2dweight, tline1, tline2, tline3
1347 
1348  if fitsine or fitsawteeth:
1349  id = mapNameToId(name)
1350  if not id:
1351  print "bad id for ", name
1352  raise Exception
1353 
1354  hdir = "AlignmentMonitorMuonSystemMap1D/iter1/"
1355  hpref= "%s_%s" % (name, param)
1356  hhh = hdir+hpref
1357 
1358  prof = tfiles[0].Get(hhh+"_prof").Clone(hpref+"_prof_")
1359  profPos = tfiles[0].Get(hhh+"_profPos").Clone(hpref+"_profPos_")
1360  profNeg = tfiles[0].Get(hhh+"_profNeg").Clone(hpref+"_profNeg_")
1361  weights = tfiles[0].Get(hhh+"_weights").Clone(hpref+"_weights_")
1362  valweights = tfiles[0].Get(hhh+"_valweights").Clone(hpref+"_valweights_")
1363  hist2d = tfiles[0].Get(hhh+"_2d").Clone(hpref+"_2d_")
1364  hist2dweight = tfiles[0].Get(hhh+"_2dweight").Clone(hpref+"_2dweight_")
1365 
1366  for tfile in tfiles[1:]:
1367  prof.Add(tfile.Get(hhh+"_prof"))
1368  profPos.Add(tfile.Get(hhh+"_profPos"))
1369  profNeg.Add(tfile.Get(hhh+"_profNeg"))
1370  weights.Add(tfile.Get(hhh+"_weights"))
1371  valweights.Add(tfile.Get(hhh+"_valweights"))
1372  hist2d.Add(tfile.Get(hhh+"_2d"))
1373  hist2dweight.Add(tfile.Get(hhh+"_2dweight"))
1374 
1375  if mode == "plain":
1376  hist = prof
1377 
1378  elif mode in ("from2d", "from2dweight"):
1379  if mode == "from2d": the2d = hist2d
1380  else: the2d = hist2dweight
1381 
1382  hist = weights.Clone()
1383  hist.Reset()
1384  skip = 1
1385  if widebins:
1386  hist.Rebin(10)
1387  skip = 10
1388 
1389  #f = ROOT.TF1("g", "gaus", -40., 40)
1390  for i in xrange(0, int(weights.GetNbinsX()), skip):
1391  tmp = the2d.ProjectionY("tmp", i+1, i + skip)
1392  if tmp.GetEntries() > 1:
1393  #tmp.Fit("g","LNq")
1394  hist.SetBinContent(i/skip+1, tmp.GetMean())
1395  hist.SetBinError(i/skip+1, ROOT.TMath.StudentQuantile(0.841345,tmp.GetEntries()) * tmp.GetRMS() / sqrt(tmp.GetEntries()))
1396  #hist.SetBinError(i/skip+1, tmp.GetRMS() / sqrt(tmp.GetEntries()))
1397  #hist.SetBinError(i/skip+1, f.GetParameter(2))
1398  else:
1399  #hist.SetBinContent(i/skip+1, 2000.)
1400  #hist.SetBinError(i/skip+1, 1000.)
1401  hist.SetBinContent(i/skip+1, 0.)
1402  hist.SetBinError(i/skip+1, 0.)
1403 
1404  elif mode == "weighted":
1405  if weights.GetEntries() == 0:
1406  averageweight = 0.
1407  else:
1408  sumofweights = 0.
1409  for i in xrange(0, int(weights.GetNbinsX())+2):
1410  sumofweights += weights.GetBinContent(i)
1411  averageweight = sumofweights / weights.GetEntries()
1412  hist = weights.Clone()
1413  for i in xrange(1, int(weights.GetNbinsX())+1):
1414  if weights.GetBinContent(i) > 0:
1415  thisweight = weights.GetBinContent(i) / averageweight
1416  hist.SetBinContent(i, valweights.GetBinContent(i) / thisweight)
1417  hist.SetBinError(i, sqrt(1. / thisweight))
1418  else:
1419  hist.SetBinContent(i, 2000.)
1420  hist.SetBinError(i, 1000.)
1421 
1422  else:
1423  raise Exception
1424 
1425  hist.SetAxisRange(-window, window, "Y")
1426  if abscissa is not None: hist.SetAxisRange(abscissa[0], abscissa[1], "X")
1427  hist.SetMarkerStyle(20)
1428  hist.SetMarkerSize(0.75)
1429  hist.GetXaxis().CenterTitle()
1430  hist.GetYaxis().CenterTitle()
1431  hist.GetYaxis().SetTitleOffset(0.75)
1432  hist.GetXaxis().SetTitleSize(0.05)
1433  hist.GetYaxis().SetTitleSize(0.05)
1434  hist.SetTitle(title)
1435  if "vsphi" in name: hist.SetXTitle("Global #phi position (rad)")
1436  elif "vsz" in name: hist.SetXTitle("Global z position (cm)")
1437  elif "vsr" in name: hist.SetXTitle("Global R position (cm)")
1438  if "DT" in name:
1439  if param == "x": hist.SetYTitle("x' residual (mm)")
1440  if param == "dxdz": hist.SetYTitle("dx'/dz residual (mrad)")
1441  if param == "y": hist.SetYTitle("y' residual (mm)")
1442  if param == "dydz": hist.SetYTitle("dy'/dz residual (mm)")
1443  if "CSC" in name:
1444  if param == "x": hist.SetYTitle("r#phi residual (mm)")
1445  if param == "dxdz": hist.SetYTitle("d(r#phi)/dz residual (mrad)")
1446  hist.SetMarkerColor(ROOT.kBlack)
1447  hist.SetLineColor(ROOT.kBlack)
1448  hist.Draw()
1449  hist2d.Draw("colzsame")
1450  if widebins: hist.Draw("samee1")
1451  else: hist.Draw("same")
1452 
1453  if fitsine and "vsphi" in name:
1454  global fitsine_const, fitsine_sin, fitsine_cos, fitsine_chi2, fitsine_ndf
1455  f = ROOT.TF1("f", "[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
1456  #hist.Fit(f,"N")
1457  hist.Fit(f,"NE")
1458  f.SetLineColor(ROOT.kRed)
1459  fitsine_const = f.GetParameter(0), f.GetParError(0)
1460  fitsine_sin = f.GetParameter(1), f.GetParError(1)
1461  fitsine_cos = f.GetParameter(2), f.GetParError(2)
1462  fitsine_chi2 = f.GetChisquare()
1463  fitsine_ndf = f.GetNDF()
1464  global MAP_RESULTS_FITSIN
1465  MAP_RESULTS_FITSIN[id] = {'a':fitsine_const, 'sin': fitsine_sin, 'cos': fitsine_cos, 'chi2': fitsine_chi2, 'ndf': fitsine_ndf}
1466  f.Draw("same")
1467  global fitsine_ttext
1468  fitsine_ttext = ROOT.TLatex(-1., 0.8*window,
1469  "%.3g %+.3g sin(#phi) %+.3g cos(#phi)" % (fitsine_const[0], fitsine_sin[0], fitsine_cos[0]))
1470  fitsine_ttext.SetTextColor(ROOT.kRed)
1471  fitsine_ttext.Draw()
1472 
1473  if fitline:
1474  f = ROOT.TF1("f", "[0] + [1]*x", -1000., 1000.)
1475  hist2d.Fit(f, "q")
1476  hist2d.GetFunction("f").SetLineColor(ROOT.kRed)
1477  global fitline_const, fitline_linear, fitline_chi2, fitline_ndf
1478  fitline_const = hist2d.GetFunction("f").GetParameter(0), hist2d.GetFunction("f").GetParError(0)
1479  fitline_linear = hist2d.GetFunction("f").GetParameter(1), hist2d.GetFunction("f").GetParError(1)
1480  fitline_chi2 = hist2d.GetFunction("f").GetChisquare()
1481  fitline_ndf = hist2d.GetFunction("f").GetNDF()
1482  hist2d.GetFunction("f").Draw("same")
1483  global fitline_ttext
1484  if "vsz" in name: which = "Z"
1485  elif "vsr" in name: which = "R"
1486  fitline_ttext = ROOT.TText(hist.GetBinCenter(hist.GetNbinsX()/4),
1487  0.8*window, "%.3g %+.3g %s" % (fitline_const[0], fitline_linear[0], which))
1488  fitline_ttext.SetTextColor(ROOT.kRed)
1489  fitline_ttext.Draw()
1490 
1491  ROOT.gPad.RedrawAxis()
1492 
1493  if "vsphi" in name:
1494  if not widebins: philines(name, window, abscissa)
1495  if abscissa is None:
1496  tline1 = ROOT.TLine(-pi, 0, pi, 0); tline1.Draw()
1497  tline2 = ROOT.TLine(-pi, -window, pi, -window); tline2.SetLineWidth(2); tline2.Draw()
1498  tline3 = ROOT.TLine(-pi, window, pi, window); tline3.Draw()
1499  else:
1500  tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1501  tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1502  tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1503  elif "vsz" in name:
1504  if not widebins: zlines(window, abscissa)
1505  if abscissa is None:
1506  tline1 = ROOT.TLine(-660, 0, 660, 0); tline1.Draw()
1507  tline2 = ROOT.TLine(-660, -window, 660, -window); tline2.SetLineWidth(2); tline2.Draw()
1508  tline3 = ROOT.TLine(-660, window, 660, window); tline3.Draw()
1509  else:
1510  tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1511  tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1512  tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1513  elif "vsr" in name:
1514  if "mem1" in name or "mep1" in name and not widebins: rlines(1, window, abscissa)
1515  if "mem2" in name or "mep2" in name and not widebins: rlines(2, window, abscissa)
1516  if "mem3" in name or "mep3" in name and not widebins: rlines(3, window, abscissa)
1517  if "mem4" in name or "mep4" in name and not widebins: rlines(4, window, abscissa)
1518  if abscissa is None:
1519  tline1 = ROOT.TLine(100, 0, 700, 0); tline1.Draw()
1520  tline2 = ROOT.TLine(100, -window, 700, -window); tline2.SetLineWidth(2); tline2.Draw()
1521  tline3 = ROOT.TLine(100, window, 700, window); tline3.Draw()
1522  else:
1523  tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1524  tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1525  tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1526 
1527  if "vsphi" in name and fitsawteeth:
1528  global CPP_LOADED
1529  if not CPP_LOADED:
1530  phiedges2c()
1531  ROOT.gROOT.ProcessLine(".L phiedges_fitfunctions.C++")
1532  CPP_LOADED = True
1533  fn={0: ROOT.fitf0,
1534  1: ROOT.fitf2,
1535  2: ROOT.fitf2,
1536  3: ROOT.fitf3,
1537  4: ROOT.fitf4,
1538  5: ROOT.fitf5,
1539  6: ROOT.fitf6,
1540  7: ROOT.fitf7,
1541  8: ROOT.fitf8,
1542  9: ROOT.fitf9,
1543  10: ROOT.fitf10,
1544  11: ROOT.fitf11,
1545  12: ROOT.fitf12,
1546  13: ROOT.fitf13
1547  } [stationIndex(name)]
1548  fn.SetNpx(5000)
1549  fn.SetLineColor(ROOT.kYellow)
1550  hist.Fit(fn,"N")
1551  fn.Draw("same")
1552 
1553  # get properly arranged phi edges
1554  edges = (phiedges[stationIndex(name)])[:]
1555  ed = sorted(edges)
1556  # add some padding to the end
1557  ed.append(pi+abs(ed[0]))
1558 
1559  global sawtooth_a, sawtooth_b
1560  sawtooth_a = []
1561  sawtooth_da = []
1562  sawtooth_b = []
1563  for pr in range(0,fn.GetNpar(),2):
1564  sawtooth_a.append( (fn.GetParameter(pr), fn.GetParError(pr)) )
1565  sawtooth_b.append( (fn.GetParameter(pr+1), fn.GetParError(pr+1)) )
1566  sawtooth_da.append( (fn.Eval(ed[pr/2]+0.01), fn.Eval(ed[pr/2+1]-0.01)) )
1567  global MAP_RESULTS_SAWTOOTH
1568  MAP_RESULTS_SAWTOOTH[id] = {'a': sawtooth_a, 'da': sawtooth_da, 'b': sawtooth_b, 'chi2': fn.GetChisquare(), 'ndf': fn.GetNDF()}
1569 
1570  # fill number of contributiong bins
1571 
1572 
1573  #ROOT.SetOwnership(hist,False)
1574  ROOT.SetOwnership(hist2d,False)
1575  ROOT.SetOwnership(hist2dweight,False)
1576  ROOT.SetOwnership(tline1,False)
1577  ROOT.SetOwnership(tline2,False)
1578  ROOT.SetOwnership(tline3,False)
1579  return hist
1580 
1581 
1582 def mapNameToId(name):
1583  if "DT" in name:
1584  wh = "-ALL"
1585  if name.find('wh')>1: wh = name[name.find('wh')+2]
1586  if wh == "A": w = "-2"
1587  elif wh == "B": w = "-1"
1588  elif wh == "C": w = "-0"
1589  elif wh == "D": w = "+1"
1590  elif wh == "E": w = "+2"
1591  elif wh == "-ALL": w = "-ALL"
1592  else: return None
1593  station=''
1594  if wh == "-ALL":
1595  if name.find('sec')<0: return None
1596  station = name[name.find('sec')-1]
1597  sector = ''
1598  sector = name[name.find('sec')+3:name.find('sec')+5]
1599  return "MB%s/%s/%s" % (w, station, sector)
1600  if name.find('st')>1: station = name[name.find('st')+2]
1601  else: return None
1602  return "MB%s/%s" % (w, station)
1603  elif "CSC" in name:
1604  p = name.find('me')
1605  if p<0: return None
1606  if name[p+2]=="p": endcap = "+"
1607  elif name[p+2]=="m": endcap = "-"
1608  else: return None
1609  station = name[p+3]
1610  pch = name.find('ch')
1611  if pch<0:
1612  ring = name[p+4]
1613  return "ME%s%s/%s" % (endcap, station, ring)
1614  ring = 'ALL'
1615  chamber = name[pch+2:pch+4]
1616  return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
1617  return None
1618 
1619 
1620 def curvatureplot(tfiles, name, param, mode="from2d", window=15., widebins=False, title="", fitgauss=False, fitconst=False, fitline=False, reset_palette=False):
1621 # "param" may be one of "deltax" (Delta x position residuals), "deltadxdz" (Delta (dx/dz) angular residuals), "curverr" (Delta x * d(Delta q/pT)/d(Delta x) = Delta q/pT in the absence of misalignment)
1622  tdrStyle.SetOptTitle(1)
1623  tdrStyle.SetTitleBorderSize(0)
1624  tdrStyle.SetOptStat(0)
1625  tdrStyle.SetOptFit(0)
1626  tdrStyle.SetTitleFontSize(0.05)
1627 
1628  c1.Clear()
1629  if reset_palette: set_palette("blues")
1630  global hist, histCOPY, hist2d, tline1, tline2, tline3, tline4, tline5
1631 
1632  hdir = "AlignmentMonitorMuonVsCurvature/iter1/"
1633 
1634  if name not in ("all", "top", "bottom"):
1635  hsuffix = "_%s_%s" % (name, param)
1636  prof = tfiles[0].Get(hdir+"tprofile"+hsuffix).Clone("tprofile_"+hsuffix)
1637  hist2d = tfiles[0].Get(hdir+"th2f"+hsuffix).Clone("th2f_"+hsuffix)
1638  for tfile in tfiles[1:]:
1639  prof.Add(tfile.Get(hdir+"tprofile"+hsuffix))
1640  hist2d.Add(tfile.Get(hdir+"th2f"+hsuffix))
1641  else:
1642  prof = None
1643  hist2d = None
1644  for wheel in "m2", "m1", "z", "p1", "p2":
1645  if name == "all": sectors = "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"
1646  elif name == "top": sectors = "01", "02", "03", "04", "05", "06"
1647  elif name == "bottom": sectors = "07", "08", "09", "10", "11", "12"
1648  else: raise Exception
1649 
1650  for sector in sectors:
1651  hsuffix = "_%s_%s" % ("wheel%s_sector%s" % (wheel, sector), param)
1652  for tfile in tfiles:
1653  if prof is None:
1654  prof = tfiles[0].Get(hdir+"tprofile"+hsuffix).Clone("tprofile_"+hsuffix)
1655  hist2d = tfiles[0].Get(hdir+"th2f"+hsuffix).Clone("tprofile_"+hsuffix)
1656  else:
1657  prof.Add(tfile.Get(hdir+"tprofile"+hsuffix))
1658  hist2d.Add(tfile.Get(hdir+"th2f"+hsuffix))
1659 
1660  hist = ROOT.TH1F("hist", "", prof.GetNbinsX(), prof.GetBinLowEdge(1), -prof.GetBinLowEdge(1))
1661  for i in xrange(1, prof.GetNbinsX()+1):
1662  hist.SetBinContent(i, prof.GetBinContent(i))
1663  hist.SetBinError(i, prof.GetBinError(i))
1664 
1665  if mode == "plain":
1666  hist = prof
1667  elif mode == "from2d":
1668  skip = 1
1669  if widebins:
1670  hist.Rebin(5)
1671  skip = 5
1672  for i in xrange(0, int(prof.GetNbinsX()), skip):
1673  tmp = hist2d.ProjectionY("tmp", i+1, i + skip)
1674  if tmp.GetEntries() > 1:
1675  hist.SetBinContent(i/skip+1, tmp.GetMean())
1676  hist.SetBinError(i/skip+1, ROOT.TMath.StudentQuantile(0.841345,tmp.GetEntries()) * tmp.GetRMS() / sqrt(tmp.GetEntries()))
1677  #hist.SetBinError(i/skip+1, tmp.GetRMS() / sqrt(tmp.GetEntries()))
1678  else:
1679  #hist.SetBinContent(i/skip+1, 2000.)
1680  #hist.SetBinError(i/skip+1, 1000.)
1681  hist.SetBinContent(i/skip+1, 0.)
1682  hist.SetBinError(i/skip+1, 0.)
1683  else:
1684  raise Exception
1685 
1686 
1687  if fitgauss:
1688  f = ROOT.TF1("f", "[0] + [1]*exp(-x**2/2/0.01**2)", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1689  f.SetParameters(0, 0., 0.01)
1690  hist.Fit(f, "q")
1691  f.SetLineColor(ROOT.kRed)
1692  global fitgauss_diff, fitgauss_chi2, fitgauss_ndf
1693 # fitter = ROOT.TVirtualFitter.GetFitter()
1694 # fitgauss_diff = f.GetParameter(0) - f.GetParameter(1), \
1695 # sqrt(f.GetParError(0)**2 + f.GetParError(1)**2 + 2.*fitter.GetCovarianceMatrixElement(0, 1))
1696  fitgauss_diff = f.GetParameter(1), f.GetParError(1)
1697  fitgauss_chi2 = f.GetChisquare()
1698  fitgauss_ndf = f.GetNDF()
1699 
1700  global fitline_intercept, fitline_slope
1701  if fitconst:
1702  f = ROOT.TF1("f", "[0]", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1703  hist.Fit(f, "q")
1704  f.SetLineColor(ROOT.kRed)
1705  fitline_intercept = f.GetParameter(0), f.GetParError(0)
1706 
1707  if fitline:
1708  f = ROOT.TF1("f", "[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1709  hist.Fit(f, "qNE")
1710  f.SetLineColor(ROOT.kRed)
1711  global f2, f3
1712  f2 = ROOT.TF1("2", "[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1713  f3 = ROOT.TF1("2", "[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1714  f2.SetParameters(f.GetParameter(0), f.GetParameter(1) + f.GetParError(1))
1715  f3.SetParameters(f.GetParameter(0), f.GetParameter(1) - f.GetParError(1))
1716  f2.SetLineColor(ROOT.kRed)
1717  f3.SetLineColor(ROOT.kRed)
1718  f2.SetLineStyle(2)
1719  f3.SetLineStyle(2)
1720  fitline_intercept = f.GetParameter(0), f.GetParError(0)
1721  fitline_slope = f.GetParameter(1), f.GetParError(1)
1722 
1723  hist.SetAxisRange(-window, window, "Y")
1724  hist.SetMarkerStyle(20)
1725  hist.SetMarkerSize(0.75)
1726  hist.GetXaxis().CenterTitle()
1727  hist.GetYaxis().CenterTitle()
1728  if param == "curverr":
1729  hist.GetYaxis().SetTitleOffset(1.35)
1730  else:
1731  hist.GetYaxis().SetTitleOffset(0.75)
1732  hist.GetXaxis().SetTitleOffset(1.2)
1733  hist.GetXaxis().SetTitleSize(0.05)
1734  hist.GetYaxis().SetTitleSize(0.05)
1735  hist.SetTitle(title)
1736  if param == "pterr": hist.SetXTitle("qp_{T} (GeV/c)")
1737  else: hist.SetXTitle("q/p_{T} (c/GeV)")
1738  if param == "deltax": hist.SetYTitle("#Deltax' (mm)")
1739  if param == "deltadxdz": hist.SetYTitle("#Deltadx'/dz (mrad)")
1740  if param == "pterr": hist.SetYTitle("#Deltap_{T}/p_{T} (%)")
1741  if param == "curverr": hist.SetYTitle("#Deltaq/p_{T} (c/GeV)")
1742  hist.SetMarkerColor(ROOT.kBlack)
1743  hist.SetLineColor(ROOT.kBlack)
1744  hist.Draw()
1745  hist2d.Draw("colzsame")
1746  histCOPY = hist.Clone()
1747  histCOPY.SetXTitle("")
1748  histCOPY.SetYTitle("")
1749 
1750  if widebins:
1751  histCOPY.Draw("samee1")
1752  histCOPY.Draw("sameaxis")
1753  else:
1754  histCOPY.Draw("same")
1755  histCOPY.Draw("sameaxis")
1756 
1757  if fitline:
1758  f.Draw("same")
1759  #f2.Draw("same")
1760  #f3.Draw("same")
1761 
1762  tline1 = ROOT.TLine(hist.GetBinLowEdge(1), -window, hist.GetBinLowEdge(1), window)
1763  tline2 = ROOT.TLine(hist.GetBinLowEdge(1), window, -hist.GetBinLowEdge(1), window)
1764  tline3 = ROOT.TLine(-hist.GetBinLowEdge(1), window, -hist.GetBinLowEdge(1), -window)
1765  tline4 = ROOT.TLine(-hist.GetBinLowEdge(1), -window, hist.GetBinLowEdge(1), -window)
1766  tline5 = ROOT.TLine(-hist.GetBinLowEdge(1), 0., hist.GetBinLowEdge(1), 0.)
1767  for t in tline1, tline2, tline3, tline4, tline5: t.Draw()
1768 
1769 
1770 def curvatureDTsummary(tfiles, window=15., pdgSfactor=False):
1771  global h, gm2, gm1, gz, gp1, gp2, tlegend
1772 
1773  set_palette("blues")
1774  phis = {-2: [], -1: [], 0: [], 1: [], 2: []}
1775  diffs = {-2: [], -1: [], 0: [], 1: [], 2: []}
1776  differrs = {-2: [], -1: [], 0: [], 1: [], 2: []}
1777  for wheelstr, wheel in ("m2", "-2"), ("m1", "-1"), ("z", "0"), ("p1", "+1"), ("p2", "+2"):
1778  for sector in "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12":
1779  curvatureplot(tfiles, "wheel%s_sector%s" % (wheelstr, sector), "deltax",
1780  title="Wheel %s, sector %s" % (wheel, sector), fitgauss=True, reset_palette=False)
1781  if fitgauss_diff[1] < window:
1782  uncertainty = fitgauss_diff[1]
1783  if pdgSfactor and (fitgauss_chi2/fitgauss_ndf) > 1.: uncertainty *= sqrt(fitgauss_chi2/fitgauss_ndf)
1784 
1785  phis[int(wheel)].append(signConventions["DT", int(wheel), 1, int(sector)][4])
1786  diffs[int(wheel)].append(fitgauss_diff[0])
1787  differrs[int(wheel)].append(uncertainty)
1788 
1789  h = ROOT.TH1F("h", "", 1, -pi, pi)
1790  h.SetAxisRange(-window, window, "Y")
1791  h.SetXTitle("#phi (rad)")
1792  h.SetYTitle("#Deltax(p_{T} #rightarrow #infty) - #Deltax(p_{T} #rightarrow 0) (mm)")
1793  h.GetXaxis().CenterTitle()
1794  h.GetYaxis().CenterTitle()
1795 
1796  gm2 = ROOT.TGraphErrors(len(phis[-2]), array.array("d", phis[-2]), array.array("d", diffs[-2]),
1797  array.array("d", [0.]*len(phis[-2])), array.array("d", differrs[-2]))
1798  gm1 = ROOT.TGraphErrors(len(phis[-1]), array.array("d", phis[-1]), array.array("d", diffs[-1]),
1799  array.array("d", [0.]*len(phis[-1])), array.array("d", differrs[-1]))
1800  gz = ROOT.TGraphErrors(len(phis[0]), array.array("d", phis[0]), array.array("d", diffs[0]),
1801  array.array("d", [0.]*len(phis[0])), array.array("d", differrs[0]))
1802  gp1 = ROOT.TGraphErrors(len(phis[1]), array.array("d", phis[1]), array.array("d", diffs[1]),
1803  array.array("d", [0.]*len(phis[1])), array.array("d", differrs[1]))
1804  gp2 = ROOT.TGraphErrors(len(phis[2]), array.array("d", phis[2]), array.array("d", diffs[2]),
1805  array.array("d", [0.]*len(phis[2])), array.array("d", differrs[2]))
1806 
1807  gm2.SetMarkerStyle(21); gm2.SetMarkerColor(ROOT.kRed); gm2.SetLineColor(ROOT.kRed)
1808  gm1.SetMarkerStyle(22); gm1.SetMarkerColor(ROOT.kBlue); gm1.SetLineColor(ROOT.kBlue)
1809  gz.SetMarkerStyle(3); gz.SetMarkerColor(ROOT.kBlack); gz.SetLineColor(ROOT.kBlack)
1810  gp1.SetMarkerStyle(26); gp1.SetMarkerColor(ROOT.kBlue); gp1.SetLineColor(ROOT.kBlue)
1811  gp2.SetMarkerStyle(25); gp2.SetMarkerColor(ROOT.kRed); gp2.SetLineColor(ROOT.kRed)
1812 
1813  h.Draw()
1814  tlegend = ROOT.TLegend(0.25, 0.2, 0.85, 0.5)
1815  tlegend.SetFillColor(ROOT.kWhite)
1816  tlegend.SetBorderSize(0)
1817  tlegend.AddEntry(gm2, "Wheel -2", "p")
1818  tlegend.AddEntry(gm1, "Wheel -1", "p")
1819  tlegend.AddEntry(gz, "Wheel 0", "p")
1820  tlegend.AddEntry(gp1, "Wheel +1", "p")
1821  tlegend.AddEntry(gp2, "Wheel +2", "p")
1822  tlegend.Draw()
1823 
1824  gm2.Draw("p")
1825  gm1.Draw("p")
1826  gz.Draw("p")
1827  gp1.Draw("p")
1828  gp2.Draw("p")
1829 
1830 
1831 def getname(r):
1832  if r.postal_address[0] == "DT":
1833  wheel, station, sector = r.postal_address[1:]
1834  return "DT wheel %d, station %d, sector %d" % (wheel, station, sector)
1835  elif r.postal_address[0] == "CSC":
1836  endcap, station, ring, chamber = r.postal_address[1:]
1837  if endcap != 1: station = -1 * abs(station)
1838  return "CSC ME%d/%d chamber %d" % (station, ring, chamber)
1839 
1840 ddt=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
1841 def clearDDT():
1842  for i in range(0,15):
1843  ddt[i]=0.
1844 
1846  n = 0
1847  for t in ddt:
1848  if n==0 or n==7 or n==15: print "%d calls" % t
1849  else: print "%d : %0.3f ms" % (n,t*1000.0)
1850  n += 1
1851 
1852 def bellcurves(tfile, reports, name, twobin=True, suppressblue=False):
1853  t1 = time.time()
1854  ddt[0] += 1
1855  tdrStyle.SetOptTitle(1)
1856  tdrStyle.SetTitleBorderSize(1)
1857  tdrStyle.SetTitleFontSize(0.1)
1858  tdrStyle.SetOptStat(0)
1859  tdrStyle.SetHistMinimumZero()
1860 
1861  c1.Clear()
1862  c1.ResetAttPad()
1863 
1864  found = False
1865  for r in reports:
1866  if r.name == name:
1867  found = True
1868  break
1869  if not found: raise Exception, "Not a valid name"
1870  if r.status == "FAIL":
1871  #raise Exception, "Fit failed"
1872  print "Fit failed"
1873  c1.Clear()
1874  return
1875 
1876  Pos = "Pos"; Neg = "Neg"
1877  if not twobin:
1878  Pos = ""; Neg = ""
1879 
1880  pdirPos = "MuonAlignmentFromReference/%s%s" % (name, Pos)
1881  pdirNeg = "MuonAlignmentFromReference/%s%s" % (name, Neg)
1882 
1883  t2 = time.time()
1884  ddt[1] = 1./ddt[0]*((ddt[0]-1)*ddt[1] + t2-t1)
1885 
1886  chamber_x = tfile.Get(pdirPos+"_x")
1887  chamber_x_fit = tfile.Get(pdirPos+"_x_fit")
1888  chamber_y = tfile.Get(pdirPos+"_y")
1889  chamber_y_fit = tfile.Get(pdirPos+"_y_fit")
1890  chamber_dxdz = tfile.Get(pdirPos+"_dxdz")
1891  chamber_dxdz_fit = tfile.Get(pdirPos+"_dxdz_fit")
1892  chamber_dydz = tfile.Get(pdirPos+"_dydz")
1893  chamber_dydz_fit = tfile.Get(pdirPos+"_dydz_fit")
1894  chamber_alphax = tfile.Get(pdirPos+"_alphax")
1895  chamber_alphax_fit = tfile.Get(pdirPos+"_alphax_fit")
1896  chamber_alphay = tfile.Get(pdirPos+"_alphay")
1897  chamber_alphay_fit = tfile.Get(pdirPos+"_alphay_fit")
1898  chamber_x_fit2 = tfile.Get(pdirNeg+"_x_fit")
1899  chamber_y_fit2 = tfile.Get(pdirNeg+"_y_fit")
1900  chamber_dxdz_fit2 = tfile.Get(pdirNeg+"_dxdz_fit")
1901  chamber_dydz_fit2 = tfile.Get(pdirNeg+"_dydz_fit")
1902  chamber_alphax_fit2 = tfile.Get(pdirNeg+"_alphax_fit")
1903  chamber_alphay_fit2 = tfile.Get(pdirNeg+"_alphay_fit")
1904 
1905  if not chamber_x:
1906  chamber_x = tfile.Get(pdirPos+"_residual")
1907  chamber_x_fit = tfile.Get(pdirPos+"_residual_fit")
1908  chamber_dxdz = tfile.Get(pdirPos+"_resslope")
1909  chamber_dxdz_fit = tfile.Get(pdirPos+"_resslope_fit")
1910  chamber_alphax = tfile.Get(pdirPos+"_alpha")
1911  chamber_alphax_fit = tfile.Get(pdirPos+"_alpha_fit")
1912  chamber_x_fit2 = tfile.Get(pdirNeg+"_residual_fit")
1913  chamber_dxdz_fit2 = tfile.Get(pdirNeg+"_resslope_fit")
1914  chamber_alphax_fit2 = tfile.Get(pdirNeg+"_alpha_fit")
1915 
1916  if not chamber_x:
1917  print "Can't find neither "+pdirPos+"_x nor "+pdirPos+"_residual"
1918  return
1919 
1920  t3 = time.time()
1921  ddt[2] = 1./ddt[0]*((ddt[0]-1)*ddt[2] + t3-t2)
1922 
1923  ####
1924  chamber_x.SetAxisRange(-30., 30., "X")
1925  chamber_dxdz.SetAxisRange(-50., 50., "X")
1926  if not not chamber_y:
1927  chamber_y.SetAxisRange(-150., 150., "X")
1928  chamber_dydz.SetAxisRange(-200., 200., "X")
1929  ####
1930 
1931  chamber_x.SetXTitle("Local x residual (mm)")
1932  chamber_dxdz.SetXTitle("Local dx/dz residual (mrad)")
1933  chamber_alphax.SetXTitle("Local dx/dz residual (mrad)")
1934  chamber_alphax.SetYTitle("Local x residual (mm)")
1935  if not not chamber_y:
1936  chamber_y.SetXTitle("Local y residual (mm)")
1937  chamber_dydz.SetXTitle("Local dy/dz residual (mrad)")
1938  chamber_alphay.SetXTitle("Local dy/dz residual (mrad)")
1939  chamber_alphay.SetYTitle("Local y residual (mm)")
1940  if name[0:2] == "ME":
1941  chamber_x.SetXTitle("Local r#phi residual (mm)")
1942  chamber_dxdz.SetXTitle("Local d(r#phi)/dz residual (mrad)")
1943  chamber_alphax.SetXTitle("Local d(r#phi)/dz residual (mrad)")
1944  chamber_alphax.SetYTitle("Local r#phi residual (mm)")
1945 
1946  t4 = time.time()
1947  ddt[3] = 1./ddt[0]*((ddt[0]-1)*ddt[3] + t4-t3)
1948 
1949  for h in chamber_x, chamber_dxdz, chamber_alphax, chamber_alphax, \
1950  chamber_y, chamber_dydz, chamber_alphay, chamber_alphay:
1951  if not not h:
1952  h.GetXaxis().CenterTitle()
1953  h.GetYaxis().CenterTitle()
1954  h.GetXaxis().SetLabelSize(0.05)
1955  h.GetYaxis().SetLabelSize(0.05)
1956  h.GetXaxis().SetTitleSize(0.07)
1957  h.GetYaxis().SetTitleSize(0.07)
1958  h.GetXaxis().SetTitleOffset(0.9)
1959  h.GetYaxis().SetTitleOffset(0.9)
1960 
1961  for f in chamber_x_fit2, chamber_y_fit2, chamber_dxdz_fit2, chamber_dydz_fit2, \
1962  chamber_alphax_fit2, chamber_alphay_fit2:
1963  if not not f:
1964  f.SetLineColor(4)
1965 
1966  t5 = time.time()
1967  ddt[4] = 1./ddt[0]*((ddt[0]-1)*ddt[4] + t5-t4)
1968 
1969  if not not chamber_y:
1970  c1.Clear()
1971  c1.Divide(3, 2)
1972  chamber_x.SetTitle(getname(r))
1973 
1974  c1.GetPad(1).cd()
1975  chamber_x.Draw()
1976  if not suppressblue: chamber_x_fit2.Draw("same")
1977  chamber_x_fit.Draw("same")
1978 
1979  c1.GetPad(2).cd()
1980  chamber_dxdz.Draw()
1981  if not suppressblue: chamber_dxdz_fit2.Draw("same")
1982  chamber_dxdz_fit.Draw("same")
1983 
1984  c1.GetPad(3).cd()
1985  chamber_alphax.Draw()
1986  if not suppressblue: chamber_alphax_fit2.Draw("same")
1987  chamber_alphax_fit.Draw("same")
1988 
1989  c1.GetPad(4).cd()
1990  chamber_y.Draw()
1991  if not suppressblue: chamber_y_fit2.Draw("same")
1992  chamber_y_fit.Draw("same")
1993 
1994  c1.GetPad(5).cd()
1995  chamber_dydz.Draw()
1996  if not suppressblue: chamber_dydz_fit2.Draw("same")
1997  chamber_dydz_fit.Draw("same")
1998 
1999  c1.GetPad(6).cd()
2000  chamber_alphay.Draw()
2001  if not suppressblue: chamber_alphay_fit2.Draw("same")
2002  chamber_alphay_fit.Draw("same")
2003 
2004  else:
2005  c1.Clear()
2006  c1.Divide(3, 1)
2007  chamber_x.SetTitle(getname(r))
2008 
2009  c1.GetPad(1).cd()
2010  chamber_x.Draw()
2011  if not suppressblue: chamber_x_fit2.Draw("same")
2012  chamber_x_fit.Draw("same")
2013 
2014  c1.GetPad(2).cd()
2015  chamber_dxdz.Draw()
2016  if not suppressblue: chamber_dxdz_fit2.Draw("same")
2017  chamber_dxdz_fit.Draw("same")
2018 
2019  c1.GetPad(3).cd()
2020  chamber_alphax.Draw()
2021  if not suppressblue: chamber_alphax_fit2.Draw("same")
2022  chamber_alphax_fit.Draw("same")
2023 
2024  t6 = time.time()
2025  ddt[5] = 1./ddt[0]*((ddt[0]-1)*ddt[5] + t6-t5)
2026  ddt[6] = 1./ddt[0]*((ddt[0]-1)*ddt[6] + t6-t1)
2027 
2028 
2029 def polynomials(tfile, reports, name, twobin=True, suppressblue=False):
2030  t1 = time.time()
2031  ddt[7] += 1
2032  global label1, label2, label3, label4, label5, label6, label7, label8, label9
2033  plotDirectory = "MuonAlignmentFromReference"
2034  tdrStyle.SetOptTitle(1)
2035  tdrStyle.SetTitleBorderSize(1)
2036  tdrStyle.SetTitleFontSize(0.1)
2037  tdrStyle.SetOptStat(0)
2038 
2039  c1.Clear()
2040  c1.ResetAttPad()
2041 
2042  found = False
2043  for r in reports:
2044  if r.name == name:
2045  found = True
2046  break
2047  if not found: raise Exception, "Not a valid name"
2048 
2049  if r.status == "FAIL":
2050  #raise Exception, "Fit failed"
2051  print "Fit failed"
2052  c1.Clear()
2053  return
2054 
2055  Pos = "Pos"; Neg = "Neg"
2056  if not twobin:
2057  Pos = ""; Neg = ""
2058 
2059  pdirPos = "MuonAlignmentFromReference/%s%s" % (name, Pos)
2060  pdirNeg = "MuonAlignmentFromReference/%s%s" % (name, Neg)
2061 
2062  global chamber_x_trackx, chamber_x_trackx_fit, chamber_y_trackx, chamber_y_trackx_fit, \
2063  chamber_dxdz_trackx, chamber_dxdz_trackx_fit, chamber_dydz_trackx, chamber_dydz_trackx_fit, \
2064  chamber_x_trackx_fit2, chamber_y_trackx_fit2, chamber_dxdz_trackx_fit2, chamber_dydz_trackx_fit2
2065  global chamber_x_tracky, chamber_x_tracky_fit, chamber_y_tracky, chamber_y_tracky_fit, \
2066  chamber_dxdz_tracky, chamber_dxdz_tracky_fit, chamber_dydz_tracky, chamber_dydz_tracky_fit, \
2067  chamber_x_tracky_fit2, chamber_y_tracky_fit2, chamber_dxdz_tracky_fit2, chamber_dydz_tracky_fit2
2068  global chamber_x_trackdxdz, chamber_x_trackdxdz_fit, chamber_y_trackdxdz, chamber_y_trackdxdz_fit, \
2069  chamber_dxdz_trackdxdz, chamber_dxdz_trackdxdz_fit, chamber_dydz_trackdxdz, chamber_dydz_trackdxdz_fit, \
2070  chamber_x_trackdxdz_fit2, chamber_y_trackdxdz_fit2, chamber_dxdz_trackdxdz_fit2, chamber_dydz_trackdxdz_fit2
2071  global chamber_x_trackdydz, chamber_x_trackdydz_fit, chamber_y_trackdydz, chamber_y_trackdydz_fit, \
2072  chamber_dxdz_trackdydz, chamber_dxdz_trackdydz_fit, chamber_dydz_trackdydz, chamber_dydz_trackdydz_fit, \
2073  chamber_x_trackdydz_fit2, chamber_y_trackdydz_fit2, chamber_dxdz_trackdydz_fit2, chamber_dydz_trackdydz_fit2
2074 
2075  chamber_x_trackx = tfile.Get(pdirPos+"_x_trackx")
2076  chamber_x_trackx_fit = tfile.Get(pdirPos+"_x_trackx_fitline")
2077  chamber_y_trackx = tfile.Get(pdirPos+"_y_trackx")
2078  chamber_y_trackx_fit = tfile.Get(pdirPos+"_y_trackx_fitline")
2079  chamber_dxdz_trackx = tfile.Get(pdirPos+"_dxdz_trackx")
2080  chamber_dxdz_trackx_fit = tfile.Get(pdirPos+"_dxdz_trackx_fitline")
2081  chamber_dydz_trackx = tfile.Get(pdirPos+"_dydz_trackx")
2082  chamber_dydz_trackx_fit = tfile.Get(pdirPos+"_dydz_trackx_fitline")
2083  chamber_x_trackx_fit2 = tfile.Get(pdirNeg+"_x_trackx_fitline")
2084  chamber_y_trackx_fit2 = tfile.Get(pdirNeg+"_y_trackx_fitline")
2085  chamber_dxdz_trackx_fit2 = tfile.Get(pdirNeg+"_dxdz_trackx_fitline")
2086  chamber_dydz_trackx_fit2 = tfile.Get(pdirNeg+"_dydz_trackx_fitline")
2087 
2088  chamber_x_tracky = tfile.Get(pdirPos+"_x_tracky")
2089  chamber_x_tracky_fit = tfile.Get(pdirPos+"_x_tracky_fitline")
2090  chamber_y_tracky = tfile.Get(pdirPos+"_y_tracky")
2091  chamber_y_tracky_fit = tfile.Get(pdirPos+"_y_tracky_fitline")
2092  chamber_dxdz_tracky = tfile.Get(pdirPos+"_dxdz_tracky")
2093  chamber_dxdz_tracky_fit = tfile.Get(pdirPos+"_dxdz_tracky_fitline")
2094  chamber_dydz_tracky = tfile.Get(pdirPos+"_dydz_tracky")
2095  chamber_dydz_tracky_fit = tfile.Get(pdirPos+"_dydz_tracky_fitline")
2096  chamber_x_tracky_fit2 = tfile.Get(pdirNeg+"_x_tracky_fitline")
2097  chamber_y_tracky_fit2 = tfile.Get(pdirNeg+"_y_tracky_fitline")
2098  chamber_dxdz_tracky_fit2 = tfile.Get(pdirNeg+"_dxdz_tracky_fitline")
2099  chamber_dydz_tracky_fit2 = tfile.Get(pdirNeg+"_dydz_tracky_fitline")
2100 
2101  chamber_x_trackdxdz = tfile.Get(pdirPos+"_x_trackdxdz")
2102  chamber_x_trackdxdz_fit = tfile.Get(pdirPos+"_x_trackdxdz_fitline")
2103  chamber_y_trackdxdz = tfile.Get(pdirPos+"_y_trackdxdz")
2104  chamber_y_trackdxdz_fit = tfile.Get(pdirPos+"_y_trackdxdz_fitline")
2105  chamber_dxdz_trackdxdz = tfile.Get(pdirPos+"_dxdz_trackdxdz")
2106  chamber_dxdz_trackdxdz_fit = tfile.Get(pdirPos+"_dxdz_trackdxdz_fitline")
2107  chamber_dydz_trackdxdz = tfile.Get(pdirPos+"_dydz_trackdxdz")
2108  chamber_dydz_trackdxdz_fit = tfile.Get(pdirPos+"_dydz_trackdxdz_fitline")
2109  chamber_x_trackdxdz_fit2 = tfile.Get(pdirNeg+"_x_trackdxdz_fitline")
2110  chamber_y_trackdxdz_fit2 = tfile.Get(pdirNeg+"_y_trackdxdz_fitline")
2111  chamber_dxdz_trackdxdz_fit2 = tfile.Get(pdirNeg+"_dxdz_trackdxdz_fitline")
2112  chamber_dydz_trackdxdz_fit2 = tfile.Get(pdirNeg+"_dydz_trackdxdz_fitline")
2113 
2114  chamber_x_trackdydz = tfile.Get(pdirPos+"_x_trackdydz")
2115  chamber_x_trackdydz_fit = tfile.Get(pdirPos+"_x_trackdydz_fitline")
2116  chamber_y_trackdydz = tfile.Get(pdirPos+"_y_trackdydz")
2117  chamber_y_trackdydz_fit = tfile.Get(pdirPos+"_y_trackdydz_fitline")
2118  chamber_dxdz_trackdydz = tfile.Get(pdirPos+"_dxdz_trackdydz")
2119  chamber_dxdz_trackdydz_fit = tfile.Get(pdirPos+"_dxdz_trackdydz_fitline")
2120  chamber_dydz_trackdydz = tfile.Get(pdirPos+"_dydz_trackdydz")
2121  chamber_dydz_trackdydz_fit = tfile.Get(pdirPos+"_dydz_trackdydz_fitline")
2122  chamber_x_trackdydz_fit2 = tfile.Get(pdirNeg+"_x_trackdydz_fitline")
2123  chamber_y_trackdydz_fit2 = tfile.Get(pdirNeg+"_y_trackdydz_fitline")
2124  chamber_dxdz_trackdydz_fit2 = tfile.Get(pdirNeg+"_dxdz_trackdydz_fitline")
2125  chamber_dydz_trackdydz_fit2 = tfile.Get(pdirNeg+"_dydz_trackdydz_fitline")
2126 
2127  if not chamber_x_trackx:
2128  chamber_x_trackx = tfile.Get(pdirPos+"_residual_trackx")
2129  chamber_x_trackx_fit = tfile.Get(pdirPos+"_residual_trackx_fitline")
2130  chamber_dxdz_trackx = tfile.Get(pdirPos+"_resslope_trackx")
2131  chamber_dxdz_trackx_fit = tfile.Get(pdirPos+"_resslope_trackx_fitline")
2132  chamber_x_trackx_fit2 = tfile.Get(pdirNeg+"_residual_trackx_fitline")
2133  chamber_dxdz_trackx_fit2 = tfile.Get(pdirNeg+"_resslope_trackx_fitline")
2134 
2135  chamber_x_tracky = tfile.Get(pdirPos+"_residual_tracky")
2136  chamber_x_tracky_fit = tfile.Get(pdirPos+"_residual_tracky_fitline")
2137  chamber_dxdz_tracky = tfile.Get(pdirPos+"_resslope_tracky")
2138  chamber_dxdz_tracky_fit = tfile.Get(pdirPos+"_resslope_tracky_fitline")
2139  chamber_x_tracky_fit2 = tfile.Get(pdirNeg+"_residual_tracky_fitline")
2140  chamber_dxdz_tracky_fit2 = tfile.Get(pdirNeg+"_resslope_tracky_fitline")
2141 
2142  chamber_x_trackdxdz = tfile.Get(pdirPos+"_residual_trackdxdz")
2143  chamber_x_trackdxdz_fit = tfile.Get(pdirPos+"_residual_trackdxdz_fitline")
2144  chamber_dxdz_trackdxdz = tfile.Get(pdirPos+"_resslope_trackdxdz")
2145  chamber_dxdz_trackdxdz_fit = tfile.Get(pdirPos+"_resslope_trackdxdz_fitline")
2146  chamber_x_trackdxdz_fit2 = tfile.Get(pdirNeg+"_residual_trackdxdz_fitline")
2147  chamber_dxdz_trackdxdz_fit2 = tfile.Get(pdirNeg+"_resslope_trackdxdz_fitline")
2148 
2149  chamber_x_trackdydz = tfile.Get(pdirPos+"_residual_trackdydz")
2150  chamber_x_trackdydz_fit = tfile.Get(pdirPos+"_residual_trackdydz_fitline")
2151  chamber_dxdz_trackdydz = tfile.Get(pdirPos+"_resslope_trackdydz")
2152  chamber_dxdz_trackdydz_fit = tfile.Get(pdirPos+"_resslope_trackdydz_fitline")
2153  chamber_x_trackdydz_fit2 = tfile.Get(pdirNeg+"_residual_trackdydz_fitline")
2154  chamber_dxdz_trackdydz_fit2 = tfile.Get(pdirNeg+"_resslope_trackdydz_fitline")
2155 
2156  if not chamber_x_trackx:
2157  print "Can't find neither "+pdirPos+"_residual nor "+pdirPos+"_residual_trackx"
2158  return
2159 
2160  chamber_x_trackx = chamber_x_trackx.Clone()
2161  chamber_dxdz_trackx = chamber_dxdz_trackx.Clone()
2162  chamber_x_tracky = chamber_x_tracky.Clone()
2163  chamber_dxdz_tracky = chamber_dxdz_tracky.Clone()
2164  chamber_x_trackdxdz = chamber_x_trackdxdz.Clone()
2165  chamber_dxdz_trackdxdz = chamber_dxdz_trackdxdz.Clone()
2166  chamber_x_trackdydz = chamber_x_trackdydz.Clone()
2167  chamber_dxdz_trackdydz = chamber_dxdz_trackdydz.Clone()
2168 
2169  if not not chamber_y_trackx:
2170  chamber_y_trackx = chamber_y_trackx.Clone()
2171  chamber_dydz_trackx = chamber_dydz_trackx.Clone()
2172  chamber_y_tracky = chamber_y_tracky.Clone()
2173  chamber_dydz_tracky = chamber_dydz_tracky.Clone()
2174  chamber_y_trackdxdz = chamber_y_trackdxdz.Clone()
2175  chamber_dydz_trackdxdz = chamber_dydz_trackdxdz.Clone()
2176  chamber_y_trackdydz = chamber_y_trackdydz.Clone()
2177  chamber_dydz_trackdydz = chamber_dydz_trackdydz.Clone()
2178 
2179  if not not chamber_y_trackx:
2180  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_trackx")); chamber_x_trackx.Merge(tlist)
2181  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_trackx")); chamber_dxdz_trackx.Merge(tlist)
2182  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_tracky")); chamber_x_tracky.Merge(tlist)
2183  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_tracky")); chamber_dxdz_tracky.Merge(tlist)
2184  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_trackdxdz")); chamber_x_trackdxdz.Merge(tlist)
2185  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_trackdxdz")); chamber_dxdz_trackdxdz.Merge(tlist)
2186  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_trackdydz")); chamber_x_trackdydz.Merge(tlist)
2187  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_trackdydz")); chamber_dxdz_trackdydz.Merge(tlist)
2188  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_trackx")); chamber_y_trackx.Merge(tlist)
2189  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_trackx")); chamber_dydz_trackx.Merge(tlist)
2190  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_tracky")); chamber_y_tracky.Merge(tlist)
2191  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_tracky")); chamber_dydz_tracky.Merge(tlist)
2192  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_trackdxdz")); chamber_y_trackdxdz.Merge(tlist)
2193  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_trackdxdz")); chamber_dydz_trackdxdz.Merge(tlist)
2194  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_trackdydz")); chamber_y_trackdydz.Merge(tlist)
2195  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_trackdydz")); chamber_dydz_trackdydz.Merge(tlist)
2196  else:
2197  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_trackx")); chamber_x_trackx.Merge(tlist)
2198  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_trackx")); chamber_dxdz_trackx.Merge(tlist)
2199  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_tracky")); chamber_x_tracky.Merge(tlist)
2200  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_tracky")); chamber_dxdz_tracky.Merge(tlist)
2201  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_trackdxdz")); chamber_x_trackdxdz.Merge(tlist)
2202  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_trackdxdz")); chamber_dxdz_trackdxdz.Merge(tlist)
2203  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_trackdydz")); chamber_x_trackdydz.Merge(tlist)
2204  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_trackdydz")); chamber_dxdz_trackdydz.Merge(tlist)
2205 
2206  rr1=19.99
2207  rr2=9.99
2208  chamber_x_trackx.SetAxisRange(-rr1, rr1, "Y")
2209  chamber_dxdz_trackx.SetAxisRange(-rr2, rr2, "Y")
2210  chamber_x_tracky.SetAxisRange(-rr1, rr1, "Y")
2211  chamber_dxdz_tracky.SetAxisRange(-rr2, rr2, "Y")
2212  chamber_x_trackdxdz.SetAxisRange(-rr1, rr1, "Y")
2213  chamber_dxdz_trackdxdz.SetAxisRange(-rr2, rr2, "Y")
2214  chamber_x_trackdydz.SetAxisRange(-rr1, rr1, "Y")
2215  chamber_dxdz_trackdydz.SetAxisRange(-rr2, rr2, "Y")
2216 
2217  rr3=49.99
2218  if not not chamber_y_trackx:
2219  chamber_y_trackx.SetAxisRange(-rr3, rr3, "Y")
2220  chamber_dydz_trackx.SetAxisRange(-rr3, rr3, "Y")
2221  chamber_y_tracky.SetAxisRange(-rr3, rr3, "Y")
2222  chamber_dydz_tracky.SetAxisRange(-rr3, rr3, "Y")
2223  chamber_y_trackdxdz.SetAxisRange(-rr3, rr3, "Y")
2224  chamber_dydz_trackdxdz.SetAxisRange(-rr3, rr3, "Y")
2225  chamber_y_trackdydz.SetAxisRange(-rr3, rr3, "Y")
2226  chamber_dydz_trackdydz.SetAxisRange(-rr3, rr3, "Y")
2227 
2228  for h in chamber_x_trackx, chamber_y_trackx, chamber_dxdz_trackx, chamber_dydz_trackx, \
2229  chamber_x_tracky, chamber_y_tracky, chamber_dxdz_tracky, chamber_dydz_tracky, \
2230  chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz, \
2231  chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2232  if not not h:
2233  h.SetMarkerStyle(20)
2234  h.SetMarkerSize(0.5)
2235  h.GetXaxis().SetLabelSize(0.12)
2236  h.GetYaxis().SetLabelSize(0.12)
2237  h.GetXaxis().SetNdivisions(505)
2238  h.GetYaxis().SetNdivisions(505)
2239  h.GetXaxis().SetLabelOffset(0.03)
2240  h.GetYaxis().SetLabelOffset(0.03)
2241 
2242  trackdxdz_minimum, trackdxdz_maximum = None, None
2243  for h in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
2244  if not not h:
2245  for i in xrange(1, h.GetNbinsX()+1):
2246  if h.GetBinError(i) > 0.01 and h.GetBinContent(i) - h.GetBinError(i) < 10. and \
2247  h.GetBinContent(i) + h.GetBinError(i) > -10.:
2248  if not trackdxdz_minimum or trackdxdz_minimum > h.GetBinCenter(i):
2249  trackdxdz_minimum = h.GetBinCenter(i)
2250  if trackdxdz_maximum < h.GetBinCenter(i):
2251  trackdxdz_maximum = h.GetBinCenter(i)
2252  if not not trackdxdz_minimum and not not trackdxdz_maximum:
2253  for h in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
2254  if not not h:
2255  h.SetAxisRange(trackdxdz_minimum, trackdxdz_maximum, "X")
2256 
2257  trackdydz_minimum, trackdydz_maximum = None, None
2258  for h in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2259  if not not h:
2260  for i in xrange(1, h.GetNbinsX()+1):
2261  if h.GetBinError(i) > 0.01 and h.GetBinContent(i) - h.GetBinError(i) < 10. and \
2262  h.GetBinContent(i) + h.GetBinError(i) > -10.:
2263  if not trackdydz_minimum or trackdydz_minimum > h.GetBinCenter(i):
2264  trackdydz_minimum = h.GetBinCenter(i)
2265  if trackdydz_maximum < h.GetBinCenter(i):
2266  trackdydz_maximum = h.GetBinCenter(i)
2267  if not not trackdydz_minimum and not not trackdydz_maximum:
2268  for h in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2269  if not not h:
2270  h.SetAxisRange(trackdydz_minimum, trackdydz_maximum, "X")
2271 
2272  for f in chamber_x_trackx_fit2, chamber_y_trackx_fit2, chamber_dxdz_trackx_fit2, chamber_dydz_trackx_fit2, \
2273  chamber_x_tracky_fit2, chamber_y_tracky_fit2, chamber_dxdz_tracky_fit2, chamber_dydz_tracky_fit2, \
2274  chamber_x_trackdxdz_fit2, chamber_y_trackdxdz_fit2, chamber_dxdz_trackdxdz_fit2, chamber_dydz_trackdxdz_fit2, \
2275  chamber_x_trackdydz_fit2, chamber_y_trackdydz_fit2, chamber_dxdz_trackdydz_fit2, chamber_dydz_trackdydz_fit2:
2276  if not not f:
2277  f.SetLineColor(4)
2278 
2279  if not not chamber_y_trackx:
2280  c1.Clear()
2281  #c1.Divide(5, 5, 1e-5, 1e-5)
2282  pads = [None]
2283  pads.append(ROOT.TPad("p1" ,"",0.00,0.78,0.07,1.00,0,0,0))
2284  pads.append(ROOT.TPad("p2" ,"",0.07,0.78,0.34,1.00,0,0,0))
2285  pads.append(ROOT.TPad("p3" ,"",0.34,0.78,0.56,1.00,0,0,0))
2286  pads.append(ROOT.TPad("p4" ,"",0.56,0.78,0.78,1.00,0,0,0))
2287  pads.append(ROOT.TPad("p5" ,"",0.78,0.78,1.00,1.00,0,0,0))
2288  pads.append(ROOT.TPad("p6" ,"",0.00,0.56,0.07,0.78,0,0,0))
2289  pads.append(ROOT.TPad("p7" ,"",0.07,0.56,0.34,0.78,0,0,0))
2290  pads.append(ROOT.TPad("p8" ,"",0.34,0.56,0.56,0.78,0,0,0))
2291  pads.append(ROOT.TPad("p9" ,"",0.56,0.56,0.78,0.78,0,0,0))
2292  pads.append(ROOT.TPad("p10","",0.78,0.56,1.00,0.78,0,0,0))
2293  pads.append(ROOT.TPad("p11","",0.00,0.34,0.07,0.56,0,0,0))
2294  pads.append(ROOT.TPad("p12","",0.07,0.34,0.34,0.56,0,0,0))
2295  pads.append(ROOT.TPad("p13","",0.34,0.34,0.56,0.56,0,0,0))
2296  pads.append(ROOT.TPad("p14","",0.56,0.34,0.78,0.56,0,0,0))
2297  pads.append(ROOT.TPad("p15","",0.78,0.34,1.00,0.56,0,0,0))
2298  pads.append(ROOT.TPad("p16","",0.00,0.07,0.07,0.34,0,0,0))
2299  pads.append(ROOT.TPad("p17","",0.07,0.07,0.34,0.34,0,0,0))
2300  pads.append(ROOT.TPad("p18","",0.34,0.07,0.56,0.34,0,0,0))
2301  pads.append(ROOT.TPad("p19","",0.56,0.07,0.78,0.34,0,0,0))
2302  pads.append(ROOT.TPad("p20","",0.78,0.07,1.00,0.34,0,0,0))
2303  pads.append(ROOT.TPad("p21","",0.00,0.00,0.07,0.07,0,0,0))
2304  pads.append(ROOT.TPad("p22","",0.07,0.00,0.34,0.07,0,0,0))
2305  pads.append(ROOT.TPad("p23","",0.34,0.00,0.56,0.07,0,0,0))
2306  pads.append(ROOT.TPad("p24","",0.56,0.00,0.78,0.07,0,0,0))
2307  pads.append(ROOT.TPad("p25","",0.78,0.00,1.00,0.07,0,0,0))
2308  for p in pads:
2309  if not not p:
2310  p.Draw()
2311  ROOT.SetOwnership(p,False)
2312 
2313  label1 = ROOT.TPaveLabel(0, 0, 1, 1, "x residuals (mm)","")
2314  label2 = ROOT.TPaveLabel(0, 0, 1, 1, "y residuals (mm)","")
2315  label3 = ROOT.TPaveLabel(0, 0, 1, 1, "dx/dz residuals (mrad)","")
2316  label4 = ROOT.TPaveLabel(0, 0, 1, 1, "dy/dz residuals (mrad)","")
2317  label5 = ROOT.TPaveLabel(0, 0, 1, 1, "x position (cm)","")
2318  label6 = ROOT.TPaveLabel(0, 0, 1, 1, "y position (cm)","")
2319  label7 = ROOT.TPaveLabel(0, 0, 1, 1, "dx/dz angle (rad)","")
2320  label8 = ROOT.TPaveLabel(0, 0, 1, 1, "dy/dz angle (rad)","")
2321  label9 = ROOT.TPaveLabel(0, 0.85, 1, 1, getname(r),"NDC")
2322 
2323  for l in label1, label2, label3, label4, label5, label6, label7, label8, label9:
2324  l.SetBorderSize(0)
2325  l.SetFillColor(ROOT.kWhite)
2326 
2327  for l in label1, label2, label3, label4:
2328  l.SetTextAngle(90)
2329  l.SetTextSize(0.09)
2330 
2331  #label9.SetTextAngle(30)
2332  label9.SetTextSize(0.59)
2333 
2334  pads[1].cd(); label1.Draw()
2335  pads[6].cd(); label2.Draw()
2336  pads[11].cd(); label3.Draw()
2337  pads[16].cd(); label4.Draw()
2338  pads[22].cd(); label5.Draw()
2339  pads[23].cd(); label6.Draw()
2340  pads[24].cd(); label7.Draw()
2341  pads[25].cd(); label8.Draw()
2342 
2343  pads[2].SetRightMargin(1e-5)
2344  pads[2].SetBottomMargin(1e-5)
2345  pads[2].SetLeftMargin(0.17)
2346  pads[3].SetLeftMargin(1e-5)
2347  pads[3].SetRightMargin(1e-5)
2348  pads[3].SetBottomMargin(1e-5)
2349  pads[4].SetLeftMargin(1e-5)
2350  pads[4].SetRightMargin(1e-5)
2351  pads[4].SetBottomMargin(1e-5)
2352  pads[5].SetLeftMargin(1e-5)
2353  pads[5].SetBottomMargin(1e-5)
2354 
2355  pads[7].SetRightMargin(1e-5)
2356  pads[7].SetBottomMargin(1e-5)
2357  pads[7].SetTopMargin(1e-5)
2358  pads[7].SetLeftMargin(0.17)
2359  pads[8].SetLeftMargin(1e-5)
2360  pads[8].SetRightMargin(1e-5)
2361  pads[8].SetBottomMargin(1e-5)
2362  pads[8].SetTopMargin(1e-5)
2363  pads[9].SetLeftMargin(1e-5)
2364  pads[9].SetRightMargin(1e-5)
2365  pads[9].SetBottomMargin(1e-5)
2366  pads[9].SetTopMargin(1e-5)
2367  pads[10].SetLeftMargin(1e-5)
2368  pads[10].SetBottomMargin(1e-5)
2369  pads[10].SetTopMargin(1e-5)
2370 
2371  pads[12].SetRightMargin(1e-5)
2372  pads[12].SetBottomMargin(1e-5)
2373  pads[12].SetTopMargin(1e-5)
2374  pads[12].SetLeftMargin(0.17)
2375  pads[13].SetLeftMargin(1e-5)
2376  pads[13].SetRightMargin(1e-5)
2377  pads[13].SetBottomMargin(1e-5)
2378  pads[13].SetTopMargin(1e-5)
2379  pads[14].SetLeftMargin(1e-5)
2380  pads[14].SetRightMargin(1e-5)
2381  pads[14].SetBottomMargin(1e-5)
2382  pads[14].SetTopMargin(1e-5)
2383  pads[15].SetLeftMargin(1e-5)
2384  pads[15].SetBottomMargin(1e-5)
2385  pads[15].SetTopMargin(1e-5)
2386 
2387  pads[17].SetRightMargin(1e-5)
2388  pads[17].SetTopMargin(1e-5)
2389  pads[17].SetLeftMargin(0.17)
2390  pads[18].SetLeftMargin(1e-5)
2391  pads[18].SetRightMargin(1e-5)
2392  pads[18].SetTopMargin(1e-5)
2393  pads[19].SetLeftMargin(1e-5)
2394  pads[19].SetRightMargin(1e-5)
2395  pads[19].SetTopMargin(1e-5)
2396  pads[20].SetLeftMargin(1e-5)
2397  pads[20].SetTopMargin(1e-5)
2398 
2399  chamber_x_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2400  chamber_x_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2401  chamber_x_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2402  chamber_x_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2403  chamber_x_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2404  chamber_x_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2405  chamber_x_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2406  chamber_y_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2407  chamber_y_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2408  chamber_y_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2409  chamber_y_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2410  chamber_y_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2411  chamber_y_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2412  chamber_y_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2413  chamber_dxdz_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2414  chamber_dxdz_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2415  chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2416  chamber_dxdz_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2417  chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2418  chamber_dxdz_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2419  chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2420 
2421  # chamber_dydz_trackx
2422  chamber_dydz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2423  chamber_dydz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2424  chamber_dydz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2425 
2426  pads[2].cd()
2427  chamber_x_trackx.Draw("e1")
2428  if not suppressblue: chamber_x_trackx_fit2.Draw("samel")
2429  chamber_x_trackx_fit.Draw("samel")
2430  #label99 = ROOT.TPaveLabel(0, 0.8, 1, 1, getname(r),"NDC")
2431  print getname(r)
2432  #label99 = ROOT.TPaveLabel(0, 0.8, 1, 1, "aaa","NDC")
2433  label9.Draw()
2434  #pads[2].Modified()
2435 
2436  pads[3].cd()
2437  chamber_x_tracky.Draw("e1")
2438  if not suppressblue: chamber_x_tracky_fit2.Draw("samel")
2439  chamber_x_tracky_fit.Draw("samel")
2440 
2441  pads[4].cd()
2442  chamber_x_trackdxdz.Draw("e1")
2443  if not suppressblue: chamber_x_trackdxdz_fit2.Draw("samel")
2444  chamber_x_trackdxdz_fit.Draw("samel")
2445 
2446  pads[5].cd()
2447  chamber_x_trackdydz.Draw("e1")
2448  if not suppressblue: chamber_x_trackdydz_fit2.Draw("samel")
2449  chamber_x_trackdydz_fit.Draw("samel")
2450 
2451  pads[7].cd()
2452  chamber_y_trackx.Draw("e1")
2453  if not suppressblue: chamber_y_trackx_fit2.Draw("samel")
2454  chamber_y_trackx_fit.Draw("samel")
2455 
2456  pads[8].cd()
2457  chamber_y_tracky.Draw("e1")
2458  if not suppressblue: chamber_y_tracky_fit2.Draw("samel")
2459  chamber_y_tracky_fit.Draw("samel")
2460 
2461  pads[9].cd()
2462  chamber_y_trackdxdz.Draw("e1")
2463  if not suppressblue: chamber_y_trackdxdz_fit2.Draw("samel")
2464  chamber_y_trackdxdz_fit.Draw("samel")
2465 
2466  pads[10].cd()
2467  chamber_y_trackdydz.Draw("e1")
2468  if not suppressblue: chamber_y_trackdydz_fit2.Draw("samel")
2469  chamber_y_trackdydz_fit.Draw("samel")
2470 
2471  pads[12].cd()
2472  chamber_dxdz_trackx.Draw("e1")
2473  if not suppressblue: chamber_dxdz_trackx_fit2.Draw("samel")
2474  chamber_dxdz_trackx_fit.Draw("samel")
2475 
2476  pads[13].cd()
2477  chamber_dxdz_tracky.Draw("e1")
2478  if not suppressblue: chamber_dxdz_tracky_fit2.Draw("samel")
2479  chamber_dxdz_tracky_fit.Draw("samel")
2480 
2481  pads[14].cd()
2482  chamber_dxdz_trackdxdz.Draw("e1")
2483  if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw("samel")
2484  chamber_dxdz_trackdxdz_fit.Draw("samel")
2485 
2486  pads[15].cd()
2487  chamber_dxdz_trackdydz.Draw("e1")
2488  if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw("samel")
2489  chamber_dxdz_trackdydz_fit.Draw("samel")
2490 
2491  pads[17].cd()
2492  chamber_dydz_trackx.Draw("e1")
2493  if not suppressblue: chamber_dydz_trackx_fit2.Draw("samel")
2494  chamber_dydz_trackx_fit.Draw("samel")
2495 
2496  pads[18].cd()
2497  chamber_dydz_tracky.Draw("e1")
2498  if not suppressblue: chamber_dydz_tracky_fit2.Draw("samel")
2499  chamber_dydz_tracky_fit.Draw("samel")
2500 
2501  pads[19].cd()
2502  chamber_dydz_trackdxdz.Draw("e1")
2503  if not suppressblue: chamber_dydz_trackdxdz_fit2.Draw("samel")
2504  chamber_dydz_trackdxdz_fit.Draw("samel")
2505 
2506  pads[20].cd()
2507  chamber_dydz_trackdydz.Draw("e1")
2508  if not suppressblue: chamber_dydz_trackdydz_fit2.Draw("samel")
2509  chamber_dydz_trackdydz_fit.Draw("samel")
2510 
2511  else:
2512  c1.Clear()
2513  #c1.Divide(5, 3, 1e-5, 1e-5)
2514  pads = [None]
2515  pads.append(ROOT.TPad("p1" ,"",0.00,0.55,0.07,1.00,0,0,0))
2516  pads.append(ROOT.TPad("p2" ,"",0.07,0.55,0.34,1.00,0,0,0))
2517  pads.append(ROOT.TPad("p3" ,"",0.34,0.55,0.56,1.00,0,0,0))
2518  pads.append(ROOT.TPad("p4" ,"",0.56,0.55,0.78,1.00,0,0,0))
2519  pads.append(ROOT.TPad("p5" ,"",0.78,0.55,1.00,1.00,0,0,0))
2520  pads.append(ROOT.TPad("p6" ,"",0.00,0.1,0.07,0.55,0,0,0))
2521  pads.append(ROOT.TPad("p7" ,"",0.07,0.1,0.34,0.55,0,0,0))
2522  pads.append(ROOT.TPad("p8" ,"",0.34,0.1,0.56,0.55,0,0,0))
2523  pads.append(ROOT.TPad("p9" ,"",0.56,0.1,0.78,0.55,0,0,0))
2524  pads.append(ROOT.TPad("p10","",0.78,0.1,1.00,0.55,0,0,0))
2525  pads.append(ROOT.TPad("p11","",0.00,0.,0.07,0.1,0,0,0))
2526  pads.append(ROOT.TPad("p12","",0.07,0.,0.34,0.1,0,0,0))
2527  pads.append(ROOT.TPad("p13","",0.34,0.,0.56,0.1,0,0,0))
2528  pads.append(ROOT.TPad("p14","",0.56,0.,0.78,0.1,0,0,0))
2529  pads.append(ROOT.TPad("p15","",0.78,0.,1.00,0.1,0,0,0))
2530  for p in pads:
2531  if not not p:
2532  p.Draw()
2533  ROOT.SetOwnership(p,False)
2534 
2535  label1 = ROOT.TPaveLabel(0, 0, 1, 1, "x residuals (mm)")
2536  label2 = ROOT.TPaveLabel(0, 0, 1, 1, "dx/dz residuals (mrad)")
2537  label3 = ROOT.TPaveLabel(0, 0.3, 1, 1, "x position (cm)")
2538  label4 = ROOT.TPaveLabel(0, 0.3, 1, 1, "y position (cm)")
2539  label5 = ROOT.TPaveLabel(0, 0.3, 1, 1, "dx/dz angle (rad)")
2540  label6 = ROOT.TPaveLabel(0, 0.3, 1, 1, "dy/dz angle (rad)")
2541  label9 = ROOT.TPaveLabel(0, 0.85, 1, 1, getname(r),"NDC")
2542 
2543  if name[0:2] == "ME":
2544  label1 = ROOT.TPaveLabel(0, 0, 1, 1, "r#phi residuals (mm)")
2545  label2 = ROOT.TPaveLabel(0, 0, 1, 1, "d(r#phi)/dz residuals (mrad)")
2546 
2547  for l in label1, label2, label3, label4, label5, label6, label9:
2548  l.SetBorderSize(0)
2549  l.SetFillColor(ROOT.kWhite)
2550 
2551  for l in label1, label2:
2552  l.SetTextAngle(90)
2553  l.SetTextSize(0.09)
2554 
2555  #label9.SetTextAngle(30)
2556  label9.SetTextSize(0.29)
2557 
2558  pads[1].cd(); label1.Draw()
2559  pads[6].cd(); label2.Draw()
2560  pads[12].cd(); label3.Draw()
2561  pads[13].cd(); label4.Draw()
2562  pads[14].cd(); label5.Draw()
2563  pads[15].cd(); label6.Draw()
2564  #pads[11].cd(); label9.Draw()
2565 
2566  pads[2].SetRightMargin(1e-5)
2567  pads[2].SetBottomMargin(1e-5)
2568  pads[3].SetLeftMargin(1e-5)
2569  pads[3].SetRightMargin(1e-5)
2570  pads[3].SetBottomMargin(1e-5)
2571  pads[4].SetLeftMargin(1e-5)
2572  pads[4].SetRightMargin(1e-5)
2573  pads[4].SetBottomMargin(1e-5)
2574  pads[5].SetLeftMargin(1e-5)
2575  pads[5].SetBottomMargin(1e-5)
2576 
2577  pads[7].SetRightMargin(1e-5)
2578  pads[7].SetTopMargin(1e-5)
2579  pads[8].SetLeftMargin(1e-5)
2580  pads[8].SetRightMargin(1e-5)
2581  pads[8].SetTopMargin(1e-5)
2582  pads[9].SetLeftMargin(1e-5)
2583  pads[9].SetRightMargin(1e-5)
2584  pads[9].SetTopMargin(1e-5)
2585  pads[10].SetLeftMargin(1e-5)
2586  pads[10].SetTopMargin(1e-5)
2587 
2588  chamber_x_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2589  chamber_x_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2590  chamber_x_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2591  chamber_x_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2592  chamber_x_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2593  chamber_x_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2594  chamber_x_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2595  # chamber_dxdz_trackx
2596  chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2597  chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2598  chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2599 
2600  pads[2].cd()
2601  chamber_x_trackx.Draw("e1")
2602  if not suppressblue: chamber_x_trackx_fit2.Draw("samel")
2603  chamber_x_trackx_fit.Draw("samel")
2604  label9.Draw()
2605 
2606  pads[3].cd()
2607  chamber_x_tracky.Draw("e1")
2608  if not suppressblue: chamber_x_tracky_fit2.Draw("samel")
2609  chamber_x_tracky_fit.Draw("samel")
2610 
2611  pads[4].cd()
2612  chamber_x_trackdxdz.Draw("e1")
2613  if not suppressblue: chamber_x_trackdxdz_fit2.Draw("samel")
2614  chamber_x_trackdxdz_fit.Draw("samel")
2615 
2616  pads[5].cd()
2617  chamber_x_trackdydz.Draw("e1")
2618  if not suppressblue: chamber_x_trackdydz_fit2.Draw("samel")
2619  chamber_x_trackdydz_fit.Draw("samel")
2620 
2621  pads[7].cd()
2622  chamber_dxdz_trackx.Draw("e1")
2623  if not suppressblue: chamber_dxdz_trackx_fit2.Draw("samel")
2624  chamber_dxdz_trackx_fit.Draw("samel")
2625 
2626  pads[8].cd()
2627  chamber_dxdz_tracky.Draw("e1")
2628  if not suppressblue: chamber_dxdz_tracky_fit2.Draw("samel")
2629  chamber_dxdz_tracky_fit.Draw("samel")
2630 
2631  pads[9].cd()
2632  chamber_dxdz_trackdxdz.Draw("e1")
2633  if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw("samel")
2634  chamber_dxdz_trackdxdz_fit.Draw("samel")
2635 
2636  pads[10].cd()
2637  chamber_dxdz_trackdydz.Draw("e1")
2638  if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw("samel")
2639  chamber_dxdz_trackdydz_fit.Draw("samel")
2640 
2641  tn = time.time()
2642  ddt[8] = 1./ddt[7]*((ddt[7]-1)*ddt[8] + tn-t1)
2643 
2644 ##################################################################################
2645 
2646 def segdiff(tfiles, component, pair, **args):
2647  tdrStyle.SetOptFit(1)
2648  tdrStyle.SetOptTitle(1)
2649  tdrStyle.SetTitleBorderSize(1)
2650  tdrStyle.SetTitleFontSize(0.05)
2651  tdrStyle.SetStatW(0.2)
2652  tdrStyle.SetStatY(0.9)
2653  tdrStyle.SetStatFontSize(0.06)
2654 
2655  if component[0:2] == "dt":
2656  wheel = args["wheel"]
2657  wheelletter = wheelLetter(wheel)
2658  sector = args["sector"]
2659  profname = "%s_%s_%02d_%s" % (component, wheelletter, sector, str(pair))
2660  posname = "pos" + profname
2661  negname = "neg" + profname
2662  #print profname
2663 
2664  station1 = int(str(pair)[0])
2665  station2 = int(str(pair)[1])
2666  phi1 = signConventions["DT", wheel, station1, sector][4]
2667  phi2 = signConventions["DT", wheel, station2, sector][4]
2668  if abs(phi1 - phi2) > 1.:
2669  if phi1 > phi2: phi1 -= 2.*pi
2670  else: phi1 += 2.*pi
2671  phi = (phi1 + phi2) / 2.
2672  while (phi < -pi): phi += 2.*pi
2673  while (phi > pi): phi -= 2.*pi
2674 
2675  elif component[0:3] == "csc":
2676  endcap = args["endcap"]
2677  if endcap=="m":
2678  endcapnum=2
2679  endcapsign="-"
2680  elif endcap=="p":
2681  endcapnum=1
2682  endcapsign="+"
2683  else: raise Exception
2684 
2685  ring = args["ring"]
2686  if ring>2 or ring<1: raise Exception
2687  station1 = int(str(pair)[0])
2688  station2 = int(str(pair)[1])
2689  if ring==1: ringname="inner"
2690  elif ring==2: ringname="outer"
2691  else: raise Exception
2692 
2693  chamber = args["chamber"]
2694  if (ring==1 and chamber>18) or (ring==2 and chamber>36): raise Exception
2695 
2696  profname = "csc%s_%s_%s_%02d_%s" % (ringname,component[4:], endcap, chamber, str(pair))
2697  posname = "pos" + profname
2698  negname = "neg" + profname
2699  #print profname
2700 
2701  station1 = int(str(pair)[0])
2702  station2 = int(str(pair)[1])
2703  phi1 = signConventions["CSC", endcapnum, station1, ring, chamber][4]
2704  phi2 = signConventions["CSC", endcapnum, station1, ring, chamber][4]
2705  if abs(phi1 - phi2) > 1.:
2706  if phi1 > phi2: phi1 -= 2.*pi
2707  else: phi1 += 2.*pi
2708  phi = (phi1 + phi2) / 2.
2709  while (phi < -pi): phi += 2.*pi
2710  while (phi > pi): phi -= 2.*pi
2711 
2712  else: raise Exception
2713 
2714  if "window" in args: window = args["window"]
2715  else: window = 5.
2716 
2717  global tmpprof, tmppos, tmpneg
2718  pdir = "AlignmentMonitorSegmentDifferences/iter1/"
2719  tmpprof = tfiles[0].Get(pdir + profname).Clone()
2720  tmpprof.SetMarkerStyle(8)
2721  tmppos = tfiles[0].Get(pdir + posname).Clone()
2722  tmpneg = tfiles[0].Get(pdir + negname).Clone()
2723  for tfile in tfiles[1:]:
2724  tmpprof.Add(tfile.Get(pdir + profname))
2725  tmppos.Add(tfile.Get(pdir + posname))
2726  tmpneg.Add(tfile.Get(pdir + negname))
2727 
2728  for i in xrange(1, tmpprof.GetNbinsX()+1):
2729  if tmpprof.GetBinError(i) < 1e-5:
2730  tmpprof.SetBinError(i, 100.)
2731  tmpprof.SetAxisRange(-window, window, "Y")
2732 
2733  f = ROOT.TF1("p1", "[0] + [1]*x", tmpprof.GetBinLowEdge(1), -tmpprof.GetBinLowEdge(1))
2734  f.SetParameters((tmppos.GetMean() + tmpneg.GetMean())/2., 0.)
2735 
2736  tmpprof.SetXTitle("q/p_{T} (c/GeV)")
2737  if component == "dt13_resid":
2738  tmpprof.SetYTitle("#Deltax^{local} (mm)")
2739  tmppos.SetXTitle("#Deltax^{local} (mm)")
2740  tmpneg.SetXTitle("#Deltax^{local} (mm)")
2741  f.SetParNames("#Deltax^{local}_{0}", "Slope")
2742  if component == "dt13_slope":
2743  tmpprof.SetYTitle("#Deltadx/dz^{local} (mrad)")
2744  tmppos.SetXTitle("#Deltadx/dz^{local} (mrad)")
2745  tmpneg.SetXTitle("#Deltadx/dz^{local} (mrad)")
2746  f.SetParNames("#Deltadx/dz^{local}_{0}", "Slope")
2747  if component == "dt2_resid":
2748  tmpprof.SetYTitle("#Deltay^{local} (mm)")
2749  tmppos.SetXTitle("#Deltay^{local} (mm)")
2750  tmpneg.SetXTitle("#Deltay^{local} (mm)")
2751  f.SetParNames("#Deltay^{local}_{0}", "Slope")
2752  if component == "dt2_slope":
2753  tmpprof.SetYTitle("#Deltady/dz^{local} (mrad)")
2754  tmppos.SetXTitle("#Deltady/dz^{local} (mrad)")
2755  tmpneg.SetXTitle("#Deltady/dz^{local} (mrad)")
2756  f.SetParNames("#Deltady/dz^{local}_{0}", "Slope")
2757  if component == "csc_resid":
2758  tmpprof.SetYTitle("#Delta(r#phi)^{local} (mm)")
2759  tmppos.SetXTitle("#Delta(r#phi)^{local} (mm)")
2760  tmpneg.SetXTitle("#Delta(r#phi)^{local} (mm)")
2761  f.SetParNames("#Delta(r#phi)^{local}_{0}", "Slope")
2762  if component == "csc_slope":
2763  tmpprof.SetYTitle("#Deltad(r#phi)/dz^{local} (mrad)")
2764  tmppos.SetXTitle("#Deltad(r#phi)/dz^{local} (mrad)")
2765  tmpneg.SetXTitle("#Deltad(r#phi)/dz^{local} (mrad)")
2766  f.SetParNames("#Deltad(r#phi)/dz^{local}_{0}", "Slope")
2767 
2768  tmpprof.GetXaxis().CenterTitle()
2769  tmpprof.GetYaxis().CenterTitle()
2770  tmppos.GetXaxis().CenterTitle()
2771  tmpneg.GetXaxis().CenterTitle()
2772  if component[0:2] == "dt":
2773  tmpprof.SetTitle("MB%d - MB%d, wheel %d, sector %02d" % (station1, station2, int(wheel), int(sector)))
2774  elif component[0:3] == "csc":
2775  tmpprof.SetTitle("ME%d - ME%d, for ME%s%d/%d/%d" % (station1, station2, endcapsign, station2, ring, chamber))
2776  else: raise Exception
2777 
2778  tmppos.SetTitle("Positive muons")
2779  tmpneg.SetTitle("Negative muons")
2780 
2781  c1.Clear()
2782  c1.Divide(2, 1)
2783  c1.GetPad(1).cd()
2784  fit1 = tmpprof.Fit("p1", "q")
2785  tmpprof.Draw("e1")
2786  c1.GetPad(2).cd()
2787  c1.GetPad(2).Divide(1, 2)
2788  c1.GetPad(2).GetPad(1).cd()
2789  tmppos.Draw()
2790  f = ROOT.TF1("gausR", "[0]*exp(-(x - [1])**2 / 2. / [2]**2) / sqrt(2.*3.1415926) / [2]",
2791  tmppos.GetMean() - tmppos.GetRMS(), tmppos.GetMean() + tmppos.GetRMS())
2792  f.SetParameters(tmppos.GetEntries() * ((10. - -10.)/100.), tmppos.GetMean(), tmppos.GetRMS())
2793  f.SetParNames("Constant", "Mean", "Sigma")
2794  fit2 = tmppos.Fit("gausR", "qR")
2795  c1.GetPad(2).GetPad(2).cd()
2796  tmpneg.Draw()
2797  f = ROOT.TF1("gausR", "[0]*exp(-(x - [1])**2 / 2. / [2]**2) / sqrt(2.*3.1415926) / [2]",
2798  tmpneg.GetMean() - tmpneg.GetRMS(), tmpneg.GetMean() + tmpneg.GetRMS())
2799  f.SetParameters(tmpneg.GetEntries() * ((10. - -10.)/100.), tmpneg.GetMean(), tmpneg.GetRMS())
2800  f.SetParNames("Constant", "Mean", "Sigma")
2801  fit3 = tmpneg.Fit("gausR", "qR")
2802 
2803  fitresult1 = None, None
2804  if fit1 == 0:
2805  fitresult1 = tmpprof.GetFunction("p1").GetParameter(0), tmpprof.GetFunction("p1").GetParError(0)
2806  fitresult2 = None, None
2807  if fit2 == 0 and fit3 == 0:
2808  fitresult2 = (tmppos.GetFunction("gausR").GetParameter(1) + tmpneg.GetFunction("gausR").GetParameter(1)) / 2., \
2809  sqrt(tmppos.GetFunction("gausR").GetParError(1)**2 + tmpneg.GetFunction("gausR").GetParError(1)**2) / 2.
2810  return phi, fitresult1[0], fitresult1[1], fitresult2[0], fitresult2[1], fit1, fit2, fit3
2811 
2812 def segdiffvsphi(tfiles, reports, component, wheel, window=5., excludesectors=()):
2813  tdrStyle.SetOptTitle(1)
2814  tdrStyle.SetTitleBorderSize(1)
2815  tdrStyle.SetTitleFontSize(0.05)
2816 
2817  global htemp, gtemp_12, gtemp2_12, gtemp_23, gtemp2_23, gtemp_34, gtemp2_34, tlegend
2818  htemp = ROOT.TH1F("htemp", "", 1, -pi, pi)
2819  gtemp_12_phi, gtemp_12_val, gtemp_12_err, gtemp_12_val2, gtemp_12_err2 = [], [], [], [], []
2820  gtemp_23_phi, gtemp_23_val, gtemp_23_err, gtemp_23_val2, gtemp_23_err2 = [], [], [], [], []
2821  gtemp_34_phi, gtemp_34_val, gtemp_34_err, gtemp_34_val2, gtemp_34_err2 = [], [], [], [], []
2822  for sector in xrange(1, 12+1):
2823  #print sector
2824  r1_found, r2_found, r3_found, r4_found = False, False, False, False
2825  for r1 in reports:
2826  if r1.postal_address == ("DT", wheel, 1, sector):
2827  r1_found = True
2828  break
2829  for r2 in reports:
2830  if r2.postal_address == ("DT", wheel, 2, sector):
2831  r2_found = True
2832  break
2833  for r3 in reports:
2834  if r3.postal_address == ("DT", wheel, 3, sector):
2835  r3_found = True
2836  break
2837  for r4 in reports:
2838  if r4.postal_address == ("DT", wheel, 4, sector):
2839  r4_found = True
2840  break
2841  #print "rfounds: ", r1_found, r2_found, r3_found, r4_found
2842 
2843  if sector not in excludesectors:
2844  if r1_found and r2_found and r1.status == "PASS" and r2.status == "PASS":
2845  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, 12, wheel=wheel, sector=sector)
2846  #print "segdif 12", phi, val, err, val2, err2, fit1, fit2, fit3
2847  if fit1 == 0 and fit2 == 0 and fit3 == 0:
2848  #if fit1 == 0 and fit2 == 0:
2849  gtemp_12_phi.append(phi)
2850  gtemp_12_val.append(val)
2851  gtemp_12_err.append(err)
2852  gtemp_12_val2.append(val2)
2853  gtemp_12_err2.append(err2)
2854  if r2_found and r3_found and r2.status == "PASS" and r3.status == "PASS":
2855  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, 23, wheel=wheel, sector=sector)
2856  #print "segdif 23", phi, val, err, val2, err2, fit1, fit2, fit3
2857  if fit1 == 0 and fit2 == 0 and fit3 == 0:
2858  #if fit1 == 0 and fit2 == 0:
2859  gtemp_23_phi.append(phi)
2860  gtemp_23_val.append(val)
2861  gtemp_23_err.append(err)
2862  gtemp_23_val2.append(val2)
2863  gtemp_23_err2.append(err2)
2864  if component[:4] == "dt13":
2865  if r3_found and r4_found and r3.status == "PASS" and r4.status == "PASS":
2866  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, 34, wheel=wheel, sector=sector)
2867  #print "segdif 34", phi, val, err, val2, err2, fit1, fit2, fit3
2868  if fit1 == 0 and fit2 == 0 and fit3 == 0:
2869  #if fit1 == 0 and fit2 == 0:
2870  gtemp_34_phi.append(phi)
2871  gtemp_34_val.append(val)
2872  gtemp_34_err.append(err)
2873  gtemp_34_val2.append(val2)
2874  gtemp_34_err2.append(err2)
2875 
2876  #print "len(gtemp_12_phi) ", len(gtemp_12_phi)
2877  #print "len(gtemp_23_phi) ",len(gtemp_23_phi)
2878  #print "len(gtemp_34_phi) ",len(gtemp_34_phi)
2879  if len(gtemp_12_phi) > 0:
2880  gtemp_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array("d", gtemp_12_phi), array.array("d", gtemp_12_val),
2881  array.array("d", [0.] * len(gtemp_12_phi)), array.array("d", gtemp_12_err))
2882  gtemp2_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array("d", gtemp_12_phi), array.array("d", gtemp_12_val2),
2883  array.array("d", [0.] * len(gtemp_12_phi)), array.array("d", gtemp_12_err2))
2884  if len(gtemp_23_phi) > 0:
2885  gtemp_23 = ROOT.TGraphErrors(len(gtemp_23_phi), array.array("d", gtemp_23_phi), array.array("d", gtemp_23_val),
2886  array.array("d", [0.] * len(gtemp_23_phi)), array.array("d", gtemp_23_err))
2887  gtemp2_23 = ROOT.TGraphErrors(len(gtemp_23_phi), array.array("d", gtemp_23_phi), array.array("d", gtemp_23_val2),
2888  array.array("d", [0.] * len(gtemp_23_phi)), array.array("d", gtemp_23_err2))
2889  if len(gtemp_34_phi) > 0:
2890  gtemp_34 = ROOT.TGraphErrors(len(gtemp_34_phi), array.array("d", gtemp_34_phi), array.array("d", gtemp_34_val),
2891  array.array("d", [0.] * len(gtemp_34_phi)), array.array("d", gtemp_34_err))
2892  gtemp2_34 = ROOT.TGraphErrors(len(gtemp_34_phi), array.array("d", gtemp_34_phi), array.array("d", gtemp_34_val2),
2893  array.array("d", [0.] * len(gtemp_34_phi)), array.array("d", gtemp_34_err2))
2894 
2895  if len(gtemp_12_phi) > 0:
2896  gtemp_12.SetMarkerStyle(20); gtemp_12.SetMarkerSize(1.);
2897  gtemp_12.SetMarkerColor(ROOT.kBlue); gtemp_12.SetLineColor(ROOT.kBlue)
2898  gtemp2_12.SetMarkerStyle(24); gtemp2_12.SetMarkerSize(1.);
2899  gtemp2_12.SetMarkerColor(ROOT.kBlue); gtemp2_12.SetLineColor(ROOT.kBlue)
2900  if len(gtemp_23_phi) > 0:
2901  gtemp_23.SetMarkerStyle(21); gtemp_23.SetMarkerSize(1.);
2902  gtemp_23.SetMarkerColor(ROOT.kRed); gtemp_23.SetLineColor(ROOT.kRed)
2903  gtemp2_23.SetMarkerStyle(25); gtemp2_23.SetMarkerSize(1.);
2904  gtemp2_23.SetMarkerColor(ROOT.kRed); gtemp2_23.SetLineColor(ROOT.kRed)
2905  if len(gtemp_34_phi) > 0 and component[:4] == "dt13":
2906  gtemp_34.SetMarkerStyle(22); gtemp_34.SetMarkerSize(1.25);
2907  gtemp_34.SetMarkerColor(ROOT.kGreen+2); gtemp_34.SetLineColor(ROOT.kGreen+2)
2908  gtemp2_34.SetMarkerStyle(26); gtemp2_34.SetMarkerSize(1.25);
2909  gtemp2_34.SetMarkerColor(ROOT.kGreen+2); gtemp2_34.SetLineColor(ROOT.kGreen+2)
2910 
2911  if wheel == 0: htemp.SetTitle("Wheel %d" % wheel)
2912  else: htemp.SetTitle("Wheel %+d" % wheel)
2913  htemp.SetAxisRange(-window, window, "Y")
2914  htemp.SetXTitle("Average #phi of pair (rad)")
2915  if component == "dt13_resid": htemp.SetYTitle("#Deltax^{local} (mm)")
2916  if component == "dt13_slope": htemp.SetYTitle("#Deltadx/dz^{local} (mrad)")
2917  if component == "dt2_resid": htemp.SetYTitle("#Deltay^{local} (mm)")
2918  if component == "dt2_slope": htemp.SetYTitle("#Deltady/dz^{local} (mrad)")
2919  htemp.GetXaxis().CenterTitle()
2920  htemp.GetYaxis().CenterTitle()
2921  htemp.GetYaxis().SetTitleOffset(0.75)
2922 
2923  c1.Clear()
2924  htemp.Draw()
2925  if len(gtemp_12_phi) > 0:
2926  gtemp_12.Draw("p")
2927  gtemp2_12.Draw("p")
2928  if len(gtemp_23_phi) > 0:
2929  gtemp_23.Draw("p")
2930  gtemp2_23.Draw("p")
2931  if len(gtemp_34_phi) > 0:
2932  gtemp_34.Draw("p")
2933  gtemp2_34.Draw("p")
2934 
2935  tlegend = ROOT.TLegend(0.5, 0.72, 0.9, 0.92)
2936  tlegend.SetBorderSize(0)
2937  tlegend.SetFillColor(ROOT.kWhite)
2938  if len(gtemp_12_phi) > 0:
2939  tlegend.AddEntry(gtemp_12, "MB1 - MB2 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_12_val), stdev(gtemp_12_val)), "pl")
2940  if len(gtemp_23_phi) > 0:
2941  tlegend.AddEntry(gtemp_23, "MB2 - MB3 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_23_val), stdev(gtemp_23_val)), "pl")
2942  if len(gtemp_34_phi) > 0:
2943  tlegend.AddEntry(gtemp_34, "MB3 - MB4 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_34_val), stdev(gtemp_34_val)), "pl")
2944  if len(gtemp_12_phi) > 0:
2945  tlegend.AddEntry(gtemp_12, "total mean: %4.2f, total RMS: %4.2f" % \
2946  (mean(gtemp_12_val + gtemp_23_val + gtemp_34_val),
2947  stdev(gtemp_12_val + gtemp_23_val + gtemp_34_val)), "")
2948  tlegend.Draw()
2949 
2950 
def availableCellsCSC
Definition: plotscripts.py:903
def DBdiffVersus
Definition: plotscripts.py:663
def setTDRStyle
Definition: plotscripts.py:84
def wheelm2only
Convenience functions.
Definition: plotscripts.py:28
def curvatureDTsummary
def writeDQMReport
#define abs(x)
Definition: mlp_lapack.h:159
def wheelp2only
Definition: plotscripts.py:32
def wheelLetter
Definition: plotscripts.py:34
dictionary map
Definition: Association.py:160
def idToPostalAddress
Definition: plotscripts.py:804
def availableCellsDT
Definition: plotscripts.py:862
def wheel0only
Definition: plotscripts.py:30
const T & max(const T &a, const T &b)
T sqrt(T t)
Definition: SSEVec.h:28
def saveTestResultsMap
def addToTestResults
Definition: plotscripts.py:959
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def doTestsForMapPlots
def wheelm1only
Definition: plotscripts.py:29
def postalAddressToId
Definition: plotscripts.py:827
def testZeroWithin5Sigma
Definition: plotscripts.py:972
def loadTestResultsMap
def stationIndex
Definition: plotscripts.py:386
def wheelp1only
Definition: plotscripts.py:31
def wheelNumber
Definition: plotscripts.py:42
def doTestsForReport
def testDeltaWithin5Sigma
Definition: plotscripts.py:979