00001
00019 #ifndef StiKalmanTrack_H
00020 #define StiKalmanTrack_H 1
00021
00022
00023 #include <vector>
00024 using namespace std;
00025
00026 #include "Sti/Base/Factory.h"
00027 #include "StiKTNIterator.h"
00028 #include "StiTrack.h"
00029
00030 #include "StThreeVectorD.hh"
00031 #include "StMCTruth.h"
00032 class StiHit;
00033 class StiTrackNode;
00034 class StiKalmanTrackNode;
00035
00078 class StiKalmanTrack : public StiTrack
00079 {
00080 public:
00081
00090 StiKalmanTrack() :
00091 firstNode(0),
00092 lastNode(0),
00093 mSeedHitCount(0),
00094 mFlag(0),
00095 m(-1.)
00096 { }
00097
00103 virtual ~StiKalmanTrack()
00104 { }
00105
00107 static void setKalmanTrackNodeFactory(Factory<StiKalmanTrackNode>*);
00108 static void setMaxRefiter(int maxRefiter);
00109
00110 void reset();
00111 void unset();
00112
00114 void getMomentum(double p[3], double e[6]) const ;
00115
00117 double getP() const;
00118
00120 double getPt() const;
00121
00123 double getCurvature() const;
00124
00126 double getRapidity() const;
00127
00129 double getPseudoRapidity() const;
00130
00132 double getPhi() const;
00133
00135 double getTanL() const;
00136
00142 double getDca() const;
00143 virtual double getDca(const StiHit * vertex) const;
00144
00145 void setDca(double dca);
00146
00151 double getDca(StiTrack *t) const;
00152
00157
00158 int getPointCount(int detectorId=0) const;
00159
00161 int getFitPointCount(int detectorId=0) const;
00162
00164 void getAllPointCount(int count[1][3],int maxDetId) const;
00165
00167 int getGapCount() const;
00168
00174 double getTrackLength() const;
00182 double getNearBeam(StThreeVectorD *pnt=0,StThreeVectorD *dir=0) const;
00183
00190 int getMaxPointCount(int detectorId=0) const;
00191
00192 UShort_t getSeedHitCount() const {return mSeedHitCount;}
00193 void setSeedHitCount(UShort_t c) {mSeedHitCount=c;}
00194
00201 int isPrimary() const {return mVertex;}
00202 void setPrimary(int vertex) {mVertex=vertex;}
00203
00204 double calculateTrackLength() const;
00205 double calculateTrackSegmentLength(const StiKalmanTrackNode &p1, const StiKalmanTrackNode &p2) const;
00206 double getTrackRadLength() const;
00207 int calculatePointCount() const;
00208 int calculateMaxPointCount() const;
00209
00210 double getTpcDedx() const;
00211 double getSvtDedx() const;
00212
00213 StiKTNBidirectionalIterator begin() const;
00214 const StiKTNBidirectionalIterator& end() const;
00215 StiKTNBidirectionalIterator rbegin() const;
00216 const StiKTNBidirectionalIterator& rend() const;
00217 void removeLastNode();
00218
00223 StiKalmanTrackNode * getInnOutMostNode(int inot,int qua) const;
00225 StiKalmanTrackNode * getOuterMostNode(int qua=0) const;
00227 StiKalmanTrackNode * getInnerMostNode(int qua=0) const;
00228
00230 StiKalmanTrackNode * getOuterMostHitNode(int qua=0) const;
00232 StiKalmanTrackNode * getInnerMostHitNode(int qua=0) const;
00233 #ifdef DO_TPCCATRACKER
00234 StiKalmanTrackNode * getInnerMostTPCHitNode(int qua=0) const;
00235 #endif
00236 int getNNodes(int qua=0) const;
00237 int releaseHits(double rMin=4,double rMax=50);
00239 StiKalmanTrackNode * getFirstNode() const { return firstNode; };
00241
00242 StiKalmanTrackNode * getLastNode() const { return lastNode; };
00243
00244 void setLastNode (StiKalmanTrackNode *n) { lastNode = n; };
00245 void setFirstNode(StiKalmanTrackNode *n) { firstNode = n; };
00246 void setFirstLastNode(StiKalmanTrackNode *n);
00247
00248
00251 virtual void add(StiTrackNode * node,int direction);
00252
00254 int initialize(const vector<StiHit*> &);
00255 #ifdef DO_TPCCATRACKER
00256 int initialize0(const std::vector<StiHit*> &hits, StiNodePars *firstPars = 0, StiNodePars *lastPars = 0, StiNodeErrs *firstErrs = 0, StiNodeErrs *lastErrs = 0);
00257 #endif
00259
00260 StThreeVector<double> getMomentumAtOrigin() const;
00261 StThreeVector<double> getPoint(int firstLast=0) const;
00262
00263 virtual vector<StiHit*> getHits();
00264 virtual vector<const StMeasuredPoint*> stHits() const;
00265 virtual vector<StiKalmanTrackNode*> getNodes(int detectorGroupId) const;
00266
00267
00268 double getMass() const;
00269 int getCharge()const;
00270 double getChi2() const;
00271 double getDca2(StiTrack *t) const;
00272 double getDca3(StiTrack *t) const;
00273
00274 bool find(int direction=kOutsideIn);
00275 int refit();
00276 int refitL();
00277 void reserveHits();
00278 StiTrackNode *extendToVertex(StiHit* vertex);
00279 #if 0
00280 bool extendToVertex(StiHit* vertex, const StiDetector*alternate);
00281 #endif
00282 void setFlag(long v);
00283 long getFlag() const;
00284
00285 StiKalmanTrackNode * extrapolateToBeam();
00286 StiKalmanTrackNode * extrapolateToRadius(double radius);
00287 int approx(int mode=0);
00288
00289 void reduce();
00290
00291 StMCTruth getTruth(double rXYMin=0, double rXYMax=1000) const;
00292 void print(const char *opt="") const;
00293 static void setDebug(int m = 0) {_debug = m;}
00294 static int debug() {return _debug;}
00295 StiKalmanTrack &operator=(const StiKalmanTrack &tk);
00296 int rejectByHitSet() const;
00297
00298 typedef enum{
00299 kNoErrors = 0,
00300 kRefitFail,
00301 kNotEnoughUsed,
00302 kInNodeNotValid,
00303 kBadQA,
00304 kVertexNodeInvalid,
00305 kNodeNotValid,
00306 kTooManyDroppedNodes
00307 } TRefitStatus;
00308
00309
00310 protected:
00311 friend ostream& operator<<(ostream& os, const StiKalmanTrack& track);
00312 protected:
00313
00314 static int mgMaxRefiter;
00315 static Factory<StiKalmanTrackNode> * trackNodeFactory;
00316
00317 StiKalmanTrackNode * firstNode;
00318 StiKalmanTrackNode * lastNode;
00319
00320 UShort_t mSeedHitCount;
00321 int mVertex;
00322 long mFlag;
00323 double m;
00324
00325 double _dca;
00326
00327 public:
00328 double _vChi2;
00329 static int _debug;
00330
00331 };
00332
00335 inline double StiKalmanTrack::getMass() const
00336 {
00337 return m;
00338 }
00339
00340 inline void StiKalmanTrack::setFlag(long v)
00341 {
00342 mFlag = v;
00343 }
00344
00345 inline long StiKalmanTrack::getFlag() const
00346 {
00347 return mFlag;
00348 }
00349
00366 inline void StiKalmanTrack::getMomentum(double p[3], double e[6]) const
00367 {
00368
00369
00370
00371 getInnerMostHitNode()->getMomentum(p,e);
00372 }
00373
00378 inline double StiKalmanTrack::getP() const
00379 {
00380 return getInnerMostHitNode()->getP();
00381 }
00382
00387 inline double StiKalmanTrack::getPt() const
00388 {
00389 return getInnerMostHitNode()->getPt();
00390 }
00391
00397 inline double StiKalmanTrack::getCurvature() const
00398 {
00399 return getInnerMostHitNode()->getCurvature();
00400 }
00401
00413 inline double StiKalmanTrack::getRapidity() const
00414 {
00415
00416
00417 double p[3];
00418 StiKalmanTrackNode * inner = getInnerMostHitNode();
00419 inner->getMomentum(p,0);
00420 double mass = getMass();
00421 if (mass<0)
00422 throw runtime_error("StiKalmanTrack::getRapidity() - particle mass unknown");
00423 double e = ::sqrt(mass*mass+p[0]*p[0]+p[1]*p[1]+p[2]*p[2]);
00424 if (e<=p[2])
00425 throw runtime_error("StiKalmanTrack::getRapidity() - Error: e<=pz");
00426 return 0.5*::log(e+p[2]/e-p[2]);
00427 }
00428
00438 inline double StiKalmanTrack::getPseudoRapidity() const
00439 {
00440
00441
00442 double tanTheta = tan(M_PI/4.- getInnerMostHitNode()->getDipAngle()/2. );
00443 if (tanTheta>0.)
00444 return -::log(tanTheta);
00445 else
00446 throw runtime_error("StiKalmanTrack::getPseudoRapidity() -E- Attempting ::log(non positive number)");
00447 }
00448
00454 inline double StiKalmanTrack::getPhi() const
00455 {
00456 double p[3];
00457 getInnerMostHitNode()->getGlobalMomentum(p,0);
00458 return atan2(p[1],p[0]);
00459 }
00460
00466 inline double StiKalmanTrack::getTanL() const
00467 {
00468 return getInnerMostHitNode()->getTanL();
00469 }
00470
00471 inline double StiKalmanTrack::getTpcDedx() const
00472 {
00473 return 0.;
00474 }
00475
00476 inline double StiKalmanTrack::getSvtDedx() const
00477 {
00478 return 0.;
00479 }
00487 inline double StiKalmanTrack::getDca() const
00488 {
00489 return _dca;
00490 }
00491
00492 inline void StiKalmanTrack::setDca(double dca)
00493 {
00494 _dca = dca;
00495 }
00496
00497
00505 inline double StiKalmanTrack::getDca(StiTrack *t) const
00506 {
00507 return 0;
00508 }
00509
00517 inline double StiKalmanTrack::getDca2(StiTrack *t) const
00518 {
00519 return 0;
00520 }
00521
00529 inline double StiKalmanTrack::getDca3(StiTrack *t) const
00530 {
00531 return 0;
00532 }
00533
00534
00539 inline StiKTNBidirectionalIterator StiKalmanTrack::begin() const
00540 {
00541 if (!firstNode)
00542 {
00543 cout << "StiKTNBidirectionalIterator StiKalmanTrack::begin() -F- firstNode==0"<<endl;
00544 throw runtime_error("StiKalmanTrack::begin() - ERROR - firstNode==0");
00545 }
00546 return StiKTNBidirectionalIterator::begin(firstNode);
00547 }
00548 inline StiKTNBidirectionalIterator StiKalmanTrack::rbegin() const
00549 {
00550 if (!lastNode)
00551 {
00552 cout << "StiKTNBidirectionalIterator StiKalmanTrack::rbegin() -F- lastNode==0"<<endl;
00553 throw runtime_error("StiKalmanTrack::rbegin() - ERROR - lastNode==0");
00554 }
00555 return StiKTNBidirectionalIterator::rbegin(lastNode);
00556 }
00557
00562 inline const StiKTNBidirectionalIterator &StiKalmanTrack::end() const
00563 {
00564 return StiKTNBidirectionalIterator::end();
00565 }
00566 inline const StiKTNBidirectionalIterator &StiKalmanTrack::rend() const
00567 {
00568 return StiKTNBidirectionalIterator::rend();
00569 }
00570
00587 inline StiKalmanTrackNode * StiKalmanTrack::getOuterMostNode(int qua) const
00588 {
00589 return getInnOutMostNode(1,qua);
00590 }
00591
00601 inline StiKalmanTrackNode * StiKalmanTrack::getInnerMostNode(int qua) const
00602 {
00603 return getInnOutMostNode(0,qua);
00604 }
00605
00606 #endif
00607