SND@LHC Software
Loading...
Searching...
No Matches
eventDisplay_shipLHC.DrawTracks Class Reference
Inheritance diagram for eventDisplay_shipLHC.DrawTracks:
Collaboration diagram for eventDisplay_shipLHC.DrawTracks:

Public Member Functions

 InitTask (self)
 
 FinishEvent (self)
 
 ExecuteTask (self, option='')
 
 DrawParticle (self, n)
 
 DrawMCTrack (self, n)
 
 DrawMCTracks (self, option='')
 
 DrawSimpleMCTracks (self)
 
 DrawFittedTracks (self, option='')
 

Public Attributes

 comp
 
 trackColors
 
 z_start
 
 evscene
 
 Targetz
 
 niter
 

Detailed Description

Definition at line 92 of file eventDisplay_shipLHC.py.

Member Function Documentation

◆ DrawFittedTracks()

eventDisplay_shipLHC.DrawTracks.DrawFittedTracks (   self,
  option = '' 
)

Definition at line 268 of file eventDisplay_shipLHC.py.

268 def DrawFittedTracks(self,option=''):
269 n,ntot = -1,0
270 for fT in sTree.FitTracks:
271 n+=1
272 fst = fT.getFitStatus()
273 if not fst.isFitConverged(): continue
274 if fst.getNdf() < 20: continue
275 DTrack = ROOT.TEveLine()
276 DTrack.SetPickable(ROOT.kTRUE)
277 DTrack.SetTitle(fT.__repr__())
278 fstate = fT.getFittedState(0)
279 fPos = fstate.getPos()
280 fMom = fstate.getMom()
281 pos = fPos
282 mom = fMom
283 pid = fstate.getPDG()
284 zs = self.z_start
285 before = True
286 for i in range(self.niter):
287 rc,newpos,newmom = TrackExtrapolateTool.extrapolateToPlane(fT,zs)
288 if rc:
289 DTrack.SetNextPoint(newpos.X(),newpos.Y(),newpos.Z())
290 else:
291 print('error with extrapolation: z=',zs)
292 # use linear extrapolation
293 px,py,pz = mom.X(),mom.Y(),mom.Z()
294 lam = (zs-pos.Z())/pz
295 DTrack.SetNextPoint(pos.X()+lam*px,pos.Y()+lam*py,zs)
296 zs+=self.dz
297 DTrack.SetName('FitTrack_'+str(n))
298 c = ROOT.kWhite
299 if abs(pid) in self.trackColors : c = self.trackColors[abs(pid)]
300 DTrack.SetMainColor(c)
301 DTrack.SetLineWidth(3)
302 self.comp.AddElement(DTrack)
303 ntot+=1
304 print("draw ",ntot," fitted tracks")
305 n=-1
306 for aP in sTree.Particles:
307 n+=1
308# check fitted tracks
309 tracksOK = True
310 if aP.GetMother(1)==99: # DOCA is set
311 if aP.T()>3*u.cm : continue
312 for k in range(aP.GetNDaughters()):
313 if k>1: break # we don't have more than 2tracks/vertex yet, no idea why ROOT sometimes comes up with 4!
314 fT = sTree.FitTracks[aP.GetDaughter(k)]
315 fst = fT.getFitStatus()
316 if not fst.isFitConverged(): tracksOK=False
317 if fst.getNdf() < 20: tracksOK=False
318 if not tracksOK: continue
319 DTrack = ROOT.TEveLine()
320 DTrack.SetPickable(ROOT.kTRUE)
321 DTrack.SetMainColor(ROOT.kCyan)
322 DTrack.SetLineWidth(4)
323 DTrack.SetName('Particle_'+str(n))
324 DTrack.SetTitle(aP.__repr__())
325 DTrack.SetNextPoint(aP.Vx(),aP.Vy(),aP.Vz())
326 lam = (self.Targetz - aP.Vz())/aP.Pz()
327 DTrack.SetNextPoint(aP.Vx()+lam*aP.Px(),aP.Vy()+lam*aP.Py(),self.Targetz)
328 self.comp.AddElement(DTrack)
329#

◆ DrawMCTrack()

eventDisplay_shipLHC.DrawTracks.DrawMCTrack (   self,
  n 
)

Definition at line 130 of file eventDisplay_shipLHC.py.

130 def DrawMCTrack(self,n):
131 self.comp.OpenCompound()
132 fT = sTree.MCTrack[n]
133 DTrack = ROOT.TEveLine()
134 DTrack.SetPickable(ROOT.kTRUE)
135 DTrack.SetTitle(fT.__repr__())
136 p = pdg.GetParticle(fT.GetPdgCode())
137 if p : pName = p.GetName()
138 else: pName = str(fT.GetPdgCode())
139 DTrack.SetName('MCTrck_'+str(n)+'_'+pName)
140 fPos = ROOT.TVector3()
141 fMom = ROOT.TVector3()
142 fT.GetStartVertex(fPos)
143 fT.GetMomentum(fMom)
144# check for end vertex
145 evVx = False
146 for da in sTree.MCTrack:
147 if da.GetMotherId()==n:
148 evVx = True
149 break
150 DTrack.SetNextPoint(fPos.X(),fPos.Y(),fPos.Z())
151 if evVx and abs( da.GetStartZ()-fPos.Z() )>1*u.cm :
152 DTrack.SetNextPoint(da.GetStartX(),da.GetStartY(),da.GetStartZ())
153 else:
154 zEx = 10*u.m
155 if evVx : zEx = -10*u.m
156 lam = (zEx+fPos.Z())/fMom.Z()
157 DTrack.SetNextPoint(fPos.X()+lam*fMom.X(),fPos.Y()+lam*fMom.Y(),zEx+fPos.Z())
158 c = ROOT.kYellow
159 DTrack.SetMainColor(c)
160 DTrack.SetLineWidth(3)
161 self.comp.AddElement(DTrack)
162 self.comp.CloseCompound()
163 gEve.ElementChanged(self.evscene,True,True)

◆ DrawMCTracks()

eventDisplay_shipLHC.DrawTracks.DrawMCTracks (   self,
  option = '' 
)

Definition at line 164 of file eventDisplay_shipLHC.py.

164 def DrawMCTracks(self,option=''):
165 n = -1
166 ntot = 0
167 fPos = ROOT.TVector3()
168 fMom = ROOT.TVector3()
169 for fT in sTree.MCTrack:
170 n+=1
171 DTrack = ROOT.TEveLine()
172 DTrack.SetPickable(ROOT.kTRUE)
173 DTrack.SetTitle(fT.__repr__())
174 fT.GetStartVertex(fPos)
175 hitlist = {}
176 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
177 # look for HNL
178 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
179 for da in sTree.MCTrack:
180 if da.GetMotherId()==n: break
181 # end vertex of HNL
182 da.GetStartVertex(fPos)
183 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
184 # loop over all sensitive volumes to find hits
185 for P in ["EmulsionDetPoint","ScifiPoint"]:
186 if not sTree.GetBranch(P): continue
187 c=eval("sTree."+P)
188 for p in c:
189 if p.GetTrackID()==n:
190 if hasattr(p, "LastPoint"):
191 lp = p.LastPoint()
192 if lp.x()==lp.y() and lp.x()==lp.z() and lp.x()==0:
193# must be old data, don't expect hit at 0,0,0
194 hitlist[p.GetZ()] = [p.GetX(),p.GetY()]
195 else:
196 hitlist[lp.z()] = [lp.x(),lp.y()]
197 hitlist[2.*p.GetZ()-lp.z()] = [2.*p.GetX()-lp.x(),2.*p.GetY()-lp.y()]
198 else:
199 hitlist[p.GetZ()] = [p.GetX(),p.GetY()]
200 if len(hitlist)==1:
201 if fT.GetMotherId()<0: continue
202 if abs(sTree.MCTrack[fT.GetMotherId()].GetPdgCode()) == options.HiddenParticleID:
203 # still would like to draw track stub
204 # check for end vertex
205 evVx = False
206 for da in sTree.MCTrack:
207 if da.GetMotherId()==n:
208 evVx = True
209 break
210 if evVx : hitlist[da.GetStartZ()] = [da.GetStartX(),da.GetStartY()]
211 else :
212 zEx = 10*u.m
213 fT.GetMomentum(fMom)
214 lam = (zEx+fPos.Z())/fMom.Z()
215 hitlist[zEx+fPos.Z()] = [fPos.X()+lam*fMom.X(),fPos.Y()+lam*fMom.Y()]
216# sort in z
217 lz = list(hitlist.keys())
218 if len(lz)>1:
219 lz.sort()
220 for z in lz: DTrack.SetNextPoint(hitlist[z][0],hitlist[z][1],z)
221 p = pdg.GetParticle(fT.GetPdgCode())
222 if p : pName = p.GetName()
223 else: pName = str(fT.GetPdgCode())
224 DTrack.SetName('MCTrack_'+str(n)+'_'+pName)
225 c = ROOT.kYellow
226 if abs(fT.GetPdgCode()) == options.HiddenParticleID:c = ROOT.kMagenta
227 DTrack.SetMainColor(c)
228 DTrack.SetLineWidth(3)
229 self.comp.AddElement(DTrack)
230 ntot+=1
231 print("draw ",ntot," MC tracks")

◆ DrawParticle()

eventDisplay_shipLHC.DrawTracks.DrawParticle (   self,
  n 
)

Definition at line 117 of file eventDisplay_shipLHC.py.

117 def DrawParticle(self,n):
118 self.comp.OpenCompound()
119 DTrack = ROOT.TEveLine()
120 DTrack.SetPickable(ROOT.kTRUE)
121 DTrack.SetMainColor(ROOT.kCyan)
122 DTrack.SetLineWidth(4)
123 aP=sTree.Particles[n]
124 DTrack.SetTitle(aP.__repr__())
125 DTrack.SetName('Prtcle_'+str(n))
126 DTrack.SetNextPoint(aP.Vx(),aP.Vy(),aP.Vz())
127 lam = (self.Targetz - aP.Vz())/aP.Pz()
128 DTrack.SetNextPoint(aP.Vx()+lam*aP.Px(),aP.Vy()+lam*aP.Py(),self.Targetz)
129 self.comp.AddElement(DTrack)

◆ DrawSimpleMCTracks()

eventDisplay_shipLHC.DrawTracks.DrawSimpleMCTracks (   self)

Definition at line 232 of file eventDisplay_shipLHC.py.

232 def DrawSimpleMCTracks(self):
233 comp = self.comp
234 comp.OpenCompound()
235 n = -1
236 ntot = 0
237 fPos = ROOT.TVector3()
238 fMom = ROOT.TVector3()
239 delZ = 10*u.m
240 for fT in sTree.MCTrack:
241 n+=1
242 DTrack = ROOT.TEveLine()
243 DTrack.SetPickable(ROOT.kTRUE)
244 DTrack.SetTitle(fT.__repr__())
245 fT.GetStartVertex(fPos)
246 fT.GetMomentum(fMom)
247 hitlist = {}
248 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
249 z = fPos.Z() + delZ
250 slx,sly = fMom.X()/fMom.Z(),fMom.Y()/fMom.Z()
251 hitlist[z] = [fPos.X()+slx*delZ,fPos.Y()+sly*delZ]
252 for z in hitlist.keys():
253 DTrack.SetNextPoint(hitlist[z][0],hitlist[z][1],z)
254 p = pdg.GetParticle(fT.GetPdgCode())
255 if p : pName = p.GetName()
256 else: pName = str(fT.GetPdgCode())
257 DTrack.SetName('MCTrack_'+str(n)+'_'+pName)
258 c = ROOT.kYellow
259 DTrack.SetMainColor(c)
260 DTrack.SetLineWidth(3)
261 comp.AddElement(DTrack)
262 ntot+=1
263 comp.CloseCompound()
264 gEve.ElementChanged(SHiPDisplay.tracks.evscene,True,True)
265
266
267

◆ ExecuteTask()

eventDisplay_shipLHC.DrawTracks.ExecuteTask (   self,
  option = '' 
)

Definition at line 105 of file eventDisplay_shipLHC.py.

105 def ExecuteTask(self,option=''):
106 self.comp.DestroyElements()
107 self.comp.OpenCompound()
108 if sTree.FindBranch('FitTracks') or sTree.FindBranch('FitTracks_PR'):
109 if sTree.FitTracks.GetEntries() > 0:
110 self.DrawFittedTracks()
111 if not sTree.FindBranch("GeoTracks") and sTree.MCTrack.GetEntries() > 0:
112 if globals()['withMCTracks']:
113 self.DrawMCTracks()
114 #self.DrawSimpleMCTracks()
115 self.comp.CloseCompound()
116 gEve.ElementChanged(self.evscene,True,True)

◆ FinishEvent()

eventDisplay_shipLHC.DrawTracks.FinishEvent (   self)

Definition at line 103 of file eventDisplay_shipLHC.py.

103 def FinishEvent(self):
104 pass

◆ InitTask()

eventDisplay_shipLHC.DrawTracks.InitTask (   self)

Definition at line 94 of file eventDisplay_shipLHC.py.

94 def InitTask(self):
95# prepare container for fitted tracks
96 self.comp = ROOT.TEveCompound('Tracks')
97 gEve.AddElement(self.comp)
98 self.trackColors = {13:ROOT.kGreen,211:ROOT.kRed,11:ROOT.kOrange,321:ROOT.kMagenta}
99 self.z_start = 0
100 sc = gEve.GetScenes()
101 self.evscene = sc.FindChild('Event scene')
102

Member Data Documentation

◆ comp

eventDisplay_shipLHC.DrawTracks.comp

Definition at line 96 of file eventDisplay_shipLHC.py.

◆ evscene

eventDisplay_shipLHC.DrawTracks.evscene

Definition at line 101 of file eventDisplay_shipLHC.py.

◆ niter

eventDisplay_shipLHC.DrawTracks.niter

Definition at line 286 of file eventDisplay_shipLHC.py.

◆ Targetz

eventDisplay_shipLHC.DrawTracks.Targetz

Definition at line 128 of file eventDisplay_shipLHC.py.

◆ trackColors

eventDisplay_shipLHC.DrawTracks.trackColors

Definition at line 98 of file eventDisplay_shipLHC.py.

◆ z_start

eventDisplay_shipLHC.DrawTracks.z_start

Definition at line 99 of file eventDisplay_shipLHC.py.


The documentation for this class was generated from the following file: