1 package org.lcsim.event.base;
2
3 import hep.physics.vec.BasicHep3Vector;
4 import hep.physics.vec.Hep3Vector;
5 import hep.physics.vec.VecOp;
6
7 import org.lcsim.detector.IDetectorElement;
8 import org.lcsim.detector.identifier.IIdentifier;
9 import org.lcsim.detector.identifier.Identifier;
10 import org.lcsim.event.EventHeader.LCMetaData;
11 import org.lcsim.event.MCParticle;
12 import org.lcsim.event.SimTrackerHit;
13
14
15
16
17
18
19
20 public class BaseSimTrackerHit extends BaseHit implements SimTrackerHit {
21
22 protected double[] position = new double[3];
23 protected double[] momentum = new double[3];
24 protected MCParticle mcparticle;
25 protected double time;
26 protected double dEdx;
27 protected int cellID0;
28 protected int cellID1;
29 protected long id;
30 protected double pathLength;
31 private Hep3Vector startPoint, endPoint;
32
33
34
35
36 protected BaseSimTrackerHit() {
37 }
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 public BaseSimTrackerHit(double[] position, double dEdx, double[] momentum, double pathLength, double time, int cellID, MCParticle mcparticle, LCMetaData meta, IDetectorElement de) {
53
54 positionVec = new BasicHep3Vector(position[0], position[1], position[2]);
55
56 if (position.length != 3)
57 throw new IllegalArgumentException("The position array is of the wrong size!");
58 for (int i = 0, n = this.position.length; i < n; i++) {
59 this.position[i] = position[i];
60 }
61
62 if (momentum == null)
63 throw new IllegalArgumentException("The momentum points to null!");
64 if (momentum.length != 3)
65 throw new IllegalArgumentException("The momentum array is of the wrong size!");
66 for (int i = 0, n = this.momentum.length; i < n; i++) {
67 this.momentum[i] = momentum[i];
68 }
69
70 this.mcparticle = mcparticle;
71 this.time = time;
72 this.dEdx = dEdx;
73 this.cellID0 = cellID;
74
75 this.id = (long) cellID;
76 this.pathLength = pathLength;
77 this.metaData = meta;
78 this.detectorElement = de;
79 }
80
81 public void setTime(double time) {
82 this.time = time;
83 }
84
85 public int getLayer() {
86 getIDDecoder().setID(getCellID());
87 return getIDDecoder().getLayer();
88 }
89
90 public double[] getPoint() {
91 return positionVec.v();
92 }
93
94 public double getTime() {
95 return time;
96 }
97
98 public double getdEdx() {
99 return dEdx;
100 }
101
102 public MCParticle getMCParticle() {
103 return mcparticle;
104 }
105
106
107
108 public int getCellID() {
109 return cellID0;
110 }
111
112 public long getCellID64() {
113 return id;
114 }
115
116 public void setCellID64(long cellID) {
117 id = cellID;
118 }
119
120 public double getPathLength() {
121 return pathLength;
122 }
123
124 public double[] getMomentum() {
125 return momentum;
126 }
127
128 public double[] getStartPoint() {
129 if (startPoint == null)
130 computePoints();
131 return startPoint.v();
132 }
133
134 public double[] getEndPoint() {
135 if (endPoint == null)
136 computePoints();
137 return endPoint.v();
138 }
139
140 private void computePoints() {
141 Hep3Vector midpoint = new BasicHep3Vector(getPoint());
142 Hep3Vector direction = VecOp.unit(new BasicHep3Vector(getMomentum()));
143 Hep3Vector halfLength = VecOp.mult(getPathLength() / 2.0, direction);
144
145 startPoint = VecOp.add(midpoint, VecOp.mult(-1.0, halfLength));
146 endPoint = VecOp.add(midpoint, halfLength);
147 }
148
149 public IIdentifier getIdentifier() {
150 if (packedID == null)
151 packedID = new Identifier(id);
152 return packedID;
153 }
154
155
156
157
158
159 public IDetectorElement getDetectorElement() {
160 if (detectorElement == null) {
161
162 detectorElement = findDetectorElement(this.getPositionVec());
163 }
164 return detectorElement;
165 }
166 }