CMS 3D CMS Logo

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 # sign conventions and some dimensions
13 from signConventions import *
14 
15 # common muon types structures
16 from mutypes import *
17 
18 CPP_LOADED = False
19 
20 # containers for test results for map plots
21 MAP_RESULTS_SAWTOOTH = {}
22 MAP_RESULTS_FITSIN = {}
23 MAP_RESULTS_BINS = {}
24 
25 # general container for all test results
26 TEST_RESULTS = {}
27 
28 #############################################################
29 # Convenience functions
30 
31 def wheelm2only(dt, wheel, station, sector): return dt == "DT" and wheel == -2
32 def wheelm1only(dt, wheel, station, sector): return dt == "DT" and wheel == -1
33 def wheel0only(dt, wheel, station, sector): return dt == "DT" and wheel == 0
34 def wheelp1only(dt, wheel, station, sector): return dt == "DT" and wheel == 1
35 def wheelp2only(dt, wheel, station, sector): return dt == "DT" and wheel == 2
36 
37 def wheelLetter(wheel):
38  if wheel == -2: return "A"
39  elif wheel == -1: return "B"
40  elif wheel == 0: return "C"
41  elif wheel == +1: return "D"
42  elif wheel == +2: return "E"
43  else: raise Exception
44 
45 def wheelNumber(wheell):
46  if wheell == "A": return -2
47  elif wheell == "B": return -1
48  elif wheell == "C": return 0
49  elif wheell == "D": return 1
50  elif wheell == "E": return 2
51  else: raise Exception
52 
53 def mean(xlist):
54  s, n = 0., 0.
55  for x in xlist:
56  s += x
57  n += 1.
58  return s/n
59 
60 def rms(xlist):
61  s2, n = 0., 0.
62  for x in xlist:
63  s2 += x**2
64  n += 1.
65  return sqrt(s2/n)
66 
67 def stdev(xlist):
68  s, s2, n = 0., 0., 0.
69  for x in xlist:
70  s += x
71  s2 += x**2
72  n += 1.
73  return sqrt(s2/n - (s/n)**2)
74 
75 def wmean(xlist):
76  s, w = 0., 0.
77  for x, e in xlist:
78  if e > 0.:
79  wi = 1./e**2
80  s += x*wi
81  w += wi
82  return s/w, sqrt(1./w)
83 
84 #############################################################
85 
86 tdrStyle = None
88  global tdrStyle
89  tdrStyle = ROOT.TStyle("tdrStyle","Style for P-TDR")
90 # For the canvas:
91  tdrStyle.SetCanvasBorderMode(0)
92  tdrStyle.SetCanvasColor(ROOT.kWhite)
93  tdrStyle.SetCanvasDefH(600) #Height of canvas
94  tdrStyle.SetCanvasDefW(600) #Width of canvas
95  tdrStyle.SetCanvasDefX(0) #POsition on screen
96  tdrStyle.SetCanvasDefY(0)
97 
98 # For the Pad:
99  tdrStyle.SetPadBorderMode(0)
100  # tdrStyle.SetPadBorderSize(Width_t size = 1)
101  tdrStyle.SetPadColor(ROOT.kWhite)
102  tdrStyle.SetPadGridX(False)
103  tdrStyle.SetPadGridY(False)
104  tdrStyle.SetGridColor(0)
105  tdrStyle.SetGridStyle(3)
106  tdrStyle.SetGridWidth(1)
107 
108 # For the frame:
109  tdrStyle.SetFrameBorderMode(0)
110  tdrStyle.SetFrameBorderSize(1)
111  tdrStyle.SetFrameFillColor(0)
112  tdrStyle.SetFrameFillStyle(0)
113  tdrStyle.SetFrameLineColor(1)
114  tdrStyle.SetFrameLineStyle(1)
115  tdrStyle.SetFrameLineWidth(1)
116 
117 # For the histo:
118  # tdrStyle.SetHistFillColor(1)
119  # tdrStyle.SetHistFillStyle(0)
120  tdrStyle.SetHistLineColor(1)
121  tdrStyle.SetHistLineStyle(0)
122  tdrStyle.SetHistLineWidth(1)
123  # tdrStyle.SetLegoInnerR(Float_t rad = 0.5)
124  # tdrStyle.SetNumberContours(Int_t number = 20)
125 
126  tdrStyle.SetEndErrorSize(2)
127 # tdrStyle.SetErrorMarker(20)
128  tdrStyle.SetErrorX(0.)
129 
130  tdrStyle.SetMarkerStyle(20)
131 
132 #For the fit/function:
133  tdrStyle.SetOptFit(1)
134  tdrStyle.SetFitFormat("5.4g")
135  tdrStyle.SetFuncColor(2)
136  tdrStyle.SetFuncStyle(1)
137  tdrStyle.SetFuncWidth(1)
138 
139 #For the date:
140  tdrStyle.SetOptDate(0)
141  # tdrStyle.SetDateX(Float_t x = 0.01)
142  # tdrStyle.SetDateY(Float_t y = 0.01)
143 
144 # For the statistics box:
145  tdrStyle.SetOptFile(0)
146  tdrStyle.SetOptStat(0) # To display the mean and RMS: SetOptStat("mr")
147  tdrStyle.SetStatColor(ROOT.kWhite)
148  tdrStyle.SetStatFont(42)
149  tdrStyle.SetStatFontSize(0.025)
150  tdrStyle.SetStatTextColor(1)
151  tdrStyle.SetStatFormat("6.4g")
152  tdrStyle.SetStatBorderSize(1)
153  tdrStyle.SetStatH(0.1)
154  tdrStyle.SetStatW(0.15)
155  # tdrStyle.SetStatStyle(Style_t style = 1001)
156  # tdrStyle.SetStatX(Float_t x = 0)
157  # tdrStyle.SetStatY(Float_t y = 0)
158 
159 # Margins:
160  tdrStyle.SetPadTopMargin(0.05)
161  tdrStyle.SetPadBottomMargin(0.13)
162  tdrStyle.SetPadLeftMargin(0.13)
163  tdrStyle.SetPadRightMargin(0.05)
164 
165 # For the Global title:
166  tdrStyle.SetOptTitle(0)
167  tdrStyle.SetTitleFont(42)
168  tdrStyle.SetTitleColor(1)
169  tdrStyle.SetTitleTextColor(1)
170  tdrStyle.SetTitleFillColor(10)
171  tdrStyle.SetTitleFontSize(0.05)
172  # tdrStyle.SetTitleH(0) # Set the height of the title box
173  # tdrStyle.SetTitleW(0) # Set the width of the title box
174  # tdrStyle.SetTitleX(0) # Set the position of the title box
175  # tdrStyle.SetTitleY(0.985) # Set the position of the title box
176  # tdrStyle.SetTitleStyle(Style_t style = 1001)
177  # tdrStyle.SetTitleBorderSize(2)
178 
179 # For the axis titles:
180  tdrStyle.SetTitleColor(1, "XYZ")
181  tdrStyle.SetTitleFont(42, "XYZ")
182  tdrStyle.SetTitleSize(0.06, "XYZ")
183  # tdrStyle.SetTitleXSize(Float_t size = 0.02) # Another way to set the size?
184  # tdrStyle.SetTitleYSize(Float_t size = 0.02)
185  tdrStyle.SetTitleXOffset(0.9)
186  tdrStyle.SetTitleYOffset(1.05)
187  # tdrStyle.SetTitleOffset(1.1, "Y") # Another way to set the Offset
188 
189 # For the axis labels:
190  tdrStyle.SetLabelColor(1, "XYZ")
191  tdrStyle.SetLabelFont(42, "XYZ")
192  tdrStyle.SetLabelOffset(0.007, "XYZ")
193  tdrStyle.SetLabelSize(0.05, "XYZ")
194 
195 # For the axis:
196  tdrStyle.SetAxisColor(1, "XYZ")
197  tdrStyle.SetStripDecimals(True)
198  tdrStyle.SetTickLength(0.03, "XYZ")
199  tdrStyle.SetNdivisions(510, "XYZ")
200  tdrStyle.SetPadTickX(1) # To get tick marks on the opposite side of the frame
201  tdrStyle.SetPadTickY(1)
202 
203 # Change for log plots:
204  tdrStyle.SetOptLogx(0)
205  tdrStyle.SetOptLogy(0)
206  tdrStyle.SetOptLogz(0)
207 
208 # Postscript options:
209  tdrStyle.SetPaperSize(20.,20.)
210  # tdrStyle.SetLineScalePS(Float_t scale = 3)
211  # tdrStyle.SetLineStyleString(Int_t i, const char* text)
212  # tdrStyle.SetHeaderPS(const char* header)
213  # tdrStyle.SetTitlePS(const char* pstitle)
214 
215  # tdrStyle.SetBarOffset(Float_t baroff = 0.5)
216  # tdrStyle.SetBarWidth(Float_t barwidth = 0.5)
217  # tdrStyle.SetPaintTextFormat(const char* format = "g")
218  # tdrStyle.SetPalette(Int_t ncolors = 0, Int_t* colors = 0)
219  # tdrStyle.SetTimeOffset(Double_t toffset)
220  # tdrStyle.SetHistMinimumZero(True)
221 
222  tdrStyle.cd()
223 
224 setTDRStyle()
225 
226 def set_palette(name=None, ncontours=999):
227  """Set a color palette from a given RGB list
228  stops, red, green and blue should all be lists of the same length
229  see set_decent_colors for an example"""
230 
231  if name == "halfgray":
232  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
233  red = map(lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
234  green = map(lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
235  blue = map(lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
236  elif name == "gray":
237  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
238  red = [1.00, 0.84, 0.61, 0.34, 0.00]
239  green = [1.00, 0.84, 0.61, 0.34, 0.00]
240  blue = [1.00, 0.84, 0.61, 0.34, 0.00]
241  elif name == "blues":
242  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
243  red = [1.00, 0.84, 0.61, 0.34, 0.00]
244  green = [1.00, 0.84, 0.61, 0.34, 0.00]
245  blue = [1.00, 1.00, 1.00, 1.00, 1.00]
246  elif name == "reds":
247  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
248  red = [1.00, 1.00, 1.00, 1.00, 1.00]
249  green = [1.00, 0.84, 0.61, 0.34, 0.00]
250  blue = [1.00, 0.84, 0.61, 0.34, 0.00]
251  elif name == "antigray":
252  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
253  red = [1.00, 0.84, 0.61, 0.34, 0.00]
254  green = [1.00, 0.84, 0.61, 0.34, 0.00]
255  blue = [1.00, 0.84, 0.61, 0.34, 0.00]
256  red.reverse()
257  green.reverse()
258  blue.reverse()
259  elif name == "fire":
260  stops = [0.00, 0.20, 0.80, 1.00]
261  red = [1.00, 1.00, 1.00, 0.50]
262  green = [1.00, 1.00, 0.00, 0.00]
263  blue = [0.20, 0.00, 0.00, 0.00]
264  elif name == "antifire":
265  stops = [0.00, 0.20, 0.80, 1.00]
266  red = [0.50, 1.00, 1.00, 1.00]
267  green = [0.00, 0.00, 1.00, 1.00]
268  blue = [0.00, 0.00, 0.00, 0.20]
269  else:
270  # default palette, looks cool
271  stops = [0.00, 0.34, 0.61, 0.84, 1.00]
272  red = [0.00, 0.00, 0.87, 1.00, 0.51]
273  green = [0.00, 0.81, 1.00, 0.20, 0.00]
274  blue = [0.51, 1.00, 0.12, 0.00, 0.00]
275 
276  s = array.array('d', stops)
277  r = array.array('d', red)
278  g = array.array('d', green)
279  b = array.array('d', blue)
280 
281  npoints = len(s)
282  ROOT.TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
283  ROOT.gStyle.SetNumberContours(ncontours)
284 
285 set_palette()
286 
287 ######################################################################################################
288 ## sector phi edges in: me11 me12 me13 me14 me21 me22 me31 me32 me41 me42 mb1 mb2 mb3 mb4
289 ## index: 0 1 2 3 4 5 6 7 8 9 10 11 12 13
290 
291 #phiedgesCSC36 = [pi/180.*(-175. + 10.*i) for i in range(36)]
292 #phiedgesCSC18 = [pi/180.*(-175. + 20.*i) for i in range(18)]
293 phiedgesCSC36 = [pi/180.*(-5. + 10.*i) for i in range(36)]
294 phiedgesCSC18 = [pi/180.*(-5. + 20.*i) for i in range(18)]
295 phiedges = [
296  phiedgesCSC36,
297  phiedgesCSC36,
298  phiedgesCSC36,
299  phiedgesCSC36,
300  phiedgesCSC18,
301  phiedgesCSC36,
302  phiedgesCSC18,
303  phiedgesCSC36,
304  phiedgesCSC18,
305  phiedgesCSC36,
306  [0.35228048120123945, 0.87587781482541827, 1.3994776462193192, 1.923076807996136, 2.4466741416203148, 2.970273973014216,
307  -2.7893121723885534, -2.2657148387643748, -1.7421150073704739, -1.2185158455936571, -0.69491851196947851, -0.17131868057557731],
308  [0.22000706229660855, 0.74360690430428489, 1.267204926935573, 1.7908033890915052, 2.3144032310991816, 2.8380012537304697,
309  -2.9215855912931841, -2.3979857492855081, -1.8743877266542202, -1.3507892644982882, -0.82718942249061178, -0.30359139985932365],
310  [0.29751957124275596, 0.82111826253905784, 1.3447162969496083, 1.8683158980376524, 2.3919145893339548, 2.915512623744505,
311  -2.844073082347037, -2.3204743910507353, -1.7968763566401849, -1.2732767555521407, -0.74967806425583894, -0.22608002984528835],
312  [3.0136655290752188, -2.7530905195097337, -2.2922883025568734, -1.9222915077192773, -1.5707963267948966, -1.2193011458705159,
313  -0.84930435103291968, -0.38850213408005951, 0.127927124514574, 0.65152597487624719, 1.1322596819239259, 1.5707963267948966,
314  2.0093329716658674, 2.4900666787135459]]
315 
317  lines = []
318  for ed in phiedges[:]:
319  ed.sort()
320  #print ed
321  ed.extend([999 for n in range(0,37-len(ed))])
322  lines.append('{' + ', '.join(map(str, ed)) + '}')
323  #print lines
324  res = ', '.join(lines)
325  ff = open("phiedges_export.h",mode="w")
326  print>>ff,'double phiedges[14][37] = {' + res + '};'
327  ff.close()
328 
330  def __init__(self, name):
331  self.name = name
332  self.edges = (phiedges[stationIndex(name)])[:]
333  self.ed = sorted(self.edges)
334  # add some padding to the end
335  self.ed.append(pi+1.)
336  self.n = len(self.edges)
337  def __call__(self, xx, par):
338  # wrap x in the most negative phi sector into positive phi
339  x = xx[0]
340  if x < self.ed[0]: x += 2*pi
341  # locate sector
342  for i in range(0,self.n):
343  if x <= self.ed[i]: continue
344  if x > self.ed[i+1]: continue
345  return par[i*2] + par[i*2+1]*(x - self.ed[i])
346  return 0
347  def pp(self):
348  print self.name, self.n
349  print self.edges
350  print self.ed
351 
352 
353 def stationIndex(name):
354  if ("MB" in name or "ME" in name):
355  # assume the name is ID
356  pa = idToPostalAddress(name)
357  if pa is None: return None
358  if pa[0]=="CSC":
359  if pa[2]==1 and pa[3]==1: return 0
360  if pa[2]==1 and pa[3]==2: return 1
361  if pa[2]==1 and pa[3]==3: return 2
362  if pa[2]==1 and pa[3]==4: return 3
363  if pa[2]==2 and pa[3]==1: return 4
364  if pa[2]==2 and pa[3]==2: return 5
365  if pa[2]==3 and pa[3]==1: return 6
366  if pa[2]==3 and pa[3]==2: return 7
367  if pa[2]==4 and pa[3]==1: return 8
368  if pa[2]==4 and pa[3]==2: return 9
369  if pa[0]=="DT":
370  if pa[2]==1: return 10
371  if pa[2]==2: return 11
372  if pa[2]==3: return 12
373  if pa[2]==4: return 13
374  else:
375  if ("mem11" in name or "mep11" in name): return 0
376  if ("mem12" in name or "mep12" in name): return 1
377  if ("mem13" in name or "mep13" in name): return 2
378  if ("mem14" in name or "mep14" in name): return 3
379  if ("mem21" in name or "mep21" in name): return 4
380  if ("mem22" in name or "mep22" in name): return 5
381  if ("mem31" in name or "mep31" in name): return 6
382  if ("mem32" in name or "mep32" in name): return 7
383  if ("mem41" in name or "mep41" in name): return 8
384  if ("mem42" in name or "mep42" in name): return 9
385  if ("st1" in name): return 10
386  if ("st2" in name): return 11
387  if ("st3" in name): return 12
388  if ("st4" in name): return 13
389 
390 
391 
392 def philines(name, window, abscissa):
393  global philine_tlines, philine_labels
394  philine_tlines = []
395  edges = phiedges[stationIndex(name)]
396  #print name, len(edges)
397  for phi in edges:
398  if abscissa is None or abscissa[0] < phi < abscissa[1]:
399  philine_tlines.append(ROOT.TLine(phi, -window, phi, window))
400  philine_tlines[-1].SetLineStyle(2)
401  philine_tlines[-1].Draw()
402  if "st" in name: # DT labels
403  philine_labels = []
404  edges = sorted(edges[:])
405  if "st4" in name:
406  labels = [" 7", " 8", " 9", "14", "10", "11", "12", " 1", " 2", " 3", "13", " 4", " 5", " 6"]
407  else:
408  labels = [" 8", " 9", "10", "11", "12", " 1", " 2", " 3", " 4", " 5", " 6"]
409  edges = edges[1:]
410  for phi, label in zip(edges, labels):
411  littlebit = 0.
412  if label in (" 7", " 9", "14", "10", "11"): littlebit = 0.05
413  philine_labels.append(ROOT.TText(phi-0.35+littlebit, -0.9*window, label))
414  philine_labels[-1].Draw()
415  philine_labels.append(ROOT.TText(-2.9, -0.75*window, "Sector:"))
416  philine_labels[-1].Draw()
417  if "CSC" in name: # DT labels
418  philine_labels = []
419  edges = sorted(edges[:])
420  labels = [" 1", " 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
421  "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36"]
422  #else:
423  # labels = [" 8", " 9", "10", "11", "12", " 1", " 2", " 3", " 4", " 5", " 6"]
424  # edges = edges[1:]
425  for phi, label in zip(edges, labels):
426  littlebit = 0.
427  #if label in (" 7", " 9", "14", "10", "11"): littlebit = 0.05
428  philine_labels.append(ROOT.TText(phi+littlebit, -0.9*window, label))
429  philine_labels[-1].SetTextFont(42)
430  philine_labels[-1].SetTextSize(0.028)
431  philine_labels[-1].Draw()
432  philine_labels.append(ROOT.TText(0, -0.78*window, "Chamber:"))
433  philine_labels[-1].SetTextSize(0.035)
434  philine_labels[-1].Draw()
435 
436 def zlines(window, abscissa):
437  global zline_tlines
438  zline_tlines = []
439  for z in -401.625, -133.875, 133.875, 401.625:
440  if abscissa is None or abscissa[0] < z < abscissa[1]:
441  zline_tlines.append(ROOT.TLine(z, -window, z, window))
442  zline_tlines[-1].SetLineStyle(2)
443  zline_tlines[-1].Draw()
444  zline_labels = []
445  zline_labels.append(ROOT.TText(-550, -0.9*window, "-2"))
446  zline_labels.append(ROOT.TText(-300, -0.9*window, "-1"))
447  zline_labels.append(ROOT.TText(-10, -0.9*window, "0"))
448  zline_labels.append(ROOT.TText(250, -0.9*window, "+1"))
449  zline_labels.append(ROOT.TText(500, -0.9*window, "+2"))
450  for z in zline_labels: z.Draw()
451  zline_labels.append(ROOT.TText(-600, -0.75*window, "Wheel:")); zline_labels[-1].Draw()
452 
453 def rlines(disk, window, abscissa):
454  global rline_tlines
455  rline_tlines = []
456  if disk == 1: rl = [150., 270., 480.]
457  else: rl = [350.]
458  for r in rl:
459  if abscissa is None or abscissa[0] < r < abscissa[1]:
460  rline_tlines.append(ROOT.TLine(r, -window, r, window))
461  rline_tlines[-1].SetLineStyle(2)
462  rline_tlines[-1].Draw()
463 
464 ######################################################################################################
465 
466 def getReportByPostalAddress(postal_address, report):
467  for r in report:
468  if postal_address == r.postal_address:
469  return r
470  return None
471 
472 
473 ######################################################################################################
474 
475 def DBMC(database, reports, window=10., windows=None, selection=None, phi=False,
476  color=ROOT.kBlue-8, style=1, bins=50, normalized=False, getvalues=False, name="", canvas=None, reportdiff=False, inlog=True):
477  return DBdiff(database, None, reports, None, window, windows, selection, phi, color, style, bins, normalized, getvalues,
478  name, canvas, reportdiff, inlog)
479 
480 
481 def DBdiff(database1, database2, reports1, reports2,
482  window=10., windows=None, selection=None, phi=False, color=ROOT.kBlue-8,
483  style=1, bins=50, normalized=False, getvalues=False, name="tmp", canvas=None, reportdiff=False, inlog=False ):
484 
485  tdrStyle.SetOptStat("emrou")
486  tdrStyle.SetStatW(0.40)
487 
488  wnd = [window]*6
489  if windows is not None:
490  i=0
491  for w in windows:
492  wnd[i] = windows[i]
493  i+=1
494 
495  global hx, hy, hz, hphix, hphiy, hphiz
496 
497  if phi:
498  hx = ROOT.TH1F("%s_phi" % name, "", bins, -wnd[0], wnd[0])
499  else:
500  hx = ROOT.TH1F("%s_x" % name, "", bins, -wnd[0], wnd[0])
501  hy = ROOT.TH1F("%s_y" % name, "", bins, -wnd[1], wnd[1])
502  hz = ROOT.TH1F("%s_z" % name, "", bins, -wnd[2], wnd[2])
503  hphix = ROOT.TH1F("%s_phix" % name, "", bins, -wnd[3], wnd[3])
504  hphiy = ROOT.TH1F("%s_phiy" % name, "", bins, -wnd[4], wnd[4])
505  hphiz = ROOT.TH1F("%s_phiz" % name, "", bins, -wnd[5], wnd[5])
506 
507  for r1 in reports1:
508  if selection is None or (selection.__code__.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
509  if reports2 is None:
510  r2 = Report(r1.chamberId, r1.postal_address, r1.name)
511  r2.add_parameters(ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.),
512  ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.), 0., 0., 0., 0.)
513  else:
514  r2 = getReportByPostalAddress(r1.postal_address, reports2)
515  if r2 is None: continue
516 
517  found = False
518  if r1.postal_address[0] == "DT":
519  if r1.postal_address[1:] in database1.dt:
520  found = True
521  db1 = database1.dt[r1.postal_address[1:]]
522  if database2 is None:
523  db2 = DTAlignable()
524  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
525  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
526  else:
527  db2 = database2.dt[r1.postal_address[1:]]
528 
529  else:
530  # skip ME1/a
531  if r1.postal_address[2]==1 and r1.postal_address[3]==4: continue
532  if r1.postal_address[1:] in database1.csc:
533  found = True
534  db1 = database1.csc[r1.postal_address[1:]]
535  if database2 is None:
536  db2 = CSCAlignable()
537  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
538  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
539  else:
540  db2 = database2.csc[r1.postal_address[1:]]
541 
542  if found and r1.status == "PASS" and r2.status == "PASS":
543  if r1.deltax is not None and r2.deltax is not None and r1.deltax.error is not None and \
544  r2.deltax.error is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
545  delta = db1.x - db2.x
546  if reportdiff: delta -= r1.deltax.value
547  if normalized:
548  fill = delta/sqrt(r1.deltax.error**2 + r2.deltax.error**2) * signConventions[r1.postal_address][0]
549  else:
550  if phi:
551  fill = delta/signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0]
552  else:
553  fill = delta * 10. * signConventions[r1.postal_address][0]
554  hx.Fill(fill)
555  if getvalues not in (False, None):
556  getvalues["x"].append((fill, 10. * sqrt(r1.deltax.error**2 + r2.deltax.error**2)))
557 
558  if r1.deltay is not None and r2.deltay is not None and r1.deltay.error is not None and \
559  r2.deltay.error is not None and (r1.deltay.error**2 + r2.deltay.error**2) > 0.:
560  delta = db1.y - db2.y
561  if reportdiff: delta -= r1.deltay.value
562  if normalized:
563  fill = delta/sqrt(r1.deltay.error**2 + r2.deltay.error**2) * signConventions[r1.postal_address][1]
564  else:
565  fill = delta * 10. * signConventions[r1.postal_address][1]
566  hy.Fill(fill)
567  if getvalues not in (False, None):
568  getvalues["y"].append((fill, 10. * sqrt(r1.deltay.error**2 + r2.deltay.error**2)))
569 
570  if r1.deltaz is not None and r2.deltaz is not None and r1.deltaz.error is not None and \
571  r2.deltaz.error is not None and (r1.deltaz.error**2 + r2.deltaz.error**2) > 0.:
572  delta = db1.z - db2.z
573  if reportdiff: delta -= r1.deltaz.value
574  if normalized:
575  fill = delta/sqrt(r1.deltaz.error**2 + r2.deltaz.error**2) * signConventions[r1.postal_address][2]
576  else:
577  fill = delta * 10. * signConventions[r1.postal_address][2]
578  hz.Fill(fill)
579  if getvalues not in (False, None):
580  getvalues["z"].append((fill, 10. * sqrt(r1.deltaz.error**2 + r2.deltaz.error**2)))
581 
582  if r1.deltaphix is not None and r2.deltaphix is not None and r1.deltaphix.error is not None and \
583  r2.deltaphix.error is not None and (r1.deltaphix.error**2 + r2.deltaphix.error**2) > 0.:
584  delta = db1.phix - db2.phix
585  if reportdiff: delta -= r1.deltaphix.value
586  if normalized:
587  fill = delta/sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)
588  else:
589  fill = delta * 1000.
590  hphix.Fill(fill)
591  if getvalues not in (False, None):
592  getvalues["phix"].append((fill, 10. * sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)))
593 
594  if r1.deltaphiy is not None and r2.deltaphiy is not None and r1.deltaphiy.error is not None and \
595  r2.deltaphiy.error is not None and (r1.deltaphiy.error**2 + r2.deltaphiy.error**2) > 0.:
596  delta = db1.phiy - db2.phiy
597  if reportdiff:
598  delta -= r1.deltaphiy.value
599  if abs(delta)>0.02/1000: print r1.postal_address, 1000*delta, "=", 1000*db1.phiy - 1000*db2.phiy, "-", 1000*r1.deltaphiy.value, "... ",1000*db1.phiy , 1000*db2.phiy
600  if normalized:
601  fill = delta/sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)
602  else:
603  fill = delta * 1000.
604  hphiy.Fill(fill)
605  if getvalues not in (False, None):
606  getvalues["phiy"].append((fill, 10. * sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)))
607 
608  if r1.deltaphiz is not None and r2.deltaphiz is not None and r1.deltaphiz.error is not None and \
609  r2.deltaphiz.error is not None and (r1.deltaphiz.error**2 + r2.deltaphiz.error**2) > 0.:
610  delta = db1.phiz - db2.phiz
611  if reportdiff: delta -= r1.deltaphiz.value
612  if normalized:
613  fill = delta/sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)
614  else:
615  fill = delta * 1000.
616  hphiz.Fill(fill)
617  if getvalues not in (False, None):
618  getvalues["phiz"].append((fill, 10. * sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)))
619 
620  if not normalized:
621  if phi:
622  hx.SetXTitle("#delta_{#phi} position (mrad)")
623  else:
624  hx.SetXTitle("#delta_{x'} (mm)")
625  hy.SetXTitle("#delta_{y'} (mm)")
626  hz.SetXTitle("#delta_{z'} (mm)")
627  hphix.SetXTitle("#delta_{#phi_{x}} (mrad)")
628  hphiy.SetXTitle("#delta_{#phi_{y}} (mrad)")
629  hphiz.SetXTitle("#delta_{#phi_{z}} (mrad)")
630  if reportdiff:
631  if phi:
632  hx.SetXTitle("#delta_{#phi}(XML) - #delta_{#phi}(report) position (mrad)")
633  else:
634  hx.SetXTitle("#delta_{x'}(XML) - #delta_{x'}(report) (mm)")
635  hy.SetXTitle("#delta_{y'}(XML) - #delta_{y'}(report) (mm)")
636  hz.SetXTitle("#delta_{z'}(XML) - #delta_{z'}(report) (mm)")
637  hphix.SetXTitle("#delta_{#phi_{x}}(XML) - #delta_{#phi_{x}}(report) (mrad)")
638  hphiy.SetXTitle("#delta_{#phi_{y}}(XML) - #delta_{#phi_{y}}(report) (mrad)")
639  hphiz.SetXTitle("#delta_{#phi_{z}}(XML) - #delta_{#phi_{z}}(report) (mrad)")
640  else:
641  if phi:
642  hx.SetXTitle("#delta_{#phi}/#sigma_{#phi} position")
643  else:
644  hx.SetXTitle("#delta_{x'}/#sigma_{x'}")
645  hy.SetXTitle("#delta_{y'}/#sigma_{y'}")
646  hz.SetXTitle("#delta_{z'}/#sigma_{z'}")
647  hphix.SetXTitle("#delta_{#phi_{x}}/#sigma_{#phi_{x}}")
648  hphiy.SetXTitle("#delta_{#phi_{y}}/#sigma_{#phi_{y}}")
649  hphiz.SetXTitle("#delta_{#phi_{z}}/#sigma_{#phi_{z}}")
650 
651  for h in hx, hy, hz, hphix, hphiy, hphiz:
652  h.GetXaxis().CenterTitle()
653  h.GetYaxis().CenterTitle()
654  h.SetFillColor(color)
655  h.SetLineStyle(style)
656 
657  if canvas is not None: c = canvas
658  else: c = c1
659 
660  if normalized:
661  fx = ROOT.TF1("fx", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hx.GetEntries()*2.*window/bins), -window, window)
662  fy = ROOT.TF1("fy", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hy.GetEntries()*2.*window/bins), -window, window)
663  fz = ROOT.TF1("fz", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hz.GetEntries()*2.*window/bins), -window, window)
664  fphix = ROOT.TF1("fphix", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphix.GetEntries()*2.*window/bins), -window, window)
665  fphiy = ROOT.TF1("fphiy", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphiy.GetEntries()*2.*window/bins), -window, window)
666  fphiz = ROOT.TF1("fphiz", "%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphiz.GetEntries()*2.*window/bins), -window, window)
667  for f in fx, fy, fz, fphix, fphiy, fphiz:
668  f.SetLineWidth(2)
669  f.SetLineColor(ROOT.kBlue)
670  for h, f in (hx, fx), (hy, fy), (hz, fz), (hphix, fphix), (hphiy, fphiy), (hphiz, fphiz):
671  h.SetAxisRange(0, 1.1*max(h.GetMaximum(), f.GetMaximum()), "Y")
672 
673  c.Clear()
674  c.Divide(3, 2)
675  c.GetPad(1).cd(); hx.Draw(); fx.Draw("same")
676  c.GetPad(2).cd(); hy.Draw(); fy.Draw("same")
677  c.GetPad(3).cd(); hz.Draw(); fz.Draw("same")
678  c.GetPad(4).cd(); hphix.Draw(); fphix.Draw("same")
679  c.GetPad(5).cd(); hphiy.Draw(); fphiy.Draw("same")
680  c.GetPad(6).cd(); hphiz.Draw(); fphiz.Draw("same")
681  return hx, hy, hz, hphix, hphiy, hphiz, fx, fy, fz, fphix, fphiy, fphiz
682  else:
683  nvar = 6
684 
685  c.Clear()
686  if nvar == 4: c.Divide(2, 2)
687  if nvar == 6: c.Divide(3, 2)
688  c.GetPad(1).cd(); hx.Draw()
689  c.GetPad(2).cd(); hy.Draw()
690  if nvar == 4:
691  c.GetPad(3).cd(); hphiy.Draw()
692  c.GetPad(4).cd(); hphiz.Draw()
693  if nvar == 6:
694  c.GetPad(3).cd(); hz.Draw()
695  c.GetPad(4).cd(); hphix.Draw()
696  c.GetPad(5).cd(); hphiy.Draw()
697  c.GetPad(6).cd(); hphiz.Draw()
698 
699  if inlog:
700  if hx.GetEntries()>0: c.GetPad(1).SetLogy(1)
701  if hy.GetEntries()>0: c.GetPad(2).SetLogy(1)
702  if nvar == 4:
703  if hphiy.GetEntries()>0: c.GetPad(3).SetLogy(1)
704  if hphiz.GetEntries()>0: c.GetPad(4).SetLogy(1)
705  if nvar == 6:
706  if hz.GetEntries()>0: c.GetPad(3).SetLogy(1)
707  if hphix.GetEntries()>0: c.GetPad(4).SetLogy(1)
708  if hphiy.GetEntries()>0: c.GetPad(5).SetLogy(1)
709  if hphiz.GetEntries()>0: c.GetPad(6).SetLogy(1)
710 
711  return hx, hy, hz, hphix, hphiy, hphiz
712 
713 
714 
715 def DBMCVersus(quantity, versus, database, reports, window=10., selection=None, color=ROOT.kBlack):
716  return DBdiffVersus(quantity, versus, database, None, reports, None, window, selection, color)
717 
718 def DBdiffVersus(quantity, versus, database1, database2, reports1, reports2, windwselection=None, color=ROOT.kBlack):
719  tdrStyle.SetOptStat("")
720 
721  domain = []
722  values = []
723  errors = []
724 
725  for r1 in reports1:
726  if selection is None or (selection.__code__.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
727  if reports2 is None:
728  r2 = Report(r1.chamberId, r1.postal_address, r1.name)
729  r2.add_parameters(ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.),
730  ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.), 0., 0., 0.)
731  else:
732  found = False
733  for r2 in reports2:
734  if r1.postal_address == r2.postal_address:
735  found = True
736  break
737  if not found: continue
738 
739  found = False
740  if r1.postal_address[0] == "DT":
741  if r1.postal_address[1:] in database1.dt:
742  found = True
743  db1 = database1.dt[r1.postal_address[1:]]
744  if database2 is None:
745  db2 = DTAlignable()
746  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
747  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
748  else:
749  db2 = database2.dt[r1.postal_address[1:]]
750  else:
751  if r1.postal_address[1:] in database1.csc:
752  found = True
753  db1 = database1.csc[r1.postal_address[1:]]
754  if database2 is None:
755  db2 = CSCAlignable()
756  db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
757  db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
758  else:
759  db2 = database2.csc[r1.postal_address[1:]]
760 
761  if found and r1.status == "PASS" and r2.status == "PASS":
762  okay = False
763 
764  if quantity == "phi":
765  if r1.deltax is not None and r2.deltax is not None and r1.deltax.error is not None and \
766  r2.deltax.error is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
767  okay = True
768  values.append((db1.x - db2.x)/
769  signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0])
770  errors.append((r1.deltax.error**2 + r2.deltax.error**2)/
771  signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0])
772 
773  elif quantity == "x":
774  if r1.deltax is not None and r2.deltax is not None and r1.deltax.error is not None and \
775  r2.deltax.error is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
776  okay = True
777  values.append((db1.x - db2.x) * 10. * signConventions[r1.postal_address][0])
778  errors.append((r1.deltax.error**2 + r2.deltax.error**2) * 10. * signConventions[r1.postal_address][0])
779 
780  elif quantity == "y":
781  if r1.deltay is not None and r2.deltay is not None and r1.deltay.error is not None and \
782  r2.deltay.error is not None and (r1.deltay.error**2 + r2.deltay.error**2) > 0.:
783  okay = True
784  values.append((db1.y - db2.y) * 10. * signConventions[r1.postal_address][1])
785  errors.append((r1.deltay.error**2 + r2.deltay.error**2) * 10. * signConventions[r1.postal_address][1])
786 
787  elif quantity == "z":
788  if r1.deltaz is not None and r2.deltaz is not None and r1.deltaz.error is not None and \
789  r2.deltaz.error is not None and (r1.deltaz.error**2 + r2.deltaz.error**2) > 0.:
790  okay = True
791  values.append((db1.z - db2.z) * 10. * signConventions[r1.postal_address][2])
792  errors.append((r1.deltaz.error**2 + r2.deltaz.error**2) * 10. * signConventions[r1.postal_address][2])
793 
794  elif quantity == "phix":
795  if r1.deltaphix is not None and r2.deltaphix is not None and r1.deltaphix.error is not None and \
796  r2.deltaphix.error is not None and (r1.deltaphix.error**2 + r2.deltaphix.error**2) > 0.:
797  okay = True
798  values.append((db1.phix - db2.phix) * 1000.)
799  errors.append((r1.deltaphix.error**2 + r2.deltaphix.error**2) * 1000.)
800 
801  elif quantity == "phiy":
802  if r1.deltaphiy is not None and r2.deltaphiy is not None and r1.deltaphiy.error is not None and \
803  r2.deltaphiy.error is not None and (r1.deltaphiy.error**2 + r2.deltaphiy.error**2) > 0.:
804  okay = True
805  values.append((db1.phiy - db2.phiy) * 1000.)
806  errors.append((r1.deltaphiy.error**2 + r2.deltaphiy.error**2) * 1000.)
807 
808  elif quantity == "phiz":
809  if r1.deltaphiz is not None and r2.deltaphiz is not None and r1.deltaphiz.error is not None and \
810  r2.deltaphiz.error is not None and (r1.deltaphiz.error**2 + r2.deltaphiz.error**2) > 0.:
811  okay = True
812  values.append((db1.phiz - db2.phiz) * 1000.)
813  errors.append((r1.deltaphiz.error**2 + r2.deltaphiz.error**2) * 1000.)
814 
815  else: raise Exception
816 
817  if okay:
818  if versus == "r": domain.append(signConventions[r1.postal_address][3])
819  elif versus == "phi": domain.append(signConventions[r1.postal_address][4])
820  elif versus == "z": domain.append(signConventions[r1.postal_address][5])
821  else: raise Exception
822 
823  if versus == "r":
824  bkgndhist = ROOT.TH1F("bkgndhist", "", 100, 0., 800.)
825  bkgndhist.SetXTitle("R (cm)")
826  elif versus == "phi":
827  bkgndhist = ROOT.TH1F("bkgndhist", "", 100, -pi, pi)
828  bkgndhist.SetXTitle("#phi (rad)")
829  elif versus == "z":
830  bkgndhist = ROOT.TH1F("bkgndhist", "", 100, -1100., 1100.)
831  bkgndhist.SetXTitle("z (cm)")
832  bkgndhist.GetXaxis().CenterTitle()
833 
834  bkgndhist.SetAxisRange(-window, window, "Y")
835  if quantity == "phi": bkgndhist.SetYTitle("#delta_{#phi} position (mrad)")
836  elif quantity == "x": bkgndhist.SetYTitle("#delta_{x'} (mm)")
837  elif quantity == "y": bkgndhist.SetYTitle("#delta_{y'} (mm)")
838  elif quantity == "z": bkgndhist.SetYTitle("#delta_{z'} (mm)")
839  elif quantity == "phix": bkgndhist.SetYTitle("#delta_{#phi_{x}} (mrad)")
840  elif quantity == "phiy": bkgndhist.SetYTitle("#delta_{#phi_{y}} (mrad)")
841  elif quantity == "phiz": bkgndhist.SetYTitle("#delta_{#phi_{z}} (mrad)")
842  else: raise Exception
843  bkgndhist.GetYaxis().CenterTitle()
844 
845  if len(domain) == 0:
846  tgraph = ROOT.TGraphErrors(0)
847  else:
848  tgraph = ROOT.TGraphErrors(len(domain), array.array("d", domain), array.array("d", values),
849  array.array("d", [0.]*len(domain)), array.array("d", errors))
850  tgraph.SetMarkerColor(color)
851  tgraph.SetLineColor(color)
852 
853  bkgndhist.Draw()
854  if tgraph.GetN() > 0: tgraph.Draw("p")
855  return bkgndhist, tgraph, domain, values, errors
856 
857 ######################################################################################################
858 
860  # only len==9 ids can correspond to valid postal address
861  if len(id)!=9: return None
862  if id[0:2]=="MB":
863  #print id
864  pa = ("DT", int(id[2:4]), int(id[5]), int(id[7:9]))
865  #print pa
866  if pa[1]<-2 or pa[1]>2: return None
867  if pa[2]>4: return None
868  if pa[3]<1 or pa[3]>14 or (pa[3]==4 and pa[3]>12): return None
869  return pa
870  elif id[0:2]=="ME":
871  if id[2]=="+": ec=1
872  elif id[2]=="-": ec=2
873  else: return None
874  pa = ("CSC", ec, int(id[3]), int(id[5]), int(id[7:9]))
875  if pa[2]<1 or pa[2]>4: return None
876  if pa[3]<1 or pa[3]>4 or (pa[2]>1 and pa[3]>2): return None
877  if pa[4]<1 or pa[4]>36 or (pa[2]>1 and pa[3]==1 and pa[4]>18): return None
878  return pa
879  else: return None
880 
881 
882 def postalAddressToId(postal_address):
883  if postal_address[0] == "DT":
884  wheel, station, sector = postal_address[1:]
885  w = "%+d"%wheel
886  if w=="+0": w = "-0"
887  return "MB%s/%d/%02d" % (w, station, sector)
888  elif postal_address[0] == "CSC":
889  endcap, station, ring, chamber = postal_address[1:]
890  if endcap != 1: station = -1 * abs(station)
891  return "ME%+d/%d/%02d" % (station, ring, chamber)
892 
893 
894 def nameToId(name):
895  if name[0:2] == "MB":
896  wh = name[4]
897  if wh == "A": w = "-2"
898  elif wh == "B": w = "-1"
899  elif wh == "C": w = "-0"
900  elif wh == "D": w = "+1"
901  elif wh == "E": w = "+2"
902  else: return ""
903  station = name[7]
904  sector = name[11:13]
905  return "MB%s/%s/%s" % (w, station, sector)
906  elif name[0:2] == "ME":
907  if name[2]=="p": endcap = "+"
908  elif name[2]=="m": endcap = "-"
909  else: return ""
910  station = name[3]
911  ring = name[4]
912  chamber = name[6:8]
913  return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
914  return None
915 
916 
917 def availableCellsDT(reports):
918  dts = []
919  # DT wheels
920  for iwheel in DT_TYPES:
921  if iwheel[1]=="ALL": continue
922  dts.append(iwheel[0])
923  # DT wheel & station
924  for wheel in DT_TYPES:
925  if wheel[1]=="ALL": continue
926  for station in wheel[2]:
927  dts.append(wheel[0]+'/'+station[1])
928  # DT station & sector
929  for wheel in DT_TYPES:
930  if wheel[1]!="ALL": continue
931  for station in wheel[2]:
932  for sector in range(1,station[2]+1):
933  ssector = "%02d" % sector
934  dts.append(wheel[0]+'/'+station[1]+'/'+ssector)
935  # DT station & ALL sectors
936  for wheel in DT_TYPES:
937  if wheel[1]!="ALL": continue
938  for station in wheel[2]:
939  dts.append(wheel[0]+'/'+station[1])
940  # DT chambers
941  for wheel in DT_TYPES:
942  if wheel[1]=="ALL": continue
943  for station in wheel[2]:
944  for sector in range(1,station[2]+1):
945  ssector = "%02d" % sector
946  label = "MBwh%sst%ssec%s" % (wheelLetter(int(wheel[1])),station[1],ssector)
947  if len(reports)==0:
948  # no reports case: do not include chambers
949  #dts.append(wheel[0]+'/'+station[1]+'/'+ssector)
950  continue
951  found = False
952  for r in reports:
953  if r.name == label:
954  found = True
955  break
956  if not found: continue
957  if r.status == "TOOFEWHITS" and r.posNum+r.negNum==0: continue
958  if r.status == "NOFIT": continue
959  dts.append(wheel[0]+'/'+station[1]+'/'+ssector)
960  return dts
961 
962 
963 def availableCellsCSC(reports):
964  cscs = []
965  # CSC station
966  for endcap in CSC_TYPES:
967  for station in endcap[2]:
968  cscs.append("%s%s" % (endcap[0], station[1]))
969  # CSC station & ring
970  for endcap in CSC_TYPES:
971  for station in endcap[2]:
972  for ring in station[2]:
973  if ring[1]=="ALL": continue
974  #label = "CSCvsphi_me%s%s%s" % (endcap[1], station[1], ring[1])
975  cscs.append("%s%s/%s" % (endcap[0], station[1],ring[1]))
976  # CSC station and chamber
977  for endcap in CSC_TYPES:
978  for station in endcap[2]:
979  for ring in station[2]:
980  if ring[1]!="ALL": continue
981  for chamber in range(1,ring[2]+1):
982  #label = "CSCvsr_me%s%sch%02d" % (endcap[1], station[1], chamber)
983  cscs.append("%s%s/ALL/%02d" % (endcap[0], station[1],chamber))
984  # CSC station and ALL chambers
985  for endcap in CSC_TYPES:
986  for station in endcap[2]:
987  for ring in station[2]:
988  if ring[1]!="ALL": continue
989  #label = "CSCvsr_me%s%schALL" % (endcap[1], station[1])
990  cscs.append("%s%s/ALL" % (endcap[0], station[1]))
991  # CSC chambers
992  for endcap in CSC_TYPES:
993  for station in endcap[2]:
994  for ring in station[2]:
995  if ring[1]=="ALL": continue
996  for chamber in range(1,ring[2]+1):
997  # exclude non instrumented ME4/2
998  if station[1]=="4" and ring[1]=="2":
999  if endcap[1]=="m": continue
1000  if chamber<9 or chamber>13: continue
1001  schamber = "%02d" % chamber
1002  label = "ME%s%s%s_%s" % (endcap[1], station[1], ring[1], schamber)
1003  if len(reports)==0:
1004  # no reports case: do not include chambers
1005  #cscs.append(endcap[0]+station[1]+'/'+ring[1]+'/'+schamber)
1006  continue
1007  found = False
1008  for r in reports:
1009  if r.name == label:
1010  found = True
1011  break
1012  if not found: continue
1013  if r.status == "TOOFEWHITS" and r.posNum+r.negNum==0: continue
1014  if r.status == "NOFIT": continue
1015  cscs.append(endcap[0]+station[1]+'/'+ring[1]+'/'+schamber)
1016  return cscs
1017 
1018 
1019 DQM_SEVERITY = [
1020  {"idx":0, "name": "NONE", "color": "lightgreen", "hex":"#90EE90"},
1021  {"idx":1, "name": "LOWSTAT05", "color": "lightgreen", "hex":"#96D953"},
1022  {"idx":2, "name": "LOWSTAT075", "color": "lightgreen", "hex":"#94E26F"},
1023  {"idx":3, "name": "LOWSTAT1", "color": "yellowgreen", "hex":"#9ACD32"},
1024  {"idx":4, "name": "LOWSTAT", "color": "yellow", "hex":"#FFFF00"},
1025  {"idx":5, "name": "TOLERABLE", "color": "lightpink", "hex":"#FFB6C1"},
1026  {"idx":6, "name": "SEVERE", "color": "orange", "hex":"#FFA500"},
1027  {"idx":7, "name": "CRITICAL", "color": "red", "hex":"#FF0000"}];
1028 
1029 
1030 def addToTestResults(c,res):
1031  if len(res)>0:
1032  if c in TEST_RESULTS: TEST_RESULTS[c].extend(res)
1033  else: TEST_RESULTS[c] = res
1034 
1035 
1036 def testEntry(testID,scope,descr,severity):
1037  s = 0
1038  for sev in DQM_SEVERITY:
1039  if sev["name"]==severity: s = sev["idx"]
1040  return {"testID":testID,"scope":scope,"descr":descr,"severity":s}
1041 
1042 
1044  if abs(x[1])==0.: return 0.
1045  pull = abs(x[0])/abs(x[1])
1046  if pull <= 5: return 0.
1047  else: return pull
1048 
1049 
1051  n = len(x)
1052  res = []
1053  dr = []
1054  #print x
1055  #print sx
1056  for i in range(1,n+1):
1057  x1 = x[i-1]
1058  sx1 = sx[i-1]
1059  x2 = x[0]
1060  sx2 = sx[0]
1061  if i<n:
1062  x2 = x[i]
1063  sx2 = sx[i]
1064  sig1 = sqrt( (sx1[0]-sx1[1])**2 + x1[1]**2 )
1065  sig2 = sqrt( (sx2[0]-sx2[1])**2 + x2[1]**2 )
1066  df = abs(x1[0]-x2[0]) - 3*( sig1 + sig2 )
1067  #df = abs(sx1[1]-sx2[0]) - 5*(abs(x1[1]) + abs(x2[1]))
1068  #print i, df, '= abs(',sx1[1],'-',sx2[0],')-5*(abs(',x1[1],')+abs(',x2[1],'))'
1069  dr.append(df)
1070  if df > 0: res.append(i)
1071  #print dr
1072  #print res
1073  return res
1074 
1075 
1076 def doTestsForReport(cells,reports):
1077  for c in cells:
1078  # can a cell be converted to a chamber postal address?
1079  postal_address = idToPostalAddress(c)
1080  if not postal_address: continue
1081 
1082  # is this chamber in _report?
1083  found = False
1084  for r in reports:
1085  if r.postal_address == postal_address:
1086  found = True
1087  break
1088  if not found: continue
1089 
1090  # chamber's tests result
1091  res = []
1092  scope = postal_address[0]
1093 
1094  # noting could be done if fitting fails
1095  if r.status == "FAIL" or r.status == "MINUITFAIL":
1096  res.append(testEntry("FAILURE",scope,r.status+" failure","CRITICAL"))
1097  addToTestResults(c,res)
1098  continue
1099 
1100  # noting could be done if TOOFEWHITS
1101  nseg = r.posNum + r.negNum
1102  if r.status == "TOOFEWHITS" and nseg>0:
1103  res.append(testEntry("LOW_STAT",scope,"low stat, #segments=%d"%nseg,"LOWSTAT"))
1104  addToTestResults(c,res)
1105  continue
1106 
1107  # set shades of light green according to sidma(dx)
1108  sdx = 10.*r.deltax.error
1109  if sdx>0.5:
1110  if sdx<0.75: res.append(testEntry("LOW_STAT_DDX05",scope,"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),"LOWSTAT05"))
1111  elif sdx<1.: res.append(testEntry("LOW_STAT_DDX075",scope,"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),"LOWSTAT075"))
1112  else: res.append(testEntry("LOW_STAT_DDX1",scope,"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),"LOWSTAT1"))
1113 
1114  # check chi2
1115  if r.redchi2 > 20.: #2.5:
1116  res.append(testEntry("BIG_CHI2",scope,"chi2=%f>20" % r.redchi2,"TOLERABLE"))
1117 
1118  # check medians
1119  medx, meddx = 10.*r.median_x, 1000.*r.median_dxdz
1120  #medy, meddy = 10.*r.median_y, 1000.*r.median_dydz
1121  if medx>2: res.append(testEntry("BIG_MED_X",scope,"median dx=%f>2 mm"%medx,"SEVERE"))
1122  #if medy>3: res.append(testEntry("BIG_MED_Y",scope,"median dy=%f>3 mm"%medy,"SEVERE"))
1123  if meddx>2: res.append(testEntry("BIG_MED_DXDZ",scope,"median d(dx/dz)=%f>2 mrad"%meddx,"SEVERE"))
1124  #if meddy>3: res.append(testEntry("BIG_MED_DYDZ",scope,"median d(dy/dz)=%f>3 mrad"%meddy,"SEVERE"))
1125 
1126  # check residuals far from zero
1127  isDTst4 = False
1128  if postal_address[0] == "DT" and postal_address[2]==4: isDTst4 = True
1129  dx, dy, dpy, dpz = 10.*r.deltax.value, 0., 1000.*r.deltaphiy.value, 1000.*r.deltaphiz.value
1130  if not isDTst4: dy = 10.*r.deltay.value
1131  if dx>0.2: res.append(testEntry("BIG_LAST_ITR_DX",scope,"dx=%f>0.2 mm"%dx,"CRITICAL"))
1132  if dy>0.2: res.append(testEntry("BIG_LAST_ITR_DY",scope,"dy=%f>0.2 mm"%dy,"CRITICAL"))
1133  if dpy>0.2: res.append(testEntry("BIG_LAST_ITR_DPHIY",scope,"dphiy=%f>0.2 mrad"%dpy,"CRITICAL"))
1134  if dpz>0.2: res.append(testEntry("BIG_LAST_ITR_DPHIZ",scope,"dphiz=%f>0.2 mrad"%dpz,"CRITICAL"))
1135  #if ddx>0.03: res.append(testEntry("BIG_DX",scope,"dphix=%f>0.03 mrad"%ddx,"CRITICAL"))
1136 
1137  addToTestResults(c,res)
1138 
1139 
1141  for c in cells:
1142  res = []
1143 
1144  scope = "zzz"
1145  if c[0:2]=="MB": scope = "DT"
1146  if c[0:2]=="ME": scope = "CSC"
1147  if scope == "zzz":
1148  print "strange cell ID: ", c
1149  return None
1150 
1151  if c in MAP_RESULTS_FITSIN:
1152  t = MAP_RESULTS_FITSIN[c]
1153  t_a = testZeroWithin5Sigma(t['a'])
1154  t_s = testZeroWithin5Sigma(t['sin'])
1155  t_c = testZeroWithin5Sigma(t['cos'])
1156  if t_a+t_s+t_c >0:
1157  descr = "map fitsin 5 sigma away from 0; pulls : a=%.2f sin=%.2f, cos=%.2f" % (t_a,t_s,t_c)
1158  res.append(testEntry("MAP_FITSIN",scope,descr,"SEVERE"))
1159 
1160  if c in MAP_RESULTS_SAWTOOTH:
1161  t = MAP_RESULTS_SAWTOOTH[c]
1162 
1163  t_a = testDeltaWithin5Sigma(t['a'],t['da'])
1164  if len(t_a)>0:
1165  descr = "map discontinuities: %s" % ",".join(map(str,t_a))
1166  res.append(testEntry("MAP_DISCONTIN",scope,descr,"SEVERE"))
1167 
1168  t_b = map(testZeroWithin5Sigma, t['b'])
1169  t_bi = []
1170  for i in range(0,len(t_b)):
1171  if t_b[i]>0: t_bi.append(i+1)
1172  if len(t_bi)>0:
1173  descr = "map sawteeth: %s" % ",".join(map(str,t_bi))
1174  res.append(testEntry("MAP_SAWTEETH",scope,descr,"TOLERABLE"))
1175 
1176  addToTestResults(c,res)
1177 
1178 
1179 def saveTestResultsMap(run_name):
1180  if len(MAP_RESULTS_SAWTOOTH)+len(MAP_RESULTS_FITSIN)==0: return None
1181  ff = open("tmp_test_results_map__%s.pkl" % run_name, "wb")
1182  pickle.dump(MAP_RESULTS_SAWTOOTH, ff)
1183  pickle.dump(MAP_RESULTS_FITSIN, ff)
1184  ff.close()
1185 
1186 
1187 def loadTestResultsMap(run_name):
1188  print "tmp_test_results_map__%s.pkl" % run_name, os.access("tmp_test_results_map__%s.pkl" % run_name,os.F_OK)
1189  if not os.access("tmp_test_results_map__%s.pkl" % run_name,os.F_OK): return None
1190  global MAP_RESULTS_FITSIN, MAP_RESULTS_SAWTOOTH
1191  ff = open("tmp_test_results_map__%s.pkl" % run_name, "rb")
1192  MAP_RESULTS_SAWTOOTH = pickle.load(ff)
1193  MAP_RESULTS_FITSIN = pickle.load(ff)
1194  ff.close()
1195  #execfile("tmp_test_results_map__%s.py" % run_name)
1196  #print 'asasas', MAP_RESULTS_FITSIN
1197  return True
1198 
1199 def writeDQMReport(fname_dqm, run_name):
1200  tests = []
1201  for c in TEST_RESULTS:
1202  tests.append({"objID":c, "name":c, "list":TEST_RESULTS[c]})
1203  lt = time.localtime(time.time())
1204  lts = "%04d-%02d-%02d %02d:%02d:%02d %s" % (lt[0], lt[1], lt[2], lt[3], lt[4], lt[5], time.tzname[1])
1205  dqm_report = {"run":run_name, "genDate": lts, "report":tests}
1206  ff = open(fname_dqm,mode="w")
1207  print >>ff, "var DQM_REPORT = "
1208  json.dump(dqm_report,ff)
1209  #print >>ff, "];"
1210  ff.close()
1211 
1212 
1213 def doTests(reports, pic_ids, fname_base, fname_dqm, run_name):
1214  # find available baseline
1215  dts = []
1216  cscs = []
1217  if len(reports)>0:
1218  dts = availableCellsDT(reports)
1219  cscs = availableCellsCSC(reports)
1220  elif len(pic_ids)>0:
1221  dts = [id for id in pic_ids if 'MB' in id]
1222  cscs = [id for id in pic_ids if 'ME' in id]
1223  mulist = ['Run: '+run_name,['ALL',['MU']],['DT',dts],['CSC',cscs]]
1224  ff = open(fname_base,mode="w")
1225  print >>ff, "var MU_LIST = ["
1226  json.dump(mulist,ff)
1227  print >>ff, "];"
1228  ff.close()
1229 
1230  doTestsForReport(dts,reports)
1231  doTestsForReport(cscs,reports)
1232 
1233  loadTestResultsMap(run_name)
1234  doTestsForMapPlots(dts)
1235  doTestsForMapPlots(cscs)
1236 
1237  writeDQMReport(fname_dqm, run_name)
1238 
1239 
1240 ######################################################################################################
1241 
1242 def plotmedians(reports1, reports2, selection=None, binsx=100, windowx=5., ceilingx=None, binsy=100, windowy=5.,
1243  ceilingy=None, binsdxdz=100, windowdxdz=5., ceilingdxdz=None, binsdydz=100, windowdydz=5., ceilingdydz=None,
1244  r1text=" before", r2text=" after", which="median"):
1245  tdrStyle.SetOptStat("emrou")
1246  tdrStyle.SetStatW(0.40)
1247  tdrStyle.SetStatFontSize(0.05)
1248 
1249  global hmediandxdz_after, hmediandxdz_before, hmediandxdz_beforecopy, \
1250  hmediandydz_after, hmediandydz_before, hmediandydz_beforecopy, \
1251  hmedianx_after, hmedianx_before, hmedianx_beforecopy, \
1252  hmediany_after, hmediany_before, hmediany_beforecopy, tlegend
1253 
1254  hmedianx_before = ROOT.TH1F("hmedianx_before", "", binsx, -windowx, windowx)
1255  hmediany_before = ROOT.TH1F("hmediany_before", "", binsy, -windowy, windowy)
1256  hmediandxdz_before = ROOT.TH1F("hmediandxdz_before", "", binsdxdz, -windowdxdz, windowdxdz)
1257  hmediandydz_before = ROOT.TH1F("hmediandydz_before", "", binsdydz, -windowdydz, windowdydz)
1258  hmedianx_after = ROOT.TH1F("hmedianx_after", "", binsx, -windowx, windowx)
1259  hmediany_after = ROOT.TH1F("hmediany_after", "", binsy, -windowy, windowy)
1260  hmediandxdz_after = ROOT.TH1F("hmediandxdz_after", "", binsdxdz, -windowdxdz, windowdxdz)
1261  hmediandydz_after = ROOT.TH1F("hmediandydz_after", "", binsdydz, -windowdydz, windowdydz)
1262 
1263  if which == "median":
1264  whichx = whichy = whichdxdz = whichdydz = "median"
1265  elif which == "bigmean":
1266  whichx = "mean30"
1267  whichy = "mean30"
1268  whichdxdz = "mean20"
1269  whichdydz = "mean50"
1270  elif which == "mean":
1271  whichx = "mean15"
1272  whichy = "mean15"
1273  whichdxdz = "mean10"
1274  whichdydz = "mean25"
1275  elif which == "bigwmean":
1276  whichx = "wmean30"
1277  whichy = "wmean30"
1278  whichdxdz = "wmean20"
1279  whichdydz = "wmean50"
1280  elif which == "wmean":
1281  whichx = "wmean15"
1282  whichy = "wmean15"
1283  whichdxdz = "wmean10"
1284  whichdydz = "wmean25"
1285  elif which == "bigstdev":
1286  whichx = "stdev30"
1287  whichy = "stdev30"
1288  whichdxdz = "stdev20"
1289  whichdydz = "stdev50"
1290  elif which == "stdev":
1291  whichx = "stdev15"
1292  whichy = "stdev15"
1293  whichdxdz = "stdev10"
1294  whichdydz = "stdev25"
1295  else:
1296  raise Exception(which + " not recognized")
1297 
1298  for r1 in reports1:
1299  if selection is None or (selection.__code__.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
1300  found = False
1301  for r2 in reports2:
1302  if r1.postal_address == r2.postal_address:
1303  found = True
1304  break
1305  if not found: continue
1306 
1307  #skip ME1/1a
1308  if r1.postal_address[0]=='CSC':
1309  if r1.postal_address[2]==1 and r1.postal_address[3]==4: continue
1310 
1311  if r1.status == "PASS" and r2.status == "PASS":
1312  hmedianx_before.Fill(10.*eval("r1.%s_x" % whichx))
1313  hmediandxdz_before.Fill(1000.*eval("r1.%s_dxdz" % whichdxdz))
1314  hmedianx_after.Fill(10.*eval("r2.%s_x" % whichx))
1315  hmediandxdz_after.Fill(1000.*eval("r2.%s_dxdz" % whichdxdz))
1316 
1317  if r1.median_y is not None:
1318  hmediany_before.Fill(10.*eval("r1.%s_y" % whichy))
1319  hmediandydz_before.Fill(1000.*eval("r1.%s_dydz" % whichdydz))
1320  hmediany_after.Fill(10.*eval("r2.%s_y" % whichy))
1321  hmediandydz_after.Fill(1000.*eval("r2.%s_dydz" % whichdydz))
1322 
1323  hmedianx_beforecopy = hmedianx_before.Clone()
1324  hmediany_beforecopy = hmediany_before.Clone()
1325  hmediandxdz_beforecopy = hmediandxdz_before.Clone()
1326  hmediandydz_beforecopy = hmediandydz_before.Clone()
1327  hmedianx_beforecopy.SetLineStyle(2)
1328  hmediany_beforecopy.SetLineStyle(2)
1329  hmediandxdz_beforecopy.SetLineStyle(2)
1330  hmediandydz_beforecopy.SetLineStyle(2)
1331 
1332  hmedianx_before.SetFillColor(ROOT.kMagenta+2)
1333  hmediany_before.SetFillColor(ROOT.kMagenta+2)
1334  hmediandxdz_before.SetFillColor(ROOT.kMagenta+2)
1335  hmediandydz_before.SetFillColor(ROOT.kMagenta+2)
1336  hmedianx_after.SetFillColor(ROOT.kYellow)
1337  hmediany_after.SetFillColor(ROOT.kYellow)
1338  hmediandxdz_after.SetFillColor(ROOT.kYellow)
1339  hmediandydz_after.SetFillColor(ROOT.kYellow)
1340 
1341  hmedianx_after.SetXTitle("median(#Deltax) (mm)")
1342  hmediany_after.SetXTitle("median(#Deltay) (mm)")
1343  hmediandxdz_after.SetXTitle("median(#Deltadx/dz) (mrad)")
1344  hmediandydz_after.SetXTitle("median(#Deltadydz) (mrad)")
1345  hmedianx_after.GetXaxis().CenterTitle()
1346  hmediany_after.GetXaxis().CenterTitle()
1347  hmediandxdz_after.GetXaxis().CenterTitle()
1348  hmediandydz_after.GetXaxis().CenterTitle()
1349 
1350  if ceilingx is not None: hmedianx_after.SetAxisRange(0., ceilingx, "Y")
1351  if ceilingy is not None: hmediany_after.SetAxisRange(0., ceilingy, "Y")
1352  if ceilingdxdz is not None: hmediandxdz_after.SetAxisRange(0., ceilingdxdz, "Y")
1353  if ceilingdydz is not None: hmediandydz_after.SetAxisRange(0., ceilingdydz, "Y")
1354 
1355  c1.Clear()
1356  c1.Divide(2, 2)
1357 
1358  c1.GetPad(1).cd()
1359  hmedianx_after.Draw()
1360  hmedianx_before.Draw("same")
1361  hmedianx_after.Draw("same")
1362  hmedianx_beforecopy.Draw("same")
1363  hmedianx_after.Draw("axissame")
1364 
1365  tlegend = ROOT.TLegend(0.17, 0.75-0.05, 0.45+0.05, 0.9)
1366  tlegend.SetFillColor(ROOT.kWhite)
1367  tlegend.SetBorderSize(0)
1368  tlegend.AddEntry(hmedianx_after, r2text, "f")
1369  tlegend.AddEntry(hmedianx_before, r1text, "f")
1370  tlegend.Draw()
1371 
1372  c1.GetPad(2).cd()
1373  hmediandxdz_after.Draw()
1374  hmediandxdz_before.Draw("same")
1375  hmediandxdz_after.Draw("same")
1376  hmediandxdz_beforecopy.Draw("same")
1377  hmediandxdz_after.Draw("axissame")
1378 
1379  c1.GetPad(3).cd()
1380  hmediany_after.Draw()
1381  hmediany_before.Draw("same")
1382  hmediany_after.Draw("same")
1383  hmediany_beforecopy.Draw("same")
1384  hmediany_after.Draw("axissame")
1385 
1386  c1.GetPad(4).cd()
1387  hmediandydz_after.Draw()
1388  hmediandydz_before.Draw("same")
1389  hmediandydz_after.Draw("same")
1390  hmediandydz_beforecopy.Draw("same")
1391  hmediandydz_after.Draw("axissame")
1392 
1393  return hmediandxdz_after, hmediandxdz_before, hmediandxdz_beforecopy, \
1394  hmediandydz_after, hmediandydz_before, hmediandydz_beforecopy, \
1395  hmedianx_after, hmedianx_before, hmedianx_beforecopy, \
1396  hmediany_after, hmediany_before, hmediany_beforecopy, tlegend
1397 
1398 
1399 ######################################################################################################
1400 
1401 def createPeaksProfile(the2d, rebin=1):
1402  htmp = ROOT.gROOT.FindObject(the2d.GetName()+"_peaks")
1403  if htmp != None: htmp.Delete()
1404 
1405  hpeaks = the2d.ProjectionX(the2d.GetName()+"_peaks")
1406  hpeaks.Reset()
1407  hpeaks.Rebin(rebin)
1408  bad_fit_bins = []
1409  for i in xrange(0, int(the2d.GetNbinsX()), rebin):
1410  tmp = the2d.ProjectionY("tmp", i+1, i + rebin)
1411  nn = tmp.GetEntries()
1412 
1413  drange = tmp.GetRMS()
1414  drange = 2.*drange
1415  fgaus = ROOT.TF1("fgaus","gaus", tmp.GetMean() - drange, tmp.GetMean() + drange)
1416  fgaus.SetParameter(0,nn)
1417  fgaus.SetParameter(1,tmp.GetMean())
1418  fgaus.SetParameter(2,tmp.GetRMS())
1419  #print " ", i, nn, tmp.GetMean() , drange, "[", tmp.GetMean() - drange, tmp.GetMean() + drange, ']'
1420 
1421  fitOk = False
1422  if nn > 10: # good to fit
1423  fr = tmp.Fit("fgaus","RNSQ")
1424  #print " ", fgaus.GetParameter(1), " +- ", fgaus.GetParError(1), " fitres = " , fr.Status() , fr.CovMatrixStatus()
1425  hpeaks.SetBinContent(i/rebin+1, fgaus.GetParameter(1))
1426  hpeaks.SetBinError(i/rebin+1, fgaus.GetParError(1))
1427  if fr.Status()==0 and fr.CovMatrixStatus()==3 : fitOk = True
1428  if not fitOk:
1429  bad_fit_bins.append(i/rebin+1)
1430  if nn > 1. and tmp.GetRMS() > 0: # use mean
1431  hpeaks.SetBinContent(i/rebin+1, tmp.GetMean())
1432  hpeaks.SetBinError(i/rebin+1, ROOT.TMath.StudentQuantile(0.841345,nn) * tmp.GetRMS() / sqrt(nn))
1433  else:
1434  hpeaks.SetBinContent(i/rebin+1, 0.)
1435  hpeaks.SetBinError(i/rebin+1, 0.)
1436  if len(bad_fit_bins): print "createPeaksProfile bad fit bins: ", bad_fit_bins
1437  return hpeaks
1438 
1439 
1440 ######################################################################################################
1441 
1442 def mapplot(tfiles, name, param, mode="from2d", window=10., abscissa=None, title="",
1443  widebins=False, fitsine=False, fitline=False, reset_palette=False, fitsawteeth=False, fitpeaks=False, peaksbins=1, fixfitpars={}, **args):
1444  tdrStyle.SetOptTitle(1)
1445  tdrStyle.SetTitleBorderSize(0)
1446  tdrStyle.SetOptStat(0)
1447  #tdrStyle.SetOptStat("emrou")
1448  tdrStyle.SetOptFit(0)
1449  tdrStyle.SetTitleFontSize(0.05)
1450  tdrStyle.SetPadRightMargin(0.1) # to see the pallete labels on the left
1451 
1452  c1.Clear()
1453  c1.ResetAttPad()
1454 
1455  if reset_palette: set_palette("blues")
1456  global hist, hist2d, hist2dweight, tline1, tline2, tline3
1457 
1458  if fitsine or fitsawteeth:
1459  id = mapNameToId(name)
1460  if not id:
1461  print "bad id for ", name
1462  raise Exception
1463 
1464  hdir = "AlignmentMonitorMuonSystemMap1D/iter1/"
1465  hpref= "%s_%s" % (name, param)
1466  hhh = hdir+hpref
1467 
1468  combine_all = False
1469  if "ALL" in name and ("CSCvsr" in name or "DTvsz" in name): combine_all = True
1470 
1471  add1d = ("vsphi" in name) and (param == "x")
1472 
1473  if "h2d" in args:
1474  hist2d = args["h2d"].Clone(hpref+"_2d_")
1475  if "CSC" in name and add1d: hist1d = args["h1d"].Clone(hpref+"_1d_")
1476 
1477  elif combine_all:
1478  nch = 12
1479  if "DT" in name and name[6:9]=='st4': nch = 14
1480  if "CSC" in name: nch = 36
1481  chambers = ["%02d" % ch for ch in range (2,nch+1)]
1482 
1483  ch_hhh = hhh.replace('ALL','01')
1484  ch_hpref = hpref.replace('ALL','01')
1485  hist2d = tfiles[0].Get(ch_hhh+"_2d").Clone(ch_hpref+"_2d_")
1486  if "CSC" in name and add1d: hist1d = tfiles[0].Get(ch_hhh+"_1d").Clone(ch_hpref+"_1d_")
1487 
1488  for ch in chambers:
1489  ch_hhh = hhh.replace('ALL',ch)
1490  ch_hpref = hpref.replace('ALL',ch)
1491  hist2d.Add(tfiles[0].Get(ch_hhh+"_2d"))
1492  if "CSC" in name and add1d: hist1d.Add(tfiles[0].Get(ch_hhh+"_1d"))
1493  for tfile in tfiles[1:]:
1494  hist2d.Add(tfile.Get(ch_hhh+"_2d"))
1495  if "CSC" in name and add1d: hist1d.Add(tfile.Get(ch_hhh+"_1d"))
1496 
1497  else:
1498  hist2d = tfiles[0].Get(hhh+"_2d").Clone(hpref+"_2d_")
1499  if "CSC" in name and add1d: hist1d = tfiles[0].Get(hhh+"_1d").Clone(hpref+"_1d_")
1500  for tfile in tfiles[1:]:
1501  hist2d.Add(tfile.Get(hhh+"_2d"))
1502  if "CSC" in name and add1d: hist1d.Add(tfile.Get(hhh+"_1d"))
1503 
1504 
1505  if mode == "from2d":
1506  the2d = hist2d
1507 
1508  hist = the2d.ProjectionX()
1509  hist.Reset()
1510 
1511  skip = 1
1512  if widebins:
1513  hist.Rebin(10)
1514  skip = 10
1515 
1516  #f = ROOT.TF1("g", "gaus", -40., 40)
1517  for i in xrange(0, int(the2d.GetNbinsX()), skip):
1518  tmp = the2d.ProjectionY("tmp", i+1, i + skip)
1519  if tmp.GetEntries() > 1:
1520  #tmp.Fit("g","LNq")
1521  hist.SetBinContent(i/skip+1, tmp.GetMean())
1522  hist.SetBinError(i/skip+1, ROOT.TMath.StudentQuantile(0.841345,tmp.GetEntries()) * tmp.GetRMS() / sqrt(tmp.GetEntries()))
1523  #hist.SetBinError(i/skip+1, tmp.GetRMS() / sqrt(tmp.GetEntries()))
1524  #hist.SetBinError(i/skip+1, f.GetParameter(2))
1525  else:
1526  #hist.SetBinContent(i/skip+1, 2000.)
1527  #hist.SetBinError(i/skip+1, 1000.)
1528  hist.SetBinContent(i/skip+1, 0.)
1529  hist.SetBinError(i/skip+1, 0.)
1530 
1531  hpeaks = createPeaksProfile(the2d, peaksbins)
1532 
1533  else:
1534  raise Exception
1535 
1536  hist.SetAxisRange(-window, window, "Y")
1537  if abscissa is not None: hist.SetAxisRange(abscissa[0], abscissa[1], "X")
1538  hist.SetMarkerStyle(20)
1539  hist.SetMarkerSize(0.75)
1540  hist.GetXaxis().CenterTitle()
1541  hist.GetYaxis().CenterTitle()
1542  hist.GetYaxis().SetTitleOffset(0.75)
1543  hist.GetXaxis().SetTitleSize(0.05)
1544  hist.GetYaxis().SetTitleSize(0.05)
1545  hist.SetTitle(title)
1546  if "vsphi" in name: hist.SetXTitle("Global #phi position (rad)")
1547  elif "vsz" in name: hist.SetXTitle("Global z position (cm)")
1548  elif "vsr" in name: hist.SetXTitle("Global R position (cm)")
1549  if "DT" in name:
1550  if param == "x": hist.SetYTitle("x' residual (mm)")
1551  if param == "dxdz": hist.SetYTitle("dx'/dz residual (mrad)")
1552  if param == "y": hist.SetYTitle("y' residual (mm)")
1553  if param == "dydz": hist.SetYTitle("dy'/dz residual (mrad)")
1554  if "CSC" in name:
1555  if param == "x": hist.SetYTitle("r#phi residual (mm)")
1556  if param == "dxdz": hist.SetYTitle("d(r#phi)/dz residual (mrad)")
1557  hist.SetMarkerColor(ROOT.kBlack)
1558  hist.SetLineColor(ROOT.kBlack)
1559  hist.Draw()
1560  hist2d.Draw("colzsame")
1561  if widebins: hist.Draw("samee1")
1562  else: hist.Draw("same")
1563 
1564  hpeaks.SetMarkerStyle(20)
1565  hpeaks.SetMarkerSize(0.9)
1566  hpeaks.SetMarkerColor(ROOT.kRed)
1567  hpeaks.SetLineColor(ROOT.kRed)
1568  hpeaks.SetLineWidth(2)
1569  #if fitpeaks: hpeaks.Draw("same")
1570  hpeaks.Draw("same")
1571 
1572  if fitsine and "vsphi" in name:
1573  global fitsine_const, fitsine_sin, fitsine_cos, fitsine_chi2, fitsine_ndf
1574  if 'CSC' in name:
1575  f = ROOT.TF1("f", "[0] + [1]*sin(x) + [2]*cos(x)", -pi/180.*5., pi*(2.-5./180.))
1576  else:
1577  f = ROOT.TF1("f", "[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
1578  f.SetLineColor(ROOT.kRed)
1579  f.SetLineWidth(2)
1580  if len(fixfitpars)>0:
1581  for fpar in fixfitpars.keys():
1582  f.FixParameter(fpar, fixfitpars[fpar])
1583  #hist.Fit(f,"N")
1584  if fitpeaks: hpeaks.Fit(f,"NQ")
1585  else: hist.Fit(f,"NEQ")
1586  if len(fixfitpars)>0:
1587  for fpar in fixfitpars.keys():
1588  f.ReleaseParameter(fpar)
1589  fitsine_const = f.GetParameter(0), f.GetParError(0)
1590  fitsine_sin = f.GetParameter(1), f.GetParError(1)
1591  fitsine_cos = f.GetParameter(2), f.GetParError(2)
1592  fitsine_chi2 = f.GetChisquare()
1593  fitsine_ndf = f.GetNDF()
1594  global MAP_RESULTS_FITSIN
1595  # 'phi' coefficienct will be updated further for CSC
1596  MAP_RESULTS_FITSIN[id] = {'a':fitsine_const, 'phi':fitsine_const, 'sin': fitsine_sin, 'cos': fitsine_cos, 'chi2': fitsine_chi2, 'ndf': fitsine_ndf}
1597  f.Draw("same")
1598  global fitsine_ttext, fitsine_etext
1599  text_xposition = -1.
1600  if 'CSC' in name: text_xposition = 2.
1601  fitsine_ttext = ROOT.TLatex(text_xposition, 0.8*window,
1602  "%+.3f %+.3f sin#phi %+.3f cos#phi" % (fitsine_const[0], fitsine_sin[0], fitsine_cos[0]))
1603  fitsine_ttext.SetTextColor(ROOT.kRed)
1604  fitsine_ttext.SetTextSize(0.05)
1605  fitsine_ttext.Draw()
1606  fitsine_etext = ROOT.TLatex(text_xposition, 0.70*window,
1607  " #pm%.3f #pm%.3f #pm%.3f" % (fitsine_const[1], fitsine_sin[1], fitsine_cos[1]))
1608  fitsine_etext.SetTextColor(ROOT.kRed)
1609  fitsine_etext.SetTextSize(0.045)
1610  fitsine_etext.Draw()
1611 
1612  # additional estimate of phiz ring rotation from 1d distribution
1613  if 'CSC' in name and add1d:
1614  # zero-order rough fit to obtain the fitting range:
1615  f0 = ROOT.TF1("f0", "gaus", hist1d.GetBinLowEdge(1), -hist1d.GetBinLowEdge(1))
1616  fit = hist1d.Fit(f0,"NRQ")
1617  rangea, rangeb = hist1d.GetMean() - hist1d.GetRMS(), hist1d.GetMean() + hist1d.GetRMS()
1618  if fit==0: rangea, rangeb = f0.GetParameter(1) - f0.GetParameter(2), f0.GetParameter(1) + f0.GetParameter(2)
1619  #print rangea, rangeb
1620 
1621  # second fit for finding the peak:
1622  f1 = ROOT.TF1("f1", "gaus", rangea, rangeb)
1623  fit = hist1d.Fit(f1,"NRQ")
1624  nn = hist1d.GetEntries()
1625  dphiz, ephiz = 0, 0
1626  if nn>0: dphiz, ephiz = hist1d.GetMean(), ROOT.TMath.StudentQuantile(0.841345,nn) * hist1d.GetRMS() / sqrt(nn)
1627  if fit==0: dphiz, ephiz = f1.GetParameter(1), f1.GetParError(1)
1628  #print dphiz, ephiz
1629  MAP_RESULTS_FITSIN[id]['phi'] = (dphiz, ephiz)
1630 
1631  global ttex_sine_, ttex_sine, ttex_1d_, ttex_1d
1632  postal_address = idToPostalAddress(id+'/01')
1633  ttex_sine_ = ROOT.TLatex(0, 0.8*window,"#Delta#phi_{z}^{sine} (mrad):")
1634  ttex_sine_.SetTextColor(ROOT.kGreen+2); ttex_sine_.SetTextSize(0.04); ttex_sine_.Draw()
1635  ttex_sine = ROOT.TLatex(0, 0.7*window," %+.3f#pm%.3f" %
1636  (-100*fitsine_const[0]/signConventions[postal_address][3],
1637  100*fitsine_const[1]/signConventions[postal_address][3]))
1638  ttex_sine.SetTextColor(ROOT.kGreen+2); ttex_sine.SetTextSize(0.04); ttex_sine.Draw()
1639  ttex_1d_ = ROOT.TLatex(0, 0.6*window,"#Delta#phi_{z}^{phi} (mrad):")
1640  ttex_1d_.SetTextColor(ROOT.kGreen+2); ttex_1d_.SetTextSize(0.04); ttex_1d_.Draw()
1641  ttex_1d = ROOT.TLatex(0, 0.5*window," %+.3f#pm%.3f" % (-dphiz, ephiz))
1642  ttex_1d.SetTextColor(ROOT.kGreen+2); ttex_1d.SetTextSize(0.04); ttex_1d.Draw()
1643  ROOT.gPad.Update()
1644 
1645  if fitline:
1646  f = ROOT.TF1("f", "[0] + [1]*x", -1000., 1000.)
1647  hist2d.Fit(f, "q")
1648  hist2d.GetFunction("f").SetLineColor(ROOT.kRed)
1649  global fitline_const, fitline_linear, fitline_chi2, fitline_ndf
1650  fitline_const = hist2d.GetFunction("f").GetParameter(0), hist2d.GetFunction("f").GetParError(0)
1651  fitline_linear = hist2d.GetFunction("f").GetParameter(1), hist2d.GetFunction("f").GetParError(1)
1652  fitline_chi2 = hist2d.GetFunction("f").GetChisquare()
1653  fitline_ndf = hist2d.GetFunction("f").GetNDF()
1654  hist2d.GetFunction("f").Draw("same")
1655  global fitline_ttext
1656  if "vsz" in name: which = "Z"
1657  elif "vsr" in name: which = "R"
1658  fitline_ttext = ROOT.TText(hist.GetBinCenter(hist.GetNbinsX()/4),
1659  0.8*window, "%.3g %+.3g %s" % (fitline_const[0], fitline_linear[0], which))
1660  fitline_ttext.SetTextColor(ROOT.kRed)
1661  fitline_ttext.Draw()
1662 
1663  ROOT.gPad.RedrawAxis()
1664 
1665  if "vsphi" in name:
1666  if not widebins: philines(name, window, abscissa)
1667  if abscissa is None:
1668  if 'CSC' in name:
1669  tline1 = ROOT.TLine(-pi/180.*5., 0, pi*(2.-5./180.), 0); tline1.Draw()
1670  tline2 = ROOT.TLine(-pi/180.*5., -window, pi*(2.-5./180.), -window); tline2.SetLineWidth(2); tline2.Draw()
1671  tline3 = ROOT.TLine(-pi/180.*5., window, pi*(2.-5./180.), window); tline3.Draw()
1672  else:
1673  tline1 = ROOT.TLine(-pi, 0, pi, 0); tline1.Draw()
1674  tline2 = ROOT.TLine(-pi, -window, pi, -window); tline2.SetLineWidth(2); tline2.Draw()
1675  tline3 = ROOT.TLine(-pi, window, pi, window); tline3.Draw()
1676  else:
1677  tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1678  tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1679  tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1680  elif "vsz" in name:
1681  if not widebins: zlines(window, abscissa)
1682  if abscissa is None:
1683  tline1 = ROOT.TLine(-660, 0, 660, 0); tline1.Draw()
1684  tline2 = ROOT.TLine(-660, -window, 660, -window); tline2.SetLineWidth(2); tline2.Draw()
1685  tline3 = ROOT.TLine(-660, window, 660, window); tline3.Draw()
1686  else:
1687  tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1688  tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1689  tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1690  elif "vsr" in name:
1691  if "mem1" in name or "mep1" in name and not widebins: rlines(1, window, abscissa)
1692  if "mem2" in name or "mep2" in name and not widebins: rlines(2, window, abscissa)
1693  if "mem3" in name or "mep3" in name and not widebins: rlines(3, window, abscissa)
1694  if "mem4" in name or "mep4" in name and not widebins: rlines(4, window, abscissa)
1695  if abscissa is None:
1696  tline1 = ROOT.TLine(100, 0, 700, 0); tline1.Draw()
1697  tline2 = ROOT.TLine(100, -window, 700, -window); tline2.SetLineWidth(2); tline2.Draw()
1698  tline3 = ROOT.TLine(100, window, 700, window); tline3.Draw()
1699  else:
1700  tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1701  tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1702  tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1703 
1704  if "vsphi" in name and fitsawteeth:
1705  global CPP_LOADED
1706  if not CPP_LOADED:
1707  phiedges2c()
1708  ROOT.gROOT.ProcessLine(".L phiedges_fitfunctions.C++")
1709  CPP_LOADED = True
1710  fn={0: ROOT.fitf0,
1711  1: ROOT.fitf2,
1712  2: ROOT.fitf2,
1713  3: ROOT.fitf3,
1714  4: ROOT.fitf4,
1715  5: ROOT.fitf5,
1716  6: ROOT.fitf6,
1717  7: ROOT.fitf7,
1718  8: ROOT.fitf8,
1719  9: ROOT.fitf9,
1720  10: ROOT.fitf10,
1721  11: ROOT.fitf11,
1722  12: ROOT.fitf12,
1723  13: ROOT.fitf13
1724  } [stationIndex(name)]
1725  fn.SetNpx(5000)
1726  fn.SetLineColor(ROOT.kYellow)
1727  hist.Fit(fn,"N")
1728  fn.Draw("same")
1729 
1730  # get properly arranged phi edges
1731  edges = (phiedges[stationIndex(name)])[:]
1732  ed = sorted(edges)
1733  # add some padding to the end
1734  ed.append(pi+abs(ed[0]))
1735 
1736  global sawtooth_a, sawtooth_b
1737  sawtooth_a = []
1738  sawtooth_da = []
1739  sawtooth_b = []
1740  for pr in range(0,fn.GetNpar(),2):
1741  sawtooth_a.append( (fn.GetParameter(pr), fn.GetParError(pr)) )
1742  sawtooth_b.append( (fn.GetParameter(pr+1), fn.GetParError(pr+1)) )
1743  sawtooth_da.append( (fn.Eval(ed[pr/2]+0.01), fn.Eval(ed[pr/2+1]-0.01)) )
1744  global MAP_RESULTS_SAWTOOTH
1745  MAP_RESULTS_SAWTOOTH[id] = {'a': sawtooth_a, 'da': sawtooth_da, 'b': sawtooth_b, 'chi2': fn.GetChisquare(), 'ndf': fn.GetNDF()}
1746 
1747  # fill number of contributiong bins
1748 
1749 
1750  #ROOT.SetOwnership(hist,False)
1751  ROOT.SetOwnership(hist2d,False)
1752  ROOT.SetOwnership(hist,False)
1753  ROOT.SetOwnership(tline1,False)
1754  ROOT.SetOwnership(tline2,False)
1755  ROOT.SetOwnership(tline3,False)
1756  return hist
1757 
1758 
1759 def mapNameToId(name):
1760  if "DT" in name:
1761  wh = "-ALL"
1762  if name.find('wh')>1: wh = name[name.find('wh')+2]
1763  if wh == "A": w = "-2"
1764  elif wh == "B": w = "-1"
1765  elif wh == "C": w = "-0"
1766  elif wh == "D": w = "+1"
1767  elif wh == "E": w = "+2"
1768  elif wh == "-ALL": w = "-ALL"
1769  else: return None
1770  station=''
1771  if wh == "-ALL":
1772  if name.find('sec')<0: return None
1773  station = name[name.find('sec')-1]
1774  sector = ''
1775  sector = name[name.find('sec')+3:name.find('sec')+5]
1776  return "MB%s/%s/%s" % (w, station, sector)
1777  if name.find('st')>1: station = name[name.find('st')+2]
1778  else: return None
1779  return "MB%s/%s" % (w, station)
1780  elif "CSC" in name:
1781  p = name.find('me')
1782  if p<0: return None
1783  if name[p+2]=="p": endcap = "+"
1784  elif name[p+2]=="m": endcap = "-"
1785  else: return None
1786  station = name[p+3]
1787  pch = name.find('ch')
1788  if pch<0:
1789  ring = name[p+4]
1790  return "ME%s%s/%s" % (endcap, station, ring)
1791  ring = 'ALL'
1792  chamber = name[pch+2:pch+4]
1793  return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
1794  return None
1795 
1796 
1797 ##################################################################################
1798 # "param" may be one of "deltax" (Delta x position residuals),
1799 # "deltadxdz" (Delta (dx/dz) angular residuals),
1800 # "curverr" (Delta x * d(Delta q/pT)/d(Delta x) = Delta q/pT in the absence of misalignment)
1801 
1802 def curvatureplot(tfiles, name, param, mode="from2d", window=15., widebins=False, title="", fitgauss=False, fitconst=False, fitline=False, fitpeaks=True, reset_palette=False):
1803  tdrStyle.SetOptTitle(1)
1804  tdrStyle.SetTitleBorderSize(0)
1805  tdrStyle.SetOptStat(0)
1806  tdrStyle.SetOptFit(0)
1807  tdrStyle.SetTitleFontSize(0.05)
1808 
1809  c1.Clear()
1810  if reset_palette: set_palette("blues")
1811  global hist, histCOPY, hist2d, tline1, tline2, tline3, tline4, tline5
1812 
1813  hdir = "AlignmentMonitorMuonVsCurvature/iter1/"
1814 
1815  if name not in ("all", "top", "bottom"):
1816  hsuffix = "_%s_%s" % (name, param)
1817  prof = tfiles[0].Get(hdir+"tprofile"+hsuffix).Clone("tprofile_"+hsuffix)
1818  hist2d = tfiles[0].Get(hdir+"th2f"+hsuffix).Clone("th2f_"+hsuffix)
1819  for tfile in tfiles[1:]:
1820  prof.Add(tfile.Get(hdir+"tprofile"+hsuffix))
1821  hist2d.Add(tfile.Get(hdir+"th2f"+hsuffix))
1822  else:
1823  prof = None
1824  hist2d = None
1825  for wheel in "m2", "m1", "z", "p1", "p2":
1826  if name == "all": sectors = "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"
1827  elif name == "top": sectors = "01", "02", "03", "04", "05", "06"
1828  elif name == "bottom": sectors = "07", "08", "09", "10", "11", "12"
1829  else: raise Exception
1830 
1831  for sector in sectors:
1832  hsuffix = "_%s_%s" % ("wheel%s_sector%s" % (wheel, sector), param)
1833  for tfile in tfiles:
1834  if prof is None:
1835  prof = tfiles[0].Get(hdir+"tprofile"+hsuffix).Clone("tprofile_"+hsuffix)
1836  hist2d = tfiles[0].Get(hdir+"th2f"+hsuffix).Clone("tprofile_"+hsuffix)
1837  else:
1838  prof.Add(tfile.Get(hdir+"tprofile"+hsuffix))
1839  hist2d.Add(tfile.Get(hdir+"th2f"+hsuffix))
1840 
1841  hist = ROOT.TH1F("hist", "", prof.GetNbinsX(), prof.GetBinLowEdge(1), -prof.GetBinLowEdge(1))
1842  for i in xrange(1, prof.GetNbinsX()+1):
1843  hist.SetBinContent(i, prof.GetBinContent(i))
1844  hist.SetBinError(i, prof.GetBinError(i))
1845 
1846  if mode == "plain":
1847  hist = prof
1848  elif mode == "from2d":
1849  skip = 1
1850  if widebins:
1851  hist.Rebin(5)
1852  skip = 5
1853  htmp = ROOT.gROOT.FindObject("tmp")
1854  if htmp != None: htmp.Delete()
1855 
1856  for i in xrange(0, int(prof.GetNbinsX()), skip):
1857  tmp = hist2d.ProjectionY("tmp", i+1, i + skip)
1858  if tmp.GetEntries() > 1:
1859  hist.SetBinContent(i/skip+1, tmp.GetMean())
1860  hist.SetBinError(i/skip+1, ROOT.TMath.StudentQuantile(0.841345,tmp.GetEntries()) * tmp.GetRMS() / sqrt(tmp.GetEntries()))
1861  #hist.SetBinError(i/skip+1, tmp.GetRMS() / sqrt(tmp.GetEntries()))
1862  else:
1863  #hist.SetBinContent(i/skip+1, 2000.)
1864  #hist.SetBinError(i/skip+1, 1000.)
1865  hist.SetBinContent(i/skip+1, 0.)
1866  hist.SetBinError(i/skip+1, 0.)
1867 
1868  hpeaks = createPeaksProfile(hist2d, skip)
1869 
1870  else:
1871  raise Exception
1872 
1873 
1874  if fitgauss:
1875  f = ROOT.TF1("f", "[0] + [1]*exp(-x**2/2/0.01**2)", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1876  f.SetParameters(0, 0., 0.01)
1877  if fitpeaks: hpeaks.Fit(f, "q")
1878  else: hist.Fit(f, "q")
1879  f.SetLineColor(ROOT.kRed)
1880  global fitgauss_diff, fitgauss_chi2, fitgauss_ndf
1881 # fitter = ROOT.TVirtualFitter.GetFitter()
1882 # fitgauss_diff = f.GetParameter(0) - f.GetParameter(1), \
1883 # sqrt(f.GetParError(0)**2 + f.GetParError(1)**2 + 2.*fitter.GetCovarianceMatrixElement(0, 1))
1884  fitgauss_diff = f.GetParameter(1), f.GetParError(1)
1885  fitgauss_chi2 = f.GetChisquare()
1886  fitgauss_ndf = f.GetNDF()
1887 
1888  global fitline_intercept, fitline_slope
1889  if fitconst:
1890  f = ROOT.TF1("f", "[0]", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1891  if fitpeaks: hpeaks.Fit(f, "q")
1892  else: hist.Fit(f, "q")
1893  f.SetLineColor(ROOT.kRed)
1894  fitline_intercept = f.GetParameter(0), f.GetParError(0)
1895 
1896  if fitline:
1897  f = ROOT.TF1("f", "[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1898  if fitpeaks: hpeaks.Fit(f, "qNE")
1899  else: hist.Fit(f, "qNE")
1900  f.SetLineColor(ROOT.kRed)
1901  global f2, f3
1902  f2 = ROOT.TF1("2", "[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1903  f3 = ROOT.TF1("2", "[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1904  f2.SetParameters(f.GetParameter(0), f.GetParameter(1) + f.GetParError(1))
1905  f3.SetParameters(f.GetParameter(0), f.GetParameter(1) - f.GetParError(1))
1906  f2.SetLineColor(ROOT.kRed)
1907  f3.SetLineColor(ROOT.kRed)
1908  f2.SetLineStyle(2)
1909  f3.SetLineStyle(2)
1910  fitline_intercept = f.GetParameter(0), f.GetParError(0)
1911  fitline_slope = f.GetParameter(1), f.GetParError(1)
1912 
1913  hist2d.SetAxisRange(-window, window, "Y")
1914  hist2d.SetMarkerStyle(20)
1915  hist2d.SetMarkerSize(0.75)
1916  hist2d.GetXaxis().CenterTitle()
1917  hist2d.GetYaxis().CenterTitle()
1918  if param == "curverr":
1919  hist2d.GetYaxis().SetTitleOffset(1.35)
1920  else:
1921  hist2d.GetYaxis().SetTitleOffset(0.75)
1922  hist2d.GetXaxis().SetTitleOffset(1.2)
1923  hist2d.GetXaxis().SetTitleSize(0.05)
1924  hist2d.GetYaxis().SetTitleSize(0.05)
1925  hist2d.SetTitle(title)
1926  if param == "pterr": hist2d.SetXTitle("qp_{T} (GeV/c)")
1927  else: hist2d.SetXTitle("q/p_{T} (c/GeV)")
1928  if param == "deltax": hist2d.SetYTitle("#Deltax' (mm)")
1929  if param == "deltadxdz": hist2d.SetYTitle("#Deltadx'/dz (mrad)")
1930  if param == "pterr": hist2d.SetYTitle("#Deltap_{T}/p_{T} (%)")
1931  if param == "curverr": hist2d.SetYTitle("#Deltaq/p_{T} (c/GeV)")
1932  hist2d.Draw("colz")
1933  hist.SetMarkerColor(ROOT.kBlack)
1934  hist.SetLineColor(ROOT.kBlack)
1935  hist.Draw("same")
1936  #histCOPY = hist.Clone()
1937  #histCOPY.SetXTitle("")
1938  #histCOPY.SetYTitle("")
1939 
1940  #if widebins:
1941  # histCOPY.Draw("samee1")
1942  # histCOPY.Draw("sameaxis")
1943  #else:
1944  # histCOPY.Draw("same")
1945  # histCOPY.Draw("sameaxis")
1946 
1947  if fitline:
1948  f.Draw("same")
1949  #f2.Draw("same")
1950  #f3.Draw("same")
1951 
1952  hpeaks.SetMarkerStyle(20)
1953  hpeaks.SetMarkerSize(0.9)
1954  hpeaks.SetMarkerColor(ROOT.kRed)
1955  hpeaks.SetLineColor(ROOT.kRed)
1956  hpeaks.SetLineWidth(2)
1957  #if fitpeaks: hpeaks.Draw("same")
1958  hpeaks.Draw("same")
1959 
1960  #tline1 = ROOT.TLine(hist.GetBinLowEdge(1), -window, hist.GetBinLowEdge(1), window)
1961  #tline2 = ROOT.TLine(hist.GetBinLowEdge(1), window, -hist.GetBinLowEdge(1), window)
1962  #tline3 = ROOT.TLine(-hist.GetBinLowEdge(1), window, -hist.GetBinLowEdge(1), -window)
1963  #tline4 = ROOT.TLine(-hist.GetBinLowEdge(1), -window, hist.GetBinLowEdge(1), -window)
1964  tline5 = ROOT.TLine(-hist.GetBinLowEdge(1), 0., hist.GetBinLowEdge(1), 0.)
1965  tline5.Draw()
1966  #for t in tline1, tline2, tline3, tline4, tline5: t.Draw()
1967 
1968 
1969 def curvatureDTsummary(tfiles, window=15., pdgSfactor=False):
1970  global h, gm2, gm1, gz, gp1, gp2, tlegend
1971 
1972  set_palette("blues")
1973  phis = {-2: [], -1: [], 0: [], 1: [], 2: []}
1974  diffs = {-2: [], -1: [], 0: [], 1: [], 2: []}
1975  differrs = {-2: [], -1: [], 0: [], 1: [], 2: []}
1976  for wheelstr, wheel in ("m2", "-2"), ("m1", "-1"), ("z", "0"), ("p1", "+1"), ("p2", "+2"):
1977  for sector in "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12":
1978  curvatureplot(tfiles, "wheel%s_sector%s" % (wheelstr, sector), "deltax",
1979  title="Wheel %s, sector %s" % (wheel, sector), fitgauss=True, reset_palette=False)
1980  if fitgauss_diff[1] < window:
1981  uncertainty = fitgauss_diff[1]
1982  if pdgSfactor and (fitgauss_chi2/fitgauss_ndf) > 1.: uncertainty *= sqrt(fitgauss_chi2/fitgauss_ndf)
1983 
1984  phis[int(wheel)].append(signConventions["DT", int(wheel), 1, int(sector)][4])
1985  diffs[int(wheel)].append(fitgauss_diff[0])
1986  differrs[int(wheel)].append(uncertainty)
1987 
1988  h = ROOT.TH1F("h", "", 1, -pi, pi)
1989  h.SetAxisRange(-window, window, "Y")
1990  h.SetXTitle("#phi (rad)")
1991  h.SetYTitle("#Deltax(p_{T} #rightarrow #infty) - #Deltax(p_{T} #rightarrow 0) (mm)")
1992  h.GetXaxis().CenterTitle()
1993  h.GetYaxis().CenterTitle()
1994 
1995  gm2 = ROOT.TGraphErrors(len(phis[-2]), array.array("d", phis[-2]), array.array("d", diffs[-2]),
1996  array.array("d", [0.]*len(phis[-2])), array.array("d", differrs[-2]))
1997  gm1 = ROOT.TGraphErrors(len(phis[-1]), array.array("d", phis[-1]), array.array("d", diffs[-1]),
1998  array.array("d", [0.]*len(phis[-1])), array.array("d", differrs[-1]))
1999  gz = ROOT.TGraphErrors(len(phis[0]), array.array("d", phis[0]), array.array("d", diffs[0]),
2000  array.array("d", [0.]*len(phis[0])), array.array("d", differrs[0]))
2001  gp1 = ROOT.TGraphErrors(len(phis[1]), array.array("d", phis[1]), array.array("d", diffs[1]),
2002  array.array("d", [0.]*len(phis[1])), array.array("d", differrs[1]))
2003  gp2 = ROOT.TGraphErrors(len(phis[2]), array.array("d", phis[2]), array.array("d", diffs[2]),
2004  array.array("d", [0.]*len(phis[2])), array.array("d", differrs[2]))
2005 
2006  gm2.SetMarkerStyle(21); gm2.SetMarkerColor(ROOT.kRed); gm2.SetLineColor(ROOT.kRed)
2007  gm1.SetMarkerStyle(22); gm1.SetMarkerColor(ROOT.kBlue); gm1.SetLineColor(ROOT.kBlue)
2008  gz.SetMarkerStyle(3); gz.SetMarkerColor(ROOT.kBlack); gz.SetLineColor(ROOT.kBlack)
2009  gp1.SetMarkerStyle(26); gp1.SetMarkerColor(ROOT.kBlue); gp1.SetLineColor(ROOT.kBlue)
2010  gp2.SetMarkerStyle(25); gp2.SetMarkerColor(ROOT.kRed); gp2.SetLineColor(ROOT.kRed)
2011 
2012  h.Draw()
2013  tlegend = ROOT.TLegend(0.25, 0.2, 0.85, 0.5)
2014  tlegend.SetFillColor(ROOT.kWhite)
2015  tlegend.SetBorderSize(0)
2016  tlegend.AddEntry(gm2, "Wheel -2", "p")
2017  tlegend.AddEntry(gm1, "Wheel -1", "p")
2018  tlegend.AddEntry(gz, "Wheel 0", "p")
2019  tlegend.AddEntry(gp1, "Wheel +1", "p")
2020  tlegend.AddEntry(gp2, "Wheel +2", "p")
2021  tlegend.Draw()
2022 
2023  gm2.Draw("p")
2024  gm1.Draw("p")
2025  gz.Draw("p")
2026  gp1.Draw("p")
2027  gp2.Draw("p")
2028 
2029 
2030 def getname(r):
2031  if r.postal_address[0] == "DT":
2032  wheel, station, sector = r.postal_address[1:]
2033  return "DT wheel %d, station %d, sector %d" % (wheel, station, sector)
2034  elif r.postal_address[0] == "CSC":
2035  endcap, station, ring, chamber = r.postal_address[1:]
2036  if endcap != 1: station = -1 * abs(station)
2037  return "CSC ME%d/%d chamber %d" % (station, ring, chamber)
2038 
2039 ddt=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
2040 def clearDDT():
2041  for i in range(0,15):
2042  ddt[i]=0.
2043 
2045  n = 0
2046  for t in ddt:
2047  if n==0 or n==7 or n==15: print "%d calls" % t
2048  else: print "%d : %0.3f ms" % (n,t*1000.0)
2049  n += 1
2050 
2051 def bellcurves(tfile, reports, name, twobin=True, suppressblue=False):
2052  t1 = time.time()
2053  ddt[0] += 1
2054  tdrStyle.SetOptTitle(1)
2055  tdrStyle.SetTitleBorderSize(1)
2056  tdrStyle.SetTitleFontSize(0.1)
2057  tdrStyle.SetOptStat(0)
2058  tdrStyle.SetHistMinimumZero()
2059 
2060  c1.Clear()
2061  c1.ResetAttPad()
2062 
2063  found = False
2064  for r in reports:
2065  if r.name == name:
2066  found = True
2067  break
2068  if not found: raise Exception("Not a valid name")
2069  if r.status == "FAIL":
2070  #raise Exception, "Fit failed"
2071  print "Fit failed"
2072  c1.Clear()
2073  return
2074 
2075  Pos = "Pos"; Neg = "Neg"
2076  if not twobin:
2077  Pos = ""; Neg = ""
2078 
2079  pdirPos = "MuonAlignmentFromReference/%s%s" % (name, Pos)
2080  pdirNeg = "MuonAlignmentFromReference/%s%s" % (name, Neg)
2081 
2082  t2 = time.time()
2083  ddt[1] = 1./ddt[0]*((ddt[0]-1)*ddt[1] + t2-t1)
2084 
2085  chamber_x = tfile.Get(pdirPos+"_x")
2086  chamber_x_fit = tfile.Get(pdirPos+"_x_fit")
2087  chamber_y = tfile.Get(pdirPos+"_y")
2088  chamber_y_fit = tfile.Get(pdirPos+"_y_fit")
2089  chamber_dxdz = tfile.Get(pdirPos+"_dxdz")
2090  chamber_dxdz_fit = tfile.Get(pdirPos+"_dxdz_fit")
2091  chamber_dydz = tfile.Get(pdirPos+"_dydz")
2092  chamber_dydz_fit = tfile.Get(pdirPos+"_dydz_fit")
2093  chamber_alphax = tfile.Get(pdirPos+"_alphax")
2094  chamber_alphax_fit = tfile.Get(pdirPos+"_alphax_fit")
2095  chamber_alphay = tfile.Get(pdirPos+"_alphay")
2096  chamber_alphay_fit = tfile.Get(pdirPos+"_alphay_fit")
2097  if twobin:
2098  chamber_x_fit2 = tfile.Get(pdirNeg+"_x_fit")
2099  chamber_y_fit2 = tfile.Get(pdirNeg+"_y_fit")
2100  chamber_dxdz_fit2 = tfile.Get(pdirNeg+"_dxdz_fit")
2101  chamber_dydz_fit2 = tfile.Get(pdirNeg+"_dydz_fit")
2102  chamber_alphax_fit2 = tfile.Get(pdirNeg+"_alphax_fit")
2103  chamber_alphay_fit2 = tfile.Get(pdirNeg+"_alphay_fit")
2104 
2105  if not chamber_x:
2106  chamber_x = tfile.Get(pdirPos+"_residual")
2107  chamber_x_fit = tfile.Get(pdirPos+"_residual_fit")
2108  chamber_dxdz = tfile.Get(pdirPos+"_resslope")
2109  chamber_dxdz_fit = tfile.Get(pdirPos+"_resslope_fit")
2110  chamber_alphax = tfile.Get(pdirPos+"_alpha")
2111  chamber_alphax_fit = tfile.Get(pdirPos+"_alpha_fit")
2112  if twobin:
2113  chamber_x_fit2 = tfile.Get(pdirNeg+"_residual_fit")
2114  chamber_dxdz_fit2 = tfile.Get(pdirNeg+"_resslope_fit")
2115  chamber_alphax_fit2 = tfile.Get(pdirNeg+"_alpha_fit")
2116 
2117  if not chamber_x:
2118  print "Can't find neither "+pdirPos+"_x nor "+pdirPos+"_residual"
2119  return
2120 
2121  t3 = time.time()
2122  ddt[2] = 1./ddt[0]*((ddt[0]-1)*ddt[2] + t3-t2)
2123 
2124  ####
2125  chamber_x.SetAxisRange(-50., 50., "X")
2126  if chamber_x.GetRMS()>15: chamber_x.SetAxisRange(-75., 75., "X")
2127  chamber_dxdz.SetAxisRange(-30., 30., "X")
2128  chamber_alphax.SetAxisRange(-50., 50., "X")
2129  if not not chamber_y:
2130  chamber_y.SetAxisRange(-75., 75., "X")
2131  chamber_dydz.SetAxisRange(-120., 120., "X")
2132  chamber_alphay.SetAxisRange(-120., 120., "X")
2133  chamber_alphay.SetAxisRange(-75., 75., "Y")
2134  ####
2135 
2136  chamber_x.SetXTitle("Local x residual (mm)")
2137  chamber_dxdz.SetXTitle("Local dx/dz residual (mrad)")
2138  chamber_alphax.SetXTitle("Local dx/dz residual (mrad)")
2139  chamber_alphax.SetYTitle("Local x residual (mm)")
2140  if not not chamber_y:
2141  chamber_y.SetXTitle("Local y residual (mm)")
2142  chamber_dydz.SetXTitle("Local dy/dz residual (mrad)")
2143  chamber_alphay.SetXTitle("Local dy/dz residual (mrad)")
2144  chamber_alphay.SetYTitle("Local y residual (mm)")
2145  if name[0:2] == "ME":
2146  chamber_x.SetXTitle("Local r#phi residual (mm)")
2147  chamber_dxdz.SetXTitle("Local d(r#phi)/dz residual (mrad)")
2148  chamber_alphax.SetXTitle("Local d(r#phi)/dz residual (mrad)")
2149  chamber_alphax.SetYTitle("Local r#phi residual (mm)")
2150 
2151  t4 = time.time()
2152  ddt[3] = 1./ddt[0]*((ddt[0]-1)*ddt[3] + t4-t3)
2153 
2154  for h in chamber_x, chamber_dxdz, chamber_alphax, chamber_alphax, \
2155  chamber_y, chamber_dydz, chamber_alphay, chamber_alphay:
2156  if not not h:
2157  h.GetXaxis().CenterTitle()
2158  h.GetYaxis().CenterTitle()
2159  h.GetXaxis().SetLabelSize(0.05)
2160  h.GetYaxis().SetLabelSize(0.05)
2161  h.GetXaxis().SetTitleSize(0.07)
2162  h.GetYaxis().SetTitleSize(0.07)
2163  h.GetXaxis().SetTitleOffset(0.9)
2164  h.GetYaxis().SetTitleOffset(0.9)
2165 
2166  if twobin:
2167  for f in chamber_x_fit2, chamber_y_fit2, chamber_dxdz_fit2, chamber_dydz_fit2, \
2168  chamber_alphax_fit2, chamber_alphay_fit2:
2169  if not not f:
2170  f.SetLineColor(4)
2171  if not twobin:
2172  suppressblue = True
2173 
2174  t5 = time.time()
2175  ddt[4] = 1./ddt[0]*((ddt[0]-1)*ddt[4] + t5-t4)
2176 
2177  global l1, l2, l3, l4
2178  if not not chamber_y:
2179  c1.Clear()
2180  c1.Divide(3, 2)
2181  chamber_x.SetTitle(getname(r))
2182 
2183  c1.GetPad(1).cd()
2184  chamber_x.Draw()
2185  if not suppressblue: chamber_x_fit2.Draw("same")
2186  chamber_x_fit.Draw("same")
2187  l1 = ROOT.TLatex(0.67,0.8,"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2188  chamber_x_fit.GetParameter(1), chamber_x_fit.GetParError(1),
2189  chamber_x_fit.GetParameter(2), chamber_x_fit.GetParError(2)))
2190  l1.Draw()
2191 
2192  c1.GetPad(2).cd()
2193  chamber_dxdz.Draw()
2194  if not suppressblue: chamber_dxdz_fit2.Draw("same")
2195  chamber_dxdz_fit.Draw("same")
2196  l2 = ROOT.TLatex(0.67,0.8,"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2197  chamber_dxdz_fit.GetParameter(1), chamber_dxdz_fit.GetParError(1),
2198  chamber_dxdz_fit.GetParameter(2), chamber_dxdz_fit.GetParError(2)))
2199  l2.Draw()
2200 
2201  c1.GetPad(3).cd()
2202  chamber_alphax.Draw("col")
2203  if not suppressblue: chamber_alphax_fit2.Draw("same")
2204  chamber_alphax_fit.Draw("same")
2205 
2206  c1.GetPad(4).cd()
2207  chamber_y.Draw()
2208  if not suppressblue: chamber_y_fit2.Draw("same")
2209  chamber_y_fit.Draw("same")
2210  l3 = ROOT.TLatex(0.67,0.8,"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2211  chamber_y_fit.GetParameter(1), chamber_y_fit.GetParError(1),
2212  chamber_y_fit.GetParameter(2), chamber_y_fit.GetParError(2)))
2213  l3.Draw()
2214 
2215  c1.GetPad(5).cd()
2216  chamber_dydz.Draw()
2217  if not suppressblue: chamber_dydz_fit2.Draw("same")
2218  chamber_dydz_fit.Draw("same")
2219  l4 = ROOT.TLatex(0.67,0.8,"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2220  chamber_dydz_fit.GetParameter(1), chamber_dydz_fit.GetParError(1),
2221  chamber_dydz_fit.GetParameter(2), chamber_dydz_fit.GetParError(2)))
2222  l4.Draw()
2223 
2224  for lb in l1,l2,l3,l4:
2225  lb.SetNDC(1)
2226  lb.SetTextColor(ROOT.kRed)
2227 
2228  c1.GetPad(6).cd()
2229  chamber_alphay.Draw("col")
2230  if not suppressblue: chamber_alphay_fit2.Draw("same")
2231  chamber_alphay_fit.Draw("same")
2232 
2233  else:
2234  c1.Clear()
2235  c1.Divide(3, 1)
2236  chamber_x.SetTitle(getname(r))
2237 
2238  c1.GetPad(1).cd()
2239  chamber_x.Draw()
2240  if not suppressblue: chamber_x_fit2.Draw("same")
2241  chamber_x_fit.Draw("same")
2242  l1 = ROOT.TLatex(0.67,0.8,"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2243  chamber_x_fit.GetParameter(1), chamber_x_fit.GetParError(1),
2244  chamber_x_fit.GetParameter(2), chamber_x_fit.GetParError(2)))
2245  l1.Draw()
2246 
2247  c1.GetPad(2).cd()
2248  chamber_dxdz.Draw()
2249  if not suppressblue: chamber_dxdz_fit2.Draw("same")
2250  chamber_dxdz_fit.Draw("same")
2251  l2 = ROOT.TLatex(0.67,0.8,"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2252  chamber_dxdz_fit.GetParameter(1), chamber_dxdz_fit.GetParError(1),
2253  chamber_dxdz_fit.GetParameter(2), chamber_dxdz_fit.GetParError(2)))
2254  l2.Draw()
2255 
2256  c1.GetPad(3).cd()
2257  chamber_alphax.Draw("col")
2258  if not suppressblue: chamber_alphax_fit2.Draw("same")
2259  chamber_alphax_fit.Draw("same")
2260 
2261  for lb in l1,l2:
2262  lb.SetNDC(1)
2263  lb.SetTextColor(ROOT.kRed)
2264 
2265  t6 = time.time()
2266  ddt[5] = 1./ddt[0]*((ddt[0]-1)*ddt[5] + t6-t5)
2267  ddt[6] = 1./ddt[0]*((ddt[0]-1)*ddt[6] + t6-t1)
2268 
2269 
2270 def polynomials(tfile, reports, name, twobin=True, suppressblue=False):
2271  t1 = time.time()
2272  ddt[7] += 1
2273  global label1, label2, label3, label4, label5, label6, label7, label8, label9
2274  plotDirectory = "MuonAlignmentFromReference"
2275  tdrStyle.SetOptTitle(1)
2276  tdrStyle.SetTitleBorderSize(1)
2277  tdrStyle.SetTitleFontSize(0.1)
2278  tdrStyle.SetOptStat(0)
2279 
2280  c1.Clear()
2281  c1.ResetAttPad()
2282 
2283  found = False
2284  for r in reports:
2285  if r.name == name:
2286  found = True
2287  break
2288  if not found: raise Exception("Not a valid name")
2289 
2290  if r.status == "FAIL":
2291  #raise Exception, "Fit failed"
2292  print "Fit failed"
2293  c1.Clear()
2294  return
2295 
2296  Pos = "Pos"; Neg = "Neg"
2297  if not twobin:
2298  Pos = ""; Neg = ""
2299 
2300  pdirPos = "MuonAlignmentFromReference/%s%s" % (name, Pos)
2301  pdirNeg = "MuonAlignmentFromReference/%s%s" % (name, Neg)
2302 
2303  global chamber_x_trackx, chamber_x_trackx_fit, chamber_y_trackx, chamber_y_trackx_fit, \
2304  chamber_dxdz_trackx, chamber_dxdz_trackx_fit, chamber_dydz_trackx, chamber_dydz_trackx_fit, \
2305  chamber_x_trackx_fit2, chamber_y_trackx_fit2, chamber_dxdz_trackx_fit2, chamber_dydz_trackx_fit2
2306  global chamber_x_tracky, chamber_x_tracky_fit, chamber_y_tracky, chamber_y_tracky_fit, \
2307  chamber_dxdz_tracky, chamber_dxdz_tracky_fit, chamber_dydz_tracky, chamber_dydz_tracky_fit, \
2308  chamber_x_tracky_fit2, chamber_y_tracky_fit2, chamber_dxdz_tracky_fit2, chamber_dydz_tracky_fit2
2309  global chamber_x_trackdxdz, chamber_x_trackdxdz_fit, chamber_y_trackdxdz, chamber_y_trackdxdz_fit, \
2310  chamber_dxdz_trackdxdz, chamber_dxdz_trackdxdz_fit, chamber_dydz_trackdxdz, chamber_dydz_trackdxdz_fit, \
2311  chamber_x_trackdxdz_fit2, chamber_y_trackdxdz_fit2, chamber_dxdz_trackdxdz_fit2, chamber_dydz_trackdxdz_fit2
2312  global chamber_x_trackdydz, chamber_x_trackdydz_fit, chamber_y_trackdydz, chamber_y_trackdydz_fit, \
2313  chamber_dxdz_trackdydz, chamber_dxdz_trackdydz_fit, chamber_dydz_trackdydz, chamber_dydz_trackdydz_fit, \
2314  chamber_x_trackdydz_fit2, chamber_y_trackdydz_fit2, chamber_dxdz_trackdydz_fit2, chamber_dydz_trackdydz_fit2
2315 
2316  chamber_x_trackx = tfile.Get(pdirPos+"_x_trackx")
2317  chamber_x_trackx_fit = tfile.Get(pdirPos+"_x_trackx_fitline")
2318  chamber_y_trackx = tfile.Get(pdirPos+"_y_trackx")
2319  chamber_y_trackx_fit = tfile.Get(pdirPos+"_y_trackx_fitline")
2320  chamber_dxdz_trackx = tfile.Get(pdirPos+"_dxdz_trackx")
2321  chamber_dxdz_trackx_fit = tfile.Get(pdirPos+"_dxdz_trackx_fitline")
2322  chamber_dydz_trackx = tfile.Get(pdirPos+"_dydz_trackx")
2323  chamber_dydz_trackx_fit = tfile.Get(pdirPos+"_dydz_trackx_fitline")
2324  chamber_x_trackx_fit2 = tfile.Get(pdirNeg+"_x_trackx_fitline")
2325  chamber_y_trackx_fit2 = tfile.Get(pdirNeg+"_y_trackx_fitline")
2326  chamber_dxdz_trackx_fit2 = tfile.Get(pdirNeg+"_dxdz_trackx_fitline")
2327  chamber_dydz_trackx_fit2 = tfile.Get(pdirNeg+"_dydz_trackx_fitline")
2328 
2329  chamber_x_tracky = tfile.Get(pdirPos+"_x_tracky")
2330  chamber_x_tracky_fit = tfile.Get(pdirPos+"_x_tracky_fitline")
2331  chamber_y_tracky = tfile.Get(pdirPos+"_y_tracky")
2332  chamber_y_tracky_fit = tfile.Get(pdirPos+"_y_tracky_fitline")
2333  chamber_dxdz_tracky = tfile.Get(pdirPos+"_dxdz_tracky")
2334  chamber_dxdz_tracky_fit = tfile.Get(pdirPos+"_dxdz_tracky_fitline")
2335  chamber_dydz_tracky = tfile.Get(pdirPos+"_dydz_tracky")
2336  chamber_dydz_tracky_fit = tfile.Get(pdirPos+"_dydz_tracky_fitline")
2337  chamber_x_tracky_fit2 = tfile.Get(pdirNeg+"_x_tracky_fitline")
2338  chamber_y_tracky_fit2 = tfile.Get(pdirNeg+"_y_tracky_fitline")
2339  chamber_dxdz_tracky_fit2 = tfile.Get(pdirNeg+"_dxdz_tracky_fitline")
2340  chamber_dydz_tracky_fit2 = tfile.Get(pdirNeg+"_dydz_tracky_fitline")
2341 
2342  chamber_x_trackdxdz = tfile.Get(pdirPos+"_x_trackdxdz")
2343  chamber_x_trackdxdz_fit = tfile.Get(pdirPos+"_x_trackdxdz_fitline")
2344  chamber_y_trackdxdz = tfile.Get(pdirPos+"_y_trackdxdz")
2345  chamber_y_trackdxdz_fit = tfile.Get(pdirPos+"_y_trackdxdz_fitline")
2346  chamber_dxdz_trackdxdz = tfile.Get(pdirPos+"_dxdz_trackdxdz")
2347  chamber_dxdz_trackdxdz_fit = tfile.Get(pdirPos+"_dxdz_trackdxdz_fitline")
2348  chamber_dydz_trackdxdz = tfile.Get(pdirPos+"_dydz_trackdxdz")
2349  chamber_dydz_trackdxdz_fit = tfile.Get(pdirPos+"_dydz_trackdxdz_fitline")
2350  chamber_x_trackdxdz_fit2 = tfile.Get(pdirNeg+"_x_trackdxdz_fitline")
2351  chamber_y_trackdxdz_fit2 = tfile.Get(pdirNeg+"_y_trackdxdz_fitline")
2352  chamber_dxdz_trackdxdz_fit2 = tfile.Get(pdirNeg+"_dxdz_trackdxdz_fitline")
2353  chamber_dydz_trackdxdz_fit2 = tfile.Get(pdirNeg+"_dydz_trackdxdz_fitline")
2354 
2355  chamber_x_trackdydz = tfile.Get(pdirPos+"_x_trackdydz")
2356  chamber_x_trackdydz_fit = tfile.Get(pdirPos+"_x_trackdydz_fitline")
2357  chamber_y_trackdydz = tfile.Get(pdirPos+"_y_trackdydz")
2358  chamber_y_trackdydz_fit = tfile.Get(pdirPos+"_y_trackdydz_fitline")
2359  chamber_dxdz_trackdydz = tfile.Get(pdirPos+"_dxdz_trackdydz")
2360  chamber_dxdz_trackdydz_fit = tfile.Get(pdirPos+"_dxdz_trackdydz_fitline")
2361  chamber_dydz_trackdydz = tfile.Get(pdirPos+"_dydz_trackdydz")
2362  chamber_dydz_trackdydz_fit = tfile.Get(pdirPos+"_dydz_trackdydz_fitline")
2363  chamber_x_trackdydz_fit2 = tfile.Get(pdirNeg+"_x_trackdydz_fitline")
2364  chamber_y_trackdydz_fit2 = tfile.Get(pdirNeg+"_y_trackdydz_fitline")
2365  chamber_dxdz_trackdydz_fit2 = tfile.Get(pdirNeg+"_dxdz_trackdydz_fitline")
2366  chamber_dydz_trackdydz_fit2 = tfile.Get(pdirNeg+"_dydz_trackdydz_fitline")
2367 
2368  if not chamber_x_trackx:
2369  chamber_x_trackx = tfile.Get(pdirPos+"_residual_trackx")
2370  chamber_x_trackx_fit = tfile.Get(pdirPos+"_residual_trackx_fitline")
2371  chamber_dxdz_trackx = tfile.Get(pdirPos+"_resslope_trackx")
2372  chamber_dxdz_trackx_fit = tfile.Get(pdirPos+"_resslope_trackx_fitline")
2373  chamber_x_trackx_fit2 = tfile.Get(pdirNeg+"_residual_trackx_fitline")
2374  chamber_dxdz_trackx_fit2 = tfile.Get(pdirNeg+"_resslope_trackx_fitline")
2375 
2376  chamber_x_tracky = tfile.Get(pdirPos+"_residual_tracky")
2377  chamber_x_tracky_fit = tfile.Get(pdirPos+"_residual_tracky_fitline")
2378  chamber_dxdz_tracky = tfile.Get(pdirPos+"_resslope_tracky")
2379  chamber_dxdz_tracky_fit = tfile.Get(pdirPos+"_resslope_tracky_fitline")
2380  chamber_x_tracky_fit2 = tfile.Get(pdirNeg+"_residual_tracky_fitline")
2381  chamber_dxdz_tracky_fit2 = tfile.Get(pdirNeg+"_resslope_tracky_fitline")
2382 
2383  chamber_x_trackdxdz = tfile.Get(pdirPos+"_residual_trackdxdz")
2384  chamber_x_trackdxdz_fit = tfile.Get(pdirPos+"_residual_trackdxdz_fitline")
2385  chamber_dxdz_trackdxdz = tfile.Get(pdirPos+"_resslope_trackdxdz")
2386  chamber_dxdz_trackdxdz_fit = tfile.Get(pdirPos+"_resslope_trackdxdz_fitline")
2387  chamber_x_trackdxdz_fit2 = tfile.Get(pdirNeg+"_residual_trackdxdz_fitline")
2388  chamber_dxdz_trackdxdz_fit2 = tfile.Get(pdirNeg+"_resslope_trackdxdz_fitline")
2389 
2390  chamber_x_trackdydz = tfile.Get(pdirPos+"_residual_trackdydz")
2391  chamber_x_trackdydz_fit = tfile.Get(pdirPos+"_residual_trackdydz_fitline")
2392  chamber_dxdz_trackdydz = tfile.Get(pdirPos+"_resslope_trackdydz")
2393  chamber_dxdz_trackdydz_fit = tfile.Get(pdirPos+"_resslope_trackdydz_fitline")
2394  chamber_x_trackdydz_fit2 = tfile.Get(pdirNeg+"_residual_trackdydz_fitline")
2395  chamber_dxdz_trackdydz_fit2 = tfile.Get(pdirNeg+"_resslope_trackdydz_fitline")
2396 
2397  if not chamber_x_trackx:
2398  print "Can't find neither "+pdirPos+"_residual nor "+pdirPos+"_residual_trackx"
2399  return
2400 
2401  chamber_x_trackx = chamber_x_trackx.Clone()
2402  chamber_dxdz_trackx = chamber_dxdz_trackx.Clone()
2403  chamber_x_tracky = chamber_x_tracky.Clone()
2404  chamber_dxdz_tracky = chamber_dxdz_tracky.Clone()
2405  chamber_x_trackdxdz = chamber_x_trackdxdz.Clone()
2406  chamber_dxdz_trackdxdz = chamber_dxdz_trackdxdz.Clone()
2407  chamber_x_trackdydz = chamber_x_trackdydz.Clone()
2408  chamber_dxdz_trackdydz = chamber_dxdz_trackdydz.Clone()
2409 
2410  if not not chamber_y_trackx:
2411  chamber_y_trackx = chamber_y_trackx.Clone()
2412  chamber_dydz_trackx = chamber_dydz_trackx.Clone()
2413  chamber_y_tracky = chamber_y_tracky.Clone()
2414  chamber_dydz_tracky = chamber_dydz_tracky.Clone()
2415  chamber_y_trackdxdz = chamber_y_trackdxdz.Clone()
2416  chamber_dydz_trackdxdz = chamber_dydz_trackdxdz.Clone()
2417  chamber_y_trackdydz = chamber_y_trackdydz.Clone()
2418  chamber_dydz_trackdydz = chamber_dydz_trackdydz.Clone()
2419 
2420  if not not chamber_y_trackx:
2421  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_trackx")); chamber_x_trackx.Merge(tlist)
2422  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_trackx")); chamber_dxdz_trackx.Merge(tlist)
2423  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_tracky")); chamber_x_tracky.Merge(tlist)
2424  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_tracky")); chamber_dxdz_tracky.Merge(tlist)
2425  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_trackdxdz")); chamber_x_trackdxdz.Merge(tlist)
2426  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_trackdxdz")); chamber_dxdz_trackdxdz.Merge(tlist)
2427  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_x_trackdydz")); chamber_x_trackdydz.Merge(tlist)
2428  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dxdz_trackdydz")); chamber_dxdz_trackdydz.Merge(tlist)
2429  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_trackx")); chamber_y_trackx.Merge(tlist)
2430  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_trackx")); chamber_dydz_trackx.Merge(tlist)
2431  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_tracky")); chamber_y_tracky.Merge(tlist)
2432  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_tracky")); chamber_dydz_tracky.Merge(tlist)
2433  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_trackdxdz")); chamber_y_trackdxdz.Merge(tlist)
2434  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_trackdxdz")); chamber_dydz_trackdxdz.Merge(tlist)
2435  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_y_trackdydz")); chamber_y_trackdydz.Merge(tlist)
2436  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_dydz_trackdydz")); chamber_dydz_trackdydz.Merge(tlist)
2437  else:
2438  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_trackx")); chamber_x_trackx.Merge(tlist)
2439  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_trackx")); chamber_dxdz_trackx.Merge(tlist)
2440  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_tracky")); chamber_x_tracky.Merge(tlist)
2441  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_tracky")); chamber_dxdz_tracky.Merge(tlist)
2442  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_trackdxdz")); chamber_x_trackdxdz.Merge(tlist)
2443  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_trackdxdz")); chamber_dxdz_trackdxdz.Merge(tlist)
2444  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_residual_trackdydz")); chamber_x_trackdydz.Merge(tlist)
2445  tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+"_resslope_trackdydz")); chamber_dxdz_trackdydz.Merge(tlist)
2446 
2447  rr1=10.
2448  rr2=10.
2449  chamber_x_trackx.SetAxisRange(-rr1, rr1, "Y")
2450  chamber_dxdz_trackx.SetAxisRange(-rr2, rr2, "Y")
2451  chamber_x_tracky.SetAxisRange(-rr1, rr1, "Y")
2452  chamber_dxdz_tracky.SetAxisRange(-rr2, rr2, "Y")
2453  chamber_x_trackdxdz.SetAxisRange(-rr1, rr1, "Y")
2454  chamber_dxdz_trackdxdz.SetAxisRange(-rr2, rr2, "Y")
2455  chamber_x_trackdydz.SetAxisRange(-rr1, rr1, "Y")
2456  chamber_dxdz_trackdydz.SetAxisRange(-rr2, rr2, "Y")
2457 
2458  rr3=10.
2459  if not not chamber_y_trackx:
2460  chamber_y_trackx.SetAxisRange(-rr3, rr3, "Y")
2461  chamber_dydz_trackx.SetAxisRange(-rr3, rr3, "Y")
2462  chamber_y_tracky.SetAxisRange(-rr3, rr3, "Y")
2463  chamber_dydz_tracky.SetAxisRange(-rr3, rr3, "Y")
2464  chamber_y_trackdxdz.SetAxisRange(-rr3, rr3, "Y")
2465  chamber_dydz_trackdxdz.SetAxisRange(-rr3, rr3, "Y")
2466  chamber_y_trackdydz.SetAxisRange(-rr3, rr3, "Y")
2467  chamber_dydz_trackdydz.SetAxisRange(-rr3, rr3, "Y")
2468 
2469  for h in chamber_x_trackx, chamber_y_trackx, chamber_dxdz_trackx, chamber_dydz_trackx, \
2470  chamber_x_tracky, chamber_y_tracky, chamber_dxdz_tracky, chamber_dydz_tracky, \
2471  chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz, \
2472  chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2473  if not not h:
2474  h.SetMarkerStyle(20)
2475  h.SetMarkerSize(0.5)
2476  h.GetXaxis().SetLabelSize(0.12)
2477  h.GetYaxis().SetLabelSize(0.12)
2478  h.GetXaxis().SetNdivisions(505)
2479  h.GetYaxis().SetNdivisions(505)
2480  h.GetXaxis().SetLabelOffset(0.03)
2481  h.GetYaxis().SetLabelOffset(0.03)
2482 
2483  trackdxdz_minimum, trackdxdz_maximum = None, None
2484  for h in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
2485  if not not h:
2486  for i in xrange(1, h.GetNbinsX()+1):
2487  if h.GetBinError(i) > 0.01 and h.GetBinContent(i) - h.GetBinError(i) < 10. and \
2488  h.GetBinContent(i) + h.GetBinError(i) > -10.:
2489  if not trackdxdz_minimum or trackdxdz_minimum > h.GetBinCenter(i):
2490  trackdxdz_minimum = h.GetBinCenter(i)
2491  if trackdxdz_maximum < h.GetBinCenter(i):
2492  trackdxdz_maximum = h.GetBinCenter(i)
2493  if not not trackdxdz_minimum and not not trackdxdz_maximum:
2494  for h in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
2495  if not not h:
2496  h.SetAxisRange(trackdxdz_minimum, trackdxdz_maximum, "X")
2497 
2498  trackdydz_minimum, trackdydz_maximum = None, None
2499  for h in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2500  if not not h:
2501  for i in xrange(1, h.GetNbinsX()+1):
2502  if h.GetBinError(i) > 0.01 and h.GetBinContent(i) - h.GetBinError(i) < 10. and \
2503  h.GetBinContent(i) + h.GetBinError(i) > -10.:
2504  if not trackdydz_minimum or trackdydz_minimum > h.GetBinCenter(i):
2505  trackdydz_minimum = h.GetBinCenter(i)
2506  if trackdydz_maximum < h.GetBinCenter(i):
2507  trackdydz_maximum = h.GetBinCenter(i)
2508  if not not trackdydz_minimum and not not trackdydz_maximum:
2509  for h in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2510  if not not h:
2511  h.SetAxisRange(trackdydz_minimum, trackdydz_maximum, "X")
2512 
2513  for f in chamber_x_trackx_fit2, chamber_y_trackx_fit2, chamber_dxdz_trackx_fit2, chamber_dydz_trackx_fit2, \
2514  chamber_x_tracky_fit2, chamber_y_tracky_fit2, chamber_dxdz_tracky_fit2, chamber_dydz_tracky_fit2, \
2515  chamber_x_trackdxdz_fit2, chamber_y_trackdxdz_fit2, chamber_dxdz_trackdxdz_fit2, chamber_dydz_trackdxdz_fit2, \
2516  chamber_x_trackdydz_fit2, chamber_y_trackdydz_fit2, chamber_dxdz_trackdydz_fit2, chamber_dydz_trackdydz_fit2:
2517  if not not f:
2518  f.SetLineColor(4)
2519 
2520  if not not chamber_y_trackx:
2521  c1.Clear()
2522  #c1.Divide(5, 5, 1e-5, 1e-5)
2523  pads = [None]
2524  pads.append(ROOT.TPad("p1" ,"",0.00,0.78,0.07,1.00,0,0,0))
2525  pads.append(ROOT.TPad("p2" ,"",0.07,0.78,0.34,1.00,0,0,0))
2526  pads.append(ROOT.TPad("p3" ,"",0.34,0.78,0.56,1.00,0,0,0))
2527  pads.append(ROOT.TPad("p4" ,"",0.56,0.78,0.78,1.00,0,0,0))
2528  pads.append(ROOT.TPad("p5" ,"",0.78,0.78,1.00,1.00,0,0,0))
2529  pads.append(ROOT.TPad("p6" ,"",0.00,0.56,0.07,0.78,0,0,0))
2530  pads.append(ROOT.TPad("p7" ,"",0.07,0.56,0.34,0.78,0,0,0))
2531  pads.append(ROOT.TPad("p8" ,"",0.34,0.56,0.56,0.78,0,0,0))
2532  pads.append(ROOT.TPad("p9" ,"",0.56,0.56,0.78,0.78,0,0,0))
2533  pads.append(ROOT.TPad("p10","",0.78,0.56,1.00,0.78,0,0,0))
2534  pads.append(ROOT.TPad("p11","",0.00,0.34,0.07,0.56,0,0,0))
2535  pads.append(ROOT.TPad("p12","",0.07,0.34,0.34,0.56,0,0,0))
2536  pads.append(ROOT.TPad("p13","",0.34,0.34,0.56,0.56,0,0,0))
2537  pads.append(ROOT.TPad("p14","",0.56,0.34,0.78,0.56,0,0,0))
2538  pads.append(ROOT.TPad("p15","",0.78,0.34,1.00,0.56,0,0,0))
2539  pads.append(ROOT.TPad("p16","",0.00,0.07,0.07,0.34,0,0,0))
2540  pads.append(ROOT.TPad("p17","",0.07,0.07,0.34,0.34,0,0,0))
2541  pads.append(ROOT.TPad("p18","",0.34,0.07,0.56,0.34,0,0,0))
2542  pads.append(ROOT.TPad("p19","",0.56,0.07,0.78,0.34,0,0,0))
2543  pads.append(ROOT.TPad("p20","",0.78,0.07,1.00,0.34,0,0,0))
2544  pads.append(ROOT.TPad("p21","",0.00,0.00,0.07,0.07,0,0,0))
2545  pads.append(ROOT.TPad("p22","",0.07,0.00,0.34,0.07,0,0,0))
2546  pads.append(ROOT.TPad("p23","",0.34,0.00,0.56,0.07,0,0,0))
2547  pads.append(ROOT.TPad("p24","",0.56,0.00,0.78,0.07,0,0,0))
2548  pads.append(ROOT.TPad("p25","",0.78,0.00,1.00,0.07,0,0,0))
2549  for p in pads:
2550  if not not p:
2551  p.Draw()
2552  ROOT.SetOwnership(p,False)
2553 
2554  label1 = ROOT.TPaveLabel(0, 0, 1, 1, "x residuals (mm)","")
2555  label2 = ROOT.TPaveLabel(0, 0, 1, 1, "y residuals (mm)","")
2556  label3 = ROOT.TPaveLabel(0, 0, 1, 1, "dx/dz residuals (mrad)","")
2557  label4 = ROOT.TPaveLabel(0, 0, 1, 1, "dy/dz residuals (mrad)","")
2558  label5 = ROOT.TPaveLabel(0, 0, 1, 1, "x position (cm)","")
2559  label6 = ROOT.TPaveLabel(0, 0, 1, 1, "y position (cm)","")
2560  label7 = ROOT.TPaveLabel(0, 0, 1, 1, "dx/dz angle (rad)","")
2561  label8 = ROOT.TPaveLabel(0, 0, 1, 1, "dy/dz angle (rad)","")
2562  label9 = ROOT.TPaveLabel(0, 0.85, 1, 1, getname(r),"NDC")
2563 
2564  for l in label1, label2, label3, label4, label5, label6, label7, label8, label9:
2565  l.SetBorderSize(0)
2566  l.SetFillColor(ROOT.kWhite)
2567 
2568  for l in label1, label2, label3, label4:
2569  l.SetTextAngle(90)
2570  l.SetTextSize(0.09)
2571 
2572  #label9.SetTextAngle(30)
2573  label9.SetTextSize(0.59)
2574 
2575  pads[1].cd(); label1.Draw()
2576  pads[6].cd(); label2.Draw()
2577  pads[11].cd(); label3.Draw()
2578  pads[16].cd(); label4.Draw()
2579  pads[22].cd(); label5.Draw()
2580  pads[23].cd(); label6.Draw()
2581  pads[24].cd(); label7.Draw()
2582  pads[25].cd(); label8.Draw()
2583 
2584  pads[2].SetRightMargin(1e-5)
2585  pads[2].SetBottomMargin(1e-5)
2586  pads[2].SetLeftMargin(0.17)
2587  pads[3].SetLeftMargin(1e-5)
2588  pads[3].SetRightMargin(1e-5)
2589  pads[3].SetBottomMargin(1e-5)
2590  pads[4].SetLeftMargin(1e-5)
2591  pads[4].SetRightMargin(1e-5)
2592  pads[4].SetBottomMargin(1e-5)
2593  pads[5].SetLeftMargin(1e-5)
2594  pads[5].SetBottomMargin(1e-5)
2595 
2596  pads[7].SetRightMargin(1e-5)
2597  pads[7].SetBottomMargin(1e-5)
2598  pads[7].SetTopMargin(1e-5)
2599  pads[7].SetLeftMargin(0.17)
2600  pads[8].SetLeftMargin(1e-5)
2601  pads[8].SetRightMargin(1e-5)
2602  pads[8].SetBottomMargin(1e-5)
2603  pads[8].SetTopMargin(1e-5)
2604  pads[9].SetLeftMargin(1e-5)
2605  pads[9].SetRightMargin(1e-5)
2606  pads[9].SetBottomMargin(1e-5)
2607  pads[9].SetTopMargin(1e-5)
2608  pads[10].SetLeftMargin(1e-5)
2609  pads[10].SetBottomMargin(1e-5)
2610  pads[10].SetTopMargin(1e-5)
2611 
2612  pads[12].SetRightMargin(1e-5)
2613  pads[12].SetBottomMargin(1e-5)
2614  pads[12].SetTopMargin(1e-5)
2615  pads[12].SetLeftMargin(0.17)
2616  pads[13].SetLeftMargin(1e-5)
2617  pads[13].SetRightMargin(1e-5)
2618  pads[13].SetBottomMargin(1e-5)
2619  pads[13].SetTopMargin(1e-5)
2620  pads[14].SetLeftMargin(1e-5)
2621  pads[14].SetRightMargin(1e-5)
2622  pads[14].SetBottomMargin(1e-5)
2623  pads[14].SetTopMargin(1e-5)
2624  pads[15].SetLeftMargin(1e-5)
2625  pads[15].SetBottomMargin(1e-5)
2626  pads[15].SetTopMargin(1e-5)
2627 
2628  pads[17].SetRightMargin(1e-5)
2629  pads[17].SetTopMargin(1e-5)
2630  pads[17].SetLeftMargin(0.17)
2631  pads[18].SetLeftMargin(1e-5)
2632  pads[18].SetRightMargin(1e-5)
2633  pads[18].SetTopMargin(1e-5)
2634  pads[19].SetLeftMargin(1e-5)
2635  pads[19].SetRightMargin(1e-5)
2636  pads[19].SetTopMargin(1e-5)
2637  pads[20].SetLeftMargin(1e-5)
2638  pads[20].SetTopMargin(1e-5)
2639 
2640  chamber_x_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2641  chamber_x_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2642  chamber_x_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2643  chamber_x_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2644  chamber_x_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2645  chamber_x_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2646  chamber_x_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2647  chamber_y_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2648  chamber_y_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2649  chamber_y_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2650  chamber_y_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2651  chamber_y_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2652  chamber_y_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2653  chamber_y_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2654  chamber_dxdz_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2655  chamber_dxdz_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2656  chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2657  chamber_dxdz_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2658  chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2659  chamber_dxdz_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2660  chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2661 
2662  # chamber_dydz_trackx
2663  chamber_dydz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2664  chamber_dydz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2665  chamber_dydz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2666 
2667  pads[2].cd()
2668  chamber_x_trackx.Draw("e1")
2669  if not suppressblue: chamber_x_trackx_fit2.Draw("samel")
2670  chamber_x_trackx_fit.Draw("samel")
2671  #label99 = ROOT.TPaveLabel(0, 0.8, 1, 1, getname(r),"NDC")
2672  print getname(r)
2673  #label99 = ROOT.TPaveLabel(0, 0.8, 1, 1, "aaa","NDC")
2674  label9.Draw()
2675  #pads[2].Modified()
2676 
2677  pads[3].cd()
2678  chamber_x_tracky.Draw("e1")
2679  if not suppressblue: chamber_x_tracky_fit2.Draw("samel")
2680  chamber_x_tracky_fit.Draw("samel")
2681 
2682  pads[4].cd()
2683  chamber_x_trackdxdz.Draw("e1")
2684  if not suppressblue: chamber_x_trackdxdz_fit2.Draw("samel")
2685  chamber_x_trackdxdz_fit.Draw("samel")
2686 
2687  pads[5].cd()
2688  chamber_x_trackdydz.Draw("e1")
2689  if not suppressblue: chamber_x_trackdydz_fit2.Draw("samel")
2690  chamber_x_trackdydz_fit.Draw("samel")
2691 
2692  pads[7].cd()
2693  chamber_y_trackx.Draw("e1")
2694  if not suppressblue: chamber_y_trackx_fit2.Draw("samel")
2695  chamber_y_trackx_fit.Draw("samel")
2696 
2697  pads[8].cd()
2698  chamber_y_tracky.Draw("e1")
2699  if not suppressblue: chamber_y_tracky_fit2.Draw("samel")
2700  chamber_y_tracky_fit.Draw("samel")
2701 
2702  pads[9].cd()
2703  chamber_y_trackdxdz.Draw("e1")
2704  if not suppressblue: chamber_y_trackdxdz_fit2.Draw("samel")
2705  chamber_y_trackdxdz_fit.Draw("samel")
2706 
2707  pads[10].cd()
2708  chamber_y_trackdydz.Draw("e1")
2709  if not suppressblue: chamber_y_trackdydz_fit2.Draw("samel")
2710  chamber_y_trackdydz_fit.Draw("samel")
2711 
2712  pads[12].cd()
2713  chamber_dxdz_trackx.Draw("e1")
2714  if not suppressblue: chamber_dxdz_trackx_fit2.Draw("samel")
2715  chamber_dxdz_trackx_fit.Draw("samel")
2716 
2717  pads[13].cd()
2718  chamber_dxdz_tracky.Draw("e1")
2719  if not suppressblue: chamber_dxdz_tracky_fit2.Draw("samel")
2720  chamber_dxdz_tracky_fit.Draw("samel")
2721 
2722  pads[14].cd()
2723  chamber_dxdz_trackdxdz.Draw("e1")
2724  if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw("samel")
2725  chamber_dxdz_trackdxdz_fit.Draw("samel")
2726 
2727  pads[15].cd()
2728  chamber_dxdz_trackdydz.Draw("e1")
2729  if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw("samel")
2730  chamber_dxdz_trackdydz_fit.Draw("samel")
2731 
2732  pads[17].cd()
2733  chamber_dydz_trackx.Draw("e1")
2734  if not suppressblue: chamber_dydz_trackx_fit2.Draw("samel")
2735  chamber_dydz_trackx_fit.Draw("samel")
2736 
2737  pads[18].cd()
2738  chamber_dydz_tracky.Draw("e1")
2739  if not suppressblue: chamber_dydz_tracky_fit2.Draw("samel")
2740  chamber_dydz_tracky_fit.Draw("samel")
2741 
2742  pads[19].cd()
2743  chamber_dydz_trackdxdz.Draw("e1")
2744  if not suppressblue: chamber_dydz_trackdxdz_fit2.Draw("samel")
2745  chamber_dydz_trackdxdz_fit.Draw("samel")
2746 
2747  pads[20].cd()
2748  chamber_dydz_trackdydz.Draw("e1")
2749  if not suppressblue: chamber_dydz_trackdydz_fit2.Draw("samel")
2750  chamber_dydz_trackdydz_fit.Draw("samel")
2751 
2752  else:
2753  c1.Clear()
2754  #c1.Divide(5, 3, 1e-5, 1e-5)
2755  pads = [None]
2756  pads.append(ROOT.TPad("p1" ,"",0.00,0.55,0.07,1.00,0,0,0))
2757  pads.append(ROOT.TPad("p2" ,"",0.07,0.55,0.34,1.00,0,0,0))
2758  pads.append(ROOT.TPad("p3" ,"",0.34,0.55,0.56,1.00,0,0,0))
2759  pads.append(ROOT.TPad("p4" ,"",0.56,0.55,0.78,1.00,0,0,0))
2760  pads.append(ROOT.TPad("p5" ,"",0.78,0.55,1.00,1.00,0,0,0))
2761  pads.append(ROOT.TPad("p6" ,"",0.00,0.1,0.07,0.55,0,0,0))
2762  pads.append(ROOT.TPad("p7" ,"",0.07,0.1,0.34,0.55,0,0,0))
2763  pads.append(ROOT.TPad("p8" ,"",0.34,0.1,0.56,0.55,0,0,0))
2764  pads.append(ROOT.TPad("p9" ,"",0.56,0.1,0.78,0.55,0,0,0))
2765  pads.append(ROOT.TPad("p10","",0.78,0.1,1.00,0.55,0,0,0))
2766  pads.append(ROOT.TPad("p11","",0.00,0.,0.07,0.1,0,0,0))
2767  pads.append(ROOT.TPad("p12","",0.07,0.,0.34,0.1,0,0,0))
2768  pads.append(ROOT.TPad("p13","",0.34,0.,0.56,0.1,0,0,0))
2769  pads.append(ROOT.TPad("p14","",0.56,0.,0.78,0.1,0,0,0))
2770  pads.append(ROOT.TPad("p15","",0.78,0.,1.00,0.1,0,0,0))
2771  for p in pads:
2772  if not not p:
2773  p.Draw()
2774  ROOT.SetOwnership(p,False)
2775 
2776  label1 = ROOT.TPaveLabel(0, 0, 1, 1, "x residuals (mm)")
2777  label2 = ROOT.TPaveLabel(0, 0, 1, 1, "dx/dz residuals (mrad)")
2778  label3 = ROOT.TPaveLabel(0, 0.3, 1, 1, "x position (cm)")
2779  label4 = ROOT.TPaveLabel(0, 0.3, 1, 1, "y position (cm)")
2780  label5 = ROOT.TPaveLabel(0, 0.3, 1, 1, "dx/dz angle (rad)")
2781  label6 = ROOT.TPaveLabel(0, 0.3, 1, 1, "dy/dz angle (rad)")
2782  label9 = ROOT.TPaveLabel(0, 0.85, 1, 1, getname(r),"NDC")
2783 
2784  if name[0:2] == "ME":
2785  label1 = ROOT.TPaveLabel(0, 0, 1, 1, "r#phi residuals (mm)")
2786  label2 = ROOT.TPaveLabel(0, 0, 1, 1, "d(r#phi)/dz residuals (mrad)")
2787 
2788  for l in label1, label2, label3, label4, label5, label6, label9:
2789  l.SetBorderSize(0)
2790  l.SetFillColor(ROOT.kWhite)
2791 
2792  for l in label1, label2:
2793  l.SetTextAngle(90)
2794  l.SetTextSize(0.09)
2795 
2796  #label9.SetTextAngle(30)
2797  label9.SetTextSize(0.29)
2798 
2799  pads[1].cd(); label1.Draw()
2800  pads[6].cd(); label2.Draw()
2801  pads[12].cd(); label3.Draw()
2802  pads[13].cd(); label4.Draw()
2803  pads[14].cd(); label5.Draw()
2804  pads[15].cd(); label6.Draw()
2805  #pads[11].cd(); label9.Draw()
2806 
2807  pads[2].SetRightMargin(1e-5)
2808  pads[2].SetBottomMargin(1e-5)
2809  pads[3].SetLeftMargin(1e-5)
2810  pads[3].SetRightMargin(1e-5)
2811  pads[3].SetBottomMargin(1e-5)
2812  pads[4].SetLeftMargin(1e-5)
2813  pads[4].SetRightMargin(1e-5)
2814  pads[4].SetBottomMargin(1e-5)
2815  pads[5].SetLeftMargin(1e-5)
2816  pads[5].SetBottomMargin(1e-5)
2817 
2818  pads[7].SetRightMargin(1e-5)
2819  pads[7].SetTopMargin(1e-5)
2820  pads[8].SetLeftMargin(1e-5)
2821  pads[8].SetRightMargin(1e-5)
2822  pads[8].SetTopMargin(1e-5)
2823  pads[9].SetLeftMargin(1e-5)
2824  pads[9].SetRightMargin(1e-5)
2825  pads[9].SetTopMargin(1e-5)
2826  pads[10].SetLeftMargin(1e-5)
2827  pads[10].SetTopMargin(1e-5)
2828 
2829  chamber_x_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2830  chamber_x_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2831  chamber_x_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2832  chamber_x_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2833  chamber_x_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2834  chamber_x_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2835  chamber_x_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2836  # chamber_dxdz_trackx
2837  chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2838  chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2839  chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2840 
2841  pads[2].cd()
2842  chamber_x_trackx.Draw("e1")
2843  if not suppressblue: chamber_x_trackx_fit2.Draw("samel")
2844  chamber_x_trackx_fit.Draw("samel")
2845  label9.Draw()
2846 
2847  pads[3].cd()
2848  chamber_x_tracky.Draw("e1")
2849  if not suppressblue: chamber_x_tracky_fit2.Draw("samel")
2850  chamber_x_tracky_fit.Draw("samel")
2851 
2852  pads[4].cd()
2853  chamber_x_trackdxdz.Draw("e1")
2854  if not suppressblue: chamber_x_trackdxdz_fit2.Draw("samel")
2855  chamber_x_trackdxdz_fit.Draw("samel")
2856 
2857  pads[5].cd()
2858  chamber_x_trackdydz.Draw("e1")
2859  if not suppressblue: chamber_x_trackdydz_fit2.Draw("samel")
2860  chamber_x_trackdydz_fit.Draw("samel")
2861 
2862  pads[7].cd()
2863  chamber_dxdz_trackx.Draw("e1")
2864  if not suppressblue: chamber_dxdz_trackx_fit2.Draw("samel")
2865  chamber_dxdz_trackx_fit.Draw("samel")
2866 
2867  pads[8].cd()
2868  chamber_dxdz_tracky.Draw("e1")
2869  if not suppressblue: chamber_dxdz_tracky_fit2.Draw("samel")
2870  chamber_dxdz_tracky_fit.Draw("samel")
2871 
2872  pads[9].cd()
2873  chamber_dxdz_trackdxdz.Draw("e1")
2874  if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw("samel")
2875  chamber_dxdz_trackdxdz_fit.Draw("samel")
2876 
2877  pads[10].cd()
2878  chamber_dxdz_trackdydz.Draw("e1")
2879  if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw("samel")
2880  chamber_dxdz_trackdydz_fit.Draw("samel")
2881 
2882  tn = time.time()
2883  ddt[8] = 1./ddt[7]*((ddt[7]-1)*ddt[8] + tn-t1)
2884 
2885 ##################################################################################
2886 
2887 def segdiff(tfiles, component, pair, **args):
2888  tdrStyle.SetOptFit(1)
2889  tdrStyle.SetOptTitle(1)
2890  tdrStyle.SetTitleBorderSize(1)
2891  tdrStyle.SetTitleFontSize(0.05)
2892  tdrStyle.SetStatW(0.2)
2893  tdrStyle.SetStatY(0.9)
2894  tdrStyle.SetStatFontSize(0.06)
2895 
2896  if component[0:2] == "dt":
2897  wheel = args["wheel"]
2898  wheelletter = wheelLetter(wheel)
2899  sector = args["sector"]
2900  profname = "%s_%s_%02d_%s" % (component, wheelletter, sector, str(pair))
2901  posname = "pos" + profname
2902  negname = "neg" + profname
2903  #print profname
2904 
2905  station1 = int(str(pair)[0])
2906  station2 = int(str(pair)[1])
2907  phi1 = signConventions["DT", wheel, station1, sector][4]
2908  phi2 = signConventions["DT", wheel, station2, sector][4]
2909  if abs(phi1 - phi2) > 1.:
2910  if phi1 > phi2: phi1 -= 2.*pi
2911  else: phi1 += 2.*pi
2912  phi = (phi1 + phi2) / 2.
2913  while (phi < -pi): phi += 2.*pi
2914  while (phi > pi): phi -= 2.*pi
2915 
2916  elif component[0:3] == "csc":
2917  endcap = args["endcap"]
2918  if endcap=="m":
2919  endcapnum=2
2920  endcapsign="-"
2921  elif endcap=="p":
2922  endcapnum=1
2923  endcapsign="+"
2924  else: raise Exception
2925 
2926  ring = args["ring"]
2927  if ring>2 or ring<1: raise Exception
2928  station1 = int(str(pair)[0])
2929  station2 = int(str(pair)[1])
2930  if ring==1: ringname="inner"
2931  elif ring==2: ringname="outer"
2932  else: raise Exception
2933 
2934  chamber = args["chamber"]
2935  if (ring==1 and chamber>18) or (ring==2 and chamber>36): raise Exception
2936 
2937  profname = "csc%s_%s_%s_%02d_%s" % (ringname,component[4:], endcap, chamber, str(pair))
2938  posname = "pos" + profname
2939  negname = "neg" + profname
2940  #print profname
2941 
2942  station1 = int(str(pair)[0])
2943  station2 = int(str(pair)[1])
2944  phi1 = signConventions["CSC", endcapnum, station1, ring, chamber][4]
2945  phi2 = signConventions["CSC", endcapnum, station2, ring, chamber][4]
2946  if abs(phi1 - phi2) > 1.:
2947  if phi1 > phi2: phi1 -= 2.*pi
2948  else: phi1 += 2.*pi
2949  phi = (phi1 + phi2) / 2.
2950  while (phi < -pi*5./180.): phi += 2.*pi
2951  while (phi > pi*(2.-5./180.)): phi -= 2.*pi
2952 
2953  else: raise Exception
2954 
2955  if "window" in args: window = args["window"]
2956  else: window = 5.
2957 
2958  global tmpprof, tmppos, tmpneg
2959  pdir = "AlignmentMonitorSegmentDifferences/iter1/"
2960  tmpprof = tfiles[0].Get(pdir + profname).Clone()
2961  tmpprof.SetMarkerStyle(8)
2962  tmppos = tfiles[0].Get(pdir + posname).Clone()
2963  tmpneg = tfiles[0].Get(pdir + negname).Clone()
2964  for tfile in tfiles[1:]:
2965  tmpprof.Add(tfile.Get(pdir + profname))
2966  tmppos.Add(tfile.Get(pdir + posname))
2967  tmpneg.Add(tfile.Get(pdir + negname))
2968 
2969  for i in xrange(1, tmpprof.GetNbinsX()+1):
2970  if tmpprof.GetBinError(i) < 1e-5:
2971  tmpprof.SetBinError(i, 100.)
2972  tmpprof.SetAxisRange(-window, window, "Y")
2973 
2974  f = ROOT.TF1("p1", "[0] + [1]*x", tmpprof.GetBinLowEdge(1), -tmpprof.GetBinLowEdge(1))
2975  f.SetParameters((tmppos.GetMean() + tmpneg.GetMean())/2., 0.)
2976 
2977  tmpprof.SetXTitle("q/p_{T} (c/GeV)")
2978  if component == "dt13_resid":
2979  tmpprof.SetYTitle("#Deltax^{local} (mm)")
2980  tmppos.SetXTitle("#Deltax^{local} (mm)")
2981  tmpneg.SetXTitle("#Deltax^{local} (mm)")
2982  f.SetParNames("#Deltax^{local}_{0}", "Slope")
2983  if component == "dt13_slope":
2984  tmpprof.SetYTitle("#Deltadx/dz^{local} (mrad)")
2985  tmppos.SetXTitle("#Deltadx/dz^{local} (mrad)")
2986  tmpneg.SetXTitle("#Deltadx/dz^{local} (mrad)")
2987  f.SetParNames("#Deltadx/dz^{local}_{0}", "Slope")
2988  if component == "dt2_resid":
2989  tmpprof.SetYTitle("#Deltay^{local} (mm)")
2990  tmppos.SetXTitle("#Deltay^{local} (mm)")
2991  tmpneg.SetXTitle("#Deltay^{local} (mm)")
2992  f.SetParNames("#Deltay^{local}_{0}", "Slope")
2993  if component == "dt2_slope":
2994  tmpprof.SetYTitle("#Deltady/dz^{local} (mrad)")
2995  tmppos.SetXTitle("#Deltady/dz^{local} (mrad)")
2996  tmpneg.SetXTitle("#Deltady/dz^{local} (mrad)")
2997  f.SetParNames("#Deltady/dz^{local}_{0}", "Slope")
2998  if component == "csc_resid":
2999  tmpprof.SetXTitle("q/p_{z} (c/GeV)")
3000  tmpprof.SetYTitle("#Delta(r#phi)^{local} (mm)")
3001  tmppos.SetXTitle("#Delta(r#phi)^{local} (mm)")
3002  tmpneg.SetXTitle("#Delta(r#phi)^{local} (mm)")
3003  f.SetParNames("#Delta(r#phi)^{local}_{0}", "Slope")
3004  if component == "csc_slope":
3005  tmpprof.SetXTitle("q/p_{z} (c/GeV)")
3006  tmpprof.SetYTitle("#Deltad(r#phi)/dz^{local} (mrad)")
3007  tmppos.SetXTitle("#Deltad(r#phi)/dz^{local} (mrad)")
3008  tmpneg.SetXTitle("#Deltad(r#phi)/dz^{local} (mrad)")
3009  f.SetParNames("#Deltad(r#phi)/dz^{local}_{0}", "Slope")
3010 
3011  tmpprof.GetXaxis().CenterTitle()
3012  tmpprof.GetYaxis().CenterTitle()
3013  tmppos.GetXaxis().CenterTitle()
3014  tmpneg.GetXaxis().CenterTitle()
3015  if component[0:2] == "dt":
3016  tmpprof.SetTitle("MB%d - MB%d, wheel %d, sector %02d" % (station1, station2, int(wheel), int(sector)))
3017  elif component[0:3] == "csc":
3018  tmpprof.SetTitle("ME%d - ME%d, for ME%s%d/%d/%d" % (station1, station2, endcapsign, station2, ring, chamber))
3019  else: raise Exception
3020 
3021  tmppos.SetTitle("Positive muons")
3022  tmpneg.SetTitle("Negative muons")
3023 
3024  c1.Clear()
3025  c1.Divide(2, 1)
3026  c1.GetPad(1).cd()
3027  fit1 = tmpprof.Fit("p1", "qS")
3028  tmpprof.Draw("e1")
3029  c1.GetPad(2).cd()
3030  c1.GetPad(2).Divide(1, 2)
3031  c1.GetPad(2).GetPad(1).cd()
3032  tmppos.Draw()
3033  f = ROOT.TF1("gausR", "[0]*exp(-(x - [1])**2 / 2. / [2]**2) / sqrt(2.*3.1415926) / [2]",
3034  tmppos.GetMean() - tmppos.GetRMS(), tmppos.GetMean() + tmppos.GetRMS())
3035  f.SetParameters(tmppos.GetEntries() * ((10. - -10.)/100.), tmppos.GetMean(), tmppos.GetRMS())
3036  f.SetParNames("Constant", "Mean", "Sigma")
3037  fit2 = tmppos.Fit("gausR", "qRS")
3038  c1.GetPad(2).GetPad(2).cd()
3039  tmpneg.Draw()
3040  f = ROOT.TF1("gausR", "[0]*exp(-(x - [1])**2 / 2. / [2]**2) / sqrt(2.*3.1415926) / [2]",
3041  tmpneg.GetMean() - tmpneg.GetRMS(), tmpneg.GetMean() + tmpneg.GetRMS())
3042  f.SetParameters(tmpneg.GetEntries() * ((10. - -10.)/100.), tmpneg.GetMean(), tmpneg.GetRMS())
3043  f.SetParNames("Constant", "Mean", "Sigma")
3044  fit3 = tmpneg.Fit("gausR", "qRS")
3045 
3046  fit1ok = fit1.Status()==0 and fit1.CovMatrixStatus()==3
3047  fit2ok = fit2.Status()==0 and fit2.CovMatrixStatus()==3
3048  fit3ok = fit3.Status()==0 and fit3.CovMatrixStatus()==3
3049 
3050  fitresult1 = None, None
3051  if fit1ok:
3052  fitresult1 = tmpprof.GetFunction("p1").GetParameter(0), tmpprof.GetFunction("p1").GetParError(0)
3053  fitresult2 = None, None
3054  if fit2ok and fit3ok:
3055  fitresult2 = (tmppos.GetFunction("gausR").GetParameter(1) + tmpneg.GetFunction("gausR").GetParameter(1)) / 2., \
3056  sqrt(tmppos.GetFunction("gausR").GetParError(1)**2 + tmpneg.GetFunction("gausR").GetParError(1)**2) / 2.
3057  return phi, fitresult1[0], fitresult1[1], fitresult2[0], fitresult2[1], fit1ok, fit2ok, fit3ok
3058 
3059 
3060 
3061 ##################################################################################
3062 
3063 def segdiff_xalign(tfiles, component, **args):
3064  tdrStyle.SetOptFit(1)
3065  tdrStyle.SetOptTitle(1)
3066  tdrStyle.SetTitleBorderSize(1)
3067  tdrStyle.SetTitleFontSize(0.05)
3068  tdrStyle.SetStatW(0.2)
3069  tdrStyle.SetStatY(0.9)
3070  tdrStyle.SetStatFontSize(0.06)
3071 
3072  if component[0:4] == "x_dt":
3073  wheel = int(args["wheel"])
3074  if int(wheel)<0:
3075  wheell = "m%d" % abs(wheel)
3076  endcapsign="-"
3077  else:
3078  wheell = "p%d" % abs(wheel)
3079  endcapsign="+"
3080  station_dt = component[4]
3081  station_csc_1 = args["cscstations"][0]
3082  if station_csc_1=='1': ring_1 = 3
3083  else: ring_1 = 2
3084  sector = args["sector"]
3085  profname = "%s%s_W%sS%02d" % (component, station_csc_1, wheell, sector)
3086  posname_1 = "pos_" + profname
3087  negname_1 = "neg_" + profname
3088  if len(args["cscstations"]) > 1:
3089  station_csc_2 = args["cscstations"][1]
3090  if station_csc_2=='1': ring_2 = 3
3091  else: ring_2 = 2
3092  profname = "%s%s_W%sS%02d" % (component, station_csc_2, wheell, sector)
3093  posname_2 = "pos_" + profname
3094  negname_2 = "neg_" + profname
3095 
3096  phi = signConventions["DT", wheel, int(station_dt), sector][4]
3097  while (phi < -pi): phi += 2.*pi
3098  while (phi > pi): phi -= 2.*pi
3099 
3100  else: raise Exception
3101 
3102  if "window" in args: window = args["window"]
3103  else: window = 5.
3104 
3105  global tmppos, tmpneg, tmppos_2, tmpneg_2
3106  pdir = "AlignmentMonitorSegmentDifferences/iter1/"
3107  tmppos = tfiles[0].Get(pdir + posname_1).Clone()
3108  tmpneg = tfiles[0].Get(pdir + negname_1).Clone()
3109  if len(args["cscstations"]) > 1:
3110  tmppos_2 = tfiles[0].Get(pdir + posname_2).Clone()
3111  tmpneg_2 = tfiles[0].Get(pdir + negname_2).Clone()
3112  tmpneg.Rebin(2); tmppos.Rebin(2)
3113  for tfile in tfiles[1:]:
3114  tmppos.Add(tfile.Get(pdir + posname_1))
3115  tmpneg.Add(tfile.Get(pdir + negname_1))
3116  if len(args["cscstations"]) > 1:
3117  tmppos_2.Add(tfile.Get(pdir + posname_2))
3118  tmpneg_2.Add(tfile.Get(pdir + negname_2))
3119  tmpneg_2.Rebin(2); tmppos_2.Rebin(2)
3120 
3121  result = {}
3122  result["fit_ok"] = False
3123  result["phi"] = phi
3124  ntot = tmppos.GetEntries() + tmpneg.GetEntries()
3125  if ntot == 0:
3126  return result
3127 
3128  tmppos.SetXTitle("#Deltax^{loc}_{MB} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{ME} (mm)")
3129  tmpneg.SetXTitle("#Deltax^{loc}_{MB} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{ME} (mm)")
3130  title1 = "MB(W%+d St%s Sec%d) - ME%s%s/%d" % (wheel, station_dt, int(sector), endcapsign, station_csc_1, ring_1)
3131  tmppos.SetTitle("Positive #mu: %s" % title1);
3132  tmpneg.SetTitle("Negative #mu: %s" % title1);
3133  tmppos.GetXaxis().CenterTitle()
3134  tmpneg.GetXaxis().CenterTitle()
3135  if len(args["cscstations"]) > 1:
3136  tmppos.SetXTitle("#Deltax^{loc}_{DT} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{CSC} (mm)")
3137  tmpneg.SetXTitle("#Deltax^{loc}_{DT} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{CSC} (mm)")
3138  title2 = "MB(W%+d St%s Sec%d) - ME%s%s/%d" % (wheel, station_dt, int(sector), endcapsign, station_csc_2, ring_2)
3139  tmppos_2.SetTitle("Positive #mu: %s" % title2);
3140  tmpneg_2.SetTitle("Negative #mu: %s" % title2);
3141  tmppos_2.GetXaxis().CenterTitle()
3142  tmpneg_2.GetXaxis().CenterTitle()
3143 
3144  c1.Clear()
3145  c1.Divide(2, 2)
3146 
3147  c1.GetPad(1).cd()
3148  tmppos.Draw()
3149  fpos = ROOT.TF1("gpos", "gaus", tmppos.GetMean() - tmppos.GetRMS(), tmppos.GetMean() + tmppos.GetRMS())
3150  fpos.SetParameters(tmppos.GetEntries() * 2.5, tmppos.GetMean(), tmppos.GetRMS())
3151  fit_pos = tmppos.Fit("gpos", "qRS")
3152 
3153  c1.GetPad(3).cd()
3154  tmpneg.Draw()
3155  fneg = ROOT.TF1("gneg", "gaus", tmpneg.GetMean() - tmpneg.GetRMS(), tmpneg.GetMean() + tmpneg.GetRMS())
3156  fneg.SetParameters(tmpneg.GetEntries() * 2.5, tmpneg.GetMean(), tmpneg.GetRMS())
3157  fit_neg = tmpneg.Fit("gneg", "qRS")
3158 
3159  result["fit_ok"] = (fit_pos.Status()==0 and fit_pos.CovMatrixStatus()==3 and fit_neg.Status()==0 and fit_neg.CovMatrixStatus()==3)
3160  result["fit_peak"] = (fpos.GetParameter(1)*tmppos.GetEntries() + fneg.GetParameter(1)*tmpneg.GetEntries()) / ntot
3161  result["fit_peak_error"] = sqrt( (fpos.GetParError(1)*tmppos.GetEntries())**2 + (fneg.GetParError(1)*tmpneg.GetEntries())**2) / ntot
3162 
3163  if len(args["cscstations"]) > 1:
3164  c1.GetPad(2).cd()
3165  tmppos_2.Draw()
3166  fpos_2 = ROOT.TF1("gpos2", "gaus", tmppos_2.GetMean() - tmppos_2.GetRMS(), tmppos_2.GetMean() + tmppos_2.GetRMS())
3167  fpos_2.SetParameters(tmppos_2.GetEntries() * 2.5, tmppos_2.GetMean(), tmppos_2.GetRMS())
3168  fit_pos_2 = tmppos_2.Fit("gpos2", "qRS")
3169 
3170  c1.GetPad(4).cd()
3171  tmpneg_2.Draw()
3172  fneg_2 = ROOT.TF1("gneg2", "gaus", tmpneg_2.GetMean() - tmpneg_2.GetRMS(), tmpneg_2.GetMean() + tmpneg_2.GetRMS())
3173  fneg_2.SetParameters(tmpneg_2.GetEntries() * 2.5, tmpneg_2.GetMean(), tmpneg_2.GetRMS())
3174  fit_neg_2 = tmpneg_2.Fit("gneg2", "qRS")
3175 
3176  result["fit_ok_2"] = (fit_pos_2.Status()==0 and fit_pos_2.CovMatrixStatus()==3 and fit_neg_2.Status()==0 and fit_neg_2.CovMatrixStatus()==3)
3177  ntot = tmppos_2.GetEntries() + tmpneg_2.GetEntries()
3178  result["fit_peak_2"] = (fpos_2.GetParameter(1)*tmppos_2.GetEntries() + fneg_2.GetParameter(1)*tmpneg_2.GetEntries()) / ntot
3179  result["fit_peak_error_2"] = sqrt( (fpos_2.GetParError(1)*tmppos_2.GetEntries())**2 + (fneg_2.GetParError(1)*tmpneg_2.GetEntries())**2) / ntot
3180 
3181  return result
3182 
3183 ##################################################################################
3184 
3185 def segdiffvsphi_xalign(tfiles, wheel, window=10.):
3186  tdrStyle.SetOptTitle(1)
3187  tdrStyle.SetTitleBorderSize(1)
3188  tdrStyle.SetTitleFontSize(0.05)
3189 
3190  global htemp, gtemp_12, gtemp_21, gtemp_11, tlegend
3191  htemp = ROOT.TH1F("htemp", "", 1, -pi, pi)
3192  gtemp_11_phi, gtemp_11_val, gtemp_11_err = [], [], []
3193  gtemp_12_phi, gtemp_12_val, gtemp_12_err = [], [], []
3194  gtemp_21_phi, gtemp_21_val, gtemp_21_err = [], [], []
3195  for sector in xrange(1, 12+1):
3196  #print "sect", sector
3197  r1 = segdiff_xalign(tfiles, "x_dt1_csc", wheel=wheel, sector=sector, cscstations = "12")
3198  r2 = segdiff_xalign(tfiles, "x_dt2_csc", wheel=wheel, sector=sector, cscstations = "1")
3199 
3200  if r1["fit_ok"]:
3201  gtemp_11_phi.append(r1["phi"])
3202  gtemp_11_val.append(r1["fit_peak"])
3203  gtemp_11_err.append(r1["fit_peak_error"])
3204  if r1["fit_ok_2"]:
3205  gtemp_12_phi.append(r1["phi"])
3206  gtemp_12_val.append(r1["fit_peak_2"])
3207  gtemp_12_err.append(r1["fit_peak_error_2"])
3208  if r2["fit_ok"]:
3209  gtemp_21_phi.append(r2["phi"])
3210  gtemp_21_val.append(r2["fit_peak"])
3211  gtemp_21_err.append(r2["fit_peak_error"])
3212 
3213  #print "len(gtemp_11_phi) ",len(gtemp_11_phi)
3214  #print "len(gtemp_12_phi) ",len(gtemp_12_phi)
3215  #print "len(gtemp_21_phi) ",len(gtemp_21_phi)
3216  if len(gtemp_11_phi) > 0:
3217  gtemp_11 = ROOT.TGraphErrors(len(gtemp_11_phi), array.array("d", gtemp_11_phi), array.array("d", gtemp_11_val),
3218  array.array("d", [0.] * len(gtemp_11_phi)), array.array("d", gtemp_11_err))
3219  if len(gtemp_12_phi) > 0:
3220  gtemp_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array("d", gtemp_12_phi), array.array("d", gtemp_12_val),
3221  array.array("d", [0.] * len(gtemp_12_phi)), array.array("d", gtemp_12_err))
3222  if len(gtemp_11_phi) > 0:
3223  gtemp_21 = ROOT.TGraphErrors(len(gtemp_21_phi), array.array("d", gtemp_21_phi), array.array("d", gtemp_21_val),
3224  array.array("d", [0.] * len(gtemp_21_phi)), array.array("d", gtemp_21_err))
3225 
3226  if len(gtemp_11_phi) > 0:
3227  gtemp_11.SetMarkerStyle(20); gtemp_11.SetMarkerSize(1.5);
3228  gtemp_11.SetMarkerColor(ROOT.kRed); gtemp_11.SetLineColor(ROOT.kRed)
3229  if len(gtemp_12_phi) > 0:
3230  gtemp_12.SetMarkerStyle(22); gtemp_12.SetMarkerSize(1.);
3231  gtemp_12.SetMarkerColor(ROOT.kGreen+2); gtemp_12.SetLineColor(ROOT.kGreen+2)
3232  if len(gtemp_21_phi) > 0:
3233  gtemp_21.SetMarkerStyle(21); gtemp_21.SetMarkerSize(1.5);
3234  gtemp_21.SetMarkerColor(ROOT.kBlue); gtemp_21.SetLineColor(ROOT.kBlue)
3235 
3236  htemp.SetTitle("Wheel %+d" % wheel)
3237  htemp.SetAxisRange(-window, window, "Y")
3238  htemp.SetXTitle("#phi of MB")
3239  htemp.SetYTitle("#Deltax^{loc}_{DT} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{CSC} (mm)")
3240  htemp.GetXaxis().CenterTitle()
3241  htemp.GetYaxis().CenterTitle()
3242  htemp.GetYaxis().SetTitleOffset(0.75)
3243 
3244  c1.Clear()
3245  htemp.Draw()
3246  if len(gtemp_12_phi) > 0:
3247  gtemp_12.Draw("p")
3248  if len(gtemp_21_phi) > 0:
3249  gtemp_21.Draw("p")
3250  if len(gtemp_11_phi) > 0:
3251  gtemp_11.Draw("p")
3252 
3253  tlegend = ROOT.TLegend(0.59, 0.75, 0.99, 0.92)
3254  tlegend.SetBorderSize(0)
3255  tlegend.SetFillColor(ROOT.kWhite)
3256  if len(gtemp_11_phi) > 0:
3257  tlegend.AddEntry(gtemp_11, "MB1 - ME1/3 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_11_val), stdev(gtemp_11_val)), "pl")
3258  if len(gtemp_21_phi) > 0:
3259  tlegend.AddEntry(gtemp_21, "MB2 - ME1/3 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_21_val), stdev(gtemp_21_val)), "pl")
3260  if len(gtemp_12_phi) > 0:
3261  tlegend.AddEntry(gtemp_12, "MB1 - ME2/2 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_12_val), stdev(gtemp_12_val)), "pl")
3262  #if len(gtemp_12_phi) > 0:
3263  # tlegend.AddEntry(gtemp_12, "total mean: %4.2f, total RMS: %4.2f" % \
3264  # (mean(gtemp_11_val + gtemp_12_val + gtemp_21_val),
3265  # stdev(gtemp_11_val + gtemp_12_val + gtemp_21_val)), "")
3266  tlegend.Draw()
3267 
3268  f_11 = ROOT.TF1("f11", "[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
3269  f_11.SetLineColor(ROOT.kRed)
3270  f_11.SetLineWidth(2)
3271  f_21 = ROOT.TF1("f21", "[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
3272  f_21.SetLineColor(ROOT.kBlue)
3273  f_21.SetLineWidth(2)
3274  if len(gtemp_11_phi) > 0:
3275  gtemp_11.Fit(f_11,"")
3276  if len(gtemp_21_phi) > 0:
3277  gtemp_21.Fit(f_21,"")
3278 
3279  global f_txt,f_11_txt, f_21_txt
3280  f_txt = ROOT.TLatex(-2.9, -0.7*window, "ME1/3 ring corrections equivalents:")
3281  f_txt.SetTextSize(0.028)
3282  f_txt.Draw()
3283  if len(gtemp_11_phi) > 0:
3284  rdt = signConventions[("DT", 2, 1, 1)][3]*10
3285  f_11_txt = ROOT.TLatex(-2.9, -0.8*window, "#Deltax=%.2f#pm%.2f mm #Deltay=%.2f#pm%.2f mm #Delta#phi_{z}=%.2f#pm%.2f mrad" % (
3286  -f_11.GetParameter(1), f_11.GetParError(1), f_11.GetParameter(2), f_11.GetParError(2), -f_11.GetParameter(0)/rdt*1000, f_11.GetParError(0)/rdt*1000))
3287  f_11_txt.SetTextSize(0.028)
3288  f_11_txt.SetTextColor(ROOT.kRed)
3289  f_11_txt.Draw()
3290  if len(gtemp_11_phi) > 0:
3291  rdt = signConventions[("DT", 2, 2, 1)][3]*10
3292  f_21_txt = ROOT.TLatex(-2.9, -0.9*window, "#Deltax=%.2f#pm%.2f mm #Deltay=%.2f#pm%.2f mm #Delta#phi_{z}=%.2f#pm%.2f mrad" % (
3293  -f_21.GetParameter(1), f_21.GetParError(1), f_21.GetParameter(2), f_21.GetParError(2), -f_21.GetParameter(0)/rdt*1000, f_21.GetParError(0)/rdt*1000))
3294  f_21_txt.SetTextSize(0.028)
3295  f_21_txt.SetTextColor(ROOT.kBlue)
3296  f_21_txt.Draw()
3297 
3298 ##################################################################################
3299 
3300 def segdiffvsphi(tfiles, reports, component, wheel, window=5., excludesectors=()):
3301  tdrStyle.SetOptTitle(1)
3302  tdrStyle.SetTitleBorderSize(1)
3303  tdrStyle.SetTitleFontSize(0.05)
3304 
3305  global htemp, gtemp_12, gtemp2_12, gtemp_23, gtemp2_23, gtemp_34, gtemp2_34, tlegend
3306  htemp = ROOT.TH1F("htemp", "", 1, -pi, pi)
3307  gtemp_12_phi, gtemp_12_val, gtemp_12_err, gtemp_12_val2, gtemp_12_err2 = [], [], [], [], []
3308  gtemp_23_phi, gtemp_23_val, gtemp_23_err, gtemp_23_val2, gtemp_23_err2 = [], [], [], [], []
3309  gtemp_34_phi, gtemp_34_val, gtemp_34_err, gtemp_34_val2, gtemp_34_err2 = [], [], [], [], []
3310  for sector in xrange(1, 12+1):
3311  #print "sect", sector
3312  r1_found, r2_found, r3_found, r4_found = False, False, False, False
3313  for r1 in reports:
3314  if r1.postal_address == ("DT", wheel, 1, sector):
3315  r1_found = True
3316  break
3317  for r2 in reports:
3318  if r2.postal_address == ("DT", wheel, 2, sector):
3319  r2_found = True
3320  break
3321  for r3 in reports:
3322  if r3.postal_address == ("DT", wheel, 3, sector):
3323  r3_found = True
3324  break
3325  for r4 in reports:
3326  if r4.postal_address == ("DT", wheel, 4, sector):
3327  r4_found = True
3328  break
3329  #print "rfounds: ", r1_found, r2_found, r3_found, r4_found
3330 
3331  if sector not in excludesectors:
3332  if r1_found and r2_found and r1.status == "PASS" and r2.status == "PASS":
3333  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, 12, wheel=wheel, sector=sector)
3334  #print "segdif 12", phi, val, err, val2, err2, fit1, fit2, fit3
3335  if fit1 and fit2 and fit3:
3336  gtemp_12_phi.append(phi)
3337  gtemp_12_val.append(val)
3338  gtemp_12_err.append(err)
3339  gtemp_12_val2.append(val2)
3340  gtemp_12_err2.append(err2)
3341  if r2_found and r3_found and r2.status == "PASS" and r3.status == "PASS":
3342  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, 23, wheel=wheel, sector=sector)
3343  #print "segdif 23", phi, val, err, val2, err2, fit1, fit2, fit3
3344  if fit1 and fit2 and fit3:
3345  gtemp_23_phi.append(phi)
3346  gtemp_23_val.append(val)
3347  gtemp_23_err.append(err)
3348  gtemp_23_val2.append(val2)
3349  gtemp_23_err2.append(err2)
3350  if component[:4] == "dt13":
3351  if r3_found and r4_found and r3.status == "PASS" and r4.status == "PASS":
3352  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, 34, wheel=wheel, sector=sector)
3353  #print "segdif 34", phi, val, err, val2, err2, fit1, fit2, fit3
3354  if fit1 and fit2 and fit3:
3355  gtemp_34_phi.append(phi)
3356  gtemp_34_val.append(val)
3357  gtemp_34_err.append(err)
3358  gtemp_34_val2.append(val2)
3359  gtemp_34_err2.append(err2)
3360 
3361  #print "len(gtemp_12_phi) ", len(gtemp_12_phi)
3362  #print "len(gtemp_23_phi) ",len(gtemp_23_phi)
3363  #print "len(gtemp_34_phi) ",len(gtemp_34_phi)
3364  if len(gtemp_12_phi) > 0:
3365  gtemp_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array("d", gtemp_12_phi), array.array("d", gtemp_12_val),
3366  array.array("d", [0.] * len(gtemp_12_phi)), array.array("d", gtemp_12_err))
3367  gtemp2_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array("d", gtemp_12_phi), array.array("d", gtemp_12_val2),
3368  array.array("d", [0.] * len(gtemp_12_phi)), array.array("d", gtemp_12_err2))
3369  if len(gtemp_23_phi) > 0:
3370  gtemp_23 = ROOT.TGraphErrors(len(gtemp_23_phi), array.array("d", gtemp_23_phi), array.array("d", gtemp_23_val),
3371  array.array("d", [0.] * len(gtemp_23_phi)), array.array("d", gtemp_23_err))
3372  gtemp2_23 = ROOT.TGraphErrors(len(gtemp_23_phi), array.array("d", gtemp_23_phi), array.array("d", gtemp_23_val2),
3373  array.array("d", [0.] * len(gtemp_23_phi)), array.array("d", gtemp_23_err2))
3374  if len(gtemp_34_phi) > 0:
3375  gtemp_34 = ROOT.TGraphErrors(len(gtemp_34_phi), array.array("d", gtemp_34_phi), array.array("d", gtemp_34_val),
3376  array.array("d", [0.] * len(gtemp_34_phi)), array.array("d", gtemp_34_err))
3377  gtemp2_34 = ROOT.TGraphErrors(len(gtemp_34_phi), array.array("d", gtemp_34_phi), array.array("d", gtemp_34_val2),
3378  array.array("d", [0.] * len(gtemp_34_phi)), array.array("d", gtemp_34_err2))
3379 
3380  if len(gtemp_12_phi) > 0:
3381  gtemp_12.SetMarkerStyle(20); gtemp_12.SetMarkerSize(1.);
3382  gtemp_12.SetMarkerColor(ROOT.kBlue); gtemp_12.SetLineColor(ROOT.kBlue)
3383  gtemp2_12.SetMarkerStyle(24); gtemp2_12.SetMarkerSize(1.);
3384  gtemp2_12.SetMarkerColor(ROOT.kBlue); gtemp2_12.SetLineColor(ROOT.kBlue)
3385  if len(gtemp_23_phi) > 0:
3386  gtemp_23.SetMarkerStyle(21); gtemp_23.SetMarkerSize(1.);
3387  gtemp_23.SetMarkerColor(ROOT.kRed); gtemp_23.SetLineColor(ROOT.kRed)
3388  gtemp2_23.SetMarkerStyle(25); gtemp2_23.SetMarkerSize(1.);
3389  gtemp2_23.SetMarkerColor(ROOT.kRed); gtemp2_23.SetLineColor(ROOT.kRed)
3390  if len(gtemp_34_phi) > 0 and component[:4] == "dt13":
3391  gtemp_34.SetMarkerStyle(22); gtemp_34.SetMarkerSize(1.25);
3392  gtemp_34.SetMarkerColor(ROOT.kGreen+2); gtemp_34.SetLineColor(ROOT.kGreen+2)
3393  gtemp2_34.SetMarkerStyle(26); gtemp2_34.SetMarkerSize(1.25);
3394  gtemp2_34.SetMarkerColor(ROOT.kGreen+2); gtemp2_34.SetLineColor(ROOT.kGreen+2)
3395 
3396  if wheel == 0: htemp.SetTitle("Wheel %d" % wheel)
3397  else: htemp.SetTitle("Wheel %+d" % wheel)
3398  htemp.SetAxisRange(-window, window, "Y")
3399  htemp.SetXTitle("Average #phi of pair (rad)")
3400  if component == "dt13_resid": htemp.SetYTitle("#Deltax^{local} (mm)")
3401  if component == "dt13_slope": htemp.SetYTitle("#Deltadx/dz^{local} (mrad)")
3402  if component == "dt2_resid": htemp.SetYTitle("#Deltay^{local} (mm)")
3403  if component == "dt2_slope": htemp.SetYTitle("#Deltady/dz^{local} (mrad)")
3404  htemp.GetXaxis().CenterTitle()
3405  htemp.GetYaxis().CenterTitle()
3406  htemp.GetYaxis().SetTitleOffset(0.75)
3407 
3408  c1.Clear()
3409  htemp.Draw()
3410  if len(gtemp_12_phi) > 0:
3411  gtemp_12.Draw("p")
3412  gtemp2_12.Draw("p")
3413  if len(gtemp_23_phi) > 0:
3414  gtemp_23.Draw("p")
3415  gtemp2_23.Draw("p")
3416  if len(gtemp_34_phi) > 0:
3417  gtemp_34.Draw("p")
3418  gtemp2_34.Draw("p")
3419 
3420  tlegend = ROOT.TLegend(0.5, 0.72, 0.9, 0.92)
3421  tlegend.SetBorderSize(0)
3422  tlegend.SetFillColor(ROOT.kWhite)
3423  if len(gtemp_12_phi) > 0:
3424  tlegend.AddEntry(gtemp_12, "MB1 - MB2 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_12_val), stdev(gtemp_12_val)), "pl")
3425  if len(gtemp_23_phi) > 0:
3426  tlegend.AddEntry(gtemp_23, "MB2 - MB3 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_23_val), stdev(gtemp_23_val)), "pl")
3427  if len(gtemp_34_phi) > 0:
3428  tlegend.AddEntry(gtemp_34, "MB3 - MB4 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_34_val), stdev(gtemp_34_val)), "pl")
3429  if len(gtemp_12_phi) > 0:
3430  tlegend.AddEntry(gtemp_12, "total mean: %4.2f, total RMS: %4.2f" % \
3431  (mean(gtemp_12_val + gtemp_23_val + gtemp_34_val),
3432  stdev(gtemp_12_val + gtemp_23_val + gtemp_34_val)), "")
3433  tlegend.Draw()
3434 
3435 
3436 ##################################################################################
3437 
3438 def segdiffvsphicsc(tfiles, component, pair, window=5., **args):
3439  tdrStyle.SetOptTitle(1)
3440  tdrStyle.SetTitleBorderSize(1)
3441  tdrStyle.SetTitleFontSize(0.05)
3442 
3443  if not component[0:3] == "csc": Exception
3444 
3445  endcap = args["endcap"]
3446  if endcap=="m":
3447  endcapnum=2
3448  endcapsign="-"
3449  elif endcap=="p":
3450  endcapnum=1
3451  endcapsign="+"
3452  else: raise Exception
3453 
3454  station1 = int(str(pair)[0])
3455  station2 = int(str(pair)[1])
3456  if not station2-station1==1: raise Exception
3457 
3458  rings = [1,2]
3459  if station2==4: rings = [1]
3460 
3461 
3462  global htemp, gtemp_1, gtemp2_1, gtemp_2, gtemp2_2, tlegend
3463  htemp = ROOT.TH1F("htemp", "", 1, -pi*5./180., pi*(2.-5./180.))
3464  gtemp_1_phi, gtemp_1_val, gtemp_1_err, gtemp_1_val2, gtemp_1_err2 = [], [], [], [], []
3465  gtemp_2_phi, gtemp_2_val, gtemp_2_err, gtemp_2_val2, gtemp_2_err2 = [], [], [], [], []
3466 
3467  for ring in rings:
3468  chambers = xrange(1,37)
3469  if ring == 1: chambers = xrange(1,19)
3470 
3471  for chamber in chambers:
3472  phi, val, err, val2, err2, fit1, fit2, fit3 = segdiff(tfiles, component, pair, endcap=endcap, ring=ring, chamber=chamber)
3473  if fit1 and fit2 and fit3:
3474  if ring==1:
3475  gtemp_1_phi.append(phi)
3476  gtemp_1_val.append(val)
3477  gtemp_1_err.append(err)
3478  gtemp_1_val2.append(val2)
3479  gtemp_1_err2.append(err2)
3480  if ring==2:
3481  gtemp_2_phi.append(phi)
3482  gtemp_2_val.append(val)
3483  gtemp_2_err.append(err)
3484  gtemp_2_val2.append(val2)
3485  gtemp_2_err2.append(err2)
3486 
3487  #print "len(gtemp_12_phi) ", len(gtemp_12_phi)
3488  #print "len(gtemp_23_phi) ",len(gtemp_23_phi)
3489  #print "len(gtemp_34_phi) ",len(gtemp_34_phi)
3490  if len(gtemp_1_phi) > 0:
3491  gtemp_1 = ROOT.TGraphErrors(len(gtemp_1_phi), array.array("d", gtemp_1_phi), array.array("d", gtemp_1_val),
3492  array.array("d", [0.] * len(gtemp_1_phi)), array.array("d", gtemp_1_err))
3493  gtemp2_1 = ROOT.TGraphErrors(len(gtemp_1_phi), array.array("d", gtemp_1_phi), array.array("d", gtemp_1_val2),
3494  array.array("d", [0.] * len(gtemp_1_phi)), array.array("d", gtemp_1_err2))
3495  if len(gtemp_2_phi) > 0:
3496  gtemp_2 = ROOT.TGraphErrors(len(gtemp_2_phi), array.array("d", gtemp_2_phi), array.array("d", gtemp_2_val),
3497  array.array("d", [0.] * len(gtemp_2_phi)), array.array("d", gtemp_2_err))
3498  gtemp2_2 = ROOT.TGraphErrors(len(gtemp_2_phi), array.array("d", gtemp_2_phi), array.array("d", gtemp_2_val2),
3499  array.array("d", [0.] * len(gtemp_2_phi)), array.array("d", gtemp_2_err2))
3500 
3501  if len(gtemp_1_phi) > 0:
3502  gtemp_1.SetMarkerStyle(20); gtemp_1.SetMarkerSize(1.);
3503  gtemp_1.SetMarkerColor(ROOT.kBlue); gtemp_1.SetLineColor(ROOT.kBlue)
3504  gtemp2_1.SetMarkerStyle(24); gtemp2_1.SetMarkerSize(1.);
3505  gtemp2_1.SetMarkerColor(ROOT.kBlue); gtemp2_1.SetLineColor(ROOT.kBlue)
3506  if len(gtemp_2_phi) > 0:
3507  gtemp_2.SetMarkerStyle(21); gtemp_2.SetMarkerSize(1.);
3508  gtemp_2.SetMarkerColor(ROOT.kRed); gtemp_2.SetLineColor(ROOT.kRed)
3509  gtemp2_2.SetMarkerStyle(25); gtemp2_2.SetMarkerSize(1.);
3510  gtemp2_2.SetMarkerColor(ROOT.kRed); gtemp2_2.SetLineColor(ROOT.kRed)
3511 
3512  htemp.SetTitle("ME%s%d - ME%s%d" % (endcapsign,station2,endcapsign,station1))
3513  htemp.SetAxisRange(-window, window, "Y")
3514  htemp.SetXTitle("Average #phi of pair (rad)")
3515  if component == "csc_resid": htemp.SetYTitle("#Delta(r#phi)^{local} (mm)")
3516  if component == "csc_slope": htemp.SetYTitle("#Deltad(r#phi)/dz^{local} (mrad)")
3517  htemp.GetXaxis().CenterTitle()
3518  htemp.GetYaxis().CenterTitle()
3519  htemp.GetYaxis().SetTitleOffset(0.75)
3520 
3521  c1.Clear()
3522  htemp.Draw()
3523  if len(gtemp_1_phi) > 0:
3524  gtemp_1.Draw("p")
3525  gtemp2_1.Draw("p")
3526  if len(gtemp_2_phi) > 0:
3527  gtemp_2.Draw("p")
3528  gtemp2_2.Draw("p")
3529 
3530  tlegend = ROOT.TLegend(0.5, 0.72, 0.9, 0.92)
3531  tlegend.SetBorderSize(0)
3532  tlegend.SetFillColor(ROOT.kWhite)
3533  if len(gtemp_1_phi) > 0:
3534  tlegend.AddEntry(gtemp_1, "ring 1 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_1_val), stdev(gtemp_1_val)), "pl")
3535  if len(gtemp_2_phi) > 0:
3536  tlegend.AddEntry(gtemp_2, "ring 2 (mean: %4.2f, RMS: %4.2f)" % (mean(gtemp_2_val), stdev(gtemp_2_val)), "pl")
3537  #if len(gtemp_12_phi) > 0:
3538  # tlegend.AddEntry(gtemp_12, "total mean: %4.2f, total RMS: %4.2f" % \
3539  # (mean(gtemp_12_val + gtemp_23_val + gtemp_34_val),
3540  # stdev(gtemp_12_val + gtemp_23_val + gtemp_34_val)), "")
3541  tlegend.Draw()
3542 
3543 
3544 
3545 ##################################################################################
3546 # makes a scatterplot of corrections coming either from reports (if xml geometries are None)
3547 # or from geometryX and geometryY (WRT the common initial geometry0)
3548 
3549 def corrections2D(reportsX=None, reportsY=None, geometry0=None, geometryX=None, geometryY=None,
3550  window=25., selection=None, name="tmp", canvas=None, pre_title_x=None, pre_title_y=None,
3551  which="110011"):
3552 
3553  tdrStyle.SetOptStat(0)
3554  tdrStyle.SetStatW(0.40)
3555 
3556  # determine what are we plotting: report vs report or xml vs xml
3557  mode = None
3558  check_reports = False
3559  if reportsX is not None and reportsY is not None:
3560  mode = "reports"
3561  check_reports = True
3562  if geometry0 is not None and geometryX is not None and geometryY is not None:
3563  mode = "xmls"
3564  if mode is None:
3565  print "Either couple of reports or three geometries have to be given as input. Exiting..."
3566  return
3567 
3568  # setup ranges with the maximum [-window,window] that later will be optimized to [-wnd_adaptive,wnd_adaptive]
3569  wnd = [window]*6
3570  wnd_adaptive = [.1]*6
3571 
3572  global hx, hy, hz, hphix, hphiy, hphiz
3573  bins=2000
3574  hx = ROOT.TH2F("%s_x" % name, "", bins, -wnd[0], wnd[0], bins, -wnd[0], wnd[0])
3575  hy = ROOT.TH2F("%s_y" % name, "", bins, -wnd[1], wnd[1], bins, -wnd[1], wnd[1])
3576  hz = ROOT.TH2F("%s_z" % name, "", bins, -wnd[2], wnd[2], bins, -wnd[2], wnd[2])
3577  hphix = ROOT.TH2F("%s_phix" % name, "", bins, -wnd[3], wnd[3], bins, -wnd[3], wnd[3])
3578  hphiy = ROOT.TH2F("%s_phiy" % name, "", bins, -wnd[4], wnd[4], bins, -wnd[4], wnd[4])
3579  hphiz = ROOT.TH2F("%s_phiz" % name, "", bins, -wnd[5], wnd[5], bins, -wnd[5], wnd[5])
3580  hhh = [hx, hy, hz, hphix, hphiy, hphiz]
3581 
3582  # initialize PCA objects
3583  global pca_x, pca_y, pca_z, pca_phix, pca_phiy, pca_phiz
3584  pca_x = ROOT.TPrincipal(2,"D")
3585  pca_y = ROOT.TPrincipal(2,"D")
3586  pca_z = ROOT.TPrincipal(2,"D")
3587  pca_phix = ROOT.TPrincipal(2,"D")
3588  pca_phiy = ROOT.TPrincipal(2,"D")
3589  pca_phiz = ROOT.TPrincipal(2,"D")
3590  pcas = [pca_x, pca_y, pca_z, pca_phix, pca_phiy, pca_phiz]
3591 
3592  # arrays to later fill graphs with
3593  ax=[]; ay=[]; az=[]; aphix=[]; aphiy=[]; aphiz=[]
3594  aaa = [ax, ay, az, aphix, aphiy, aphiz]
3595 
3596  # list of postal addresses
3597  postal_addresses = []
3598 
3599  # if reports are given, use them to fill addresses and do extra checks
3600  if check_reports:
3601  for r1 in reportsX:
3602  # skip ME1/a
3603  if r1.postal_address[0]=='CSC' and r1.postal_address[2]==1 and r1.postal_address[3]==4: continue
3604  if selection is None or (selection.__code__.co_argcount == len(r1.postal_address) and selection(*r1.postal_address)):
3605  r2 = getReportByPostalAddress(r1.postal_address, reportsY)
3606  if r2 is None:
3607  print "bad r2 in ",r1.postal_address
3608  continue
3609 
3610  if r1.status != "PASS" or r2.status != "PASS":
3611  print "bad status", r1.postal_address, r1.status, r2.status
3612  continue
3613  postal_addresses.append(r1.postal_address)
3614  # otherwise, use chamber addresses from xmls
3615  else:
3616  for key in geometry0.dt.keys():
3617  if len(key)==3 and key in geometryX.dt and key in geometryY.dt:
3618  postal_addresses.append( tuple(['DT'] + list(key)) )
3619  for key in geometry0.csc.keys():
3620  # skip ME1/a
3621  if key[2]==1 and key[3]==4: continue
3622  if len(key)==4 and key in geometryX.csc and key in geometryY.csc:
3623  postal_addresses.append( tuple(['CSC'] + list(key)) )
3624 
3625  # fill the values
3626  for addr in postal_addresses:
3627 
3628  # checks the selection function
3629  if not (selection is None or (selection.__code__.co_argcount == len(addr) and selection(*addr)) ): continue
3630 
3631  factors = [10. * signConventions[addr][0], 10. * signConventions[addr][1], 10. * signConventions[addr][2],
3632  1000., 1000., 1000. ]
3633 
3634  if check_reports:
3635  rX = getReportByPostalAddress(addr, reportsX)
3636  rY = getReportByPostalAddress(addr, reportsY)
3637  deltasX = [rX.deltax, rX.deltay, rX.deltaz, rX.deltaphix, rX.deltaphiy, rX.deltaphiz]
3638  deltasY = [rY.deltax, rY.deltay, rY.deltaz, rY.deltaphix, rY.deltaphiy, rY.deltaphiz]
3639 
3640  if mode == "reports":
3641 
3642  checks = map( lambda d1, d2: d1 is not None and d2 is not None and d1.error is not None \
3643  and d2.error is not None and (d1.error**2 + d2.error**2) > 0. , \
3644  deltasX, deltasY)
3645 
3646  for i in range(len(checks)):
3647  if not checks[i]: continue
3648  fillX = deltasX[i].value * factors[i]
3649  fillY = deltasY[i].value * factors[i]
3650  aaa[i].append([fillX,fillY])
3651  pcas[i].AddRow(array.array('d',[fillX,fillY]))
3652  mx = max(abs(fillX), abs(fillY))
3653  if mx > wnd_adaptive[i]: wnd_adaptive[i] = mx
3654 
3655  if mode == "xmls":
3656 
3657  db0 = dbX = dbY = None
3658  if addr[0] == "DT":
3659  db0, dbX, dbY = geometry0.dt[addr[1:]], geometryX.dt[addr[1:]], geometryY.dt[addr[1:]]
3660  if addr[0] == 'CSC':
3661  db0, dbX, dbY = geometry0.csc[addr[1:]], geometryX.csc[addr[1:]], geometryY.csc[addr[1:]]
3662 
3663  checks = [True]*6
3664  if check_reports:
3665  checks = map( lambda d1, d2: d1 is not None and d2 is not None , deltasX, deltasY)
3666 
3667  gdeltas0 = [db0.x, db0.y, db0.z, db0.phix, db0.phiy, db0.phiz]
3668  gdeltasX = [dbX.x, dbX.y, dbX.z, dbX.phix, dbX.phiy, dbX.phiz]
3669  gdeltasY = [dbY.x, dbY.y, dbY.z, dbY.phix, dbY.phiy, dbY.phiz]
3670 
3671  for i in range(len(checks)):
3672  if not checks[i]: continue
3673  fillX = (gdeltasX[i] - gdeltas0[i]) * factors[i]
3674  fillY = (gdeltasY[i] - gdeltas0[i]) * factors[i]
3675  aaa[i].append([fillX,fillY])
3676  pcas[i].AddRow(array.array('d',[fillX,fillY]))
3677  mx = max(abs(fillX), abs(fillY))
3678  if mx > wnd_adaptive[i]: wnd_adaptive[i] = mx
3679  #if addr[0] == 'CSC' and i==1 and (abs(fillX)>0.01 or abs(fillY)>0.01): print addr, ": hugeCSC i=%d dx=%.03g dy=%.03g"%(i,fillX,fillY)
3680  #if addr[0] == 'CSC' and i==2 and (abs(fillX)>0.02 or abs(fillY)>0.02): print addr, ": hugeCSC i=%d dx=%.03g dy=%.03g"%(i,fillX,fillY)
3681  #if addr[0] == 'CSC' and i==3 and (abs(fillX)>0.05 or abs(fillY)>0.05): print addr, ": hugeCSC i=%d dx=%.03g dy=%.03g"%(i,fillX,fillY)
3682 
3683  if mode == "xmls":
3684  if pre_title_x is None: pre_title_x = "geometry 1 "
3685  if pre_title_y is None: pre_title_y = "geometry 2 "
3686  if mode == "reports":
3687  if pre_title_x is None: pre_title_x = "iteration's "
3688  if pre_title_y is None: pre_title_y = "other iteration's "
3689  tmptitles = ["#Deltax (mm)", "#Deltay (mm)", "#Deltaz (mm)",
3690  "#Delta#phi_{x} (mrad)", "#Delta#phi_{y} (mrad)", "#Delta#phi_{z} (mrad)"]
3691  htitles = []
3692  for t in tmptitles: htitles.append([pre_title_x + t, pre_title_y + t])
3693 
3694  if canvas is not None: c = canvas
3695  else: c = c1
3696  c.Clear()
3697  ndraw = which.count('1')
3698  if ndraw > 4: c.Divide(3, 2)
3699  elif ndraw > 2: c.Divide(2, 2)
3700  elif ndraw > 1: c.Divide(2, 1)
3701 
3702  global lines, graphs, texs
3703  lines = []; graphs = []; texs = []
3704 
3705  ipad = 0
3706  for i in range(6):
3707 
3708  # decode 'which' binary mask
3709  if ( int(which,2) & (1<<i) ) == 0: continue
3710 
3711  ipad += 1
3712  c.GetPad(ipad).cd()
3713  c.GetPad(ipad).SetGridx(1)
3714  c.GetPad(ipad).SetGridy(1)
3715 
3716  wn = 1.08 * wnd_adaptive[i]
3717  hhh[i].GetXaxis().SetRangeUser(-wn, wn)
3718  hhh[i].GetYaxis().SetRangeUser(-wn, wn)
3719  hhh[i].SetXTitle(htitles[i][0])
3720  hhh[i].SetYTitle(htitles[i][1])
3721  hhh[i].GetXaxis().CenterTitle()
3722  hhh[i].GetYaxis().CenterTitle()
3723  hhh[i].Draw()
3724 
3725  if len(aaa[i]) == 0: continue
3726 
3727  a1, a2 = map( lambda x: array.array('d',x), list(zip(*aaa[i])) )
3728  g = ROOT.TGraph(len(a1), a1, a2)
3729  g.SetMarkerStyle(5)
3730  g.SetMarkerSize(0.3)
3731  g.SetMarkerColor(ROOT.kBlue)
3732  graphs.append(g)
3733 
3734  pcas[i].MakePrincipals()
3735  #pcas[i].Print()
3736  #pcas[i].MakeHistograms()
3737  b = pcas[i].GetEigenVectors()(1,0) / pcas[i].GetEigenVectors()(0,0)
3738  a = pcas[i].GetMeanValues()[1] - b * pcas[i].GetMeanValues()[0]
3739  #print a, b, " ", pcas[i].GetEigenValues()[0], pcas[i].GetEigenValues()[1]
3740 
3741  cov = pcas[i].GetCovarianceMatrix()
3742  r = cov(0,1)/sqrt(cov(1,1)*cov(0,0))
3743  print "r, RMSx, RMSy =", r, g.GetRMS(1), g.GetRMS(2)
3744  texrms = ROOT.TLatex(0.17,0.87, "RMS x,y = %.02g, %.02g" % (g.GetRMS(1),g.GetRMS(2)))
3745  texr = ROOT.TLatex(0.17,0.80, "r = %.02g" % r)
3746  for t in texr, texrms:
3747  t.SetNDC(1)
3748  t.SetTextColor(ROOT.kBlue)
3749  t.SetTextSize(0.053)
3750  t.Draw()
3751  texs.append(t)
3752 
3753  g.Draw("p")
3754 
3755  if not isnan(b):
3756  wn = wnd_adaptive[i]
3757  line = ROOT.TLine(-wn, a - b*wn, wn, a + b*wn)
3758  line.SetLineColor(ROOT.kRed)
3759  line.Draw()
3760  lines.append(line)
3761 
3762  #return hx, hy, hphiy, hphiz, pca_x, pca_y, pca_phiy, pca_phiz
3763  return aaa
def rlines(disk, window, abscissa)
Definition: plotscripts.py:453
def writeDQMReport(fname_dqm, run_name)
def Divide(hNum, hDen)
def mean(xlist)
Definition: plotscripts.py:53
def testZeroWithin5Sigma(x)
def segdiffvsphi_xalign(tfiles, wheel, window=10.)
def DBdiffVersus(quantity, versus, database1, database2, reports1, reports2, windwselection=None, color=ROOT.kBlack)
Definition: plotscripts.py:718
def wheelm1only(dt, wheel, station, sector)
Definition: plotscripts.py:32
def saveTestResultsMap(run_name)
def curvatureplot(tfiles, name, param, mode="from2d", window=15., widebins=False, title="", fitgauss=False, fitconst=False, fitline=False, fitpeaks=True, reset_palette=False)
"param" may be one of "deltax" (Delta x position residuals), "deltadxdz" (Delta (dx/dz) angular resid...
def rms(xlist)
Definition: plotscripts.py:60
selection
main part
Definition: corrVsCorr.py:98
def philines(name, window, abscissa)
Definition: plotscripts.py:392
def availableCellsCSC(reports)
Definition: plotscripts.py:963
def doTests(reports, pic_ids, fname_base, fname_dqm, run_name)
def clearDDT()
def DBMC(database, reports, window=10., windows=None, selection=None, phi=False, color=ROOT.kBlue-8, style=1, bins=50, normalized=False, getvalues=False, name="", canvas=None, reportdiff=False, inlog=True)
Definition: plotscripts.py:476
def DBdiff(database1, database2, reports1, reports2, window=10., windows=None, selection=None, phi=False, color=ROOT.kBlue-8, style=1, bins=50, normalized=False, getvalues=False, name="tmp", canvas=None, reportdiff=False, inlog=False)
Definition: plotscripts.py:483
def postalAddressToId(postal_address)
Definition: plotscripts.py:882
def corrections2D(reportsX=None, reportsY=None, geometry0=None, geometryX=None, geometryY=None, window=25., selection=None, name="tmp", canvas=None, pre_title_x=None, pre_title_y=None, which="110011")
makes a scatterplot of corrections coming either from reports (if xml geometries are None) or from ge...
def segdiff_xalign(tfiles, component, args)
def printDeltaTs()
def doTestsForMapPlots(cells)
def nameToId(name)
Definition: plotscripts.py:894
def DBMCVersus(quantity, versus, database, reports, window=10., selection=None, color=ROOT.kBlack)
Definition: plotscripts.py:715
def wheelNumber(wheell)
Definition: plotscripts.py:45
def mapplot(tfiles, name, param, mode="from2d", window=10., abscissa=None, title="", widebins=False, fitsine=False, fitline=False, reset_palette=False, fitsawteeth=False, fitpeaks=False, peaksbins=1, fixfitpars={}, args)
bool isnan(float x)
Definition: math.h:13
def getname(r)
def wheelm2only(dt, wheel, station, sector)
Convenience functions.
Definition: plotscripts.py:31
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
T sqrt(T t)
Definition: SSEVec.h:18
def setTDRStyle()
Definition: plotscripts.py:87
def segdiffvsphicsc(tfiles, component, pair, window=5., args)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
def stationIndex(name)
Definition: plotscripts.py:353
def segdiffvsphi(tfiles, reports, component, wheel, window=5., excludesectors=())
def loadTestResultsMap(run_name)
def polynomials(tfile, reports, name, twobin=True, suppressblue=False)
def testDeltaWithin5Sigma(x, sx)
def bellcurves(tfile, reports, name, twobin=True, suppressblue=False)
def availableCellsDT(reports)
Definition: plotscripts.py:917
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def wheelp2only(dt, wheel, station, sector)
Definition: plotscripts.py:35
def testEntry(testID, scope, descr, severity)
def createPeaksProfile(the2d, rebin=1)
def __call__(self, xx, par)
Definition: plotscripts.py:337
def curvatureDTsummary(tfiles, window=15., pdgSfactor=False)
def doTestsForReport(cells, reports)
def segdiff(tfiles, component, pair, args)
def mapNameToId(name)
def zlines(window, abscissa)
Definition: plotscripts.py:436
def wheel0only(dt, wheel, station, sector)
Definition: plotscripts.py:33
def wmean(xlist)
Definition: plotscripts.py:75
def stdev(xlist)
Definition: plotscripts.py:67
def wheelLetter(wheel)
Definition: plotscripts.py:37
def set_palette(name=None, ncontours=999)
Definition: plotscripts.py:226
def idToPostalAddress(id)
Definition: plotscripts.py:859
def addToTestResults(c, res)
#define str(s)
def getReportByPostalAddress(postal_address, report)
Definition: plotscripts.py:466
def phiedges2c()
Definition: plotscripts.py:316
def wheelp1only(dt, wheel, station, sector)
Definition: plotscripts.py:34
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
def plotmedians(reports1, reports2, selection=None, binsx=100, windowx=5., ceilingx=None, binsy=100, windowy=5., ceilingy=None, binsdxdz=100, windowdxdz=5., ceilingdxdz=None, binsdydz=100, windowdydz=5., ceilingdydz=None, r1text=" before", r2text=" after", which="median")