00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TrackEvent_Track_H
00016 #define TrackEvent_Track_H 1
00017
00018
00019 #include "GaudiKernel/GaudiException.h"
00020 #include "Event/State.h"
00021 #include "Event/Measurement.h"
00022 #include "Event/Node.h"
00023 #include "Kernel/LHCbID.h"
00024 #include "CLHEP/Geometry/Plane3D.h"
00025 #include "GaudiKernel/KeyedObject.h"
00026 #include "GaudiKernel/KeyedContainer.h"
00027 #include "GaudiKernel/SmartRefVector.h"
00028 #include <vector>
00029
00030
00031
00032 class Point3D;
00033 class Vector3D;
00034 class SymMatrix;
00035
00036
00037
00038 static const CLID& CLID_Track = 10010;
00039
00040
00041 namespace TrackLocation {
00042 static const std::string& Default = "Rec/Track/Best";
00043 static const std::string& Ideal = "Rec/Track/Ideal";
00044 static const std::string& Velo = "Rec/Track/Velo";
00045 static const std::string& Seed = "Rec/Track/Seed";
00046 static const std::string& Match = "Rec/Track/Match";
00047 static const std::string& Forward = "Rec/Track/Forward";
00048 static const std::string& Follow = "Rec/Track/Follow";
00049 static const std::string& VeloTT = "Rec/Track/VeloTT";
00050 static const std::string& KsTrack = "Rec/Track/KsTrack";
00051 }
00052
00053
00063 class Track: public KeyedObject<int>
00064 {
00065 public:
00066
00068 Track(int key) : KeyedObject<int>( key ),
00069 m_chi2PerDoF(0.0),
00070 m_nDoF(0),
00071 m_flags(0),
00072 m_lhcbIDs(),
00073 m_states(),
00074 m_measurements(),
00075 m_nodes(),
00076 m_ancestors() {}
00077
00079 Track() : m_chi2PerDoF(0.0),
00080 m_nDoF(0),
00081 m_flags(0),
00082 m_lhcbIDs(),
00083 m_states(),
00084 m_measurements(),
00085 m_nodes() {}
00086
00088 ~Track();
00089
00090
00091 virtual const CLID& clID() const;
00092 static const CLID& classID();
00093
00095 void positionAndMomentum(HepPoint3D& pos,
00096 HepVector3D& mom,
00097 HepSymMatrix& cov6D) const;
00098
00100 void positionAndMomentum(HepPoint3D& pos,
00101 HepVector3D& mom) const;
00102
00104 HepPoint3D position() const;
00105
00107 void position(HepPoint3D& pos,
00108 HepSymMatrix& errPos) const;
00109
00111 HepVector3D slopes() const;
00112
00114 void slopes(HepVector3D& slopes,
00115 HepSymMatrix& errSlopes) const;
00116
00118 HepVector3D momentum() const;
00119
00121 double p() const;
00122
00124 double pt() const;
00125
00127 void momentum(HepVector3D& mom,
00128 HepSymMatrix& errMom) const;
00129
00131 void posMomCovariance(HepSymMatrix& cov6D) const;
00132
00134 State & firstState() const;
00135
00137 int charge() const;
00138
00140 double chi2() const;
00141
00143 unsigned int nStates() const;
00144
00146 void addToStates(const State& state);
00147
00149 void removeFromStates(State* value);
00150
00152 State & closestState(double z);
00153
00155 const State & closestState(double z) const;
00156
00158 State & closestState(const HepPlane3D& plane);
00159
00161 const State & closestState(const HepPlane3D& plane) const;
00162
00164 bool hasStateAt(unsigned int location) const;
00165
00167 State & stateAt(unsigned int location);
00168
00170 const State & stateAt(unsigned int location) const;
00171
00173 unsigned int nMeasurements() const;
00174
00176 void addToMeasurements(const Measurement& meas);
00177
00179 void removeFromMeasurements(Measurement* value);
00180
00182 void addToNodes(Node* node);
00183
00185 void removeFromNodes(Node* value);
00186
00188 void addToLhcbIDs(const LHCbID& value);
00189
00191 void removeFromLhcbIDs(const LHCbID& value);
00192
00194 void addToAncestors(const Track & ancestor);
00195
00197 virtual void reset();
00198
00200 virtual Track* clone() const;
00201
00203 bool checkType(unsigned int value) const;
00204
00206 bool checkHistory(unsigned int value) const;
00207
00209 bool checkHistoryFit(unsigned int value) const;
00210
00212 void setFlag(unsigned int flag,
00213 bool ok);
00214
00216 bool checkFlag(unsigned int flag) const;
00217
00219 double chi2PerDoF() const;
00220
00222 void setChi2PerDoF(double value);
00223
00225 int nDoF() const;
00226
00228 void setNDoF(int value);
00229
00231 unsigned int flags() const;
00232
00234 void setFlags(unsigned int value);
00235
00237 unsigned int type() const;
00238
00240 void setType(unsigned int value);
00241
00243 unsigned int history() const;
00244
00246 void setHistory(unsigned int value);
00247
00249 unsigned int historyFit() const;
00250
00252 void setHistoryFit(unsigned int value);
00253
00255 unsigned int status() const;
00256
00258 void setStatus(unsigned int value);
00259
00261 unsigned int flag() const;
00262
00264 unsigned int specific() const;
00265
00267 void setSpecific(unsigned int value);
00268
00270 const std::vector<LHCbID>& lhcbIDs() const;
00271
00273 std::vector<LHCbID>& lhcbIDs();
00274
00276 void setLhcbIDs(const std::vector<LHCbID>& value);
00277
00279 const std::vector<State*>& states() const;
00280
00282 std::vector<State*>& states();
00283
00285 const std::vector<Measurement*>& measurements() const;
00286
00288 std::vector<Measurement*>& measurements();
00289
00291 const std::vector<Node*>& nodes() const;
00292
00294 std::vector<Node*>& nodes();
00295
00297 const SmartRefVector<Track>& ancestors() const;
00298
00300 SmartRefVector<Track>& ancestors();
00301
00303 void addToAncestors(const SmartRef<Track>& value);
00304
00306 void addToAncestors(const Track* value);
00307
00309 void removeFromAncestors(const SmartRef<Track>& value);
00310
00312 void clearAncestors();
00313
00314 protected:
00315
00317 enum flagsBits{typeBits = 0,
00318 historyBits = 5,
00319 historyFitBits = 10,
00320 statusBits = 15,
00321 flagBits = 18,
00322 specificBits = 28};
00323
00325 enum flagsMasks{typeMask = 0x1FL,
00326 historyMask = 0x3E0L,
00327 historyFitMask = 0x7C00L,
00328 statusMask = 0x38000L,
00329 flagMask = 0xFFC0000L,
00330 specificMask = 0xF0000000L};
00331
00332
00333 double m_chi2PerDoF;
00334 int m_nDoF;
00335 unsigned int m_flags;
00336 std::vector<LHCbID> m_lhcbIDs;
00337 std::vector<State*> m_states;
00338 std::vector<Measurement*> m_measurements;
00339 std::vector<Node*> m_nodes;
00340 SmartRefVector<Track> m_ancestors;
00341
00342 private:
00343
00344 };
00345
00346
00347
00348
00349
00350
00351 #include "CLHEP/Geometry/Point3D.h"
00352 #include "CLHEP/Geometry/Vector3D.h"
00353 #include "CLHEP/Matrix/SymMatrix.h"
00354
00355
00356 inline Track::~Track()
00357 {
00358
00359 reset();
00360
00361 }
00362
00363 inline const CLID& Track::clID() const
00364 {
00365 return Track::classID();
00366 }
00367
00368 inline const CLID& Track::classID()
00369 {
00370 return CLID_Track;
00371 }
00372
00373 inline double Track::chi2PerDoF() const
00374 {
00375 return m_chi2PerDoF;
00376 }
00377
00378 inline void Track::setChi2PerDoF(double value)
00379 {
00380 m_chi2PerDoF = value;
00381 }
00382
00383 inline int Track::nDoF() const
00384 {
00385 return m_nDoF;
00386 }
00387
00388 inline void Track::setNDoF(int value)
00389 {
00390 m_nDoF = value;
00391 }
00392
00393 inline unsigned int Track::flags() const
00394 {
00395 return m_flags;
00396 }
00397
00398 inline void Track::setFlags(unsigned int value)
00399 {
00400 m_flags = value;
00401 }
00402
00403 inline unsigned int Track::type() const
00404 {
00405 return (unsigned int)((m_flags & typeMask) >> typeBits);
00406 }
00407
00408 inline void Track::setType(unsigned int value)
00409 {
00410 unsigned int val = (unsigned int)value;
00411 m_flags &= ~typeMask;
00412 m_flags |= ((((unsigned int)val) << typeBits) & typeMask);
00413 }
00414
00415 inline unsigned int Track::history() const
00416 {
00417 return (unsigned int)((m_flags & historyMask) >> historyBits);
00418 }
00419
00420 inline void Track::setHistory(unsigned int value)
00421 {
00422 unsigned int val = (unsigned int)value;
00423 m_flags &= ~historyMask;
00424 m_flags |= ((((unsigned int)val) << historyBits) & historyMask);
00425 }
00426
00427 inline unsigned int Track::historyFit() const
00428 {
00429 return (unsigned int)((m_flags & historyFitMask) >> historyFitBits);
00430 }
00431
00432 inline void Track::setHistoryFit(unsigned int value)
00433 {
00434 unsigned int val = (unsigned int)value;
00435 m_flags &= ~historyFitMask;
00436 m_flags |= ((((unsigned int)val) << historyFitBits) & historyFitMask);
00437 }
00438
00439 inline unsigned int Track::status() const
00440 {
00441 return (unsigned int)((m_flags & statusMask) >> statusBits);
00442 }
00443
00444 inline void Track::setStatus(unsigned int value)
00445 {
00446 unsigned int val = (unsigned int)value;
00447 m_flags &= ~statusMask;
00448 m_flags |= ((((unsigned int)val) << statusBits) & statusMask);
00449 }
00450
00451 inline unsigned int Track::flag() const
00452 {
00453 return (unsigned int)((m_flags & flagMask) >> flagBits);
00454 }
00455
00456 inline unsigned int Track::specific() const
00457 {
00458 return (unsigned int)((m_flags & specificMask) >> specificBits);
00459 }
00460
00461 inline void Track::setSpecific(unsigned int value)
00462 {
00463 unsigned int val = (unsigned int)value;
00464 m_flags &= ~specificMask;
00465 m_flags |= ((((unsigned int)val) << specificBits) & specificMask);
00466 }
00467
00468 inline const std::vector<LHCbID>& Track::lhcbIDs() const
00469 {
00470 return m_lhcbIDs;
00471 }
00472
00473 inline std::vector<LHCbID>& Track::lhcbIDs()
00474 {
00475 return m_lhcbIDs;
00476 }
00477
00478 inline void Track::setLhcbIDs(const std::vector<LHCbID>& value)
00479 {
00480 m_lhcbIDs = value;
00481 }
00482
00483 inline const std::vector<State*>& Track::states() const
00484 {
00485 return m_states;
00486 }
00487
00488 inline std::vector<State*>& Track::states()
00489 {
00490 return m_states;
00491 }
00492
00493 inline const std::vector<Measurement*>& Track::measurements() const
00494 {
00495 return m_measurements;
00496 }
00497
00498 inline std::vector<Measurement*>& Track::measurements()
00499 {
00500 return m_measurements;
00501 }
00502
00503 inline const std::vector<Node*>& Track::nodes() const
00504 {
00505 return m_nodes;
00506 }
00507
00508 inline std::vector<Node*>& Track::nodes()
00509 {
00510 return m_nodes;
00511 }
00512
00513 inline const SmartRefVector<Track>& Track::ancestors() const
00514 {
00515 return m_ancestors;
00516 }
00517
00518 inline SmartRefVector<Track>& Track::ancestors()
00519 {
00520 return m_ancestors;
00521 }
00522
00523 inline void Track::addToAncestors(const SmartRef<Track>& value)
00524 {
00525 m_ancestors.push_back(value);
00526 }
00527
00528 inline void Track::addToAncestors(const Track* value)
00529 {
00530 m_ancestors.push_back(value);
00531 }
00532
00533 inline void Track::removeFromAncestors(const SmartRef<Track>& value)
00534 {
00535 SmartRefVector<Track>::iterator iter =
00536 std::remove(m_ancestors.begin(), m_ancestors.end(), value);
00537 m_ancestors.erase(iter, m_ancestors.end());
00538 }
00539
00540 inline void Track::clearAncestors()
00541 {
00542 m_ancestors.clear();
00543 }
00544
00545 inline HepPoint3D Track::position() const
00546 {
00547
00548 return firstState().position();
00549
00550 }
00551
00552 inline HepVector3D Track::slopes() const
00553 {
00554
00555 return firstState().slopes();
00556
00557 }
00558
00559 inline HepVector3D Track::momentum() const
00560 {
00561
00562 return firstState().momentum();
00563
00564 }
00565
00566 inline State & Track::firstState() const
00567 {
00568
00569
00570 if ( m_states.empty() )
00571 throw GaudiException( "first (first) state not defined!",
00572 "Track.h",
00573 StatusCode::FAILURE );
00574 return *m_states[0];
00575
00576 }
00577
00578 inline int Track::charge() const
00579 {
00580
00581 double qP = firstState().qOverP();
00582 return ( qP != 0. ? int(fabs(qP)/qP) : 0 );
00583
00584 }
00585
00586 inline double Track::chi2() const
00587 {
00588
00589 return ( m_chi2PerDoF * double(m_nDoF) );
00590
00591 }
00592
00593 inline unsigned int Track::nStates() const
00594 {
00595
00596 return m_states.size();
00597
00598 }
00599
00600 inline unsigned int Track::nMeasurements() const
00601 {
00602
00603 unsigned int n = m_measurements.size();
00604 if (n == 0) n = m_lhcbIDs.size();
00605 return n;
00606
00607 }
00608
00609 inline void Track::addToNodes(Node* node)
00610 {
00611
00612 m_nodes.push_back( node );
00613
00614 }
00615
00616 inline void Track::addToLhcbIDs(const LHCbID& value)
00617 {
00618
00619 m_lhcbIDs.push_back( value );
00620
00621 }
00622
00623 inline void Track::removeFromLhcbIDs(const LHCbID& value)
00624 {
00625
00626 std::vector<LHCbID>::iterator iter =
00627 std::remove( m_lhcbIDs.begin(), m_lhcbIDs.end(), value );
00628 m_lhcbIDs.erase( iter, m_lhcbIDs.end() );
00629
00630 }
00631
00632 inline void Track::addToAncestors(const Track & ancestor)
00633 {
00634
00635 m_ancestors.push_back( (Track*) &ancestor );
00636
00637 }
00638
00639 inline bool Track::checkType(unsigned int value) const
00640 {
00641
00642 return type() == value;
00643
00644 }
00645
00646 inline bool Track::checkHistory(unsigned int value) const
00647 {
00648
00649 return history() == value;
00650
00651 }
00652
00653 inline bool Track::checkHistoryFit(unsigned int value) const
00654 {
00655
00656 return historyFit() == value;
00657
00658 }
00659
00660 inline void Track::setFlag(unsigned int flag,
00661 bool ok)
00662 {
00663
00664 unsigned int val = (((unsigned int) flag) << flagBits) & flagMask;
00665 if (ok) m_flags |= val;
00666 else m_flags &= ~val;
00667
00668 }
00669
00670 inline bool Track::checkFlag(unsigned int flag) const
00671 {
00672
00673 unsigned int val = ((unsigned int) flag << flagBits);
00674 bool ok = (0 != ( m_flags & flagMask & val ));
00675 return ok;
00676
00677 }
00678
00679
00680 typedef KeyedContainer<Track, Containers::HashMap> Tracks;
00681
00682
00683
00684 #endif