View Javadoc

1   package org.lcsim.recon.tracking.gtrbase;
2   // McTrackState
3   
4   import org.lcsim.recon.tracking.trfbase.VTrack;
5   import org.lcsim.recon.tracking.trfbase.Surface;
6   import org.lcsim.recon.tracking.trfbase.TrackVector;
7   
8   /**
9    * This class represents the state of a Monte Carlo track at one
10   * point along its trajectory.  It consists of the path distance and
11   * a VTrack. It can be sorted by the path distance.
12   *
13   *@author Norman A. Graf
14   *@version 1.0
15   *
16   */
17  
18  public class McTrackState implements Comparable
19  {
20      
21      // The path distance.
22      private double _s;
23      
24      // The track.
25      private VTrack _trv;
26      
27      // The detector element id
28      
29      private int _id;
30      
31    
32      /**
33       *Construct a default instance.
34       *
35       */
36      public McTrackState()
37      {
38      }
39     
40      /**
41       *Construct an instance from a path distance and track.
42       *
43       * @param   s The path distance to this state..
44       * @param   trv The VTrack at this state.
45       */
46      public McTrackState(double s, VTrack trv)
47      {
48          _s = s;
49          _trv = new VTrack(trv);
50          _id = 0;
51      }
52      
53      /**
54       *Construct an instance replicating the McTrackState (copy constructor).
55       *
56       * @param   ts The McTrackState to replicate.
57       */
58      public McTrackState( McTrackState ts)
59      {
60          _s = ts._s;
61          _trv = new VTrack(ts._trv);
62          _id = ts._id;
63      }
64     
65      /**
66       *Construct an instance from the track distance, a surface and a track vector.
67       *
68       * @param   s The path distance to this state.
69       * @param   srf The surface for this state.
70       * @param   vec The VTrack at this state.
71       */
72      public McTrackState(double s, Surface srf, TrackVector vec)
73      {
74          _s = s;
75          _trv = new VTrack(srf,vec);
76          _id = 0;
77      }
78     
79      /**
80       *Check this state's validity.
81       *
82       * @return true if the track is valid.
83       */
84      public boolean isValid()
85      {
86          if(_trv==null) return false;
87          return _trv.isValid();
88      }
89     
90      /**
91       *Return the path distance for this McTrackState.
92       *
93       * @return The path distance.
94       */
95      public double s()
96      { 
97          return _s; 
98      }
99      
100     /**
101      * Return the track.
102      *
103      * @return The VTrack at this state.
104      */
105     public  VTrack track()
106     { 
107         return new VTrack(_trv); 
108     }
109    
110     /**
111      *Return the detector id for this state.
112      *
113      * @return The detector id for this state.
114      */
115     public DetectorID detectorId()
116     {
117         return new DetectorID(_id);
118     }
119   
120     /**
121      * Set the detector id for this state.
122      *
123      * @param   id The detector id for this state.
124      */
125     public void setDetectorId( DetectorID id)
126     {
127         _id=id.detectorId();
128     }
129     
130     
131     /**
132      * Test equality.
133      *
134      * @param   ts The McTrackState to test.
135      * @return true if the states are equal.
136      */
137     public boolean equals(McTrackState ts)
138     {
139         return (_s == ts._s) && (track().equals(ts.track()) );
140     }
141   
142     /**
143      * Test object equality.
144      *
145      * @param   ts The Object to test.
146      * @return true if objects are equal.
147      */
148     public boolean equals(Object ts)
149     {
150         if(!(ts instanceof McTrackState)) return false;
151         return (_s == ((McTrackState)ts)._s) && (track().equals(((McTrackState)ts).track()) );
152     }
153   
154     /**
155      * Test ordering.
156      *
157      * @param ts McTrackState to test.
158      * @return true if detid is larger.
159      */
160     public boolean lessThan(McTrackState ts)
161     {
162         return _s<ts._s;
163     }
164     
165     // print
166     
167     /**
168      *output stream
169      *
170      * @return A String representation of this instance.
171      */
172     public String toString()
173     {
174         StringBuffer sb = new StringBuffer("McTrackState ");
175         if ( isValid() )
176         {
177             sb.append("Path distance is " +_s + ".\n");
178             sb.append("Detector Element Id is " + detectorId() +".\n");
179             sb.append(track());
180             sb.append("\n");
181         }
182         else
183         {
184             sb.append("Invalid state.");
185         }
186         return sb.toString();
187     }
188  
189     /**
190      * Comparable interface
191      * @param o Object to compare to.
192      * @return -1 if less, 0 if equal, 1 if greater.
193      */    
194     public int compareTo(Object o)
195     {
196         double s = ( (McTrackState) o)._s;
197         return (_s < s ? -1 : (_s == s ? 0 : 1));
198     }
199     
200 }