FairShip
Loading...
Searching...
No Matches
TrackExtrapolateTool.py
Go to the documentation of this file.
1# SPDX-License-Identifier: LGPL-3.0-or-later
2# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
3
4import ROOT
5import shipunit as u
6
7
8def cmp(a, b):
9 return (a > b) - (a < b)
10
11
12minNdf = 20
13parallelToZ = ROOT.TVector3(0.0, 0.0, 1.0)
14top = ROOT.gGeoManager.GetTopVolume()
15if top.GetNode("SplitCalDetector_1"):
16 z_ecal = top.GetNode("SplitCalDetector_1").GetMatrix().GetTranslation()[2]
17else:
18 print("TrackExtraploate tool: Error, no calo present")
19 z_ecal = 100 * u.m
20
21
23 # etrapolate to a plane perpendicular to beam direction (z)
24 rc, pos, mom = False, None, None
25 fst = fT.getFitStatus()
26 if fst.isFitConverged() and fst.getNdf() > minNdf:
27 # test for fit status for each point
28 if fT.getPoint(0).getFitterInfo() and fT.getPoint(1).getFitterInfo():
29 fstate0, fstate1 = fT.getFittedState(0), fT.getFittedState(1)
30 fPos0, fPos1 = fstate0.getPos(), fstate1.getPos()
31 if abs(z - fPos0.z()) < abs(z - fPos1.z()):
32 fstate = fstate0
33 else:
34 fstate = fstate1
35 zs = min(z, z_ecal)
36 NewPosition = ROOT.TVector3(0.0, 0.0, zs)
37 rep = ROOT.genfit.RKTrackRep(13 * cmp(fstate.getPDG(), 0))
38 state = ROOT.genfit.StateOnPlane(rep)
39 pos, mom = fstate.getPos(), fstate.getMom()
40 rep.setPosMom(state, pos, mom)
41 try:
42 rep.extrapolateToPlane(state, NewPosition, parallelToZ)
43 pos, mom = state.getPos(), state.getMom()
44 rc = True
45 except Exception:
46 # print 'error with extrapolation: z=',z/u.m,'m',pos.X(),pos.Y(),pos.Z(),mom.X(),mom.Y(),mom.Z()
47 pass
48 if not rc or z > z_ecal:
49 # use linear extrapolation
50 px, py, pz = mom.X(), mom.Y(), mom.Z()
51 lam = (z - pos.Z()) / pz
52 pos = ROOT.TVector3(pos.X() + lam * px, pos.Y() + lam * py, z)
53 return rc, pos, mom