21 r.PyConfig.IgnoreCommandLineOptions =
True
22 r.gStyle.SetPadTickX(1)
23 r.gStyle.SetPadTickY(1)
32 repv = r.Math.RhoEtaPhiVector
33 xyzv = r.Math.XYZVector
35 sectorDphi = 2.0*math.pi/16.
36 sin, cos, tan, atan, exp = math.sin, math.cos, math.tan, math.atan, math.exp
38 def average(lst) :
return sum(lst)/len(lst)
43 return r*
cos(phi), r*
sin(phi)
44 def tuple2vec(tpl) :
return xyzv(tpl[0], tpl[1], tpl[2])
48 Use the kargs trick to set all the attributes except the ones
49 that are my classes, and not basic types. See for example:
50 http://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python
53 for k,v
in kargs.iteritems() : setattr(self, k, v)
57 super(PadWithHits, self).
__init__(**kargs)
67 def color(layer) :
return [r.kBlack, r.kRed, r.kBlue, r.kViolet, r.kGreen][layer]
68 def width(isPivot) :
return 2
if isPivot
else 1
71 def setFont(self, font) : self.font = font
72 def isPivot(self) :
return self.multiplet
in [0,2]
74 "Rotate a vector to sector5 coordinates (note: delta phi depends only on the sector)"
76 return repv(vec.rho(), vec.eta(), vec.phi()).SetPhi(vec.phi() - deltaPhi)
92 return min(phis),
max(phis)
94 def draw(self, view='yx') :
101 segments, lines = [], []
103 if view==
'yx' : segments = [(corners[i], corners[j])
for i,j
in [(0, 1), (1, 3), (2, 3), (0, 2)]]
104 elif view==
'hz' : segments = [(corners[i], corners[j])
for i,j
in [(0, 1)]]
105 elif view==
'zphi' : segments = [(corners[i], corners[j])
for i,j
in [(0, 2)]]
107 if view==
'yx' : lines = [
l(p1.x(), p1.y(), p2.x(), p2.y())
for p1,p2
in segments]
108 elif view==
'hz' : lines = [
l(p1.z(), p1.y(), p2.z(), p2.y())
for p1,p2
in segments]
109 elif view==
'zphi' : lines = [
l(p1.phi(), p1.z(), p2.phi(), p2.z())
for p1,p2
in segments]
111 l.SetLineColor(lineColor)
112 l.SetLineWidth(lineWidth)
118 if view
not in [
'hz',
'zphi'] :
return
119 coord = {
'hz':
'ieta',
'zphi':
'iphi'}[view]
120 leftOrRight = self.layer%2
121 angle = 90.
if view==
'hz' else 0.
122 xs =
sorted([line.GetX1(), line.GetX2()], reverse=leftOrRight)
123 ys =
sorted([line.GetY1(), line.GetY2()], reverse=leftOrRight)
124 def outside(xx) :
return xx[1] + 0.75*(xx[1]-xx[0])
127 text = r.TLatex(x, y,
"%d" % getattr(self, coord))
128 text.SetTextAlign(22)
129 text.SetTextAngle(angle)
130 text.SetTextColor(line.GetLineColor())
131 if hasattr(self,
'font') : text.SetTextFont(self.
font)
138 if view==
'yx' : x, y = v.x(), v.y()
139 elif view==
'hz' : x, y = v.z(), v.y()
140 elif view==
'zphi' : x, y = v.phi(), v.z()
141 marker = r.TMarker(x, y, r.kMultiply)
142 marker.SetMarkerColor(color)
146 def drawCloud() :
print 'drawCloud not implemented yet'
147 if len(self.hitIndices)>1 : drawCloud()
153 super(SingleWedgePadTrigger, self).
__init__(**kargs)
156 for p
in self.
pads : p.setFont(font)
159 def sector(self) :
return self.pads[0].sector
161 for p
in self.
pads : p.draw(view)
163 values = [getattr(p, pname)
for p
in self.
pads for pname
in parNames]
164 return min(values),
max(values)
177 text = r.TLatex( x, y,
'')
179 if hasattr(self,
'font') : text.SetTextFont(self.
font)
182 text.DrawLatex(x, y,
"Sector %d"%self.
sector())
184 text.DrawLatex(x, y, ((
'Pivot' if self.
isPivot()
else '') +
185 (
'Confirm' if self.
isConfirm()
else '') +
186 ", %d/4"%len(self.
pads) +
189 ieta, iphi = self.halfPadIndices
190 text.DrawLatex(x, y,
"Half-pad indices : (%d, %d)"%(ieta, iphi))
198 super(SectorTriggerCandidate, self).
__init__(**kargs)
208 xVar, yVar = self.
xVars[view], self.
yVars[view]
209 marginX = dict(zip(possibleViews, [20*cm, 20*cm, math.pi/32]))[view]
210 marginY = dict(zip(possibleViews, [10*cm, 20*cm, 10*cm] ))[view]
213 xMin, xMax = xMin-marginX, xMax+marginX
214 yMin, yMax = yMin-marginY, yMax+marginY
216 padMaster.GetXaxis().SetRangeUser(xMin, xMax)
217 padMaster.GetYaxis().SetRangeUser(yMin, yMax)
218 self.
setFont(padMaster.GetTitleFont())
219 def draw(self, padMaster, view='yx', onlyPivot=False, onlyConfirm=False) :
221 assert view
in possibleViews,
"Invalid view %s"%view
222 xVar = dict(zip(possibleViews, [
'x',
'z',
'phi']))[view]
223 yVar = dict(zip(possibleViews, [
'y',
'h',
'z'] ))[view]
224 gridX = dict(zip(possibleViews, [0, 0, 1] ))[view]
225 gridY = dict(zip(possibleViews, [0, 1, 0] ))[view]
227 r.gPad.SetGridx(gridX)
228 r.gPad.SetGridy(gridY)
229 wedgeTrigs = [w
for w
in self.
wedgeTrigs if (
not (onlyConfirm
or onlyPivot)
or
230 (onlyConfirm
and w.isConfirm())
or
231 (onlyPivot
and w.isPivot()))]
232 for w
in wedgeTrigs : w.draw(view)
236 minMaxVals = [w.minMaxPadVar(var)
for w
in self.
wedgeTrigs]
237 mins, maxs = [m[0]
for m
in minMaxVals], [m[1]
for m
in minMaxVals]
238 return min(mins),
max(maxs)
240 if view!=
'yx' :
return
241 xMin, xMax = padMaster.GetXaxis().GetXmin(), padMaster.GetXaxis().GetXmax()
242 yMin, yMax = padMaster.GetYaxis().GetXmin(), padMaster.GetYaxis().GetXmax()
243 x, y, dy = 0.125, 0.85, -0.05
244 for w
in wedgeTriggers : y = w.drawLabelsLeft(x, y, dy)
246 (xMin, xMax), (yMin, yMax) = xyRanges
247 def topTwelwthRange(vMin, vMax) :
return vMax-(vMax-vMin)/12.0, vMax
248 xMin, xMax = topTwelwthRange(xMin, xMax)
249 yMin, yMax = topTwelwthRange(yMin, yMax)
250 hdx, hdy = 0.5*(xMax-xMin), 0.5*(yMax-yMin)
251 R = math.sqrt(hdx*hdx +hdy*hdy)
253 minPhi, maxPhi = math.degrees(midPhi-0.5*sectorDphi), math.degrees(midPhi+0.5*sectorDphi)
254 circle = r.TEllipse(0.5*(xMin+xMax), 0.5*(yMin+yMax), R, R)
255 circle.SetLineColor(r.kBlack)
256 circle.SetFillStyle(0)
258 slice = r.TCrown(0.5*(xMin+xMax), 0.5*(yMin+yMax), 0.2*R, 1.0*R, minPhi, maxPhi)
259 slice.SetFillColor(r.kBlack)
260 slice.SetFillStyle(1001)
268 if __name__==
'__main__' :
270 filename = sys.argv[1]
272 outputBaseName = os.path.splitext(filename)[0]
273 print "found %d sector trigger candidates"%len(candidates)
274 xRangeMin, xRangeMax = -500*cm, +500*cm
275 yRangeMin, yRangeMax = -500*cm, +500*cm
276 zRangeMin, zRangeMax = -800*cm, +800*cm
277 hRangeMin, hRangeMax = 0*cm, yRangeMax
278 phiRangeMin, phiRangeMax = -2*math.pi, +2*math.pi
279 padMasterYx = r.TH2F(
'padMasterYx',
';x [mm]; y [mm]', 200, xRangeMin, xRangeMax, 200, yRangeMin, yRangeMax)
280 padMasterHz = r.TH2F(
'padMasterHz',
';z [mm]; h [mm]', 200, zRangeMin, zRangeMax, 200, hRangeMin, hRangeMax)
281 padMasterZphi = r.TH2F(
'padMasterZphi',
';phi [rad];z [mm]', 200, phiRangeMin, phiRangeMax, 200, zRangeMin, zRangeMax)
282 can = r.TCanvas(
'can')
285 h.GetXaxis().CenterTitle()
286 h.GetYaxis().CenterTitle()
287 for h
in [padMasterYx, padMasterHz, padMasterZphi] :
formatPadMaster(h)
288 for i,c
in enumerate(candidates) :
294 view, padMaster =
'zphi', padMasterZphi
295 sCan.adjustRanges(padMaster, view)
296 sCan.draw(padMaster, view)
299 view, padMaster =
'hz', padMasterHz
300 sCan.adjustRanges(padMaster, view)
301 sCan.draw(padMaster, view)
303 view, padMaster =
'yx', padMasterYx
304 sCan.adjustRanges(padMaster, view)
306 sCan.draw(padMaster, view, onlyPivot=
True)
308 sCan.draw(padMaster, view, onlyConfirm=
True)
310 can.SaveAs(
"%s_%03d.png"%(outputBaseName, i))