StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiLocalTrackSeedFinder.cxx
Go to the documentation of this file.
1 #include <stdexcept>
4 #include <math.h>
5 #include "StThreeVectorF.hh"
6 #include "StThreeVectorD.hh"
7 #include "StThreeVector.hh"
8 #include "StiHit.h"
9 #include "StiHitContainer.h"
10 #include "StiKalmanTrack.h"
11 #include "StiDetector.h"
12 #include "StiPlacement.h"
13 #include "StiDetectorContainer.h"
14 #include "StiLocalTrackSeedFinder.h"
15 #include "StiSortedHitIterator.h"
16 #include "StiMasterDetectorBuilder.h"
17 
18 ostream& operator<<(ostream&, const StiDetector&);
19 
20 //______________________________________________________________________________
21 StiLocalTrackSeedFinder::StiLocalTrackSeedFinder(const string& name,
22  const string& description,
23  Factory<StiKalmanTrack> * trackFactory,
24  StiHitContainer * hitContainer,
25  StiDetectorContainer * detectorContainer)
26  : StiTrackFinder(),
27  _reset(true),
28  _trackFactory(trackFactory),
29  _hitContainer(hitContainer),
30  _detectorContainer(detectorContainer)
31 {
32  fRxyMin=0;
33 // cout <<"StiLocalTrackSeedFinder::StiLocalTrackSeedFinder() -I- Started/Done"<<endl;
34 }
35 
36 //______________________________________________________________________________
37 StiLocalTrackSeedFinder::~StiLocalTrackSeedFinder()
38 {
39 // cout <<"StiLocalTrackSeedFinder::~StiLocalTrackSeedFinder() -I- Started/Done"<<endl;
40 }
41 
42 //______________________________________________________________________________
47 //______________________________________________________________________________
49 {
50  fRxyMin = rMin;
51  StiKalmanTrack* track = 0;
52  if (isReset())
53  {
54 // cout << "StiLocalTrackSeedFinder::findTrack() -I- Getting iterator" << endl;
55 
56  _hitIter = StiSortedHitIterator(_hitContainer,_detectorContainer->begin(),_detectorContainer->end());
57  }
58  for (;_hitIter!=StiSortedHitIterator() && track==0;++_hitIter)
59  {
60  try
61  {
62  StiHit *hit = &(*_hitIter);
63  if (hit->timesUsed()) continue;
64  if (fRxyMin && pow(hit->x(),2)+pow(hit->y(),2)<fRxyMin*fRxyMin) continue;
65  track = makeTrack(&*_hitIter);
66  }
67  catch(runtime_error & rte )
68  {
69  // cout<< "StiLocalTrackSeedFinder::findTrack() -W- Run Time Error :" << rte.what() << endl;
70  }
71  }
72  //cout <<"StiLocalTrackSeedFinder::findTrack() -I- Done"<<endl;
73  fRxyMin = 0;
74  return track;
75 }
76 
77 //______________________________________________________________________________
82 {
83  //cout <<"StiLocalTrackSeedFinder::extendHit(StiHit& hit) -I- Started"<<endl;
84  _detectorContainer->setToDetector( hit.detector() );
85  //Done if the inner most detector is reached.
86  if ( _detectorContainer->moveIn()==false ) return false;
87  const StiDetector* d = _detectorContainer->getCurrentDetector(); //**_detectorContainer;
88  StiPlacement * p = d->getPlacement();
89  if (p->getLayerRadius() < fRxyMin) return false;
90  StiHit* closestHit = _hitContainer->getNearestHit(p->getLayerRadius(),
91  p->getLayerAngle(),
92  hit.y(), hit.z(),
93  StiLocalTrackSeedFinderParameters::instance()->deltaY(),
94  StiLocalTrackSeedFinderParameters::instance()->deltaZ());
95 
96  if (!closestHit ) return false;
97  _seedHits.push_back(closestHit);
98  return true;
99 }
100 
101 //______________________________________________________________________________
105 {
106  //cout <<"StiLocalTrackSeedFinder::makeTrack() -I- Started"<<endl;
107  StiKalmanTrack* track = 0;
108  _seedHits.clear();
109  _seedHits.push_back(hit);
110  //Recursively extend track:
111  bool go=true;
112  StiLocalTrackSeedFinderParameters *seedPars=StiLocalTrackSeedFinderParameters::instance();
113  int iSeedLength = seedPars->seedLength();
114  int iExtrapMaxLength = seedPars->extrapMaxLength();
115  int iExtrapMinLength = seedPars->extrapMinLength();
116  int iMaxSkipped = seedPars->maxSkipped();
117 
118  while ( go && (int)_seedHits.size()<iSeedLength)
119  {
120  go = extendHit( *_seedHits.back() );
121  }
122  //Extension failed if current track length less than seedPars->seedLength()
123  //Return 0.
124  if ( (int)_seedHits.size()<iSeedLength )
125  {
126  return track;
127  }
128  //now use straight line propogation to recursively extend
129  _skipped = 0;
130  go=true;
131  while ( go && _skipped<=iMaxSkipped &&
132  (int)_seedHits.size()<=( iSeedLength+iExtrapMaxLength))
133  {
134  go = extrapolate();
135  }
136  //Extension failed if current track length less than seedPars->seedLength()+
137  //seedPars->extrapMinLength()
138  //Return 0.
139  if ( (int)_seedHits.size()<( iSeedLength+iExtrapMinLength) )
140  {
141  //seedPars->extrapMinLength()"<<endl;
142  return track;
143  }
144  track = initializeTrack(_trackFactory->getInstance());
145  return track;
146 }
147 
148 //______________________________________________________________________________
149 /* We define the following picture
150  r
151  ^
152  |
153  |
154  ----> y or z, depending on projection
155 
156  -------------- x -------------- pt3
157 
158 
159  ------------------- x --------- pt2
160  \
161  \
162  ---------------------- x ------ pt1
163 
164  We try to extrapolate the segment (pt1->pt2) to predict pt3. We
165  do this in two projections (r,y) and (r,z) where y is the distance
166  along pad, z is the global z, and r is the inward pointing sector
167  normal (i.e., StiPlacement->getNormalRadius() )
168 
169  In the r,y plane, e.g., we define r = m*y + b s.t.
170  m = (r2-r1) / (y2-y1)
171  b = r2 - m2
172  then
173  y3 = (r3 - b) / m, which is our prediction, since we know r3
174 
175 */
176 //______________________________________________________________________________
178 {
179  //This is a little ugly, but it's faster than manipulating 3-vectors
180  //cout <<"StiLocalTrackSeedFinder::extrapolate()"<<endl;
181  //Calculate slope and offset in r-z and r-y projections, then extend
182  const StiHit* hit1 = *( _seedHits.begin()+_seedHits.size() -2 ); //second to last
183  const StiHit* hit2 = _seedHits.back();
184 
185  //Get the next detector plane:
186 
187  double r1 = hit1->x();
188  double y1 = hit1->y();
189  double z1 = hit1->z();
190  double r2 = hit2->x();
191  double y2 = hit2->y();
192  double z2 = hit2->z();
193 
194  double dr = r2-r1;
195  double dy = y2-y1;
196  double dz = z2-z1;
197  if (fabs(dr) <=1.e-3) return false;
198  assert (fabs(dr) >1.e-3);
199  //Now look for a hit in the next layer in:
200  _detectorContainer->setToDetector( hit2->detector());
201  //Test to see if move in worked
202  for (int i=0; i<=_skipped; ++i)
203  {
204  if ( _detectorContainer->moveIn()==false)
205  {
206  //cout<<"StiLocalTrackSeedFinder::extrapolate() -W- Nowhere to move in to. Seed done"<<endl;
207  return false;
208  }
209  }
210 
211  const StiDetector* newLayer = **_detectorContainer;
212  double r3 = newLayer->getPlacement()->getNormalRadius();
213 
214  //Temp hack by Mike
215 //VP if (r3<=60.) { return false; }
216  if (r3<=25.) { return false; } //VP avoid SVT from seed
217 
218  //First, r-y plane
219  //double m_ry = dr/dy;
220  //double b_ry = hit2->x() - m_ry * hit2->y();
221  //double y3 = (r3 - b_ry) / m_ry;
222  double y3 = y1 + dy/dr*(r3-r1);
223 
224  //Now calculate the projection of window onto that plane:
225  double beta_ry = atan2(dr, dy);
226  double rho_ry = ::sqrt(dr*dr + dy*dy);
227  double alpha_ry = atan2(StiLocalTrackSeedFinderParameters::instance()->extrapDeltaY(), 2.*rho_ry);
228  double tanplus_ry = tan(beta_ry+alpha_ry);
229  double tanminus_ry = tan(beta_ry-alpha_ry);
230  if (tanplus_ry==0. || tanminus_ry==0.)
231  cout<<"StiLocalTrackSeedFidner::extrapolate(). -W- tanplus_ry==0. || tanminus_ry==0."<<endl;
232 
233  double y3_minus = (r3-r1)/tanplus_ry + y1;
234  double y3_plus = (r3-r1)/tanminus_ry + y1;
235  //Next, r-z plane
236  double z3 = z1 + dz/dr*(r3-r1);
237 
238  double beta_rz = atan2(dr, dz);
239  double rho_rz = ::sqrt(dr*dr + dz*dz);
240  double alpha_rz = atan2(StiLocalTrackSeedFinderParameters::instance()->extrapDeltaZ(), 2.*rho_rz);
241  double tanplus_rz = tan(beta_rz+alpha_rz);
242  double tanminus_rz = tan(beta_rz-alpha_rz);
243  if (tanplus_rz==0. || tanminus_rz==0.)
244  cout<<"StiLocalTrackSeedFidner::extrapolate(). -W- tanplus_rz==0. || tanminus_rz==0."<<endl;
245  double z3_minus = (r3-r1)/tanplus_rz + z1;
246  double z3_plus = (r3-r1)/tanminus_rz + z1;
247  /*
248  cout<<"beta_ry: "<<beta_ry<<" alpha_ry: "<<alpha_ry
249  <<" y3+: "<<y3_plus<<" y3: "<<y3<<" y3-: "<<y3_minus<<endl
250  <<"beta_rz: "<<beta_rz<<" alpha_rz: "<<alpha_rz
251  <<" z3+: "<<z3_plus<<" z3: "<<z3<<" z3-: "<<z3_minus<<endl
252  <<"query hit container for extension hits"<<endl;
253  */
254  StiPlacement * p = newLayer->getPlacement();
255  StiHit* closestHit = _hitContainer->getNearestHit(p->getLayerRadius(),
256  p->getLayerAngle(),
257  y3,z3,
258  fabs(y3_plus-y3_minus) /2.,
259  fabs(z3_plus-z3_minus) /2.);
260  if ( !closestHit )
261  {
262  //cout<<"StiLocalTrackSeedFinder::extrapolate() -W- No hits found in next layer."<<endl;
263  ++_skipped;
264  return true;
265  }
266  _skipped=0;
267  _seedHits.push_back(closestHit);
268  return true;
269 }
270 
271 
272 //______________________________________________________________________________
276 {
277  bool status = fit(track);
278  if (!status) track = 0;
279  return track;
280 }
281 
282 //______________________________________________________________________________
283 bool StiLocalTrackSeedFinder::fit(StiKalmanTrack* track)
284 {
285  int ierr = track->initialize(_seedHits);
286  return (ierr==0);
287 }
288 
289 //______________________________________________________________________________
290 void StiLocalTrackSeedFinder::print() const
291 {
292  cout <<"StiLocalTrackSeedFinder::print() -I- ";
293  for (vector<StiDetector*>::const_iterator it=_detectorContainer->begin();
294  it!=_detectorContainer->end();
295  ++it)
296  {
297  cout << **it <<endl;
298  }
299  cout <<"\n Search Window in Y:\t"<<StiLocalTrackSeedFinderParameters::instance()->deltaY()<<endl;
300  cout <<"\n Search Window in Z:\t"<<StiLocalTrackSeedFinderParameters::instance()->deltaZ()<<endl;
301 }
302 
303 //______________________________________________________________________________
304 ostream& operator<<(ostream& os, const StiLocalTrackSeedFinder & f)
305 {
306  return os << " StiLocalTrackSeedFinder " << endl;
307 }
Definition of Kalman Track.
Abstract definition of a Track.
Definition: StiTrack.h:59
bool moveIn(double phiCut=-1.0, double zCut=-1.0, double rMin=-1.0)
Step in radially in STAR TPC global coordinates.
StiKalmanTrack * initializeTrack(StiKalmanTrack *)
Definition: StiHit.h:51
StiKalmanTrack * makeTrack(StiHit *hit)
void setToDetector(const StiDetector *layer)
Set iterators to the detector nearest to the passed StiDetector pointer.
const Float_t & x() const
Return the local x, y, z values.
Definition: StiHit.h:67
const StiDetector * detector() const
Definition: StiHit.h:96
virtual Abstract * getInstance()=0
Get a pointer to instance of objects served by this factory.
Definition of Kalman Track.
virtual int initialize(const vector< StiHit * > &)
Convenience method to initialize a track based on seed information.
StiTrack * findTrack(double rMin=0)
bool extendHit(StiHit &hit)
Extend hit looking for closest neighbor in z.
UInt_t timesUsed() const
Return the number of times this hit was assigned to a track.
Definition: StiHit.h:108
An abstract class defining the interface to the track finder.
bool extrapolate()
Extrapolate to next layer using straight line, add hit closest in z.