1 import ROOT, array, os, re, random
10 import simplejson
as json
13 from signConventions
import *
21 MAP_RESULTS_SAWTOOTH = {}
22 MAP_RESULTS_FITSIN = {}
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
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" 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
73 return sqrt(s2/n - (s/n)**2)
82 return s/w,
sqrt(1./w)
89 tdrStyle = ROOT.TStyle(
"tdrStyle",
"Style for P-TDR")
91 tdrStyle.SetCanvasBorderMode(0)
92 tdrStyle.SetCanvasColor(ROOT.kWhite)
93 tdrStyle.SetCanvasDefH(600)
94 tdrStyle.SetCanvasDefW(600)
95 tdrStyle.SetCanvasDefX(0)
96 tdrStyle.SetCanvasDefY(0)
99 tdrStyle.SetPadBorderMode(0)
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)
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)
120 tdrStyle.SetHistLineColor(1)
121 tdrStyle.SetHistLineStyle(0)
122 tdrStyle.SetHistLineWidth(1)
126 tdrStyle.SetEndErrorSize(2)
128 tdrStyle.SetErrorX(0.)
130 tdrStyle.SetMarkerStyle(20)
133 tdrStyle.SetOptFit(1)
134 tdrStyle.SetFitFormat(
"5.4g")
135 tdrStyle.SetFuncColor(2)
136 tdrStyle.SetFuncStyle(1)
137 tdrStyle.SetFuncWidth(1)
140 tdrStyle.SetOptDate(0)
145 tdrStyle.SetOptFile(0)
146 tdrStyle.SetOptStat(0)
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)
160 tdrStyle.SetPadTopMargin(0.05)
161 tdrStyle.SetPadBottomMargin(0.13)
162 tdrStyle.SetPadLeftMargin(0.13)
163 tdrStyle.SetPadRightMargin(0.05)
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)
180 tdrStyle.SetTitleColor(1,
"XYZ")
181 tdrStyle.SetTitleFont(42,
"XYZ")
182 tdrStyle.SetTitleSize(0.06,
"XYZ")
185 tdrStyle.SetTitleXOffset(0.9)
186 tdrStyle.SetTitleYOffset(1.05)
190 tdrStyle.SetLabelColor(1,
"XYZ")
191 tdrStyle.SetLabelFont(42,
"XYZ")
192 tdrStyle.SetLabelOffset(0.007,
"XYZ")
193 tdrStyle.SetLabelSize(0.05,
"XYZ")
196 tdrStyle.SetAxisColor(1,
"XYZ")
197 tdrStyle.SetStripDecimals(
True)
198 tdrStyle.SetTickLength(0.03,
"XYZ")
199 tdrStyle.SetNdivisions(510,
"XYZ")
200 tdrStyle.SetPadTickX(1)
201 tdrStyle.SetPadTickY(1)
204 tdrStyle.SetOptLogx(0)
205 tdrStyle.SetOptLogy(0)
206 tdrStyle.SetOptLogz(0)
209 tdrStyle.SetPaperSize(20.,20.)
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""" 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])
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]
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]
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]
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]
276 s = array.array(
'd', stops)
277 r = array.array(
'd', red)
278 g = array.array(
'd', green)
279 b = array.array(
'd', blue)
282 ROOT.TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
283 ROOT.gStyle.SetNumberContours(ncontours)
293 phiedgesCSC36 = [pi/180.*(-5. + 10.*i)
for i
in range(36)]
294 phiedgesCSC18 = [pi/180.*(-5. + 20.*i)
for i
in range(18)]
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]]
318 for ed
in phiedges[:]:
321 ed.extend([999
for n
in range(0,37-len(ed))])
322 lines.append(
'{' +
', '.
join(
map(str, ed)) +
'}')
324 res =
', '.
join(lines)
325 ff = open(
"phiedges_export.h",mode=
"w")
326 print>>ff,
'double phiedges[14][37] = {' + res +
'};' 335 self.ed.append(pi+1.)
340 if x < self.
ed[0]: x += 2*pi
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])
348 print self.
name, self.
n 354 if (
"MB" in name
or "ME" in name):
357 if pa
is None:
return None 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
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
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
393 global philine_tlines, philine_labels
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()
404 edges = sorted(edges[:])
406 labels = [
" 7",
" 8",
" 9",
"14",
"10",
"11",
"12",
" 1",
" 2",
" 3",
"13",
" 4",
" 5",
" 6"]
408 labels = [
" 8",
" 9",
"10",
"11",
"12",
" 1",
" 2",
" 3",
" 4",
" 5",
" 6"]
410 for phi, label
in zip(edges, labels):
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()
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"]
425 for phi, label
in zip(edges, labels):
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()
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()
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()
456 if disk == 1: rl = [150., 270., 480.]
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()
468 if postal_address == r.postal_address:
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)
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 ):
485 tdrStyle.SetOptStat(
"emrou")
486 tdrStyle.SetStatW(0.40)
489 if windows
is not None:
495 global hx, hy, hz, hphix, hphiy, hphiz
498 hx = ROOT.TH1F(
"%s_phi" % name,
"", bins, -wnd[0], wnd[0])
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])
508 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
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.)
515 if r2
is None:
continue 518 if r1.postal_address[0] ==
"DT":
519 if r1.postal_address[1:]
in database1.dt:
521 db1 = database1.dt[r1.postal_address[1:]]
522 if database2
is None:
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.
527 db2 = database2.dt[r1.postal_address[1:]]
531 if r1.postal_address[2]==1
and r1.postal_address[3]==4:
continue 532 if r1.postal_address[1:]
in database1.csc:
534 db1 = database1.csc[r1.postal_address[1:]]
535 if database2
is None:
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.
540 db2 = database2.csc[r1.postal_address[1:]]
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
548 fill = delta/
sqrt(r1.deltax.error**2 + r2.deltax.error**2) * signConventions[r1.postal_address][0]
551 fill = delta/signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0]
553 fill = delta * 10. * signConventions[r1.postal_address][0]
555 if getvalues
not in (
False,
None):
556 getvalues[
"x"].
append((fill, 10. *
sqrt(r1.deltax.error**2 + r2.deltax.error**2)))
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
563 fill = delta/
sqrt(r1.deltay.error**2 + r2.deltay.error**2) * signConventions[r1.postal_address][1]
565 fill = delta * 10. * signConventions[r1.postal_address][1]
567 if getvalues
not in (
False,
None):
568 getvalues[
"y"].
append((fill, 10. *
sqrt(r1.deltay.error**2 + r2.deltay.error**2)))
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
575 fill = delta/
sqrt(r1.deltaz.error**2 + r2.deltaz.error**2) * signConventions[r1.postal_address][2]
577 fill = delta * 10. * signConventions[r1.postal_address][2]
579 if getvalues
not in (
False,
None):
580 getvalues[
"z"].
append((fill, 10. *
sqrt(r1.deltaz.error**2 + r2.deltaz.error**2)))
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
587 fill = delta/
sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)
591 if getvalues
not in (
False,
None):
592 getvalues[
"phix"].
append((fill, 10. *
sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)))
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
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
601 fill = delta/
sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)
605 if getvalues
not in (
False,
None):
606 getvalues[
"phiy"].
append((fill, 10. *
sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)))
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
613 fill = delta/
sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)
617 if getvalues
not in (
False,
None):
618 getvalues[
"phiz"].
append((fill, 10. *
sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)))
622 hx.SetXTitle(
"#delta_{#phi} position (mrad)")
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)")
632 hx.SetXTitle(
"#delta_{#phi}(XML) - #delta_{#phi}(report) position (mrad)")
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)")
642 hx.SetXTitle(
"#delta_{#phi}/#sigma_{#phi} position")
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}}")
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)
657 if canvas
is not None: c = canvas
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:
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")
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
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()
691 c.GetPad(3).cd(); hphiy.Draw()
692 c.GetPad(4).cd(); hphiz.Draw()
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()
700 if hx.GetEntries()>0: c.GetPad(1).SetLogy(1)
701 if hy.GetEntries()>0: c.GetPad(2).SetLogy(1)
703 if hphiy.GetEntries()>0: c.GetPad(3).SetLogy(1)
704 if hphiz.GetEntries()>0: c.GetPad(4).SetLogy(1)
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)
711 return hx, hy, hz, hphix, hphiy, hphiz
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)
718 def DBdiffVersus(quantity, versus, database1, database2, reports1, reports2, windwselection=None, color=ROOT.kBlack):
719 tdrStyle.SetOptStat(
"")
726 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
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.)
734 if r1.postal_address == r2.postal_address:
737 if not found:
continue 740 if r1.postal_address[0] ==
"DT":
741 if r1.postal_address[1:]
in database1.dt:
743 db1 = database1.dt[r1.postal_address[1:]]
744 if database2
is None:
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.
749 db2 = database2.dt[r1.postal_address[1:]]
751 if r1.postal_address[1:]
in database1.csc:
753 db1 = database1.csc[r1.postal_address[1:]]
754 if database2
is None:
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.
759 db2 = database2.csc[r1.postal_address[1:]]
761 if found
and r1.status ==
"PASS" and r2.status ==
"PASS":
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.:
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])
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.:
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])
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.:
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])
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.:
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])
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.:
798 values.append((db1.phix - db2.phix) * 1000.)
799 errors.append((r1.deltaphix.error**2 + r2.deltaphix.error**2) * 1000.)
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.:
805 values.append((db1.phiy - db2.phiy) * 1000.)
806 errors.append((r1.deltaphiy.error**2 + r2.deltaphiy.error**2) * 1000.)
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.:
812 values.append((db1.phiz - db2.phiz) * 1000.)
813 errors.append((r1.deltaphiz.error**2 + r2.deltaphiz.error**2) * 1000.)
815 else:
raise Exception
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
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)")
830 bkgndhist = ROOT.TH1F(
"bkgndhist",
"", 100, -1100., 1100.)
831 bkgndhist.SetXTitle(
"z (cm)")
832 bkgndhist.GetXaxis().CenterTitle()
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()
846 tgraph = ROOT.TGraphErrors(0)
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)
854 if tgraph.GetN() > 0: tgraph.Draw(
"p")
855 return bkgndhist, tgraph, domain, values, errors
861 if len(id)!=9:
return None 864 pa = (
"DT",
int(id[2:4]),
int(id[5]),
int(id[7:9]))
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 872 elif id[2]==
"-": ec=2
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 883 if postal_address[0] ==
"DT":
884 wheel, station, sector = postal_address[1:]
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)
895 if name[0:2] ==
"MB":
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" 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 =
"-" 913 return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
920 for iwheel
in DT_TYPES:
921 if iwheel[1]==
"ALL":
continue 922 dts.append(iwheel[0])
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])
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)
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])
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)
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)
966 for endcap
in CSC_TYPES:
967 for station
in endcap[2]:
968 cscs.append(
"%s%s" % (endcap[0], station[1]))
970 for endcap
in CSC_TYPES:
971 for station
in endcap[2]:
972 for ring
in station[2]:
973 if ring[1]==
"ALL":
continue 975 cscs.append(
"%s%s/%s" % (endcap[0], station[1],ring[1]))
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):
983 cscs.append(
"%s%s/ALL/%02d" % (endcap[0], station[1],chamber))
985 for endcap
in CSC_TYPES:
986 for station
in endcap[2]:
987 for ring
in station[2]:
988 if ring[1]!=
"ALL":
continue 990 cscs.append(
"%s%s/ALL" % (endcap[0], station[1]))
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):
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)
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)
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"}];
1032 if c
in TEST_RESULTS: TEST_RESULTS[c].extend(res)
1033 else: TEST_RESULTS[c] = res
1038 for sev
in DQM_SEVERITY:
1039 if sev[
"name"]==severity: s = sev[
"idx"]
1040 return {
"testID":testID,
"scope":scope,
"descr":descr,
"severity":s}
1044 if abs(x[1])==0.:
return 0.
1045 pull =
abs(x[0])/
abs(x[1])
1046 if pull <= 5:
return 0.
1056 for i
in range(1,n+1):
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 )
1070 if df > 0: res.append(i)
1080 if not postal_address:
continue 1085 if r.postal_address == postal_address:
1088 if not found:
continue 1092 scope = postal_address[0]
1095 if r.status ==
"FAIL" or r.status ==
"MINUITFAIL":
1096 res.append(
testEntry(
"FAILURE",scope,r.status+
" failure",
"CRITICAL"))
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"))
1108 sdx = 10.*r.deltax.error
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"))
1116 res.append(
testEntry(
"BIG_CHI2",scope,
"chi2=%f>20" % r.redchi2,
"TOLERABLE"))
1119 medx, meddx = 10.*r.median_x, 1000.*r.median_dxdz
1121 if medx>2: res.append(
testEntry(
"BIG_MED_X",scope,
"median dx=%f>2 mm"%medx,
"SEVERE"))
1123 if meddx>2: res.append(
testEntry(
"BIG_MED_DXDZ",scope,
"median d(dx/dz)=%f>2 mrad"%meddx,
"SEVERE"))
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"))
1145 if c[0:2]==
"MB": scope =
"DT" 1146 if c[0:2]==
"ME": scope =
"CSC" 1148 print "strange cell ID: ", c
1151 if c
in MAP_RESULTS_FITSIN:
1152 t = MAP_RESULTS_FITSIN[c]
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"))
1160 if c
in MAP_RESULTS_SAWTOOTH:
1161 t = MAP_RESULTS_SAWTOOTH[c]
1165 descr =
"map discontinuities: %s" %
",".
join(
map(str,t_a))
1166 res.append(
testEntry(
"MAP_DISCONTIN",scope,descr,
"SEVERE"))
1168 t_b =
map(testZeroWithin5Sigma, t[
'b'])
1170 for i
in range(0,len(t_b)):
1171 if t_b[i]>0: t_bi.append(i+1)
1173 descr =
"map sawteeth: %s" %
",".
join(
map(str,t_bi))
1174 res.append(
testEntry(
"MAP_SAWTEETH",scope,descr,
"TOLERABLE"))
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)
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)
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)
1213 def doTests(reports, pic_ids, fname_base, fname_dqm, run_name):
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)
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)
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
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)
1263 if which ==
"median":
1264 whichx = whichy = whichdxdz = whichdydz =
"median" 1265 elif which ==
"bigmean":
1268 whichdxdz =
"mean20" 1269 whichdydz =
"mean50" 1270 elif which ==
"mean":
1273 whichdxdz =
"mean10" 1274 whichdydz =
"mean25" 1275 elif which ==
"bigwmean":
1278 whichdxdz =
"wmean20" 1279 whichdydz =
"wmean50" 1280 elif which ==
"wmean":
1283 whichdxdz =
"wmean10" 1284 whichdydz =
"wmean25" 1285 elif which ==
"bigstdev":
1288 whichdxdz =
"stdev20" 1289 whichdydz =
"stdev50" 1290 elif which ==
"stdev":
1293 whichdxdz =
"stdev10" 1294 whichdydz =
"stdev25" 1296 raise Exception(which +
" not recognized")
1299 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
1302 if r1.postal_address == r2.postal_address:
1305 if not found:
continue 1308 if r1.postal_address[0]==
'CSC':
1309 if r1.postal_address[2]==1
and r1.postal_address[3]==4:
continue 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))
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))
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)
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)
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()
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")
1359 hmedianx_after.Draw()
1360 hmedianx_before.Draw(
"same")
1361 hmedianx_after.Draw(
"same")
1362 hmedianx_beforecopy.Draw(
"same")
1363 hmedianx_after.Draw(
"axissame")
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")
1373 hmediandxdz_after.Draw()
1374 hmediandxdz_before.Draw(
"same")
1375 hmediandxdz_after.Draw(
"same")
1376 hmediandxdz_beforecopy.Draw(
"same")
1377 hmediandxdz_after.Draw(
"axissame")
1380 hmediany_after.Draw()
1381 hmediany_before.Draw(
"same")
1382 hmediany_after.Draw(
"same")
1383 hmediany_beforecopy.Draw(
"same")
1384 hmediany_after.Draw(
"axissame")
1387 hmediandydz_after.Draw()
1388 hmediandydz_before.Draw(
"same")
1389 hmediandydz_after.Draw(
"same")
1390 hmediandydz_beforecopy.Draw(
"same")
1391 hmediandydz_after.Draw(
"axissame")
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
1402 htmp = ROOT.gROOT.FindObject(the2d.GetName()+
"_peaks")
1403 if htmp !=
None: htmp.Delete()
1405 hpeaks = the2d.ProjectionX(the2d.GetName()+
"_peaks")
1409 for i
in xrange(0,
int(the2d.GetNbinsX()), rebin):
1410 tmp = the2d.ProjectionY(
"tmp", i+1, i + rebin)
1411 nn = tmp.GetEntries()
1413 drange = tmp.GetRMS()
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())
1423 fr = tmp.Fit(
"fgaus",
"RNSQ")
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 1429 bad_fit_bins.append(i/rebin+1)
1430 if nn > 1.
and tmp.GetRMS() > 0:
1431 hpeaks.SetBinContent(i/rebin+1, tmp.GetMean())
1432 hpeaks.SetBinError(i/rebin+1, ROOT.TMath.StudentQuantile(0.841345,nn) * tmp.GetRMS() /
sqrt(nn))
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
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)
1448 tdrStyle.SetOptFit(0)
1449 tdrStyle.SetTitleFontSize(0.05)
1450 tdrStyle.SetPadRightMargin(0.1)
1456 global hist, hist2d, hist2dweight, tline1, tline2, tline3
1458 if fitsine
or fitsawteeth:
1461 print "bad id for ", name
1464 hdir =
"AlignmentMonitorMuonSystemMap1D/iter1/" 1465 hpref=
"%s_%s" % (name, param)
1469 if "ALL" in name
and (
"CSCvsr" in name
or "DTvsz" in name): combine_all =
True 1471 add1d = (
"vsphi" in name)
and (param ==
"x")
1474 hist2d = args[
"h2d"].Clone(hpref+
"_2d_")
1475 if "CSC" in name
and add1d: hist1d = args[
"h1d"].Clone(hpref+
"_1d_")
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)]
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_")
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"))
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"))
1505 if mode ==
"from2d":
1508 hist = the2d.ProjectionX()
1517 for i
in xrange(0,
int(the2d.GetNbinsX()), skip):
1518 tmp = the2d.ProjectionY(
"tmp", i+1, i + skip)
1519 if tmp.GetEntries() > 1:
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()))
1528 hist.SetBinContent(i/skip+1, 0.)
1529 hist.SetBinError(i/skip+1, 0.)
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)")
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)")
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)
1560 hist2d.Draw(
"colzsame")
1561 if widebins: hist.Draw(
"samee1")
1562 else: hist.Draw(
"same")
1564 hpeaks.SetMarkerStyle(20)
1565 hpeaks.SetMarkerSize(0.9)
1566 hpeaks.SetMarkerColor(ROOT.kRed)
1567 hpeaks.SetLineColor(ROOT.kRed)
1568 hpeaks.SetLineWidth(2)
1572 if fitsine
and "vsphi" in name:
1573 global fitsine_const, fitsine_sin, fitsine_cos, fitsine_chi2, fitsine_ndf
1575 f = ROOT.TF1(
"f",
"[0] + [1]*sin(x) + [2]*cos(x)", -pi/180.*5., pi*(2.-5./180.))
1577 f = ROOT.TF1(
"f",
"[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
1578 f.SetLineColor(ROOT.kRed)
1580 if len(fixfitpars)>0:
1581 for fpar
in fixfitpars.keys():
1582 f.FixParameter(fpar, fixfitpars[fpar])
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
1596 MAP_RESULTS_FITSIN[id] = {
'a':fitsine_const,
'phi':fitsine_const,
'sin': fitsine_sin,
'cos': fitsine_cos,
'chi2': fitsine_chi2,
'ndf': fitsine_ndf}
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()
1613 if 'CSC' in name
and add1d:
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)
1622 f1 = ROOT.TF1(
"f1",
"gaus", rangea, rangeb)
1623 fit = hist1d.Fit(f1,
"NRQ")
1624 nn = hist1d.GetEntries()
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)
1629 MAP_RESULTS_FITSIN[id][
'phi'] = (dphiz, ephiz)
1631 global ttex_sine_, ttex_sine, ttex_1d_, ttex_1d
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()
1646 f = ROOT.TF1(
"f",
"[0] + [1]*x", -1000., 1000.)
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()
1663 ROOT.gPad.RedrawAxis()
1666 if not widebins:
philines(name, window, abscissa)
1667 if abscissa
is None:
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()
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()
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()
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()
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()
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()
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()
1704 if "vsphi" in name
and fitsawteeth:
1708 ROOT.gROOT.ProcessLine(
".L phiedges_fitfunctions.C++")
1726 fn.SetLineColor(ROOT.kYellow)
1734 ed.append(pi+
abs(ed[0]))
1736 global sawtooth_a, 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()}
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)
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" 1772 if name.find(
'sec')<0:
return None 1773 station = name[name.find(
'sec')-1]
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]
1779 return "MB%s/%s" % (w, station)
1783 if name[p+2]==
"p": endcap =
"+" 1784 elif name[p+2]==
"m": endcap =
"-" 1787 pch = name.find(
'ch')
1790 return "ME%s%s/%s" % (endcap, station, ring)
1792 chamber = name[pch+2:pch+4]
1793 return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
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)
1811 global hist, histCOPY, hist2d, tline1, tline2, tline3, tline4, tline5
1813 hdir =
"AlignmentMonitorMuonVsCurvature/iter1/" 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))
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
1831 for sector
in sectors:
1832 hsuffix =
"_%s_%s" % (
"wheel%s_sector%s" % (wheel, sector), param)
1833 for tfile
in tfiles:
1835 prof = tfiles[0].Get(hdir+
"tprofile"+hsuffix).Clone(
"tprofile_"+hsuffix)
1836 hist2d = tfiles[0].Get(hdir+
"th2f"+hsuffix).Clone(
"tprofile_"+hsuffix)
1838 prof.Add(tfile.Get(hdir+
"tprofile"+hsuffix))
1839 hist2d.Add(tfile.Get(hdir+
"th2f"+hsuffix))
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))
1848 elif mode ==
"from2d":
1853 htmp = ROOT.gROOT.FindObject(
"tmp")
1854 if htmp !=
None: htmp.Delete()
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()))
1865 hist.SetBinContent(i/skip+1, 0.)
1866 hist.SetBinError(i/skip+1, 0.)
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
1884 fitgauss_diff = f.GetParameter(1), f.GetParError(1)
1885 fitgauss_chi2 = f.GetChisquare()
1886 fitgauss_ndf = f.GetNDF()
1888 global fitline_intercept, fitline_slope
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)
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)
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)
1910 fitline_intercept = f.GetParameter(0), f.GetParError(0)
1911 fitline_slope = f.GetParameter(1), f.GetParError(1)
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)
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)")
1933 hist.SetMarkerColor(ROOT.kBlack)
1934 hist.SetLineColor(ROOT.kBlack)
1952 hpeaks.SetMarkerStyle(20)
1953 hpeaks.SetMarkerSize(0.9)
1954 hpeaks.SetMarkerColor(ROOT.kRed)
1955 hpeaks.SetLineColor(ROOT.kRed)
1956 hpeaks.SetLineWidth(2)
1964 tline5 = ROOT.TLine(-hist.GetBinLowEdge(1), 0., hist.GetBinLowEdge(1), 0.)
1970 global h, gm2, gm1, gz, gp1, gp2, tlegend
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)
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)
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()
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]))
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)
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")
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)
2039 ddt=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
2041 for i
in range(0,15):
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)
2051 def bellcurves(tfile, reports, name, twobin=True, suppressblue=False):
2054 tdrStyle.SetOptTitle(1)
2055 tdrStyle.SetTitleBorderSize(1)
2056 tdrStyle.SetTitleFontSize(0.1)
2057 tdrStyle.SetOptStat(0)
2058 tdrStyle.SetHistMinimumZero()
2068 if not found:
raise Exception(
"Not a valid name")
2069 if r.status ==
"FAIL":
2075 Pos =
"Pos"; Neg =
"Neg" 2079 pdirPos =
"MuonAlignmentFromReference/%s%s" % (name, Pos)
2080 pdirNeg =
"MuonAlignmentFromReference/%s%s" % (name, Neg)
2083 ddt[1] = 1./ddt[0]*((ddt[0]-1)*ddt[1] + t2-t1)
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")
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")
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")
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")
2118 print "Can't find neither "+pdirPos+
"_x nor "+pdirPos+
"_residual" 2122 ddt[2] = 1./ddt[0]*((ddt[0]-1)*ddt[2] + t3-t2)
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")
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)")
2152 ddt[3] = 1./ddt[0]*((ddt[0]-1)*ddt[3] + t4-t3)
2154 for h
in chamber_x, chamber_dxdz, chamber_alphax, chamber_alphax, \
2155 chamber_y, chamber_dydz, chamber_alphay, chamber_alphay:
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)
2167 for f
in chamber_x_fit2, chamber_y_fit2, chamber_dxdz_fit2, chamber_dydz_fit2, \
2168 chamber_alphax_fit2, chamber_alphay_fit2:
2175 ddt[4] = 1./ddt[0]*((ddt[0]-1)*ddt[4] + t5-t4)
2177 global l1, l2, l3, l4
2178 if not not chamber_y:
2181 chamber_x.SetTitle(
getname(r))
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)))
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)))
2202 chamber_alphax.Draw(
"col")
2203 if not suppressblue: chamber_alphax_fit2.Draw(
"same")
2204 chamber_alphax_fit.Draw(
"same")
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)))
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)))
2224 for lb
in l1,l2,l3,l4:
2226 lb.SetTextColor(ROOT.kRed)
2229 chamber_alphay.Draw(
"col")
2230 if not suppressblue: chamber_alphay_fit2.Draw(
"same")
2231 chamber_alphay_fit.Draw(
"same")
2236 chamber_x.SetTitle(
getname(r))
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)))
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)))
2257 chamber_alphax.Draw(
"col")
2258 if not suppressblue: chamber_alphax_fit2.Draw(
"same")
2259 chamber_alphax_fit.Draw(
"same")
2263 lb.SetTextColor(ROOT.kRed)
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)
2270 def polynomials(tfile, reports, name, twobin=True, suppressblue=False):
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)
2288 if not found:
raise Exception(
"Not a valid name")
2290 if r.status ==
"FAIL":
2296 Pos =
"Pos"; Neg =
"Neg" 2300 pdirPos =
"MuonAlignmentFromReference/%s%s" % (name, Pos)
2301 pdirNeg =
"MuonAlignmentFromReference/%s%s" % (name, Neg)
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
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")
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")
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")
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")
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")
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")
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")
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")
2397 if not chamber_x_trackx:
2398 print "Can't find neither "+pdirPos+
"_residual nor "+pdirPos+
"_residual_trackx" 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()
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()
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)
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)
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")
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")
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:
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)
2483 trackdxdz_minimum, trackdxdz_maximum =
None,
None 2484 for h
in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
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:
2496 h.SetAxisRange(trackdxdz_minimum, trackdxdz_maximum,
"X")
2498 trackdydz_minimum, trackdydz_maximum =
None,
None 2499 for h
in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
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:
2511 h.SetAxisRange(trackdydz_minimum, trackdydz_maximum,
"X")
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:
2520 if not not chamber_y_trackx:
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))
2552 ROOT.SetOwnership(p,
False)
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")
2564 for l
in label1, label2, label3, label4, label5, label6, label7, label8, label9:
2566 l.SetFillColor(ROOT.kWhite)
2568 for l
in label1, label2, label3, label4:
2573 label9.SetTextSize(0.59)
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()
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)
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)
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)
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)
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)
2663 chamber_dydz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2664 chamber_dydz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2665 chamber_dydz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2668 chamber_x_trackx.Draw(
"e1")
2669 if not suppressblue: chamber_x_trackx_fit2.Draw(
"samel")
2670 chamber_x_trackx_fit.Draw(
"samel")
2678 chamber_x_tracky.Draw(
"e1")
2679 if not suppressblue: chamber_x_tracky_fit2.Draw(
"samel")
2680 chamber_x_tracky_fit.Draw(
"samel")
2683 chamber_x_trackdxdz.Draw(
"e1")
2684 if not suppressblue: chamber_x_trackdxdz_fit2.Draw(
"samel")
2685 chamber_x_trackdxdz_fit.Draw(
"samel")
2688 chamber_x_trackdydz.Draw(
"e1")
2689 if not suppressblue: chamber_x_trackdydz_fit2.Draw(
"samel")
2690 chamber_x_trackdydz_fit.Draw(
"samel")
2693 chamber_y_trackx.Draw(
"e1")
2694 if not suppressblue: chamber_y_trackx_fit2.Draw(
"samel")
2695 chamber_y_trackx_fit.Draw(
"samel")
2698 chamber_y_tracky.Draw(
"e1")
2699 if not suppressblue: chamber_y_tracky_fit2.Draw(
"samel")
2700 chamber_y_tracky_fit.Draw(
"samel")
2703 chamber_y_trackdxdz.Draw(
"e1")
2704 if not suppressblue: chamber_y_trackdxdz_fit2.Draw(
"samel")
2705 chamber_y_trackdxdz_fit.Draw(
"samel")
2708 chamber_y_trackdydz.Draw(
"e1")
2709 if not suppressblue: chamber_y_trackdydz_fit2.Draw(
"samel")
2710 chamber_y_trackdydz_fit.Draw(
"samel")
2713 chamber_dxdz_trackx.Draw(
"e1")
2714 if not suppressblue: chamber_dxdz_trackx_fit2.Draw(
"samel")
2715 chamber_dxdz_trackx_fit.Draw(
"samel")
2718 chamber_dxdz_tracky.Draw(
"e1")
2719 if not suppressblue: chamber_dxdz_tracky_fit2.Draw(
"samel")
2720 chamber_dxdz_tracky_fit.Draw(
"samel")
2723 chamber_dxdz_trackdxdz.Draw(
"e1")
2724 if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw(
"samel")
2725 chamber_dxdz_trackdxdz_fit.Draw(
"samel")
2728 chamber_dxdz_trackdydz.Draw(
"e1")
2729 if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw(
"samel")
2730 chamber_dxdz_trackdydz_fit.Draw(
"samel")
2733 chamber_dydz_trackx.Draw(
"e1")
2734 if not suppressblue: chamber_dydz_trackx_fit2.Draw(
"samel")
2735 chamber_dydz_trackx_fit.Draw(
"samel")
2738 chamber_dydz_tracky.Draw(
"e1")
2739 if not suppressblue: chamber_dydz_tracky_fit2.Draw(
"samel")
2740 chamber_dydz_tracky_fit.Draw(
"samel")
2743 chamber_dydz_trackdxdz.Draw(
"e1")
2744 if not suppressblue: chamber_dydz_trackdxdz_fit2.Draw(
"samel")
2745 chamber_dydz_trackdxdz_fit.Draw(
"samel")
2748 chamber_dydz_trackdydz.Draw(
"e1")
2749 if not suppressblue: chamber_dydz_trackdydz_fit2.Draw(
"samel")
2750 chamber_dydz_trackdydz_fit.Draw(
"samel")
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))
2774 ROOT.SetOwnership(p,
False)
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")
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)")
2788 for l
in label1, label2, label3, label4, label5, label6, label9:
2790 l.SetFillColor(ROOT.kWhite)
2792 for l
in label1, label2:
2797 label9.SetTextSize(0.29)
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()
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)
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)
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)
2837 chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2838 chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2839 chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2842 chamber_x_trackx.Draw(
"e1")
2843 if not suppressblue: chamber_x_trackx_fit2.Draw(
"samel")
2844 chamber_x_trackx_fit.Draw(
"samel")
2848 chamber_x_tracky.Draw(
"e1")
2849 if not suppressblue: chamber_x_tracky_fit2.Draw(
"samel")
2850 chamber_x_tracky_fit.Draw(
"samel")
2853 chamber_x_trackdxdz.Draw(
"e1")
2854 if not suppressblue: chamber_x_trackdxdz_fit2.Draw(
"samel")
2855 chamber_x_trackdxdz_fit.Draw(
"samel")
2858 chamber_x_trackdydz.Draw(
"e1")
2859 if not suppressblue: chamber_x_trackdydz_fit2.Draw(
"samel")
2860 chamber_x_trackdydz_fit.Draw(
"samel")
2863 chamber_dxdz_trackx.Draw(
"e1")
2864 if not suppressblue: chamber_dxdz_trackx_fit2.Draw(
"samel")
2865 chamber_dxdz_trackx_fit.Draw(
"samel")
2868 chamber_dxdz_tracky.Draw(
"e1")
2869 if not suppressblue: chamber_dxdz_tracky_fit2.Draw(
"samel")
2870 chamber_dxdz_tracky_fit.Draw(
"samel")
2873 chamber_dxdz_trackdxdz.Draw(
"e1")
2874 if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw(
"samel")
2875 chamber_dxdz_trackdxdz_fit.Draw(
"samel")
2878 chamber_dxdz_trackdydz.Draw(
"e1")
2879 if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw(
"samel")
2880 chamber_dxdz_trackdydz_fit.Draw(
"samel")
2883 ddt[8] = 1./ddt[7]*((ddt[7]-1)*ddt[8] + tn-t1)
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)
2896 if component[0:2] ==
"dt":
2897 wheel = args[
"wheel"]
2899 sector = args[
"sector"]
2900 profname =
"%s_%s_%02d_%s" % (component, wheelletter, sector,
str(pair))
2901 posname =
"pos" + profname
2902 negname =
"neg" + profname
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
2912 phi = (phi1 + phi2) / 2.
2913 while (phi < -pi): phi += 2.*pi
2914 while (phi > pi): phi -= 2.*pi
2916 elif component[0:3] ==
"csc":
2917 endcap = args[
"endcap"]
2924 else:
raise Exception
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
2934 chamber = args[
"chamber"]
2935 if (ring==1
and chamber>18)
or (ring==2
and chamber>36):
raise Exception
2937 profname =
"csc%s_%s_%s_%02d_%s" % (ringname,component[4:], endcap, chamber,
str(pair))
2938 posname =
"pos" + profname
2939 negname =
"neg" + profname
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
2949 phi = (phi1 + phi2) / 2.
2950 while (phi < -pi*5./180.): phi += 2.*pi
2951 while (phi > pi*(2.-5./180.)): phi -= 2.*pi
2953 else:
raise Exception
2955 if "window" in args: window = args[
"window"]
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))
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")
2974 f = ROOT.TF1(
"p1",
"[0] + [1]*x", tmpprof.GetBinLowEdge(1), -tmpprof.GetBinLowEdge(1))
2975 f.SetParameters((tmppos.GetMean() + tmpneg.GetMean())/2., 0.)
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")
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
3021 tmppos.SetTitle(
"Positive muons")
3022 tmpneg.SetTitle(
"Negative muons")
3027 fit1 = tmpprof.Fit(
"p1",
"qS")
3030 c1.GetPad(2).
Divide(1, 2)
3031 c1.GetPad(2).GetPad(1).cd()
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()
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")
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
3050 fitresult1 =
None,
None 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
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)
3072 if component[0:4] ==
"x_dt":
3073 wheel =
int(args[
"wheel"])
3075 wheell =
"m%d" %
abs(wheel)
3078 wheell =
"p%d" %
abs(wheel)
3080 station_dt = component[4]
3081 station_csc_1 = args[
"cscstations"][0]
3082 if station_csc_1==
'1': ring_1 = 3
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
3092 profname =
"%s%s_W%sS%02d" % (component, station_csc_2, wheell, sector)
3093 posname_2 =
"pos_" + profname
3094 negname_2 =
"neg_" + profname
3096 phi = signConventions[
"DT", wheel,
int(station_dt), sector][4]
3097 while (phi < -pi): phi += 2.*pi
3098 while (phi > pi): phi -= 2.*pi
3100 else:
raise Exception
3102 if "window" in args: window = args[
"window"]
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)
3122 result[
"fit_ok"] =
False 3124 ntot = tmppos.GetEntries() + tmpneg.GetEntries()
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()
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")
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")
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
3163 if len(args[
"cscstations"]) > 1:
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")
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")
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
3186 tdrStyle.SetOptTitle(1)
3187 tdrStyle.SetTitleBorderSize(1)
3188 tdrStyle.SetTitleFontSize(0.05)
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):
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")
3201 gtemp_11_phi.append(r1[
"phi"])
3202 gtemp_11_val.append(r1[
"fit_peak"])
3203 gtemp_11_err.append(r1[
"fit_peak_error"])
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"])
3209 gtemp_21_phi.append(r2[
"phi"])
3210 gtemp_21_val.append(r2[
"fit_peak"])
3211 gtemp_21_err.append(r2[
"fit_peak_error"])
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))
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)
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)
3246 if len(gtemp_12_phi) > 0:
3248 if len(gtemp_21_phi) > 0:
3250 if len(gtemp_11_phi) > 0:
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")
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,
"")
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)
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)
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)
3300 def segdiffvsphi(tfiles, reports, component, wheel, window=5., excludesectors=()):
3301 tdrStyle.SetOptTitle(1)
3302 tdrStyle.SetTitleBorderSize(1)
3303 tdrStyle.SetTitleFontSize(0.05)
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):
3312 r1_found, r2_found, r3_found, r4_found =
False,
False,
False,
False 3314 if r1.postal_address == (
"DT", wheel, 1, sector):
3318 if r2.postal_address == (
"DT", wheel, 2, sector):
3322 if r3.postal_address == (
"DT", wheel, 3, sector):
3326 if r4.postal_address == (
"DT", wheel, 4, sector):
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)
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)
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)
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)
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))
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)
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)
3410 if len(gtemp_12_phi) > 0:
3413 if len(gtemp_23_phi) > 0:
3416 if len(gtemp_34_phi) > 0:
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)),
"")
3439 tdrStyle.SetOptTitle(1)
3440 tdrStyle.SetTitleBorderSize(1)
3441 tdrStyle.SetTitleFontSize(0.05)
3443 if not component[0:3] ==
"csc": Exception
3445 endcap = args[
"endcap"]
3452 else:
raise Exception
3454 station1 =
int(
str(pair)[0])
3455 station2 =
int(
str(pair)[1])
3456 if not station2-station1==1:
raise Exception
3459 if station2==4: rings = [1]
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 = [], [], [], [], []
3468 chambers = xrange(1,37)
3469 if ring == 1: chambers = xrange(1,19)
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:
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)
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)
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))
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)
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)
3523 if len(gtemp_1_phi) > 0:
3526 if len(gtemp_2_phi) > 0:
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")
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,
3553 tdrStyle.SetOptStat(0)
3554 tdrStyle.SetStatW(0.40)
3558 check_reports =
False 3559 if reportsX
is not None and reportsY
is not None:
3561 check_reports =
True 3562 if geometry0
is not None and geometryX
is not None and geometryY
is not None:
3565 print "Either couple of reports or three geometries have to be given as input. Exiting..." 3570 wnd_adaptive = [.1]*6
3572 global hx, hy, hz, hphix, hphiy, hphiz
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]
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]
3593 ax=[]; ay=[]; az=[]; aphix=[]; aphiy=[]; aphiz=[]
3594 aaa = [ax, ay, az, aphix, aphiy, aphiz]
3597 postal_addresses = []
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)):
3607 print "bad r2 in ",r1.postal_address
3610 if r1.status !=
"PASS" or r2.status !=
"PASS":
3611 print "bad status", r1.postal_address, r1.status, r2.status
3613 postal_addresses.append(r1.postal_address)
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():
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)) )
3626 for addr
in postal_addresses:
3629 if not (selection
is None or (selection.__code__.co_argcount == len(addr)
and selection(*addr)) ):
continue 3631 factors = [10. * signConventions[addr][0], 10. * signConventions[addr][1], 10. * signConventions[addr][2],
3632 1000., 1000., 1000. ]
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]
3640 if mode ==
"reports":
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. , \
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]))
3653 if mx > wnd_adaptive[i]: wnd_adaptive[i] = mx
3657 db0 = dbX = dbY =
None 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:]]
3665 checks =
map(
lambda d1, d2: d1
is not None and d2
is not None , deltasX, deltasY)
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]
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]))
3678 if mx > wnd_adaptive[i]: wnd_adaptive[i] = mx
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)"]
3692 for t
in tmptitles: htitles.append([pre_title_x + t, pre_title_y + t])
3694 if canvas
is not None: c = canvas
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)
3702 global lines, graphs, texs
3703 lines = []; graphs = []; texs = []
3709 if (
int(which,2) & (1<<i) ) == 0:
continue 3713 c.GetPad(ipad).SetGridx(1)
3714 c.GetPad(ipad).SetGridy(1)
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()
3725 if len(aaa[i]) == 0:
continue 3727 a1, a2 =
map(
lambda x: array.array(
'd',x),
list(
zip(*aaa[i])) )
3728 g = ROOT.TGraph(len(a1), a1, a2)
3730 g.SetMarkerSize(0.3)
3731 g.SetMarkerColor(ROOT.kBlue)
3734 pcas[i].MakePrincipals()
3737 b = pcas[i].GetEigenVectors()(1,0) / pcas[i].GetEigenVectors()(0,0)
3738 a = pcas[i].GetMeanValues()[1] - b * pcas[i].GetMeanValues()[0]
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:
3748 t.SetTextColor(ROOT.kBlue)
3749 t.SetTextSize(0.053)
3756 wn = wnd_adaptive[i]
3757 line = ROOT.TLine(-wn, a - b*wn, wn, a + b*wn)
3758 line.SetLineColor(ROOT.kRed)
def rlines(disk, window, abscissa)
def writeDQMReport(fname_dqm, run_name)
def testZeroWithin5Sigma(x)
def segdiffvsphi_xalign(tfiles, wheel, window=10.)
def DBdiffVersus(quantity, versus, database1, database2, reports1, reports2, windwselection=None, color=ROOT.kBlack)
def wheelm1only(dt, wheel, station, sector)
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 philines(name, window, abscissa)
def availableCellsCSC(reports)
def doTests(reports, pic_ids, fname_base, fname_dqm, run_name)
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)
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)
def postalAddressToId(postal_address)
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 doTestsForMapPlots(cells)
def DBMCVersus(quantity, versus, database, reports, window=10., selection=None, color=ROOT.kBlack)
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)
def wheelm2only(dt, wheel, station, sector)
Convenience functions.
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def segdiffvsphicsc(tfiles, component, pair, window=5., args)
Abs< T >::type abs(const T &t)
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)
static std::string join(char **cmd)
def wheelp2only(dt, wheel, station, sector)
def testEntry(testID, scope, descr, severity)
def createPeaksProfile(the2d, rebin=1)
def __call__(self, xx, par)
def curvatureDTsummary(tfiles, window=15., pdgSfactor=False)
def doTestsForReport(cells, reports)
def segdiff(tfiles, component, pair, args)
def zlines(window, abscissa)
def wheel0only(dt, wheel, station, sector)
def set_palette(name=None, ncontours=999)
def idToPostalAddress(id)
def addToTestResults(c, res)
def getReportByPostalAddress(postal_address, report)
def wheelp1only(dt, wheel, station, sector)
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")