MarlinTrk  02.08
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MarlinAidaTTTrack.cc
Go to the documentation of this file.
2 
5 
6 
7 
8 #include "aidaTT/IBField.hh"
9 #include "aidaTT/ConstantSolenoidBField.hh"
10 #include "aidaTT/analyticalPropagation.hh"
11 #include "aidaTT/simplifiedPropagation.hh"
12 #include "aidaTT/GBLInterface.hh"
13 #include "aidaTT/fitResults.hh"
14 #include "aidaTT/Vector5.hh"
15 #include "aidaTT/utilities.hh"
16 #include "aidaTT/LCIOPersistency.hh"
17 #include "aidaTT/Vector3D.hh"
18 #include "aidaTT/DD4hepGeometry.hh"
19 #include "aidaTT/materialUtils.hh"
20 
21 #include "DD4hep/DD4hepUnits.h"
22 
23 #include <lcio.h>
24 #include <EVENT/TrackerHit.h>
25 #include <EVENT/TrackerHitPlane.h>
26 
27 #include <UTIL/BitField64.h>
28 #include <UTIL/Operators.h>
29 #include <UTIL/ILDConf.h>
30 #include "UTIL/LCTrackerConf.h"
31 
32 #include <sstream>
33 
34 #include "streamlog/streamlog.h"
35 
36 
37 using namespace UTIL ;
38 using namespace lcio ;
39 
40 namespace MarlinTrk {
41 
42  //---------------------------------------------------------------------------------------------------------------
43 
44  namespace{
45  std::string cellIDString( int detElementID) {
46  lcio::BitField64 bf( UTIL::LCTrackerCellID::encoding_string() ) ;
47  bf.setValue( detElementID ) ;
48  return bf.valueString() ;
49  }
50  }
51  //---------------------------------------------------------------------------------------------------------------
52 
53 
54  MarlinAidaTTTrack::MarlinAidaTTTrack( MarlinAidaTT* mAidaTT)
55  : _aidaTT( mAidaTT ) , _initialised( false ) , _mass( aidaTT::pionMass ) {
56 
57  }
58 
59 
61  delete _fitTrajectory ;
62  }
63 
64 
65  void MarlinAidaTTTrack::setMass(double mass) { _mass = mass ; }
66 
67  double MarlinAidaTTTrack::getMass() { return _mass ; }
68 
69 
71  _lcioHits.push_back( trkhit ) ;
72  return success ;
73  }
74 
75  int MarlinAidaTTTrack::initialise( bool /*fitDirection*/ ) {;
76 
77  if ( _initialised ) {
78  throw MarlinTrk::Exception("Track fit already initialised");
79  }
80  unsigned nHits = _lcioHits.size() ;
81  if( nHits < 3) {
82 
83  streamlog_out( ERROR) << "<<<<<< MarlinAidaTTTrack::initialise: Shortage of Hits! nhits = "
84  << _lcioHits.size() << " >>>>>>>" << std::endl;
85  return error ;
86  }
87 
88  //--------- get the start helix from three points
89  bool backwards = false ;
90 
91  lcio::TrackerHit* h1 = ( backwards ? _lcioHits[ nHits-1 ] : _lcioHits[ 0 ] ) ;
92  lcio::TrackerHit* h2 = _lcioHits[ (nHits+1) / 2 ] ;
93  lcio::TrackerHit* h3 = ( backwards ? _lcioHits[ 0 ] : _lcioHits[ nHits-1 ] ) ;
94 
95  const double* pos1 = h1->getPosition() ;
96  const double* pos2 = h2->getPosition() ;
97  const double* pos3 = h3->getPosition() ;
98 
99  aidaTT::Vector3D x1( pos1[0] * dd4hep::mm, pos1[1] * dd4hep::mm , pos1[2] * dd4hep::mm ) ;
100  aidaTT::Vector3D x2( pos2[0] * dd4hep::mm, pos2[1] * dd4hep::mm , pos2[2] * dd4hep::mm ) ;
101  aidaTT::Vector3D x3( pos3[0] * dd4hep::mm, pos3[1] * dd4hep::mm , pos3[2] * dd4hep::mm ) ;
102 
103 
104  aidaTT::trackParameters tp ;
105  calculateStartHelix( x1, x2, x3 , tp , backwards ) ;
106 
107  streamlog_out( DEBUG3 ) << " start helix from three points : " << tp << std::endl ;
108 
109 
110 #if 1 // create prefit from this helix
112 #else
113  _initialTrackParams = tp ;
114 #endif
115 
116  return myInit() ;
117  }
118 
119 
120  int MarlinAidaTTTrack::initialise( const EVENT::TrackState& ts, double, bool ) {
121 
122  if ( _initialised ) {
123  throw MarlinTrk::Exception("Track fit already initialised");
124  }
125 
126 #if 0 // debug code - initialize with hits and a prefit ....
127 
128  return initialise( dir ) ;
129 
130 #else
131  _initialTrackParams = aidaTT::readLCIO( &ts ) ;
132 
133  return myInit() ;
134 #endif
135 
136  }
137 
139 
140  moveHelixTo( _initialTrackParams, aidaTT::Vector3D() ) ; // move to origin
141 
142  // --- set some large errors to the covariance matrix ( might not be needed for GBL )
143  _initialTrackParams.covarianceMatrix().Unit() ;
144  _initialTrackParams.covarianceMatrix()( aidaTT::OMEGA, aidaTT::OMEGA ) = 1.e-2 ;
145  _initialTrackParams.covarianceMatrix()( aidaTT::TANL , aidaTT::TANL ) = 1.e2 ;
146  _initialTrackParams.covarianceMatrix()( aidaTT::PHI0 , aidaTT::PHI0 ) = 1.e2 ;
147  _initialTrackParams.covarianceMatrix()( aidaTT::D0 , aidaTT::D0 ) = 1.e5 ;
148  _initialTrackParams.covarianceMatrix()( aidaTT::Z0 , aidaTT::Z0 ) = 1.e5 ;
149 
150  _fitTrajectory = new aidaTT::trajectory( _initialTrackParams, _aidaTT->_fitter, //_aidaTT->_bfield,
152 
153  _fitTrajectory->setMass( _mass ) ;
154 
155  // add the Interaction Point as the first element of the trajectory
156  // int ID = 1;
157  // _fitTrajectory->addElement( aidaTT::Vector3D(), &ID);
158  //done internally in trajectory ...
159 
160  _initialised = true ;
161 
162  return success ;
163  }
164 
166 
167  streamlog_out( DEBUG ) << "MarlinAidaTTTrack::addAndFit: nothing to be done ... " << std::endl ;
168  return success ;
169  }
170 
172 
173  streamlog_out( DEBUG ) << "MarlinAidaTTTrack::testChi2Increment: nothing to be done ... " << std::endl ;
174  return success ;
175  }
176 
177  int MarlinAidaTTTrack::fit( double ) {
178 
179  streamlog_out(DEBUG2) << "MarlinAidaTTTrack::fit() called " << std::endl ;
180 
181  if ( ! _initialised ) {
182  throw MarlinTrk::Exception("Track fit not initialised");
183  }
184 
185  unsigned nHits = _lcioHits.size() ;
186  if( nHits < 3) {
187  streamlog_out( ERROR) << "<<<<<< MarlinAidaTTTrack::initialise: Shortage of Hits! nhits = "
188  << _lcioHits.size() << " >>>>>>>" << std::endl;
189  return error ;
190  }
191 
192  // ==== store hits in a map ===============
194  for(unsigned i=0 ; i < nHits ; ++i){
195  hitMap[ _lcioHits[i]->getCellID0() ] = _lcioHits[i] ;
196  }
197 
198  //==== compute _all_ surface intersections ======================
199  _intersections = &_fitTrajectory->getIntersectionsWithSurfaces( _aidaTT->_geom->getSurfaces() ) ;
200 
201 
202  //========= loop over all intersections =========
203  int pointLabel = 0 ;
204  for( std::vector<std::pair<double, const aidaTT::ISurface*> >::const_iterator it =
205  _intersections->begin() ; it != _intersections->end() ; ++it ){
206 
207  const aidaTT::ISurface* surf = it->second ;
208 
209  EVENT::TrackerHit* hit = hitMap[ surf->id() ] ;
210 
211  streamlog_out(DEBUG7) << "MarlinAidaTTTrack::fit() - intersection - current pointLabel : " << pointLabel
212  << ": at s = " << it->first << " surface id : "
213  << cellIDString( surf->id() ) << std::endl
214  << *surf << std::endl ;
215 
216  if( hit != 0 ){ //-------- we have to add a measurement
217 
218  double hitpos[3] ;
219  std::vector<double> precision ;
220  getHitInfo( hit, hitpos, precision , surf) ;
221 
222  if ( _fitTrajectory->addMeasurement( hitpos, precision, *surf, hit , _aidaTT->_useQMS ) )
223  _indexMap[ surf->id() ] = ++pointLabel ; // label 0 is for the IP point
224 
225  streamlog_out(DEBUG) << "MarlinAidaTTTrack::fit() addMeasurement called for pointLabel : " << pointLabel << std::endl ;
226 
227  } else { // we just add a scatterer
228 
229  if (_aidaTT->_useQMS ){
230 
231  // ignore virtual surface with no material (e.g. inside the beam pipe )
232 
233  if( ! ( surf->innerMaterial().density() < 1e-6 &&
234  surf->outerMaterial().density() < 1e-6 ) ) {
235 
236  _fitTrajectory->addScatterer( *surf ) ;
237  _indexMap[ surf->id() ] = ++pointLabel ; // label 0 is for the IP point
238 
239  streamlog_out(DEBUG) << "MarlinAidaTTTrack::fit() addScatterer called for pointLabel : " << pointLabel << std::endl ;
240  }
241  }
242  }
243  }
244 
245 
246  // do the fit:
247  _fitTrajectory->prepareForFitting();
248 
249  int fit_ok = _fitTrajectory->fit();
250 
251  streamlog_out( DEBUG4 ) << "MarlinAidaTTTrack::fit() - fit worked " << fit_ok
252  << std::endl ;
253 
254 
255 #if 0 // ---------------- try to run a refit --- does not work really ....
256  // refit one more time w/ new start parameters
257  const aidaTT::fitResults* result = _fitTrajectory->getFitResults();
258  const aidaTT::trackParameters& tp = result->estimatedParameters() ;
259 
260  streamlog_out( MESSAGE ) << " --- first fit result : " << tp << std::endl ;
261 
262  _fitTrajectory->setInitialTrackParameters( tp );
263  _fitTrajectory->prepareForFitting();
264  fit_ok = _fitTrajectory->fit();
265  streamlog_out( DEBUG4 ) << "MarlinAidaTTTrack::fit() - refit worked " << fit_ok << std::endl ;
266 
267  result = _fitTrajectory->getFitResults();
268  const aidaTT::trackParameters& tp1 = result->estimatedParameters() ;
269 
270  streamlog_out( MESSAGE ) << " --- second fit result : " << tp1 << std::endl ;
271 #endif
272 
273  return ( fit_ok ? success : error ) ;
274  }
275 
276 
277  aidaTT::trackParameters MarlinAidaTTTrack::createPreFit(aidaTT::trackParameters& tp ){
278 
279  // create a prefit from the hits w/o QMS and dEdx
280 
281  moveHelixTo( tp, aidaTT::Vector3D() ) ; // move to origin
282 
283  aidaTT::trajectory traj( tp , _aidaTT->_fitter, //_aidaTT->_bfield,
285 
286  traj.setMass( _mass ) ;
287 
288  // Add the Interaction Point as the first element of the trajectory
289  // int ID = 1;
290  // aidaTT::Vector3D IntPoint(0,0,0);
291  // traj.addElement(IntPoint, &ID);
292  // done internally in trajectory
293 
294  // try to use up to 25 or so hits....
295  unsigned nHits=_lcioHits.size() ;
296 
297  int step = ( nHits <= 25 ? 1 : int( 1.*nHits/25. ) ) ;
298 
299  streamlog_out( DEBUG1 ) << " MarlinAidaTTTrack::createPreFit() : will use every "
300  << step << "-th hit for prefit ! " << std::endl ;
301 
302  for(unsigned i=0 ; i < nHits ; i+= step ){
303 
304  EVENT::TrackerHit* hit = _lcioHits[i] ;
305 
306  long hitid = hit->getCellID0() ;
307 
308  SurfMap::iterator it = _aidaTT->_surfMap.find( hitid ) ;
309 
310  if( it == _aidaTT->_surfMap.end() ){
311 
312  streamlog_out( DEBUG1 ) << " MarlinAidaTTTrack::createPreFit() : no surface found for id : "
313  << cellIDString( hitid ) << std::endl ;
314  continue;
315  }
316 
317  const aidaTT::ISurface* surf = it->second ;
318 
319  double hitpos[3] ;
320  std::vector<double> precision ;
321  getHitInfo( hit, hitpos, precision , surf) ;
322 
323  streamlog_out( DEBUG1 ) << " MarlinAidaTTTrack::createPreFit() : adding hit for "
324  << cellIDString( hitid ) << " at "
325  << aidaTT::Vector3D( hit->getPosition() ) << std::endl ;
326 
327 
328 
329  traj.addMeasurement( hitpos, precision, *surf, hit );
330  }
331 
332  traj.prepareForFitting();
333 
334  int success = traj.fit();
335 
336 
337  if( success ) {
338 
339  const aidaTT::fitResults* result = traj.getFitResults();
340 
341  const aidaTT::trackParameters& newTP = result->estimatedParameters() ;
342 
343  streamlog_out( DEBUG4 ) << " MarlinAidaTTTrack::createPreFit() : prefit tp: "
344  << newTP << std::endl ;
345 
346 
347  return newTP ;
348 
349  } else {
350 
351  streamlog_out( WARNING ) << " MarlinAidaTTTrack::createPreFit() : prefit failed for tp: "
352  << tp << std::endl ;
353 
354  return tp ;
355  }
356 
357  }
358 
359 
360  void MarlinAidaTTTrack::getHitInfo( const EVENT::TrackerHit* hit, double* hitpos,
361  std::vector<double>& precision, const aidaTT::ISurface* surf){
362 
363  // get the hit position in dd4hep/aidaTT units
364  for(unsigned int i = 0; i < 3; ++i) hitpos[i] = hit->getPosition()[i] * dd4hep::mm;
365 
366  //---- compute the precision from the hit errors
367  double du,dv ;
368 
369  const TrackerHitPlane* planarhit = dynamic_cast<const TrackerHitPlane*>( hit );
370  if( planarhit != 0 ) {
371 
372  du = planarhit->getdU() * dd4hep::mm ;
373  dv = planarhit->getdV() * dd4hep::mm ;
374 
375  } else { // we have a TPC hit which is not yet using the CylinderTrackerHit ...
376 
377  const FloatVec& cov = hit->getCovMatrix();
378 
379  du = sqrt( cov[0] + cov[2] ) * dd4hep::mm ;
380  dv = sqrt( cov[5] ) * dd4hep::mm ;
381  }
382 
383  precision.push_back( 1./ (du*du) );
384 
385  if( ! surf->type().isMeasurement1D() )
386  precision.push_back( 1./ (dv*dv) );
387  else
388  precision.push_back( 0. );
389 
390  }
391 
392 
393 
394 
398 
399  streamlog_out( DEBUG2 ) << "MarlinAidaTTTrack::smooth() - nothing to do ...." << std::endl ;
400  return success ;
401  }
402 
403 
407 
408  streamlog_out( DEBUG2 ) << "MarlinAidaTTTrack::smooth() - nothing to do ...." << std::endl ;
409  return success ;
410  }
411 
412 
413  int MarlinAidaTTTrack::getTrackState( IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) {
414 
415  const aidaTT::fitResults& result = *_fitTrajectory->getFitResults();
416 
417  ts = *aidaTT::createLCIO( result.estimatedParameters() );
418 
419  ts.setLocation(lcio::TrackState::AtIP);
420 
421  chi2 = result.chiSquare() ;
422 
423  ndf = result.ndf() ;
424 
425  return success ;
426  }
427 
428 
429  int MarlinAidaTTTrack::getTrackState( EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) {
430 
432 
433  if( it == _indexMap.end() ) {
434 
435  streamlog_out( DEBUG2 ) << " MarlinAidaTTTrack::getTrackState(): "
436  << " no surface intersection for given hit "
437  << cellIDString( trkhit->getCellID0()) << std::endl ;
438  return error ;
439  }
440 
441  return getTrackState( aidaTT::Vector3D( trkhit->getPosition() ), it->second, ts, chi2, ndf ) ;
442  }
443 
444 
445  int MarlinAidaTTTrack::getTrackState( const aidaTT::Vector3D& refPoint, int label,
446  IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
447 
448  const aidaTT::fitResults* result = _fitTrajectory->getFitResults( label );
449 
450  if( result == 0 ) {
451 
452  streamlog_out( DEBUG2 ) << " MarlinAidaTTTrack::getTrackState(): "
453  << " no result at label " << label
454  << " close to " << refPoint << std::endl ;
455  return error ;
456  }
457 
458  // results are returned with origin as reference point
459  aidaTT::trackParameters resTS = result->estimatedParameters() ;
460 
461 
462  const double* pos = refPoint ;
463  aidaTT::Vector3D hitPos( pos[0] * dd4hep::mm, pos[1] * dd4hep::mm , pos[2] * dd4hep::mm ) ;
464  // hitPos = dd4hep::mm * hitPos ;
465 
466  streamlog_out( DEBUG2 ) << " MarlinAidaTTTrack::getTrackState(): "
467  << " moving helix to " << hitPos << std::endl ;
468 
469  bool calcCovMat = true ;
470  moveHelixTo( resTS , hitPos , calcCovMat ) ;
471 
472  ts = *aidaTT::createLCIO( resTS );
473 
474  chi2 = result->chiSquare() ;
475 
476  ndf = result->ndf() ;
477 
478  return success ;
479  }
480 
481 
483 
484  streamlog_out( DEBUG2 ) << "MarlinAidaTTTrack::getHitsInFit() - returning all hits used ..." << std::endl ;
485 
486  hits.reserve( _lcioHits.size() ) ;
487 
488  for(unsigned i=0,N=_lcioHits.size(); i<N ; ++i){
489 
490  hits.push_back( std::make_pair( _lcioHits[i] , 0. ) );
491  }
492 
493  return success ;
494  }
495 
497  streamlog_out( DEBUG2 ) << "MarlinAidaTTTrack::getOutliers() - nothing to do ..." << std::endl ;
498  return success ;
499  }
500 
501 
502  int MarlinAidaTTTrack::getNDF( int& ndf ){
503 
504  const aidaTT::fitResults& result = *_fitTrajectory->getFitResults();
505  ndf = result.ndf();
506  return success;
507  }
508 
509 
510 
512 
513  trkhit = _lcioHits[0] ; // is this correct ???
514  return success;
515  }
516 
517 
518  int MarlinAidaTTTrack::extrapolate( const Vector3D& point, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
519 
520  return propagate( point, ts, chi2, ndf ) ;
521  }
522 
523  int MarlinAidaTTTrack::extrapolate( const Vector3D& point, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) {
524 
525  return propagate( point, trkhit, ts, chi2, ndf ) ;
526  }
527 
528 
529  int MarlinAidaTTTrack::extrapolateToLayer( int layerID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
530 
531  return propagateToLayer( layerID, ts, chi2, ndf, detElementID, mode ) ;
532  }
533 
534 
535  int MarlinAidaTTTrack::extrapolateToLayer( int layerID, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
536 
537  return propagateToLayer( layerID, trkhit, ts, chi2, ndf, detElementID, mode ) ;
538  }
539 
540 
541 
542 
543  int MarlinAidaTTTrack::extrapolateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
544 
545  return propagateToDetElement( detElementID, ts, chi2, ndf, mode ) ;
546  }
547 
548 
549  int MarlinAidaTTTrack::extrapolateToDetElement( int detElementID, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
550 
551  return propagateToDetElement( detElementID, trkhit, ts, chi2, ndf, mode ) ;
552  }
553 
554 
555 
556  int MarlinAidaTTTrack::propagate( const Vector3D& point, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
557 
558  if( point[0] == 0.0 && point[1] == 0.0 && point[2] == 0.0 ) {
559 
560  return getTrackState( ts, chi2, ndf ) ;
561 
562 
563  }else{
564 
565  aidaTT::Vector3D thePoint( point[0]*dd4hep::mm,point[1]*dd4hep::mm, point[2]*dd4hep::mm ) ;
566 
567  //========= loop over all intersections and find the one closest to given point
568  // double minDist2 = 1.e99 ;
569  // unsigned index = 0, count = 0 ;
570  // for( std::vector<std::pair<double, const aidaTT::ISurface*> >::const_iterator it =
571  // _intersections->begin() ; it != _intersections->end() ; ++it ){
572 
573  // // get the (cached) intersection point
574 
575  // double s ; aidaTT::Vector2D uv ; aidaTT::Vector3D position ;
576  // _fitTrajectory->_calculateIntersectionWithSurface( it->second, s , &uv, &position );
577 
578  // aidaTT::Vector3D dv = position - thePoint ;
579  // double dist2 = dv.r2() ;
580 
581  // if( dist2 < minDist2 ){
582  // minDist2 = dist2 ;
583  // index = count ;
584  // }
585  // ++count ;
586  // }
587  // streamlog_out( DEBUG2 ) << "MarlinAidaTTTrack::propagate(): found closest intersection "
588  // << " to point " << point << " at surface "
589  // << *(*_intersections)[index].second << std::endl ;
590 
591  // const aidaTT::ISurface* s = _intersections->at(index).second ;
592  //int label = _indexMap[ s->id() ] ;
593 
594  const std::vector<aidaTT::trajectoryElement*>& elemVec = _fitTrajectory->trajectoryElements() ;
595  double minDist2 = 1.e99 ;
596  unsigned label = 0 ;
597  for( unsigned i=0,N=elemVec.size() ; i < N ; ++i ){
598  const aidaTT::Vector3D& rp = elemVec[i]->getTrackParameters()->referencePoint() ;
599  aidaTT::Vector3D dv = rp - thePoint ;
600  double dist2 = dv.r2() ;
601  if( dist2 < minDist2 ){
602  minDist2 = dist2 ;
603  label = i ;
604  }
605  }
606 
607  return getTrackState( aidaTT::Vector3D( point[0], point[1], point[2] ),
608  label, ts, chi2, ndf ) ;
609 
610  }
611  }
612 
613  int MarlinAidaTTTrack::propagate( const Vector3D& point, EVENT::TrackerHit*, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
614 
615  return this->propagate( point, ts, chi2, ndf ) ;
616  }
617 
618 
619 
620  int MarlinAidaTTTrack::propagateToLayer( int layerID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int ) {
621 
622  UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ;
623  encoder.reset() ; // reset to 0
624 
625 
626  // compute a mask for the layerid
627  int mask=0 ;
628  mask |= encoder[lcio::LCTrackerCellID::subdet()].mask() ;
629  mask |= encoder[lcio::LCTrackerCellID::side() ].mask() ;
630  mask |= encoder[lcio::LCTrackerCellID::layer() ].mask() ;
631 
632  // loop over intersections to find the (first) intersection w/ the given layerid
633  // double s ; aidaTT::Vector2D uv ; aidaTT::Vector3D position ;
634  // //========= loop over all intersections and find on that matches layerID
635  // int theID = -1 ;
636  // unsigned index = 0, count = 0 ;
637  // for( std::vector<std::pair<double, const aidaTT::ISurface*> >::const_iterator it =
638  // _intersections->begin() ; it != _intersections->end() ; ++it ){
639  // ++count ;
640 
641  // int id = it->second->id() ;
642 
643  // if( layerID == ( id & mask ) ){
644 
645  // index = count ;
646  // theID = id ;
647 
648  // _fitTrajectory->_calculateIntersectionWithSurface( it->second, s , &uv, &position );
649 
650  // break ;
651  // }
652  // }
653 
654  streamlog_out( DEBUG ) << "MarlinAidaTTTrack::propagate(): looking for cellID " << cellIDString( layerID ) << std::endl ;
655 
656  const std::vector<aidaTT::trajectoryElement*>& elemVec = _fitTrajectory->trajectoryElements() ;
657  unsigned label = 0 ;
658  int theID = -1 ;
659  unsigned index = 0 ;
660  // first element has not surface ...
661  for( unsigned i=1,N=elemVec.size() ; i < N ; ++i ){
662 
663  int id = elemVec[i]->surface().id() ;
664 
665 
666  streamlog_out( DEBUG ) << "MarlinAidaTTTrack::propagate(): comparing to cellID " << cellIDString( id ) << std::endl ;
667 
668  if( layerID == ( id & mask ) ){
669  theID = id ;
670  label = i ;
671  break ;
672  }
673  }
674 
675  if( theID == -1 ){
676  streamlog_out( ERROR ) << "MarlinAidaTTTrack::propagate(): no intersection "
677  << " found for layerID " << cellIDString( layerID )
678  << std::endl ;
679  return no_intersection ;
680  }
681 
682  detElementID = theID ;
683 
684  const aidaTT::Vector3D& position = elemVec[label]->getTrackParameters()->referencePoint() ;
685 
686  // need to convert intersection position back to mm ...
687  aidaTT::Vector3D point( position[0]/dd4hep::mm, position[1]/dd4hep::mm,position[2]/dd4hep::mm ) ;
688 
689  int res = getTrackState( point, index, ts, chi2, ndf ) ;
690 
691  return res ;
692  }
693 
694 
695 
697  double& chi2, int& ndf, int& detElementID, int ) {
698 
699  return propagateToLayer( layerID, ts, chi2, ndf, detElementID ) ;
700  }
701 
702 
703  int MarlinAidaTTTrack::propagateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int ) {
704 
705  std::map<int,int>::iterator it = _indexMap.find( detElementID ) ;
706 
707  if( it == _indexMap.end() ) {
708 
709  streamlog_out( DEBUG2 ) << " MarlinAidaTTTrack::propagateToDetElement(): "
710  << " no surface intersection for given DetElementID "
711  << cellIDString( detElementID ) << std::endl ;
712  return error ;
713  }
714 
715 
716  // const aidaTT::ISurface* surf = (*_intersections)[ it->second - 1 ].second ;
717  // // sanity check:
718  // if( surf->id() != detElementID ){
719  // std::stringstream s ; s << "MarlinAidaTTTrack::propagateToDetElement() - inconsistent ids: detElementID = "
720  // << cellIDString( detElementID ) << " and surf.id() " << surf->id() << std::endl ;
721  // throw MarlinTrk::Exception( s.str() );
722  // }
723  // double s ; aidaTT::Vector2D uv ; aidaTT::Vector3D position ;
724  // _fitTrajectory->_calculateIntersectionWithSurface( surf, s , &uv, &position );
725 
726  int label = it->second ;
727  const std::vector<aidaTT::trajectoryElement*>& elemVec = _fitTrajectory->trajectoryElements() ;
728  const aidaTT::Vector3D& position = elemVec[label]->getTrackParameters()->referencePoint() ;
729 
730  // need to convert intersection position back to mm ...
731  aidaTT::Vector3D point( position[0]/dd4hep::mm, position[1]/dd4hep::mm,position[2]/dd4hep::mm ) ;
732 
733  return getTrackState( point , it->second, ts, chi2, ndf ) ;
734  }
735 
736 
737  int MarlinAidaTTTrack::propagateToDetElement( int detElementID, EVENT::TrackerHit*, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int ) {
738 
739  return propagateToDetElement(detElementID, ts, chi2, ndf ) ;
740  }
741 
742 
743  int MarlinAidaTTTrack::intersectionWithDetElement( int detElementID, Vector3D& point, int) {
744 
745  // SurfMap::iterator it = _aidaTT->_surfMap.find( detElementID ) ;
746  // if( it == _aidaTT->_surfMap.end() ){
747  // streamlog_out( DEBUG2 ) << " MarlinAidaTTTrack::intersectionWithDetElement() - no surface found for " << cellIDString( detElementID ) << std::endl ;
748  // return error ;
749  // }
750  // const aidaTT::ISurface* surf = it->second ;
751  // double s ; aidaTT::Vector2D uv ; aidaTT::Vector3D position ;
752  // bool intersects = _fitTrajectory->_calculateIntersectionWithSurface( surf, s , &uv, &position );
753  // // need to convert intersection position back to mm ...
754  // if( intersects)
755  std::map<int,int>::iterator it = _indexMap.find( detElementID ) ;
756 
757  if( it == _indexMap.end() ) {
758 
759  streamlog_out( DEBUG2 ) << " MarlinAidaTTTrack::intersectionWithDetElement(): "
760  << " no surface intersection for given DetElementID "
761  << cellIDString( detElementID ) << std::endl ;
762  return error ;
763  }
764  int label = it->second ;
765  const std::vector<aidaTT::trajectoryElement*>& elemVec = _fitTrajectory->trajectoryElements() ;
766  const aidaTT::Vector3D& position = elemVec[label]->getTrackParameters()->referencePoint() ;
767 
768 
769  point = aidaTT::Vector3D( position[0]/dd4hep::mm, position[1]/dd4hep::mm,position[2]/dd4hep::mm ) ;
770 
771  return success ;
772  // return (intersects ? success : error ) ;
773  }
774 
775 
776  int MarlinAidaTTTrack::intersectionWithDetElement( int detElementID, EVENT::TrackerHit*, Vector3D& point, int mode ) {
777 
778  return intersectionWithDetElement( detElementID, point, mode ) ;
779  }
780 
781 
782  int MarlinAidaTTTrack::intersectionWithLayer( int layerID, Vector3D& point, int& detElementID, int mode ) {
783 
784  UTIL::BitField64 encoder( lcio::LCTrackerCellID::encoding_string() ) ;
785  encoder.reset() ; // reset to 0
786 
787  // compute a mask for the layerid
788  int mask=0 ;
789  mask |= encoder[lcio::LCTrackerCellID::subdet()].mask() ;
790  mask |= encoder[lcio::LCTrackerCellID::side() ].mask() ;
791  mask |= encoder[lcio::LCTrackerCellID::layer() ].mask() ;
792 
793  int theID = -1 ;
794  for( std::vector<std::pair<double, const aidaTT::ISurface*> >::const_iterator it =
795  _intersections->begin() ; it != _intersections->end() ; ++it ){
796 
797  int id = it->second->id() ;
798 
799  if( layerID == ( id & mask ) ){
800  theID = id ;
801  break ;
802  }
803  }
804 
805  if( theID == -1 ){
806  streamlog_out( ERROR ) << "MarlinAidaTTTrack::intersectionWithLayer(): no intersection "
807  << " found for layerID " << cellIDString( layerID )
808  << std::endl ;
809  return error ;
810  }
811 
812  detElementID = theID ;
813 
814  return intersectionWithDetElement( detElementID, point, mode ) ;
815  }
816 
817 
818  int MarlinAidaTTTrack::intersectionWithLayer( int layerID, EVENT::TrackerHit*, Vector3D& point, int& detElementID, int ) {
819 
820  return intersectionWithLayer( layerID, point, detElementID ) ;
821  }
822 
824 
825  return std::string(" AidaTTTrack - to String ... " ) ;
826  }
827 
828 
829 
830 
831 } // end of namespace MarlinTrk
int fit(double maxChi2Increment=DBL_MAX)
perform the fit of all current hits, returns error code ( IMarlinTrack::success if no error ) ...
int initialise(bool)
initialise the fit using the hits added up to this point - the fit direction has to be specified usin...
aidaTT::IPropagation * _propagation
Definition: MarlinAidaTT.h:115
int extrapolateToDetElement(int detElementID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int mode=modeClosest)
extrapolate the fit to sensitive detector element, returning TrackState, chi2 and ndf via reference ...
virtual const double * getPosition() const =0
int intersectionWithLayer(int layerID, Vector3D &point, int &detElementID, int mode=modeClosest)
extrapolate the fit to numbered sensitive layer, returning intersection point in global coordinates a...
int getTrackState(IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
get track state, returning TrackState, chi2 and ndf via reference
void getHitInfo(const EVENT::TrackerHit *hit, double *hitpos, std::vector< double > &precision, const aidaTT::ISurface *surf)
Interface to KaltTest Kalman fitter - instantiates and holds the detector geometry.
Definition: MarlinAidaTT.h:43
int propagateToLayer(int layerID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int &detElementID, int mode=modeClosest)
propagate the fit to the numbered sensitive layer, returning TrackState, chi2, ndf and integer ID of ...
std::string cellIDString(int detElementID)
T endl(T...args)
int myInit()
common initialization
double r2() const
aidaTT::IFittingAlgorithm * _fitter
Definition: MarlinAidaTT.h:114
T end(T...args)
bool _useQMS
take multiple scattering into account during the fit
Definition: MarlinAidaTT.h:105
int intersectionWithDetElement(int detElementID, Vector3D &point, int mode=modeClosest)
extrapolate the fit to numbered sensitive detector element, returning intersection point in global co...
std::string toString()
Dump this track to a string for debugging.
int extrapolate(const Vector3D &point, IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
extrapolate the fit to the point of closest approach to the given point, returning TrackState...
int testChi2Increment(EVENT::TrackerHit *, double &)
this method has no effect for aidaTT/GBL ...
dd4hep::rec::Vector3D Vector3D
the Vector3D used for the tracking interface
Definition: IMarlinTrack.h:26
aidaTT::trackParameters createPreFit(aidaTT::trackParameters &tp)
STL class.
virtual const FloatVec & getCovMatrix() const =0
const std::vector< std::pair< double, const aidaTT::ISurface * > > * _intersections
STL class.
virtual void setLocation(int location)
int getOutliers(std::vector< std::pair< EVENT::TrackerHit *, double > > &)
this method has no effect for aidaTT/GBL ...
std::map< int, int > _indexMap
T push_back(T...args)
vector< level > position
int getHitsInFit(std::vector< std::pair< EVENT::TrackerHit *, double > > &hits)
get the list of hits included in the fit, together with the chi2 contributions of the hits...
aidaTT::trajectory * _fitTrajectory
int propagateToDetElement(int detElementID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int mode=modeClosest)
propagate the fit to sensitive detector element, returning TrackState, chi2 and ndf via reference ...
int smooth()
this method has no effect for aidaTT/GBL ...
int addAndFit(EVENT::TrackerHit *, double &, double)
this method has no effect for aidaTT/GBL ...
T make_pair(T...args)
static const std::string & encoding_string()
int getTrackerHitAtPositiveNDF(EVENT::TrackerHit *&trkhit)
get TrackeHit at which fit became constrained, i.e.
const aidaTT::IGeometry * _geom
Definition: MarlinAidaTT.h:112
int extrapolateToLayer(int layerID, IMPL::TrackStateImpl &ts, double &chi2, int &ndf, int &detElementID, int mode=modeClosest)
extrapolate the fit to numbered sensitive layer, returning TrackState via provided reference ...
int propagate(const Vector3D &point, IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
propagate the fit to the point of closest approach to the given point, returning TrackState, chi2 and ndf via reference
virtual int getCellID0() const =0
SurfMap _surfMap
multi-map of surfaces
Definition: MarlinAidaTT.h:110
static const int success
Definition: IMarlinTrack.h:53
int getNDF(int &ndf)
get the current number of degrees of freedom for the fit.
static const int no_intersection
Definition: IMarlinTrack.h:56
T find(T...args)
T size(T...args)
STL class.
void setMass(double mass)
set the mass of the charged particle (GeV) that is used for energy loss and multiple scattering - def...
T begin(T...args)
std::vector< EVENT::TrackerHit * > _lcioHits
bool _initialised
used to store whether initial track state has been supplied or created
Exception thrown in IMarlinTrk namespace (implemetations of IMarlinTrkSystem and IMarlinTrack).
double getMass()
return the of the charged particle (GeV) that is used for energy loss and multiple scattering...
int addHit(EVENT::TrackerHit *hit)
add hit to track - the hits have to be added ordered in time ( i.e.
aidaTT::trackParameters _initialTrackParams
static const int error
Definition: IMarlinTrack.h:54