View Javadoc

1   package org.lcsim.recon.tracking.trfbase;
2   
3   /**
4    * Class to describe the result of a propagation.
5    *<p>
6    * Class is constructed in a state indicating failure.
7    *<p>
8    * Call set_same() or set_path_distance(s) if propagation is
9    * successful.
10   *
11   *@author Norman A. Graf
12   *@version 1.0
13   */
14  public class PropStat
15  {
16      
17      static final double DEFAULT_PATH_DISTANCE = 1.e30;
18      
19      private boolean _success;
20      private double _s;
21      
22      //
23      
24      /**
25       *Default Constructor leaves object invalid.
26       * Default state indicates failure.
27       * Call one of the set methods to validate.
28       *
29       */
30      public PropStat()
31      {
32          _success = false;
33          _s = 0.0;
34      }
35      
36      //
37      
38      /**
39       * Copy constructor.
40       *
41       * @param   pstat  PropStat to copy.
42       */
43      public PropStat( PropStat pstat)
44      {
45          _success = pstat._success;
46          _s = pstat._s;
47      }
48      
49      //
50      
51      /**
52       * Set the distance of propagation.
53       *
54       * @param   s  distance to propagate.
55       */
56      public void setPathDistance(double s)
57      {
58          _success = true;
59          _s = s;
60      }
61      
62      //
63      
64      /**
65       * Set successful propagation to same point.
66       *
67       */
68      public void setSame()
69      {
70          _success = true;
71          _s = 0.0;
72      }
73      
74      //
75      
76      /**
77       * Was propagation successful?
78       *
79       * @return true if propagation was successful.
80       */
81      public boolean success()
82      {
83          return _success;
84      }
85      
86      //
87      
88      /**
89       * Did track move forward?
90       *
91       * @return true if track propagated in forward direction.
92       */
93      public boolean forward()
94      {
95          return _success && _s>0.0;
96      }
97      
98      //
99      
100     /**
101      * Did track move backward?
102      *
103      * @return  true if track propagated in backward direction.
104      */
105     public boolean backward()
106     {
107         return _success && _s<0.0;
108     }
109     
110     //
111     
112     /**
113      * Did track propagate succesfully to the same position?
114      *
115      * @return true if track propagated to current position.
116      */
117     public boolean same()
118     {
119         return _success && _s==0.0;
120     }
121     
122     //
123     
124     /**
125      * Return the propagation path distance.
126      *
127      * @return path distance s.
128      */
129     public double pathDistance()
130     {
131         //should check on _success here assert( _success );
132         return _s;
133     }
134     
135     
136     /**
137      * String representation of PropStat.
138      *
139      * @return String representation of PropStat.
140      */
141     public String toString()
142     {
143         String className = getClass().getName();
144         int lastDot = className.lastIndexOf('.');
145         if(lastDot!=-1)className = className.substring(lastDot+1);
146         
147         StringBuffer sb = new StringBuffer(className+"\n");
148         if ( forward() ) sb.append("successful forward propagation");
149         if ( backward() ) sb.append("successful backward propagation");
150         if ( same() ) sb.append("successful propagation with no movement");
151         if ( ! success() ) sb.append("propagation failed");
152         if ( success() ) sb.append(" " + pathDistance());
153         return sb.toString();
154     }
155     
156     // deprecated, but used in tests...
157     
158     //
159     
160     /**
161      * Set successful propagation forward.
162      * Should only be used in tests.
163      */
164     public void setForward()
165     {
166         _success = true;
167         _s = DEFAULT_PATH_DISTANCE;
168     }
169     
170     //**********************************************************************
171     
172     //
173     
174     /**
175      * Set successful propagation backward.
176      * Should only be used in tests.
177      */
178     public void setBackward()
179     {
180         _success = true;
181         _s = -DEFAULT_PATH_DISTANCE;
182     }
183     
184 }