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,tkinter,atexit
3ROOT.gROOT.ProcessLine('#include "FairEventHeader.h"')
4# only helps if class version in FairEventHeader.h is increased
5
6from argparse import ArgumentParser
7from ShipGeoConfig import ConfigRegistry
8from rootpyPickler import Unpickler
9from array import array
10import shipunit as u
11from decorators import *
12import shipRoot_conf,shipDet_conf
14
15def evExit():
16 if ROOT.gROOT.FindObject('Root Canvas EnergyLoss'):
17 print("make suicide before framework makes seg fault")
18 os.kill(os.getpid(),9)
19# apperantly problem disappeared in more recent root versions
20if float(ROOT.gROOT.GetVersion().split('/')[0])>6.07: atexit.register(evExit)
21
22fMan = None
23fRun = None
24pdg = ROOT.TDatabasePDG.Instance()
25g = ROOT.gROOT
26gEnv = ROOT.gEnv
27gEnv.SetValue('Eve.Viewer.HideMenus','off')
28
29mcEngine = "TGeant4"
30simEngine = "Pythia8"
31withGeo = False
32withMCTracks = True
33withAllMCTracks = False
34# muon shield strawtube decay vessel
35transparentMaterials = {'iron':80,'aluminium':80,'mylar':60,'STTmix9010_2bar':95,'steel':80,'Aluminum':80,'Scintillator':80,
36# tau nu detector
37 'CoilCopper':70,'copper':90,'HPTgas':70,'Bakelite':70,'RPCgas':70,'TTmedium':70,
38# charm detector
39 'CoilAluminium':70,'molybdenum':80,'PlasticBase':70,'tantalum':70}
40#
41
42parser = ArgumentParser()
43
44parser.add_argument("-f", "--inputFile", dest="InputFile", help="Input file", required=True)
45parser.add_argument("-g", "--geoFile", dest="geoFile", help="ROOT geofile", required=True)
46parser.add_argument("-p", "--paramFile", dest="ParFile", help="FairRoot param file", required=False, default=None)
47parser.add_argument("--Debug", dest="Debug", help="Switch on debugging", required=False, action="store_true")
48parser.add_argument("-o", "--outFile", dest="OutputFile", help="Output file", required=False,default=None)
49parser.add_argument("-i", dest="HiddenParticleID", help="HiddenParticle ID", required=False,default=9900015)
50
51options = parser.parse_args()
52if options.InputFile.find('_D')>0: withGeo = True
53
54def printMCTrack(n,MCTrack):
55 mcp = MCTrack[n]
56 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, \
57 mcp.GetStartX()/u.m,mcp.GetStartY()/u.m,mcp.GetStartZ()/u.m,mcp.GetMotherId() ))
58def dump(pcut=0):
59 print(' # pid px py pz vx vy vz mid')
60 n=-1
61 for mcp in sTree.MCTrack:
62 n+=1
63 if mcp.GetP()/u.GeV < pcut : continue
64 printMCTrack(n,sTree.MCTrack)
66 print(' # converged Ndf chi2/Ndf P Pt MCid')
67 n=-1
68 for ft in sTree.FitTracks:
69 n+=1
70 fitStatus = ft.getFitStatus()
71 fitState = ft.getFittedState()
72 mom = fitState.getMom()
73 print('%3i %6i %4i %6.3F %6.3F %6.3F %6i '%(n,fitStatus.isFitConverged(),\
74 fitStatus.getNdf(),fitStatus.getChi2()/fitStatus.getNdf(),\
75 mom.Mag()/u.GeV,mom.Pt()/u.GeV,sTree.fitTrack2MC[n] ))
77 print(' # P Pt[GeV/c] DOCA[mm] Rsq Vz[m] d1 d2')
78 n=-1
79 for aP in sTree.Particles:
80 n+=1
81 doca = -1.
82 if aP.GetMother(1)==99: # DOCA is set
83 doca = aP.T()
84 Rsq = (aP.Vx()/(2.45*u.m) )**2 + (aP.Vy()/((10./2.-0.05)*u.m) )**2
85 print('%3i %6.3F %6.3F %9.3F %6.3F %6.3F %4i %4i '%(n,aP.P()/u.GeV,aP.Pt()/u.GeV,\
86 doca/u.mm,Rsq,aP.Vz()/u.m,aP.GetDaughter(0),aP.GetDaughter(1) ))
87class DrawVetoDigi(ROOT.FairTask):
88 " My Fair Task"
89 def InitTask(self):
90 self.comp = ROOT.TEveCompound('Veto Digis')
91 gEve.AddElement(self.comp)
92 sc = gEve.GetScenes()
93 self.evscene = sc.FindChild('Event scene')
94 def FinishEvent(self):
95 pass
96 def ExecuteTask(self,option=''):
97 self.comp.DestroyElements()
98 self.comp.OpenCompound()
99 nav = ROOT.gGeoManager.GetCurrentNavigator()
100 for digi in sTree.Digi_SBTHits:
101 if not digi.isValid(): continue
102 node = digi.GetNode()
103 shape = node.GetVolume().GetShape()
104 bx = ROOT.TEveBox( node.GetName() )
105 bx.SetPickable(ROOT.kTRUE)
106 bx.SetTitle(digi.__repr__())
107 bx.SetMainColor(ROOT.kMagenta+3)
108 dx,dy,dz = shape.GetDX(),shape.GetDY(),shape.GetDZ()
109 o = shape.GetOrigin()
110 master = array('d',[0,0,0])
111 n=0
112 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]]:
113 origin = array('d',[edge[0]+o[0],edge[1]+o[1],edge[2]+o[2]])
114 nav.LocalToMaster(origin,master)
115 bx.SetVertex(n,master[0],master[1],master[2])
116 n+=1
117 self.comp.AddElement(bx)
118 self.comp.CloseCompound()
119 gEve.ElementChanged(self.evscene,True,True)
120class DrawEcalCluster(ROOT.FairTask):
121 " My Fair Task"
122 def InitTask(self,ecalStructure):
123# prepare ecal structure
124 self.comp = ROOT.TEveCompound('Ecal Clusters')
125 gEve.AddElement(self.comp)
126 sc = gEve.GetScenes()
127 self.evscene = sc.FindChild('Event scene')
128 mE = top.GetNode('Ecal_1').GetMatrix()
129 self.z_ecal = mE.GetTranslation()[2]
130 self.ecalStructure = ecalStructure
131 def FinishEvent(self):
132 pass
133 def ExecuteTask(self,option=''):
134 self.comp.DestroyElements()
135 self.comp.OpenCompound()
136 cl=-1
137 for aClus in sTree.EcalClusters:
138# ecal cell dx=dy=2cm, dz=21.84cm
139 cl+=1
140 for i in range( aClus.Size() ):
141 mccell = self.ecalStructure.GetHitCell(aClus.CellNum(i)) # Get i'th cell of the cluster.
142 if not mccell: continue
143 x1,y1,x2,y2,dz = mccell.X1(),mccell.Y1(),mccell.X2(),mccell.Y2(),mccell.GetEnergy()/u.GeV*0.5*u.m
144 if mccell.GetEnergy()/u.MeV < 4. : continue
145# ADC noise simulated Guassian with \sigma=1 MeV
146 DClus = ROOT.TEveBox()
147 DClus.SetName('EcalCluster_'+str(cl)+'_'+str(i))
148 DClus.SetPickable(ROOT.kTRUE)
149 DClus.SetTitle(aClus.__repr__())
150 DClus.SetMainColor(ROOT.kRed-4)
151 DClus.SetMainTransparency("\x10")
152 DClus.SetVertex(0,x1,y1,self.z_ecal)
153 DClus.SetVertex(1,x1,y1,self.z_ecal+dz)
154 DClus.SetVertex(2,x2,y1,self.z_ecal+dz)
155 DClus.SetVertex(3,x2,y1,self.z_ecal)
156 DClus.SetVertex(4,x1,y2,self.z_ecal)
157 DClus.SetVertex(5,x1,y2,self.z_ecal+dz)
158 DClus.SetVertex(6,x2,y2,self.z_ecal+dz)
159 DClus.SetVertex(7,x2,y2,self.z_ecal)
160 self.comp.AddElement(DClus)
161 self.comp.CloseCompound()
162 gEve.ElementChanged(self.evscene,True,True)
163 def DrawParticle(self,n):
164 self.comp.OpenCompound()
165 DTrack = ROOT.TEveLine()
166 DTrack.SetPickable(ROOT.kTRUE)
167 DTrack.SetMainColor(ROOT.kCyan)
168 DTrack.SetLineWidth(4)
169 aP=sTree.Particles[n]
170 DTrack.SetTitle(aP.__repr__())
171 DTrack.SetName('Prtcle_'+str(n))
172 DTrack.SetNextPoint(aP.Vx(),aP.Vy(),aP.Vz())
173 lam = (self.Targetz - aP.Vz())/aP.Pz()
174 DTrack.SetNextPoint(aP.Vx()+lam*aP.Px(),aP.Vy()+lam*aP.Py(),self.Targetz)
175 self.comp.AddElement(DTrack)
176 self.comp.CloseCompound()
177 gEve.ElementChanged(self.evscene,True,True)
178#
179class DrawTracks(ROOT.FairTask):
180 " My Fair Task"
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
216 def FinishEvent(self):
217 pass
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)
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)
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)
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")
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#
407import evd_fillEnergy
408class IO():
409 def __init__(self):
410 self.master = tkinter.Tk()
411 self.master.title('SHiP Event Display GUI')
412 self.master.geometry(u'320x580+165+820')
413 self.fram1 = tkinter.Frame(self.master)
414 b = tkinter.Button(self.fram1, text="Next Event",command=self.nextEventnextEventnextEvent)
415 b.pack(fill=tkinter.BOTH, expand=1)
416 label = tkinter.Label(self.fram1, text='Event number:')
417 label["relief"] = tkinter.RAISED
418 entry = tkinter.Entry(self.fram1)
419 entry["foreground"] = "blue"
420 label.pack(side=tkinter.LEFT)
421 entry.pack(side=tkinter.RIGHT)
422 self.contents = tkinter.IntVar()
423 # set it to some value
424 self.n = 0
425 self.contents.set(self.n)
426 # tell the entry widget to watch this variable
427 entry["textvariable"] = self.contents
428 # and here we get a callback when the user hits return.
429 # we will have the program print out the value of the
430 # application variable when the user hits return
431 entry.bind('<Key-Return>', self.nextEventnextEventnextEvent)
432 self.lbut = {}
433 x = 'withMC'
434 a = tkinter.IntVar()
435 if globals()['withMCTracks']: a.set(1)
436 else: a.set(0)
437 self.lbut[x] = tkinter.Checkbutton(self.master,text="with MC Tracks",compound=tkinter.LEFT,variable=a)
438 self.lbut[x].var = a
439 self.lbut[x]['command'] = self.toogleMCTrackstoogleMCTracks
440 self.lbut[x].pack(side=tkinter.TOP)
441 self.geoscene = ROOT.gEve.GetScenes().FindChild("Geometry scene")
442 for v in top.GetNodes():
443 x=v.GetName()
444 cmd = 'toogle("'+x+'")'
445 a = tkinter.IntVar()
446 assemb = "Assembly" in v.GetVolume().__str__()
447 if v.IsVisible() or (assemb and v.IsVisDaughters()): a.set(1)
448 else : a.set(0)
449 self.lbut[x] = tkinter.Checkbutton(self.master,text=x.replace('_1',''),compound=tkinter.LEFT,variable=a)
450 self.lbut[x].var = a
451 self.lbut[x]['command'] = lambda j=x: self.toogletoogle(j)
452 self.lbut[x].pack(side=tkinter.BOTTOM)
453 self.fram1.pack()
454# add ship actions to eve display
455 gEve = ROOT.gEve
456 slot = ROOT.TEveWindow.CreateWindowInTab(gEve.GetBrowser().GetTabLeft())
457 slot.SetShowTitleBar(ROOT.kFALSE)
458 packs = slot.MakePack();
459 packs.SetShowTitleBar(ROOT.kFALSE);
460 packs.SetElementName("SHiP actions")
461 packs.SetHorizontal()
462 slot = packs.NewSlot()
463 frame = slot.MakeFrame()
464 frame.SetElementName("commands")
465 frame.SetShowTitleBar(ROOT.kFALSE)
466 cf = frame.GetGUICompositeFrame()
467 hf = ROOT.TGVerticalFrame(cf)
468 hf.SetCleanup(ROOT.kLocalCleanup)
469 hf.SetWidth(150)
470 cf.AddFrame(hf)
471 guiFrame = ROOT.TGVerticalFrame(hf)
472 hf.AddFrame(guiFrame, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
473 guiFrame.SetCleanup(ROOT.kDeepCleanup)
474 b = ROOT.TGTextButton(guiFrame, "Add particle follower")
475 b.SetWidth(150)
476 b.SetToolTipText('start new window with top projection and energy loss')
477 b.SetCommand('TPython::ExecScript("'+os.environ['FAIRSHIP']+'/macro/evd_addParticleFollower.py")')
478 guiFrame.AddFrame(b, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
479 bn = ROOT.TGTextButton(guiFrame, "fill histogram")
480 bn.SetWidth(150)
481 bn.SetToolTipText('Fill histogram with energy along flight path')
482 bn.SetCommand('TPython::ExecScript("'+os.environ['FAIRSHIP']+'/macro/evd_fillEnergy.py")')
483 guiFrame.AddFrame(bn, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
484 bt = ROOT.TGTextButton(guiFrame, "switch transparent mode on/off")
485 bt.SetWidth(150)
486 bt.SetToolTipText('switch transparent mode on/off for better visibility of tracks')
487 bt.SetCommand('TPython::ExecScript("'+os.environ['FAIRSHIP']+'/macro/evd_transparentMode.py")')
488 guiFrame.AddFrame(bt, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
489 bnx = ROOT.TGTextButton(guiFrame, "next event")
490 bnx.SetWidth(150)
491 bnx.SetToolTipText('click for next event')
492 bnx.SetCommand('TPython::ExecScript("'+os.environ['FAIRSHIP']+'/macro/evd_nextEvent.py")')
493 guiFrame.AddFrame(bnx, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
494 bzt = ROOT.TGTextButton(guiFrame, "synch zoom top->side")
495 bzt.SetWidth(150)
496 bzt.SetToolTipText('synchronize zoom top with side')
497 bzt.SetCommand('TPython::ExecScript("'+os.environ['FAIRSHIP']+'/macro/evd_synchZoomt.py")')
498 guiFrame.AddFrame(bzt, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
499 bzs = ROOT.TGTextButton(guiFrame, "synch zoom side->top")
500 bzs.SetWidth(150)
501 bzs.SetToolTipText('synchronize zoom side with top')
502 bzs.SetCommand('TPython::ExecScript("'+os.environ['FAIRSHIP']+'/macro/evd_synchZooms.py")')
503 guiFrame.AddFrame(bzs, ROOT.TGLayoutHints(ROOT.kLHintsExpandX))
504#
505 cf.MapSubwindows()
506 cf.Layout()
507 cf.MapWindow()
508 def nextEvent(self,event=None):
509 i = int(self.contents.get())
510 if i==self.n: self.n+=1
511 else : self.n=i
512 self.contents.set(self.n)
513 SHiPDisplay.NextEvent(self.n)
514 def toogleMCTracks(self):
515 tl = fRun.GetMainTask().GetListOfTasks()
516 geoTask = tl.FindObject("GeoTracks")
517 if globals()['withMCTracks']:
518 globals()['withMCTracks'] = False
519 self.lbut['withMC'].var.set(1)
520 if geoTask: geoTask.SetActive(0)
521 else:
522 globals()['withMCTracks'] = True
523 self.lbut['withMC'].var.set(0)
524 if geoTask: geoTask.SetActive(1)
525 def toogle(self,x):
526 v = top.GetNode(x)
527 assemb = "Assembly" in v.GetVolume().__str__()
528 if v.IsVisible()>0 or assemb and v.IsVisDaughters()>0 :
529 print("switch off ",x)
530 v.SetVisibility(0)
531 v.SetVisDaughters(0)
532 self.lbut[x].var.set(0)
533 else:
534 print("switch on ",x)
535 if assemb: v.SetVisDaughters(1)
536 else: v.SetVisibility(1)
537 self.lbut[x].var.set(1)
538 gEve.ElementChanged(self.geoscene,True,True)
539 for v in top.GetNodes():
540 x = v.GetName()
541 if x in self.lbut:
542 assemb = "Assembly" in v.GetVolume().__str__()
543 if v.IsVisible()>0 or assemb and v.IsVisDaughters()>0 : self.lbut[x].var.set(1)
544 else : self.lbut[x].var.set(0)
545#
546class EventLoop(ROOT.FairTask):
547 " My Fair Task"
548 def InitTask(self):
549 self.n = 0
550 self.first = True
551 if sGeo.GetVolume('volTarget'): DisplayNuDetector()
552 if sGeo.GetVolume('Ecal'):
553 # initialize ecalStructure
554 ecalGeo = ecalGeoFile+'z'+str(ShipGeo.ecal.z)+".geo"
555 if not ecalGeo in os.listdir(os.environ["FAIRSHIP"]+"/geometry"): shipDet_conf.makeEcalGeoFile(ShipGeo.ecal.z,ShipGeo.ecal.File)
556 self.ecalFiller = ROOT.ecalStructureFiller("ecalFiller", 0,ecalGeo)
557 if ecalGeoFile.find("5x10")<0:
558 self.ecalFiller.SetUseMCPoints(ROOT.kFALSE)
559 print("ecal cluster display disabled, seems only to work with 5x10m ecal geofile")
560 else: self.ecalFiller.SetUseMCPoints(ROOT.kTRUE)
561 self.ecalFiller.StoreTrackInformation()
562 rc = sTree.GetEvent(0)
563 self.ecalStructure = self.ecalFiller.InitPython(sTree.EcalPointLite)
565 self.calos.InitTask(self.ecalStructure)
567 self.veto.InitTask()
569 self.tracks.InitTask()
570# create SHiP GUI
571 self.ioBar = IO()
573 v1 = gEve.GetDefaultViewer()
574 v1.GetEveFrame().HideAllDecorations()
575 tr=gEve.GetBrowser().GetTabRight()
576 t0 = tr.GetTabTab(0)
577 t0.SetText(ROOT.TGString('3D'))
578 def NextEvent(self,i=-1):
579 if i<0: self.n+=1
580 else : self.n=i
581 fRun.Run(self.n,self.n+1) # go for first event
582# check if tracks are made from real pattern recognition
583 if sTree.GetBranch("FitTracks_PR"): sTree.FitTracks = sTree.FitTracks_PR
584 if sTree.GetBranch("fitTrack2MC_PR"): sTree.fitTrack2MC = sTree.fitTrack2MC_PR
585 if sTree.GetBranch("Particles_PR"): sTree.Particles = sTree.Particles_PR
586 if hasattr(self,"tracks"): self.tracks.ExecuteTask()
587 if sTree.FindBranch("EcalClusters"):
588 if sTree.EcalClusters.GetEntries()>0:
589 self.ecalFiller.Exec('start',sTree.EcalPointLite)
590 self.calos.ExecuteTask()
591 if sTree.FindBranch("Digi_SBTHits"): self.veto.ExecuteTask()
592 if ROOT.gROOT.FindObject('Root Canvas EnergyLoss'): evd_fillEnergy.execute()
593 print('Event %i ready'%(self.n))
594# make pointsets pickable
595 for x in mcHits:
596 p = ROOT.gEve.GetCurrentEvent().FindChild(mcHits[x].GetName())
597 if p:
598 p.SetPickable(ROOT.kTRUE)
599 p.SetTitle(p.__repr__())
600 def rotateView(self,hor=0,ver=0):
601 v = ROOT.gEve.GetDefaultGLViewer()
602 cam = v.CurrentCamera()
603 cam.Reset()
604 if hor!=0 or ver!=0:
605 cam.RotateRad(hor,ver)
606 v.DoDraw()
607 def topView(self):
608 self.rotateViewrotateView(ROOT.TMath.Pi()/2.,0.) # rotation around z axis
609 def bottomView(self):
610 self.rotateViewrotateView(-ROOT.TMath.Pi()/2.,0.) # rotation around z axis
611 def frontView(self):
612 self.rotateViewrotateView(0.,ROOT.TMath.Pi()/2.) # rotation around y or x axis
613 def backView(self):
614 self.rotateViewrotateView(0.,-ROOT.TMath.Pi()/2.) # rotation around y or x axis
615 def leftView(self):
616 self.rotateViewrotateView(0.,ROOT.TMath.Pi()) # rotation around y or x axis
617 def rightView(self):
618 self.rotateViewrotateView(0.,ROOT.TMath.Pi()) # rotation around y or x axis
619 def transparentMode(self,mode='on'):
620 for m in transparentMaterials:
621 mat = ROOT.gGeoManager.GetMaterial(m)
622 if not mat:continue
623 if mode.lower()=='on' or mode==1:
624 mat.SetTransparency(transparentMaterials[m])
625 self.TransparentMode = 1
626 else:
627 mat.SetTransparency("\x00")
628 self.TransparentMode = 0
629 sc = gEve.GetScenes()
630 geoscene = sc.FindChild('Geometry scene')
631 if geoscene: gEve.ElementChanged(geoscene,True,True)
632# add projections DOES NOT WORK YET AS FORESEEN, under investigation. 30.11.2016
634#if 1>0:
635 # camera
636 s = ROOT.gEve.SpawnNewScene("Projected Event")
637 ROOT.gEve.GetDefaultViewer().AddScene(s)
638 v = ROOT.gEve.GetDefaultGLViewer()
639 v.SetCurrentCamera(ROOT.TGLViewer.kCameraOrthoXOY)
640 cam = v.CurrentCamera()
641 cam.SetZoomMinMax(0.2, 20)
642 # projections
643 mng = ROOT.TEveProjectionManager(ROOT.TEveProjection.kPT_RPhi)
644 s.AddElement(mng)
645 axes = ROOT.TEveProjectionAxes(mng)
646 axes.SetTitle("TEveProjections demo")
647 s.AddElement(axes)
648 ROOT.gEve.AddToListTree(axes, ROOT.kTRUE)
649 ROOT.gEve.AddToListTree(mng, ROOT.kTRUE)
650
652#if 1>0:
653 v = gEve.GetViewers()
654 vw = v.FindChild('Viewer 1')
655 if vw: vw.SetName('3d')
656 sev = ROOT.gEve.SpawnNewViewer("Scaled 2D")
657 smng = ROOT.TEveProjectionManager(ROOT.TEveProjection.kPP_Plane)
658 sp = smng.GetProjection()
659 sp.SetUsePreScale(ROOT.kTRUE)
660 sp.AddPreScaleEntry(2, 100000000., 0.1)
661 ss = ROOT.gEve.SpawnNewScene("Scaled Geom")
662 sev.AddScene(ss)
663 ss.AddElement(smng)
664 N = sGeo.GetTopNode()
665 TNod=ROOT.TEveGeoTopNode(sGeo, N, 1, 3, 10)
666 ss.AddElement(TNod)
667 eventscene = ROOT.gEve.SpawnNewScene('Scaled event')
668 eventscene.AddElement(ROOT.FairEventManager.Instance())
669 sev.AddScene(eventscene)
670 eventscene.AddElement(smng)
671 ROOT.gEve.GetBrowser().GetTabRight().SetTab(1)
672 ROOT.gEve.FullRedraw3D(ROOT.kTRUE)
673
674def storeCameraSetting(fname='camSetting.root'):
675 f = ROOT.TFile.Open(fname, "RECREATE");
676 cam = ROOT.gEve.GetDefaultGLViewer().CurrentCamera()
677 cam.Write()
678 f.Close()
679def readCameraSetting(fname='camSetting.root'):
680 f = ROOT.TFile.Open(fname)
681 cam = ROOT.gEve.GetDefaultGLViewer().CurrentCamera()
682 f.GetKey(cam.ClassName()).Read(cam)
683 cam.IncTimeStamp()
684 gEve.GetDefaultGLViewer().RequestDraw()
685 f.Close()
687 for x in ["wire","gas","rockD","rockS","rockSFe"]:
688 xvol = sGeo.GetVolume(x)
689 if xvol: xvol.SetVisibility(0)
690 for k in range(1,7):
691 va = sGeo.GetVolume("T"+str(k))
692 if not va: continue
693 for x in va.GetNodes():
694 nm = x.GetName()
695 if not nm.find("Inner")<0 and k < 3:
696 x.SetVisDaughters(False)
697 x.SetVisibility(False)
698 if not nm.find("LiSc")<0: x.SetVisDaughters(False)
699 if not nm.find("RibPhi")<0: x.SetVisDaughters(False)
700#
701 for x in ["Ecal","Hcal"]:
702 xvol = sGeo.GetVolume(x)
703 if not xvol: continue
704 xvol.SetVisDaughters(0)
705 xvol.SetVisibility(1)
706 if x=="Ecal": xvol.SetLineColor(ROOT.kYellow)
707 else: xvol.SetLineColor(ROOT.kOrange+3)
708
709# set display properties for tau nu target
711 for x in ["Wall"]:
712 xvol = sGeo.GetVolume(x)
713 if not xvol: continue
714 xvol.SetVisDaughters(0)
715 xvol.SetVisibility(1)
716 sc = gEve.GetScenes()
717 geoscene = sc.FindChild('Geometry scene')
718 gEve.ElementChanged(geoscene,True,True)
719# draw Ecal yellow instead of black
721 sc = gEve.GetScenes()
722 geoscene = sc.FindChild('Geometry scene')
723 ecal = top.GetNode("Ecal_1")
724 if ecal :
725 ecal.GetVolume().SetLineColor(ROOT.kYellow)
726 hcal = top.GetNode("Hcal_1")
727 if hcal :
728 hcal.GetVolume().SetLineColor(ROOT.kOrange+3)
729 if ecal or hcal: gEve.ElementChanged(geoscene,True,True)
730def switchOf(tag):
731 sc = gEve.GetScenes()
732 geoscene = sc.FindChild('Geometry scene')
733 for v in top.GetNodes():
734 vname = v.GetName()
735 if not vname.find(tag)<0:
736 v.SetVisibility(0)
737 v.SetVisDaughters(0)
738 gEve.ElementChanged(geoscene,True,True)
739def switchOn(tag):
740 sc = gEve.GetScenes()
741 geoscene = sc.FindChild('Geometry scene')
742 for v in top.GetNodes():
743 vname = v.GetName()
744 if not vname.find(tag)<0:
745 print('switch on ',vname)
746 v.SetVisibility(1)
747 v.SetVisDaughters(1)
748 gEve.ElementChanged(geoscene,True,True)
750 sc = gEve.GetScenes()
751 geoscene = sc.FindChild('Geometry scene')
752 v = sGeo.FindVolumeFast('vleft')
753 v.SetVisibility(0)
754 v.SetVisDaughters(0)
755 for v in sGeo.GetListOfVolumes():
756 if v.GetName().find('wallVeto')>0:
757 v.SetVisibility(0)
758 v.SetVisDaughters(0)
759 gEve.ElementChanged(geoscene,True,True)
760
761# switch of drawing of rock
763 sc = gEve.GetScenes()
764 geoscene = sc.FindChild('Geometry scene')
765 for x in [ 'rockD', 'rockS']:
766 v = sGeo.FindVolumeFast(x)
767 v.SetVisibility(0)
768 gEve.ElementChanged(geoscene,True,True)
769def switchOfAll(exc):
770 sc = gEve.GetScenes()
771 geoscene = sc.FindChild('Geometry scene')
772 for v in top.GetNodes():
773 vname = v.GetName()
774 if not vname.find('cave')< 0 : continue
775 todo = True
776 for tag in exc:
777 if not tag.find(vname)<0: todo = False
778 if todo:
779 v.SetVisibility(0)
780 v.SetVisDaughters(0)
781 gEve.ElementChanged(geoscene,True,True)
782def switchOnAll(exc):
783 sc = gEve.GetScenes()
784 geoscene = sc.FindChild('Geometry scene')
785 for v in top.GetNodes():
786 vname = v.GetName()
787 if not vname.find('cave')< 0 : continue
788 todo = True
789 for tag in exc:
790 if not tag.find(vname)<0: todo = False
791 if todo:
792 v.SetVisibility(1)
793 v.SetVisDaughters(1)
794 gEve.ElementChanged(geoscene,True,True)
795
796def select(pattern):
797 exc = []
798 for v in sGeo.GetListOfVolumes():
799 vname = v.GetName()
800 if not vname.find(pattern) < 0 : exc.append(vname)
801 return exc
802def search(lvdict,tag):
803 for x in lvdict:
804 if not x.find(tag)<0: print(x)
805def rename(name='ship.TGeant4.root'):
806 f = ROOT.TFile(name,'UPDATE')
807 t = f.Get('cbmsim')
808 for x in t.GetListOfBranches():
809 nm = x.GetName().replace('_1','')
810 x.SetName(nm)
811 t.Write()
812 f.Close()
813
814class Rulers(ROOT.FairTask):
815 " add Ruler"
816 def __init__(self):
817 self.ruler = ROOT.TEveCompound('Rulers')
818 gEve.AddElement(self.ruler)
819 def show(self,xy=0,ticks=5):
820 self.ruler.DestroyElements()
821 self.ruler.OpenCompound()
822 xpos,ypos = -500., -1500.
823 zstart = ShipGeo.target.z0
824 zlength = ShipGeo.MuonStation3.z - zstart + 10*u.m
825 a1 = ROOT.TEveLine()
826 a1.SetNextPoint(xpos,ypos, zstart)
827 a1.SetNextPoint(xpos,ypos, zstart+zlength)
828 a1.SetMainColor(ROOT.kAzure-9)
829 a1.SetLineWidth(30)
830 #self.ruler.AddElement(a1)
831 z=zstart
832 for i in range(int(zlength/100/ticks)):
833 m = ROOT.TEveLine()
834 m.SetNextPoint(xpos,ypos, z)
835 m.SetNextPoint(xpos-1*u.m,ypos,z)
836 m.SetMainColor(ROOT.kRed)
837 m.SetLineWidth(5)
838 self.ruler.AddElement(m)
839 t1 = ROOT.TEveText(str(i*ticks)+'m')
840 t1.SetMainColor(ROOT.kGray+3)
841 t1.SetFontSize(5)
842 t1.RefMainTrans().SetPos(xpos-0.1*u.m,ypos+0.2*u.m,z)
843 self.ruler.AddElement(t1)
844 z+=ticks*u.m
845 xpos,ypos = 0., 0.
846 if xy==0: z = ShipGeo.MuonStation3.z+6*u.m
847 else: z=xy
848 ylength = 7*u.m
849 a2 = ROOT.TEveLine()
850 a2.SetNextPoint(xpos,-ylength, z)
851 a2.SetNextPoint(xpos,ylength, z)
852 a2.SetMainColor(ROOT.kAzure-9)
853 a2.SetLineWidth(30)
854 #self.ruler.AddElement(a2)
855 ypos=-ylength
856 for i in range(-int(ylength/100),int(ylength/100),1):
857 m = ROOT.TEveLine()
858 m.SetNextPoint(xpos,ypos, z)
859 m.SetNextPoint(xpos+0.05*u.m,ypos,z)
860 m.SetMainColor(ROOT.kRed)
861 m.SetLineWidth(3)
862 self.ruler.AddElement(m)
863 t1 = ROOT.TEveText(str(i)+'m')
864 t1.SetMainColor(ROOT.kGray+3)
865 t1.SetFontSize(5)
866 t1.RefMainTrans().SetPos(xpos-0.5*u.m,ypos,z)
867 self.ruler.AddElement(t1)
868 ypos+=1*u.m
869 ty = ROOT.TEveText("y-axis")
870 ty.SetFontSize(10)
871 ty.RefMainTrans().SetPos(0.,ypos+1*u.m,z)
872 ty.SetMainColor(ROOT.kRed-2)
873 self.ruler.AddElement(ty)
874 xpos,ypos = 0., 0.
875 if xy==0: z = ShipGeo.MuonStation3.z+10*u.m
876 xlength = 3*u.m
877 a3 = ROOT.TEveLine()
878 a3.SetNextPoint(-xlength,0, z)
879 a3.SetNextPoint(xlength,0, z)
880 a3.SetMainColor(ROOT.kAzure-9)
881 a3.SetLineWidth(30)
882 #self.ruler.AddElement(a3)
883 xpos=-xlength
884 for i in range(-int(xlength/100),int(xlength/100),1):
885 m = ROOT.TEveLine()
886 m.SetNextPoint(xpos,ypos, z)
887 m.SetNextPoint(xpos,ypos-0.05*u.m,z)
888 m.SetMainColor(ROOT.kRed)
889 m.SetLineWidth(3)
890 self.ruler.AddElement(m)
891 t1 = ROOT.TEveText(str(i)+'m')
892 t1.SetMainColor(ROOT.kGray+3)
893 t1.SetFontSize(5)
894 t1.RefMainTrans().SetPos(xpos,ypos-0.1*u.m,z)
895 self.ruler.AddElement(t1)
896 xpos+=1*u.m
897 tx = ROOT.TEveText("x-axis")
898 tx.SetFontSize(10)
899 tx.RefMainTrans().SetPos(xpos+1*u.m,0.,z)
900 tx.SetMainColor(ROOT.kRed-2)
901 self.ruler.AddElement(tx)
902 t1 = ROOT.TEveText("SHiP")
903 t1.SetFontSize(200)
904 t1.RefMainTrans().SetPos(0.,600.,ShipGeo.TrackStation1.z-10*u.m)
905 t1.PtrMainTrans().RotateLF(1, 3, ROOT.TMath.PiOver2())
906 t1.SetMainColor(ROOT.kOrange-2)
907 t1.SetFontMode(ROOT.TGLFont.kExtrude)
908 t1.SetLighting(ROOT.kTRUE)
909 self.ruler.AddElement(t1)
910 self.ruler.CloseCompound()
911 sc = ROOT.gEve.GetScenes()
912 geoscene = sc.FindChild('Geometry scene')
913 ROOT.gEve.ElementChanged(geoscene,True,True)
914 def remove(self):
915 self.ruler.DestroyElements()
916
917def mydebug():
918 t = g.FindObjectAny('cbmsim')
919 nev = t.GetEntriesFast()
920 t.GetEntry(0)
921# Loop over Geo tracks
922 for i in range( min(5,nev) ) :
923 t.GetEntry(i)
924 for gTr in t.GeoTracks:
925 gTr.Print()
926 part = gTr.GetParticle()
927 lorv = ROOT.TLorentzVector()
928 print('xyz E pxpypz',gTr.GetPoint(0)[0],gTr.GetPoint(0)[1] ,gTr.GetPoint(0)[2],lorv.E(),lorv.Px(),lorv.Py(),lorv.Pz())
929# Loop over MC tracks
930 for i in range( min(5,nev) ) :
931 t.GetEntry(i)
932 for gMCTr in t.MCTrack:
933 gMCTr.Print()
934 print(gMCTr.GetPdgCode(),gMCTr.GetMass(),gMCTr.GetP())
935# MC event header
936 for i in range( nev ) :
937 t.GetEntry(i)
938 print(t.MCEventHeader.GetEventID(),t.MCEventHeader.GetRunID(),t.MCEventHeader.GetZ())
939# geometrie
940 sGeo = ROOT.gGeoManager
941 cave = sGeo.GetTopVolume()
942 cave.Draw('ogl')
943# eve
944 gEve = ROOT.gEve
945#
946 sc = gEve.GetScenes()
947 geoscene = sc.FindChild('Geometry scene')
948 topnode = geoscene.FindChild('cave_1')
949 topnode.SetVisLevel(4)
950 gEve.ElementChanged(geoscene,True,True)
952 sGeo = ROOT.gGeoManager
953 vols = sGeo.GetListOfVolumes()
954 sTree = g.FindObjectAny('cbmsim')
955 sTree.GetEntry(n)
956 for s in sTree.strawtubesPoint:
957 print(vols[s.GetDetectorID()-1].GetName())
958
959#----Load the default libraries------
960from basiclibs import *
961# ----- Reconstruction run -------------------------------------------
962fRun = ROOT.FairRunAna()
963if options.geoFile:
964 if options.geoFile[0:4] == "/eos": options.geoFile=ROOT.gSystem.Getenv("EOSSHIP")+options.geoFile
965 fRun.SetGeomFile(options.geoFile)
966
967if options.InputFile[0:4] == "/eos": options.InputFile=ROOT.gSystem.Getenv("EOSSHIP")+options.InputFile
968if hasattr(fRun,'SetSource'):
969 inFile = ROOT.FairFileSource(options.InputFile)
970 fRun.SetSource(inFile)
971else:
972 fRun.SetInputFile(options.InputFile)
973if options.OutputFile == None:
974 options.OutputFile = ROOT.TMemFile('event_display_output', 'recreate')
975fRun.SetOutputFile(options.OutputFile)
976
977if options.ParFile:
978 rtdb = fRun.GetRuntimeDb()
979 parInput1 = ROOT.FairParRootFileIo()
980 parInput1.open(options.ParFile)
981 rtdb.setFirstInput(parInput1)
982
983fMan= ROOT.FairEventManager()
984fMan.SetMaxEnergy(400.) # default is 25 GeV only !
985fMan.SetMinEnergy(0.1) # 100 MeV
986fMan.SetEvtMaxEnergy(400.) # what is the difference between EvtMaxEnergy and MaxEnergy ?
987fMan.SetPriOnly(False) # display everything
988
989#----------------------Tracks and points -------------------------------------
990verbose = 0 # 3 lot of output
991if withGeo:
992 Track = ROOT.FairMCTracks("Monte-Carlo Tracks",verbose)
993 GTrack = ROOT.FairMCTracks("GeoTracks",verbose)
994 fMan.AddTask(GTrack)
995 fMan.AddTask(Track)
996
997if not fRun.GetGeoFile().FindKey('ShipGeo'):
998 # old geofile, missing Shipgeo dictionary
999 # try to figure out which ecal geo to load
1000 if sGeo.GetVolume('EcalModule3') : ecalGeoFile = "ecal_ellipse6x12m2.geo"
1001 else: ecalGeoFile = "ecal_ellipse5x10m2.geo"
1002 ShipGeo = ConfigRegistry.loadpy("$FAIRSHIP/geometry/geometry_config.py", Yheight = float(dy), EcalGeoFile = ecalGeoFile)
1003else:
1004 # new geofile, load Shipgeo dictionary written by run_simScript.py
1005 upkl = Unpickler( fRun.GetGeoFile() )
1006 ShipGeo = upkl.load('ShipGeo')
1007 if hasattr(ShipGeo,"ecal") :
1008 if hasattr(ShipGeo.ecal,"File") :
1009 ecalGeoFile = ShipGeo.ecal.File
1010mcHits = {}
1011if hasattr(ShipGeo,"MuonTagger"):
1012 mcHits['MufluxSpectrometerPoints'] = ROOT.FairMCPointDraw("MufluxSpectrometerPoint", ROOT.kRed, ROOT.kFullSquare)
1013 mcHits['MuonTaggerPoints'] = ROOT.FairMCPointDraw("MuonTaggerPoint", ROOT.kGreen, ROOT.kFullCircle)
1014 if ShipGeo.MufluxSpectrometer.muflux == False:
1015 mcHits['BoxPoints'] = ROOT.FairMCPointDraw("BoxPoint", ROOT.kBlue, ROOT.kFullDiamond)
1016 mcHits['PixelModulesPoints'] = ROOT.FairMCPointDraw("PixelModulesPoint",ROOT.kRed,ROOT.kFullCircle)
1017 mcHits['SciFiPoints'] = ROOT.FairMCPointDraw("SciFiPoint",ROOT.kGreen,ROOT.kFullSquare)
1018elif hasattr(ShipGeo,"MuFilter"):
1019 mcHits['ScifiPoints'] = ROOT.FairMCPointDraw("ScifiPoint", ROOT.kRed, ROOT.kFullDiamond)
1020 mcHits['MuFilterPoints'] = ROOT.FairMCPointDraw("MuFilterPoint", ROOT.kGreen, ROOT.kFullCircle)
1021 mcHits['EmulsionDetPoints'] = ROOT.FairMCPointDraw("EmulsionDetPoint", ROOT.kMagenta, ROOT.kCircle)
1022else:
1023 mcHits['VetoPoints'] = ROOT.FairMCPointDraw("vetoPoint", ROOT.kBlue, ROOT.kFullDiamond)
1024 mcHits['TimeDetPoints'] = ROOT.FairMCPointDraw("TimeDetPoint", ROOT.kBlue, ROOT.kFullDiamond)
1025 mcHits['StrawPoints'] = ROOT.FairMCPointDraw("strawtubesPoint", ROOT.kGreen, ROOT.kFullCircle)
1026 if hasattr(ShipGeo,"EcalOption"):
1027 if ShipGeo.EcalOption==2:
1028 mcHits['SplitCalPoints'] = ROOT.FairMCPointDraw("splitcalPoint", ROOT.kRed, ROOT.kFullSquare)
1029 if not hasattr(mcHits,'SplitCalPoints') and hasattr(ShipGeo,"HcalOption"):
1030 mcHits['EcalPoints'] = ROOT.FairMCPointDraw("EcalPoint", ROOT.kRed, ROOT.kFullSquare)
1031 if ShipGeo.HcalOption!=2: mcHits['HcalPoints'] = ROOT.FairMCPointDraw("HcalPoint", ROOT.kMagenta, ROOT.kFullSquare)
1032 mcHits['MuonPoints'] = ROOT.FairMCPointDraw("muonPoint", ROOT.kYellow, ROOT.kFullSquare)
1033 mcHits['RpcPoints'] = ROOT.FairMCPointDraw("ShipRpcPoint", ROOT.kOrange, ROOT.kFullSquare)
1034 mcHits['TargetPoints'] = ROOT.FairMCPointDraw("TargetPoint", ROOT.kRed, ROOT.kFullSquare)
1035
1036 if hasattr(ShipGeo,'preshowerOption'):
1037 if ShipGeo.preshowerOption >0:
1038 mcHits['preshowerPoints'] = ROOT.FairMCPointDraw("preshowerPoint", ROOT.kYellow, ROOT.kFullCircle)
1039
1040for x in mcHits: fMan.AddTask(mcHits[x])
1041
1042fMan.Init(1,4,10) # default Init(visopt=1, vislvl=3, maxvisnds=10000), ecal display requires vislvl=4
1043#visopt, set drawing mode :
1044# option=0 (default) all nodes drawn down to vislevel
1045# option=1 leaves and nodes at vislevel drawn
1046# option=2 path is drawn
1047# vislvl
1048#
1049fRman = ROOT.FairRootManager.Instance()
1050sTree = fRman.GetInChain()
1051lsOfGlobals = ROOT.gROOT.GetListOfGlobals()
1052lsOfGlobals.Add(sTree)
1053sGeo = ROOT.gGeoManager
1054top = sGeo.GetTopVolume()
1055# manipulate colors and transparency before scene created
1056speedUp()
1057gEve = ROOT.gEve
1058
1059if hasattr(ShipGeo,"Bfield"):
1060 if hasattr(ShipGeo.Bfield,"fieldMap"):
1061 ROOT.gSystem.Load('libG4clhep.so')
1062 ROOT.gSystem.Load('libgeant4vmc.so')
1063 import geomGeant4
1064 fieldMaker = geomGeant4.addVMCFields(ShipGeo, '', True, withVirtualMC = False)
1065 bfield = ROOT.genfit.FairShipFields()
1066 bfield.setField(fieldMaker.getGlobalField())
1067 else:
1068 bfield = ROOT.genfit.BellField(ShipGeo.Bfield.max ,ShipGeo.Bfield.z,2, ShipGeo.Bfield.y/2.*u.m)
1069 geoMat = ROOT.genfit.TGeoMaterialInterface()
1070 ROOT.genfit.MaterialEffects.getInstance().init(geoMat)
1071 fM = ROOT.genfit.FieldManager.getInstance()
1072 fM.init(bfield)
1073
1074import TrackExtrapolateTool
1075br = gEve.GetBrowser()
1076br.HideBottomTab() # make more space for graphics
1077br.SetWindowName('SHiP Eve Window')
1078
1079#switchOf('RockD')
1080if sGeo.FindVolumeFast('T2LiSc'): hidePlasticScintillator()
1081rulers = Rulers()
1082SHiPDisplay = EventLoop()
1083import eveGlobal
1084eveGlobal.SHiPDisplay = SHiPDisplay
1085SHiPDisplay.SetName('SHiP Displayer')
1086lsOfGlobals.Add(SHiPDisplay)
1087SHiPDisplay.InitTask()
1088
1089# SHiPDisplay.NextEvent(0)
1090
1091print('Help on GL viewer can be found by pressing Help button followed by help on GL viewer')
1092print('With the camera button, you can switch to different views.')
1093# short cuts
1094# w go to wire frame
1095# r smooth display
1096# t technical display
1097# e black<->white background
1098# j zoom in
1099# k zoom out
1100# d GL debug mode
1101
1102# fGeo.SetNsegments(10) # can help a bit in case of performance problems
1104 i = -1
1105 for aTrack in sTree.MCTrack:
1106 i+=1
1107 if i<2: continue
1108 if aTrack.GetMotherId()==1:
1109 pa = pdg.GetParticle(sTree.MCTrack[i] .GetPdgCode())
1110 if pa.Lifetime()>1.E-12:
1111 print(sTree.MCTrack[i])
1112 SHiPDisplay.tracks.DrawMCTrack(i)
1114 comp = SHiPDisplay.tracks.comp
1115 comp.OpenCompound()
1116 n = -1
1117 ntot = 0
1118 fPos = ROOT.TVector3()
1119 fMom = ROOT.TVector3()
1120 delZ = 10*u.m
1121 for fT in sTree.MCTrack:
1122 n+=1
1123 DTrack = ROOT.TEveLine()
1124 DTrack.SetPickable(ROOT.kTRUE)
1125 DTrack.SetTitle(fT.__repr__())
1126 fT.GetStartVertex(fPos)
1127 fT.GetMomentum(fMom)
1128 hitlist = {}
1129 hitlist[fPos.Z()] = [fPos.X(),fPos.Y()]
1130 z = fPos.Z() + delZ
1131 slx,sly = fMom.X()/fMom.Z(),fMom.Y()/fMom.Z()
1132 hitlist[z] = [fPos.X()+slx*delZ,fPos.Y()+sly*delZ]
1133 for z in hitlist.keys():
1134 DTrack.SetNextPoint(hitlist[z][0],hitlist[z][1],z)
1135 p = pdg.GetParticle(fT.GetPdgCode())
1136 if p : pName = p.GetName()
1137 else: pName = str(fT.GetPdgCode())
1138 DTrack.SetName('MCTrack_'+str(n)+'_'+pName)
1139 c = ROOT.kYellow
1140 DTrack.SetMainColor(c)
1141 DTrack.SetLineWidth(3)
1142 comp.AddElement(DTrack)
1143 ntot+=1
1144 comp.CloseCompound()
1145 gEve.ElementChanged(SHiPDisplay.tracks.evscene,True,True)
1146
1148# some default setup
1149 SND = ['SciFi','Wall','volVetoBar ','volFeBlock',' volMuUpstreamBar ','volMuDownstreamBar_hor ','volMuDownstreamBar_ver ']
1150 tunnel = sGeo.GetVolume('Tunnel')
1151 tunnel.SetVisibility(0)
1152 tunnel.SetVisDaughters(0)
1153 for x in sGeo.GetListOfVolumes():
1154 if x.GetName() in SND:
1155 x.SetTransparency(60)
1156 br = gEve.GetBrowser()
1157 br.SetWindowName('SND@LHC Eve Window')
1158 br.SetWidth(1600)
1159 sc = gEve.GetScenes()
1160 geoscene = sc.FindChild('Geometry scene')
1161 gEve.ElementChanged(geoscene,True,True)
1162
1163 v = gEve.GetDefaultGLViewer()
1164 camera = v.CurrentCamera()
1165 for i in range(2): # don't know why this needs to be executed twice to update the screen
1166 camera.Reset()
1167 center = array('d',[-9.,46.,28.])
1168 camera.Configure(1.6, 0, center, -1.57, 0)
1169 v.DoDraw()
1170
1171
1172def positionText(r,x,y,z,angle,txt,size=200,color=ROOT.kBlue,mode=ROOT.TGLFont.kExtrude,light=ROOT.kTRUE):
1173 tt = ROOT.TEveText(txt)
1174 tt.SetFontSize(size)
1175 tt.RefMainTrans().SetPos(x,y,z)
1176 tt.PtrMainTrans().RotateLF(1, 3, angle)
1177 tt.SetMainColor(color)
1178 tt.SetFontMode(mode)
1179 tt.SetLighting(light)
1180 r.AddElement(tt)
1183 for x in ['moreShieldingSide', 'moreShieldingTopBot','CoatWall','CoatVol','AbsorberVol']:
1184 vol = ROOT.gGeoManager.FindVolumeFast(x)
1185 vol.SetVisibility(0)
1186 ROOT.gGeoManager.GetMaterial('Concrete').SetTransparency(0)
1187 r = rulers.ruler
1188 ticks = 5
1189 r.DestroyElements()
1190 r.OpenCompound()
1191 xpos,ypos = -500., -1500.
1192 zstart = ShipGeo.target.z0
1193 zlength = ShipGeo.MuonStation3.z - zstart + 10*u.m
1194 z=zstart
1195 for i in range(int(zlength/100/ticks)):
1196 m = ROOT.TEveLine()
1197 m.SetNextPoint(xpos,ypos, z)
1198 m.SetNextPoint(xpos-1*u.m,ypos,z)
1199 m.SetMainColor(ROOT.kRed)
1200 m.SetLineWidth(5)
1201 r.AddElement(m)
1202 t1 = ROOT.TEveText(str(i*ticks)+'m')
1203 t1.SetMainColor(ROOT.kGray+3)
1204 t1.SetFontSize(5)
1205 t1.RefMainTrans().SetPos(xpos-0.1*u.m,ypos+0.2*u.m,z)
1206 r.AddElement(t1)
1207 z+=ticks*u.m
1208 xpos,ypos = 0., 0.
1209 z = ShipGeo.MuonStation3.z+6*u.m
1210 ylength = 7*u.m
1211 ypos=-ylength
1212 for i in range(-int(ylength/100),int(ylength/100),1):
1213 m = ROOT.TEveLine()
1214 m.SetNextPoint(xpos,ypos, z)
1215 m.SetNextPoint(xpos+0.05*u.m,ypos,z)
1216 m.SetMainColor(ROOT.kRed)
1217 m.SetLineWidth(3)
1218 r.AddElement(m)
1219 t1 = ROOT.TEveText(str(i)+'m')
1220 t1.SetMainColor(ROOT.kGray+3)
1221 t1.SetFontSize(5)
1222 t1.RefMainTrans().SetPos(xpos-0.5*u.m,ypos,z)
1223 r.AddElement(t1)
1224 ypos+=1*u.m
1225 ty = ROOT.TEveText("y-axis")
1226 ty.SetFontSize(10)
1227 ty.RefMainTrans().SetPos(0.,ypos+1*u.m,z)
1228 ty.SetMainColor(ROOT.kRed-2)
1229 r.AddElement(ty)
1230 xpos,ypos = 0., 0.
1231 z = ShipGeo.MuonStation3.z+10*u.m
1232 xlength = 3*u.m
1233 xpos=-xlength
1234 for i in range(-int(xlength/100),int(xlength/100),1):
1235 m = ROOT.TEveLine()
1236 m.SetNextPoint(xpos,ypos, z)
1237 m.SetNextPoint(xpos,ypos-0.05*u.m,z)
1238 m.SetMainColor(ROOT.kRed)
1239 m.SetLineWidth(3)
1240 r.AddElement(m)
1241 t1 = ROOT.TEveText(str(i)+'m')
1242 t1.SetMainColor(ROOT.kGray+3)
1243 t1.SetFontSize(5)
1244 t1.RefMainTrans().SetPos(xpos,ypos-0.1*u.m,z)
1245 r.AddElement(t1)
1246 xpos+=1*u.m
1247 tx = ROOT.TEveText("x-axis")
1248 tx.SetFontSize(10)
1249 tx.RefMainTrans().SetPos(xpos+1*u.m,0.,z)
1250 tx.SetMainColor(ROOT.kRed-2)
1251 r.AddElement(tx)
1252 rotAngle = ROOT.TMath.Pi()+ROOT.TMath.PiOver2()*5./2.
1253 positionText(r,0.,900.,ShipGeo.TrackStation1.z-20*u.m,rotAngle,"SHiP",200,ROOT.kOrange-2)
1254 positionText(r,0.,750.,ShipGeo.TrackStation1.z-40*u.m,rotAngle,"Vacuum decay vessel",200,ROOT.kGray+1)
1255 positionText(r,0.,100.,ShipGeo.target.z-6*u.m,rotAngle,"Target",200,ROOT.kBlue)
1256 positionText(r,0.,600.,ShipGeo.muShield.z-10*u.m,rotAngle,"Active muon shield",200,ROOT.kGreen-2)
1257 positionText(r,0.,600.,ShipGeo.tauMudet.zMudetC-10*u.m,rotAngle,"Tau neutrino detector",200,ROOT.kRed-2)
1258 positionText(r,0.,900.,ShipGeo.Bfield.z-5*u.m,rotAngle,"Dipole Magnet",200,ROOT.kBlue+2)
1259 positionText(r,-1500.,-800.,ShipGeo.TrackStation3.z-2*u.m,rotAngle,"Strawtracker",200,ROOT.kRed+2)
1260 positionText(r,0.,730.,ShipGeo.ecal.z-1*u.m,rotAngle,"Ecal",200,ROOT.kOrange)
1261 positionText(r,0.,700.,ShipGeo.MuonFilter2.z,rotAngle,"Muon",200,ROOT.kGreen+2)
1262 r.CloseCompound()
1263 sc = gEve.GetScenes()
1264 geoscene = sc.FindChild('Geometry scene')
1265 gEve.ElementChanged(geoscene,True,True)
1266
1267
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
InitTask(self, ecalStructure)
DrawFittedTracks(self, option='')
ExecuteTask(self, option='')
DrawMCTracks(self, option='')
ExecuteTask(self, option='')
transparentMode(self, mode='on')
rotateView(self, hor=0, ver=0)
nextEvent(self, event=None)
show(self, xy=0, ticks=5)
select(pattern)
rename(name='ship.TGeant4.root')
positionText(r, x, y, z, angle, txt, size=200, color=ROOT.kBlue, mode=ROOT.TGLFont.kExtrude, light=ROOT.kTRUE)
readCameraSetting(fname='camSetting.root')
search(lvdict, tag)
printMCTrack(n, MCTrack)
storeCameraSetting(fname='camSetting.root')
addVMCFields(shipGeo, controlFile='', verbose=False, withVirtualMC=True)
makeEcalGeoFile(z, efile)
configure(darkphoton=None)