1
2
3
4
5
6
7
8
9
10 package org.lcsim.recon.tracking.digitization.sisim;
11
12 import hep.physics.matrix.SymmetricMatrix;
13 import hep.physics.vec.BasicHep3Vector;
14 import hep.physics.vec.Hep3Vector;
15 import java.util.List;
16 import org.lcsim.detector.ITransform3D;
17 import org.lcsim.detector.Transform3D;
18 import org.lcsim.event.RawTrackerHit;
19 import org.lcsim.event.TrackerHit;
20
21
22
23
24
25 public class TransformableTrackerHit extends BaseTrackerHit
26 {
27
28 private TrackerHitType _decoded_type;
29
30 private ITransform3D _local_to_global;
31
32
33 private TrackerHitType.CoordinateSystem _coordinate_system;
34 private TrackerHitType.MeasurementType _measurement_type;
35
36
37
38
39
40
41 public TransformableTrackerHit(Hep3Vector position_vector, SymmetricMatrix covariance_matrix, double energy, double time, List<RawTrackerHit> raw_hits, TrackerHitType decoded_type)
42 {
43 super(position_vector,covariance_matrix,energy,time,raw_hits,TrackerHitType.encoded(decoded_type));
44
45 _decoded_type = decoded_type;
46
47 if (getCoordinateSystem() == TrackerHitType.CoordinateSystem.GLOBAL)
48 {
49 _local_to_global = new Transform3D();
50 }
51 else if (getCoordinateSystem() == TrackerHitType.CoordinateSystem.SENSOR)
52 {
53 _local_to_global = getSensor().getGeometry().getLocalToGlobal();
54 }
55 else
56 {
57 throw new RuntimeException("Cannot instantiate a BaseTrackerHit object with unknown coordinates!");
58 }
59 }
60
61
62 public TransformableTrackerHit(TrackerHit hit)
63 {
64 this(
65 new BasicHep3Vector(hit.getPosition()[0],hit.getPosition()[1],hit.getPosition()[2]),
66 new SymmetricMatrix( 3, hit.getCovMatrix(), true),
67 hit.getdEdx(),
68 hit.getTime(),
69 hit.getRawHits(),
70 TrackerHitType.decoded(hit.getType())
71 );
72 }
73
74
75 public TransformableTrackerHit(TrackerHit hit, TrackerHitType.CoordinateSystem coordinate_system)
76 {
77 this(hit);
78
79
80 ITransform3D global_to_local = getGlobalToHit(coordinate_system);
81 ITransform3D hit_to_local = Transform3D.multiply(global_to_local,_local_to_global);
82
83 _position_vector = hit_to_local.transformed(_position_vector);
84 _covariance_matrix = hit_to_local.transformed(_covariance_matrix);
85 _local_to_global = global_to_local.inverse();
86 _decoded_type = new TrackerHitType(coordinate_system,getMeasurementType());
87 }
88
89
90
91
92
93 public TransformableTrackerHit getTransformedHit(TrackerHitType.CoordinateSystem coordinate_system)
94 {
95
96 ITransform3D global_to_local = getGlobalToHit(coordinate_system);
97 ITransform3D hit_to_local = Transform3D.multiply(global_to_local,_local_to_global);
98
99 Hep3Vector position_vector = hit_to_local.transformed(_position_vector);
100 SymmetricMatrix covariance_matrix = hit_to_local.transformed(_covariance_matrix);
101 double energy = getdEdx();
102 double time = getTime();
103 List<RawTrackerHit> raw_hits = getRawHits();
104 TrackerHitType decoded_type = new TrackerHitType(coordinate_system,getMeasurementType());
105
106 return new TransformableTrackerHit(position_vector,covariance_matrix,energy,time,raw_hits,decoded_type);
107 }
108
109
110 public TransformableTrackerHit getTransformedHit(ITransform3D global_to_local)
111 {
112
113 ITransform3D hit_to_local = Transform3D.multiply(global_to_local,_local_to_global);
114
115 Hep3Vector position_vector = hit_to_local.transformed(_position_vector);
116 SymmetricMatrix covariance_matrix = hit_to_local.transformed(_covariance_matrix);
117 double energy = getdEdx();
118 double time = getTime();
119 List<RawTrackerHit> raw_hits = getRawHits();
120
121 ITransform3D local_to_global = global_to_local.inverse();
122
123 TrackerHitType dummy_type = new TrackerHitType(TrackerHitType.CoordinateSystem.GLOBAL,getMeasurementType());
124 TrackerHitType decoded_type = new TrackerHitType(TrackerHitType.CoordinateSystem.UNKNOWN,getMeasurementType());
125
126
127 TransformableTrackerHit new_hit = new TransformableTrackerHit(position_vector,covariance_matrix,energy,time,raw_hits,dummy_type);
128
129
130 new_hit._decoded_type = decoded_type;
131 new_hit._local_to_global = local_to_global;
132
133 return new_hit;
134 }
135
136
137
138 public boolean isPersistable()
139 {
140 return (this.getCoordinateSystem() != TrackerHitType.CoordinateSystem.UNKNOWN);
141 }
142
143 public ITransform3D getLocalToGlobal()
144 {
145 return _local_to_global;
146 }
147
148 public TrackerHitType.CoordinateSystem getCoordinateSystem()
149 {
150 if (_coordinate_system == null)
151 {
152 _coordinate_system = _decoded_type.getCoordinateSystem();
153 }
154 return _coordinate_system;
155 }
156
157 public TrackerHitType.MeasurementType getMeasurementType()
158 {
159 if (_measurement_type == null)
160 {
161 _measurement_type = _decoded_type.getMeasurementType();
162 }
163 return _measurement_type;
164 }
165
166
167 private ITransform3D getGlobalToHit(TrackerHitType.CoordinateSystem coordinate_system)
168 {
169 if (coordinate_system == TrackerHitType.CoordinateSystem.GLOBAL)
170 {
171 return new Transform3D();
172 }
173 else if (coordinate_system == TrackerHitType.CoordinateSystem.SENSOR)
174 {
175 return ((List<RawTrackerHit>)getRawHits()).get(0).getDetectorElement().getGeometry().getGlobalToLocal();
176 }
177 else
178 {
179 throw new RuntimeException("Cannot determine Transform3D to UNKNOWN coordinates!");
180 }
181 }
182
183 }
184