-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fit.py
114 lines (93 loc) · 2.97 KB
/
test_fit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import ROOT
def main():
ROOT.gInterpreter.Declare('#include "MaterialEffects.h"')
ROOT.gInterpreter.Declare('#include "TGeoMaterialInterface.h"')
ROOT.gInterpreter.Declare('#include "FieldManager.h"')
ROOT.gInterpreter.Declare('#include "ConstField.h"')
ROOT.TGeoManager("Geometry", "Geane geometry")
ROOT.TGeoManager.Import("geofile_full.Ntuple-TGeant4.root")
ROOT.genfit.MaterialEffects.getInstance().init(ROOT.genfit.TGeoMaterialInterface())
ROOT.genfit.FieldManager.getInstance().init(ROOT.genfit.ConstField(0.0, 10.0, 0.0))
# init event display
display = ROOT.genfit.EventDisplay.getInstance()
# init fitter
fitter = ROOT.genfit.DAF()
# particle pdg code; muon
pdg = 13
# start values for the fit, e.g. from pattern recognition
pos = ROOT.TVector3(0, 0, 0)
mom = ROOT.TVector3(0, 0, 3)
# trackrep
rep = ROOT.genfit.RKTrackRep(pdg)
# create track
fitTrack = ROOT.genfit.Track(rep, pos, mom)
detId = 0
planeId = 0
hitId = 0
detectorResolution = 0.001
hitCov = ROOT.TMatrixDSym(2)
hitCov.UnitMatrix()
hitCov *= detectorResolution**2
# add some planar hits to track with coordinates I just made up
hitCoords = ROOT.TVectorD(2)
hitCoords[0] = 0
hitCoords[1] = 0
measurement = ROOT.genfit.PlanarMeasurement(
hitCoords, hitCov, detId, hitId, ROOT.nullptr
)
hitId += 1
measurement.setPlane(
ROOT.genfit.SharedPlanePtr(
ROOT.genfit.DetPlane(
ROOT.TVector3(0, 0, 0), ROOT.TVector3(1, 0, 0), ROOT.TVector3(0, 1, 0)
)
),
planeId,
)
planeId += 1
fitTrack.insertPoint(ROOT.genfit.TrackPoint(measurement, fitTrack))
hitCoords[0] = -0.15
hitCoords[1] = 0
measurement = ROOT.genfit.PlanarMeasurement(
hitCoords, hitCov, detId, hitId, ROOT.nullptr
)
hitId += 1
measurement.setPlane(
ROOT.genfit.SharedPlanePtr(
ROOT.genfit.DetPlane(
ROOT.TVector3(0, 0, 0), ROOT.TVector3(1, 0, 0), ROOT.TVector3(0, 1, 0)
)
),
planeId,
)
planeId += 1
fitTrack.insertPoint(ROOT.genfit.TrackPoint(measurement, fitTrack))
hitCoords[0] = -0.4
hitCoords[1] = 0
measurement = ROOT.genfit.PlanarMeasurement(
hitCoords, hitCov, detId, hitId, ROOT.nullptr
)
hitId += 1
measurement.setPlane(
ROOT.genfit.SharedPlanePtr(
ROOT.genfit.DetPlane(
ROOT.TVector3(0, 0, 0), ROOT.TVector3(1, 0, 0), ROOT.TVector3(0, 1, 0)
)
),
planeId,
)
planeId += 1
fitTrack.insertPoint(ROOT.genfit.TrackPoint(measurement, fitTrack))
# check
fitTrack.checkConsistency()
# do the fit
fitter.processTrack(fitTrack)
# print fit result
fitTrack.getFittedState().Print()
# check
fitTrack.checkConsistency()
display.addEvent(fitTrack)
# delete fitter;
# open event display
display.open()
main()