SND@LHC Software
Loading...
Searching...
No Matches
shipVeto.py
Go to the documentation of this file.
1# utility to simulate response of the veto systems
2from __future__ import division
3import ROOT
4import shipunit as u
5from array import array
6
7class Task:
8 "initialize and give response of the veto systems"
9 def __init__(self,t):
10 self.SBTefficiency = 0.99 # Surrounding Background tagger: 99% efficiency picked up from TP
11 self.SVTefficiency = 0.995 # Straw Veto tagger: guestimate, including dead channels
12 self.random = ROOT.TRandom()
13 ROOT.gRandom.SetSeed(13)
14 self.detList = self.detMap()
15 self.sTree = t
16
17 def detMap(self):
18 fGeo = ROOT.gGeoManager
19 detList = {}
20 for v in fGeo.GetListOfVolumes():
21 nm = v.GetName()
22 i = fGeo.FindVolumeFast(nm).GetNumber()
23 detList[i] = nm
24 return detList
25
26 def SBT_plastic_decision(self,mcParticle=None):
27 SBT_decision(self,mcParticle,detector='plastic')
28 def SBT_liquid_decision(self,mcParticle=None):
29 SBT_decision(self,mcParticle,detector='liquid')
30
31 def SBT_decision(self,mcParticle=None,detector='liquid'):
32 # if mcParticle >0, only count hits with this particle
33 # if mcParticle <0, do not count hits with this particle
34 hitSegments = 0
35 index = -1
36 fdetector = detector=='liquid'
37 for aDigi in self.sTree.Digi_SBTHits:
38 index+=1
39 detID = aDigi.GetDetectorID()
40 if fdetector and detID > 999999:continue
41 if not fdetector and not detID > 999999:continue
42 if mcParticle:
43 found = False
44 for mcP in self.sTree.digiSBT2MC[index]:
45 if mcParticle>0 and mcParticle != mcP : found=True
46 if mcParticle<0 and abs(mcParticle) == mcP : found=True
47 if found: continue
48 position = aDigi.GetXYZ()
49 ELoss = aDigi.GetEloss()
50 if aDigi.isValid(): hitSegments += 1 #threshold of 45 MeV per segment
51 w = (1-self.SBTefficiency)**hitSegments
52 veto = self.random.Rndm() > w
53 #print 'SBT :',hitSegments
54 return veto, w, hitSegments
55 def SVT_decision(self,mcParticle=None):
56 nHits = 0
57 for ahit in self.sTree.strawtubesPoint:
58 if mcParticle:
59 if mcParticle>0 and mcParticle != ahit.GetTrackID() : continue
60 if mcParticle<0 and abs(mcParticle) == ahit.GetTrackID() : continue
61 detID = ahit.GetDetectorID()
62 if detID<50000000: continue # StrawVeto station = 5
63 nHits+=1
64 w = (1-self.SVTefficiency)**nHits
65 veto = self.random.Rndm() > w
66 # print 'SVT :',nHits
67 return veto,w,nHits
68 def RPC_decision(self,mcParticle=None):
69 nHits = 0
70 mom = ROOT.TVector3()
71 for ahit in self.sTree.ShipRpcPoint:
72 if mcParticle:
73 if mcParticle>0 and mcParticle != ahit.GetTrackID() : continue
74 if mcParticle<0 and abs(mcParticle) == ahit.GetTrackID() : continue
75 ahit.Momentum(mom)
76 if mom.Mag() > 0.1: nHits+=1
77 w = 1
78 veto = nHits > 0 # 10 change to >0 since neutrino background ntuple not possible otherwise
79 if veto: w = 0.
80 #print 'RPC :',nHits
81 return veto,w,nHits
82 def Track_decision(self,mcParticle=None):
83 nMultCon = 0
84 k = -1
85 for aTrack in self.sTree.FitTracks:
86 k+=1
87 if mcParticle:
88 if mcParticle>0 and mcParticle != ahit.GetTrackID() : continue
89 if mcParticle<0 and abs(mcParticle) == ahit.GetTrackID() : continue
90 fstatus = aTrack.getFitStatus()
91 if not fstatus.isFitConverged() : continue
92 if fstatus.getNdf() < 25: continue
93 nMultCon+=1
94 w = 1
95 veto = nMultCon > 2
96 if veto: w = 0.
97 return veto,w,nMultCon
99 hnl = self.sTree.Particles[n]
100 aPoint = ROOT.TVector3(hnl.Vx(),hnl.Vy(),hnl.Vz())
101 distmin = self.fiducialCheck(aPoint)
102 return distmin
103 def fiducialCheck(self,aPoint):
104 nav = ROOT.gGeoManager.GetCurrentNavigator()
105 phi = 0.
106 nSteps = 36
107 delPhi = 2.*ROOT.TMath.Pi()/nSteps
108 distmin = 1E10
109 nav.SetCurrentPoint(aPoint.x(),aPoint.y(),aPoint.z())
110 cNode = 'outside'
111 aNode = nav.FindNode()
112 if aNode: cNode = aNode.GetName()
113 if cNode != 'T2decayVol_0' and cNode != 'T1decayVol_0':
114 distmin = 0.
115 else:
116 for n in range(nSteps):
117 # set direction
118 xDir = ROOT.TMath.Sin(phi)
119 yDir = ROOT.TMath.Cos(phi)
120 nav.SetCurrentPoint(aPoint.x(),aPoint.y(),aPoint.z())
121 cNode = nav.FindNode().GetName()
122 nav.SetCurrentDirection(xDir,yDir,0.)
123 rc = nav.FindNextBoundaryAndStep()
124 x,y = nav.GetCurrentPoint()[0],nav.GetCurrentPoint()[1]
125 if cNode != nav.GetCurrentNode().GetName():
126 dist = ROOT.TMath.Sqrt( (aPoint.x()-x)**2 + (aPoint.y()-y)**2)
127 if dist < distmin : distmin = dist
128 phi+=delPhi
129# distance to Tr1_x1
130 nav.cd("/Tr1_1")
131 shape = nav.GetCurrentNode().GetVolume().GetShape()
132 origin = array('d',[0,0,shape.GetDZ()])
133 master = array('d',[0,0,0])
134 nav.LocalToMaster(origin,master)
135 dist = master[2] - aPoint.z()
136 if dist < distmin : distmin = dist
137# distance to straw veto:
138 nav.cd("/Veto_5")
139 shape = nav.GetCurrentNode().GetVolume().GetShape()
140 origin = array('d',[0,0,shape.GetDZ()])
141 master = array('d',[0,0,0])
142 nav.LocalToMaster(origin,master)
143 dist = aPoint.z() - master[2]
144 return distmin
145
146#usage
147# import shipVeto
148# veto = shipVeto.Task(sTree)
149# veto,w = veto.SBT_decision()
150# or for plastic veto,w = veto.SBT_decision(detector='plastic')
151# if veto: continue # reject event
152# or
153# continue using weight w
Track_decision(self, mcParticle=None)
Definition shipVeto.py:82
fiducialCheckSignal(self, n)
Definition shipVeto.py:98
SBT_decision(self, mcParticle=None, detector='liquid')
Definition shipVeto.py:31
RPC_decision(self, mcParticle=None)
Definition shipVeto.py:68
detMap(self)
Definition shipVeto.py:17
__init__(self, t)
Definition shipVeto.py:9
SBT_plastic_decision(self, mcParticle=None)
Definition shipVeto.py:26
fiducialCheck(self, aPoint)
Definition shipVeto.py:103
SVT_decision(self, mcParticle=None)
Definition shipVeto.py:55
SBT_liquid_decision(self, mcParticle=None)
Definition shipVeto.py:28