1 from __future__
import print_function
2 import ROOT, array, os, re, random
11 import simplejson
as json
14 from signConventions
import *
22 MAP_RESULTS_SAWTOOTH = {}
23 MAP_RESULTS_FITSIN = {}
32 def wheelm2only(dt, wheel, station, sector):
return dt ==
"DT" and wheel == -2
33 def wheelm1only(dt, wheel, station, sector):
return dt ==
"DT" and wheel == -1
34 def wheel0only(dt, wheel, station, sector):
return dt ==
"DT" and wheel == 0
35 def wheelp1only(dt, wheel, station, sector):
return dt ==
"DT" and wheel == 1
36 def wheelp2only(dt, wheel, station, sector):
return dt ==
"DT" and wheel == 2
39 if wheel == -2:
return "A" 40 elif wheel == -1:
return "B" 41 elif wheel == 0:
return "C" 42 elif wheel == +1:
return "D" 43 elif wheel == +2:
return "E" 47 if wheell ==
"A":
return -2
48 elif wheell ==
"B":
return -1
49 elif wheell ==
"C":
return 0
50 elif wheell ==
"D":
return 1
51 elif wheell ==
"E":
return 2
74 return sqrt(s2/n - (s/n)**2)
83 return s/w,
sqrt(1./w)
90 tdrStyle = ROOT.TStyle(
"tdrStyle",
"Style for P-TDR")
92 tdrStyle.SetCanvasBorderMode(0)
93 tdrStyle.SetCanvasColor(ROOT.kWhite)
94 tdrStyle.SetCanvasDefH(600)
95 tdrStyle.SetCanvasDefW(600)
96 tdrStyle.SetCanvasDefX(0)
97 tdrStyle.SetCanvasDefY(0)
100 tdrStyle.SetPadBorderMode(0)
102 tdrStyle.SetPadColor(ROOT.kWhite)
103 tdrStyle.SetPadGridX(
False)
104 tdrStyle.SetPadGridY(
False)
105 tdrStyle.SetGridColor(0)
106 tdrStyle.SetGridStyle(3)
107 tdrStyle.SetGridWidth(1)
110 tdrStyle.SetFrameBorderMode(0)
111 tdrStyle.SetFrameBorderSize(1)
112 tdrStyle.SetFrameFillColor(0)
113 tdrStyle.SetFrameFillStyle(0)
114 tdrStyle.SetFrameLineColor(1)
115 tdrStyle.SetFrameLineStyle(1)
116 tdrStyle.SetFrameLineWidth(1)
121 tdrStyle.SetHistLineColor(1)
122 tdrStyle.SetHistLineStyle(0)
123 tdrStyle.SetHistLineWidth(1)
127 tdrStyle.SetEndErrorSize(2)
129 tdrStyle.SetErrorX(0.)
131 tdrStyle.SetMarkerStyle(20)
134 tdrStyle.SetOptFit(1)
135 tdrStyle.SetFitFormat(
"5.4g")
136 tdrStyle.SetFuncColor(2)
137 tdrStyle.SetFuncStyle(1)
138 tdrStyle.SetFuncWidth(1)
141 tdrStyle.SetOptDate(0)
146 tdrStyle.SetOptFile(0)
147 tdrStyle.SetOptStat(0)
148 tdrStyle.SetStatColor(ROOT.kWhite)
149 tdrStyle.SetStatFont(42)
150 tdrStyle.SetStatFontSize(0.025)
151 tdrStyle.SetStatTextColor(1)
152 tdrStyle.SetStatFormat(
"6.4g")
153 tdrStyle.SetStatBorderSize(1)
154 tdrStyle.SetStatH(0.1)
155 tdrStyle.SetStatW(0.15)
161 tdrStyle.SetPadTopMargin(0.05)
162 tdrStyle.SetPadBottomMargin(0.13)
163 tdrStyle.SetPadLeftMargin(0.13)
164 tdrStyle.SetPadRightMargin(0.05)
167 tdrStyle.SetOptTitle(0)
168 tdrStyle.SetTitleFont(42)
169 tdrStyle.SetTitleColor(1)
170 tdrStyle.SetTitleTextColor(1)
171 tdrStyle.SetTitleFillColor(10)
172 tdrStyle.SetTitleFontSize(0.05)
181 tdrStyle.SetTitleColor(1,
"XYZ")
182 tdrStyle.SetTitleFont(42,
"XYZ")
183 tdrStyle.SetTitleSize(0.06,
"XYZ")
186 tdrStyle.SetTitleXOffset(0.9)
187 tdrStyle.SetTitleYOffset(1.05)
191 tdrStyle.SetLabelColor(1,
"XYZ")
192 tdrStyle.SetLabelFont(42,
"XYZ")
193 tdrStyle.SetLabelOffset(0.007,
"XYZ")
194 tdrStyle.SetLabelSize(0.05,
"XYZ")
197 tdrStyle.SetAxisColor(1,
"XYZ")
198 tdrStyle.SetStripDecimals(
True)
199 tdrStyle.SetTickLength(0.03,
"XYZ")
200 tdrStyle.SetNdivisions(510,
"XYZ")
201 tdrStyle.SetPadTickX(1)
202 tdrStyle.SetPadTickY(1)
205 tdrStyle.SetOptLogx(0)
206 tdrStyle.SetOptLogy(0)
207 tdrStyle.SetOptLogz(0)
210 tdrStyle.SetPaperSize(20.,20.)
228 """Set a color palette from a given RGB list 229 stops, red, green and blue should all be lists of the same length 230 see set_decent_colors for an example""" 232 if name ==
"halfgray":
233 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
234 red =
map(
lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
235 green =
map(
lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
236 blue =
map(
lambda x: 1. - (1.-x)/2., [1.00, 0.84, 0.61, 0.34, 0.00])
238 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
239 red = [1.00, 0.84, 0.61, 0.34, 0.00]
240 green = [1.00, 0.84, 0.61, 0.34, 0.00]
241 blue = [1.00, 0.84, 0.61, 0.34, 0.00]
242 elif name ==
"blues":
243 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
244 red = [1.00, 0.84, 0.61, 0.34, 0.00]
245 green = [1.00, 0.84, 0.61, 0.34, 0.00]
246 blue = [1.00, 1.00, 1.00, 1.00, 1.00]
248 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
249 red = [1.00, 1.00, 1.00, 1.00, 1.00]
250 green = [1.00, 0.84, 0.61, 0.34, 0.00]
251 blue = [1.00, 0.84, 0.61, 0.34, 0.00]
252 elif name ==
"antigray":
253 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
254 red = [1.00, 0.84, 0.61, 0.34, 0.00]
255 green = [1.00, 0.84, 0.61, 0.34, 0.00]
256 blue = [1.00, 0.84, 0.61, 0.34, 0.00]
261 stops = [0.00, 0.20, 0.80, 1.00]
262 red = [1.00, 1.00, 1.00, 0.50]
263 green = [1.00, 1.00, 0.00, 0.00]
264 blue = [0.20, 0.00, 0.00, 0.00]
265 elif name ==
"antifire":
266 stops = [0.00, 0.20, 0.80, 1.00]
267 red = [0.50, 1.00, 1.00, 1.00]
268 green = [0.00, 0.00, 1.00, 1.00]
269 blue = [0.00, 0.00, 0.00, 0.20]
272 stops = [0.00, 0.34, 0.61, 0.84, 1.00]
273 red = [0.00, 0.00, 0.87, 1.00, 0.51]
274 green = [0.00, 0.81, 1.00, 0.20, 0.00]
275 blue = [0.51, 1.00, 0.12, 0.00, 0.00]
277 s = array.array(
'd', stops)
278 r = array.array(
'd', red)
279 g = array.array(
'd', green)
280 b = array.array(
'd', blue)
283 ROOT.TColor.CreateGradientColorTable(npoints, s, r, g, b, ncontours)
284 ROOT.gStyle.SetNumberContours(ncontours)
294 phiedgesCSC36 = [pi/180.*(-5. + 10.*i)
for i
in range(36)]
295 phiedgesCSC18 = [pi/180.*(-5. + 20.*i)
for i
in range(18)]
307 [0.35228048120123945, 0.87587781482541827, 1.3994776462193192, 1.923076807996136, 2.4466741416203148, 2.970273973014216,
308 -2.7893121723885534, -2.2657148387643748, -1.7421150073704739, -1.2185158455936571, -0.69491851196947851, -0.17131868057557731],
309 [0.22000706229660855, 0.74360690430428489, 1.267204926935573, 1.7908033890915052, 2.3144032310991816, 2.8380012537304697,
310 -2.9215855912931841, -2.3979857492855081, -1.8743877266542202, -1.3507892644982882, -0.82718942249061178, -0.30359139985932365],
311 [0.29751957124275596, 0.82111826253905784, 1.3447162969496083, 1.8683158980376524, 2.3919145893339548, 2.915512623744505,
312 -2.844073082347037, -2.3204743910507353, -1.7968763566401849, -1.2732767555521407, -0.74967806425583894, -0.22608002984528835],
313 [3.0136655290752188, -2.7530905195097337, -2.2922883025568734, -1.9222915077192773, -1.5707963267948966, -1.2193011458705159,
314 -0.84930435103291968, -0.38850213408005951, 0.127927124514574, 0.65152597487624719, 1.1322596819239259, 1.5707963267948966,
315 2.0093329716658674, 2.4900666787135459]]
319 for ed
in phiedges[:]:
322 ed.extend([999
for n
in range(0,37-len(ed))])
323 lines.append(
'{' +
', '.
join(
map(str, ed)) +
'}')
325 res =
', '.
join(lines)
326 ff = open(
"phiedges_export.h",mode=
"w")
327 print(
'double phiedges[14][37] = {' + res +
'};', file=ff)
336 self.ed.append(pi+1.)
341 if x < self.
ed[0]: x += 2*pi
343 for i
in range(0,self.
n):
344 if x <= self.
ed[i]:
continue 345 if x > self.
ed[i+1]:
continue 346 return par[i*2] + par[i*2+1]*(x - self.
ed[i])
355 if (
"MB" in name
or "ME" in name):
358 if pa
is None:
return None 360 if pa[2]==1
and pa[3]==1:
return 0
361 if pa[2]==1
and pa[3]==2:
return 1
362 if pa[2]==1
and pa[3]==3:
return 2
363 if pa[2]==1
and pa[3]==4:
return 3
364 if pa[2]==2
and pa[3]==1:
return 4
365 if pa[2]==2
and pa[3]==2:
return 5
366 if pa[2]==3
and pa[3]==1:
return 6
367 if pa[2]==3
and pa[3]==2:
return 7
368 if pa[2]==4
and pa[3]==1:
return 8
369 if pa[2]==4
and pa[3]==2:
return 9
371 if pa[2]==1:
return 10
372 if pa[2]==2:
return 11
373 if pa[2]==3:
return 12
374 if pa[2]==4:
return 13
376 if (
"mem11" in name
or "mep11" in name):
return 0
377 if (
"mem12" in name
or "mep12" in name):
return 1
378 if (
"mem13" in name
or "mep13" in name):
return 2
379 if (
"mem14" in name
or "mep14" in name):
return 3
380 if (
"mem21" in name
or "mep21" in name):
return 4
381 if (
"mem22" in name
or "mep22" in name):
return 5
382 if (
"mem31" in name
or "mep31" in name):
return 6
383 if (
"mem32" in name
or "mep32" in name):
return 7
384 if (
"mem41" in name
or "mep41" in name):
return 8
385 if (
"mem42" in name
or "mep42" in name):
return 9
386 if (
"st1" in name):
return 10
387 if (
"st2" in name):
return 11
388 if (
"st3" in name):
return 12
389 if (
"st4" in name):
return 13
394 global philine_tlines, philine_labels
399 if abscissa
is None or abscissa[0] < phi < abscissa[1]:
400 philine_tlines.append(ROOT.TLine(phi, -window, phi, window))
401 philine_tlines[-1].SetLineStyle(2)
402 philine_tlines[-1].Draw()
405 edges = sorted(edges[:])
407 labels = [
" 7",
" 8",
" 9",
"14",
"10",
"11",
"12",
" 1",
" 2",
" 3",
"13",
" 4",
" 5",
" 6"]
409 labels = [
" 8",
" 9",
"10",
"11",
"12",
" 1",
" 2",
" 3",
" 4",
" 5",
" 6"]
411 for phi, label
in zip(edges, labels):
413 if label
in (
" 7",
" 9",
"14",
"10",
"11"): littlebit = 0.05
414 philine_labels.append(ROOT.TText(phi-0.35+littlebit, -0.9*window, label))
415 philine_labels[-1].Draw()
416 philine_labels.append(ROOT.TText(-2.9, -0.75*window,
"Sector:"))
417 philine_labels[-1].Draw()
420 edges = sorted(edges[:])
421 labels = [
" 1",
" 2",
" 3",
" 4",
" 5",
" 6",
" 7",
" 8",
" 9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
422 "19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36"]
426 for phi, label
in zip(edges, labels):
429 philine_labels.append(ROOT.TText(phi+littlebit, -0.9*window, label))
430 philine_labels[-1].SetTextFont(42)
431 philine_labels[-1].SetTextSize(0.028)
432 philine_labels[-1].Draw()
433 philine_labels.append(ROOT.TText(0, -0.78*window,
"Chamber:"))
434 philine_labels[-1].SetTextSize(0.035)
435 philine_labels[-1].Draw()
440 for z
in -401.625, -133.875, 133.875, 401.625:
441 if abscissa
is None or abscissa[0] < z < abscissa[1]:
442 zline_tlines.append(ROOT.TLine(z, -window, z, window))
443 zline_tlines[-1].SetLineStyle(2)
444 zline_tlines[-1].Draw()
446 zline_labels.append(ROOT.TText(-550, -0.9*window,
"-2"))
447 zline_labels.append(ROOT.TText(-300, -0.9*window,
"-1"))
448 zline_labels.append(ROOT.TText(-10, -0.9*window,
"0"))
449 zline_labels.append(ROOT.TText(250, -0.9*window,
"+1"))
450 zline_labels.append(ROOT.TText(500, -0.9*window,
"+2"))
451 for z
in zline_labels: z.Draw()
452 zline_labels.append(ROOT.TText(-600, -0.75*window,
"Wheel:")); zline_labels[-1].Draw()
457 if disk == 1: rl = [150., 270., 480.]
460 if abscissa
is None or abscissa[0] < r < abscissa[1]:
461 rline_tlines.append(ROOT.TLine(r, -window, r, window))
462 rline_tlines[-1].SetLineStyle(2)
463 rline_tlines[-1].Draw()
469 if postal_address == r.postal_address:
476 def DBMC(database, reports, window=10., windows=None, selection=None, phi=False,
477 color=ROOT.kBlue-8, style=1, bins=50, normalized=
False, getvalues=
False, name=
"", canvas=
None, reportdiff=
False, inlog=
True):
478 return DBdiff(database,
None, reports,
None, window, windows, selection, phi, color, style, bins, normalized, getvalues,
479 name, canvas, reportdiff, inlog)
482 def DBdiff(database1, database2, reports1, reports2,
483 window=10., windows=
None, selection=
None, phi=
False, color=ROOT.kBlue-8,
484 style=1, bins=50, normalized=
False, getvalues=
False, name=
"tmp", canvas=
None, reportdiff=
False, inlog=
False ):
486 tdrStyle.SetOptStat(
"emrou")
487 tdrStyle.SetStatW(0.40)
490 if windows
is not None:
496 global hx, hy, hz, hphix, hphiy, hphiz
499 hx = ROOT.TH1F(
"%s_phi" % name,
"", bins, -wnd[0], wnd[0])
501 hx = ROOT.TH1F(
"%s_x" % name,
"", bins, -wnd[0], wnd[0])
502 hy = ROOT.TH1F(
"%s_y" % name,
"", bins, -wnd[1], wnd[1])
503 hz = ROOT.TH1F(
"%s_z" % name,
"", bins, -wnd[2], wnd[2])
504 hphix = ROOT.TH1F(
"%s_phix" % name,
"", bins, -wnd[3], wnd[3])
505 hphiy = ROOT.TH1F(
"%s_phiy" % name,
"", bins, -wnd[4], wnd[4])
506 hphiz = ROOT.TH1F(
"%s_phiz" % name,
"", bins, -wnd[5], wnd[5])
509 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
511 r2 = Report(r1.chamberId, r1.postal_address, r1.name)
512 r2.add_parameters(ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.),
513 ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.), 0., 0., 0., 0.)
516 if r2
is None:
continue 519 if r1.postal_address[0] ==
"DT":
520 if r1.postal_address[1:]
in database1.dt:
522 db1 = database1.dt[r1.postal_address[1:]]
523 if database2
is None:
525 db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
526 db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
528 db2 = database2.dt[r1.postal_address[1:]]
532 if r1.postal_address[2]==1
and r1.postal_address[3]==4:
continue 533 if r1.postal_address[1:]
in database1.csc:
535 db1 = database1.csc[r1.postal_address[1:]]
536 if database2
is None:
538 db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
539 db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
541 db2 = database2.csc[r1.postal_address[1:]]
543 if found
and r1.status ==
"PASS" and r2.status ==
"PASS":
544 if r1.deltax
is not None and r2.deltax
is not None and r1.deltax.error
is not None and \
545 r2.deltax.error
is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
546 delta = db1.x - db2.x
547 if reportdiff: delta -= r1.deltax.value
549 fill = delta/
sqrt(r1.deltax.error**2 + r2.deltax.error**2) * signConventions[r1.postal_address][0]
552 fill = delta/signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0]
554 fill = delta * 10. * signConventions[r1.postal_address][0]
556 if getvalues
not in (
False,
None):
557 getvalues[
"x"].
append((fill, 10. *
sqrt(r1.deltax.error**2 + r2.deltax.error**2)))
559 if r1.deltay
is not None and r2.deltay
is not None and r1.deltay.error
is not None and \
560 r2.deltay.error
is not None and (r1.deltay.error**2 + r2.deltay.error**2) > 0.:
561 delta = db1.y - db2.y
562 if reportdiff: delta -= r1.deltay.value
564 fill = delta/
sqrt(r1.deltay.error**2 + r2.deltay.error**2) * signConventions[r1.postal_address][1]
566 fill = delta * 10. * signConventions[r1.postal_address][1]
568 if getvalues
not in (
False,
None):
569 getvalues[
"y"].
append((fill, 10. *
sqrt(r1.deltay.error**2 + r2.deltay.error**2)))
571 if r1.deltaz
is not None and r2.deltaz
is not None and r1.deltaz.error
is not None and \
572 r2.deltaz.error
is not None and (r1.deltaz.error**2 + r2.deltaz.error**2) > 0.:
573 delta = db1.z - db2.z
574 if reportdiff: delta -= r1.deltaz.value
576 fill = delta/
sqrt(r1.deltaz.error**2 + r2.deltaz.error**2) * signConventions[r1.postal_address][2]
578 fill = delta * 10. * signConventions[r1.postal_address][2]
580 if getvalues
not in (
False,
None):
581 getvalues[
"z"].
append((fill, 10. *
sqrt(r1.deltaz.error**2 + r2.deltaz.error**2)))
583 if r1.deltaphix
is not None and r2.deltaphix
is not None and r1.deltaphix.error
is not None and \
584 r2.deltaphix.error
is not None and (r1.deltaphix.error**2 + r2.deltaphix.error**2) > 0.:
585 delta = db1.phix - db2.phix
586 if reportdiff: delta -= r1.deltaphix.value
588 fill = delta/
sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)
592 if getvalues
not in (
False,
None):
593 getvalues[
"phix"].
append((fill, 10. *
sqrt(r1.deltaphix.error**2 + r2.deltaphix.error**2)))
595 if r1.deltaphiy
is not None and r2.deltaphiy
is not None and r1.deltaphiy.error
is not None and \
596 r2.deltaphiy.error
is not None and (r1.deltaphiy.error**2 + r2.deltaphiy.error**2) > 0.:
597 delta = db1.phiy - db2.phiy
599 delta -= r1.deltaphiy.value
600 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)
602 fill = delta/
sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)
606 if getvalues
not in (
False,
None):
607 getvalues[
"phiy"].
append((fill, 10. *
sqrt(r1.deltaphiy.error**2 + r2.deltaphiy.error**2)))
609 if r1.deltaphiz
is not None and r2.deltaphiz
is not None and r1.deltaphiz.error
is not None and \
610 r2.deltaphiz.error
is not None and (r1.deltaphiz.error**2 + r2.deltaphiz.error**2) > 0.:
611 delta = db1.phiz - db2.phiz
612 if reportdiff: delta -= r1.deltaphiz.value
614 fill = delta/
sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)
618 if getvalues
not in (
False,
None):
619 getvalues[
"phiz"].
append((fill, 10. *
sqrt(r1.deltaphiz.error**2 + r2.deltaphiz.error**2)))
623 hx.SetXTitle(
"#delta_{#phi} position (mrad)")
625 hx.SetXTitle(
"#delta_{x'} (mm)")
626 hy.SetXTitle(
"#delta_{y'} (mm)")
627 hz.SetXTitle(
"#delta_{z'} (mm)")
628 hphix.SetXTitle(
"#delta_{#phi_{x}} (mrad)")
629 hphiy.SetXTitle(
"#delta_{#phi_{y}} (mrad)")
630 hphiz.SetXTitle(
"#delta_{#phi_{z}} (mrad)")
633 hx.SetXTitle(
"#delta_{#phi}(XML) - #delta_{#phi}(report) position (mrad)")
635 hx.SetXTitle(
"#delta_{x'}(XML) - #delta_{x'}(report) (mm)")
636 hy.SetXTitle(
"#delta_{y'}(XML) - #delta_{y'}(report) (mm)")
637 hz.SetXTitle(
"#delta_{z'}(XML) - #delta_{z'}(report) (mm)")
638 hphix.SetXTitle(
"#delta_{#phi_{x}}(XML) - #delta_{#phi_{x}}(report) (mrad)")
639 hphiy.SetXTitle(
"#delta_{#phi_{y}}(XML) - #delta_{#phi_{y}}(report) (mrad)")
640 hphiz.SetXTitle(
"#delta_{#phi_{z}}(XML) - #delta_{#phi_{z}}(report) (mrad)")
643 hx.SetXTitle(
"#delta_{#phi}/#sigma_{#phi} position")
645 hx.SetXTitle(
"#delta_{x'}/#sigma_{x'}")
646 hy.SetXTitle(
"#delta_{y'}/#sigma_{y'}")
647 hz.SetXTitle(
"#delta_{z'}/#sigma_{z'}")
648 hphix.SetXTitle(
"#delta_{#phi_{x}}/#sigma_{#phi_{x}}")
649 hphiy.SetXTitle(
"#delta_{#phi_{y}}/#sigma_{#phi_{y}}")
650 hphiz.SetXTitle(
"#delta_{#phi_{z}}/#sigma_{#phi_{z}}")
652 for h
in hx, hy, hz, hphix, hphiy, hphiz:
653 h.GetXaxis().CenterTitle()
654 h.GetYaxis().CenterTitle()
655 h.SetFillColor(color)
656 h.SetLineStyle(style)
658 if canvas
is not None: c = canvas
662 fx = ROOT.TF1(
"fx",
"%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hx.GetEntries()*2.*window/bins), -window, window)
663 fy = ROOT.TF1(
"fy",
"%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hy.GetEntries()*2.*window/bins), -window, window)
664 fz = ROOT.TF1(
"fz",
"%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hz.GetEntries()*2.*window/bins), -window, window)
665 fphix = ROOT.TF1(
"fphix",
"%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphix.GetEntries()*2.*window/bins), -window, window)
666 fphiy = ROOT.TF1(
"fphiy",
"%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphiy.GetEntries()*2.*window/bins), -window, window)
667 fphiz = ROOT.TF1(
"fphiz",
"%g * exp(-x**2/2.)/sqrt(2.*3.1415926)" % (hphiz.GetEntries()*2.*window/bins), -window, window)
668 for f
in fx, fy, fz, fphix, fphiy, fphiz:
670 f.SetLineColor(ROOT.kBlue)
671 for h, f
in (hx, fx), (hy, fy), (hz, fz), (hphix, fphix), (hphiy, fphiy), (hphiz, fphiz):
672 h.SetAxisRange(0, 1.1*
max(h.GetMaximum(), f.GetMaximum()),
"Y")
676 c.GetPad(1).cd(); hx.Draw(); fx.Draw(
"same")
677 c.GetPad(2).cd(); hy.Draw(); fy.Draw(
"same")
678 c.GetPad(3).cd(); hz.Draw(); fz.Draw(
"same")
679 c.GetPad(4).cd(); hphix.Draw(); fphix.Draw(
"same")
680 c.GetPad(5).cd(); hphiy.Draw(); fphiy.Draw(
"same")
681 c.GetPad(6).cd(); hphiz.Draw(); fphiz.Draw(
"same")
682 return hx, hy, hz, hphix, hphiy, hphiz, fx, fy, fz, fphix, fphiy, fphiz
687 if nvar == 4: c.Divide(2, 2)
688 if nvar == 6: c.Divide(3, 2)
689 c.GetPad(1).cd(); hx.Draw()
690 c.GetPad(2).cd(); hy.Draw()
692 c.GetPad(3).cd(); hphiy.Draw()
693 c.GetPad(4).cd(); hphiz.Draw()
695 c.GetPad(3).cd(); hz.Draw()
696 c.GetPad(4).cd(); hphix.Draw()
697 c.GetPad(5).cd(); hphiy.Draw()
698 c.GetPad(6).cd(); hphiz.Draw()
701 if hx.GetEntries()>0: c.GetPad(1).SetLogy(1)
702 if hy.GetEntries()>0: c.GetPad(2).SetLogy(1)
704 if hphiy.GetEntries()>0: c.GetPad(3).SetLogy(1)
705 if hphiz.GetEntries()>0: c.GetPad(4).SetLogy(1)
707 if hz.GetEntries()>0: c.GetPad(3).SetLogy(1)
708 if hphix.GetEntries()>0: c.GetPad(4).SetLogy(1)
709 if hphiy.GetEntries()>0: c.GetPad(5).SetLogy(1)
710 if hphiz.GetEntries()>0: c.GetPad(6).SetLogy(1)
712 return hx, hy, hz, hphix, hphiy, hphiz
716 def DBMCVersus(quantity, versus, database, reports, window=10., selection=None, color=ROOT.kBlack):
717 return DBdiffVersus(quantity, versus, database,
None, reports,
None, window, selection, color)
719 def DBdiffVersus(quantity, versus, database1, database2, reports1, reports2, windwselection=None, color=ROOT.kBlack):
720 tdrStyle.SetOptStat(
"")
727 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
729 r2 = Report(r1.chamberId, r1.postal_address, r1.name)
730 r2.add_parameters(ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.),
731 ValErr(0., 0., 0.), ValErr(0., 0., 0.), ValErr(0., 0., 0.), 0., 0., 0.)
735 if r1.postal_address == r2.postal_address:
738 if not found:
continue 741 if r1.postal_address[0] ==
"DT":
742 if r1.postal_address[1:]
in database1.dt:
744 db1 = database1.dt[r1.postal_address[1:]]
745 if database2
is None:
747 db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
748 db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
750 db2 = database2.dt[r1.postal_address[1:]]
752 if r1.postal_address[1:]
in database1.csc:
754 db1 = database1.csc[r1.postal_address[1:]]
755 if database2
is None:
757 db2.x = db2.y = db2.z = db2.phix = db2.phiy = db2.phiz = 0.
758 db2.xx = db2.xy = db2.xz = db2.yx = db2.yy = db2.yz = db2.zx = db2.zy = db2.zz = 0.
760 db2 = database2.csc[r1.postal_address[1:]]
762 if found
and r1.status ==
"PASS" and r2.status ==
"PASS":
765 if quantity ==
"phi":
766 if r1.deltax
is not None and r2.deltax
is not None and r1.deltax.error
is not None and \
767 r2.deltax.error
is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
769 values.append((db1.x - db2.x)/
770 signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0])
771 errors.append((r1.deltax.error**2 + r2.deltax.error**2)/
772 signConventions[r1.postal_address][3] * 1000. * signConventions[r1.postal_address][0])
774 elif quantity ==
"x":
775 if r1.deltax
is not None and r2.deltax
is not None and r1.deltax.error
is not None and \
776 r2.deltax.error
is not None and (r1.deltax.error**2 + r2.deltax.error**2) > 0.:
778 values.append((db1.x - db2.x) * 10. * signConventions[r1.postal_address][0])
779 errors.append((r1.deltax.error**2 + r2.deltax.error**2) * 10. * signConventions[r1.postal_address][0])
781 elif quantity ==
"y":
782 if r1.deltay
is not None and r2.deltay
is not None and r1.deltay.error
is not None and \
783 r2.deltay.error
is not None and (r1.deltay.error**2 + r2.deltay.error**2) > 0.:
785 values.append((db1.y - db2.y) * 10. * signConventions[r1.postal_address][1])
786 errors.append((r1.deltay.error**2 + r2.deltay.error**2) * 10. * signConventions[r1.postal_address][1])
788 elif quantity ==
"z":
789 if r1.deltaz
is not None and r2.deltaz
is not None and r1.deltaz.error
is not None and \
790 r2.deltaz.error
is not None and (r1.deltaz.error**2 + r2.deltaz.error**2) > 0.:
792 values.append((db1.z - db2.z) * 10. * signConventions[r1.postal_address][2])
793 errors.append((r1.deltaz.error**2 + r2.deltaz.error**2) * 10. * signConventions[r1.postal_address][2])
795 elif quantity ==
"phix":
796 if r1.deltaphix
is not None and r2.deltaphix
is not None and r1.deltaphix.error
is not None and \
797 r2.deltaphix.error
is not None and (r1.deltaphix.error**2 + r2.deltaphix.error**2) > 0.:
799 values.append((db1.phix - db2.phix) * 1000.)
800 errors.append((r1.deltaphix.error**2 + r2.deltaphix.error**2) * 1000.)
802 elif quantity ==
"phiy":
803 if r1.deltaphiy
is not None and r2.deltaphiy
is not None and r1.deltaphiy.error
is not None and \
804 r2.deltaphiy.error
is not None and (r1.deltaphiy.error**2 + r2.deltaphiy.error**2) > 0.:
806 values.append((db1.phiy - db2.phiy) * 1000.)
807 errors.append((r1.deltaphiy.error**2 + r2.deltaphiy.error**2) * 1000.)
809 elif quantity ==
"phiz":
810 if r1.deltaphiz
is not None and r2.deltaphiz
is not None and r1.deltaphiz.error
is not None and \
811 r2.deltaphiz.error
is not None and (r1.deltaphiz.error**2 + r2.deltaphiz.error**2) > 0.:
813 values.append((db1.phiz - db2.phiz) * 1000.)
814 errors.append((r1.deltaphiz.error**2 + r2.deltaphiz.error**2) * 1000.)
816 else:
raise Exception
819 if versus ==
"r": domain.append(signConventions[r1.postal_address][3]) 820 elif versus ==
"phi": domain.append(signConventions[r1.postal_address][4])
821 elif versus ==
"z": domain.append(signConventions[r1.postal_address][5])
822 else:
raise Exception
825 bkgndhist = ROOT.TH1F("bkgndhist",
"", 100, 0., 800.)
826 bkgndhist.SetXTitle(
"R (cm)")
827 elif versus ==
"phi":
828 bkgndhist = ROOT.TH1F(
"bkgndhist",
"", 100, -pi, pi)
829 bkgndhist.SetXTitle(
"#phi (rad)")
831 bkgndhist = ROOT.TH1F(
"bkgndhist",
"", 100, -1100., 1100.)
832 bkgndhist.SetXTitle(
"z (cm)")
833 bkgndhist.GetXaxis().CenterTitle()
835 bkgndhist.SetAxisRange(-window, window,
"Y")
836 if quantity ==
"phi": bkgndhist.SetYTitle(
"#delta_{#phi} position (mrad)")
837 elif quantity ==
"x": bkgndhist.SetYTitle(
"#delta_{x'} (mm)")
838 elif quantity ==
"y": bkgndhist.SetYTitle(
"#delta_{y'} (mm)")
839 elif quantity ==
"z": bkgndhist.SetYTitle(
"#delta_{z'} (mm)")
840 elif quantity ==
"phix": bkgndhist.SetYTitle(
"#delta_{#phi_{x}} (mrad)")
841 elif quantity ==
"phiy": bkgndhist.SetYTitle(
"#delta_{#phi_{y}} (mrad)")
842 elif quantity ==
"phiz": bkgndhist.SetYTitle(
"#delta_{#phi_{z}} (mrad)")
843 else:
raise Exception
844 bkgndhist.GetYaxis().CenterTitle()
847 tgraph = ROOT.TGraphErrors(0)
849 tgraph = ROOT.TGraphErrors(len(domain), array.array(
"d", domain), array.array(
"d", values),
850 array.array(
"d", [0.]*len(domain)), array.array(
"d", errors))
851 tgraph.SetMarkerColor(color)
852 tgraph.SetLineColor(color)
855 if tgraph.GetN() > 0: tgraph.Draw(
"p")
856 return bkgndhist, tgraph, domain, values, errors
862 if len(id)!=9:
return None 865 pa = (
"DT",
int(id[2:4]),
int(id[5]),
int(id[7:9]))
867 if pa[1]<-2
or pa[1]>2:
return None 868 if pa[2]>4:
return None 869 if pa[3]<1
or pa[3]>14
or (pa[3]==4
and pa[3]>12):
return None 873 elif id[2]==
"-": ec=2
875 pa = (
"CSC", ec,
int(id[3]),
int(id[5]),
int(id[7:9]))
876 if pa[2]<1
or pa[2]>4:
return None 877 if pa[3]<1
or pa[3]>4
or (pa[2]>1
and pa[3]>2):
return None 878 if pa[4]<1
or pa[4]>36
or (pa[2]>1
and pa[3]==1
and pa[4]>18):
return None 884 if postal_address[0] ==
"DT":
885 wheel, station, sector = postal_address[1:]
888 return "MB%s/%d/%02d" % (w, station, sector)
889 elif postal_address[0] ==
"CSC":
890 endcap, station, ring, chamber = postal_address[1:]
891 if endcap != 1: station = -1 *
abs(station)
892 return "ME%+d/%d/%02d" % (station, ring, chamber)
896 if name[0:2] ==
"MB":
898 if wh ==
"A": w =
"-2" 899 elif wh ==
"B": w =
"-1" 900 elif wh ==
"C": w =
"-0" 901 elif wh ==
"D": w =
"+1" 902 elif wh ==
"E": w =
"+2" 906 return "MB%s/%s/%s" % (w, station, sector)
907 elif name[0:2] ==
"ME":
908 if name[2]==
"p": endcap =
"+" 909 elif name[2]==
"m": endcap =
"-" 914 return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
921 for iwheel
in DT_TYPES:
922 if iwheel[1]==
"ALL":
continue 923 dts.append(iwheel[0])
925 for wheel
in DT_TYPES:
926 if wheel[1]==
"ALL":
continue 927 for station
in wheel[2]:
928 dts.append(wheel[0]+
'/'+station[1])
930 for wheel
in DT_TYPES:
931 if wheel[1]!=
"ALL":
continue 932 for station
in wheel[2]:
933 for sector
in range(1,station[2]+1):
934 ssector =
"%02d" % sector
935 dts.append(wheel[0]+
'/'+station[1]+
'/'+ssector)
937 for wheel
in DT_TYPES:
938 if wheel[1]!=
"ALL":
continue 939 for station
in wheel[2]:
940 dts.append(wheel[0]+
'/'+station[1])
942 for wheel
in DT_TYPES:
943 if wheel[1]==
"ALL":
continue 944 for station
in wheel[2]:
945 for sector
in range(1,station[2]+1):
946 ssector =
"%02d" % sector
947 label =
"MBwh%sst%ssec%s" % (
wheelLetter(
int(wheel[1])),station[1],ssector)
957 if not found:
continue 958 if r.status ==
"TOOFEWHITS" and r.posNum+r.negNum==0:
continue 959 if r.status ==
"NOFIT":
continue 960 dts.append(wheel[0]+
'/'+station[1]+
'/'+ssector)
967 for endcap
in CSC_TYPES:
968 for station
in endcap[2]:
969 cscs.append(
"%s%s" % (endcap[0], station[1]))
971 for endcap
in CSC_TYPES:
972 for station
in endcap[2]:
973 for ring
in station[2]:
974 if ring[1]==
"ALL":
continue 976 cscs.append(
"%s%s/%s" % (endcap[0], station[1],ring[1]))
978 for endcap
in CSC_TYPES:
979 for station
in endcap[2]:
980 for ring
in station[2]:
981 if ring[1]!=
"ALL":
continue 982 for chamber
in range(1,ring[2]+1):
984 cscs.append(
"%s%s/ALL/%02d" % (endcap[0], station[1],chamber))
986 for endcap
in CSC_TYPES:
987 for station
in endcap[2]:
988 for ring
in station[2]:
989 if ring[1]!=
"ALL":
continue 991 cscs.append(
"%s%s/ALL" % (endcap[0], station[1]))
993 for endcap
in CSC_TYPES:
994 for station
in endcap[2]:
995 for ring
in station[2]:
996 if ring[1]==
"ALL":
continue 997 for chamber
in range(1,ring[2]+1):
999 if station[1]==
"4" and ring[1]==
"2":
1000 if endcap[1]==
"m":
continue 1001 if chamber<9
or chamber>13:
continue 1002 schamber =
"%02d" % chamber
1003 label =
"ME%s%s%s_%s" % (endcap[1], station[1], ring[1], schamber)
1013 if not found:
continue 1014 if r.status ==
"TOOFEWHITS" and r.posNum+r.negNum==0:
continue 1015 if r.status ==
"NOFIT":
continue 1016 cscs.append(endcap[0]+station[1]+
'/'+ring[1]+
'/'+schamber)
1021 {
"idx":0,
"name":
"NONE",
"color":
"lightgreen",
"hex":
"#90EE90"},
1022 {
"idx":1,
"name":
"LOWSTAT05",
"color":
"lightgreen",
"hex":
"#96D953"},
1023 {
"idx":2,
"name":
"LOWSTAT075",
"color":
"lightgreen",
"hex":
"#94E26F"},
1024 {
"idx":3,
"name":
"LOWSTAT1",
"color":
"yellowgreen",
"hex":
"#9ACD32"},
1025 {
"idx":4,
"name":
"LOWSTAT",
"color":
"yellow",
"hex":
"#FFFF00"},
1026 {
"idx":5,
"name":
"TOLERABLE",
"color":
"lightpink",
"hex":
"#FFB6C1"},
1027 {
"idx":6,
"name":
"SEVERE",
"color":
"orange",
"hex":
"#FFA500"},
1028 {
"idx":7,
"name":
"CRITICAL",
"color":
"red",
"hex":
"#FF0000"}];
1033 if c
in TEST_RESULTS: TEST_RESULTS[c].extend(res)
1034 else: TEST_RESULTS[c] = res
1039 for sev
in DQM_SEVERITY:
1040 if sev[
"name"]==severity: s = sev[
"idx"]
1041 return {
"testID":testID,
"scope":scope,
"descr":descr,
"severity":s}
1045 if abs(x[1])==0.:
return 0.
1046 pull =
abs(x[0])/
abs(x[1])
1047 if pull <= 5:
return 0.
1057 for i
in range(1,n+1):
1065 sig1 =
sqrt( (sx1[0]-sx1[1])**2 + x1[1]**2 )
1066 sig2 =
sqrt( (sx2[0]-sx2[1])**2 + x2[1]**2 )
1067 df =
abs(x1[0]-x2[0]) - 3*( sig1 + sig2 )
1071 if df > 0: res.append(i)
1081 if not postal_address:
continue 1086 if r.postal_address == postal_address:
1089 if not found:
continue 1093 scope = postal_address[0]
1096 if r.status ==
"FAIL" or r.status ==
"MINUITFAIL":
1097 res.append(
testEntry(
"FAILURE",scope,r.status+
" failure",
"CRITICAL"))
1102 nseg = r.posNum + r.negNum
1103 if r.status ==
"TOOFEWHITS" and nseg>0:
1104 res.append(
testEntry(
"LOW_STAT",scope,
"low stat, #segments=%d"%nseg,
"LOWSTAT"))
1109 sdx = 10.*r.deltax.error
1111 if sdx<0.75: res.append(
testEntry(
"LOW_STAT_DDX05",scope,
"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),
"LOWSTAT05"))
1112 elif sdx<1.: res.append(
testEntry(
"LOW_STAT_DDX075",scope,
"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),
"LOWSTAT075"))
1113 else: res.append(
testEntry(
"LOW_STAT_DDX1",scope,
"low stat, delta(dx)=%f #segments=%d" % (sdx,nseg),
"LOWSTAT1"))
1117 res.append(
testEntry(
"BIG_CHI2",scope,
"chi2=%f>20" % r.redchi2,
"TOLERABLE"))
1120 medx, meddx = 10.*r.median_x, 1000.*r.median_dxdz
1122 if medx>2: res.append(
testEntry(
"BIG_MED_X",scope,
"median dx=%f>2 mm"%medx,
"SEVERE"))
1124 if meddx>2: res.append(
testEntry(
"BIG_MED_DXDZ",scope,
"median d(dx/dz)=%f>2 mrad"%meddx,
"SEVERE"))
1129 if postal_address[0] ==
"DT" and postal_address[2]==4: isDTst4 =
True 1130 dx, dy, dpy, dpz = 10.*r.deltax.value, 0., 1000.*r.deltaphiy.value, 1000.*r.deltaphiz.value
1131 if not isDTst4: dy = 10.*r.deltay.value
1132 if dx>0.2: res.append(
testEntry(
"BIG_LAST_ITR_DX",scope,
"dx=%f>0.2 mm"%dx,
"CRITICAL"))
1133 if dy>0.2: res.append(
testEntry(
"BIG_LAST_ITR_DY",scope,
"dy=%f>0.2 mm"%dy,
"CRITICAL"))
1134 if dpy>0.2: res.append(
testEntry(
"BIG_LAST_ITR_DPHIY",scope,
"dphiy=%f>0.2 mrad"%dpy,
"CRITICAL"))
1135 if dpz>0.2: res.append(
testEntry(
"BIG_LAST_ITR_DPHIZ",scope,
"dphiz=%f>0.2 mrad"%dpz,
"CRITICAL"))
1146 if c[0:2]==
"MB": scope =
"DT" 1147 if c[0:2]==
"ME": scope =
"CSC" 1149 print(
"strange cell ID: ", c)
1152 if c
in MAP_RESULTS_FITSIN:
1153 t = MAP_RESULTS_FITSIN[c]
1158 descr =
"map fitsin 5 sigma away from 0; pulls : a=%.2f sin=%.2f, cos=%.2f" % (t_a,t_s,t_c)
1159 res.append(
testEntry(
"MAP_FITSIN",scope,descr,
"SEVERE"))
1161 if c
in MAP_RESULTS_SAWTOOTH:
1162 t = MAP_RESULTS_SAWTOOTH[c]
1166 descr =
"map discontinuities: %s" %
",".
join(
map(str,t_a))
1167 res.append(
testEntry(
"MAP_DISCONTIN",scope,descr,
"SEVERE"))
1169 t_b =
map(testZeroWithin5Sigma, t[
'b'])
1171 for i
in range(0,len(t_b)):
1172 if t_b[i]>0: t_bi.append(i+1)
1174 descr =
"map sawteeth: %s" %
",".
join(
map(str,t_bi))
1175 res.append(
testEntry(
"MAP_SAWTEETH",scope,descr,
"TOLERABLE"))
1181 if len(MAP_RESULTS_SAWTOOTH)+len(MAP_RESULTS_FITSIN)==0:
return None 1182 ff = open(
"tmp_test_results_map__%s.pkl" % run_name,
"wb")
1183 pickle.dump(MAP_RESULTS_SAWTOOTH, ff)
1184 pickle.dump(MAP_RESULTS_FITSIN, ff)
1189 print(
"tmp_test_results_map__%s.pkl" % run_name, os.access(
"tmp_test_results_map__%s.pkl" % run_name,os.F_OK))
1190 if not os.access(
"tmp_test_results_map__%s.pkl" % run_name,os.F_OK):
return None 1191 global MAP_RESULTS_FITSIN, MAP_RESULTS_SAWTOOTH
1192 ff = open(
"tmp_test_results_map__%s.pkl" % run_name,
"rb")
1193 MAP_RESULTS_SAWTOOTH = pickle.load(ff)
1194 MAP_RESULTS_FITSIN = pickle.load(ff)
1202 for c
in TEST_RESULTS:
1203 tests.append({
"objID":c,
"name":c,
"list":TEST_RESULTS[c]})
1204 lt = time.localtime(time.time())
1205 lts =
"%04d-%02d-%02d %02d:%02d:%02d %s" % (lt[0], lt[1], lt[2], lt[3], lt[4], lt[5], time.tzname[1])
1206 dqm_report = {
"run":run_name,
"genDate": lts,
"report":tests}
1207 ff = open(fname_dqm,mode=
"w")
1208 print(
"var DQM_REPORT = ", file=ff)
1209 json.dump(dqm_report,ff)
1214 def doTests(reports, pic_ids, fname_base, fname_dqm, run_name):
1221 elif len(pic_ids)>0:
1222 dts = [id
for id
in pic_ids
if 'MB' in id]
1223 cscs = [id
for id
in pic_ids
if 'ME' in id]
1224 mulist = [
'Run: '+run_name,[
'ALL',[
'MU']],[
'DT',dts],[
'CSC',cscs]]
1225 ff = open(fname_base,mode=
"w")
1226 print(
"var MU_LIST = [", file=ff)
1227 json.dump(mulist,ff)
1228 print(
"];", file=ff)
1243 def plotmedians(reports1, reports2, selection=None, binsx=100, windowx=5., ceilingx=None, binsy=100, windowy=5.,
1244 ceilingy=
None, binsdxdz=100, windowdxdz=5., ceilingdxdz=
None, binsdydz=100, windowdydz=5., ceilingdydz=
None,
1245 r1text=
" before", r2text=
" after", which=
"median"):
1246 tdrStyle.SetOptStat(
"emrou")
1247 tdrStyle.SetStatW(0.40)
1248 tdrStyle.SetStatFontSize(0.05)
1250 global hmediandxdz_after, hmediandxdz_before, hmediandxdz_beforecopy, \
1251 hmediandydz_after, hmediandydz_before, hmediandydz_beforecopy, \
1252 hmedianx_after, hmedianx_before, hmedianx_beforecopy, \
1253 hmediany_after, hmediany_before, hmediany_beforecopy, tlegend
1255 hmedianx_before = ROOT.TH1F(
"hmedianx_before",
"", binsx, -windowx, windowx)
1256 hmediany_before = ROOT.TH1F(
"hmediany_before",
"", binsy, -windowy, windowy)
1257 hmediandxdz_before = ROOT.TH1F(
"hmediandxdz_before",
"", binsdxdz, -windowdxdz, windowdxdz)
1258 hmediandydz_before = ROOT.TH1F(
"hmediandydz_before",
"", binsdydz, -windowdydz, windowdydz)
1259 hmedianx_after = ROOT.TH1F(
"hmedianx_after",
"", binsx, -windowx, windowx)
1260 hmediany_after = ROOT.TH1F(
"hmediany_after",
"", binsy, -windowy, windowy)
1261 hmediandxdz_after = ROOT.TH1F(
"hmediandxdz_after",
"", binsdxdz, -windowdxdz, windowdxdz)
1262 hmediandydz_after = ROOT.TH1F(
"hmediandydz_after",
"", binsdydz, -windowdydz, windowdydz)
1264 if which ==
"median":
1265 whichx = whichy = whichdxdz = whichdydz =
"median" 1266 elif which ==
"bigmean":
1269 whichdxdz =
"mean20" 1270 whichdydz =
"mean50" 1271 elif which ==
"mean":
1274 whichdxdz =
"mean10" 1275 whichdydz =
"mean25" 1276 elif which ==
"bigwmean":
1279 whichdxdz =
"wmean20" 1280 whichdydz =
"wmean50" 1281 elif which ==
"wmean":
1284 whichdxdz =
"wmean10" 1285 whichdydz =
"wmean25" 1286 elif which ==
"bigstdev":
1289 whichdxdz =
"stdev20" 1290 whichdydz =
"stdev50" 1291 elif which ==
"stdev":
1294 whichdxdz =
"stdev10" 1295 whichdydz =
"stdev25" 1297 raise Exception(which +
" not recognized")
1300 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
1303 if r1.postal_address == r2.postal_address:
1306 if not found:
continue 1309 if r1.postal_address[0]==
'CSC':
1310 if r1.postal_address[2]==1
and r1.postal_address[3]==4:
continue 1312 if r1.status ==
"PASS" and r2.status ==
"PASS":
1313 hmedianx_before.Fill(10.*eval(
"r1.%s_x" % whichx))
1314 hmediandxdz_before.Fill(1000.*eval(
"r1.%s_dxdz" % whichdxdz))
1315 hmedianx_after.Fill(10.*eval(
"r2.%s_x" % whichx))
1316 hmediandxdz_after.Fill(1000.*eval(
"r2.%s_dxdz" % whichdxdz))
1318 if r1.median_y
is not None:
1319 hmediany_before.Fill(10.*eval(
"r1.%s_y" % whichy))
1320 hmediandydz_before.Fill(1000.*eval(
"r1.%s_dydz" % whichdydz))
1321 hmediany_after.Fill(10.*eval(
"r2.%s_y" % whichy))
1322 hmediandydz_after.Fill(1000.*eval(
"r2.%s_dydz" % whichdydz))
1324 hmedianx_beforecopy = hmedianx_before.Clone()
1325 hmediany_beforecopy = hmediany_before.Clone()
1326 hmediandxdz_beforecopy = hmediandxdz_before.Clone()
1327 hmediandydz_beforecopy = hmediandydz_before.Clone()
1328 hmedianx_beforecopy.SetLineStyle(2)
1329 hmediany_beforecopy.SetLineStyle(2)
1330 hmediandxdz_beforecopy.SetLineStyle(2)
1331 hmediandydz_beforecopy.SetLineStyle(2)
1333 hmedianx_before.SetFillColor(ROOT.kMagenta+2)
1334 hmediany_before.SetFillColor(ROOT.kMagenta+2)
1335 hmediandxdz_before.SetFillColor(ROOT.kMagenta+2)
1336 hmediandydz_before.SetFillColor(ROOT.kMagenta+2)
1337 hmedianx_after.SetFillColor(ROOT.kYellow)
1338 hmediany_after.SetFillColor(ROOT.kYellow)
1339 hmediandxdz_after.SetFillColor(ROOT.kYellow)
1340 hmediandydz_after.SetFillColor(ROOT.kYellow)
1342 hmedianx_after.SetXTitle(
"median(#Deltax) (mm)")
1343 hmediany_after.SetXTitle(
"median(#Deltay) (mm)")
1344 hmediandxdz_after.SetXTitle(
"median(#Deltadx/dz) (mrad)")
1345 hmediandydz_after.SetXTitle(
"median(#Deltadydz) (mrad)")
1346 hmedianx_after.GetXaxis().CenterTitle()
1347 hmediany_after.GetXaxis().CenterTitle()
1348 hmediandxdz_after.GetXaxis().CenterTitle()
1349 hmediandydz_after.GetXaxis().CenterTitle()
1351 if ceilingx
is not None: hmedianx_after.SetAxisRange(0., ceilingx,
"Y")
1352 if ceilingy
is not None: hmediany_after.SetAxisRange(0., ceilingy,
"Y")
1353 if ceilingdxdz
is not None: hmediandxdz_after.SetAxisRange(0., ceilingdxdz,
"Y")
1354 if ceilingdydz
is not None: hmediandydz_after.SetAxisRange(0., ceilingdydz,
"Y")
1360 hmedianx_after.Draw()
1361 hmedianx_before.Draw(
"same")
1362 hmedianx_after.Draw(
"same")
1363 hmedianx_beforecopy.Draw(
"same")
1364 hmedianx_after.Draw(
"axissame")
1366 tlegend = ROOT.TLegend(0.17, 0.75-0.05, 0.45+0.05, 0.9)
1367 tlegend.SetFillColor(ROOT.kWhite)
1368 tlegend.SetBorderSize(0)
1369 tlegend.AddEntry(hmedianx_after, r2text,
"f")
1370 tlegend.AddEntry(hmedianx_before, r1text,
"f")
1374 hmediandxdz_after.Draw()
1375 hmediandxdz_before.Draw(
"same")
1376 hmediandxdz_after.Draw(
"same")
1377 hmediandxdz_beforecopy.Draw(
"same")
1378 hmediandxdz_after.Draw(
"axissame")
1381 hmediany_after.Draw()
1382 hmediany_before.Draw(
"same")
1383 hmediany_after.Draw(
"same")
1384 hmediany_beforecopy.Draw(
"same")
1385 hmediany_after.Draw(
"axissame")
1388 hmediandydz_after.Draw()
1389 hmediandydz_before.Draw(
"same")
1390 hmediandydz_after.Draw(
"same")
1391 hmediandydz_beforecopy.Draw(
"same")
1392 hmediandydz_after.Draw(
"axissame")
1394 return hmediandxdz_after, hmediandxdz_before, hmediandxdz_beforecopy, \
1395 hmediandydz_after, hmediandydz_before, hmediandydz_beforecopy, \
1396 hmedianx_after, hmedianx_before, hmedianx_beforecopy, \
1397 hmediany_after, hmediany_before, hmediany_beforecopy, tlegend
1403 htmp = ROOT.gROOT.FindObject(the2d.GetName()+
"_peaks")
1404 if htmp !=
None: htmp.Delete()
1406 hpeaks = the2d.ProjectionX(the2d.GetName()+
"_peaks")
1410 for i
in xrange(0,
int(the2d.GetNbinsX()), rebin):
1411 tmp = the2d.ProjectionY(
"tmp", i+1, i + rebin)
1412 nn = tmp.GetEntries()
1414 drange = tmp.GetRMS()
1416 fgaus = ROOT.TF1(
"fgaus",
"gaus", tmp.GetMean() - drange, tmp.GetMean() + drange)
1417 fgaus.SetParameter(0,nn)
1418 fgaus.SetParameter(1,tmp.GetMean())
1419 fgaus.SetParameter(2,tmp.GetRMS())
1424 fr = tmp.Fit(
"fgaus",
"RNSQ")
1426 hpeaks.SetBinContent(i/rebin+1, fgaus.GetParameter(1))
1427 hpeaks.SetBinError(i/rebin+1, fgaus.GetParError(1))
1428 if fr.Status()==0
and fr.CovMatrixStatus()==3 : fitOk =
True 1430 bad_fit_bins.append(i/rebin+1)
1431 if nn > 1.
and tmp.GetRMS() > 0:
1432 hpeaks.SetBinContent(i/rebin+1, tmp.GetMean())
1433 hpeaks.SetBinError(i/rebin+1, ROOT.TMath.StudentQuantile(0.841345,nn) * tmp.GetRMS() /
sqrt(nn))
1435 hpeaks.SetBinContent(i/rebin+1, 0.)
1436 hpeaks.SetBinError(i/rebin+1, 0.)
1437 if len(bad_fit_bins):
print(
"createPeaksProfile bad fit bins: ", bad_fit_bins)
1443 def mapplot(tfiles, name, param, mode="from2d", window=10., abscissa=None, title="",
1444 widebins=
False, fitsine=
False, fitline=
False, reset_palette=
False, fitsawteeth=
False, fitpeaks=
False, peaksbins=1, fixfitpars={}, **args):
1445 tdrStyle.SetOptTitle(1)
1446 tdrStyle.SetTitleBorderSize(0)
1447 tdrStyle.SetOptStat(0)
1449 tdrStyle.SetOptFit(0)
1450 tdrStyle.SetTitleFontSize(0.05)
1451 tdrStyle.SetPadRightMargin(0.1)
1457 global hist, hist2d, hist2dweight, tline1, tline2, tline3
1459 if fitsine
or fitsawteeth:
1462 print(
"bad id for ", name)
1465 hdir =
"AlignmentMonitorMuonSystemMap1D/iter1/" 1466 hpref=
"%s_%s" % (name, param)
1470 if "ALL" in name
and (
"CSCvsr" in name
or "DTvsz" in name): combine_all =
True 1472 add1d = (
"vsphi" in name)
and (param ==
"x")
1475 hist2d = args[
"h2d"].Clone(hpref+
"_2d_")
1476 if "CSC" in name
and add1d: hist1d = args[
"h1d"].Clone(hpref+
"_1d_")
1480 if "DT" in name
and name[6:9]==
'st4': nch = 14
1481 if "CSC" in name: nch = 36
1482 chambers = [
"%02d" % ch
for ch
in range (2,nch+1)]
1484 ch_hhh = hhh.replace(
'ALL',
'01')
1485 ch_hpref = hpref.replace(
'ALL',
'01')
1486 hist2d = tfiles[0].Get(ch_hhh+
"_2d").Clone(ch_hpref+
"_2d_")
1487 if "CSC" in name
and add1d: hist1d = tfiles[0].Get(ch_hhh+
"_1d").Clone(ch_hpref+
"_1d_")
1490 ch_hhh = hhh.replace(
'ALL',ch)
1491 ch_hpref = hpref.replace(
'ALL',ch)
1492 hist2d.Add(tfiles[0].Get(ch_hhh+
"_2d"))
1493 if "CSC" in name
and add1d: hist1d.Add(tfiles[0].Get(ch_hhh+
"_1d"))
1494 for tfile
in tfiles[1:]:
1495 hist2d.Add(tfile.Get(ch_hhh+
"_2d"))
1496 if "CSC" in name
and add1d: hist1d.Add(tfile.Get(ch_hhh+
"_1d"))
1499 hist2d = tfiles[0].Get(hhh+
"_2d").Clone(hpref+
"_2d_")
1500 if "CSC" in name
and add1d: hist1d = tfiles[0].Get(hhh+
"_1d").Clone(hpref+
"_1d_")
1501 for tfile
in tfiles[1:]:
1502 hist2d.Add(tfile.Get(hhh+
"_2d"))
1503 if "CSC" in name
and add1d: hist1d.Add(tfile.Get(hhh+
"_1d"))
1506 if mode ==
"from2d":
1509 hist = the2d.ProjectionX()
1518 for i
in xrange(0,
int(the2d.GetNbinsX()), skip):
1519 tmp = the2d.ProjectionY(
"tmp", i+1, i + skip)
1520 if tmp.GetEntries() > 1:
1522 hist.SetBinContent(i/skip+1, tmp.GetMean())
1523 hist.SetBinError(i/skip+1, ROOT.TMath.StudentQuantile(0.841345,tmp.GetEntries()) * tmp.GetRMS() /
sqrt(tmp.GetEntries()))
1529 hist.SetBinContent(i/skip+1, 0.)
1530 hist.SetBinError(i/skip+1, 0.)
1537 hist.SetAxisRange(-window, window,
"Y")
1538 if abscissa
is not None: hist.SetAxisRange(abscissa[0], abscissa[1],
"X")
1539 hist.SetMarkerStyle(20)
1540 hist.SetMarkerSize(0.75)
1541 hist.GetXaxis().CenterTitle()
1542 hist.GetYaxis().CenterTitle()
1543 hist.GetYaxis().SetTitleOffset(0.75)
1544 hist.GetXaxis().SetTitleSize(0.05)
1545 hist.GetYaxis().SetTitleSize(0.05)
1546 hist.SetTitle(title)
1547 if "vsphi" in name: hist.SetXTitle(
"Global #phi position (rad)")
1548 elif "vsz" in name: hist.SetXTitle(
"Global z position (cm)")
1549 elif "vsr" in name: hist.SetXTitle(
"Global R position (cm)")
1551 if param ==
"x": hist.SetYTitle(
"x' residual (mm)")
1552 if param ==
"dxdz": hist.SetYTitle(
"dx'/dz residual (mrad)")
1553 if param ==
"y": hist.SetYTitle(
"y' residual (mm)")
1554 if param ==
"dydz": hist.SetYTitle(
"dy'/dz residual (mrad)")
1556 if param ==
"x": hist.SetYTitle(
"r#phi residual (mm)")
1557 if param ==
"dxdz": hist.SetYTitle(
"d(r#phi)/dz residual (mrad)")
1558 hist.SetMarkerColor(ROOT.kBlack)
1559 hist.SetLineColor(ROOT.kBlack)
1561 hist2d.Draw(
"colzsame")
1562 if widebins: hist.Draw(
"samee1")
1563 else: hist.Draw(
"same")
1565 hpeaks.SetMarkerStyle(20)
1566 hpeaks.SetMarkerSize(0.9)
1567 hpeaks.SetMarkerColor(ROOT.kRed)
1568 hpeaks.SetLineColor(ROOT.kRed)
1569 hpeaks.SetLineWidth(2)
1573 if fitsine
and "vsphi" in name:
1574 global fitsine_const, fitsine_sin, fitsine_cos, fitsine_chi2, fitsine_ndf
1576 f = ROOT.TF1(
"f",
"[0] + [1]*sin(x) + [2]*cos(x)", -pi/180.*5., pi*(2.-5./180.))
1578 f = ROOT.TF1(
"f",
"[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
1579 f.SetLineColor(ROOT.kRed)
1581 if len(fixfitpars)>0:
1582 for fpar
in fixfitpars.keys():
1583 f.FixParameter(fpar, fixfitpars[fpar])
1585 if fitpeaks: hpeaks.Fit(f,
"NQ")
1586 else: hist.Fit(f,
"NEQ")
1587 if len(fixfitpars)>0:
1588 for fpar
in fixfitpars.keys():
1589 f.ReleaseParameter(fpar)
1590 fitsine_const = f.GetParameter(0), f.GetParError(0)
1591 fitsine_sin = f.GetParameter(1), f.GetParError(1)
1592 fitsine_cos = f.GetParameter(2), f.GetParError(2)
1593 fitsine_chi2 = f.GetChisquare()
1594 fitsine_ndf = f.GetNDF()
1595 global MAP_RESULTS_FITSIN
1597 MAP_RESULTS_FITSIN[id] = {
'a':fitsine_const,
'phi':fitsine_const,
'sin': fitsine_sin,
'cos': fitsine_cos,
'chi2': fitsine_chi2,
'ndf': fitsine_ndf}
1599 global fitsine_ttext, fitsine_etext
1600 text_xposition = -1.
1601 if 'CSC' in name: text_xposition = 2.
1602 fitsine_ttext = ROOT.TLatex(text_xposition, 0.8*window,
1603 "%+.3f %+.3f sin#phi %+.3f cos#phi" % (fitsine_const[0], fitsine_sin[0], fitsine_cos[0]))
1604 fitsine_ttext.SetTextColor(ROOT.kRed)
1605 fitsine_ttext.SetTextSize(0.05)
1606 fitsine_ttext.Draw()
1607 fitsine_etext = ROOT.TLatex(text_xposition, 0.70*window,
1608 " #pm%.3f #pm%.3f #pm%.3f" % (fitsine_const[1], fitsine_sin[1], fitsine_cos[1]))
1609 fitsine_etext.SetTextColor(ROOT.kRed)
1610 fitsine_etext.SetTextSize(0.045)
1611 fitsine_etext.Draw()
1614 if 'CSC' in name
and add1d:
1616 f0 = ROOT.TF1(
"f0",
"gaus", hist1d.GetBinLowEdge(1), -hist1d.GetBinLowEdge(1))
1617 fit = hist1d.Fit(f0,
"NRQ")
1618 rangea, rangeb = hist1d.GetMean() - hist1d.GetRMS(), hist1d.GetMean() + hist1d.GetRMS()
1619 if fit==0: rangea, rangeb = f0.GetParameter(1) - f0.GetParameter(2), f0.GetParameter(1) + f0.GetParameter(2)
1623 f1 = ROOT.TF1(
"f1",
"gaus", rangea, rangeb)
1624 fit = hist1d.Fit(f1,
"NRQ")
1625 nn = hist1d.GetEntries()
1627 if nn>0: dphiz, ephiz = hist1d.GetMean(), ROOT.TMath.StudentQuantile(0.841345,nn) * hist1d.GetRMS() /
sqrt(nn)
1628 if fit==0: dphiz, ephiz = f1.GetParameter(1), f1.GetParError(1)
1630 MAP_RESULTS_FITSIN[id][
'phi'] = (dphiz, ephiz)
1632 global ttex_sine_, ttex_sine, ttex_1d_, ttex_1d
1634 ttex_sine_ = ROOT.TLatex(0, 0.8*window,
"#Delta#phi_{z}^{sine} (mrad):")
1635 ttex_sine_.SetTextColor(ROOT.kGreen+2); ttex_sine_.SetTextSize(0.04); ttex_sine_.Draw()
1636 ttex_sine = ROOT.TLatex(0, 0.7*window,
" %+.3f#pm%.3f" %
1637 (-100*fitsine_const[0]/signConventions[postal_address][3],
1638 100*fitsine_const[1]/signConventions[postal_address][3]))
1639 ttex_sine.SetTextColor(ROOT.kGreen+2); ttex_sine.SetTextSize(0.04); ttex_sine.Draw()
1640 ttex_1d_ = ROOT.TLatex(0, 0.6*window,
"#Delta#phi_{z}^{phi} (mrad):")
1641 ttex_1d_.SetTextColor(ROOT.kGreen+2); ttex_1d_.SetTextSize(0.04); ttex_1d_.Draw()
1642 ttex_1d = ROOT.TLatex(0, 0.5*window,
" %+.3f#pm%.3f" % (-dphiz, ephiz))
1643 ttex_1d.SetTextColor(ROOT.kGreen+2); ttex_1d.SetTextSize(0.04); ttex_1d.Draw()
1647 f = ROOT.TF1(
"f",
"[0] + [1]*x", -1000., 1000.)
1649 hist2d.GetFunction(
"f").SetLineColor(ROOT.kRed)
1650 global fitline_const, fitline_linear, fitline_chi2, fitline_ndf
1651 fitline_const = hist2d.GetFunction(
"f").GetParameter(0), hist2d.GetFunction(
"f").GetParError(0)
1652 fitline_linear = hist2d.GetFunction(
"f").GetParameter(1), hist2d.GetFunction(
"f").GetParError(1)
1653 fitline_chi2 = hist2d.GetFunction(
"f").GetChisquare()
1654 fitline_ndf = hist2d.GetFunction(
"f").GetNDF()
1655 hist2d.GetFunction(
"f").Draw(
"same")
1656 global fitline_ttext
1657 if "vsz" in name: which =
"Z" 1658 elif "vsr" in name: which =
"R" 1659 fitline_ttext = ROOT.TText(hist.GetBinCenter(hist.GetNbinsX()/4), 1660 0.8*window, "%.3g %+.3g %s" % (fitline_const[0], fitline_linear[0], which))
1661 fitline_ttext.SetTextColor(ROOT.kRed)
1662 fitline_ttext.Draw()
1664 ROOT.gPad.RedrawAxis()
1667 if not widebins:
philines(name, window, abscissa)
1668 if abscissa
is None:
1670 tline1 = ROOT.TLine(-pi/180.*5., 0, pi*(2.-5./180.), 0); tline1.Draw()
1671 tline2 = ROOT.TLine(-pi/180.*5., -window, pi*(2.-5./180.), -window); tline2.SetLineWidth(2); tline2.Draw()
1672 tline3 = ROOT.TLine(-pi/180.*5., window, pi*(2.-5./180.), window); tline3.Draw()
1674 tline1 = ROOT.TLine(-pi, 0, pi, 0); tline1.Draw()
1675 tline2 = ROOT.TLine(-pi, -window, pi, -window); tline2.SetLineWidth(2); tline2.Draw()
1676 tline3 = ROOT.TLine(-pi, window, pi, window); tline3.Draw()
1678 tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1679 tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1680 tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1682 if not widebins:
zlines(window, abscissa)
1683 if abscissa
is None:
1684 tline1 = ROOT.TLine(-660, 0, 660, 0); tline1.Draw()
1685 tline2 = ROOT.TLine(-660, -window, 660, -window); tline2.SetLineWidth(2); tline2.Draw()
1686 tline3 = ROOT.TLine(-660, window, 660, window); tline3.Draw()
1688 tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1689 tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1690 tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1692 if "mem1" in name
or "mep1" in name
and not widebins:
rlines(1, window, abscissa)
1693 if "mem2" in name
or "mep2" in name
and not widebins:
rlines(2, window, abscissa)
1694 if "mem3" in name
or "mep3" in name
and not widebins:
rlines(3, window, abscissa)
1695 if "mem4" in name
or "mep4" in name
and not widebins:
rlines(4, window, abscissa)
1696 if abscissa
is None:
1697 tline1 = ROOT.TLine(100, 0, 700, 0); tline1.Draw()
1698 tline2 = ROOT.TLine(100, -window, 700, -window); tline2.SetLineWidth(2); tline2.Draw()
1699 tline3 = ROOT.TLine(100, window, 700, window); tline3.Draw()
1701 tline1 = ROOT.TLine(abscissa[0], 0, abscissa[1], 0); tline1.Draw()
1702 tline2 = ROOT.TLine(abscissa[0], -window, abscissa[1], -window); tline2.SetLineWidth(2); tline2.Draw()
1703 tline3 = ROOT.TLine(abscissa[0], window, abscissa[1], window); tline3.Draw()
1705 if "vsphi" in name
and fitsawteeth:
1709 ROOT.gROOT.ProcessLine(
".L phiedges_fitfunctions.C++")
1727 fn.SetLineColor(ROOT.kYellow)
1735 ed.append(pi+
abs(ed[0]))
1737 global sawtooth_a, sawtooth_b
1741 for pr
in range(0,fn.GetNpar(),2):
1742 sawtooth_a.append( (fn.GetParameter(pr), fn.GetParError(pr)) )
1743 sawtooth_b.append( (fn.GetParameter(pr+1), fn.GetParError(pr+1)) )
1744 sawtooth_da.append( (fn.Eval(ed[pr/2]+0.01), fn.Eval(ed[pr/2+1]-0.01)) )
1745 global MAP_RESULTS_SAWTOOTH
1746 MAP_RESULTS_SAWTOOTH[id] = {
'a': sawtooth_a,
'da': sawtooth_da,
'b': sawtooth_b,
'chi2': fn.GetChisquare(),
'ndf': fn.GetNDF()}
1752 ROOT.SetOwnership(hist2d,
False)
1753 ROOT.SetOwnership(hist,
False)
1754 ROOT.SetOwnership(tline1,
False)
1755 ROOT.SetOwnership(tline2,
False)
1756 ROOT.SetOwnership(tline3,
False)
1763 if name.find(
'wh')>1: wh = name[name.find(
'wh')+2]
1764 if wh ==
"A": w =
"-2" 1765 elif wh ==
"B": w =
"-1" 1766 elif wh ==
"C": w =
"-0" 1767 elif wh ==
"D": w =
"+1" 1768 elif wh ==
"E": w =
"+2" 1769 elif wh ==
"-ALL": w =
"-ALL" 1773 if name.find(
'sec')<0:
return None 1774 station = name[name.find(
'sec')-1]
1776 sector = name[name.find(
'sec')+3:name.find(
'sec')+5]
1777 return "MB%s/%s/%s" % (w, station, sector)
1778 if name.find(
'st')>1: station = name[name.find(
'st')+2]
1780 return "MB%s/%s" % (w, station)
1784 if name[p+2]==
"p": endcap =
"+" 1785 elif name[p+2]==
"m": endcap =
"-" 1788 pch = name.find(
'ch')
1791 return "ME%s%s/%s" % (endcap, station, ring)
1793 chamber = name[pch+2:pch+4]
1794 return "ME%s%s/%s/%s" % (endcap, station, ring, chamber)
1803 def curvatureplot(tfiles, name, param, mode="from2d", window=15., widebins=False, title="", fitgauss=False, fitconst=False, fitline=False, fitpeaks=True, reset_palette=False):
1804 tdrStyle.SetOptTitle(1)
1805 tdrStyle.SetTitleBorderSize(0)
1806 tdrStyle.SetOptStat(0)
1807 tdrStyle.SetOptFit(0)
1808 tdrStyle.SetTitleFontSize(0.05)
1812 global hist, histCOPY, hist2d, tline1, tline2, tline3, tline4, tline5
1814 hdir =
"AlignmentMonitorMuonVsCurvature/iter1/" 1816 if name
not in (
"all",
"top",
"bottom"):
1817 hsuffix =
"_%s_%s" % (name, param)
1818 prof = tfiles[0].Get(hdir+
"tprofile"+hsuffix).Clone(
"tprofile_"+hsuffix)
1819 hist2d = tfiles[0].Get(hdir+
"th2f"+hsuffix).Clone(
"th2f_"+hsuffix)
1820 for tfile
in tfiles[1:]:
1821 prof.Add(tfile.Get(hdir+
"tprofile"+hsuffix))
1822 hist2d.Add(tfile.Get(hdir+
"th2f"+hsuffix))
1826 for wheel
in "m2",
"m1",
"z",
"p1",
"p2":
1827 if name ==
"all": sectors =
"01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12" 1828 elif name ==
"top": sectors =
"01",
"02",
"03",
"04",
"05",
"06" 1829 elif name ==
"bottom": sectors =
"07",
"08",
"09",
"10",
"11",
"12" 1830 else:
raise Exception
1832 for sector
in sectors:
1833 hsuffix =
"_%s_%s" % (
"wheel%s_sector%s" % (wheel, sector), param)
1834 for tfile
in tfiles:
1836 prof = tfiles[0].Get(hdir+
"tprofile"+hsuffix).Clone(
"tprofile_"+hsuffix)
1837 hist2d = tfiles[0].Get(hdir+
"th2f"+hsuffix).Clone(
"tprofile_"+hsuffix)
1839 prof.Add(tfile.Get(hdir+
"tprofile"+hsuffix))
1840 hist2d.Add(tfile.Get(hdir+
"th2f"+hsuffix))
1842 hist = ROOT.TH1F(
"hist",
"", prof.GetNbinsX(), prof.GetBinLowEdge(1), -prof.GetBinLowEdge(1))
1843 for i
in xrange(1, prof.GetNbinsX()+1):
1844 hist.SetBinContent(i, prof.GetBinContent(i))
1845 hist.SetBinError(i, prof.GetBinError(i))
1849 elif mode ==
"from2d":
1854 htmp = ROOT.gROOT.FindObject(
"tmp")
1855 if htmp !=
None: htmp.Delete()
1857 for i
in xrange(0,
int(prof.GetNbinsX()), skip):
1858 tmp = hist2d.ProjectionY(
"tmp", i+1, i + skip)
1859 if tmp.GetEntries() > 1:
1860 hist.SetBinContent(i/skip+1, tmp.GetMean())
1861 hist.SetBinError(i/skip+1, ROOT.TMath.StudentQuantile(0.841345,tmp.GetEntries()) * tmp.GetRMS() /
sqrt(tmp.GetEntries()))
1866 hist.SetBinContent(i/skip+1, 0.)
1867 hist.SetBinError(i/skip+1, 0.)
1876 f = ROOT.TF1(
"f",
"[0] + [1]*exp(-x**2/2/0.01**2)", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1877 f.SetParameters(0, 0., 0.01)
1878 if fitpeaks: hpeaks.Fit(f,
"q")
1879 else: hist.Fit(f,
"q")
1880 f.SetLineColor(ROOT.kRed)
1881 global fitgauss_diff, fitgauss_chi2, fitgauss_ndf
1885 fitgauss_diff = f.GetParameter(1), f.GetParError(1)
1886 fitgauss_chi2 = f.GetChisquare()
1887 fitgauss_ndf = f.GetNDF()
1889 global fitline_intercept, fitline_slope
1891 f = ROOT.TF1(
"f",
"[0]", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1892 if fitpeaks: hpeaks.Fit(f,
"q")
1893 else: hist.Fit(f,
"q")
1894 f.SetLineColor(ROOT.kRed)
1895 fitline_intercept = f.GetParameter(0), f.GetParError(0)
1898 f = ROOT.TF1(
"f",
"[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1899 if fitpeaks: hpeaks.Fit(f,
"qNE")
1900 else: hist.Fit(f,
"qNE")
1901 f.SetLineColor(ROOT.kRed)
1903 f2 = ROOT.TF1(
"2",
"[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1904 f3 = ROOT.TF1(
"2",
"[0] + [1]*x", hist.GetBinLowEdge(1), -hist.GetBinLowEdge(1))
1905 f2.SetParameters(f.GetParameter(0), f.GetParameter(1) + f.GetParError(1))
1906 f3.SetParameters(f.GetParameter(0), f.GetParameter(1) - f.GetParError(1))
1907 f2.SetLineColor(ROOT.kRed)
1908 f3.SetLineColor(ROOT.kRed)
1911 fitline_intercept = f.GetParameter(0), f.GetParError(0)
1912 fitline_slope = f.GetParameter(1), f.GetParError(1)
1914 hist2d.SetAxisRange(-window, window,
"Y")
1915 hist2d.SetMarkerStyle(20)
1916 hist2d.SetMarkerSize(0.75)
1917 hist2d.GetXaxis().CenterTitle()
1918 hist2d.GetYaxis().CenterTitle()
1919 if param ==
"curverr":
1920 hist2d.GetYaxis().SetTitleOffset(1.35)
1922 hist2d.GetYaxis().SetTitleOffset(0.75)
1923 hist2d.GetXaxis().SetTitleOffset(1.2)
1924 hist2d.GetXaxis().SetTitleSize(0.05)
1925 hist2d.GetYaxis().SetTitleSize(0.05)
1926 hist2d.SetTitle(title)
1927 if param ==
"pterr": hist2d.SetXTitle(
"qp_{T} (GeV/c)")
1928 else: hist2d.SetXTitle(
"q/p_{T} (c/GeV)")
1929 if param ==
"deltax": hist2d.SetYTitle(
"#Deltax' (mm)")
1930 if param ==
"deltadxdz": hist2d.SetYTitle(
"#Deltadx'/dz (mrad)")
1931 if param ==
"pterr": hist2d.SetYTitle(
"#Deltap_{T}/p_{T} (%)")
1932 if param ==
"curverr": hist2d.SetYTitle(
"#Deltaq/p_{T} (c/GeV)")
1934 hist.SetMarkerColor(ROOT.kBlack)
1935 hist.SetLineColor(ROOT.kBlack)
1953 hpeaks.SetMarkerStyle(20)
1954 hpeaks.SetMarkerSize(0.9)
1955 hpeaks.SetMarkerColor(ROOT.kRed)
1956 hpeaks.SetLineColor(ROOT.kRed)
1957 hpeaks.SetLineWidth(2)
1965 tline5 = ROOT.TLine(-hist.GetBinLowEdge(1), 0., hist.GetBinLowEdge(1), 0.)
1971 global h, gm2, gm1, gz, gp1, gp2, tlegend
1974 phis = {-2: [], -1: [], 0: [], 1: [], 2: []}
1975 diffs = {-2: [], -1: [], 0: [], 1: [], 2: []}
1976 differrs = {-2: [], -1: [], 0: [], 1: [], 2: []}
1977 for wheelstr, wheel
in (
"m2",
"-2"), (
"m1",
"-1"), (
"z",
"0"), (
"p1",
"+1"), (
"p2",
"+2"):
1978 for sector
in "01",
"02",
"03",
"04",
"05",
"06",
"07",
"08",
"09",
"10",
"11",
"12":
1979 curvatureplot(tfiles,
"wheel%s_sector%s" % (wheelstr, sector),
"deltax",
1980 title=
"Wheel %s, sector %s" % (wheel, sector), fitgauss=
True, reset_palette=
False)
1981 if fitgauss_diff[1] < window:
1982 uncertainty = fitgauss_diff[1]
1983 if pdgSfactor
and (fitgauss_chi2/fitgauss_ndf) > 1.: uncertainty *=
sqrt(fitgauss_chi2/fitgauss_ndf)
1985 phis[
int(wheel)].
append(signConventions[
"DT",
int(wheel), 1,
int(sector)][4])
1986 diffs[
int(wheel)].
append(fitgauss_diff[0])
1987 differrs[
int(wheel)].
append(uncertainty)
1989 h = ROOT.TH1F(
"h",
"", 1, -pi, pi)
1990 h.SetAxisRange(-window, window,
"Y")
1991 h.SetXTitle(
"#phi (rad)")
1992 h.SetYTitle(
"#Deltax(p_{T} #rightarrow #infty) - #Deltax(p_{T} #rightarrow 0) (mm)")
1993 h.GetXaxis().CenterTitle()
1994 h.GetYaxis().CenterTitle()
1996 gm2 = ROOT.TGraphErrors(len(phis[-2]), array.array(
"d", phis[-2]), array.array(
"d", diffs[-2]),
1997 array.array(
"d", [0.]*len(phis[-2])), array.array(
"d", differrs[-2]))
1998 gm1 = ROOT.TGraphErrors(len(phis[-1]), array.array(
"d", phis[-1]), array.array(
"d", diffs[-1]),
1999 array.array(
"d", [0.]*len(phis[-1])), array.array(
"d", differrs[-1]))
2000 gz = ROOT.TGraphErrors(len(phis[0]), array.array(
"d", phis[0]), array.array(
"d", diffs[0]),
2001 array.array(
"d", [0.]*len(phis[0])), array.array(
"d", differrs[0]))
2002 gp1 = ROOT.TGraphErrors(len(phis[1]), array.array(
"d", phis[1]), array.array(
"d", diffs[1]),
2003 array.array(
"d", [0.]*len(phis[1])), array.array(
"d", differrs[1]))
2004 gp2 = ROOT.TGraphErrors(len(phis[2]), array.array(
"d", phis[2]), array.array(
"d", diffs[2]),
2005 array.array(
"d", [0.]*len(phis[2])), array.array(
"d", differrs[2]))
2007 gm2.SetMarkerStyle(21); gm2.SetMarkerColor(ROOT.kRed); gm2.SetLineColor(ROOT.kRed)
2008 gm1.SetMarkerStyle(22); gm1.SetMarkerColor(ROOT.kBlue); gm1.SetLineColor(ROOT.kBlue)
2009 gz.SetMarkerStyle(3); gz.SetMarkerColor(ROOT.kBlack); gz.SetLineColor(ROOT.kBlack)
2010 gp1.SetMarkerStyle(26); gp1.SetMarkerColor(ROOT.kBlue); gp1.SetLineColor(ROOT.kBlue)
2011 gp2.SetMarkerStyle(25); gp2.SetMarkerColor(ROOT.kRed); gp2.SetLineColor(ROOT.kRed)
2014 tlegend = ROOT.TLegend(0.25, 0.2, 0.85, 0.5)
2015 tlegend.SetFillColor(ROOT.kWhite)
2016 tlegend.SetBorderSize(0)
2017 tlegend.AddEntry(gm2,
"Wheel -2",
"p")
2018 tlegend.AddEntry(gm1,
"Wheel -1",
"p")
2019 tlegend.AddEntry(gz,
"Wheel 0",
"p")
2020 tlegend.AddEntry(gp1,
"Wheel +1",
"p")
2021 tlegend.AddEntry(gp2,
"Wheel +2",
"p")
2032 if r.postal_address[0] ==
"DT":
2033 wheel, station, sector = r.postal_address[1:]
2034 return "DT wheel %d, station %d, sector %d" % (wheel, station, sector)
2035 elif r.postal_address[0] ==
"CSC":
2036 endcap, station, ring, chamber = r.postal_address[1:]
2037 if endcap != 1: station = -1 *
abs(station)
2038 return "CSC ME%d/%d chamber %d" % (station, ring, chamber)
2040 ddt=[0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.,0.]
2042 for i
in range(0,15):
2048 if n==0
or n==7
or n==15:
print(
"%d calls" % t)
2049 else:
print(
"%d : %0.3f ms" % (n,t*1000.0))
2052 def bellcurves(tfile, reports, name, twobin=True, suppressblue=False):
2055 tdrStyle.SetOptTitle(1)
2056 tdrStyle.SetTitleBorderSize(1)
2057 tdrStyle.SetTitleFontSize(0.1)
2058 tdrStyle.SetOptStat(0)
2059 tdrStyle.SetHistMinimumZero()
2069 if not found:
raise Exception(
"Not a valid name")
2070 if r.status ==
"FAIL":
2076 Pos =
"Pos"; Neg =
"Neg" 2080 pdirPos =
"MuonAlignmentFromReference/%s%s" % (name, Pos)
2081 pdirNeg =
"MuonAlignmentFromReference/%s%s" % (name, Neg)
2084 ddt[1] = 1./ddt[0]*((ddt[0]-1)*ddt[1] + t2-t1)
2086 chamber_x = tfile.Get(pdirPos+
"_x")
2087 chamber_x_fit = tfile.Get(pdirPos+
"_x_fit")
2088 chamber_y = tfile.Get(pdirPos+
"_y")
2089 chamber_y_fit = tfile.Get(pdirPos+
"_y_fit")
2090 chamber_dxdz = tfile.Get(pdirPos+
"_dxdz")
2091 chamber_dxdz_fit = tfile.Get(pdirPos+
"_dxdz_fit")
2092 chamber_dydz = tfile.Get(pdirPos+
"_dydz")
2093 chamber_dydz_fit = tfile.Get(pdirPos+
"_dydz_fit")
2094 chamber_alphax = tfile.Get(pdirPos+
"_alphax")
2095 chamber_alphax_fit = tfile.Get(pdirPos+
"_alphax_fit")
2096 chamber_alphay = tfile.Get(pdirPos+
"_alphay")
2097 chamber_alphay_fit = tfile.Get(pdirPos+
"_alphay_fit")
2099 chamber_x_fit2 = tfile.Get(pdirNeg+
"_x_fit")
2100 chamber_y_fit2 = tfile.Get(pdirNeg+
"_y_fit")
2101 chamber_dxdz_fit2 = tfile.Get(pdirNeg+
"_dxdz_fit")
2102 chamber_dydz_fit2 = tfile.Get(pdirNeg+
"_dydz_fit")
2103 chamber_alphax_fit2 = tfile.Get(pdirNeg+
"_alphax_fit")
2104 chamber_alphay_fit2 = tfile.Get(pdirNeg+
"_alphay_fit")
2107 chamber_x = tfile.Get(pdirPos+
"_residual")
2108 chamber_x_fit = tfile.Get(pdirPos+
"_residual_fit")
2109 chamber_dxdz = tfile.Get(pdirPos+
"_resslope")
2110 chamber_dxdz_fit = tfile.Get(pdirPos+
"_resslope_fit")
2111 chamber_alphax = tfile.Get(pdirPos+
"_alpha")
2112 chamber_alphax_fit = tfile.Get(pdirPos+
"_alpha_fit")
2114 chamber_x_fit2 = tfile.Get(pdirNeg+
"_residual_fit")
2115 chamber_dxdz_fit2 = tfile.Get(pdirNeg+
"_resslope_fit")
2116 chamber_alphax_fit2 = tfile.Get(pdirNeg+
"_alpha_fit")
2119 print(
"Can't find neither "+pdirPos+
"_x nor "+pdirPos+
"_residual")
2123 ddt[2] = 1./ddt[0]*((ddt[0]-1)*ddt[2] + t3-t2)
2126 chamber_x.SetAxisRange(-50., 50.,
"X")
2127 if chamber_x.GetRMS()>15: chamber_x.SetAxisRange(-75., 75.,
"X")
2128 chamber_dxdz.SetAxisRange(-30., 30.,
"X")
2129 chamber_alphax.SetAxisRange(-50., 50.,
"X")
2130 if not not chamber_y:
2131 chamber_y.SetAxisRange(-75., 75.,
"X")
2132 chamber_dydz.SetAxisRange(-120., 120.,
"X")
2133 chamber_alphay.SetAxisRange(-120., 120.,
"X")
2134 chamber_alphay.SetAxisRange(-75., 75.,
"Y")
2137 chamber_x.SetXTitle(
"Local x residual (mm)")
2138 chamber_dxdz.SetXTitle(
"Local dx/dz residual (mrad)")
2139 chamber_alphax.SetXTitle(
"Local dx/dz residual (mrad)")
2140 chamber_alphax.SetYTitle(
"Local x residual (mm)")
2141 if not not chamber_y:
2142 chamber_y.SetXTitle(
"Local y residual (mm)")
2143 chamber_dydz.SetXTitle(
"Local dy/dz residual (mrad)")
2144 chamber_alphay.SetXTitle(
"Local dy/dz residual (mrad)")
2145 chamber_alphay.SetYTitle(
"Local y residual (mm)")
2146 if name[0:2] ==
"ME":
2147 chamber_x.SetXTitle(
"Local r#phi residual (mm)")
2148 chamber_dxdz.SetXTitle(
"Local d(r#phi)/dz residual (mrad)")
2149 chamber_alphax.SetXTitle(
"Local d(r#phi)/dz residual (mrad)")
2150 chamber_alphax.SetYTitle(
"Local r#phi residual (mm)")
2153 ddt[3] = 1./ddt[0]*((ddt[0]-1)*ddt[3] + t4-t3)
2155 for h
in chamber_x, chamber_dxdz, chamber_alphax, chamber_alphax, \
2156 chamber_y, chamber_dydz, chamber_alphay, chamber_alphay:
2158 h.GetXaxis().CenterTitle()
2159 h.GetYaxis().CenterTitle()
2160 h.GetXaxis().SetLabelSize(0.05)
2161 h.GetYaxis().SetLabelSize(0.05)
2162 h.GetXaxis().SetTitleSize(0.07)
2163 h.GetYaxis().SetTitleSize(0.07)
2164 h.GetXaxis().SetTitleOffset(0.9)
2165 h.GetYaxis().SetTitleOffset(0.9)
2168 for f
in chamber_x_fit2, chamber_y_fit2, chamber_dxdz_fit2, chamber_dydz_fit2, \
2169 chamber_alphax_fit2, chamber_alphay_fit2:
2176 ddt[4] = 1./ddt[0]*((ddt[0]-1)*ddt[4] + t5-t4)
2178 global l1, l2, l3, l4
2179 if not not chamber_y:
2182 chamber_x.SetTitle(
getname(r))
2186 if not suppressblue: chamber_x_fit2.Draw(
"same")
2187 chamber_x_fit.Draw(
"same")
2188 l1 = ROOT.TLatex(0.67,0.8,
"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2189 chamber_x_fit.GetParameter(1), chamber_x_fit.GetParError(1),
2190 chamber_x_fit.GetParameter(2), chamber_x_fit.GetParError(2)))
2195 if not suppressblue: chamber_dxdz_fit2.Draw(
"same")
2196 chamber_dxdz_fit.Draw(
"same")
2197 l2 = ROOT.TLatex(0.67,0.8,
"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2198 chamber_dxdz_fit.GetParameter(1), chamber_dxdz_fit.GetParError(1),
2199 chamber_dxdz_fit.GetParameter(2), chamber_dxdz_fit.GetParError(2)))
2203 chamber_alphax.Draw(
"col")
2204 if not suppressblue: chamber_alphax_fit2.Draw(
"same")
2205 chamber_alphax_fit.Draw(
"same")
2209 if not suppressblue: chamber_y_fit2.Draw(
"same")
2210 chamber_y_fit.Draw(
"same")
2211 l3 = ROOT.TLatex(0.67,0.8,
"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2212 chamber_y_fit.GetParameter(1), chamber_y_fit.GetParError(1),
2213 chamber_y_fit.GetParameter(2), chamber_y_fit.GetParError(2)))
2218 if not suppressblue: chamber_dydz_fit2.Draw(
"same")
2219 chamber_dydz_fit.Draw(
"same")
2220 l4 = ROOT.TLatex(0.67,0.8,
"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2221 chamber_dydz_fit.GetParameter(1), chamber_dydz_fit.GetParError(1),
2222 chamber_dydz_fit.GetParameter(2), chamber_dydz_fit.GetParError(2)))
2225 for lb
in l1,l2,l3,l4:
2227 lb.SetTextColor(ROOT.kRed)
2230 chamber_alphay.Draw(
"col")
2231 if not suppressblue: chamber_alphay_fit2.Draw(
"same")
2232 chamber_alphay_fit.Draw(
"same")
2237 chamber_x.SetTitle(
getname(r))
2241 if not suppressblue: chamber_x_fit2.Draw(
"same")
2242 chamber_x_fit.Draw(
"same")
2243 l1 = ROOT.TLatex(0.67,0.8,
"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2244 chamber_x_fit.GetParameter(1), chamber_x_fit.GetParError(1),
2245 chamber_x_fit.GetParameter(2), chamber_x_fit.GetParError(2)))
2250 if not suppressblue: chamber_dxdz_fit2.Draw(
"same")
2251 chamber_dxdz_fit.Draw(
"same")
2252 l2 = ROOT.TLatex(0.67,0.8,
"#splitline{#mu: %0.2f#pm%0.2f}{#sigma: %0.1f#pm%0.1f}" % (
2253 chamber_dxdz_fit.GetParameter(1), chamber_dxdz_fit.GetParError(1),
2254 chamber_dxdz_fit.GetParameter(2), chamber_dxdz_fit.GetParError(2)))
2258 chamber_alphax.Draw(
"col")
2259 if not suppressblue: chamber_alphax_fit2.Draw(
"same")
2260 chamber_alphax_fit.Draw(
"same")
2264 lb.SetTextColor(ROOT.kRed)
2267 ddt[5] = 1./ddt[0]*((ddt[0]-1)*ddt[5] + t6-t5)
2268 ddt[6] = 1./ddt[0]*((ddt[0]-1)*ddt[6] + t6-t1)
2271 def polynomials(tfile, reports, name, twobin=True, suppressblue=False):
2274 global label1, label2, label3, label4, label5, label6, label7, label8, label9
2275 plotDirectory =
"MuonAlignmentFromReference" 2276 tdrStyle.SetOptTitle(1)
2277 tdrStyle.SetTitleBorderSize(1)
2278 tdrStyle.SetTitleFontSize(0.1)
2279 tdrStyle.SetOptStat(0)
2289 if not found:
raise Exception(
"Not a valid name")
2291 if r.status ==
"FAIL":
2297 Pos =
"Pos"; Neg =
"Neg" 2301 pdirPos =
"MuonAlignmentFromReference/%s%s" % (name, Pos)
2302 pdirNeg =
"MuonAlignmentFromReference/%s%s" % (name, Neg)
2304 global chamber_x_trackx, chamber_x_trackx_fit, chamber_y_trackx, chamber_y_trackx_fit, \
2305 chamber_dxdz_trackx, chamber_dxdz_trackx_fit, chamber_dydz_trackx, chamber_dydz_trackx_fit, \
2306 chamber_x_trackx_fit2, chamber_y_trackx_fit2, chamber_dxdz_trackx_fit2, chamber_dydz_trackx_fit2
2307 global chamber_x_tracky, chamber_x_tracky_fit, chamber_y_tracky, chamber_y_tracky_fit, \
2308 chamber_dxdz_tracky, chamber_dxdz_tracky_fit, chamber_dydz_tracky, chamber_dydz_tracky_fit, \
2309 chamber_x_tracky_fit2, chamber_y_tracky_fit2, chamber_dxdz_tracky_fit2, chamber_dydz_tracky_fit2
2310 global chamber_x_trackdxdz, chamber_x_trackdxdz_fit, chamber_y_trackdxdz, chamber_y_trackdxdz_fit, \
2311 chamber_dxdz_trackdxdz, chamber_dxdz_trackdxdz_fit, chamber_dydz_trackdxdz, chamber_dydz_trackdxdz_fit, \
2312 chamber_x_trackdxdz_fit2, chamber_y_trackdxdz_fit2, chamber_dxdz_trackdxdz_fit2, chamber_dydz_trackdxdz_fit2
2313 global chamber_x_trackdydz, chamber_x_trackdydz_fit, chamber_y_trackdydz, chamber_y_trackdydz_fit, \
2314 chamber_dxdz_trackdydz, chamber_dxdz_trackdydz_fit, chamber_dydz_trackdydz, chamber_dydz_trackdydz_fit, \
2315 chamber_x_trackdydz_fit2, chamber_y_trackdydz_fit2, chamber_dxdz_trackdydz_fit2, chamber_dydz_trackdydz_fit2
2317 chamber_x_trackx = tfile.Get(pdirPos+
"_x_trackx")
2318 chamber_x_trackx_fit = tfile.Get(pdirPos+
"_x_trackx_fitline")
2319 chamber_y_trackx = tfile.Get(pdirPos+
"_y_trackx")
2320 chamber_y_trackx_fit = tfile.Get(pdirPos+
"_y_trackx_fitline")
2321 chamber_dxdz_trackx = tfile.Get(pdirPos+
"_dxdz_trackx")
2322 chamber_dxdz_trackx_fit = tfile.Get(pdirPos+
"_dxdz_trackx_fitline")
2323 chamber_dydz_trackx = tfile.Get(pdirPos+
"_dydz_trackx")
2324 chamber_dydz_trackx_fit = tfile.Get(pdirPos+
"_dydz_trackx_fitline")
2325 chamber_x_trackx_fit2 = tfile.Get(pdirNeg+
"_x_trackx_fitline")
2326 chamber_y_trackx_fit2 = tfile.Get(pdirNeg+
"_y_trackx_fitline")
2327 chamber_dxdz_trackx_fit2 = tfile.Get(pdirNeg+
"_dxdz_trackx_fitline")
2328 chamber_dydz_trackx_fit2 = tfile.Get(pdirNeg+
"_dydz_trackx_fitline")
2330 chamber_x_tracky = tfile.Get(pdirPos+
"_x_tracky")
2331 chamber_x_tracky_fit = tfile.Get(pdirPos+
"_x_tracky_fitline")
2332 chamber_y_tracky = tfile.Get(pdirPos+
"_y_tracky")
2333 chamber_y_tracky_fit = tfile.Get(pdirPos+
"_y_tracky_fitline")
2334 chamber_dxdz_tracky = tfile.Get(pdirPos+
"_dxdz_tracky")
2335 chamber_dxdz_tracky_fit = tfile.Get(pdirPos+
"_dxdz_tracky_fitline")
2336 chamber_dydz_tracky = tfile.Get(pdirPos+
"_dydz_tracky")
2337 chamber_dydz_tracky_fit = tfile.Get(pdirPos+
"_dydz_tracky_fitline")
2338 chamber_x_tracky_fit2 = tfile.Get(pdirNeg+
"_x_tracky_fitline")
2339 chamber_y_tracky_fit2 = tfile.Get(pdirNeg+
"_y_tracky_fitline")
2340 chamber_dxdz_tracky_fit2 = tfile.Get(pdirNeg+
"_dxdz_tracky_fitline")
2341 chamber_dydz_tracky_fit2 = tfile.Get(pdirNeg+
"_dydz_tracky_fitline")
2343 chamber_x_trackdxdz = tfile.Get(pdirPos+
"_x_trackdxdz")
2344 chamber_x_trackdxdz_fit = tfile.Get(pdirPos+
"_x_trackdxdz_fitline")
2345 chamber_y_trackdxdz = tfile.Get(pdirPos+
"_y_trackdxdz")
2346 chamber_y_trackdxdz_fit = tfile.Get(pdirPos+
"_y_trackdxdz_fitline")
2347 chamber_dxdz_trackdxdz = tfile.Get(pdirPos+
"_dxdz_trackdxdz")
2348 chamber_dxdz_trackdxdz_fit = tfile.Get(pdirPos+
"_dxdz_trackdxdz_fitline")
2349 chamber_dydz_trackdxdz = tfile.Get(pdirPos+
"_dydz_trackdxdz")
2350 chamber_dydz_trackdxdz_fit = tfile.Get(pdirPos+
"_dydz_trackdxdz_fitline")
2351 chamber_x_trackdxdz_fit2 = tfile.Get(pdirNeg+
"_x_trackdxdz_fitline")
2352 chamber_y_trackdxdz_fit2 = tfile.Get(pdirNeg+
"_y_trackdxdz_fitline")
2353 chamber_dxdz_trackdxdz_fit2 = tfile.Get(pdirNeg+
"_dxdz_trackdxdz_fitline")
2354 chamber_dydz_trackdxdz_fit2 = tfile.Get(pdirNeg+
"_dydz_trackdxdz_fitline")
2356 chamber_x_trackdydz = tfile.Get(pdirPos+
"_x_trackdydz")
2357 chamber_x_trackdydz_fit = tfile.Get(pdirPos+
"_x_trackdydz_fitline")
2358 chamber_y_trackdydz = tfile.Get(pdirPos+
"_y_trackdydz")
2359 chamber_y_trackdydz_fit = tfile.Get(pdirPos+
"_y_trackdydz_fitline")
2360 chamber_dxdz_trackdydz = tfile.Get(pdirPos+
"_dxdz_trackdydz")
2361 chamber_dxdz_trackdydz_fit = tfile.Get(pdirPos+
"_dxdz_trackdydz_fitline")
2362 chamber_dydz_trackdydz = tfile.Get(pdirPos+
"_dydz_trackdydz")
2363 chamber_dydz_trackdydz_fit = tfile.Get(pdirPos+
"_dydz_trackdydz_fitline")
2364 chamber_x_trackdydz_fit2 = tfile.Get(pdirNeg+
"_x_trackdydz_fitline")
2365 chamber_y_trackdydz_fit2 = tfile.Get(pdirNeg+
"_y_trackdydz_fitline")
2366 chamber_dxdz_trackdydz_fit2 = tfile.Get(pdirNeg+
"_dxdz_trackdydz_fitline")
2367 chamber_dydz_trackdydz_fit2 = tfile.Get(pdirNeg+
"_dydz_trackdydz_fitline")
2369 if not chamber_x_trackx:
2370 chamber_x_trackx = tfile.Get(pdirPos+
"_residual_trackx")
2371 chamber_x_trackx_fit = tfile.Get(pdirPos+
"_residual_trackx_fitline")
2372 chamber_dxdz_trackx = tfile.Get(pdirPos+
"_resslope_trackx")
2373 chamber_dxdz_trackx_fit = tfile.Get(pdirPos+
"_resslope_trackx_fitline")
2374 chamber_x_trackx_fit2 = tfile.Get(pdirNeg+
"_residual_trackx_fitline")
2375 chamber_dxdz_trackx_fit2 = tfile.Get(pdirNeg+
"_resslope_trackx_fitline")
2377 chamber_x_tracky = tfile.Get(pdirPos+
"_residual_tracky")
2378 chamber_x_tracky_fit = tfile.Get(pdirPos+
"_residual_tracky_fitline")
2379 chamber_dxdz_tracky = tfile.Get(pdirPos+
"_resslope_tracky")
2380 chamber_dxdz_tracky_fit = tfile.Get(pdirPos+
"_resslope_tracky_fitline")
2381 chamber_x_tracky_fit2 = tfile.Get(pdirNeg+
"_residual_tracky_fitline")
2382 chamber_dxdz_tracky_fit2 = tfile.Get(pdirNeg+
"_resslope_tracky_fitline")
2384 chamber_x_trackdxdz = tfile.Get(pdirPos+
"_residual_trackdxdz")
2385 chamber_x_trackdxdz_fit = tfile.Get(pdirPos+
"_residual_trackdxdz_fitline")
2386 chamber_dxdz_trackdxdz = tfile.Get(pdirPos+
"_resslope_trackdxdz")
2387 chamber_dxdz_trackdxdz_fit = tfile.Get(pdirPos+
"_resslope_trackdxdz_fitline")
2388 chamber_x_trackdxdz_fit2 = tfile.Get(pdirNeg+
"_residual_trackdxdz_fitline")
2389 chamber_dxdz_trackdxdz_fit2 = tfile.Get(pdirNeg+
"_resslope_trackdxdz_fitline")
2391 chamber_x_trackdydz = tfile.Get(pdirPos+
"_residual_trackdydz")
2392 chamber_x_trackdydz_fit = tfile.Get(pdirPos+
"_residual_trackdydz_fitline")
2393 chamber_dxdz_trackdydz = tfile.Get(pdirPos+
"_resslope_trackdydz")
2394 chamber_dxdz_trackdydz_fit = tfile.Get(pdirPos+
"_resslope_trackdydz_fitline")
2395 chamber_x_trackdydz_fit2 = tfile.Get(pdirNeg+
"_residual_trackdydz_fitline")
2396 chamber_dxdz_trackdydz_fit2 = tfile.Get(pdirNeg+
"_resslope_trackdydz_fitline")
2398 if not chamber_x_trackx:
2399 print(
"Can't find neither "+pdirPos+
"_residual nor "+pdirPos+
"_residual_trackx")
2402 chamber_x_trackx = chamber_x_trackx.Clone()
2403 chamber_dxdz_trackx = chamber_dxdz_trackx.Clone()
2404 chamber_x_tracky = chamber_x_tracky.Clone()
2405 chamber_dxdz_tracky = chamber_dxdz_tracky.Clone()
2406 chamber_x_trackdxdz = chamber_x_trackdxdz.Clone()
2407 chamber_dxdz_trackdxdz = chamber_dxdz_trackdxdz.Clone()
2408 chamber_x_trackdydz = chamber_x_trackdydz.Clone()
2409 chamber_dxdz_trackdydz = chamber_dxdz_trackdydz.Clone()
2411 if not not chamber_y_trackx:
2412 chamber_y_trackx = chamber_y_trackx.Clone()
2413 chamber_dydz_trackx = chamber_dydz_trackx.Clone()
2414 chamber_y_tracky = chamber_y_tracky.Clone()
2415 chamber_dydz_tracky = chamber_dydz_tracky.Clone()
2416 chamber_y_trackdxdz = chamber_y_trackdxdz.Clone()
2417 chamber_dydz_trackdxdz = chamber_dydz_trackdxdz.Clone()
2418 chamber_y_trackdydz = chamber_y_trackdydz.Clone()
2419 chamber_dydz_trackdydz = chamber_dydz_trackdydz.Clone()
2421 if not not chamber_y_trackx:
2422 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_x_trackx")); chamber_x_trackx.Merge(tlist)
2423 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dxdz_trackx")); chamber_dxdz_trackx.Merge(tlist)
2424 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_x_tracky")); chamber_x_tracky.Merge(tlist)
2425 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dxdz_tracky")); chamber_dxdz_tracky.Merge(tlist)
2426 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_x_trackdxdz")); chamber_x_trackdxdz.Merge(tlist)
2427 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dxdz_trackdxdz")); chamber_dxdz_trackdxdz.Merge(tlist)
2428 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_x_trackdydz")); chamber_x_trackdydz.Merge(tlist)
2429 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dxdz_trackdydz")); chamber_dxdz_trackdydz.Merge(tlist)
2430 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_y_trackx")); chamber_y_trackx.Merge(tlist)
2431 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dydz_trackx")); chamber_dydz_trackx.Merge(tlist)
2432 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_y_tracky")); chamber_y_tracky.Merge(tlist)
2433 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dydz_tracky")); chamber_dydz_tracky.Merge(tlist)
2434 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_y_trackdxdz")); chamber_y_trackdxdz.Merge(tlist)
2435 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dydz_trackdxdz")); chamber_dydz_trackdxdz.Merge(tlist)
2436 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_y_trackdydz")); chamber_y_trackdydz.Merge(tlist)
2437 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_dydz_trackdydz")); chamber_dydz_trackdydz.Merge(tlist)
2439 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_residual_trackx")); chamber_x_trackx.Merge(tlist)
2440 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_resslope_trackx")); chamber_dxdz_trackx.Merge(tlist)
2441 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_residual_tracky")); chamber_x_tracky.Merge(tlist)
2442 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_resslope_tracky")); chamber_dxdz_tracky.Merge(tlist)
2443 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_residual_trackdxdz")); chamber_x_trackdxdz.Merge(tlist)
2444 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_resslope_trackdxdz")); chamber_dxdz_trackdxdz.Merge(tlist)
2445 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_residual_trackdydz")); chamber_x_trackdydz.Merge(tlist)
2446 tlist = ROOT.TList(); tlist.Add(tfile.Get(pdirNeg+
"_resslope_trackdydz")); chamber_dxdz_trackdydz.Merge(tlist)
2450 chamber_x_trackx.SetAxisRange(-rr1, rr1,
"Y")
2451 chamber_dxdz_trackx.SetAxisRange(-rr2, rr2,
"Y")
2452 chamber_x_tracky.SetAxisRange(-rr1, rr1,
"Y")
2453 chamber_dxdz_tracky.SetAxisRange(-rr2, rr2,
"Y")
2454 chamber_x_trackdxdz.SetAxisRange(-rr1, rr1,
"Y")
2455 chamber_dxdz_trackdxdz.SetAxisRange(-rr2, rr2,
"Y")
2456 chamber_x_trackdydz.SetAxisRange(-rr1, rr1,
"Y")
2457 chamber_dxdz_trackdydz.SetAxisRange(-rr2, rr2,
"Y")
2460 if not not chamber_y_trackx:
2461 chamber_y_trackx.SetAxisRange(-rr3, rr3,
"Y")
2462 chamber_dydz_trackx.SetAxisRange(-rr3, rr3,
"Y")
2463 chamber_y_tracky.SetAxisRange(-rr3, rr3,
"Y")
2464 chamber_dydz_tracky.SetAxisRange(-rr3, rr3,
"Y")
2465 chamber_y_trackdxdz.SetAxisRange(-rr3, rr3,
"Y")
2466 chamber_dydz_trackdxdz.SetAxisRange(-rr3, rr3,
"Y")
2467 chamber_y_trackdydz.SetAxisRange(-rr3, rr3,
"Y")
2468 chamber_dydz_trackdydz.SetAxisRange(-rr3, rr3,
"Y")
2470 for h
in chamber_x_trackx, chamber_y_trackx, chamber_dxdz_trackx, chamber_dydz_trackx, \
2471 chamber_x_tracky, chamber_y_tracky, chamber_dxdz_tracky, chamber_dydz_tracky, \
2472 chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz, \
2473 chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2475 h.SetMarkerStyle(20)
2476 h.SetMarkerSize(0.5)
2477 h.GetXaxis().SetLabelSize(0.12)
2478 h.GetYaxis().SetLabelSize(0.12)
2479 h.GetXaxis().SetNdivisions(505)
2480 h.GetYaxis().SetNdivisions(505)
2481 h.GetXaxis().SetLabelOffset(0.03)
2482 h.GetYaxis().SetLabelOffset(0.03)
2484 trackdxdz_minimum, trackdxdz_maximum =
None,
None 2485 for h
in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
2487 for i
in xrange(1, h.GetNbinsX()+1):
2488 if h.GetBinError(i) > 0.01
and h.GetBinContent(i) - h.GetBinError(i) < 10.
and \
2489 h.GetBinContent(i) + h.GetBinError(i) > -10.:
2490 if not trackdxdz_minimum
or trackdxdz_minimum > h.GetBinCenter(i):
2491 trackdxdz_minimum = h.GetBinCenter(i)
2492 if trackdxdz_maximum < h.GetBinCenter(i):
2493 trackdxdz_maximum = h.GetBinCenter(i)
2494 if not not trackdxdz_minimum
and not not trackdxdz_maximum:
2495 for h
in chamber_x_trackdxdz, chamber_y_trackdxdz, chamber_dxdz_trackdxdz, chamber_dydz_trackdxdz:
2497 h.SetAxisRange(trackdxdz_minimum, trackdxdz_maximum,
"X")
2499 trackdydz_minimum, trackdydz_maximum =
None,
None 2500 for h
in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2502 for i
in xrange(1, h.GetNbinsX()+1):
2503 if h.GetBinError(i) > 0.01
and h.GetBinContent(i) - h.GetBinError(i) < 10.
and \
2504 h.GetBinContent(i) + h.GetBinError(i) > -10.:
2505 if not trackdydz_minimum
or trackdydz_minimum > h.GetBinCenter(i):
2506 trackdydz_minimum = h.GetBinCenter(i)
2507 if trackdydz_maximum < h.GetBinCenter(i):
2508 trackdydz_maximum = h.GetBinCenter(i)
2509 if not not trackdydz_minimum
and not not trackdydz_maximum:
2510 for h
in chamber_x_trackdydz, chamber_y_trackdydz, chamber_dxdz_trackdydz, chamber_dydz_trackdydz:
2512 h.SetAxisRange(trackdydz_minimum, trackdydz_maximum,
"X")
2514 for f
in chamber_x_trackx_fit2, chamber_y_trackx_fit2, chamber_dxdz_trackx_fit2, chamber_dydz_trackx_fit2, \
2515 chamber_x_tracky_fit2, chamber_y_tracky_fit2, chamber_dxdz_tracky_fit2, chamber_dydz_tracky_fit2, \
2516 chamber_x_trackdxdz_fit2, chamber_y_trackdxdz_fit2, chamber_dxdz_trackdxdz_fit2, chamber_dydz_trackdxdz_fit2, \
2517 chamber_x_trackdydz_fit2, chamber_y_trackdydz_fit2, chamber_dxdz_trackdydz_fit2, chamber_dydz_trackdydz_fit2:
2521 if not not chamber_y_trackx:
2525 pads.append(ROOT.TPad(
"p1" ,
"",0.00,0.78,0.07,1.00,0,0,0))
2526 pads.append(ROOT.TPad(
"p2" ,
"",0.07,0.78,0.34,1.00,0,0,0))
2527 pads.append(ROOT.TPad(
"p3" ,
"",0.34,0.78,0.56,1.00,0,0,0))
2528 pads.append(ROOT.TPad(
"p4" ,
"",0.56,0.78,0.78,1.00,0,0,0))
2529 pads.append(ROOT.TPad(
"p5" ,
"",0.78,0.78,1.00,1.00,0,0,0))
2530 pads.append(ROOT.TPad(
"p6" ,
"",0.00,0.56,0.07,0.78,0,0,0))
2531 pads.append(ROOT.TPad(
"p7" ,
"",0.07,0.56,0.34,0.78,0,0,0))
2532 pads.append(ROOT.TPad(
"p8" ,
"",0.34,0.56,0.56,0.78,0,0,0))
2533 pads.append(ROOT.TPad(
"p9" ,
"",0.56,0.56,0.78,0.78,0,0,0))
2534 pads.append(ROOT.TPad(
"p10",
"",0.78,0.56,1.00,0.78,0,0,0))
2535 pads.append(ROOT.TPad(
"p11",
"",0.00,0.34,0.07,0.56,0,0,0))
2536 pads.append(ROOT.TPad(
"p12",
"",0.07,0.34,0.34,0.56,0,0,0))
2537 pads.append(ROOT.TPad(
"p13",
"",0.34,0.34,0.56,0.56,0,0,0))
2538 pads.append(ROOT.TPad(
"p14",
"",0.56,0.34,0.78,0.56,0,0,0))
2539 pads.append(ROOT.TPad(
"p15",
"",0.78,0.34,1.00,0.56,0,0,0))
2540 pads.append(ROOT.TPad(
"p16",
"",0.00,0.07,0.07,0.34,0,0,0))
2541 pads.append(ROOT.TPad(
"p17",
"",0.07,0.07,0.34,0.34,0,0,0))
2542 pads.append(ROOT.TPad(
"p18",
"",0.34,0.07,0.56,0.34,0,0,0))
2543 pads.append(ROOT.TPad(
"p19",
"",0.56,0.07,0.78,0.34,0,0,0))
2544 pads.append(ROOT.TPad(
"p20",
"",0.78,0.07,1.00,0.34,0,0,0))
2545 pads.append(ROOT.TPad(
"p21",
"",0.00,0.00,0.07,0.07,0,0,0))
2546 pads.append(ROOT.TPad(
"p22",
"",0.07,0.00,0.34,0.07,0,0,0))
2547 pads.append(ROOT.TPad(
"p23",
"",0.34,0.00,0.56,0.07,0,0,0))
2548 pads.append(ROOT.TPad(
"p24",
"",0.56,0.00,0.78,0.07,0,0,0))
2549 pads.append(ROOT.TPad(
"p25",
"",0.78,0.00,1.00,0.07,0,0,0))
2553 ROOT.SetOwnership(p,
False)
2555 label1 = ROOT.TPaveLabel(0, 0, 1, 1,
"x residuals (mm)",
"")
2556 label2 = ROOT.TPaveLabel(0, 0, 1, 1,
"y residuals (mm)",
"")
2557 label3 = ROOT.TPaveLabel(0, 0, 1, 1,
"dx/dz residuals (mrad)",
"")
2558 label4 = ROOT.TPaveLabel(0, 0, 1, 1,
"dy/dz residuals (mrad)",
"")
2559 label5 = ROOT.TPaveLabel(0, 0, 1, 1,
"x position (cm)",
"")
2560 label6 = ROOT.TPaveLabel(0, 0, 1, 1,
"y position (cm)",
"")
2561 label7 = ROOT.TPaveLabel(0, 0, 1, 1,
"dx/dz angle (rad)",
"")
2562 label8 = ROOT.TPaveLabel(0, 0, 1, 1,
"dy/dz angle (rad)",
"")
2563 label9 = ROOT.TPaveLabel(0, 0.85, 1, 1,
getname(r),
"NDC")
2565 for l
in label1, label2, label3, label4, label5, label6, label7, label8, label9:
2567 l.SetFillColor(ROOT.kWhite)
2569 for l
in label1, label2, label3, label4:
2574 label9.SetTextSize(0.59)
2576 pads[1].cd(); label1.Draw()
2577 pads[6].cd(); label2.Draw()
2578 pads[11].cd(); label3.Draw()
2579 pads[16].cd(); label4.Draw()
2580 pads[22].cd(); label5.Draw()
2581 pads[23].cd(); label6.Draw()
2582 pads[24].cd(); label7.Draw()
2583 pads[25].cd(); label8.Draw()
2585 pads[2].SetRightMargin(1e-5)
2586 pads[2].SetBottomMargin(1e-5)
2587 pads[2].SetLeftMargin(0.17)
2588 pads[3].SetLeftMargin(1e-5)
2589 pads[3].SetRightMargin(1e-5)
2590 pads[3].SetBottomMargin(1e-5)
2591 pads[4].SetLeftMargin(1e-5)
2592 pads[4].SetRightMargin(1e-5)
2593 pads[4].SetBottomMargin(1e-5)
2594 pads[5].SetLeftMargin(1e-5)
2595 pads[5].SetBottomMargin(1e-5)
2597 pads[7].SetRightMargin(1e-5)
2598 pads[7].SetBottomMargin(1e-5)
2599 pads[7].SetTopMargin(1e-5)
2600 pads[7].SetLeftMargin(0.17)
2601 pads[8].SetLeftMargin(1e-5)
2602 pads[8].SetRightMargin(1e-5)
2603 pads[8].SetBottomMargin(1e-5)
2604 pads[8].SetTopMargin(1e-5)
2605 pads[9].SetLeftMargin(1e-5)
2606 pads[9].SetRightMargin(1e-5)
2607 pads[9].SetBottomMargin(1e-5)
2608 pads[9].SetTopMargin(1e-5)
2609 pads[10].SetLeftMargin(1e-5)
2610 pads[10].SetBottomMargin(1e-5)
2611 pads[10].SetTopMargin(1e-5)
2613 pads[12].SetRightMargin(1e-5)
2614 pads[12].SetBottomMargin(1e-5)
2615 pads[12].SetTopMargin(1e-5)
2616 pads[12].SetLeftMargin(0.17)
2617 pads[13].SetLeftMargin(1e-5)
2618 pads[13].SetRightMargin(1e-5)
2619 pads[13].SetBottomMargin(1e-5)
2620 pads[13].SetTopMargin(1e-5)
2621 pads[14].SetLeftMargin(1e-5)
2622 pads[14].SetRightMargin(1e-5)
2623 pads[14].SetBottomMargin(1e-5)
2624 pads[14].SetTopMargin(1e-5)
2625 pads[15].SetLeftMargin(1e-5)
2626 pads[15].SetBottomMargin(1e-5)
2627 pads[15].SetTopMargin(1e-5)
2629 pads[17].SetRightMargin(1e-5)
2630 pads[17].SetTopMargin(1e-5)
2631 pads[17].SetLeftMargin(0.17)
2632 pads[18].SetLeftMargin(1e-5)
2633 pads[18].SetRightMargin(1e-5)
2634 pads[18].SetTopMargin(1e-5)
2635 pads[19].SetLeftMargin(1e-5)
2636 pads[19].SetRightMargin(1e-5)
2637 pads[19].SetTopMargin(1e-5)
2638 pads[20].SetLeftMargin(1e-5)
2639 pads[20].SetTopMargin(1e-5)
2641 chamber_x_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2642 chamber_x_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2643 chamber_x_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2644 chamber_x_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2645 chamber_x_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2646 chamber_x_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2647 chamber_x_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2648 chamber_y_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2649 chamber_y_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2650 chamber_y_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2651 chamber_y_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2652 chamber_y_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2653 chamber_y_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2654 chamber_y_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2655 chamber_dxdz_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2656 chamber_dxdz_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2657 chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2658 chamber_dxdz_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2659 chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2660 chamber_dxdz_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2661 chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2664 chamber_dydz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2665 chamber_dydz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2666 chamber_dydz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2669 chamber_x_trackx.Draw(
"e1")
2670 if not suppressblue: chamber_x_trackx_fit2.Draw(
"samel")
2671 chamber_x_trackx_fit.Draw(
"samel")
2679 chamber_x_tracky.Draw(
"e1")
2680 if not suppressblue: chamber_x_tracky_fit2.Draw(
"samel")
2681 chamber_x_tracky_fit.Draw(
"samel")
2684 chamber_x_trackdxdz.Draw(
"e1")
2685 if not suppressblue: chamber_x_trackdxdz_fit2.Draw(
"samel")
2686 chamber_x_trackdxdz_fit.Draw(
"samel")
2689 chamber_x_trackdydz.Draw(
"e1")
2690 if not suppressblue: chamber_x_trackdydz_fit2.Draw(
"samel")
2691 chamber_x_trackdydz_fit.Draw(
"samel")
2694 chamber_y_trackx.Draw(
"e1")
2695 if not suppressblue: chamber_y_trackx_fit2.Draw(
"samel")
2696 chamber_y_trackx_fit.Draw(
"samel")
2699 chamber_y_tracky.Draw(
"e1")
2700 if not suppressblue: chamber_y_tracky_fit2.Draw(
"samel")
2701 chamber_y_tracky_fit.Draw(
"samel")
2704 chamber_y_trackdxdz.Draw(
"e1")
2705 if not suppressblue: chamber_y_trackdxdz_fit2.Draw(
"samel")
2706 chamber_y_trackdxdz_fit.Draw(
"samel")
2709 chamber_y_trackdydz.Draw(
"e1")
2710 if not suppressblue: chamber_y_trackdydz_fit2.Draw(
"samel")
2711 chamber_y_trackdydz_fit.Draw(
"samel")
2714 chamber_dxdz_trackx.Draw(
"e1")
2715 if not suppressblue: chamber_dxdz_trackx_fit2.Draw(
"samel")
2716 chamber_dxdz_trackx_fit.Draw(
"samel")
2719 chamber_dxdz_tracky.Draw(
"e1")
2720 if not suppressblue: chamber_dxdz_tracky_fit2.Draw(
"samel")
2721 chamber_dxdz_tracky_fit.Draw(
"samel")
2724 chamber_dxdz_trackdxdz.Draw(
"e1")
2725 if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw(
"samel")
2726 chamber_dxdz_trackdxdz_fit.Draw(
"samel")
2729 chamber_dxdz_trackdydz.Draw(
"e1")
2730 if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw(
"samel")
2731 chamber_dxdz_trackdydz_fit.Draw(
"samel")
2734 chamber_dydz_trackx.Draw(
"e1")
2735 if not suppressblue: chamber_dydz_trackx_fit2.Draw(
"samel")
2736 chamber_dydz_trackx_fit.Draw(
"samel")
2739 chamber_dydz_tracky.Draw(
"e1")
2740 if not suppressblue: chamber_dydz_tracky_fit2.Draw(
"samel")
2741 chamber_dydz_tracky_fit.Draw(
"samel")
2744 chamber_dydz_trackdxdz.Draw(
"e1")
2745 if not suppressblue: chamber_dydz_trackdxdz_fit2.Draw(
"samel")
2746 chamber_dydz_trackdxdz_fit.Draw(
"samel")
2749 chamber_dydz_trackdydz.Draw(
"e1")
2750 if not suppressblue: chamber_dydz_trackdydz_fit2.Draw(
"samel")
2751 chamber_dydz_trackdydz_fit.Draw(
"samel")
2757 pads.append(ROOT.TPad(
"p1" ,
"",0.00,0.55,0.07,1.00,0,0,0))
2758 pads.append(ROOT.TPad(
"p2" ,
"",0.07,0.55,0.34,1.00,0,0,0))
2759 pads.append(ROOT.TPad(
"p3" ,
"",0.34,0.55,0.56,1.00,0,0,0))
2760 pads.append(ROOT.TPad(
"p4" ,
"",0.56,0.55,0.78,1.00,0,0,0))
2761 pads.append(ROOT.TPad(
"p5" ,
"",0.78,0.55,1.00,1.00,0,0,0))
2762 pads.append(ROOT.TPad(
"p6" ,
"",0.00,0.1,0.07,0.55,0,0,0))
2763 pads.append(ROOT.TPad(
"p7" ,
"",0.07,0.1,0.34,0.55,0,0,0))
2764 pads.append(ROOT.TPad(
"p8" ,
"",0.34,0.1,0.56,0.55,0,0,0))
2765 pads.append(ROOT.TPad(
"p9" ,
"",0.56,0.1,0.78,0.55,0,0,0))
2766 pads.append(ROOT.TPad(
"p10",
"",0.78,0.1,1.00,0.55,0,0,0))
2767 pads.append(ROOT.TPad(
"p11",
"",0.00,0.,0.07,0.1,0,0,0))
2768 pads.append(ROOT.TPad(
"p12",
"",0.07,0.,0.34,0.1,0,0,0))
2769 pads.append(ROOT.TPad(
"p13",
"",0.34,0.,0.56,0.1,0,0,0))
2770 pads.append(ROOT.TPad(
"p14",
"",0.56,0.,0.78,0.1,0,0,0))
2771 pads.append(ROOT.TPad(
"p15",
"",0.78,0.,1.00,0.1,0,0,0))
2775 ROOT.SetOwnership(p,
False)
2777 label1 = ROOT.TPaveLabel(0, 0, 1, 1,
"x residuals (mm)")
2778 label2 = ROOT.TPaveLabel(0, 0, 1, 1,
"dx/dz residuals (mrad)")
2779 label3 = ROOT.TPaveLabel(0, 0.3, 1, 1,
"x position (cm)")
2780 label4 = ROOT.TPaveLabel(0, 0.3, 1, 1,
"y position (cm)")
2781 label5 = ROOT.TPaveLabel(0, 0.3, 1, 1,
"dx/dz angle (rad)")
2782 label6 = ROOT.TPaveLabel(0, 0.3, 1, 1,
"dy/dz angle (rad)")
2783 label9 = ROOT.TPaveLabel(0, 0.85, 1, 1,
getname(r),
"NDC")
2785 if name[0:2] ==
"ME":
2786 label1 = ROOT.TPaveLabel(0, 0, 1, 1,
"r#phi residuals (mm)")
2787 label2 = ROOT.TPaveLabel(0, 0, 1, 1,
"d(r#phi)/dz residuals (mrad)")
2789 for l
in label1, label2, label3, label4, label5, label6, label9:
2791 l.SetFillColor(ROOT.kWhite)
2793 for l
in label1, label2:
2798 label9.SetTextSize(0.29)
2800 pads[1].cd(); label1.Draw()
2801 pads[6].cd(); label2.Draw()
2802 pads[12].cd(); label3.Draw()
2803 pads[13].cd(); label4.Draw()
2804 pads[14].cd(); label5.Draw()
2805 pads[15].cd(); label6.Draw()
2808 pads[2].SetRightMargin(1e-5)
2809 pads[2].SetBottomMargin(1e-5)
2810 pads[3].SetLeftMargin(1e-5)
2811 pads[3].SetRightMargin(1e-5)
2812 pads[3].SetBottomMargin(1e-5)
2813 pads[4].SetLeftMargin(1e-5)
2814 pads[4].SetRightMargin(1e-5)
2815 pads[4].SetBottomMargin(1e-5)
2816 pads[5].SetLeftMargin(1e-5)
2817 pads[5].SetBottomMargin(1e-5)
2819 pads[7].SetRightMargin(1e-5)
2820 pads[7].SetTopMargin(1e-5)
2821 pads[8].SetLeftMargin(1e-5)
2822 pads[8].SetRightMargin(1e-5)
2823 pads[8].SetTopMargin(1e-5)
2824 pads[9].SetLeftMargin(1e-5)
2825 pads[9].SetRightMargin(1e-5)
2826 pads[9].SetTopMargin(1e-5)
2827 pads[10].SetLeftMargin(1e-5)
2828 pads[10].SetTopMargin(1e-5)
2830 chamber_x_trackx.GetXaxis().SetLabelColor(ROOT.kWhite)
2831 chamber_x_tracky.GetXaxis().SetLabelColor(ROOT.kWhite)
2832 chamber_x_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2833 chamber_x_trackdxdz.GetXaxis().SetLabelColor(ROOT.kWhite)
2834 chamber_x_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2835 chamber_x_trackdydz.GetXaxis().SetLabelColor(ROOT.kWhite)
2836 chamber_x_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2838 chamber_dxdz_tracky.GetYaxis().SetLabelColor(ROOT.kWhite)
2839 chamber_dxdz_trackdxdz.GetYaxis().SetLabelColor(ROOT.kWhite)
2840 chamber_dxdz_trackdydz.GetYaxis().SetLabelColor(ROOT.kWhite)
2843 chamber_x_trackx.Draw(
"e1")
2844 if not suppressblue: chamber_x_trackx_fit2.Draw(
"samel")
2845 chamber_x_trackx_fit.Draw(
"samel")
2849 chamber_x_tracky.Draw(
"e1")
2850 if not suppressblue: chamber_x_tracky_fit2.Draw(
"samel")
2851 chamber_x_tracky_fit.Draw(
"samel")
2854 chamber_x_trackdxdz.Draw(
"e1")
2855 if not suppressblue: chamber_x_trackdxdz_fit2.Draw(
"samel")
2856 chamber_x_trackdxdz_fit.Draw(
"samel")
2859 chamber_x_trackdydz.Draw(
"e1")
2860 if not suppressblue: chamber_x_trackdydz_fit2.Draw(
"samel")
2861 chamber_x_trackdydz_fit.Draw(
"samel")
2864 chamber_dxdz_trackx.Draw(
"e1")
2865 if not suppressblue: chamber_dxdz_trackx_fit2.Draw(
"samel")
2866 chamber_dxdz_trackx_fit.Draw(
"samel")
2869 chamber_dxdz_tracky.Draw(
"e1")
2870 if not suppressblue: chamber_dxdz_tracky_fit2.Draw(
"samel")
2871 chamber_dxdz_tracky_fit.Draw(
"samel")
2874 chamber_dxdz_trackdxdz.Draw(
"e1")
2875 if not suppressblue: chamber_dxdz_trackdxdz_fit2.Draw(
"samel")
2876 chamber_dxdz_trackdxdz_fit.Draw(
"samel")
2879 chamber_dxdz_trackdydz.Draw(
"e1")
2880 if not suppressblue: chamber_dxdz_trackdydz_fit2.Draw(
"samel")
2881 chamber_dxdz_trackdydz_fit.Draw(
"samel")
2884 ddt[8] = 1./ddt[7]*((ddt[7]-1)*ddt[8] + tn-t1)
2889 tdrStyle.SetOptFit(1)
2890 tdrStyle.SetOptTitle(1)
2891 tdrStyle.SetTitleBorderSize(1)
2892 tdrStyle.SetTitleFontSize(0.05)
2893 tdrStyle.SetStatW(0.2)
2894 tdrStyle.SetStatY(0.9)
2895 tdrStyle.SetStatFontSize(0.06)
2897 if component[0:2] ==
"dt":
2898 wheel = args[
"wheel"]
2900 sector = args[
"sector"]
2901 profname =
"%s_%s_%02d_%s" % (component, wheelletter, sector,
str(pair))
2902 posname =
"pos" + profname
2903 negname =
"neg" + profname
2906 station1 =
int(
str(pair)[0])
2907 station2 =
int(
str(pair)[1])
2908 phi1 = signConventions[
"DT", wheel, station1, sector][4]
2909 phi2 = signConventions[
"DT", wheel, station2, sector][4]
2910 if abs(phi1 - phi2) > 1.:
2911 if phi1 > phi2: phi1 -= 2.*pi
2913 phi = (phi1 + phi2) / 2.
2914 while (phi < -pi): phi += 2.*pi
2915 while (phi > pi): phi -= 2.*pi
2917 elif component[0:3] ==
"csc":
2918 endcap = args[
"endcap"]
2925 else:
raise Exception
2928 if ring>2
or ring<1:
raise Exception
2929 station1 =
int(
str(pair)[0])
2930 station2 =
int(
str(pair)[1])
2931 if ring==1: ringname=
"inner" 2932 elif ring==2: ringname=
"outer" 2933 else:
raise Exception
2935 chamber = args[
"chamber"]
2936 if (ring==1
and chamber>18)
or (ring==2
and chamber>36):
raise Exception
2938 profname =
"csc%s_%s_%s_%02d_%s" % (ringname,component[4:], endcap, chamber,
str(pair))
2939 posname =
"pos" + profname
2940 negname =
"neg" + profname
2943 station1 =
int(
str(pair)[0])
2944 station2 =
int(
str(pair)[1])
2945 phi1 = signConventions[
"CSC", endcapnum, station1, ring, chamber][4]
2946 phi2 = signConventions[
"CSC", endcapnum, station2, ring, chamber][4]
2947 if abs(phi1 - phi2) > 1.:
2948 if phi1 > phi2: phi1 -= 2.*pi
2950 phi = (phi1 + phi2) / 2.
2951 while (phi < -pi*5./180.): phi += 2.*pi
2952 while (phi > pi*(2.-5./180.)): phi -= 2.*pi
2954 else:
raise Exception
2956 if "window" in args: window = args[
"window"]
2959 global tmpprof, tmppos, tmpneg
2960 pdir =
"AlignmentMonitorSegmentDifferences/iter1/" 2961 tmpprof = tfiles[0].Get(pdir + profname).Clone()
2962 tmpprof.SetMarkerStyle(8)
2963 tmppos = tfiles[0].Get(pdir + posname).Clone()
2964 tmpneg = tfiles[0].Get(pdir + negname).Clone()
2965 for tfile
in tfiles[1:]:
2966 tmpprof.Add(tfile.Get(pdir + profname))
2967 tmppos.Add(tfile.Get(pdir + posname))
2968 tmpneg.Add(tfile.Get(pdir + negname))
2970 for i
in xrange(1, tmpprof.GetNbinsX()+1):
2971 if tmpprof.GetBinError(i) < 1e-5:
2972 tmpprof.SetBinError(i, 100.)
2973 tmpprof.SetAxisRange(-window, window,
"Y")
2975 f = ROOT.TF1(
"p1",
"[0] + [1]*x", tmpprof.GetBinLowEdge(1), -tmpprof.GetBinLowEdge(1))
2976 f.SetParameters((tmppos.GetMean() + tmpneg.GetMean())/2., 0.)
2978 tmpprof.SetXTitle(
"q/p_{T} (c/GeV)")
2979 if component ==
"dt13_resid":
2980 tmpprof.SetYTitle(
"#Deltax^{local} (mm)")
2981 tmppos.SetXTitle(
"#Deltax^{local} (mm)")
2982 tmpneg.SetXTitle(
"#Deltax^{local} (mm)")
2983 f.SetParNames(
"#Deltax^{local}_{0}",
"Slope")
2984 if component ==
"dt13_slope":
2985 tmpprof.SetYTitle(
"#Deltadx/dz^{local} (mrad)")
2986 tmppos.SetXTitle(
"#Deltadx/dz^{local} (mrad)")
2987 tmpneg.SetXTitle(
"#Deltadx/dz^{local} (mrad)")
2988 f.SetParNames(
"#Deltadx/dz^{local}_{0}",
"Slope")
2989 if component ==
"dt2_resid":
2990 tmpprof.SetYTitle(
"#Deltay^{local} (mm)")
2991 tmppos.SetXTitle(
"#Deltay^{local} (mm)")
2992 tmpneg.SetXTitle(
"#Deltay^{local} (mm)")
2993 f.SetParNames(
"#Deltay^{local}_{0}",
"Slope")
2994 if component ==
"dt2_slope":
2995 tmpprof.SetYTitle(
"#Deltady/dz^{local} (mrad)")
2996 tmppos.SetXTitle(
"#Deltady/dz^{local} (mrad)")
2997 tmpneg.SetXTitle(
"#Deltady/dz^{local} (mrad)")
2998 f.SetParNames(
"#Deltady/dz^{local}_{0}",
"Slope")
2999 if component ==
"csc_resid":
3000 tmpprof.SetXTitle(
"q/p_{z} (c/GeV)")
3001 tmpprof.SetYTitle(
"#Delta(r#phi)^{local} (mm)")
3002 tmppos.SetXTitle(
"#Delta(r#phi)^{local} (mm)")
3003 tmpneg.SetXTitle(
"#Delta(r#phi)^{local} (mm)")
3004 f.SetParNames(
"#Delta(r#phi)^{local}_{0}",
"Slope")
3005 if component ==
"csc_slope":
3006 tmpprof.SetXTitle(
"q/p_{z} (c/GeV)")
3007 tmpprof.SetYTitle(
"#Deltad(r#phi)/dz^{local} (mrad)")
3008 tmppos.SetXTitle(
"#Deltad(r#phi)/dz^{local} (mrad)")
3009 tmpneg.SetXTitle(
"#Deltad(r#phi)/dz^{local} (mrad)")
3010 f.SetParNames(
"#Deltad(r#phi)/dz^{local}_{0}",
"Slope")
3012 tmpprof.GetXaxis().CenterTitle()
3013 tmpprof.GetYaxis().CenterTitle()
3014 tmppos.GetXaxis().CenterTitle()
3015 tmpneg.GetXaxis().CenterTitle()
3016 if component[0:2] ==
"dt":
3017 tmpprof.SetTitle(
"MB%d - MB%d, wheel %d, sector %02d" % (station1, station2,
int(wheel),
int(sector)))
3018 elif component[0:3] ==
"csc":
3019 tmpprof.SetTitle(
"ME%d - ME%d, for ME%s%d/%d/%d" % (station1, station2, endcapsign, station2, ring, chamber))
3020 else:
raise Exception
3022 tmppos.SetTitle(
"Positive muons")
3023 tmpneg.SetTitle(
"Negative muons")
3028 fit1 = tmpprof.Fit(
"p1",
"qS")
3031 c1.GetPad(2).
Divide(1, 2)
3032 c1.GetPad(2).GetPad(1).cd()
3034 f = ROOT.TF1(
"gausR",
"[0]*exp(-(x - [1])**2 / 2. / [2]**2) / sqrt(2.*3.1415926) / [2]",
3035 tmppos.GetMean() - tmppos.GetRMS(), tmppos.GetMean() + tmppos.GetRMS())
3036 f.SetParameters(tmppos.GetEntries() * ((10. - -10.)/100.), tmppos.GetMean(), tmppos.GetRMS())
3037 f.SetParNames(
"Constant",
"Mean",
"Sigma")
3038 fit2 = tmppos.Fit(
"gausR",
"qRS")
3039 c1.GetPad(2).GetPad(2).cd()
3041 f = ROOT.TF1(
"gausR",
"[0]*exp(-(x - [1])**2 / 2. / [2]**2) / sqrt(2.*3.1415926) / [2]",
3042 tmpneg.GetMean() - tmpneg.GetRMS(), tmpneg.GetMean() + tmpneg.GetRMS())
3043 f.SetParameters(tmpneg.GetEntries() * ((10. - -10.)/100.), tmpneg.GetMean(), tmpneg.GetRMS())
3044 f.SetParNames(
"Constant",
"Mean",
"Sigma")
3045 fit3 = tmpneg.Fit(
"gausR",
"qRS")
3047 fit1ok = fit1.Status()==0
and fit1.CovMatrixStatus()==3
3048 fit2ok = fit2.Status()==0
and fit2.CovMatrixStatus()==3
3049 fit3ok = fit3.Status()==0
and fit3.CovMatrixStatus()==3
3051 fitresult1 =
None,
None 3053 fitresult1 = tmpprof.GetFunction(
"p1").GetParameter(0), tmpprof.GetFunction(
"p1").GetParError(0)
3054 fitresult2 =
None,
None 3055 if fit2ok
and fit3ok:
3056 fitresult2 = (tmppos.GetFunction(
"gausR").GetParameter(1) + tmpneg.GetFunction(
"gausR").GetParameter(1)) / 2., \
3057 sqrt(tmppos.GetFunction(
"gausR").GetParError(1)**2 + tmpneg.GetFunction(
"gausR").GetParError(1)**2) / 2.
3058 return phi, fitresult1[0], fitresult1[1], fitresult2[0], fitresult2[1], fit1ok, fit2ok, fit3ok
3065 tdrStyle.SetOptFit(1)
3066 tdrStyle.SetOptTitle(1)
3067 tdrStyle.SetTitleBorderSize(1)
3068 tdrStyle.SetTitleFontSize(0.05)
3069 tdrStyle.SetStatW(0.2)
3070 tdrStyle.SetStatY(0.9)
3071 tdrStyle.SetStatFontSize(0.06)
3073 if component[0:4] ==
"x_dt":
3074 wheel =
int(args[
"wheel"])
3076 wheell =
"m%d" %
abs(wheel)
3079 wheell =
"p%d" %
abs(wheel)
3081 station_dt = component[4]
3082 station_csc_1 = args[
"cscstations"][0]
3083 if station_csc_1==
'1': ring_1 = 3
3085 sector = args[
"sector"]
3086 profname =
"%s%s_W%sS%02d" % (component, station_csc_1, wheell, sector)
3087 posname_1 =
"pos_" + profname
3088 negname_1 =
"neg_" + profname
3089 if len(args[
"cscstations"]) > 1:
3090 station_csc_2 = args[
"cscstations"][1]
3091 if station_csc_2==
'1': ring_2 = 3
3093 profname =
"%s%s_W%sS%02d" % (component, station_csc_2, wheell, sector)
3094 posname_2 =
"pos_" + profname
3095 negname_2 =
"neg_" + profname
3097 phi = signConventions[
"DT", wheel,
int(station_dt), sector][4]
3098 while (phi < -pi): phi += 2.*pi
3099 while (phi > pi): phi -= 2.*pi
3101 else:
raise Exception
3103 if "window" in args: window = args[
"window"]
3106 global tmppos, tmpneg, tmppos_2, tmpneg_2
3107 pdir =
"AlignmentMonitorSegmentDifferences/iter1/" 3108 tmppos = tfiles[0].Get(pdir + posname_1).Clone()
3109 tmpneg = tfiles[0].Get(pdir + negname_1).Clone()
3110 if len(args[
"cscstations"]) > 1:
3111 tmppos_2 = tfiles[0].Get(pdir + posname_2).Clone()
3112 tmpneg_2 = tfiles[0].Get(pdir + negname_2).Clone()
3113 tmpneg.Rebin(2); tmppos.Rebin(2)
3114 for tfile
in tfiles[1:]:
3115 tmppos.Add(tfile.Get(pdir + posname_1))
3116 tmpneg.Add(tfile.Get(pdir + negname_1))
3117 if len(args[
"cscstations"]) > 1:
3118 tmppos_2.Add(tfile.Get(pdir + posname_2))
3119 tmpneg_2.Add(tfile.Get(pdir + negname_2))
3120 tmpneg_2.Rebin(2); tmppos_2.Rebin(2)
3123 result[
"fit_ok"] =
False 3125 ntot = tmppos.GetEntries() + tmpneg.GetEntries()
3129 tmppos.SetXTitle(
"#Deltax^{loc}_{MB} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{ME} (mm)")
3130 tmpneg.SetXTitle(
"#Deltax^{loc}_{MB} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{ME} (mm)")
3131 title1 =
"MB(W%+d St%s Sec%d) - ME%s%s/%d" % (wheel, station_dt,
int(sector), endcapsign, station_csc_1, ring_1)
3132 tmppos.SetTitle(
"Positive #mu: %s" % title1);
3133 tmpneg.SetTitle(
"Negative #mu: %s" % title1);
3134 tmppos.GetXaxis().CenterTitle()
3135 tmpneg.GetXaxis().CenterTitle()
3136 if len(args[
"cscstations"]) > 1:
3137 tmppos.SetXTitle(
"#Deltax^{loc}_{DT} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{CSC} (mm)")
3138 tmpneg.SetXTitle(
"#Deltax^{loc}_{DT} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{CSC} (mm)")
3139 title2 =
"MB(W%+d St%s Sec%d) - ME%s%s/%d" % (wheel, station_dt,
int(sector), endcapsign, station_csc_2, ring_2)
3140 tmppos_2.SetTitle(
"Positive #mu: %s" % title2);
3141 tmpneg_2.SetTitle(
"Negative #mu: %s" % title2);
3142 tmppos_2.GetXaxis().CenterTitle()
3143 tmpneg_2.GetXaxis().CenterTitle()
3150 fpos = ROOT.TF1(
"gpos",
"gaus", tmppos.GetMean() - tmppos.GetRMS(), tmppos.GetMean() + tmppos.GetRMS())
3151 fpos.SetParameters(tmppos.GetEntries() * 2.5, tmppos.GetMean(), tmppos.GetRMS())
3152 fit_pos = tmppos.Fit(
"gpos",
"qRS")
3156 fneg = ROOT.TF1(
"gneg",
"gaus", tmpneg.GetMean() - tmpneg.GetRMS(), tmpneg.GetMean() + tmpneg.GetRMS())
3157 fneg.SetParameters(tmpneg.GetEntries() * 2.5, tmpneg.GetMean(), tmpneg.GetRMS())
3158 fit_neg = tmpneg.Fit(
"gneg",
"qRS")
3160 result[
"fit_ok"] = (fit_pos.Status()==0
and fit_pos.CovMatrixStatus()==3
and fit_neg.Status()==0
and fit_neg.CovMatrixStatus()==3)
3161 result[
"fit_peak"] = (fpos.GetParameter(1)*tmppos.GetEntries() + fneg.GetParameter(1)*tmpneg.GetEntries()) / ntot
3162 result[
"fit_peak_error"] =
sqrt( (fpos.GetParError(1)*tmppos.GetEntries())**2 + (fneg.GetParError(1)*tmpneg.GetEntries())**2) / ntot
3164 if len(args[
"cscstations"]) > 1:
3167 fpos_2 = ROOT.TF1(
"gpos2",
"gaus", tmppos_2.GetMean() - tmppos_2.GetRMS(), tmppos_2.GetMean() + tmppos_2.GetRMS())
3168 fpos_2.SetParameters(tmppos_2.GetEntries() * 2.5, tmppos_2.GetMean(), tmppos_2.GetRMS())
3169 fit_pos_2 = tmppos_2.Fit(
"gpos2",
"qRS")
3173 fneg_2 = ROOT.TF1(
"gneg2",
"gaus", tmpneg_2.GetMean() - tmpneg_2.GetRMS(), tmpneg_2.GetMean() + tmpneg_2.GetRMS())
3174 fneg_2.SetParameters(tmpneg_2.GetEntries() * 2.5, tmpneg_2.GetMean(), tmpneg_2.GetRMS())
3175 fit_neg_2 = tmpneg_2.Fit(
"gneg2",
"qRS")
3177 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)
3178 ntot = tmppos_2.GetEntries() + tmpneg_2.GetEntries()
3179 result[
"fit_peak_2"] = (fpos_2.GetParameter(1)*tmppos_2.GetEntries() + fneg_2.GetParameter(1)*tmpneg_2.GetEntries()) / ntot
3180 result[
"fit_peak_error_2"] =
sqrt( (fpos_2.GetParError(1)*tmppos_2.GetEntries())**2 + (fneg_2.GetParError(1)*tmpneg_2.GetEntries())**2) / ntot
3187 tdrStyle.SetOptTitle(1)
3188 tdrStyle.SetTitleBorderSize(1)
3189 tdrStyle.SetTitleFontSize(0.05)
3191 global htemp, gtemp_12, gtemp_21, gtemp_11, tlegend
3192 htemp = ROOT.TH1F(
"htemp",
"", 1, -pi, pi)
3193 gtemp_11_phi, gtemp_11_val, gtemp_11_err = [], [], []
3194 gtemp_12_phi, gtemp_12_val, gtemp_12_err = [], [], []
3195 gtemp_21_phi, gtemp_21_val, gtemp_21_err = [], [], []
3196 for sector
in xrange(1, 12+1):
3198 r1 =
segdiff_xalign(tfiles,
"x_dt1_csc", wheel=wheel, sector=sector, cscstations =
"12")
3199 r2 =
segdiff_xalign(tfiles,
"x_dt2_csc", wheel=wheel, sector=sector, cscstations =
"1")
3202 gtemp_11_phi.append(r1[
"phi"])
3203 gtemp_11_val.append(r1[
"fit_peak"])
3204 gtemp_11_err.append(r1[
"fit_peak_error"])
3206 gtemp_12_phi.append(r1[
"phi"])
3207 gtemp_12_val.append(r1[
"fit_peak_2"])
3208 gtemp_12_err.append(r1[
"fit_peak_error_2"])
3210 gtemp_21_phi.append(r2[
"phi"])
3211 gtemp_21_val.append(r2[
"fit_peak"])
3212 gtemp_21_err.append(r2[
"fit_peak_error"])
3217 if len(gtemp_11_phi) > 0:
3218 gtemp_11 = ROOT.TGraphErrors(len(gtemp_11_phi), array.array(
"d", gtemp_11_phi), array.array(
"d", gtemp_11_val),
3219 array.array(
"d", [0.] * len(gtemp_11_phi)), array.array(
"d", gtemp_11_err))
3220 if len(gtemp_12_phi) > 0:
3221 gtemp_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array(
"d", gtemp_12_phi), array.array(
"d", gtemp_12_val),
3222 array.array(
"d", [0.] * len(gtemp_12_phi)), array.array(
"d", gtemp_12_err))
3223 if len(gtemp_11_phi) > 0:
3224 gtemp_21 = ROOT.TGraphErrors(len(gtemp_21_phi), array.array(
"d", gtemp_21_phi), array.array(
"d", gtemp_21_val),
3225 array.array(
"d", [0.] * len(gtemp_21_phi)), array.array(
"d", gtemp_21_err))
3227 if len(gtemp_11_phi) > 0:
3228 gtemp_11.SetMarkerStyle(20); gtemp_11.SetMarkerSize(1.5);
3229 gtemp_11.SetMarkerColor(ROOT.kRed); gtemp_11.SetLineColor(ROOT.kRed)
3230 if len(gtemp_12_phi) > 0:
3231 gtemp_12.SetMarkerStyle(22); gtemp_12.SetMarkerSize(1.);
3232 gtemp_12.SetMarkerColor(ROOT.kGreen+2); gtemp_12.SetLineColor(ROOT.kGreen+2)
3233 if len(gtemp_21_phi) > 0:
3234 gtemp_21.SetMarkerStyle(21); gtemp_21.SetMarkerSize(1.5);
3235 gtemp_21.SetMarkerColor(ROOT.kBlue); gtemp_21.SetLineColor(ROOT.kBlue)
3237 htemp.SetTitle(
"Wheel %+d" % wheel)
3238 htemp.SetAxisRange(-window, window,
"Y")
3239 htemp.SetXTitle(
"#phi of MB")
3240 htemp.SetYTitle(
"#Deltax^{loc}_{DT} - r_{DT}/r_{CSC}#times#Deltax^{loc}_{CSC} (mm)")
3241 htemp.GetXaxis().CenterTitle()
3242 htemp.GetYaxis().CenterTitle()
3243 htemp.GetYaxis().SetTitleOffset(0.75)
3247 if len(gtemp_12_phi) > 0:
3249 if len(gtemp_21_phi) > 0:
3251 if len(gtemp_11_phi) > 0:
3254 tlegend = ROOT.TLegend(0.59, 0.75, 0.99, 0.92)
3255 tlegend.SetBorderSize(0)
3256 tlegend.SetFillColor(ROOT.kWhite)
3257 if len(gtemp_11_phi) > 0:
3258 tlegend.AddEntry(gtemp_11,
"MB1 - ME1/3 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_11_val),
stdev(gtemp_11_val)),
"pl")
3259 if len(gtemp_21_phi) > 0:
3260 tlegend.AddEntry(gtemp_21,
"MB2 - ME1/3 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_21_val),
stdev(gtemp_21_val)),
"pl")
3261 if len(gtemp_12_phi) > 0:
3262 tlegend.AddEntry(gtemp_12,
"MB1 - ME2/2 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_12_val),
stdev(gtemp_12_val)),
"pl")
3269 f_11 = ROOT.TF1(
"f11",
"[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
3270 f_11.SetLineColor(ROOT.kRed)
3271 f_11.SetLineWidth(2)
3272 f_21 = ROOT.TF1(
"f21",
"[0] + [1]*sin(x) + [2]*cos(x)", -pi, pi)
3273 f_21.SetLineColor(ROOT.kBlue)
3274 f_21.SetLineWidth(2)
3275 if len(gtemp_11_phi) > 0:
3276 gtemp_11.Fit(f_11,
"")
3277 if len(gtemp_21_phi) > 0:
3278 gtemp_21.Fit(f_21,
"")
3280 global f_txt,f_11_txt, f_21_txt
3281 f_txt = ROOT.TLatex(-2.9, -0.7*window,
"ME1/3 ring corrections equivalents:")
3282 f_txt.SetTextSize(0.028)
3284 if len(gtemp_11_phi) > 0:
3285 rdt = signConventions[(
"DT", 2, 1, 1)][3]*10
3286 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" % (
3287 -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))
3288 f_11_txt.SetTextSize(0.028)
3289 f_11_txt.SetTextColor(ROOT.kRed)
3291 if len(gtemp_11_phi) > 0:
3292 rdt = signConventions[(
"DT", 2, 2, 1)][3]*10
3293 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" % (
3294 -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))
3295 f_21_txt.SetTextSize(0.028)
3296 f_21_txt.SetTextColor(ROOT.kBlue)
3301 def segdiffvsphi(tfiles, reports, component, wheel, window=5., excludesectors=()):
3302 tdrStyle.SetOptTitle(1)
3303 tdrStyle.SetTitleBorderSize(1)
3304 tdrStyle.SetTitleFontSize(0.05)
3306 global htemp, gtemp_12, gtemp2_12, gtemp_23, gtemp2_23, gtemp_34, gtemp2_34, tlegend
3307 htemp = ROOT.TH1F(
"htemp",
"", 1, -pi, pi)
3308 gtemp_12_phi, gtemp_12_val, gtemp_12_err, gtemp_12_val2, gtemp_12_err2 = [], [], [], [], []
3309 gtemp_23_phi, gtemp_23_val, gtemp_23_err, gtemp_23_val2, gtemp_23_err2 = [], [], [], [], []
3310 gtemp_34_phi, gtemp_34_val, gtemp_34_err, gtemp_34_val2, gtemp_34_err2 = [], [], [], [], []
3311 for sector
in xrange(1, 12+1):
3313 r1_found, r2_found, r3_found, r4_found =
False,
False,
False,
False 3315 if r1.postal_address == (
"DT", wheel, 1, sector):
3319 if r2.postal_address == (
"DT", wheel, 2, sector):
3323 if r3.postal_address == (
"DT", wheel, 3, sector):
3327 if r4.postal_address == (
"DT", wheel, 4, sector):
3332 if sector
not in excludesectors:
3333 if r1_found
and r2_found
and r1.status ==
"PASS" and r2.status ==
"PASS":
3334 phi, val, err, val2, err2, fit1, fit2, fit3 =
segdiff(tfiles, component, 12, wheel=wheel, sector=sector)
3336 if fit1
and fit2
and fit3:
3337 gtemp_12_phi.append(phi)
3338 gtemp_12_val.append(val)
3339 gtemp_12_err.append(err)
3340 gtemp_12_val2.append(val2)
3341 gtemp_12_err2.append(err2)
3342 if r2_found
and r3_found
and r2.status ==
"PASS" and r3.status ==
"PASS":
3343 phi, val, err, val2, err2, fit1, fit2, fit3 =
segdiff(tfiles, component, 23, wheel=wheel, sector=sector)
3345 if fit1
and fit2
and fit3:
3346 gtemp_23_phi.append(phi)
3347 gtemp_23_val.append(val)
3348 gtemp_23_err.append(err)
3349 gtemp_23_val2.append(val2)
3350 gtemp_23_err2.append(err2)
3351 if component[:4] ==
"dt13":
3352 if r3_found
and r4_found
and r3.status ==
"PASS" and r4.status ==
"PASS":
3353 phi, val, err, val2, err2, fit1, fit2, fit3 =
segdiff(tfiles, component, 34, wheel=wheel, sector=sector)
3355 if fit1
and fit2
and fit3:
3356 gtemp_34_phi.append(phi)
3357 gtemp_34_val.append(val)
3358 gtemp_34_err.append(err)
3359 gtemp_34_val2.append(val2)
3360 gtemp_34_err2.append(err2)
3365 if len(gtemp_12_phi) > 0:
3366 gtemp_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array(
"d", gtemp_12_phi), array.array(
"d", gtemp_12_val),
3367 array.array(
"d", [0.] * len(gtemp_12_phi)), array.array(
"d", gtemp_12_err))
3368 gtemp2_12 = ROOT.TGraphErrors(len(gtemp_12_phi), array.array(
"d", gtemp_12_phi), array.array(
"d", gtemp_12_val2),
3369 array.array(
"d", [0.] * len(gtemp_12_phi)), array.array(
"d", gtemp_12_err2))
3370 if len(gtemp_23_phi) > 0:
3371 gtemp_23 = ROOT.TGraphErrors(len(gtemp_23_phi), array.array(
"d", gtemp_23_phi), array.array(
"d", gtemp_23_val),
3372 array.array(
"d", [0.] * len(gtemp_23_phi)), array.array(
"d", gtemp_23_err))
3373 gtemp2_23 = ROOT.TGraphErrors(len(gtemp_23_phi), array.array(
"d", gtemp_23_phi), array.array(
"d", gtemp_23_val2),
3374 array.array(
"d", [0.] * len(gtemp_23_phi)), array.array(
"d", gtemp_23_err2))
3375 if len(gtemp_34_phi) > 0:
3376 gtemp_34 = ROOT.TGraphErrors(len(gtemp_34_phi), array.array(
"d", gtemp_34_phi), array.array(
"d", gtemp_34_val),
3377 array.array(
"d", [0.] * len(gtemp_34_phi)), array.array(
"d", gtemp_34_err))
3378 gtemp2_34 = ROOT.TGraphErrors(len(gtemp_34_phi), array.array(
"d", gtemp_34_phi), array.array(
"d", gtemp_34_val2),
3379 array.array(
"d", [0.] * len(gtemp_34_phi)), array.array(
"d", gtemp_34_err2))
3381 if len(gtemp_12_phi) > 0:
3382 gtemp_12.SetMarkerStyle(20); gtemp_12.SetMarkerSize(1.);
3383 gtemp_12.SetMarkerColor(ROOT.kBlue); gtemp_12.SetLineColor(ROOT.kBlue)
3384 gtemp2_12.SetMarkerStyle(24); gtemp2_12.SetMarkerSize(1.);
3385 gtemp2_12.SetMarkerColor(ROOT.kBlue); gtemp2_12.SetLineColor(ROOT.kBlue)
3386 if len(gtemp_23_phi) > 0:
3387 gtemp_23.SetMarkerStyle(21); gtemp_23.SetMarkerSize(1.);
3388 gtemp_23.SetMarkerColor(ROOT.kRed); gtemp_23.SetLineColor(ROOT.kRed)
3389 gtemp2_23.SetMarkerStyle(25); gtemp2_23.SetMarkerSize(1.);
3390 gtemp2_23.SetMarkerColor(ROOT.kRed); gtemp2_23.SetLineColor(ROOT.kRed)
3391 if len(gtemp_34_phi) > 0
and component[:4] ==
"dt13":
3392 gtemp_34.SetMarkerStyle(22); gtemp_34.SetMarkerSize(1.25);
3393 gtemp_34.SetMarkerColor(ROOT.kGreen+2); gtemp_34.SetLineColor(ROOT.kGreen+2)
3394 gtemp2_34.SetMarkerStyle(26); gtemp2_34.SetMarkerSize(1.25);
3395 gtemp2_34.SetMarkerColor(ROOT.kGreen+2); gtemp2_34.SetLineColor(ROOT.kGreen+2)
3397 if wheel == 0: htemp.SetTitle(
"Wheel %d" % wheel)
3398 else: htemp.SetTitle(
"Wheel %+d" % wheel)
3399 htemp.SetAxisRange(-window, window,
"Y")
3400 htemp.SetXTitle(
"Average #phi of pair (rad)")
3401 if component ==
"dt13_resid": htemp.SetYTitle(
"#Deltax^{local} (mm)")
3402 if component ==
"dt13_slope": htemp.SetYTitle(
"#Deltadx/dz^{local} (mrad)")
3403 if component ==
"dt2_resid": htemp.SetYTitle(
"#Deltay^{local} (mm)")
3404 if component ==
"dt2_slope": htemp.SetYTitle(
"#Deltady/dz^{local} (mrad)")
3405 htemp.GetXaxis().CenterTitle()
3406 htemp.GetYaxis().CenterTitle()
3407 htemp.GetYaxis().SetTitleOffset(0.75)
3411 if len(gtemp_12_phi) > 0:
3414 if len(gtemp_23_phi) > 0:
3417 if len(gtemp_34_phi) > 0:
3421 tlegend = ROOT.TLegend(0.5, 0.72, 0.9, 0.92)
3422 tlegend.SetBorderSize(0)
3423 tlegend.SetFillColor(ROOT.kWhite)
3424 if len(gtemp_12_phi) > 0:
3425 tlegend.AddEntry(gtemp_12,
"MB1 - MB2 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_12_val),
stdev(gtemp_12_val)),
"pl")
3426 if len(gtemp_23_phi) > 0:
3427 tlegend.AddEntry(gtemp_23,
"MB2 - MB3 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_23_val),
stdev(gtemp_23_val)),
"pl")
3428 if len(gtemp_34_phi) > 0:
3429 tlegend.AddEntry(gtemp_34,
"MB3 - MB4 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_34_val),
stdev(gtemp_34_val)),
"pl")
3430 if len(gtemp_12_phi) > 0:
3431 tlegend.AddEntry(gtemp_12,
"total mean: %4.2f, total RMS: %4.2f" % \
3432 (
mean(gtemp_12_val + gtemp_23_val + gtemp_34_val),
3433 stdev(gtemp_12_val + gtemp_23_val + gtemp_34_val)),
"")
3440 tdrStyle.SetOptTitle(1)
3441 tdrStyle.SetTitleBorderSize(1)
3442 tdrStyle.SetTitleFontSize(0.05)
3444 if not component[0:3] ==
"csc": Exception
3446 endcap = args[
"endcap"]
3453 else:
raise Exception
3455 station1 =
int(
str(pair)[0])
3456 station2 =
int(
str(pair)[1])
3457 if not station2-station1==1:
raise Exception
3460 if station2==4: rings = [1]
3463 global htemp, gtemp_1, gtemp2_1, gtemp_2, gtemp2_2, tlegend
3464 htemp = ROOT.TH1F(
"htemp",
"", 1, -pi*5./180., pi*(2.-5./180.))
3465 gtemp_1_phi, gtemp_1_val, gtemp_1_err, gtemp_1_val2, gtemp_1_err2 = [], [], [], [], []
3466 gtemp_2_phi, gtemp_2_val, gtemp_2_err, gtemp_2_val2, gtemp_2_err2 = [], [], [], [], []
3469 chambers = xrange(1,37)
3470 if ring == 1: chambers = xrange(1,19)
3472 for chamber
in chambers:
3473 phi, val, err, val2, err2, fit1, fit2, fit3 =
segdiff(tfiles, component, pair, endcap=endcap, ring=ring, chamber=chamber)
3474 if fit1
and fit2
and fit3:
3476 gtemp_1_phi.append(phi)
3477 gtemp_1_val.append(val)
3478 gtemp_1_err.append(err)
3479 gtemp_1_val2.append(val2)
3480 gtemp_1_err2.append(err2)
3482 gtemp_2_phi.append(phi)
3483 gtemp_2_val.append(val)
3484 gtemp_2_err.append(err)
3485 gtemp_2_val2.append(val2)
3486 gtemp_2_err2.append(err2)
3491 if len(gtemp_1_phi) > 0:
3492 gtemp_1 = ROOT.TGraphErrors(len(gtemp_1_phi), array.array(
"d", gtemp_1_phi), array.array(
"d", gtemp_1_val),
3493 array.array(
"d", [0.] * len(gtemp_1_phi)), array.array(
"d", gtemp_1_err))
3494 gtemp2_1 = ROOT.TGraphErrors(len(gtemp_1_phi), array.array(
"d", gtemp_1_phi), array.array(
"d", gtemp_1_val2),
3495 array.array(
"d", [0.] * len(gtemp_1_phi)), array.array(
"d", gtemp_1_err2))
3496 if len(gtemp_2_phi) > 0:
3497 gtemp_2 = ROOT.TGraphErrors(len(gtemp_2_phi), array.array(
"d", gtemp_2_phi), array.array(
"d", gtemp_2_val),
3498 array.array(
"d", [0.] * len(gtemp_2_phi)), array.array(
"d", gtemp_2_err))
3499 gtemp2_2 = ROOT.TGraphErrors(len(gtemp_2_phi), array.array(
"d", gtemp_2_phi), array.array(
"d", gtemp_2_val2),
3500 array.array(
"d", [0.] * len(gtemp_2_phi)), array.array(
"d", gtemp_2_err2))
3502 if len(gtemp_1_phi) > 0:
3503 gtemp_1.SetMarkerStyle(20); gtemp_1.SetMarkerSize(1.);
3504 gtemp_1.SetMarkerColor(ROOT.kBlue); gtemp_1.SetLineColor(ROOT.kBlue)
3505 gtemp2_1.SetMarkerStyle(24); gtemp2_1.SetMarkerSize(1.);
3506 gtemp2_1.SetMarkerColor(ROOT.kBlue); gtemp2_1.SetLineColor(ROOT.kBlue)
3507 if len(gtemp_2_phi) > 0:
3508 gtemp_2.SetMarkerStyle(21); gtemp_2.SetMarkerSize(1.);
3509 gtemp_2.SetMarkerColor(ROOT.kRed); gtemp_2.SetLineColor(ROOT.kRed)
3510 gtemp2_2.SetMarkerStyle(25); gtemp2_2.SetMarkerSize(1.);
3511 gtemp2_2.SetMarkerColor(ROOT.kRed); gtemp2_2.SetLineColor(ROOT.kRed)
3513 htemp.SetTitle(
"ME%s%d - ME%s%d" % (endcapsign,station2,endcapsign,station1))
3514 htemp.SetAxisRange(-window, window,
"Y")
3515 htemp.SetXTitle(
"Average #phi of pair (rad)")
3516 if component ==
"csc_resid": htemp.SetYTitle(
"#Delta(r#phi)^{local} (mm)")
3517 if component ==
"csc_slope": htemp.SetYTitle(
"#Deltad(r#phi)/dz^{local} (mrad)")
3518 htemp.GetXaxis().CenterTitle()
3519 htemp.GetYaxis().CenterTitle()
3520 htemp.GetYaxis().SetTitleOffset(0.75)
3524 if len(gtemp_1_phi) > 0:
3527 if len(gtemp_2_phi) > 0:
3531 tlegend = ROOT.TLegend(0.5, 0.72, 0.9, 0.92)
3532 tlegend.SetBorderSize(0)
3533 tlegend.SetFillColor(ROOT.kWhite)
3534 if len(gtemp_1_phi) > 0:
3535 tlegend.AddEntry(gtemp_1,
"ring 1 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_1_val),
stdev(gtemp_1_val)),
"pl")
3536 if len(gtemp_2_phi) > 0:
3537 tlegend.AddEntry(gtemp_2,
"ring 2 (mean: %4.2f, RMS: %4.2f)" % (
mean(gtemp_2_val),
stdev(gtemp_2_val)),
"pl")
3550 def corrections2D(reportsX=None, reportsY=None, geometry0=None, geometryX=None, geometryY=None,
3551 window=25., selection=
None, name=
"tmp", canvas=
None, pre_title_x=
None, pre_title_y=
None,
3554 tdrStyle.SetOptStat(0)
3555 tdrStyle.SetStatW(0.40)
3559 check_reports =
False 3560 if reportsX
is not None and reportsY
is not None:
3562 check_reports =
True 3563 if geometry0
is not None and geometryX
is not None and geometryY
is not None:
3566 print(
"Either couple of reports or three geometries have to be given as input. Exiting...")
3571 wnd_adaptive = [.1]*6
3573 global hx, hy, hz, hphix, hphiy, hphiz
3575 hx = ROOT.TH2F(
"%s_x" % name,
"", bins, -wnd[0], wnd[0], bins, -wnd[0], wnd[0])
3576 hy = ROOT.TH2F(
"%s_y" % name,
"", bins, -wnd[1], wnd[1], bins, -wnd[1], wnd[1])
3577 hz = ROOT.TH2F(
"%s_z" % name,
"", bins, -wnd[2], wnd[2], bins, -wnd[2], wnd[2])
3578 hphix = ROOT.TH2F(
"%s_phix" % name,
"", bins, -wnd[3], wnd[3], bins, -wnd[3], wnd[3])
3579 hphiy = ROOT.TH2F(
"%s_phiy" % name,
"", bins, -wnd[4], wnd[4], bins, -wnd[4], wnd[4])
3580 hphiz = ROOT.TH2F(
"%s_phiz" % name,
"", bins, -wnd[5], wnd[5], bins, -wnd[5], wnd[5])
3581 hhh = [hx, hy, hz, hphix, hphiy, hphiz]
3584 global pca_x, pca_y, pca_z, pca_phix, pca_phiy, pca_phiz
3585 pca_x = ROOT.TPrincipal(2,
"D")
3586 pca_y = ROOT.TPrincipal(2,
"D")
3587 pca_z = ROOT.TPrincipal(2,
"D")
3588 pca_phix = ROOT.TPrincipal(2,
"D")
3589 pca_phiy = ROOT.TPrincipal(2,
"D")
3590 pca_phiz = ROOT.TPrincipal(2,
"D")
3591 pcas = [pca_x, pca_y, pca_z, pca_phix, pca_phiy, pca_phiz]
3594 ax=[]; ay=[]; az=[]; aphix=[]; aphiy=[]; aphiz=[]
3595 aaa = [ax, ay, az, aphix, aphiy, aphiz]
3598 postal_addresses = []
3604 if r1.postal_address[0]==
'CSC' and r1.postal_address[2]==1
and r1.postal_address[3]==4:
continue 3605 if selection
is None or (selection.__code__.co_argcount == len(r1.postal_address)
and selection(*r1.postal_address)):
3608 print(
"bad r2 in ",r1.postal_address)
3611 if r1.status !=
"PASS" or r2.status !=
"PASS":
3612 print(
"bad status", r1.postal_address, r1.status, r2.status)
3614 postal_addresses.append(r1.postal_address)
3617 for key
in geometry0.dt.keys():
3618 if len(key)==3
and key
in geometryX.dt
and key
in geometryY.dt:
3619 postal_addresses.append( tuple([
'DT'] +
list(key)) )
3620 for key
in geometry0.csc.keys():
3622 if key[2]==1
and key[3]==4:
continue 3623 if len(key)==4
and key
in geometryX.csc
and key
in geometryY.csc:
3624 postal_addresses.append( tuple([
'CSC'] +
list(key)) )
3627 for addr
in postal_addresses:
3630 if not (selection
is None or (selection.__code__.co_argcount == len(addr)
and selection(*addr)) ):
continue 3632 factors = [10. * signConventions[addr][0], 10. * signConventions[addr][1], 10. * signConventions[addr][2],
3633 1000., 1000., 1000. ]
3638 deltasX = [rX.deltax, rX.deltay, rX.deltaz, rX.deltaphix, rX.deltaphiy, rX.deltaphiz]
3639 deltasY = [rY.deltax, rY.deltay, rY.deltaz, rY.deltaphix, rY.deltaphiy, rY.deltaphiz]
3641 if mode ==
"reports":
3643 checks =
map(
lambda d1, d2: d1
is not None and d2
is not None and d1.error
is not None \
3644 and d2.error
is not None and (d1.error**2 + d2.error**2) > 0. , \
3647 for i
in range(len(checks)):
3648 if not checks[i]:
continue 3649 fillX = deltasX[i].value * factors[i]
3650 fillY = deltasY[i].value * factors[i]
3651 aaa[i].
append([fillX,fillY])
3652 pcas[i].AddRow(array.array(
'd',[fillX,fillY]))
3654 if mx > wnd_adaptive[i]: wnd_adaptive[i] = mx
3658 db0 = dbX = dbY =
None 3660 db0, dbX, dbY = geometry0.dt[addr[1:]], geometryX.dt[addr[1:]], geometryY.dt[addr[1:]]
3661 if addr[0] ==
'CSC':
3662 db0, dbX, dbY = geometry0.csc[addr[1:]], geometryX.csc[addr[1:]], geometryY.csc[addr[1:]]
3666 checks =
map(
lambda d1, d2: d1
is not None and d2
is not None , deltasX, deltasY)
3668 gdeltas0 = [db0.x, db0.y, db0.z, db0.phix, db0.phiy, db0.phiz]
3669 gdeltasX = [dbX.x, dbX.y, dbX.z, dbX.phix, dbX.phiy, dbX.phiz]
3670 gdeltasY = [dbY.x, dbY.y, dbY.z, dbY.phix, dbY.phiy, dbY.phiz]
3672 for i
in range(len(checks)):
3673 if not checks[i]:
continue 3674 fillX = (gdeltasX[i] - gdeltas0[i]) * factors[i]
3675 fillY = (gdeltasY[i] - gdeltas0[i]) * factors[i]
3676 aaa[i].
append([fillX,fillY])
3677 pcas[i].AddRow(array.array(
'd',[fillX,fillY]))
3679 if mx > wnd_adaptive[i]: wnd_adaptive[i] = mx
3685 if pre_title_x
is None: pre_title_x =
"geometry 1 " 3686 if pre_title_y
is None: pre_title_y =
"geometry 2 " 3687 if mode ==
"reports":
3688 if pre_title_x
is None: pre_title_x =
"iteration's " 3689 if pre_title_y
is None: pre_title_y =
"other iteration's " 3690 tmptitles = [
"#Deltax (mm)",
"#Deltay (mm)",
"#Deltaz (mm)",
3691 "#Delta#phi_{x} (mrad)",
"#Delta#phi_{y} (mrad)",
"#Delta#phi_{z} (mrad)"]
3693 for t
in tmptitles: htitles.append([pre_title_x + t, pre_title_y + t])
3695 if canvas
is not None: c = canvas
3698 ndraw = which.count(
'1')
3699 if ndraw > 4: c.Divide(3, 2)
3700 elif ndraw > 2: c.Divide(2, 2)
3701 elif ndraw > 1: c.Divide(2, 1)
3703 global lines, graphs, texs
3704 lines = []; graphs = []; texs = []
3710 if (
int(which,2) & (1<<i) ) == 0:
continue 3714 c.GetPad(ipad).SetGridx(1)
3715 c.GetPad(ipad).SetGridy(1)
3717 wn = 1.08 * wnd_adaptive[i]
3718 hhh[i].GetXaxis().SetRangeUser(-wn, wn)
3719 hhh[i].GetYaxis().SetRangeUser(-wn, wn)
3720 hhh[i].SetXTitle(htitles[i][0])
3721 hhh[i].SetYTitle(htitles[i][1])
3722 hhh[i].GetXaxis().CenterTitle()
3723 hhh[i].GetYaxis().CenterTitle()
3726 if len(aaa[i]) == 0:
continue 3728 a1, a2 =
map(
lambda x: array.array(
'd',x),
list(
zip(*aaa[i])) )
3729 g = ROOT.TGraph(len(a1), a1, a2)
3731 g.SetMarkerSize(0.3)
3732 g.SetMarkerColor(ROOT.kBlue)
3735 pcas[i].MakePrincipals()
3738 b = pcas[i].GetEigenVectors()(1,0) / pcas[i].GetEigenVectors()(0,0)
3739 a = pcas[i].GetMeanValues()[1] - b * pcas[i].GetMeanValues()[0]
3742 cov = pcas[i].GetCovarianceMatrix()
3743 r = cov(0,1)/
sqrt(cov(1,1)*cov(0,0))
3744 print(
"r, RMSx, RMSy =", r, g.GetRMS(1), g.GetRMS(2))
3745 texrms = ROOT.TLatex(0.17,0.87,
"RMS x,y = %.02g, %.02g" % (g.GetRMS(1),g.GetRMS(2)))
3746 texr = ROOT.TLatex(0.17,0.80,
"r = %.02g" % r)
3747 for t
in texr, texrms:
3749 t.SetTextColor(ROOT.kBlue)
3750 t.SetTextSize(0.053)
3757 wn = wnd_adaptive[i]
3758 line = ROOT.TLine(-wn, a - b*wn, wn, a + b*wn)
3759 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)
S & print(S &os, JobReport::InputFile const &f)
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")