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

Public Member Functions

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

Public Attributes

 comp
 
 trackColors
 
 z_end
 
 z_start
 
 z_mag
 
 z_ecal
 
 niter
 
 dz
 
 parallelToZ
 
 evscene
 
 Targetz
 

Detailed Description

Definition at line 179 of file eventDisplay.py.

Member Function Documentation

◆ DrawFittedTracks() [1/2]

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

Definition at line 345 of file eventDisplay.py.

345 def DrawFittedTracks(self,option=''):
346 n,ntot = -1,0
347 for fT in sTree.FitTracks:
348 n+=1
349 fst = fT.getFitStatus()
350 if not fst.isFitConverged(): continue
351 if fst.getNdf() < 20: continue
352 DTrack = ROOT.TEveLine()
353 DTrack.SetPickable(ROOT.kTRUE)
354 DTrack.SetTitle(fT.__repr__())
355 fstate = fT.getFittedState(0)
356 fPos = fstate.getPos()
357 fMom = fstate.getMom()
358 pos = fPos
359 mom = fMom
360 pid = fstate.getPDG()
361 zs = self.z_start
362 before = True
363 for i in range(self.niter):
364 rc,newpos,newmom = TrackExtrapolateTool.extrapolateToPlane(fT,zs)
365 if rc:
366 DTrack.SetNextPoint(newpos.X(),newpos.Y(),newpos.Z())
367 else:
368 print('error with extrapolation: z=',zs)
369 # use linear extrapolation
370 px,py,pz = mom.X(),mom.Y(),mom.Z()
371 lam = (zs-pos.Z())/pz
372 DTrack.SetNextPoint(pos.X()+lam*px,pos.Y()+lam*py,zs)
373 zs+=self.dz
374 DTrack.SetName('FitTrack_'+str(n))
375 c = ROOT.kWhite
376 if abs(pid) in self.trackColors : c = self.trackColors[abs(pid)]
377 DTrack.SetMainColor(c)
378 DTrack.SetLineWidth(3)
379 self.comp.AddElement(DTrack)
380 ntot+=1
381 print("draw ",ntot," fitted tracks")
382 n=-1
383 for aP in sTree.Particles:
384 n+=1
385# check fitted tracks
386 tracksOK = True
387 if aP.GetMother(1)==99: # DOCA is set
388 if aP.T()>3*u.cm : continue
389 for k in range(aP.GetNDaughters()):
390 if k>1: break # we don't have more than 2tracks/vertex yet, no idea why ROOT sometimes comes up with 4!
391 fT = sTree.FitTracks[aP.GetDaughter(k)]
392 fst = fT.getFitStatus()
393 if not fst.isFitConverged(): tracksOK=False
394 if fst.getNdf() < 20: tracksOK=False
395 if not tracksOK: continue
396 DTrack = ROOT.TEveLine()
397 DTrack.SetPickable(ROOT.kTRUE)
398 DTrack.SetMainColor(ROOT.kCyan)
399 DTrack.SetLineWidth(4)
400 DTrack.SetName('Particle_'+str(n))
401 DTrack.SetTitle(aP.__repr__())
402 DTrack.SetNextPoint(aP.Vx(),aP.Vy(),aP.Vz())
403 lam = (self.Targetz - aP.Vz())/aP.Pz()
404 DTrack.SetNextPoint(aP.Vx()+lam*aP.Px(),aP.Vy()+lam*aP.Py(),self.Targetz)
405 self.comp.AddElement(DTrack)
406#

◆ DrawFittedTracks() [2/2]

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

Definition at line 152 of file eventDisplay.py.

152 def DrawFittedTracks(self,option=''):
153 n,ntot = -1,0
154 for fT in sTree.fittedTracks:
155 n+=1
156 fst = fT.getFitStatus()
157 if not fst.isFitConverged(): continue
158 DTrack = ROOT.TEveLine()
159 DTrack.SetPickable(ROOT.kTRUE)
160 DTrack.SetTitle(fT.__repr__())
161 for n in range(fT.getNumPoints()):
162 fstate = fT.getFittedState(n)
163 fPos = fstate.getPos()
164 DTrack.SetNextPoint(fPos.X(),fPos.Y(),fPos.Z())
165 DTrack.SetName('FitTrack_'+str(n))
166 c = ROOT.kOrange
167 DTrack.SetMainColor(c)
168 DTrack.SetLineWidth(3)
169 self.comp.AddElement(DTrack)
170 ntot+=1
171 print("draw ",ntot," fitted tracks")
172

◆ DrawMCTrack() [1/2]

eventDisplay.DrawTracks.DrawMCTrack (   self,
  n 
)

Definition at line 242 of file eventDisplay.py.

242 def DrawMCTrack(self,n):
243 self.comp.OpenCompound()
244 fT = sTree.MCTrack[n]
245 DTrack = ROOT.TEveLine()
246 DTrack.SetPickable(ROOT.kTRUE)
247 DTrack.SetTitle(fT.__repr__())
248 p = pdg.GetParticle(fT.GetPdgCode())
249 if p : pName = p.GetName()
250 else: pName = str(fT.GetPdgCode())
251 DTrack.SetName('MCTrck_'+str(n)+'_'+pName)
252 fPos = ROOT.TVector3()
253 fMom = ROOT.TVector3()
254 fT.GetStartVertex(fPos)
255 fT.GetMomentum(fMom)
256# check for end vertex
257 evVx = False
258 for da in sTree.MCTrack:
259 if da.GetMotherId()==n:
260 evVx = True
261 break
262 DTrack.SetNextPoint(fPos.X(),fPos.Y(),fPos.Z())
263 if evVx and abs( da.GetStartZ()-fPos.Z() )>1*u.cm :
264 DTrack.SetNextPoint(da.GetStartX(),da.GetStartY(),da.GetStartZ())
265 else:
266 zEx = 10*u.m
267 if evVx : zEx = -10*u.m
268 lam = (zEx+fPos.Z())/fMom.Z()
269 DTrack.SetNextPoint(fPos.X()+lam*fMom.X(),fPos.Y()+lam*fMom.Y(),zEx+fPos.Z())
270 c = ROOT.kYellow
271 DTrack.SetMainColor(c)
272 DTrack.SetLineWidth(3)
273 self.comp.AddElement(DTrack)
274 self.comp.CloseCompound()
275 gEve.ElementChanged(self.evscene,True,True)

◆ DrawMCTrack() [2/2]

eventDisplay.DrawTracks.DrawMCTrack (   self,
  n 
)

Definition at line 173 of file eventDisplay.py.

173 def DrawMCTrack(self,n):
174 self.comp.OpenCompound()
175 fT = sTree.MCTrack[n]
176 DTrack = ROOT.TEveLine()
177 DTrack.SetPickable(ROOT.kTRUE)
178 DTrack.SetTitle(fT.__repr__())
179 p = pdg.GetParticle(fT.GetPdgCode())
180 if p : pName = p.GetName()
181 else: pName = str(fT.GetPdgCode())
182 DTrack.SetName('MCTrck_'+str(n)+'_'+pName)
183 fPos = ROOT.TVector3()
184 fMom = ROOT.TVector3()
185 fT.GetStartVertex(fPos)
186 fT.GetMomentum(fMom)
187# check for end vertex
188 evVx = False
189 for da in sTree.MCTrack:
190 if da.GetMotherId()==n:
191 evVx = True
192 break
193 DTrack.SetNextPoint(fPos.X(),fPos.Y(),fPos.Z())
194 if evVx and abs( da.GetStartZ()-fPos.Z() )>1*u.cm :
195 DTrack.SetNextPoint(da.GetStartX(),da.GetStartY(),da.GetStartZ())
196 else:
197 zEx = 10*u.m
198 if evVx : zEx = -10*u.m
199 lam = (zEx+fPos.Z())/fMom.Z()
200 DTrack.SetNextPoint(fPos.X()+lam*fMom.X(),fPos.Y()+lam*fMom.Y(),zEx+fPos.Z())
201 c = ROOT.kYellow
202 DTrack.SetMainColor(c)
203 DTrack.SetLineWidth(3)
204 self.comp.AddElement(DTrack)
205 self.comp.CloseCompound()
206 gEve.ElementChanged(self.evscene,True,True)

◆ DrawMCTracks() [1/2]

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

Definition at line 276 of file eventDisplay.py.

276 def DrawMCTracks(self,option=''):
277 n = -1
278 ntot = 0
279 fPos = ROOT.TVector3()
280 fMom = ROOT.TVector3()
281 for fT in sTree.MCTrack:
282 n+=1
283 DTrack = ROOT.TEveLine()
284 DTrack.SetPickable(ROOT.kTRUE)
285 DTrack.SetTitle(fT.__repr__())
286 fT.GetStartVertex(fPos)
287 hitlist = {}
288 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
289 # look for HNL
290 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
291 for da in sTree.MCTrack:
292 if da.GetMotherId()==n: break
293 # end vertex of HNL
294 da.GetStartVertex(fPos)
295 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
296 # loop over all sensitive volumes to find hits
297 for P in ["vetoPoint","muonPoint","EcalPoint","HcalPoint","preshowerPoint","strawtubesPoint","ShipRpcPoint","TargetPoint","TimeDetPoint",
298 "MuFilterPoint","ScifiPoint"]:
299 if not sTree.GetBranch(P): continue
300 c=eval("sTree."+P)
301 for p in c:
302 if p.GetTrackID()==n:
303 if hasattr(p, "LastPoint"):
304 lp = p.LastPoint()
305 if lp.x()==lp.y() and lp.x()==lp.z() and lp.x()==0:
306# must be old data, don't expect hit at 0,0,0
307 hitlist[p.GetZ()] = [p.GetX(),p.GetY()]
308 else:
309 hitlist[lp.z()] = [lp.x(),lp.y()]
310 hitlist[2.*p.GetZ()-lp.z()] = [2.*p.GetX()-lp.x(),2.*p.GetY()-lp.y()]
311 else:
312 hitlist[p.GetZ()] = [p.GetX(),p.GetY()]
313 if len(hitlist)==1:
314 if fT.GetMotherId()<0: continue
315 if abs(sTree.MCTrack[fT.GetMotherId()].GetPdgCode()) == options.HiddenParticleID:
316 # still would like to draw track stub
317 # check for end vertex
318 evVx = False
319 for da in sTree.MCTrack:
320 if da.GetMotherId()==n:
321 evVx = True
322 break
323 if evVx : hitlist[da.GetStartZ()] = [da.GetStartX(),da.GetStartY()]
324 else :
325 zEx = 10*u.m
326 fT.GetMomentum(fMom)
327 lam = (zEx+fPos.Z())/fMom.Z()
328 hitlist[zEx+fPos.Z()] = [fPos.X()+lam*fMom.X(),fPos.Y()+lam*fMom.Y()]
329# sort in z
330 lz = list(hitlist.keys())
331 if len(lz)>1:
332 lz.sort()
333 for z in lz: DTrack.SetNextPoint(hitlist[z][0],hitlist[z][1],z)
334 p = pdg.GetParticle(fT.GetPdgCode())
335 if p : pName = p.GetName()
336 else: pName = str(fT.GetPdgCode())
337 DTrack.SetName('MCTrack_'+str(n)+'_'+pName)
338 c = ROOT.kYellow
339 if abs(fT.GetPdgCode()) == options.HiddenParticleID:c = ROOT.kMagenta
340 DTrack.SetMainColor(c)
341 DTrack.SetLineWidth(3)
342 self.comp.AddElement(DTrack)
343 ntot+=1
344 print("draw ",ntot," MC tracks")

◆ DrawMCTracks() [2/2]

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

Definition at line 207 of file eventDisplay.py.

207 def DrawMCTracks(self,option=''):
208 n = -1
209 ntot = 0
210 fPos = ROOT.TVector3()
211 fMom = ROOT.TVector3()
212 for fT in sTree.MCTrack:
213 n+=1
214 DTrack = ROOT.TEveLine()
215 DTrack.SetPickable(ROOT.kTRUE)
216 DTrack.SetTitle(fT.__repr__())
217 fT.GetStartVertex(fPos)
218 hitlist = {}
219 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
220 # look for HNL
221 if abs(fT.GetPdgCode()) == options.HiddenParticleID:
222 for da in sTree.MCTrack:
223 if da.GetMotherId()==n: break
224 # end vertex of HNL
225 da.GetStartVertex(fPos)
226 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
227 # loop over all sensitive volumes to find hits
228 for P in ["EmulsionDetPoint","MuFilterPoint","ScifiPoint"]:
229 if not sTree.GetBranch(P): continue
230 c=eval("sTree."+P)
231 for p in c:
232 if p.GetTrackID()==n:
233 if hasattr(p, "LastPoint"):
234 lp = p.LastPoint()
235 if lp.x()==lp.y() and lp.x()==lp.z() and lp.x()==0:
236# must be old data, don't expect hit at 0,0,0
237 hitlist[p.GetZ()] = [p.GetX(),p.GetY()]
238 else:
239 hitlist[lp.z()] = [lp.x(),lp.y()]
240 hitlist[2.*p.GetZ()-lp.z()] = [2.*p.GetX()-lp.x(),2.*p.GetY()-lp.y()]
241 else:
242 hitlist[p.GetZ()] = [p.GetX(),p.GetY()]
243 if len(hitlist)==1:
244 if fT.GetMotherId()<0: continue
245 if abs(sTree.MCTrack[fT.GetMotherId()].GetPdgCode()) == options.HiddenParticleID:
246 # still would like to draw track stub
247 # check for end vertex
248 evVx = False
249 for da in sTree.MCTrack:
250 if da.GetMotherId()==n:
251 evVx = True
252 break
253 if evVx : hitlist[da.GetStartZ()] = [da.GetStartX(),da.GetStartY()]
254 else :
255 zEx = 10*u.m
256 fT.GetMomentum(fMom)
257 lam = (zEx+fPos.Z())/fMom.Z()
258 hitlist[zEx+fPos.Z()] = [fPos.X()+lam*fMom.X(),fPos.Y()+lam*fMom.Y()]
259# sort in z
260 lz = list(hitlist.keys())
261 if len(lz)>1:
262 lz.sort()
263 for z in lz: DTrack.SetNextPoint(hitlist[z][0],hitlist[z][1],z)
264 p = pdg.GetParticle(fT.GetPdgCode())
265 if p : pName = p.GetName()
266 else: pName = str(fT.GetPdgCode())
267 DTrack.SetName('MCTrack_'+str(n)+'_'+pName)
268 c = ROOT.kYellow
269 if abs(fT.GetPdgCode()) == options.HiddenParticleID:c = ROOT.kMagenta
270 DTrack.SetMainColor(c)
271 DTrack.SetLineWidth(3)
272 self.comp.AddElement(DTrack)
273 ntot+=1
274 print("draw ",ntot," MC tracks")
275
276#

◆ DrawParticle()

eventDisplay.DrawTracks.DrawParticle (   self,
  n 
)

Definition at line 229 of file eventDisplay.py.

229 def DrawParticle(self,n):
230 self.comp.OpenCompound()
231 DTrack = ROOT.TEveLine()
232 DTrack.SetPickable(ROOT.kTRUE)
233 DTrack.SetMainColor(ROOT.kCyan)
234 DTrack.SetLineWidth(4)
235 aP=sTree.Particles[n]
236 DTrack.SetTitle(aP.__repr__())
237 DTrack.SetName('Prtcle_'+str(n))
238 DTrack.SetNextPoint(aP.Vx(),aP.Vy(),aP.Vz())
239 lam = (self.Targetz - aP.Vz())/aP.Pz()
240 DTrack.SetNextPoint(aP.Vx()+lam*aP.Px(),aP.Vy()+lam*aP.Py(),self.Targetz)
241 self.comp.AddElement(DTrack)

◆ ExecuteTask() [1/2]

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

Definition at line 218 of file eventDisplay.py.

218 def ExecuteTask(self,option=''):
219 self.comp.DestroyElements()
220 self.comp.OpenCompound()
221 if sTree.FindBranch('FitTracks') or sTree.FindBranch('FitTracks_PR'):
222 if sTree.FitTracks.GetEntries() > 0:
223 self.DrawFittedTracks()
224 if not sTree.FindBranch("GeoTracks") and sTree.MCTrack.GetEntries() > 0:
225 if globals()['withAllMCTracks']: DrawSimpleMCTracks() # for sndlhc, until more details are simulated
226 elif globals()['withMCTracks']: self.DrawMCTracks()
227 self.comp.CloseCompound()
228 gEve.ElementChanged(self.evscene,True,True)

◆ ExecuteTask() [2/2]

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

Definition at line 143 of file eventDisplay.py.

143 def ExecuteTask(self,option=''):
144 self.comp.DestroyElements()
145 self.comp.OpenCompound()
146 if sTree.MCTrack.GetEntries() > 0:
147 if globals()['withAllMCTracks']: DrawSimpleMCTracks() # for sndlhc, until more details are simulated
148 elif globals()['withMCTracks']: self.DrawMCTracks()
149 self.comp.CloseCompound()
150 gEve.ElementChanged(self.evscene,True,True)
151

◆ FinishEvent() [1/2]

eventDisplay.DrawTracks.FinishEvent (   self)

Definition at line 216 of file eventDisplay.py.

216 def FinishEvent(self):
217 pass

◆ FinishEvent() [2/2]

eventDisplay.DrawTracks.FinishEvent (   self)

Definition at line 141 of file eventDisplay.py.

141 def FinishEvent(self):
142 pass

◆ InitTask() [1/2]

eventDisplay.DrawTracks.InitTask (   self)

Definition at line 181 of file eventDisplay.py.

181 def InitTask(self):
182# prepare container for fitted tracks
183 self.comp = ROOT.TEveCompound('Tracks')
184 gEve.AddElement(self.comp)
185 self.trackColors = {13:ROOT.kGreen,211:ROOT.kRed,11:ROOT.kOrange,321:ROOT.kMagenta}
186 dv = top.GetNode('DecayVolume_1')
187 self.z_end = 500.
188 if dv:
189 ns = dv.GetNodes()
190 T1Lid = ns.FindObject("T1Lid_1").GetMatrix()
191 self.z_start = T1Lid.GetTranslation()[2]
192 else: self.z_start = 0
193 muonDet = top.GetNode('MuonDetector_1')
194 if muonDet: self.z_end = muonDet.GetMatrix().GetTranslation()[2]+muonDet.GetVolume().GetShape().GetDZ()
195 elif hasattr(ShipGeo,'MuonStation3'): self.z_end = ShipGeo['MuonStation3'].z
196 elif top.GetNode("VMuonBox_1"):
197 xx = top.GetNode("VMuonBox_1")
198 self.z_end = xx.GetMatrix().GetTranslation()[2]+xx.GetVolume().GetShape().GetDZ()
199 magNode = top.GetNode('MCoil_1')
200 if magNode: self.z_mag = magNode.GetMatrix().GetTranslation()[2]
201 elif hasattr(ShipGeo,'Bfield'): self.z_mag = ShipGeo['Bfield'].z
202 else: self.z_mag=0
203 ecalDet = top.GetNode('Ecal_1')
204 self.z_ecal = self.z_end
205 if ecalDet: self.z_ecal = ecalDet.GetMatrix().GetTranslation()[2]
206 elif hasattr(ShipGeo,'ecal'): self.z_ecal = ShipGeo['ecal'].z
207 self.niter = 100
208 self.dz = (self.z_end - self.z_start) / float(self.niter)
209 self.parallelToZ = ROOT.TVector3(0., 0., 1.)
210 sc = gEve.GetScenes()
211 self.evscene = sc.FindChild('Event scene')
212 targetNode = top.GetNode("TargetArea_1")
213 if targetNode: self.Targetz = targetNode.GetMatrix().GetTranslation()[2]
214 elif hasattr(ShipGeo,'target'): self.Targetz = ShipGeo['target'].z0
215 else: self.Targetz=0

◆ InitTask() [2/2]

eventDisplay.DrawTracks.InitTask (   self)

Definition at line 132 of file eventDisplay.py.

132 def InitTask(self):
133# prepare container for fitted tracks
134 self.comp = ROOT.TEveCompound('Tracks')
135 gEve.AddElement(self.comp)
136 self.niter = 100
137 self.dz = (200.) / float(self.niter)
138 self.parallelToZ = ROOT.TVector3(0., 0., 1.)
139 sc = gEve.GetScenes()
140 self.evscene = sc.FindChild('Event scene')

Member Data Documentation

◆ comp

eventDisplay.DrawTracks.comp

Definition at line 183 of file eventDisplay.py.

◆ dz

eventDisplay.DrawTracks.dz

Definition at line 208 of file eventDisplay.py.

◆ evscene

eventDisplay.DrawTracks.evscene

Definition at line 211 of file eventDisplay.py.

◆ niter

eventDisplay.DrawTracks.niter

Definition at line 207 of file eventDisplay.py.

◆ parallelToZ

eventDisplay.DrawTracks.parallelToZ

Definition at line 209 of file eventDisplay.py.

◆ Targetz

eventDisplay.DrawTracks.Targetz

Definition at line 213 of file eventDisplay.py.

◆ trackColors

eventDisplay.DrawTracks.trackColors

Definition at line 185 of file eventDisplay.py.

◆ z_ecal

eventDisplay.DrawTracks.z_ecal

Definition at line 204 of file eventDisplay.py.

◆ z_end

eventDisplay.DrawTracks.z_end

Definition at line 187 of file eventDisplay.py.

◆ z_mag

eventDisplay.DrawTracks.z_mag

Definition at line 200 of file eventDisplay.py.

◆ z_start

eventDisplay.DrawTracks.z_start

Definition at line 191 of file eventDisplay.py.


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