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 State();
00052
00054 virtual ~State() {}
00055
00056
00057 virtual const CLID& clID() const;
00058 static const CLID& classID();
00059
00061 unsigned int nParameters() const;
00062
00064 void positionAndMomentum(HepPoint3D& pos,
00065 HepVector3D& mom,
00066 HepSymMatrix& cov6D) const;
00067
00069 void positionAndMomentum(HepPoint3D& pos,
00070 HepVector3D& mom) const;
00071
00073 HepPoint3D position() const;
00074
00076 double x() const;
00077
00079 double y() const;
00080
00082 double z() const;
00083
00085 HepVector3D slopes() const;
00086
00088 double tx() const;
00089
00091 double ty() const;
00092
00094 virtual double qOverP() const;
00095
00097 virtual double p() const;
00098
00100 virtual double pt() const;
00101
00103 HepVector3D momentum() const;
00104
00106 double qOverPperp() const;
00107
00109 virtual HepSymMatrix posMomCovariance() const;
00110
00112 HepSymMatrix errPosition() const;
00113
00115 double errX2() const;
00116
00118 double errY2() const;
00119
00121 HepSymMatrix errSlopes() const;
00122
00124 double errTx2() const;
00125
00127 double errTy2() const;
00128
00130 virtual double errQOverP2() const;
00131
00133 virtual double errP2() const;
00134
00136 virtual HepSymMatrix errMomentum() const;
00137
00139 virtual double errQOverPperp2() const;
00140
00142 virtual State* clone() const;
00143
00145 virtual void reset();
00146
00148 void setState(const HepVector& state);
00149
00151 virtual void setState(double x,
00152 double y,
00153 double z,
00154 double tx,
00155 double ty,
00156 double qOverP);
00157
00159 void setState(double x,
00160 double y,
00161 double z,
00162 double tx,
00163 double ty);
00164
00166 void setCovariance(const HepSymMatrix& value);
00167
00169 void setX(double value);
00170
00172 void setY(double value);
00173
00175 void setZ(double value);
00176
00178 void setTx(double value);
00179
00181 void setTy(double value);
00182
00184 virtual void setQOverP(double value);
00185
00187 bool checkType(unsigned int value) const;
00188
00190 bool checkLocation(unsigned int value) const;
00191
00193 unsigned int flags() const;
00194
00196 void setFlags(unsigned int value);
00197
00199 unsigned int type() const;
00200
00202 void setType(unsigned int value);
00203
00205 unsigned int location() const;
00206
00208 void setLocation(unsigned int value);
00209
00211 const HepVector& state() const;
00212
00214 HepVector& state();
00215
00217 const HepSymMatrix& covariance() const;
00218
00220 HepSymMatrix& covariance();
00221
00222 protected:
00223
00225 enum flagsBits{typeBits = 0,
00226 locationBits = 3};
00227
00229 enum flagsMasks{typeMask = 0x7L,
00230 locationMask = 0x1FF8L};
00231
00232
00233 unsigned int m_flags;
00234 HepVector m_state;
00235 HepSymMatrix m_covariance;
00236 double m_z;
00237
00238 private:
00239
00240 };
00241
00242
00243
00244
00245
00246
00247
00248 inline const CLID& State::clID() const
00249 {
00250 return State::classID();
00251 }
00252
00253 inline const CLID& State::classID()
00254 {
00255 return CLID_State;
00256 }
00257
00258 inline unsigned int State::flags() const
00259 {
00260 return m_flags;
00261 }
00262
00263 inline void State::setFlags(unsigned int value)
00264 {
00265 m_flags = value;
00266 }
00267
00268 inline unsigned int State::type() const
00269 {
00270 return (unsigned int)((m_flags & typeMask) >> typeBits);
00271 }
00272
00273 inline void State::setType(unsigned int value)
00274 {
00275 unsigned int val = (unsigned int)value;
00276 m_flags &= ~typeMask;
00277 m_flags |= ((((unsigned int)val) << typeBits) & typeMask);
00278 }
00279
00280 inline unsigned int State::location() const
00281 {
00282 return (unsigned int)((m_flags & locationMask) >> locationBits);
00283 }
00284
00285 inline void State::setLocation(unsigned int value)
00286 {
00287 unsigned int val = (unsigned int)value;
00288 m_flags &= ~locationMask;
00289 m_flags |= ((((unsigned int)val) << locationBits) & locationMask);
00290 }
00291
00292 inline const HepVector& State::state() const
00293 {
00294 return m_state;
00295 }
00296
00297 inline HepVector& State::state()
00298 {
00299 return m_state;
00300 }
00301
00302 inline const HepSymMatrix& State::covariance() const
00303 {
00304 return m_covariance;
00305 }
00306
00307 inline HepSymMatrix& State::covariance()
00308 {
00309 return m_covariance;
00310 }
00311
00312 inline unsigned int State::nParameters() const
00313 {
00314
00315 return (unsigned int) m_state.num_row();
00316
00317 }
00318
00319 inline void State::positionAndMomentum(HepPoint3D& pos,
00320 HepVector3D& mom,
00321 HepSymMatrix& cov6D) const
00322 {
00323
00324 pos = position();
00325 mom = momentum();
00326 cov6D = posMomCovariance();
00327
00328 }
00329
00330 inline void State::positionAndMomentum(HepPoint3D& pos,
00331 HepVector3D& mom) const
00332 {
00333
00334 pos = position();
00335 mom = momentum();
00336
00337 }
00338
00339 inline HepPoint3D State::position() const
00340 {
00341
00342 return HepPoint3D( m_state[0], m_state[1], m_z );
00343
00344 }
00345
00346 inline double State::x() const
00347 {
00348
00349 return m_state[0];
00350
00351 }
00352
00353 inline double State::y() const
00354 {
00355
00356 return m_state[1];
00357
00358 }
00359
00360 inline double State::z() const
00361 {
00362
00363 return m_z;
00364
00365 }
00366
00367 inline HepVector3D State::slopes() const
00368 {
00369
00370 return HepVector3D( m_state[2], m_state[3], 1.);
00371
00372 }
00373
00374 inline double State::tx() const
00375 {
00376
00377 return m_state[2];
00378
00379 }
00380
00381 inline double State::ty() const
00382 {
00383
00384 return m_state[3];
00385
00386 }
00387
00388 inline HepVector3D State::momentum() const
00389 {
00390
00391 HepVector3D mom = slopes();
00392 mom *= ( p() / mom.mag() );
00393 return mom;
00394
00395 }
00396
00397 inline double State::qOverPperp() const
00398 {
00399
00400 double tx2 = tx() * tx();
00401 return ( qOverP() * sqrt( (1.+ tx2 + ty()*ty()) / (1. + tx2 ) ) );
00402
00403 }
00404
00405 inline HepSymMatrix State::errPosition() const
00406 {
00407
00408 const HepSymMatrix temp = posMomCovariance();
00409 return temp.sub(1,3);
00410
00411 }
00412
00413 inline double State::errX2() const
00414 {
00415
00416 return m_covariance.fast(1,1);
00417
00418 }
00419
00420 inline double State::errY2() const
00421 {
00422
00423 return m_covariance.fast(2,2);
00424
00425 }
00426
00427 inline HepSymMatrix State::errSlopes() const
00428 {
00429
00430 const HepSymMatrix temp = m_covariance;
00431 HepSymMatrix err = temp.sub(3,5);
00432 err.fast(2,1) = 0.;
00433 err.fast(3,1) = 0.;
00434 err.fast(3,2) = 0.;
00435 err.fast(3,3) = 0.;
00436 return err;
00437
00438 }
00439
00440 inline double State::errTx2() const
00441 {
00442
00443 return m_covariance.fast(3,3);
00444
00445 }
00446
00447 inline double State::errTy2() const
00448 {
00449
00450 return m_covariance.fast(4,4);
00451
00452 }
00453
00454 inline void State::setState(const HepVector& state)
00455 {
00456
00457 m_state = state;
00458
00459 }
00460
00461 inline void State::setState(double x,
00462 double y,
00463 double z,
00464 double tx,
00465 double ty)
00466 {
00467
00468 m_state[0] = x;
00469 m_state[1] = y;
00470 m_state[2] = tx;
00471 m_state[3] = ty;
00472 m_z = z;
00473
00474 }
00475
00476 inline void State::setCovariance(const HepSymMatrix& value)
00477 {
00478
00479 if ( value.num_row() == (int) nParameters() ) {
00480 m_covariance = value;
00481 }
00482 else {
00483 std::cerr << "ERROR The dimension of the covariance matrix does not match that of the state!"
00484 << "ERROR Using the default covariance matrix." << std::endl;
00485 int dim = nParameters();
00486 m_covariance = HepSymMatrix(dim,0);
00487 }
00488
00489 }
00490
00491 inline void State::setX(double value)
00492 {
00493
00494 m_state[0] = value;
00495
00496 }
00497
00498 inline void State::setY(double value)
00499 {
00500
00501 m_state[1] = value;
00502
00503 }
00504
00505 inline void State::setZ(double value)
00506 {
00507
00508 m_z = value;
00509
00510 }
00511
00512 inline void State::setTx(double value)
00513 {
00514
00515 m_state[2] = value;
00516
00517 }
00518
00519 inline void State::setTy(double value)
00520 {
00521
00522 m_state[3] = value;
00523
00524 }
00525
00526 inline bool State::checkType(unsigned int value) const
00527 {
00528
00529 return type() == value;
00530
00531 }
00532
00533 inline bool State::checkLocation(unsigned int value) const
00534 {
00535
00536 return location() == value;
00537
00538 }
00539
00540
00541 typedef KeyedContainer<State, Containers::HashMap> States;
00542
00543
00544
00545 #endif