1 package org.lcsim.recon.tracking.trfbase; 2 /** 3 * A track vector with error. 4 * 5 * Data includes a surface pointer _srf, 5-vector _vec and 5 x 5 6 * symmetric error matrix _err. All are managed internally. 7 * 8 * @author Norman A. Graf 9 * @version 1.0 10 */ 11 public class ETrack extends VTrack 12 { 13 14 // attributes 15 16 private TrackError _err; 17 18 // methods 19 20 // 21 22 /** 23 *default constructor 24 * 25 */ 26 public ETrack() 27 { 28 _err = new TrackError(); 29 } 30 31 // 32 33 /** 34 * constructor from a surface 35 * 36 * @param srf Surface srf at which track is to be defined 37 */ 38 public ETrack( Surface srf) 39 { 40 super(srf); 41 _err = new TrackError(); 42 } 43 44 // 45 46 /** 47 *constructor from a surface, track and error matrix 48 * 49 * @param srf Surface srf at which track is to be defined 50 * @param vec TrackVector vec containing track parameters 51 * @param err TrackError err containing track parameter errors 52 */ 53 public ETrack( Surface srf, TrackVector vec, 54 TrackError err) 55 { 56 super(srf, vec); 57 _err = new TrackError(err); 58 } 59 60 // 61 62 /** 63 *constructor from a surface, track, error matrix and direction 64 * 65 * @param srf Surface srf at which track is to be defined 66 * @param vec TrackVector vec containing track parameters 67 * @param err TrackError err containing track parameter errors 68 * @param dir TrackSurfaceDirection dir direction of track relative to the Surface 69 */ 70 public ETrack( Surface srf, TrackVector vec, 71 TrackError err, TrackSurfaceDirection dir) 72 { 73 super(srf, vec, dir); 74 _err = new TrackError(err); 75 } 76 77 // 78 79 /** 80 *Constructor from a VTrack and an error matrix. 81 * 82 * @param trv VTrack trv representing track without errors 83 * @param err TrackError err containing track parameter errors 84 */ 85 public ETrack( VTrack trv, TrackError err) 86 { 87 super(trv); 88 _err = new TrackError(err); 89 } 90 91 // 92 93 /** 94 *copy constructor 95 * 96 * @param tre ETrack tre to be copied 97 */ 98 public ETrack( ETrack tre) 99 { 100 super(tre); 101 _err = new TrackError(tre.error()); 102 } 103 104 // 105 106 /** 107 *set the error matrix for the track 108 * 109 * @param newerr TrackError newerr containg error matrix 110 */ 111 public void setError( TrackError newerr) 112 { 113 _err = new TrackError(newerr); 114 } 115 116 117 118 /** 119 * String representation of ETrack 120 * 121 * @return String representation of ETrack 122 */ 123 public String toString() 124 { 125 String className = getClass().getName(); 126 int lastDot = className.lastIndexOf('.'); 127 if(lastDot!=-1)className = className.substring(lastDot+1); 128 129 StringBuffer sb = new StringBuffer(className+" \n"+super.toString()); 130 // return "ETrack: \n"+super.toString()+_err; 131 132 if ( isValid() ) 133 { 134 //stream << new_line << _err; 135 sb.append("Diagonal Sigmas:\n"); 136 TrackVector derr = new TrackVector(); 137 for ( int i=0; i<5; ++i ) 138 { 139 derr.set(i, Math.sqrt(_err.get(i,i))); 140 } 141 sb.append(derr.toString()); 142 sb.append("Normalized Covariance Matrix:\n"); 143 // stream << new_line << derr; 144 TrackError nerr = new TrackError(_err); 145 nerr.normalize(); 146 sb.append(" "+nerr); 147 // stream << new_line << nerr; 148 } 149 150 return sb.toString(); 151 } 152 153 154 // 155 156 /** 157 *get error matrix 158 * 159 * @return TrackError error matrix for track parameters 160 */ 161 public TrackError error() 162 { 163 return new TrackError(_err); 164 } 165 166 // 167 168 /** 169 *get a component of the error matrix 170 * 171 * @param i first index 172 * @param j second index 173 * @return value of error matrix element (i,j) 174 */ 175 public double error(int i, int j) 176 { 177 if( !(i>=0 && i<5) || !(j>=0 && j<5) ) 178 { 179 throw new IllegalArgumentException("Matrix indices must be within [0,4]!"); 180 } 181 return _err.matrix()[i][j]; 182 } 183 184 // 185 186 187 /** 188 *Return the number of bad entries in the error matrix. 189 * 190 * @return the number of bad entries in the error matrix 191 */ 192 public int checkError() 193 { 194 int nbad = 0; 195 for ( int i=0; i<5; ++i ) 196 { 197 double eii = _err.matrix()[i][i]; 198 if ( eii <= 0.0 ) ++nbad; 199 for ( int j=0; j<i; ++j ) 200 { 201 double ejj = _err.matrix()[j][j]; 202 double eij = _err.matrix()[j][i]; 203 if ( Math.abs(eij*eij) >= eii*ejj ) ++nbad; 204 } 205 } 206 return nbad; 207 } 208 209 210 /** equality 211 * 212 * @return true if this equals tre 213 * @param tre ETrack to compare 214 */ 215 public boolean equals(ETrack tre) 216 { 217 if ( !surface().equals(tre.surface()) ) return false; 218 if ( !vector().equals(tre.vector()) ) return false; 219 if ( !error().equals(tre.error()) ) return false; 220 return true; 221 } 222 223 224 /** Inequality 225 * 226 * @return true if this does not equal tre 227 * @param tre ETrack to compare 228 */ 229 public boolean notEquals(ETrack tre) 230 { 231 return !equals(tre); 232 } 233 234 //********************************************************************** 235 236 // 237 238 /** Return the difference between two track vectors with errors 239 * // weighted by their combined error matrix. 240 * 241 * @return chisquare difference of trv1 and trv2 242 * @param trv1 first ETrack 243 * @param trv2 second ETrack 244 */ 245 public static double chisqDiff( ETrack trv1, ETrack trv2 ) 246 { 247 // If surfaces are not the same, return -1.0. 248 if ( !trv1.surface().equals(trv2.surface()) ) return -1.0; 249 TrackVector vecdif = 250 trv1.surface().vecDiff( trv1.vector(), trv2.vector() ); 251 TrackError errsum = trv1.error().plus(trv2.error()); 252 // if ( invert(errsum) ) return -2.0; 253 return vecdif.getMatrix().transpose().times( errsum.inverse().getMatrix().times( vecdif.getMatrix() ) ).get(0,0); 254 } 255 256 //********************************************************************** 257 258 // 259 260 /** Get the difference between track vectors with and without errors 261 * weighted by the error matrix. 262 * 263 * @return chisquare difference of trv1 and trv2 264 * @param trv1 first ETrack 265 * @param trv2 second ETrack 266 */ 267 public static double chisqDiff( ETrack trv1, VTrack trv2 ) 268 { 269 // If surfaces are not the same, return -1.0. 270 if ( !trv1.surface().equals(trv2.surface()) ) return -1.0; 271 TrackVector vecdif = 272 trv1.surface().vecDiff( trv1.vector(), trv2.vector() ); 273 TrackError errsum = trv1.error(); 274 // if ( invert(errsum) ) return -2.0; 275 // return chisq_diff(vecdif,errsum); 276 return vecdif.getMatrix().transpose().times( errsum.inverse().getMatrix().times( vecdif.getMatrix() ) ).get(0,0); 277 } 278 279 //********************************************************************** 280 281 282 /** Get the difference between track vectors with and without errors 283 * weighted by the error matrix. 284 * 285 * @return chisquare difference of trv1 and trv2 286 * @param trv1 first VTrack 287 * @param trv2 second VTrack 288 */ 289 public static double chisqDiff( VTrack trv1, ETrack trv2 ) 290 { 291 return chisqDiff(trv2,trv1); 292 } 293 294 295 } 296 297 /* 298 // External functions. 299 300 // equality 301 bool operator==( ETrack trv1, ETrack trv2); 302 303 // inequality 304 bool operator!=( ETrack trv1, ETrack trv2); 305 306 // Get the difference between two track vectors with errors 307 // weighted by their combined error matrix. 308 double chisq_diff( ETrack trv1, ETrack trv2 ); 309 310 // Get the difference between two track vectors with and 311 // without errors weighted by the error matrix. 312 double chisq_diff( ETrack trv1, VTrack trv2 ); 313 314 // Get the difference between two track vectors without and 315 // with errors weighted by the error matrix. 316 double chisq_diff( VTrack trv1, ETrack trv2 ); 317 318 319 320 // equality 321 bool operator==(const ETrack& trv1, const ETrack& trv2) { 322 if ( *trv1.get_surface() != *trv2.get_surface() ) return false; 323 if ( trv1.get_vector() != trv2.get_vector() ) return false; 324 if ( trv1.get_error() != trv2.get_error() ) return false; 325 return true; 326 } 327 328 //********************************************************************** 329 330 // inequality 331 bool operator!=(const ETrack& trv1, const ETrack& trv2) { 332 return ! ( trv1 == trv2 ); 333 } 334 */