View Javadoc

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   * A concrete implementation of SimTrackerHit.
16   * 
17   * @author Jeremy McCormick
18   * @version $Id: BaseSimTrackerHit.java,v 1.19 2012/07/20 09:29:43 grefe Exp $
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       * Constructor for subclasses
35       */
36      protected BaseSimTrackerHit() {
37      }
38  
39      /**
40       * Fully qualified constructor
41       * 
42       * @param position The center point of the hit in Cartesian coordinates (x,y,z).
43       * @param momentum The momentum of the hit in GeV (px,py,pz).
44       * @param mcparticle The associated MCParticle. (may be null)
45       * @param time The time of the hit in nanoseconds.
46       * @param dEdx The energy deposited over the path in GeV.
47       * @param cellID The 32-bit identifier.
48       * @param pathLength The path length from start to end point.
49       * @param meta The LCMetaData associated to this hit. (may be null)
50       * @param de The DetectorElement associated to this hit. (may be null)
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          // TODO need to properly set a 64bit ID
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     // @Deprecated
107     // Use {@link #getCellID64()} instead.
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      * Get the {@see org.lcsim.detector.IDetectorElement} associated with this hit.     
157      * @return The IDetectorElement for this hit.
158      */
159     public IDetectorElement getDetectorElement() {        
160         if (detectorElement == null) {
161             // By default, use the hit's position to lookup the geometry.
162             detectorElement = findDetectorElement(this.getPositionVec());
163         }        
164         return detectorElement;
165     }
166 }