00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef TrEvent_TrState_H
00019 #define TrEvent_TrState_H 1
00020
00021
00022 #include "Kernel/CLHEPStreams.h"
00023 #include "CLHEP/Matrix/SymMatrix.h"
00024 #include "CLHEP/Matrix/Vector.h"
00025 #include "GaudiKernel/ObjectList.h"
00026 #include "GaudiKernel/ObjectVector.h"
00027 #include "CLHEP/Geometry/Point3D.h"
00028 #include "GaudiKernel/StreamBuffer.h"
00029 #include "CLHEP/Geometry/Vector3D.h"
00030
00031
00032
00033 static const CLID& CLID_TrState = 10004;
00034
00035
00036 namespace TrStateLocation {
00037 static const std::string& Default = "Rec/Tr/States";
00038 }
00039
00040
00050 class TrState
00051 {
00052
00053 public:
00054
00055 enum Type {HasMomentum,StraightLine};
00056 enum Location {MostUpstream,FirstMeasurement,AtTT,AtT,BegRich1,EndRich1,BegRich2,EndRich2,Calo,Muon};
00057
00059 TrState();
00060
00062 virtual ~TrState() {}
00063
00065 virtual const CLID& clID() const;
00066 static const CLID& classID();
00067
00069 unsigned int nParameters() const;
00070
00072 void positionAndMomentum(HepPoint3D& pos, HepVector3D& mom, HepSymMatrix& cov6D) const;
00073
00075 HepPoint3D position() const;
00076
00078 double x() const;
00079
00081 double y() const;
00082
00084 double z() const;
00085
00087 HepVector3D slopes() const;
00088
00090 double tx() const;
00091
00093 double ty() const;
00094
00096 virtual double qOverP() const;
00097
00099 virtual double p() const;
00100
00102 virtual double pt() const;
00103
00105 HepVector3D momentum() const;
00106
00108 double qOverPperp() const;
00109
00111 virtual HepSymMatrix posMomCovariance() const;
00112
00114 HepSymMatrix errPosition() const;
00115
00117 double errX2() const;
00118
00120 double errY2() const;
00121
00123 HepSymMatrix errSlopes() const;
00124
00126 double errTx2() const;
00127
00129 double errTy2() const;
00130
00132 virtual double errQOverP2() const;
00133
00135 virtual double errP2() const;
00136
00138 virtual HepSymMatrix errMomentum() const;
00139
00141 virtual double errQOverPperp2() const;
00142
00144 virtual TrState* clone() const;
00145
00147 virtual void reset();
00148
00150 bool type(unsigned value) const;
00151
00153 bool location(unsigned value) const;
00154
00156 void setState(const HepVector& state);
00157
00159 virtual void setState(double x, double y, double z, double tx, double ty, double qOverP);
00160
00162 void setState(double x, double y, double z, double tx, double ty);
00163
00165 void setCovariance(const HepSymMatrix& value);
00166
00168 void setX(double value);
00169
00171 void setY(double value);
00172
00174 void setTx(double value);
00175
00177 void setTy(double value);
00178
00180 virtual void setQOverP(double value);
00181
00183 void setLocation(unsigned value);
00184
00186 unsigned flags() const;
00187
00189 const HepVector& state() const;
00190
00192 HepVector& state();
00193
00195 const HepSymMatrix& covariance() const;
00196
00198 HepSymMatrix& covariance();
00199
00201 virtual StreamBuffer& serialize(StreamBuffer& s) const;
00202
00204 virtual StreamBuffer& serialize(StreamBuffer& s);
00205
00207 virtual std::ostream& fillStream(std::ostream& s) const;
00208
00209 protected:
00210
00212 bool isFlagSet(unsigned bits, unsigned mask);
00213
00215 void setType(unsigned value);
00216
00218 void setFlag(bool value, unsigned bits, unsigned mask);
00219
00220 private:
00221
00222 enum flagsBits {LocationMostUpstreamBits = 0, LocationFirstMeasurementBits = 1, LocationAtTTBits = 2, LocationAtTBits = 3, LocationBegRich1Bits = 4, LocationEndRich1Bits = 5, LocationBegRich2Bits = 6, LocationEndRich2Bits = 7, LocationCaloBits = 8, LocationMuonBits = 9, TypeHasMomentumBits = 10, TypeStraightLineBits = 11};
00223 enum flagsMasks {LocationMostUpstreamMask = 0x00000001, LocationFirstMeasurementMask = 0x00000002, LocationAtTTMask = 0x00000004, LocationAtTMask = 0x00000008, LocationBegRich1Mask = 0x00000010, LocationEndRich1Mask = 0x00000020, LocationBegRich2Mask = 0x00000040, LocationEndRich2Mask = 0x00000080, LocationCaloMask = 0x00000100, LocationMuonMask = 0x00000200, TypeHasMomentumMask = 0x00000400, TypeStraightLineMask = 0x00000800};
00224
00225 unsigned m_flags;
00226 HepVector m_state;
00227 HepSymMatrix m_covariance;
00228 double m_z;
00229
00230 };
00231
00232
00233
00234
00235
00236
00237 inline const CLID& TrState::clID() const
00238 {
00239 return TrState::classID();
00240 }
00241
00242 inline const CLID& TrState::classID()
00243 {
00244 return CLID_TrState;
00245 }
00246
00247 inline unsigned int TrState::nParameters() const
00248 {
00249
00250 return (unsigned int) m_state.num_row();
00251
00252 }
00253
00254 inline void TrState::positionAndMomentum(HepPoint3D& pos, HepVector3D& mom, HepSymMatrix& cov6D) const
00255 {
00256
00257 pos = position();
00258 mom = momentum();
00259 cov6D = posMomCovariance();
00260
00261 }
00262
00263 inline HepPoint3D TrState::position() const
00264 {
00265
00266 return HepPoint3D( m_state[0], m_state[1], m_z );
00267
00268 }
00269
00270 inline double TrState::x() const
00271 {
00272
00273 return m_state[0];
00274
00275 }
00276
00277 inline double TrState::y() const
00278 {
00279
00280 return m_state[1];
00281
00282 }
00283
00284 inline double TrState::z() const
00285 {
00286
00287 return m_z;
00288
00289 }
00290
00291 inline HepVector3D TrState::slopes() const
00292 {
00293
00294 return HepVector3D( m_state[2], m_state[3], 1.);
00295
00296 }
00297
00298 inline double TrState::tx() const
00299 {
00300
00301 return m_state[2];
00302
00303 }
00304
00305 inline double TrState::ty() const
00306 {
00307
00308 return m_state[3];
00309
00310 }
00311
00312 inline HepVector3D TrState::momentum() const
00313 {
00314
00315 HepVector3D mom = slopes();
00316 mom *= ( p() / mom.mag() );
00317 return mom;
00318
00319 }
00320
00321 inline double TrState::qOverPperp() const
00322 {
00323
00324 double tx2 = tx() * tx();
00325 return ( qOverP() * sqrt( (1.+ tx2 + ty()*ty()) / (1. + tx2 ) ) );
00326
00327 }
00328
00329 inline HepSymMatrix TrState::errPosition() const
00330 {
00331
00332 return posMomCovariance().sub(1,3);
00333
00334 }
00335
00336 inline double TrState::errX2() const
00337 {
00338
00339 return m_covariance.fast(1,1);
00340
00341 }
00342
00343 inline double TrState::errY2() const
00344 {
00345
00346 return m_covariance.fast(2,2);
00347
00348 }
00349
00350 inline HepSymMatrix TrState::errSlopes() const
00351 {
00352
00353 HepSymMatrix err = m_covariance.sub(3,5);
00354 err.fast(2,1) = 0.;
00355 err.fast(3,1) = 0.;
00356 err.fast(3,2) = 0.;
00357 err.fast(3,3) = 0.;
00358 return err;
00359
00360 }
00361
00362 inline double TrState::errTx2() const
00363 {
00364
00365 return m_covariance.fast(3,3);
00366
00367 }
00368
00369 inline double TrState::errTy2() const
00370 {
00371
00372 return m_covariance.fast(4,4);
00373
00374 }
00375
00376 inline void TrState::setState(const HepVector& state)
00377 {
00378
00379 m_state = state;
00380
00381 }
00382
00383 inline void TrState::setState(double x, double y, double z, double tx, double ty)
00384 {
00385
00386 m_state[0] = x;
00387 m_state[1] = y;
00388 m_state[2] = tx;
00389 m_state[3] = ty;
00390 m_z = z;
00391
00392 }
00393
00394 inline void TrState::setCovariance(const HepSymMatrix& value)
00395 {
00396
00397 if ( value.num_row() == (int) nParameters() ) {
00398 m_covariance = value;
00399 }
00400 else {
00401 std::cerr << "ERROR The dimension of the covariance matrix does not match that of the state!"
00402 << "ERROR Using the default covariance matrix." << std::endl;
00403 int dim = nParameters();
00404 m_covariance = HepSymMatrix(dim,0);
00405 }
00406
00407 }
00408
00409 inline void TrState::setX(double value)
00410 {
00411
00412 m_state[0] = value;
00413
00414 }
00415
00416 inline void TrState::setY(double value)
00417 {
00418
00419 m_state[1] = value;
00420
00421 }
00422
00423 inline void TrState::setTx(double value)
00424 {
00425
00426 m_state[2] = value;
00427
00428 }
00429
00430 inline void TrState::setTy(double value)
00431 {
00432
00433 m_state[3] = value;
00434
00435 }
00436
00437 inline unsigned TrState::flags() const
00438 {
00439 return m_flags;
00440 }
00441
00442 inline const HepVector& TrState::state() const
00443 {
00444 return m_state;
00445 }
00446
00447 inline HepVector& TrState::state()
00448 {
00449 return m_state;
00450 }
00451
00452 inline const HepSymMatrix& TrState::covariance() const
00453 {
00454 return m_covariance;
00455 }
00456
00457 inline HepSymMatrix& TrState::covariance()
00458 {
00459 return m_covariance;
00460 }
00461
00462 inline StreamBuffer& TrState::serialize(StreamBuffer& s) const
00463 {
00464 s << m_flags
00465 << m_state
00466 << m_covariance
00467 << (float)m_z;
00468 return s;
00469 }
00470
00471 inline StreamBuffer& TrState::serialize(StreamBuffer& s)
00472 {
00473 float l_z;
00474 s >> m_flags
00475 >> m_state
00476 >> m_covariance
00477 >> l_z;
00478 m_z = l_z;
00479 return s;
00480 }
00481
00482 inline std::ostream& TrState::fillStream(std::ostream& s) const
00483 {
00484 s << "{ "
00485 << " flags:\t" << m_flags << std::endl
00486 << " state:\t" << m_state << std::endl
00487 << " covariance:\t" << m_covariance << std::endl
00488 << " z:\t" << (float)m_z << " } ";
00489 return s;
00490 }
00491
00492
00493 #endif