StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiKalmanTrackFitter.cxx
1 #include <stdexcept>
2 #include "StiKalmanTrackFitter.h"
3 #include "StiKalmanTrack.h"
4 #include "StiKTNIterator.h"
5 
6 
7 Int_t StiKalmanTrackFitter::_debug = 0;
8 
21 Int_t StiKalmanTrackFitter::fit(StiTrack * stiTrack, Int_t fitDirection)
22 {
23  enum {kMaxNErr=333};
24  static Int_t nCall=0; nCall++;
25 
26  if (debug() > 2) cout << "SKTFitter::fit() -I- Started:"<<endl;
27  StiKalmanTrack * track = dynamic_cast<StiKalmanTrack * >(stiTrack);
28  assert(track);
29  StiHit * targetHit;
30  StiKalmanTrackNode * targetNode; // parent node
31  const StiDetector * targetDet; // parent detector
32 
36  Double_t chi2;
37  Int_t status = 0,nerr =0;
38  if (!fitDirection) {
39  first = track->begin();
40  last = track->end();
41  } else {
42  last = track->rend();
43  first = track->rbegin();
44  }
45  if (debug()) cout << "StiKalmanTrackFitter::fit direction = " << fitDirection << endl;
46 // 1st count number of accepted already good nodes
47  Int_t nGoodNodes = track->getNNodes(3);
48  if (nGoodNodes<3) return kShortTrackBeforeFit;
49 
50 
51  StiKalmanTrackNode *pNode = 0;
52  Int_t iNode=0; status = 0;
53  for (source=first;source!=last;source++) {
54  if (nerr>kMaxNErr) return nerr;
55  do { //do refit block
56  iNode++;
57  targetNode = &(*source);
58  targetDet = targetNode->getDetector();
59  targetHit = targetNode->getHit();
60  Double_t oldChi2 = targetNode->getChi2(); if(oldChi2){/*debugonly*/};
61  static Int_t myKount=0;myKount++;
62  if (!pNode && !targetNode->isValid()) continue;
63  //begin refit at first hit
64  status = 0;
65  if (pNode) {
66  targetNode->setChi2(1e51);
67  if (targetDet)
68  status = targetNode->propagate(pNode,targetDet,fitDirection); // hit
69  else if (targetHit)
70  status = targetNode->propagate(pNode,targetHit,fitDirection); // vertex
71  if (status) {nerr++; continue;}
72  }
73  else {
74  if (debug()) {
75  targetNode->ResetComment(::Form("%30s start refit",targetDet->getName().c_str()));
76  targetNode->PrintpT("S");}
77 // pNode = targetNode; continue;
78  pNode = targetNode;
79  }
80 // target node has parameters now but not fitted
81 // if targetNode has hit, get chi2 and update track parameters accordingly
82  do {// Fit
83  targetNode->setChi2(0.);
84  if (!targetHit) break; //There is no hit.
85  assert(targetNode->getHit()==targetHit);
86  StiKalmanTrackNode tryNode = *targetNode;
87  targetNode->setChi2(1e52);
88  if (tryNode.nudge(targetHit)) {nerr++; break;}
89  chi2 = tryNode.evaluateChi2(targetHit);
90  if ((chi2>StiKalmanTrackFitterParameters::instance()->getMaxChi2())) {nerr++; break;} //Chi2 is bad
91  status = tryNode.updateNode();
92  if (status) {nerr++; break;}
93  tryNode.setChi2(chi2);
94  { //continue block
95  if (debug()) {cout << Form("%5d ",status); StiKalmanTrackNode::PrintStep();}
96  }//end continue block
97 
98  *targetNode=tryNode;
99  }while(0);//end fit block
100  pNode = targetNode;
101  } while(0);//end refit block
102  }//end for of nodes
103  nGoodNodes = track->getNNodes(3);
104  if (nGoodNodes<3) return kShortTrackAfterFit;
105  return (nerr>kMaxNErr)? kManyErrors:0;
106 }
107 
int propagate(StiKalmanTrackNode *p, const StiDetector *tDet, int dir)
Propagates a track encapsulated by the given node &quot;p&quot; to the given detector &quot;tDet&quot;.
Definition of Kalman Track.
Abstract definition of a Track.
Definition: StiTrack.h:59
Definition: StiHit.h:51
Definition of Kalman Track.
const StiKTNBidirectionalIterator & end() const
StiKTNBidirectionalIterator begin() const
virtual Int_t fit(StiTrack *track, Int_t direction)
const string & getName() const
Get the name of the object.
Definition: Named.cxx:22