1 from __future__
import absolute_import
2 from __future__
import print_function
4 from builtins
import range
9 from .TkAlStyle
import TkAlStyle
11 dirNameList=[
"z",
"r",
"phi"]
12 detNameList = (
"BPIX",
"FPIX",
"TIB",
"TID",
"TOB",
"TEC")
14 if (subdet+1 == 1
and (module == 1
or overlap ==1))
or (subdet+1== 2
and (module == 0
or overlap == 0))
or ((subdet+1== 3
or subdet+1== 5)
and (overlap != 2
or module == 1))
or ((subdet+1== 4
or subdet+1== 6)
and (overlap != 2
or module == 0)):
18 def hist(tree_file_name, hist_name,subdet_ids,module_directions,overlap_directions,profile_directions):
19 f = ROOT.TFile(tree_file_name)
20 t = f.Get(
"analysis/Overlaps")
22 for subdet
in range(6):
24 for module
in range(3):
26 for overlap
in range(3):
27 h[subdet][module].
append([])
28 for profile
in range(4):
29 if subdetConditon(subdet,module,overlap):
30 h[subdet][module][overlap].
append(0)
32 name = hist_name +
"{0}_{1}_{2}".
format(dirNameList[module],dirNameList[overlap],detNameList[subdet])
33 if not ((subdet_ids[subdet])
and (module_directions[module])
and (profile_directions[profile])
and overlap_directions[overlap]):
34 h[subdet][module][overlap].
append(0)
37 if profile == 3: bins, xmin, xmax = 10, -math.pi, math.pi
38 if subdet+1 == 1
and profile == 1: bins, xmin, xmax = 10, -30, -30
39 if subdet+1 == 2
and profile == 1: bins, xmin, xmax = 40, -60, 60
40 if subdet+1 == 3
and profile == 1: bins, xmin, xmax = 10, -70, 70
41 if subdet+1 == 4
and profile == 1: bins, xmin, xmax = 40, -110, 110
42 if subdet+1 == 5
and profile == 1: bins, xmin, xmax = 10, -110, 110
43 if subdet+1 == 6
and profile == 1: bins, xmin, xmax = 20, -280, 280
44 if subdet+1 == 1
and profile == 2: bins, xmin, xmax = 10, 0, 20
45 if subdet+1 == 2
and profile == 2: bins, xmin, xmax = 10, 0, 20
46 if subdet+1 == 3
and profile == 2: bins, xmin, xmax = 10, 20, 55
47 if subdet+1 == 4
and profile == 2: bins, xmin, xmax = 10, 20, 55
48 if subdet+1 == 5
and profile == 2: bins, xmin, xmax = 10, 55, 110
49 if subdet+1 == 6
and profile == 2: bins, xmin, xmax = 10, 20, 110
50 h[subdet][module][overlap].
append(ROOT.TProfile(hist_name, hist_name, bins, xmin, xmax))
51 elif subdet+1==4
or subdet+1==6:
52 h[subdet][module][overlap].
append(ROOT.TH1F(name, name, 100, -5000, 5000))
54 h[subdet][module][overlap].
append(ROOT.TH1F(name, name, 100, -300, 300))
55 h[subdet][module][overlap][profile].SetDirectory(0)
57 nentries = t.GetEntries()
59 for i, entry
in enumerate(t, start=1):
60 if i % 10000 == 0
or i == nentries:
61 print(i,
"/", nentries)
63 subdet_id = t.subdetID
64 if subdet_ids[subdet_id-1]==
False:
67 modulePhi0 = math.atan2(t.moduleY[0], t.moduleX[0])
68 modulePhi1 = math.atan2(t.moduleY[1], t.moduleX[1])
69 phidiff =
min(
abs(modulePhi0-modulePhi1),
abs(math.pi -
abs(modulePhi0-modulePhi1)))
70 moduleR0 = math.sqrt(t.moduleY[0]**2+t.moduleX[0]**2)
71 moduleR1 = math.sqrt(t.moduleY[1]**2+t.moduleX[1]**2)
74 if subdet_id%2 == 1
and ((
abs(t.moduleZ[0] - t.moduleZ[1]) > 1)):
76 elif subdet_id%2 == 0
and (
abs(moduleR0 - moduleR1)>1):
78 elif ((moduleR0*phidiff)>1):
83 if module_directions[module_direction]==
False:
85 avgList=[(t.moduleZ[0]+t.moduleZ[1])/2,(moduleR0+moduleR1)/2,(modulePhi0+modulePhi1)/2]
86 if overlap_directions[2]:
88 if modulePhi0 > modulePhi1:
93 overlapSignA = t.localxdotglobalphi[1]
94 overlapSignB = t.localxdotglobalphi[0]
100 overlapSignA = t.localxdotglobalphi[0]
101 overlapSignB = t.localxdotglobalphi[1]
102 residualA = hitXA - predXA
103 residualB = hitXB - predXB
108 A = 10000*(residualA - residualB)
109 h[subdet_id-1][module_direction][overlap_direction][0].
Fill(A)
110 for profile
in range(3):
111 if profile_directions[profile+1]:
112 h[subdet_id-1][module_direction][overlap_direction][profile+1].
Fill(avgList[profile],A)
115 if subdet_id==1
and module_direction != 1
and overlap_directions[0]:
116 overlap_direction = 0
117 if t.moduleZ[0] > t.moduleZ[1]:
122 overlapSignA = t.localydotglobalz[1]
123 overlapSignB = t.localydotglobalz[0]
129 overlapSignA = t.localydotglobalz[0]
130 overlapSignB = t.localydotglobalz[1]
131 residualA = hitXA - predXA
132 residualB = hitXB - predXB
137 A = 10000*(residualA - residualB)
138 h[subdet_id-1][module_direction][overlap_direction][0].
Fill(A)
139 for profile
in range(3):
140 if profile_directions[profile+1]:
141 h[subdet_id-1][module_direction][overlap_direction][profile+1].
Fill(avgList[profile],A)
143 if subdet_id==2
and module_direction !=0
and overlap_directions[1]:
144 overlap_direction = 1
145 if moduleR0 > moduleR1:
150 overlapSignA = t.localydotglobalr[1]
151 overlapSignB = t.localydotglobalr[0]
157 overlapSignA = t.localydotglobalr[0]
158 overlapSignB = t.localydotglobalr[1]
160 residualA = hitXA - predXA
161 residualB = hitXB - predXB
166 A = 10000*(residualA - residualB)
167 h[subdet_id-1][module_direction][overlap_direction][0].
Fill(A)
168 for profile
in range(3):
169 if profile_directions[profile+1]:
170 h[subdet_id-1][module_direction][overlap_direction][profile+1].
Fill(avgList[profile],A)
173 def plot(file_name,subdet_ids,module_directions,overlap_directions,profile_directions,*filesTitlesColorsStyles):
178 for subdet
in range(6):
181 for module
in range(3):
184 for overlap
in range(3):
185 hstack[subdet][module].
append([])
186 legend[subdet][module].
append([])
187 for profile
in range(4):
189 hstack[subdet][module][overlap].
append(0)
190 legend[subdet][module][overlap].
append(0)
192 if not ((subdet_ids[subdet])
and (module_directions[module])
and (profile_directions[profile])
and overlap_directions[overlap]):
193 legend[subdet][module][overlap].
append(0)
194 hstack[subdet][module][overlap].
append(0)
197 hstack[subdet][module][overlap].
append(ROOT.THStack(
"hstack",
""))
199 legend[subdet][module][overlap][profile].SetBorderSize(0)
200 legend[subdet][module][overlap][profile].SetFillStyle(0)
201 for files, title, color, style
in filesTitlesColorsStyles:
202 h =
hist(files,files.replace(
"/",
""),subdet_ids,module_directions,overlap_directions,profile_directions)
203 for subdet
in range(6):
204 for module
in range(3):
205 for overlap
in range(3):
208 for profile
in range(4):
209 if not((subdet_ids[subdet])
and (module_directions[module])
and (profile_directions[profile])
and overlap_directions[overlap]):
211 g = h[subdet][module][overlap][profile]
212 g.SetLineColor(color)
213 g.SetLineStyle(style)
215 hMeanError = g.GetMeanError(1)
217 legend[subdet][module][overlap][profile].AddEntry(g, title +
", mean = {0}#pm{1}#mum ".
format(round(hMean,3),round(hMeanError,3)),
"l")
218 g.Scale(1 / g.Integral())
220 legend[subdet][module][overlap][profile].AddEntry(g, title,
"l")
221 hstack[subdet][module][overlap][profile].Add(g)
222 for subdet
in range(6):
223 for module
in range(3):
224 for overlap
in range(3):
227 for profile
in range(4):
228 if not((subdet_ids[subdet])
and (module_directions[module])
and (profile_directions[profile])
and overlap_directions[overlap]):
230 currLegend = legend[subdet][module][overlap][profile]
231 currhstack = hstack[subdet][module][overlap][profile]
232 currhstack.SetMaximum(currhstack.GetMaximum(
"nostack") * 1.2)
234 currhstack.Draw(
"hist nostack" if profile == 0
else "nostack")
236 xTitle =
"hit_{A} - pred_{A} - (hit_{B} - pred_{B}) (#mum)"
237 yTitle=
"fraction of events"
238 save_as_file_name = file_name +
"{0}_{1}_{2}".
format(dirNameList[module],dirNameList[overlap],detNameList[subdet])
240 save_as_file_name = file_name +
"Profiles/profile_{0}_{1}_{2}_{3}".
format(dirNameList[module],dirNameList[overlap],detNameList[subdet],dirNameList[profile-1])
242 xTitle= dirNameList[profile-1]
243 currhstack.GetXaxis().SetTitle(xTitle)
244 currhstack.GetYaxis().SetTitle(yTitle)
246 currhstack.GetXaxis().SetNdivisions(404)
250 for ext
in "png",
"eps",
"root",
"pdf":
251 c.SaveAs(save_as_file_name+
"." +ext)