SND@LHC Software
Loading...
Searching...
No Matches
eventDisplay.py
Go to the documentation of this file.
1#!/usr/bin/env python -i
2import ROOT,sys,os
3
4from argparse import ArgumentParser
5from ShipGeoConfig import ConfigRegistry
6from rootpyPickler import Unpickler
7from array import array
8import shipunit as u
9from decorators import *
10import shipRoot_conf,shipDet_conf
12G = open('eveGlobal.py','w')
13G.close()
14
15fMan = None
16fRun = None
17pdg = ROOT.TDatabasePDG.Instance()
18g = ROOT.gROOT
19gEnv = ROOT.gEnv
20gEnv.SetValue('Eve.Viewer.HideMenus','off')
21
22withMCTracks = True
23withAllMCTracks = False
24
25transparentMaterials = {'air':99,'iron':99,'aluminium':90,'EmulsionFilmMixture':90,'Polycarbonate':90,
26'CarbonComposite':90,'Aluminum':90,'rohacell':90,'Scintillator':90,'tungstenalloySND':99,'polyvinyltoluene':90}
27
28parser = ArgumentParser()
29
30parser.add_argument("-f", "--inputFile", dest="InputFile", help="Input file", required=True)
31parser.add_argument("-g", "--geoFile", dest="geoFile", help="ROOT geofile", required=True)
32parser.add_argument("-p", "--paramFile", dest="ParFile", help="FairRoot param file", required=False, default=None)
33parser.add_argument("--Debug", dest="Debug", help="Switch on debugging", required=False, action="store_true")
34parser.add_argument("-o", "--outFile", dest="OutputFile", help="Output file", required=False,default=None)
35
36parser.add_argument("-H", "--houghTransform", dest="houghTransform", help="do not use hough transform for track reco", action='store_false',default=True)
37parser.add_argument("-t", "--tolerance", dest="tolerance", type=float, help="How far away from Hough line hits assigned to the muon can be. In cm.", default=0.)
38parser.add_argument("--hits_to_fit", dest = "hits_to_fit", type=str, help="Which detectors to use in the fit, in the format: vesfusds, where [ve] is veto, [sf] is Scifi, [us] is Upstream muon filter, and [ds] is downstream muon filter", default = "sfusds")
39parser.add_argument("--hits_for_triplet", dest = "hits_for_triplet", type=str, help="Which detectors to use for the triplet condition. In the same format as --hits_to_fit", default = "ds")
40
41options = parser.parse_args()
42
43def printMCTrack(n,MCTrack):
44 mcp = MCTrack[n]
45 print(' %6i %7i %6.3F %6.3F %7.3F %7.3F %7.3F %7.3F %6i '%(n,mcp.GetPdgCode(),mcp.GetPx()/u.GeV,mcp.GetPy()/u.GeV,mcp.GetPz()/u.GeV, \
46 mcp.GetStartX()/u.m,mcp.GetStartY()/u.m,mcp.GetStartZ()/u.m,mcp.GetMotherId() ))
47
48def dump(pcut=0):
49 print(' # pid px py pz vx vy vz mid')
50 n=-1
51 for mcp in sTree.MCTrack:
52 n+=1
53 if mcp.GetP()/u.GeV < pcut : continue
54 printMCTrack(n,sTree.MCTrack)
55
56class DrawDigi(ROOT.FairTask):
57 " My Fair Task"
58 def InitTask(self):
59 self.comp = ROOT.TEveCompound('Digis')
60 gEve.AddElement(self.comp)
61 sc = gEve.GetScenes()
62 self.evscene = sc.FindChild('Event scene')
63 def FinishEvent(self):
64 pass
65 def ExecuteTask(self,option=''):
66 self.comp.DestroyElements()
67 self.comp.OpenCompound()
68 nav = ROOT.gGeoManager.GetCurrentNavigator()
69 digis = []
70 if sTree.FindBranch("Digi_ScifiHits"): digis.append(sTree.Digi_ScifiHits)
71 if sTree.FindBranch("Digi_MuFilterHits"): digis.append(sTree.Digi_MuFilterHits)
72 for branch in digis:
73 print('digis:',branch.GetName(),":",branch.GetEntries())
74 for digi in branch:
75 if not digi.isValid(): continue
76 B=ROOT.TVector3()
77 A=ROOT.TVector3()
78 detID = digi.GetDetectorID()
79 if digi.GetName() == 'MuFilterHit':
80 system = digi.GetSystem()
81 modules['MuFilter'].GetPosition(detID,A,B)
82 color = ROOT.kGreen
83 if system==1: vol = sGeo.GetVolume('volVetoBar')
84 elif system==2: vol = sGeo.GetVolume('volMuUpstreamBar')
85 elif system==3:
86 if digi.isVertical():
87 color = ROOT.kMagenta
88 vol = sGeo.GetVolume('volMuDownstreamBar_ver')
89 else:
90 color = ROOT.kBlue
91 vol = sGeo.GetVolume('volMuDownstreamBar_hor')
92 shape = vol.GetShape()
93 dx,dy,dz = shape.GetDX(),shape.GetDY(),shape.GetDZ()
94 origin = shape.GetOrigin()
95 mPoint = 0.5*(A+B)
96 master = array('d',[mPoint[0],mPoint[1],mPoint[2]])
97 o = array('d',[0,0,0])
98 nav.MasterToLocal(master,o)
99
100 elif digi.GetName() == 'sndScifiHit':
101 modules['Scifi'].GetSiPMPosition(detID,A,B)
102 mPoint = 0.5*(A+B)
103 master = array('d',[mPoint[0],mPoint[1],mPoint[2]])
104 o = array('d',[0,0,0])
105 nav.MasterToLocal(master,o)
106 vol = sGeo.GetVolume('ChannelVol')
107 color = ROOT.kWhite
108 shape = vol.GetShape()
109 if digi.isVertical():
110 dy,dx,dz = shape.GetDX(),shape.GetDY(),shape.GetDZ()
111 # fLengthScifiMat/2, fWidthChannel/2, fZEpoxyMat/2
112 else:
113 dx,dy,dz = shape.GetDX(),shape.GetDY(),shape.GetDZ()
114
115 bx = ROOT.TEveBox( digi.GetName()+'_'+str(digi.GetDetectorID()) )
116 bx.SetPickable(ROOT.kTRUE)
117 bx.SetTitle(digi.__repr__())
118 bx.SetMainColor(color)
119 master = array('d',[0,0,0])
120 n=0
121 for edge in [ [-dx,-dy,-dz],[-dx,+dy,-dz],[+dx,+dy,-dz],[+dx,-dy,-dz],[-dx,-dy, dz],[-dx,+dy, dz],[+dx,+dy, dz],[+dx,-dy, dz]]:
122 origin = array('d',[edge[0]+o[0],edge[1]+o[1],edge[2]+o[2]])
123 nav.LocalToMaster(origin,master)
124 bx.SetVertex(n,master[0],master[1],master[2])
125 n+=1
126 self.comp.AddElement(bx)
127 self.comp.CloseCompound()
128 gEve.ElementChanged(self.evscene,True,True)
129#
130class DrawTracks(ROOT.FairTask):
131 " My Fair Task"
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')
141 def FinishEvent(self):
142 pass
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
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
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)
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#
277class IO():
278 def __init__(self):
279# add actions to eve display
280 gEve = ROOT.gEve
281 slot = ROOT.TEveWindow.CreateWindowInTab(gEve.GetBrowser().GetTabLeft())
282 slot.SetShowTitleBar(ROOT.kFALSE)
283 packs = slot.MakePack();
284 packs.SetShowTitleBar(ROOT.kFALSE);
285 packs.SetElementName("ActionsX")
286 packs.SetHorizontal()
287 slot = packs.NewSlot()
288 frame = slot.MakeFrame()
289 frame.SetElementName("commands")
290 frame.SetShowTitleBar(ROOT.kFALSE)
291 cf = frame.GetGUICompositeFrame()
292 hf = ROOT.TGVerticalFrame(cf)
293 hf.SetCleanup(ROOT.kLocalCleanup)
294 hf.SetWidth(150)
295 cf.AddFrame(hf)
296 guiFrame = ROOT.TGVerticalFrame(hf)
297 hf.AddFrame(guiFrame, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
298 guiFrame.SetCleanup(ROOT.kDeepCleanup)
299
300 bnx = ROOT.TGTextButton(guiFrame, "next event")
301 bnx.SetWidth(150)
302 bnx.SetToolTipText('click for next event')
303 bnx.SetCommand('TPython::Exec("import evdsnd_commands ; rc=evdsnd_commands.nextEvent()")')
304 bnx.SetTextColor(ROOT.kBlue)
305 guiFrame.AddFrame(bnx, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
306
307 bt = ROOT.TGTextButton(guiFrame, "switch transparent mode on/off")
308 bt.SetWidth(150)
309 bt.SetToolTipText('switch transparent mode on/off for better visibility of tracks')
310 bt.SetCommand('TPython::Exec("import evdsnd_commands ; rc=evdsnd_commands.transparentMode()")')
311 guiFrame.AddFrame(bt, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
312
313 blu = ROOT.TGTextButton(guiFrame, "more light")
314 blu.SetWidth(150)
315 blu.SetToolTipText('increase light power. Front, Side, Specular')
316 blu.SetCommand('TPython::Exec("import evdsnd_commands ; rc=evdsnd_commands.light(0.5)")')
317 guiFrame.AddFrame(blu, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
318 bld = ROOT.TGTextButton(guiFrame, "less light")
319 bld.SetWidth(150)
320 bld.SetToolTipText('decrease light power. Front, Side, Specular')
321 bld.SetCommand('TPython::Exec("import evdsnd_commands ; rc=evdsnd_commands.light(-0.5)")')
322 guiFrame.AddFrame(bld, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
323
324 bld = ROOT.TGTextButton(guiFrame, "fit track")
325 bld.SetWidth(150)
326 bld.SetToolTipText('simple PR, fit track')
327 bld.SetCommand('TPython::Exec("import evdsnd_commands ; rc=evdsnd_commands.fittrack")')
328 guiFrame.AddFrame(bld, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
329
330#
331 cf.MapSubwindows()
332 cf.Layout()
333 cf.MapWindow()
334 def nextEvent(self,event=None):
335 i = int(self.contents.get())
336 if i==self.n: self.n+=1
337 else : self.n=i
338 self.contents.set(self.n)
339 SHiPDisplay.NextEvent(self.n)
340 def toogleMCTracks(self):
341 tl = fRun.GetMainTask().GetListOfTasks()
342 geoTask = tl.FindObject("GeoTracks")
343 if globals()['withMCTracks']:
344 globals()['withMCTracks'] = False
345 self.lbut['withMC'].var.set(1)
346 if geoTask: geoTask.SetActive(0)
347 else:
348 globals()['withMCTracks'] = True
349 self.lbut['withMC'].var.set(0)
350 if geoTask: geoTask.SetActive(1)
351 def toogle(self,x):
352 v = top.GetNode(x)
353 assemb = "Assembly" in v.GetVolume().__str__()
354 if v.IsVisible()>0 or assemb and v.IsVisDaughters()>0 :
355 print("switch off ",x)
356 v.SetVisibility(0)
357 v.SetVisDaughters(0)
358 self.lbut[x].var.set(0)
359 else:
360 print("switch on ",x)
361 if assemb: v.SetVisDaughters(1)
362 else: v.SetVisibility(1)
363 self.lbut[x].var.set(1)
364 gEve.ElementChanged(self.geoscene,True,True)
365 for v in top.GetNodes():
366 x = v.GetName()
367 if x in self.lbut:
368 assemb = "Assembly" in v.GetVolume().__str__()
369 if v.IsVisible()>0 or assemb and v.IsVisDaughters()>0 : self.lbut[x].var.set(1)
370 else : self.lbut[x].var.set(0)
371#
372class EventLoop(ROOT.FairTask):
373 " My Fair Task"
374 def InitTask(self):
375 self.n = 0
376 self.first = True
377 rc = sTree.GetEvent(0)
378 modules['Scifi'].SiPMmapping()
379 self.digi = DrawDigi()
380 self.digi.InitTask()
381 self.tracks = DrawTracks()
382 self.tracks.InitTask()
383# create GUI
384 self.ioBar = IO()
385 self.TransparentMode = 0
386 v1 = gEve.GetDefaultViewer()
387 v1.GetEveFrame().HideAllDecorations()
388 tr=gEve.GetBrowser().GetTabRight()
389 t0 = tr.GetTabTab(0)
390 t0.SetText(ROOT.TGString('3D'))
391#
392# some default setup
393 SND = ['SciFi','Wall','volVetoBar ','volFeBlock',' volMuUpstreamBar ','volMuDownstreamBar_hor ','volMuDownstreamBar_ver ']
394 tunnel = sGeo.GetVolume('Tunnel')
395 tunnel.SetVisibility(0)
396 tunnel.SetVisDaughters(0)
397 br = gEve.GetBrowser()
398 br.SetWindowName('SND@LHC Eve Window')
399 br.SetWidth(1600)
400 sc = gEve.GetScenes()
401 geoscene = sc.FindChild('Geometry scene')
402 gEve.ElementChanged(geoscene,True,True)
403
404 v = gEve.GetDefaultGLViewer()
405 camera = v.CurrentCamera()
406 for i in range(2): # don't know why this needs to be executed twice to update the screen
407 camera.Reset()
408 center = array('d',[-19.,46.,400.])
409 camera.Configure(1.6, 0, center, -1.57, 0)
410 v.DoDraw()
411
412 def update(self):
413 sc = gEve.GetScenes()
414 geoscene = sc.FindChild('Geometry scene')
415 gEve.ElementChanged(geoscene,True,True)
416
417 def NextEvent(self,i=-1):
418 if i<0: self.n+=1
419 else : self.n=i
420 fRun.Run(self.n,self.n+1) # go for first event
421 if sTree.FindBranch("Digi_MuFilterHits") or sTree.FindBranch("Digi_ScifiHits"):
422 self.digi.ExecuteTask()
423 print('Event %i ready'%(self.n))
424# make pointsets pickable
425 if isMC:
426 for x in mcHits:
427 p = ROOT.gEve.GetCurrentEvent().FindChild(mcHits[x].GetName())
428 if p:
429 p.SetPickable(ROOT.kTRUE)
430 p.SetTitle(p.__repr__())
431 def rotateView(self,hor=0,ver=0):
432 v = ROOT.gEve.GetDefaultGLViewer()
433 cam = v.CurrentCamera()
434 cam.Reset()
435 if hor!=0 or ver!=0:
436 cam.RotateRad(hor,ver)
437 v.DoDraw()
438 def topView(self):
439 self.rotateViewrotateView(ROOT.TMath.Pi()/2.,0.) # rotation around z axis
440 def bottomView(self):
441 self.rotateViewrotateView(-ROOT.TMath.Pi()/2.,0.) # rotation around z axis
442 def frontView(self):
443 self.rotateViewrotateView(0.,ROOT.TMath.Pi()/2.) # rotation around y or x axis
444 def backView(self):
445 self.rotateViewrotateView(0.,-ROOT.TMath.Pi()/2.) # rotation around y or x axis
446 def leftView(self):
447 self.rotateViewrotateView(0.,ROOT.TMath.Pi()) # rotation around y or x axis
448 def rightView(self):
449 self.rotateViewrotateView(0.,ROOT.TMath.Pi()) # rotation around y or x axis
450 def transparentMode(self,mode='on'):
451 for m in transparentMaterials:
452 mat = ROOT.gGeoManager.GetMaterial(m)
453 if not mat:continue
454 if mode.lower()=='on' or mode==1:
455 mat.SetTransparency(transparentMaterials[m])
456 vol = sGeo.FindVolumeFast('HorMatVolume')
457 vol.SetTransparency(99)
458 vol = sGeo.FindVolumeFast('VertMatVolume')
459 vol.SetTransparency(99)
460 self.TransparentMode = 1
461 else:
462 mat.SetTransparency("\x00")
463 self.TransparentMode = 0
464 self.update()
465 def light(self,step=0.2,source='all'):
466 v1 = gEve.GetDefaultViewer()
467 gl = v1.GetGLViewer()
468 status = {}
469 sources = ["Side","Front","Specular"]
470 ls = gl.GetLightSet()
471 for s in sources:
472 exec("status['"+s+"']=ls.Get"+s+"Power()")
473 if source!='all': sources = [source]
474 for s in sources:
475 newPw = str(status[s]+step)
476 exec("ls.Set"+s+"Power("+newPw+")")
477 self.update()
478 def fittrack(self):
479 trackTask.ExecuteTask()
480 print('tracks found',len(sTree.fittedTracks) )
481 self.tracks.DrawFittedTracks()
482
483# add projections DOES NOT WORK YET AS FORESEEN, under investigation. 30.11.2016
484def projection():
485#if 1>0:
486 # camera
487 s = ROOT.gEve.SpawnNewScene("Projected Event")
488 ROOT.gEve.GetDefaultViewer().AddScene(s)
489 v = ROOT.gEve.GetDefaultGLViewer()
490 v.SetCurrentCamera(ROOT.TGLViewer.kCameraOrthoXOY)
491 cam = v.CurrentCamera()
492 cam.SetZoomMinMax(0.2, 20)
493 # projections
494 mng = ROOT.TEveProjectionManager(ROOT.TEveProjection.kPT_RPhi)
495 s.AddElement(mng)
496 axes = ROOT.TEveProjectionAxes(mng)
497 axes.SetTitle("TEveProjections demo")
498 s.AddElement(axes)
499 ROOT.gEve.AddToListTree(axes, ROOT.kTRUE)
500 ROOT.gEve.AddToListTree(mng, ROOT.kTRUE)
501
503#if 1>0:
504 v = gEve.GetViewers()
505 vw = v.FindChild('Viewer 1')
506 if vw: vw.SetName('3d')
507 sev = ROOT.gEve.SpawnNewViewer("Scaled 2D")
508 smng = ROOT.TEveProjectionManager(ROOT.TEveProjection.kPP_Plane)
509 sp = smng.GetProjection()
510 sp.SetUsePreScale(ROOT.kTRUE)
511 sp.AddPreScaleEntry(2, 100000000., 0.1)
512 ss = ROOT.gEve.SpawnNewScene("Scaled Geom")
513 sev.AddScene(ss)
514 ss.AddElement(smng)
515 N = sGeo.GetTopNode()
516 TNod=ROOT.TEveGeoTopNode(sGeo, N, 1, 3, 10)
517 ss.AddElement(TNod)
518 eventscene = ROOT.gEve.SpawnNewScene('Scaled event')
519 eventscene.AddElement(ROOT.FairEventManager.Instance())
520 sev.AddScene(eventscene)
521 eventscene.AddElement(smng)
522 ROOT.gEve.GetBrowser().GetTabRight().SetTab(1)
523 ROOT.gEve.FullRedraw3D(ROOT.kTRUE)
524
525def storeCameraSetting(fname='camSetting.root'):
526 f = ROOT.TFile.Open(fname, "RECREATE");
527 cam = ROOT.gEve.GetDefaultGLViewer().CurrentCamera()
528 cam.Write()
529 f.Close()
530def readCameraSetting(fname='camSetting.root'):
531 f = ROOT.TFile.Open(fname)
532 cam = ROOT.gEve.GetDefaultGLViewer().CurrentCamera()
533 f.GetKey(cam.ClassName()).Read(cam)
534 cam.IncTimeStamp()
535 gEve.GetDefaultGLViewer().RequestDraw()
536 f.Close()
537
538# set display properties for tau nu target
539
540
541def switchOf(tag):
542 sc = gEve.GetScenes()
543 geoscene = sc.FindChild('Geometry scene')
544 for v in top.GetNodes():
545 vname = v.GetName()
546 if not vname.find(tag)<0:
547 v.SetVisibility(0)
548 v.SetVisDaughters(0)
549 gEve.ElementChanged(geoscene,True,True)
550
551def switchOn(tag):
552 sc = gEve.GetScenes()
553 geoscene = sc.FindChild('Geometry scene')
554 for v in top.GetNodes():
555 vname = v.GetName()
556 if not vname.find(tag)<0:
557 print('switch on ',vname)
558 v.SetVisibility(1)
559 v.SetVisDaughters(1)
560 gEve.ElementChanged(geoscene,True,True)
561
562
563def switchOfAll(exc):
564 sc = gEve.GetScenes()
565 geoscene = sc.FindChild('Geometry scene')
566 for v in top.GetNodes():
567 vname = v.GetName()
568 if not vname.find('cave')< 0 : continue
569 todo = True
570 for tag in exc:
571 if not tag.find(vname)<0: todo = False
572 if todo:
573 v.SetVisibility(0)
574 v.SetVisDaughters(0)
575 gEve.ElementChanged(geoscene,True,True)
576
577def switchOnAll(exc):
578 sc = gEve.GetScenes()
579 geoscene = sc.FindChild('Geometry scene')
580 for v in top.GetNodes():
581 vname = v.GetName()
582 if not vname.find('cave')< 0 : continue
583 todo = True
584 for tag in exc:
585 if not tag.find(vname)<0: todo = False
586 if todo:
587 v.SetVisibility(1)
588 v.SetVisDaughters(1)
589 gEve.ElementChanged(geoscene,True,True)
590
591def select(pattern):
592 exc = []
593 for v in sGeo.GetListOfVolumes():
594 vname = v.GetName()
595 if not vname.find(pattern) < 0 : exc.append(vname)
596 return exc
597
598def search(lvdict,tag):
599 for x in lvdict:
600 if not x.find(tag)<0: print(x)
601
602#----Load the default libraries------
603from basiclibs import *
604# ----- Reconstruction run -------------------------------------------
605fRun = ROOT.FairRunAna()
606ioman = ROOT.FairRootManager.Instance()
607
608if options.geoFile:
609 if options.geoFile[0:4] == "/eos": options.geoFile=ROOT.gSystem.Getenv("EOSSHIP")+options.geoFile
610 fRun.SetGeomFile(options.geoFile)
611
612if options.InputFile[0:4] == "/eos": options.InputFile=ROOT.gSystem.Getenv("EOSSHIP")+options.InputFile
613
614f=ROOT.TFile.Open(options.InputFile)
615
616isMC = True
617if f.FindKey('rawConv'):
618 ioman.SetTreeName('rawConv')
619 isMC = False
620
621outFile = ROOT.TMemFile('dummy','CREATE')
622source = ROOT.FairFileSource(f)
623fRun.SetSource(source)
624sink = ROOT.FairRootFileSink(outFile)
625fRun.SetSink(sink)
626
627if options.houghTransform:
628 import SndlhcMuonReco
629 muon_reco_task = SndlhcMuonReco.MuonReco()
630 fRun.AddTask(muon_reco_task)
631else:
632 import SndlhcTracking
634 trackTask.SetName('simpleTracking')
635 fRun.AddTask(trackTask)
636
637#avoiding some error messages
638xrdb = ROOT.FairRuntimeDb.instance()
639xrdb.getContainer("FairBaseParSet").setStatic()
640xrdb.getContainer("FairGeoParSet").setStatic()
641
642import SndlhcGeo
643geo = SndlhcGeo.GeoInterface(options.geoFile)
644modules = geo.modules
645lsOfGlobals = ROOT.gROOT.GetListOfGlobals()
646lsOfGlobals.Add(modules['Scifi'])
647lsOfGlobals.Add(modules['MuFilter'])
648
649if options.ParFile:
650 rtdb = fRun.GetRuntimeDb()
651 parInput1 = ROOT.FairParRootFileIo()
652 parInput1.open(options.ParFile)
653 rtdb.setFirstInput(parInput1)
654
655fMan= ROOT.FairEventManager()
656fMan.SetMaxEnergy(5000.) # default is 25 GeV only !
657fMan.SetMinEnergy(0.1) # 100 MeV
658fMan.SetEvtMaxEnergy(5000.) # what is the difference between EvtMaxEnergy and MaxEnergy ?
659fMan.SetPriOnly(False) # display everything
660
661if isMC:
662 mcHits = {}
663 mcHits['MuFilterPoints'] = ROOT.FairMCPointDraw("MuFilterPoint", ROOT.kBlue, ROOT.kFullSquare)
664 mcHits['ScifiPoints'] = ROOT.FairMCPointDraw("ScifiPoint", ROOT.kGreen, ROOT.kFullCircle)
665 mcHits['EmulsionDetPoints'] = ROOT.FairMCPointDraw("EmulsionDetPoint", ROOT.kMagenta, ROOT.kFullDiamond)
666 for x in mcHits: fMan.AddTask(mcHits[x])
667
668fMan.Init(1,4,10) # default Init(visopt=1, vislvl=3, maxvisnds=10000)
669#visopt, set drawing mode :
670# option=0 (default) all nodes drawn down to vislevel
671# option=1 leaves and nodes at vislevel drawn
672# option=2 path is drawn
673# vislvl
674#
675fRman = ROOT.FairRootManager.Instance()
676
677sTree = ioman.GetInTree()
678lsOfGlobals.Add(sTree)
679# backward compatbility for early converted events
680sTree.GetEvent(0)
681if sTree.GetBranch('Digi_MuFilterHit'): sTree.Digi_MuFilterHits = sTree.Digi_MuFilterHit
682
683sGeo = ROOT.gGeoManager
684top = sGeo.GetTopVolume()
685gEve = ROOT.gEve
686
687br = gEve.GetBrowser()
688br.HideBottomTab() # make more space for graphics
689br.SetWindowName('SND@LHC Eve Window')
690
691SHiPDisplay = EventLoop()
692import eveGlobal
693eveGlobal.SHiPDisplay = SHiPDisplay
694SHiPDisplay.SetName('SHiP Displayer')
695lsOfGlobals.Add(SHiPDisplay)
696
697import SndlhcTracking
698trackTask = SndlhcTracking.Tracking()
699
700SHiPDisplay.InitTask()
701
702print('Help on GL viewer can be found by pressing Help button followed by help on GL viewer')
703print('With the camera button, you can switch to different views.')
704# short cuts
705# w go to wire frame
706# r smooth display
707# t technical display
708# e black<->white background
709# j zoom in
710# k zoom out
711# d GL debug mode
712
714 comp = SHiPDisplay.tracks.comp
715 comp.OpenCompound()
716 n = -1
717 ntot = 0
718 fPos = ROOT.TVector3()
719 fMom = ROOT.TVector3()
720 delZ = 10*u.m
721 for fT in sTree.MCTrack:
722 n+=1
723 DTrack = ROOT.TEveLine()
724 DTrack.SetPickable(ROOT.kTRUE)
725 DTrack.SetTitle(fT.__repr__())
726 fT.GetStartVertex(fPos)
727 fT.GetMomentum(fMom)
728 hitlist = {}
729 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
730 z = fPos.Z() + delZ
731 slx,sly = fMom.X()/fMom.Z(),fMom.Y()/fMom.Z()
732 hitlist[z] = [fPos.X()+slx*delZ,fPos.Y()+sly*delZ]
733 for z in hitlist.keys():
734 DTrack.SetNextPoint(hitlist[z][0],hitlist[z][1],z)
735 p = pdg.GetParticle(fT.GetPdgCode())
736 if p : pName = p.GetName()
737 else: pName = str(fT.GetPdgCode())
738 DTrack.SetName('MCTrack_'+str(n)+'_'+pName)
739 c = ROOT.kYellow
740 DTrack.SetMainColor(c)
741 DTrack.SetLineWidth(3)
742 comp.AddElement(DTrack)
743 ntot+=1
744 comp.CloseCompound()
745 gEve.ElementChanged(SHiPDisplay.tracks.evscene,True,True)
746
747
748
749
set(INCLUDE_DIRECTORIES ${SYSTEM_INCLUDE_DIRECTORIES} ${VMC_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/shipdata ${CMAKE_SOURCE_DIR}/shipLHC ${CMAKE_SOURCE_DIR}/analysis/cuts ${CMAKE_SOURCE_DIR}/analysis/tools ${FMT_INCLUDE_DIR}) include_directories($
Definition CMakeLists.txt:1
ExecuteTask(self, option='')
DrawFittedTracks(self, option='')
ExecuteTask(self, option='')
DrawMCTracks(self, option='')
light(self, step=0.2, source='all')
transparentMode(self, mode='on')
rotateView(self, hor=0, ver=0)
select(pattern)
readCameraSetting(fname='camSetting.root')
search(lvdict, tag)
printMCTrack(n, MCTrack)
storeCameraSetting(fname='camSetting.root')
configure(darkphoton=None)