00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TrackEvent_State_H
00016 #define TrackEvent_State_H 1
00017
00018
00019 #include "CLHEP/Geometry/Point3D.h"
00020 #include "CLHEP/Geometry/Vector3D.h"
00021 #include "GaudiKernel/KeyedContainer.h"
00022 #include "CLHEP/Matrix/Vector.h"
00023 #include "CLHEP/Matrix/SymMatrix.h"
00024
00025
00026
00027
00028
00029 static const CLID& CLID_State = 10011;
00030
00031
00032 namespace StateLocation {
00033 static const std::string& Default = "Rec/Track/States";
00034 }
00035
00036
00046 class State
00047 {
00048 public:
00049
00051 enum Type{ HasMomentum=1,
00052 StraightLine=2 };
00054 enum Location{ Unknown,
00055 ClosestToBeam,
00056 FirstMeasurement,
00057 EndVelo,
00058 AtTT,
00059 AtT,
00060 BegRich1,
00061 EndRich1,
00062 BegRich2,
00063 EndRich2,
00064 Calo,
00065 Muon };
00066
00068 State();
00069
00071 virtual ~State() {}
00072
00073
00074 virtual const CLID& clID() const;
00075 static const CLID& classID();
00076
00078 unsigned int nParameters() const;
00079
00081 void positionAndMomentum(HepPoint3D& pos,
00082 HepVector3D& mom,
00083 HepSymMatrix& cov6D) const;
00084
00086 void positionAndMomentum(HepPoint3D& pos,
00087 HepVector3D& mom) const;
00088
00090 HepPoint3D position() const;
00091
00093 double x() const;
00094
00096 double y() const;
00097
00099 double z() const;
00100
00102 HepVector3D slopes() const;
00103
00105 double tx() const;
00106
00108 double ty() const;
00109
00111 virtual double qOverP() const;
00112
00114 virtual double p() const;
00115
00117 virtual double pt() const;
00118
00120 HepVector3D momentum() const;
00121
00123 double qOverPperp() const;
00124
00126 virtual HepSymMatrix posMomCovariance() const;
00127
00129 HepSymMatrix errPosition() const;
00130
00132 double errX2() const;
00133
00135 double errY2() const;
00136
00138 HepSymMatrix errSlopes() const;
00139
00141 double errTx2() const;
00142
00144 double errTy2() const;
00145
00147 virtual double errQOverP2() const;
00148
00150 virtual double errP2() const;
00151
00153 virtual HepSymMatrix errMomentum() const;
00154
00156 virtual double errQOverPperp2() const;
00157
00159 virtual State* clone() const;
00160
00162 virtual void reset();
00163
00165 void setState(const HepVector& state);
00166
00168 virtual void setState(double x,
00169 double y,
00170 double z,
00171 double tx,
00172 double ty,
00173 double qOverP);
00174
00176 void setState(double x,
00177 double y,
00178 double z,
00179 double tx,
00180 double ty);
00181
00183 void setCovariance(const HepSymMatrix& value);
00184
00186 void setX(double value);
00187
00189 void setY(double value);
00190
00192 void setZ(double value);
00193
00195 void setTx(double value);
00196
00198 void setTy(double value);
00199
00201 virtual void setQOverP(double value);
00202
00204 unsigned int flags() const;
00205
00207 bool checkType(const Type& value) const;
00208
00210 void setLocation(const Location& value);
00211
00213 bool checkLocation(const Location& value) const;
00214
00216 const HepVector& state() const;
00217
00219 HepVector& state();
00220
00222 const HepSymMatrix& covariance() const;
00223
00225 HepSymMatrix& covariance();
00226
00227 protected:
00228
00230 void setType(const State::Type& value);
00231
00233 enum flagsBits{typeBits = 0,
00234 locationBits = 2};
00235
00237 enum flagsMasks{typeMask = 0x3L,
00238 locationMask = 0xFFCL};
00239
00240
00241 unsigned int m_flags;
00242 HepVector m_state;
00243 HepSymMatrix m_covariance;
00244 double m_z;
00245
00246 private:
00247
00248 };
00249
00250
00251
00252
00253
00254
00255
00256 inline const CLID& State::clID() const
00257 {
00258 return State::classID();
00259 }
00260
00261 inline const CLID& State::classID()
00262 {
00263 return CLID_State;
00264 }
00265
00266 inline unsigned int State::flags() const
00267 {
00268 return m_flags;
00269 }
00270
00271 inline bool State::checkType(const Type& value) const
00272 {
00273 unsigned int val = (unsigned int)value;
00274 return 0 != ( m_flags & typeMask & ( val << typeBits ));
00275 }
00276
00277 inline void State::setLocation(const Location& value)
00278 {
00279 unsigned int val = (unsigned int)value;
00280 m_flags &= ~locationMask;
00281 m_flags |= ((((unsigned int)val) << locationBits) & locationMask);
00282 }
00283
00284 inline bool State::checkLocation(const Location& value) const
00285 {
00286 unsigned int val = (unsigned int)value;
00287 return 0 != ( m_flags & locationMask & ( val << locationBits ));
00288 }
00289
00290 inline const HepVector& State::state() const
00291 {
00292 return m_state;
00293 }
00294
00295 inline HepVector& State::state()
00296 {
00297 return m_state;
00298 }
00299
00300 inline const HepSymMatrix& State::covariance() const
00301 {
00302 return m_covariance;
00303 }
00304
00305 inline HepSymMatrix& State::covariance()
00306 {
00307 return m_covariance;
00308 }
00309
00310 inline unsigned int State::nParameters() const
00311 {
00312
00313 return (unsigned int) m_state.num_row();
00314
00315 }
00316
00317 inline void State::positionAndMomentum(HepPoint3D& pos,
00318 HepVector3D& mom,
00319 HepSymMatrix& cov6D) const
00320 {
00321
00322 pos = position();
00323 mom = momentum();
00324 cov6D = posMomCovariance();
00325
00326 }
00327
00328 inline void State::positionAndMomentum(HepPoint3D& pos,
00329 HepVector3D& mom) const
00330 {
00331
00332 pos = position();
00333 mom = momentum();
00334
00335 }
00336
00337 inline HepPoint3D State::position() const
00338 {
00339
00340 return HepPoint3D( m_state[0], m_state[1], m_z );
00341
00342 }
00343
00344 inline double State::x() const
00345 {
00346
00347 return m_state[0];
00348
00349 }
00350
00351 inline double State::y() const
00352 {
00353
00354 return m_state[1];
00355
00356 }
00357
00358 inline double State::z() const
00359 {
00360
00361 return m_z;
00362
00363 }
00364
00365 inline HepVector3D State::slopes() const
00366 {
00367
00368 return HepVector3D( m_state[2], m_state[3], 1.);
00369
00370 }
00371
00372 inline double State::tx() const
00373 {
00374
00375 return m_state[2];
00376
00377 }
00378
00379 inline double State::ty() const
00380 {
00381
00382 return m_state[3];
00383
00384 }
00385
00386 inline HepVector3D State::momentum() const
00387 {
00388
00389 HepVector3D mom = slopes();
00390 mom *= ( p() / mom.mag() );
00391 return mom;
00392
00393 }
00394
00395 inline double State::qOverPperp() const
00396 {
00397
00398 double tx2 = tx() * tx();
00399 return ( qOverP() * sqrt( (1.+ tx2 + ty()*ty()) / (1. + tx2 ) ) );
00400
00401 }
00402
00403 inline HepSymMatrix State::errPosition() const
00404 {
00405
00406 const HepSymMatrix temp = posMomCovariance();
00407 return temp.sub(1,3);
00408
00409 }
00410
00411 inline double State::errX2() const
00412 {
00413
00414 return m_covariance.fast(1,1);
00415
00416 }
00417
00418 inline double State::errY2() const
00419 {
00420
00421 return m_covariance.fast(2,2);
00422
00423 }
00424
00425 inline HepSymMatrix State::errSlopes() const
00426 {
00427
00428 const HepSymMatrix temp = m_covariance;
00429 HepSymMatrix err = temp.sub(3,5);
00430 err.fast(2,1) = 0.;
00431 err.fast(3,1) = 0.;
00432 err.fast(3,2) = 0.;
00433 err.fast(3,3) = 0.;
00434 return err;
00435
00436 }
00437
00438 inline double State::errTx2() const
00439 {
00440
00441 return m_covariance.fast(3,3);
00442
00443 }
00444
00445 inline double State::errTy2() const
00446 {
00447
00448 return m_covariance.fast(4,4);
00449
00450 }
00451
00452 inline void State::setState(const HepVector& state)
00453 {
00454
00455 m_state = state;
00456
00457 }
00458
00459 inline void State::setState(double x,
00460 double y,
00461 double z,
00462 double tx,
00463 double ty)
00464 {
00465
00466 m_state[0] = x;
00467 m_state[1] = y;
00468 m_state[2] = tx;
00469 m_state[3] = ty;
00470 m_z = z;
00471
00472 }
00473
00474 inline void State::setCovariance(const HepSymMatrix& value)
00475 {
00476
00477 if ( value.num_row() == (int) nParameters() ) {
00478 m_covariance = value;
00479 }
00480 else {
00481 std::cerr << "ERROR The dimension of the covariance matrix does not match that of the state!"
00482 << "ERROR Using the default covariance matrix." << std::endl;
00483 int dim = nParameters();
00484 m_covariance = HepSymMatrix(dim,0);
00485 }
00486
00487 }
00488
00489 inline void State::setX(double value)
00490 {
00491
00492 m_state[0] = value;
00493
00494 }
00495
00496 inline void State::setY(double value)
00497 {
00498
00499 m_state[1] = value;
00500
00501 }
00502
00503 inline void State::setZ(double value)
00504 {
00505
00506 m_z = value;
00507
00508 }
00509
00510 inline void State::setTx(double value)
00511 {
00512
00513 m_state[2] = value;
00514
00515 }
00516
00517 inline void State::setTy(double value)
00518 {
00519
00520 m_state[3] = value;
00521
00522 }
00523
00524
00525 typedef KeyedContainer<State, Containers::HashMap> States;
00526
00527
00528
00529 #endif