MarlinTrk  02.08
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MarlinDDKalTestTrack.cc
Go to the documentation of this file.
2 
5 
6 #include <kaltest/TKalDetCradle.h>
7 #include <kaltest/TKalTrack.h>
8 #include <kaltest/TKalTrackState.h>
9 #include "kaltest/TKalTrackSite.h"
10 #include "TKalFilterCond.h"
11 
12 #include <lcio.h>
13 #include <EVENT/TrackerHit.h>
14 #include <EVENT/TrackerHitPlane.h>
15 
16 #include <UTIL/BitField64.h>
17 #include <UTIL/Operators.h>
18 #include "UTIL/LCTrackerConf.h"
19 
20 #include "DDKalTest/DDCylinderMeasLayer.h" // needed for dedicated IP Layer
21 #include "DDKalTest/DDCylinderHit.h"
22 #include "DDKalTest/DDPlanarHit.h"
23 //#include "DDKalTest/DDPlanarStripHit.h"
24 
25 #include <sstream>
26 
27 #include "streamlog/streamlog.h"
28 
29 
33 
34 public:
35 
38  KalTrackFilter(double maxDeltaChi2 = DBL_MAX) : _maxDeltaChi2( maxDeltaChi2 ), _passed_last_filter_step(true) {
39  }
40  virtual ~KalTrackFilter() {}
41 
42  virtual Bool_t IsAccepted(const TKalTrackSite &site) {
43 
44  double deltaChi2 = site.GetDeltaChi2();
45 
46  streamlog_out( DEBUG1 ) << " KalTrackFilter::IsAccepted called ! deltaChi2 = " << std::scientific << deltaChi2 << " _maxDeltaChi2 = " << _maxDeltaChi2 << std::endl;
47 
49 
50  return ( _passed_last_filter_step ) ;
51  }
52 
55 
56 protected:
57 
58  double _maxDeltaChi2 ;
60 
61 } ;
62 
63 namespace MarlinTrk {
64 
65  //---------------------------------------------------------------------------------------------------------------
66 
67  std::string cellIDString( int detElementID ) {
68  lcio::BitField64 bf( UTIL::LCTrackerCellID::encoding_string() ) ;
69  bf.setValue( detElementID ) ;
70  return bf.valueString() ;
71  }
72 
73  //---------------------------------------------------------------------------------------------------------------
74 
75 
77  : _ktest(ktest) {
78 
79  _kaltrack = new TKalTrack() ;
80  _kaltrack->SetOwner() ;
81 
82  _kalhits = new TObjArray() ;
83  _kalhits->SetOwner() ;
84 
85  _initialised = false ;
86  _fitDirection = false ;
87  _smoothed = false ;
88 
91 
92 #ifdef MARLINTRK_DIAGNOSTICS_ON
93  _ktest->_diagnostics.new_track(this) ;
94 #endif
95 
96 
97  }
98 
99 
101 
102 #ifdef MARLINTRK_DIAGNOSTICS_ON
103  _ktest->_diagnostics.end_track() ;
104 #endif
105 
106  delete _kaltrack ;
107  delete _kalhits ;
108  }
109 
110  void MarlinDDKalTestTrack::setMass(double mass) { _kaltrack->SetMass( mass ) ; }
111 
112  double MarlinDDKalTestTrack::getMass() { return _kaltrack->GetMass() ; }
113 
114 
116 
117  return this->addHit( trkhit, _ktest->findMeasLayer( trkhit )) ;
118 
119  }
120 
121  int MarlinDDKalTestTrack::addHit( EVENT::TrackerHit * trkhit, const DDVMeasLayer* ml) {
122 
123  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::addHit: trkhit = " << trkhit->id() << " addr: " << trkhit << " ml = " << ml << std::endl ;
124 
125  if( trkhit && ml ) {
126  return this->addHit( trkhit, ml->ConvertLCIOTrkHit(trkhit), ml) ;
127  }
128  else {
129  streamlog_out( ERROR ) << " MarlinDDKalTestTrack::addHit - bad inputs " << trkhit << " ml : " << ml << std::endl ;
130  return bad_intputs ;
131  }
132 
133  }
134 
135  int MarlinDDKalTestTrack::addHit( EVENT::TrackerHit* trkhit, DDVTrackHit* kalhit, const DDVMeasLayer* ml) {
136 
137  if( kalhit && ml ) {
138  _kalhits->Add(kalhit ) ; // Add hit and set surface found
139  _lcio_hits_to_kaltest_hits[trkhit] = kalhit ; // add hit to map relating lcio and kaltest hits
140  // _kaltest_hits_to_lcio_hits[kalhit] = trkhit ; // add hit to map relating kaltest and lcio hits
141  }
142  else {
143  delete kalhit;
144  return bad_intputs ;
145  }
146 
147  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::addHit: hit added "
148  << "number of hits for track = " << _kalhits->GetEntries()
149  << std::endl ;
150 
151  return success ;
152 
153  }
154 
155 
156  int MarlinDDKalTestTrack::initialise( bool fitDirection ) {;
157 
158 
159  //SJA:FIXME: check here if the track is already initialised, and for now don't allow it to be re-initialised
160  // if the track is going to be re-initialised then we would need to do it directly on the first site
161  if ( _initialised ) {
162 
163  throw MarlinTrk::Exception("Track fit already initialised");
164 
165  }
166 
167  if (_kalhits->GetEntries() < 3) {
168 
169  streamlog_out( ERROR) << "<<<<<< MarlinDDKalTestTrack::initialise: Shortage of Hits! nhits = "
170  << _kalhits->GetEntries() << " >>>>>>>" << std::endl;
171  return error ;
172 
173  }
174 
175  _fitDirection = fitDirection ;
176 
177  // establish the hit order
178  Int_t i1, i2, i3; // (i1,i2,i3) = (1st,mid,last) hit to filter
179  if (_fitDirection == kIterBackward) {
180  i3 = 0 ; // fg: first index is 0 and not 1
181  i1 = _kalhits->GetEntries() - 1;
182  i2 = i1 / 2;
183  } else {
184  i1 = 0 ;
185  i3 = _kalhits->GetEntries() - 1;
186  i2 = i3 / 2;
187  }
188 
189 
190 
191  TVTrackHit *startingHit = dynamic_cast<TVTrackHit *>(_kalhits->At(i1));
192 
193  // ---------------------------
194  // Create an initial start site for the track using the first hit
195  // ---------------------------
196  // set up a dummy hit needed to create initial site
197 
198  TVTrackHit* pDummyHit = 0;
199 
200  if ( (pDummyHit = dynamic_cast<DDCylinderHit *>( startingHit )) ) {
201  pDummyHit = (new DDCylinderHit(*static_cast<DDCylinderHit*>( startingHit )));
202  }
203  else if ( (pDummyHit = dynamic_cast<DDPlanarHit *>( startingHit )) ) {
204  pDummyHit = (new DDPlanarHit(*static_cast<DDPlanarHit*>( startingHit )));
205  }
206  // else if ( DDPlanarStripHit_DIM == 2 && (pDummyHit = dynamic_cast<DDPlanarStripHit *>( startingHit )) ) {
207  // pDummyHit = (new DDPlanarStripHit(*static_cast<DDPlanarStripHit*>( startingHit )));
208  // }
209  else {
210  streamlog_out( ERROR) << "<<<<<<<<< MarlinDDKalTestTrack::initialise: dynamic_cast failed for hit type >>>>>>>" << std::endl;
211  return error ;
212  }
213 
214  TVTrackHit& dummyHit = *pDummyHit;
215 
216  //SJA:FIXME: this constants should go in a header file
217  // give the dummy hit huge errors so that it does not contribute to the fit
218  dummyHit(0,1) = 1.e16; // give a huge error to d
219  dummyHit(1,1) = 1.e16; // give a huge error to z
220 
221  // use dummy hit to create initial site
222  TKalTrackSite& initialSite = *new TKalTrackSite(dummyHit);
223 
224  initialSite.SetHitOwner();// site owns hit
225  initialSite.SetOwner(); // site owns states
226 
227  // ---------------------------
228  // Create initial helix
229  // ---------------------------
230 
231  TVTrackHit &h1 = *dynamic_cast<TVTrackHit *>(_kalhits->At(i1)); // first hit
232  TVTrackHit &h2 = *dynamic_cast<TVTrackHit *>(_kalhits->At(i2)); // middle hit
233  TVTrackHit &h3 = *dynamic_cast<TVTrackHit *>(_kalhits->At(i3)); // last hit
234  TVector3 x1 = h1.GetMeasLayer().HitToXv(h1);
235  TVector3 x2 = h2.GetMeasLayer().HitToXv(h2);
236  TVector3 x3 = h3.GetMeasLayer().HitToXv(h3);
237 
238  if ( h1.GetDimension() == 1 || h2.GetDimension() == 1 || h3.GetDimension() == 1 ) {
239 
240  throw MarlinTrk::Exception("Track fit cannot be initialised from 1 Dimensional hits. Use method MarlinDDKalTestTrack::initialise( bool fitDirection )");
241 
242  }
243 
244 
245  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::initialise Create initial helix from hits: \n "
246  << "P1 x = " << x1.x() << " y = " << x1.y() << " z = " << x1.z() << " r = " << x1.Perp() << "\n "
247  << "P2 x = " << x2.x() << " y = " << x2.y() << " z = " << x2.z() << " r = " << x2.Perp() << "\n "
248  << "P3 x = " << x3.x() << " y = " << x3.y() << " z = " << x3.z() << " r = " << x3.Perp() << "\n "
249  << "Bz = " << h1.GetBfield() << " direction = " << _fitDirection
250  << std::endl;
251 
252  // create helix using 3 global space points
253  THelicalTrack helstart(x1, x2, x3, h1.GetBfield(), _fitDirection); // initial helix
254 
255  // ---------------------------
256  // Set up initial track state ... could try to use lcio track parameters ...
257  // ---------------------------
258 
259  static TKalMatrix initialState(kSdim,1) ;
260  initialState(0,0) = 0.0 ; // dr
261  initialState(1,0) = helstart.GetPhi0() ; // phi0
262  initialState(2,0) = helstart.GetKappa() ; // kappa
263  initialState(3,0) = 0.0 ; // dz
264  initialState(4,0) = helstart.GetTanLambda() ; // tan(lambda)
265  if (kSdim == 6) initialState(5,0) = 0.; // t0
266 
267 
268  // ---------------------------
269  // Set up initial Covariance Matrix with very large errors
270  // ---------------------------
271 
272  TKalMatrix Cov(kSdim,kSdim);
273 
274  // make sure everything is initialised to zero
275  for (int i=0; i<kSdim*kSdim; ++i) {
276  Cov.GetMatrixArray()[i] = 0.0;
277  }
278 
279 // for (Int_t i=0; i<kSdim; i++) {
280 // // fg: if the error is too large the initial helix parameters might be changed extremely by the first three (or so) hits,
281 // // such that the fit will not work because the helix curls away and does not hit the next layer !!!
282 // Cov(i,i) = 1.e2 ; // initialise diagonal elements of dummy error matrix
283 // }
284 
285  // prefer translation over rotation of the trackstate early in the fit
286 
287  Cov(0,0) = 1.e6 ; // d0
288  Cov(1,1) = 1.e2 ; // dphi0
289  Cov(2,2) = 1.e1 ; // dkappa
290  Cov(3,3) = 1.e6 ; // dz
291  Cov(4,4) = 1.e1 ; // dtanL
292  if (kSdim == 6) Cov(5,5) = 1.e2; // t0
293 
294  // Add initial states to the site
295  initialSite.Add(new TKalTrackState(initialState,Cov,initialSite,TVKalSite::kPredicted));
296  initialSite.Add(new TKalTrackState(initialState,Cov,initialSite,TVKalSite::kFiltered));
297 
298  // add the initial site to the track: that is, give the track initial parameters and covariance
299  // matrix at the starting measurement layer
300  _kaltrack->Add(&initialSite);
301 
302  _initialised = true ;
303 
304  streamlog_out( DEBUG2 ) << " track parameters used for init : " << std::scientific << std::setprecision(6)
305  << "\t D0 " << 0.0
306  << "\t Phi :" << toBaseRange( helstart.GetPhi0() + M_PI/2. )
307  << "\t Omega " << 1. /helstart.GetRho()
308  << "\t Z0 " << 0.0
309  << "\t tan(Lambda) " << helstart.GetTanLambda()
310 
311  << "\t pivot : [" << helstart.GetPivot().X() << ", " << helstart.GetPivot().Y() << ", " << helstart.GetPivot().Z()
312  << " - r: " << std::sqrt( helstart.GetPivot().X()*helstart.GetPivot().X()+helstart.GetPivot().Y()*helstart.GetPivot().Y() ) << "]"
313  << std::endl ;
314 
315 #ifdef MARLINTRK_DIAGNOSTICS_ON
316 
317  // convert to LICO parameters first
318 
319  double d0 = 0.0 ;
320  double phi = toBaseRange( helstart.GetPhi0() + M_PI/2. );
321  double omega = 1. /helstart.GetRho() ;
322  double z0 = 0.0 ;
323  double tanLambda = helstart.GetTanLambda() ;
324 
325 // Cov.Print();
326 
327  _ktest->_diagnostics.set_intial_track_parameters(d0,
328  phi,
329  omega,
330  z0,
331  tanLambda,
332  helstart.GetPivot().X(),
333  helstart.GetPivot().Y(),
334  helstart.GetPivot().Z(),
335  Cov);
336 
337 
338 
339 #endif
340 
341 
342  return success ;
343 
344  }
345 
346  int MarlinDDKalTestTrack::initialise( const EVENT::TrackState& ts, double /*bfield_z*/, bool fitDirection ) {
347 
348  // the bfield_z is not taken from the argument but from the first hit
349  // should consider changing the interface ...
350 
351  if (_kalhits->GetEntries() == 0) {
352 
353  streamlog_out( ERROR) << "<<<<<< MarlinDDKalTestTrack::Initialise: Number of Hits is Zero. Cannot Initialise >>>>>>>" << std::endl;
354  return error ;
355 
356  }
357 
358  //SJA:FIXME: check here if the track is already initialised, and for now don't allow it to be re-initialised
359  // if the track is going to be re-initialised then we would need to do it directly on the first site
360  if ( _initialised ) {
361 
362  throw MarlinTrk::Exception("Track fit already initialised");
363 
364  }
365 
366  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::initialise using TrackState: track parameters used for init : "
367  << "\t D0 " << ts.getD0()
368  << "\t Phi :" << ts.getPhi()
369  << "\t Omega " << ts.getOmega()
370  << "\t Z0 " << ts.getZ0()
371  << "\t tan(Lambda) " << ts.getTanLambda()
372 
373  << "\t pivot : [" << ts.getReferencePoint()[0] << ", " << ts.getReferencePoint()[1] << ", " << ts.getReferencePoint()[2]
374  << " - r: " << std::sqrt( ts.getReferencePoint()[0]*ts.getReferencePoint()[0]+ts.getReferencePoint()[1]*ts.getReferencePoint()[1] ) << "]"
375  << std::endl ;
376 
377 
378  _fitDirection = fitDirection ;
379 
380  // get Bz from first hit
381  TVTrackHit &h1 = *dynamic_cast<TVTrackHit *>(_kalhits->At(0));
382  double Bz = h1.GetBfield() ;
383 
384  // for GeV, Tesla, R in mm
385  double alpha = Bz * 2.99792458E-4 ;
386 
387  double kappa = ( Bz == 0.0 ? DBL_MAX : ts.getOmega() / alpha ) ;
388 
389  THelicalTrack helix( -ts.getD0(),
390  toBaseRange( ts.getPhi() - M_PI/2. ) ,
391  kappa,
392  ts.getZ0(),
393  ts.getTanLambda(),
394  ts.getReferencePoint()[0],
395  ts.getReferencePoint()[1],
396  ts.getReferencePoint()[2],
397  Bz );
398 
399  TMatrixD cov(5,5) ;
400 
401  EVENT::FloatVec covLCIO = ts.getCovMatrix();
402 
403  cov( 0 , 0 ) = covLCIO[ 0] ; // d0, d0
404  cov( 0 , 1 ) = - covLCIO[ 1] ; // d0, phi
405  cov( 0 , 2 ) = - covLCIO[ 3] / alpha ; // d0, kappa
406  cov( 0 , 3 ) = - covLCIO[ 6] ; // d0, z0
407  cov( 0 , 4 ) = - covLCIO[10] ; // d0, tanl
408 
409  cov( 1 , 0 ) = - covLCIO[ 1] ; // phi, d0
410  cov( 1 , 1 ) = covLCIO[ 2] ; // phi, phi
411  cov( 1 , 2 ) = covLCIO[ 4] / alpha ; // phi, kappa
412  cov( 1 , 3 ) = covLCIO[ 7] ; // phi, z0
413  cov( 1 , 4 ) = covLCIO[11] ; // tanl, phi
414 
415  cov( 2 , 0 ) = - covLCIO[ 3] / alpha ; // kappa, d0
416  cov( 2 , 1 ) = covLCIO[ 4] / alpha ; // kappa, phi
417  cov( 2 , 2 ) = covLCIO[ 5] / (alpha * alpha) ; // kappa, kappa
418  cov( 2 , 3 ) = covLCIO[ 8] / alpha ; // kappa, z0
419  cov( 2 , 4 ) = covLCIO[12] / alpha ; // kappa, tanl
420 
421  cov( 3 , 0 ) = - covLCIO[ 6] ; // z0, d0
422  cov( 3 , 1 ) = covLCIO[ 7] ; // z0, phi
423  cov( 3 , 2 ) = covLCIO[ 8] / alpha ; // z0, kappa
424  cov( 3 , 3 ) = covLCIO[ 9] ; // z0, z0
425  cov( 3 , 4 ) = covLCIO[13] ; // z0, tanl
426 
427  cov( 4 , 0 ) = - covLCIO[10] ; // tanl, d0
428  cov( 4 , 1 ) = covLCIO[11] ; // tanl, phi
429  cov( 4 , 2 ) = covLCIO[12] / alpha ; // tanl, kappa
430  cov( 4 , 3 ) = covLCIO[13] ; // tanl, z0
431  cov( 4 , 4 ) = covLCIO[14] ; // tanl, tanl
432 
433 // cov.Print();
434 
435  // move the helix to either the position of the last hit or the first depending on initalise_at_end
436 
437  // default case initalise_at_end
438  int index = _kalhits->GetEntries() - 1 ;
439  // or initialise at start
440  if( _fitDirection == IMarlinTrack::forward ){
441  index = 0 ;
442  }
443 
444  TVTrackHit* kalhit = dynamic_cast<TVTrackHit *>(_kalhits->At(index));
445 
446  double dphi;
447 
448  TVector3 initial_pivot ;
449 
450  // Leave the pivot at the origin for a 1-dim hit
451  if (kalhit->GetDimension() > 1) {
452 
453  initial_pivot = kalhit->GetMeasLayer().HitToXv(*kalhit) ;
454  }
455  else{
456  initial_pivot = TVector3(0.0,0.0,0.0);
457  }
458 
459 
460  // ---------------------------
461  // Create an initial start site for the track using the hit
462  // ---------------------------
463  // set up a dummy hit needed to create initial site
464 
465  TVTrackHit* pDummyHit = 0;
466 
467  if ( (pDummyHit = dynamic_cast<DDCylinderHit *>( kalhit )) ) {
468  pDummyHit = (new DDCylinderHit(*static_cast<DDCylinderHit*>( kalhit )));
469 
470  }
471  else if ( (pDummyHit = dynamic_cast<DDPlanarHit *>( kalhit )) ) {
472  pDummyHit = (new DDPlanarHit(*static_cast<DDPlanarHit*>( kalhit )));
473  //}
474  //else if ( (pDummyHit = dynamic_cast<DDPlanarStripHit *>( kalhit )) ) {
475  //pDummyHit = (new DDPlanarStripHit(*static_cast<DDPlanarStripHit*>( kalhit )));
476  if( pDummyHit->GetDimension() == 1 ) {
477 
478  const TVMeasLayer *ml = &pDummyHit->GetMeasLayer();
479 
480  const TVSurface* surf = dynamic_cast<const TVSurface*>(ml);
481 
482  if (surf) {
483  double phi;
484 
485  surf->CalcXingPointWith(helix, initial_pivot, phi);
486  streamlog_out( DEBUG ) << " MarlinDDKalTestTrack::initialise - CalcXingPointWith called for 1d hit ... " << std::endl ;
487 
488  } else {
489  streamlog_out( ERROR) << "<<<<<<<<< MarlinDDKalTestTrack::initialise: dynamic_cast failed for TVSurface >>>>>>>" << std::endl;
490  return error ;
491  }
492 
493  }
494  }
495  else {
496  streamlog_out( ERROR) << "<<<<<<<<< MarlinDDKalTestTrack::initialise: dynamic_cast failed for hit type >>>>>>>" << std::endl;
497  return error ;
498  }
499 
500  TVTrackHit& dummyHit = *pDummyHit;
501 
502  //SJA:FIXME: this constants should go in a header file
503  // give the dummy hit huge errors so that it does not contribute to the fit
504  dummyHit(0,1) = 1.e16; // give a huge error to d
505 
506  if(dummyHit.GetDimension()>1) dummyHit(1,1) = 1.e16; // give a huge error to z
507 
508  // use dummy hit to create initial site
509  TKalTrackSite& initialSite = *new TKalTrackSite(dummyHit);
510 
511  initialSite.SetHitOwner();// site owns hit
512  initialSite.SetOwner(); // site owns states
513 
514  // ---------------------------
515  // Set up initial track state
516  // ---------------------------
517 
518  helix.MoveTo( initial_pivot, dphi, 0, &cov );
519 
520  static TKalMatrix initialState(kSdim,1) ;
521  initialState(0,0) = helix.GetDrho() ; // d0
522  initialState(1,0) = helix.GetPhi0() ; // phi0
523  initialState(2,0) = helix.GetKappa() ; // kappa
524  initialState(3,0) = helix.GetDz(); // dz
525  initialState(4,0) = helix.GetTanLambda() ; // tan(lambda)
526  if (kSdim == 6) initialState(5,0) = 0.; // t0
527 
528  // make sure that the pivot is in the right place
529  initialSite.SetPivot(initial_pivot);
530 
531  // ---------------------------
532  // Set up initial Covariance Matrix
533  // ---------------------------
534 
535  TKalMatrix covK(kSdim,kSdim) ;
536  for(int i=0;i<5;++i) {
537  for(int j=0;j<5;++j) {
538  covK[i][j] = cov[i][j] ;
539  }
540  }
541  if (kSdim == 6) covK(5,5) = 1.e6; // t0
542 
543 // covK.Print();
544 
545  // Add initial states to the site
546  initialSite.Add(new TKalTrackState(initialState,covK,initialSite,TVKalSite::kPredicted));
547  initialSite.Add(new TKalTrackState(initialState,covK,initialSite,TVKalSite::kFiltered));
548 
549  // add the initial site to the track: that is, give the track initial parameters and covariance
550  // matrix at the starting measurement layer
551  _kaltrack->Add(&initialSite);
552 
553  _initialised = true ;
554 
555 
556 #ifdef MARLINTRK_DIAGNOSTICS_ON
557 
558  // convert to LICO parameters first
559 
560  double d0 = - helix.GetDrho() ;
561  double phi = toBaseRange( helix.GetPhi0() + M_PI/2. );
562  double omega = 1. /helix.GetRho() ;
563  double z0 = helix.GetDz() ;
564  double tanLambda = helix.GetTanLambda() ;
565 
566  _ktest->_diagnostics.set_intial_track_parameters(d0,
567  phi,
568  omega,
569  z0,
570  tanLambda,
571  helix.GetPivot().X(),
572  helix.GetPivot().Y(),
573  helix.GetPivot().Z(),
574  covK);
575 
576 
577 
578 #endif
579 
580  return success ;
581 
582  }
583 
584  int MarlinDDKalTestTrack::addAndFit( DDVTrackHit* kalhit, double& chi2increment, TKalTrackSite*& site, double maxChi2Increment) {
585 
586  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::addAndFit called : maxChi2Increment = " << std::scientific << maxChi2Increment << std::endl ;
587 
588  if ( ! _initialised ) {
589 
590  throw MarlinTrk::Exception("Track fit not initialised");
591 
592  }
593 
594  // here do dynamic cast repeatedly in DEBUG statement as this will be stripped out any way for production code
595  // otherwise we have to do the cast outside of the DEBUG statement and it won't be stripped out
596  streamlog_out( DEBUG1 ) << "Kaltrack::addAndFit : add site to track at index : "
597  << (dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) ))->GetIndex()
598  << " for type "
599  << dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->GetName() ;
600  streamlog_out( DEBUG0 ) << " with CellIDs:";
601 
602  for (unsigned int i = 0; i < (dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getNCellIDs());++i) {
603  streamlog_out( DEBUG0 ) << " : "
604  << dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getCellIDs()[i] ;
605 
606  }
607 
608  streamlog_out( DEBUG1 ) << std::endl ;
609 
610  TKalTrackSite* temp_site = new TKalTrackSite(*kalhit); // create new site for this hit
611 
612  KalTrackFilter filter( maxChi2Increment );
613  filter.resetFilterStatus();
614 
615  temp_site->SetFilterCond( &filter ) ;
616 
617 
618  // this is the only point at which a hit is actually filtered
619  // and it is here that we can get the GetDeltaChi2 vs the maxChi2Increment
620  // it will always be possible to get the delta chi2 so long as we have a link to the sites ...
621  // although calling smooth will natrually update delta chi2.
622 
623 
624  if (!_kaltrack->AddAndFilter(*temp_site)) {
625 
626  chi2increment = temp_site->GetDeltaChi2() ;
627  // get the measurement layer of the current hit
628  const DDVMeasLayer* ml = dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) ) ;
629  TVector3 pos = ml->HitToXv(*kalhit);
630  streamlog_out( DEBUG2 ) << "Kaltrack::addAndFit : site discarded! at index : " << ml->GetIndex()
631  << " for type " << ml->GetName()
632  << " chi2increment = " << chi2increment
633  << " maxChi2Increment = " << maxChi2Increment
634  << " x = " << pos.x()
635  << " y = " << pos.y()
636  << " z = " << pos.z()
637  << " with CellIDs: " << std::endl;
638 
639  for (unsigned int i = 0; i < (dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getNCellIDs());++i) {
640  streamlog_out( DEBUG1 ) << " CellID = "
641  << dynamic_cast<const DDVMeasLayer*>( &(kalhit->GetMeasLayer() ) )->getCellIDs()[i]
642  << std::endl ;
643  }
644 
645 
646 #ifdef MARLINTRK_DIAGNOSTICS_ON
647  _ktest->_diagnostics.record_rejected_site(kalhit, temp_site);
648 #endif
649 
650  delete temp_site; // delete site if filter step failed
651 
652 
653  // compiling the code below with the cmake option CMAKE_BUILD_TYPE=Debug
654  // and with LDFLAGS=-Wl,--no-undefined
655  // causes an undefined reference error
656  // the problem gets fixed using the if/else statement below
657 
658  // this fails
659  //return filter.usedForLastFilterStep() ? site_fails_chi2_cut : site_discarded ;
660 
661  // this also fails..
662  //bool rc = filter.usedForLastFilterStep() ;
663  //return (rc ? site_fails_chi2_cut : site_discarded);
664 
665  // but this works ?!!
666  //return ( true ? site_fails_chi2_cut : site_discarded);
667 
668  // and this also works..
669  streamlog_out(DEBUG2) << " addAndFit : Site passed Chi2 filter step ? " << filter.passedLastFilterStep() << std::endl;
670 
671  if( filter.passedLastFilterStep() == false ) {
672  return site_fails_chi2_cut ;
673  } else {
674  return site_discarded ;
675  }
676 
677  }
678 
679  site = temp_site;
680  chi2increment = site->GetDeltaChi2() ;
681 
682 #ifdef MARLINTRK_DIAGNOSTICS_ON
683  _ktest->_diagnostics.record_site(kalhit, site);
684 #endif
685 
686  return success ;
687 
688  }
689 
690  int MarlinDDKalTestTrack::addAndFit( EVENT::TrackerHit* trkhit, double& chi2increment, double maxChi2Increment) {
691 
692  if( ! trkhit ) {
693  streamlog_out( ERROR) << "MarlinDDKalTestTrack::addAndFit( EVENT::TrackerHit* trkhit, double& chi2increment, double maxChi2Increment): trkhit == 0" << std::endl;
694  return bad_intputs ;
695  }
696 
697  const DDVMeasLayer* ml = _ktest->findMeasLayer( trkhit ) ;
698 
699  if( ml == 0 ){
700  // fg: not sure if ml should ever be 0 - but it seems to happen,
701  // if point is not on surface and more than one surface exists ...
702 
703  streamlog_out( ERROR ) << ">>>>>>>>>>> no measurment layer found for trkhit cellid0 : "
704  << cellIDString( trkhit->getCellID0() ) << " at "
705  << Vector3D( trkhit->getPosition() ) << std::endl ;
706 
707  return IMarlinTrack::bad_intputs ;
708  }
709 
710  DDVTrackHit* kalhit = ml->ConvertLCIOTrkHit(trkhit) ;
711 
712  if( kalhit == 0 ){ //fg: ml->ConvertLCIOTrkHit returns 0 if hit not on surface !!!
714  }
715 
716  TKalTrackSite* site = 0 ;
717  int error_code = this->addAndFit( kalhit, chi2increment, site, maxChi2Increment);
718 
719  if( error_code != success ){
720 
721  delete kalhit;
722 
723  // if the hit fails for any reason other than the Chi2 cut record the Chi2 contibution as DBL_MAX
724  if( error_code != site_fails_chi2_cut ) {
725  chi2increment = DBL_MAX;
726  }
727 
728  _outlier_chi2_values.push_back(std::make_pair(trkhit, chi2increment));
729 
730  streamlog_out( DEBUG2 ) << ">>>>>>>>>>> addAndFit Number of Outliers : "
732 
733  return error_code ;
734  }
735  else {
736  this->addHit( trkhit, kalhit, ml ) ;
737  _hit_used_for_sites[trkhit] = site ;
738  _hit_chi2_values.push_back(std::make_pair(trkhit, chi2increment));
739  }
740 
741  // set the values for the point at which the fit becomes constained
742  if( _trackHitAtPositiveNDF == 0 && _kaltrack->GetNDF() >= 0){
743 
744  _trackHitAtPositiveNDF = trkhit;
745  _hitIndexAtPositiveNDF = _kaltrack->IndexOf( site );
746 
747  streamlog_out( DEBUG2 ) << ">>>>>>>>>>> Fit is now constrained at : "
748  << cellIDString( trkhit->getCellID0() )
749  << " pos " << Vector3D( trkhit->getPosition() )
750  << " trkhit = " << _trackHitAtPositiveNDF
751  << " index of kalhit = " << _hitIndexAtPositiveNDF
752  << " NDF = " << _kaltrack->GetNDF()
753  << std::endl;
754 
755  }
756 
757  return success ;
758 
759  }
760 
761 
762 
763  int MarlinDDKalTestTrack::testChi2Increment( EVENT::TrackerHit* trkhit, double& chi2increment ) {
764 
765  if( ! trkhit ) {
766  streamlog_out( ERROR) << "MarlinDDKalTestTrack::addAndFit( EVENT::TrackerHit* trkhit, double& chi2increment, double maxChi2Increment): trkhit == 0" << std::endl;
767  return IMarlinTrack::bad_intputs ;
768  }
769 
770  const DDVMeasLayer* ml = _ktest->findMeasLayer( trkhit ) ;
771 
772  if( ml == 0 ){
773  // fg: not sure if ml should ever be 0 - but it seems to happen,
774  // if point is not on surface and more than one surface exists ...
775 
776  streamlog_out( ERROR ) << ">>>>>>>>>>> no measurment layer found for trkhit cellid0 : "
777  << cellIDString( trkhit->getCellID0() ) << " at "
778  << Vector3D( trkhit->getPosition() ) << std::endl ;
779 
780  return IMarlinTrack::bad_intputs ;
781 
782  }
783 
784  DDVTrackHit* kalhit = ml->ConvertLCIOTrkHit(trkhit) ;
785 
786  if( kalhit == 0 ){ //fg: ml->ConvertLCIOTrkHit returns 0 if hit not on surface !!!
788  }
789 
790 
791  TKalTrackSite* site = 0 ;
792  int error_code = this->addAndFit( kalhit, chi2increment, site, -DBL_MAX); // using -DBL_MAX here ensures the hit will never be added to the fit
793 
794  delete kalhit;
795 
796  return error_code;
797 
798  }
799 
800 
801 
802  int MarlinDDKalTestTrack::fit( double maxChi2Increment ) {
803 
804  // SJA:FIXME: what do we do about calling fit after we have already added hits and filtered
805  // I guess this would created new sites when addAndFit is called
806  // one option would be to remove the sites
807  // need to check where the sites are stored ... probably in the KalTrackSystem
808  //
809 
810  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::fit() called " << std::endl ;
811 
812  if ( ! _initialised ) {
813 
814  throw MarlinTrk::Exception("Track fit not initialised");
815 
816  }
817 
818  // ---------------------------
819  // Prepare hit iterrator for adding hits to kaltrack
820  // ---------------------------
821 
822  TIter next(_kalhits, _fitDirection);
823 
824  // ---------------------------
825  // Start Kalman Filter
826  // ---------------------------
827 
828  DDVTrackHit *kalhit = 0;
829 
830  while ( (kalhit = dynamic_cast<DDVTrackHit *>( next() ) ) ) {
831 
832  double chi2increment;
833  TKalTrackSite* site=nullptr;
834  int error_code = this->addAndFit( kalhit, chi2increment, site, maxChi2Increment );
835 
836 
837  EVENT::TrackerHit* trkhit = kalhit->getLCIOTrackerHit();
838 
839  if( error_code == 0 ){ // add trkhit to map associating trkhits and sites
840  _hit_used_for_sites[trkhit] = site;
841  _hit_chi2_values.push_back(std::make_pair(trkhit, chi2increment));
842 
843  // set the values for the point at which the fit becomes constained
844  if( _trackHitAtPositiveNDF == 0 && _kaltrack->GetNDF() >= 0){
845 
846  _trackHitAtPositiveNDF = trkhit;
847  _hitIndexAtPositiveNDF = _kaltrack->IndexOf( site );
848 
849  streamlog_out( DEBUG2 ) << ">>>>>>>>>>> Fit is now constrained at : "
850  << cellIDString( trkhit->getCellID0() )
851  << " pos " << Vector3D( trkhit->getPosition() )
852  << " trkhit = " << _trackHitAtPositiveNDF
853  << " index of kalhit = " << _hitIndexAtPositiveNDF
854  << " NDF = " << _kaltrack->GetNDF()
855  << std::endl;
856 
857  }
858 
859  }
860  else { // hit rejected by the filter, so store in the list of rejected hits
861 
862  // if the hit fails for any reason other than the Chi2 cut record the Chi2 contibution as DBL_MAX
863  if( error_code != site_fails_chi2_cut ) {
864  chi2increment = DBL_MAX;
865  }
866 
867  _outlier_chi2_values.push_back(std::make_pair(trkhit, chi2increment));
868  streamlog_out( DEBUG2 ) << ">>>>>>>>>>> fit(): Number of Outliers : "
870 
872 
873  }
874 
875  } // end of Kalman filter
876 
878  streamlog_out( DEBUG2 ) << "Perform Smoothing for All Previous Measurement Sites " << std::endl ;
879  int error = this->smooth() ;
880 
881  if( error != success ) return error ;
882 
883  }
884 
885  //return _hit_used_for_sites.empty() == false ? success : all_sites_fail_fit ;
886  if( _hit_used_for_sites.empty() == false )
887  {
888  return success ;
889  }
890  else{
891  return all_sites_fail_fit ;
892  }
893 
894  }
895 
896 
900 
901  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::smooth() " << std::endl ;
902 
903  //fg: we should actually smooth all sites - it is then up to the user which smoothed tracks state to take
904  // for any furthter extrapolation/propagation ...
905 
906  if( !_smoothed )
907  _kaltrack->SmoothAll() ;
908 
909  //SJA:FIXME: in the current implementation it is only possible to smooth back to the 4th site.
910  // This is due to the fact that the covariance matrix is not well defined at the first 3 measurement sites filtered.
911 
912  // _kaltrack->SmoothBackTo( _hitIndexAtPositiveNDF + 1 ) ;
913 
914  _smoothed = true ;
915 
916  return success ;
917 
918  }
919 
920 
924 
925  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::smooth( EVENT::TrackerHit* " << trkhit << " ) " << std::endl ;
926 
927 
928  if ( !trkhit ) {
929  return bad_intputs ;
930  }
931 
932 
934 
935 
936  TKalTrackSite* site = 0 ;
937  int error_code = getSiteFromLCIOHit(trkhit, site);
938 
939  if( error_code != success ) return error_code ;
940 
941  int index = _kaltrack->IndexOf( site );
942 
943  _kaltrack->SmoothBackTo( index ) ;
944 
945  _smoothed = true ;
946 
947  return success ;
948 
949  }
950 
951 
952  int MarlinDDKalTestTrack::getTrackState( IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) {
953 
954  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::getTrackState( IMPL::TrackStateImpl& ts ) " << std::endl ;
955 
956  // use the last filtered track state
957  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
958 
959  this->ToLCIOTrackState( site, ts, chi2, ndf );
960 
961  return success ;
962 
963 
964  }
965 
966 
967  int MarlinDDKalTestTrack::getTrackState( EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) {
968 
969  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::getTrackState( EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts ) using hit: " << trkhit << " with cellID0 = " << trkhit->getCellID0() << std::endl ;
970 
971  TKalTrackSite* site = 0 ;
972  int error_code = getSiteFromLCIOHit(trkhit, site);
973 
974  if( error_code != success ) return error_code ;
975 
976  streamlog_out( DEBUG1 ) << "MarlinDDKalTestTrack::getTrackState: site " << site << std::endl;
977 
978  this->ToLCIOTrackState( *site, ts, chi2, ndf );
979 
980  return success ;
981  }
982 
983 
985 
987 
988  // this needs more thought. What about when the hits are added using addAndFit?
989 
990  // need to check the order so that we can return the list ordered in time
991  // as they will be added to _hit_chi2_values in the order of fitting
992  // not in the order of time
993 //
994 // if( _fitDirection == IMarlinTrack::backward ){
995 // std::reverse_copy( _hit_chi2_values.begin() , _hit_chi2_values.end() , std::back_inserter( hits ) ) ;
996 // } else {
997 // std::copy( _hit_chi2_values.begin() , _hit_chi2_values.end() , std::back_inserter( hits ) ) ;
998 // }
999 
1000  return success ;
1001 
1002  }
1003 
1005 
1007 
1008 
1009  // this needs more thought. What about when the hits are added using addAndFit?
1010 // // need to check the order so that we can return the list ordered in time
1011 // // as they will be added to _hit_chi2_values in the order of fitting
1012 // // not in the order of time
1013 //
1014 // if( _fitDirection == IMarlinTrack::backward ){
1015 // std::reverse_copy( _outlier_chi2_values.begin() , _outlier_chi2_values.end() , std::back_inserter( hits ) ) ;
1016 // } else {
1017 // std::copy( _outlier_chi2_values.begin() , _outlier_chi2_values.end() , std::back_inserter( hits ) ) ;
1018 // }
1019 
1020 
1021  return success ;
1022 
1023  }
1024 
1025 
1027 
1028  if( _initialised == false ) {
1029  return error;
1030  } else {
1031 
1032  ndf = _kaltrack->GetNDF();
1033  return success;
1034 
1035  }
1036 
1037  }
1038 
1040 
1041  trkhit = _trackHitAtPositiveNDF;
1042  return success;
1043 
1044  }
1045 
1046 
1047  int MarlinDDKalTestTrack::extrapolate( const Vector3D& point, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
1048 
1049  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1050 
1051  return this->extrapolate( point, site, ts, chi2, ndf ) ;
1052 
1053  }
1054 
1055  int MarlinDDKalTestTrack::extrapolate( const Vector3D& point, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) {
1056 
1057  TKalTrackSite* site = 0 ;
1058  int error_code = getSiteFromLCIOHit(trkhit, site);
1059 
1060  if( error_code != success ) return error_code;
1061 
1062  return this->extrapolate( point, *site, ts, chi2, ndf ) ;
1063 
1064  }
1065 
1066  int MarlinDDKalTestTrack::extrapolate( const Vector3D& point, const TKalTrackSite& site ,IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
1067 
1068  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::extrapolate( const Vector3D& point, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) called " << std::endl ;
1069 
1070  TKalTrackState& trkState = (TKalTrackState&) site.GetCurState(); // this segfaults if no hits are present
1071 
1072  THelicalTrack helix = trkState.GetHelix() ;
1073  double dPhi ;
1074 
1075  const TVector3 tpoint( point.x(), point.y(), point.z() ) ;
1076 
1077  Int_t sdim = trkState.GetDimension(); // dimensions of the track state, it will be 5 or 6
1078  TKalMatrix sv(sdim,1);
1079 
1080  // now move to the point
1081  TKalMatrix DF(sdim,sdim);
1082  DF.UnitMatrix();
1083  helix.MoveTo( tpoint , dPhi , &DF , 0) ; // move helix to desired point, and get propagator matrix
1084 
1085  TMatrixD c0(trkState.GetCovMat());
1086 
1087  TKalMatrix DFt = TKalMatrix(TMatrixD::kTransposed, DF);
1088  c0 = DF * c0 * DFt ; // update the covariance matrix
1089 
1090  this->ToLCIOTrackState( helix, c0, ts, chi2, ndf );
1091 
1092  return success;
1093 
1094  }
1095 
1096 
1097  int MarlinDDKalTestTrack::extrapolateToLayer( int layerID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
1098 
1099  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1100 
1101  return this->extrapolateToLayer( layerID, site, ts, chi2, ndf, detElementID, mode ) ;
1102 
1103  }
1104 
1105 
1106  int MarlinDDKalTestTrack::extrapolateToLayer( int layerID, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
1107 
1108  TKalTrackSite* site = 0;
1109  int error_code = getSiteFromLCIOHit(trkhit, site);
1110 
1111  if( error_code != success ) return error_code ;
1112 
1113  return this->extrapolateToLayer( layerID, *site, ts, chi2, ndf, detElementID, mode ) ;
1114 
1115  }
1116 
1117 
1118  int MarlinDDKalTestTrack::extrapolateToLayer( int layerID, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
1119 
1120  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::extrapolateToLayer( int layerID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID ) called " << std::endl ;
1121 
1122  Vector3D crossing_point ;
1123  const DDVMeasLayer* ml = 0;
1124 
1125  int error_code = this->intersectionWithLayer( layerID, site, crossing_point, detElementID, ml, mode ) ;
1126 
1127  if( error_code != 0 ) return error_code ;
1128 
1129  return this->extrapolate( crossing_point, site, ts, chi2, ndf ) ;
1130 
1131  }
1132 
1133 
1134  int MarlinDDKalTestTrack::extrapolateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
1135 
1136  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1137 
1138  return this->extrapolateToDetElement( detElementID, site, ts, chi2, ndf, mode ) ;
1139 
1140  }
1141 
1142 
1143  int MarlinDDKalTestTrack::extrapolateToDetElement( int detElementID, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
1144 
1145  TKalTrackSite* site = 0;
1146  int error_code = getSiteFromLCIOHit(trkhit, site);
1147 
1148  if( error_code != success ) return error_code ;
1149 
1150  return this->extrapolateToDetElement( detElementID, *site, ts, chi2, ndf, mode ) ;
1151 
1152  }
1153 
1154 
1155  int MarlinDDKalTestTrack::extrapolateToDetElement( int detElementID, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
1156 
1157  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::extrapolateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) called " << std::endl ;
1158 
1159  Vector3D crossing_point ;
1160 
1161  const DDVMeasLayer* ml = 0;
1162  int error_code = this->intersectionWithDetElement( detElementID, site, crossing_point, ml, mode ) ;
1163 
1164  if( error_code != 0 ) return error_code ;
1165 
1166  return this->extrapolate( crossing_point, site, ts, chi2, ndf ) ;
1167 
1168  }
1169 
1170 
1171 
1172  int MarlinDDKalTestTrack::propagate( const Vector3D& point, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
1173 
1174  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1175 
1176  // check if the point is inside the beampipe
1177  // SJA:FIXME: really we should also check if the PCA to the point is also less than R
1178  const DDVMeasLayer* ml = ( (_ktest->getIPLayer() ) && point.r() < _ktest->getIPLayer()->GetR()) ? _ktest->getIPLayer() : 0;
1179 
1180  return this->propagate( point, site, ts, chi2, ndf, ml ) ;
1181 
1182  }
1183 
1184  int MarlinDDKalTestTrack::propagate( const Vector3D& point, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ){
1185 
1186  TKalTrackSite* site = 0;
1187  int error_code = getSiteFromLCIOHit(trkhit, site);
1188 
1189  if( error_code != success ) return error_code ;
1190 
1191  // check if the point is inside the beampipe
1192  // SJA:FIXME: really we should also check if the PCA to the point is also less than R
1193 
1194  const DDVMeasLayer* ml = _ktest->getIPLayer();
1195 
1196  if ( ml )
1197  if (point.r() > _ktest->getIPLayer()->GetR()) ml = NULL;
1198 
1199 // const DDVMeasLayer* ml = (point.r() < _ktest->getIPLayer()->GetR()) ? _ktest->getIPLayer() : 0;
1200 
1201  return this->propagate( point, *site, ts, chi2, ndf, ml ) ;
1202 
1203  }
1204 
1205  int MarlinDDKalTestTrack::propagate( const Vector3D& point, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, const DDVMeasLayer* ml ){
1206 
1207  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::propagate( const Vector3D& point, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) called " << std::endl ;
1208 
1209  const TVector3 tpoint( point.x(), point.y(), point.z() ) ;
1210 
1211  TKalTrackState& trkState = (TKalTrackState&) site.GetCurState(); // this segfaults if no hits are present
1212 
1213  THelicalTrack helix = trkState.GetHelix() ;
1214  double dPhi = 0.0;
1215 
1216 
1217  Int_t sdim = trkState.GetDimension(); // dimensions of the track state, it will be 5 or 6
1218  TKalMatrix sv(sdim,1);
1219 
1220  TKalMatrix F(sdim,sdim); // propagator matrix to be returned by transport function
1221  F.UnitMatrix(); // set the propagator matrix to the unit matrix
1222 
1223  TKalMatrix Q(sdim,sdim); // noise matrix to be returned by transport function
1224  Q.Zero();
1225  TVector3 x0; // intersection point to be returned by transport
1226 
1227  TMatrixD c0(trkState.GetCovMat());
1228 
1229  // the last layer crossed by the track before point
1230  if( ! ml ){
1231  ml = _ktest->getLastMeasLayer(helix, tpoint);
1232  }
1233 
1234  if ( ml ) {
1235 
1236  _ktest->_det->Transport(site, *ml, x0, sv, F, Q ) ; // transport to last layer cross before point
1237 
1238  // given that we are sure to have intersected the layer ml as this was provided via getLastMeasLayer, x0 will lie on the layer
1239  // this could be checked with the method isOnSurface
1240  // so F will be the propagation matrix from the current location to the last surface and Q will be the noise matrix up to this point
1241 
1242 
1243  TKalMatrix Ft = TKalMatrix(TMatrixD::kTransposed, F);
1244  c0 = F * c0 * Ft + Q; // update covaraince matrix and add the MS assosiated with moving to tvml
1245 
1246  helix.MoveTo( x0 , dPhi , 0 , 0 ) ; // move the helix to tvml
1247 
1248 
1249  }
1250  else { // the current site is at the last surface before the point to propagate to
1251 
1252  ml = dynamic_cast<const DDVMeasLayer*>(&(site.GetHit().GetMeasLayer())) ;
1253 
1254  }
1255 
1256  // get whether the track is incomming or outgoing at the last surface
1257  const TVSurface *sfp = dynamic_cast<const TVSurface *>(ml); // last surface
1258 
1259  TMatrixD dxdphi = helix.CalcDxDphi(0); // tangent vector at last surface
1260  TVector3 dxdphiv(dxdphi(0,0),dxdphi(1,0),dxdphi(2,0)); // convert matirix diagonal to vector
1261 // Double_t cpa = helix.GetKappa(); // get pt
1262 
1263  Bool_t isout = -dPhi*dxdphiv.Dot(sfp->GetOutwardNormal(x0)) < 0 ? kTRUE : kFALSE; // out-going or in-coming at the destination surface
1264 
1265  // now move to the point
1266  TKalMatrix DF(sdim,sdim);
1267  DF.UnitMatrix();
1268  helix.MoveTo( tpoint , dPhi , &DF , 0) ; // move helix to desired point, and get propagator matrix
1269 
1270  TKalMatrix Qms(sdim, sdim);
1271  ml->CalcQms(isout, helix, dPhi, Qms); // calculate MS for the final step through the present material
1272 
1273  TKalMatrix DFt = TKalMatrix(TMatrixD::kTransposed, DF);
1274  c0 = DF * c0 * DFt + Qms ; // update the covariance matrix
1275 
1276 
1277  this->ToLCIOTrackState( helix, c0, ts, chi2, ndf );
1278 
1279  return success;
1280 
1281  }
1282 
1283 
1284  int MarlinDDKalTestTrack::propagateToLayer( int layerID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
1285 
1286  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1287 
1288  return this->propagateToLayer( layerID, site, ts, chi2, ndf, detElementID, mode ) ;
1289 
1290  }
1291 
1292 
1293  int MarlinDDKalTestTrack::propagateToLayer( int layerID, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
1294 
1295  TKalTrackSite* site = 0;
1296  int error_code = getSiteFromLCIOHit(trkhit, site);
1297 
1298  if( error_code != success ) return error_code ;
1299 
1300  return this->propagateToLayer( layerID, *site, ts, chi2, ndf, detElementID, mode ) ;
1301 
1302  }
1303 
1304 
1305  int MarlinDDKalTestTrack::propagateToLayer( int layerID, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID, int mode ) {
1306 
1307  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::propagateToLayer( int layerID, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int& detElementID ) called " << std::endl;
1308 
1309  Vector3D crossing_point ;
1310 
1311  const DDVMeasLayer* ml = 0;
1312 
1313  int error_code = this->intersectionWithLayer( layerID, site, crossing_point, detElementID, ml, mode) ;
1314 
1315  if( error_code != success ) return error_code ;
1316 
1317  return this->propagate( crossing_point, site, ts, chi2, ndf , ml) ;
1318 
1319  }
1320 
1321 
1322  int MarlinDDKalTestTrack::propagateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
1323 
1324  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1325 
1326  return this->propagateToDetElement( detElementID, site, ts, chi2, ndf, mode ) ;
1327 
1328  }
1329 
1330 
1331  int MarlinDDKalTestTrack::propagateToDetElement( int detElementID, EVENT::TrackerHit* trkhit, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
1332 
1333  TKalTrackSite* site = 0;
1334  int error_code = getSiteFromLCIOHit(trkhit, site);
1335 
1336  if( error_code != success ) return error_code ;
1337 
1338  return this->propagateToDetElement( detElementID, *site, ts, chi2, ndf, mode ) ;
1339 
1340  }
1341 
1342 
1343  int MarlinDDKalTestTrack::propagateToDetElement( int detElementID, const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) {
1344 
1345  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::propagateToDetElement( int detElementID, IMPL::TrackStateImpl& ts, double& chi2, int& ndf, int mode ) called " << std::endl ;
1346 
1347  Vector3D crossing_point ;
1348 
1349  const DDVMeasLayer* ml = 0;
1350  int error_code = this->intersectionWithDetElement( detElementID, site, crossing_point, ml, mode ) ;
1351 
1352  if( error_code != 0 ) return error_code ;
1353 
1354  return this->propagate( crossing_point, site, ts, chi2, ndf, ml ) ;
1355 
1356  }
1357 
1358 
1359  int MarlinDDKalTestTrack::intersectionWithDetElement( int detElementID, Vector3D& point, int mode ) {
1360 
1361  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1362 
1363  const DDVMeasLayer* ml = 0;
1364  return this->intersectionWithDetElement( detElementID, site, point, ml, mode ) ;
1365 
1366  }
1367 
1368 
1369  int MarlinDDKalTestTrack::intersectionWithDetElement( int detElementID, EVENT::TrackerHit* trkhit, Vector3D& point, int mode ) {
1370 
1371  TKalTrackSite* site = 0;
1372  int error_code = getSiteFromLCIOHit(trkhit, site);
1373 
1374  if( error_code != success ) return error_code ;
1375 
1376  const DDVMeasLayer* ml = 0;
1377  return this->intersectionWithDetElement( detElementID, *site, point, ml, mode ) ;
1378 
1379  }
1380 
1381  int MarlinDDKalTestTrack::intersectionWithDetElement( int detElementID, const TKalTrackSite& site, Vector3D& point, const DDVMeasLayer*& ml, int mode ) {
1382 
1383  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::intersectionWithDetElement( int detElementID, const TKalTrackSite& site, Vector3D& point, const DDVMeasLayer*& ml, int mode) called " << std::endl;
1384 
1385  std::vector<const DDVMeasLayer*> meas_modules ;
1386  _ktest->getSensitiveMeasurementModules( detElementID, meas_modules ) ;
1387 
1388  if( meas_modules.size() == 0 ) {
1389 
1390  std::stringstream errorMsg;
1391  errorMsg << "MarlinDDKalTestTrack::intersectionWithDetElement detector element id unkown: detElementID = "
1392  << cellIDString( detElementID ) << std::endl ;
1393 
1394  throw MarlinTrk::Exception(errorMsg.str());
1395 
1396  }
1397 
1398  int dummy_detElementID; // not returned here as this is a single element as far as the outside world is concerned. Could check they are equal if we wanted ...
1399  int error_code = this->findIntersection( meas_modules, site, point, dummy_detElementID, ml, mode ) ;
1400 
1401  if( error_code == success ){
1402 
1403 
1404  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::intersectionWithDetElement intersection with detElementID = "
1405  << cellIDString( detElementID )
1406  << ": at x = " << point.x()
1407  << " y = " << point.y()
1408  << " z = " << point.z()
1409  << std::endl ;
1410  }
1411 
1412  else if( error_code == no_intersection ) {
1413 
1414  ml = 0;
1415 
1416  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::intersectionWithDetElement No intersection with detElementID = "
1417  << cellIDString( detElementID )
1418  << std::endl ;
1419 
1420  }
1421 
1422  return error_code ;
1423 
1424  }
1425 
1426  int MarlinDDKalTestTrack::intersectionWithLayer( int layerID, Vector3D& point, int& detElementID, int mode ) {
1427 
1428  const TKalTrackSite& site = *(dynamic_cast<const TKalTrackSite*>(_kaltrack->Last())) ;
1429  const DDVMeasLayer* ml = 0;
1430  return this->intersectionWithLayer( layerID, site, point, detElementID, ml, mode ) ;
1431 
1432  }
1433 
1434 
1435  int MarlinDDKalTestTrack::intersectionWithLayer( int layerID, EVENT::TrackerHit* trkhit, Vector3D& point, int& detElementID, int mode ) {
1436 
1437  TKalTrackSite* site = 0;
1438  int error_code = getSiteFromLCIOHit(trkhit, site);
1439 
1440  if( error_code != success ) return error_code ;
1441 
1442  const DDVMeasLayer* ml = 0;
1443  return this->intersectionWithLayer( layerID, *site, point, detElementID, ml, mode ) ;
1444 
1445  }
1446 
1447 
1448  int MarlinDDKalTestTrack::intersectionWithLayer( int layerID, const TKalTrackSite& site, Vector3D& point, int& detElementID, const DDVMeasLayer*& ml, int mode ) {
1449 
1450  streamlog_out(DEBUG2) << "MarlinDDKalTestTrack::intersectionWithLayer( int layerID, const TKalTrackSite& site, Vector3D& point, int& detElementID, int mode) called layerID = " << layerID << std::endl;
1451 
1452  std::vector<DDVMeasLayer const*> meas_modules ;
1453  _ktest->getSensitiveMeasurementModulesForLayer( layerID, meas_modules ) ;
1454 
1455  if( meas_modules.size() == 0 ) {
1456 
1457  streamlog_out(DEBUG5)<< "MarlinDDKalTestTrack::intersectionWithLayer layer id unknown: layerID = " << cellIDString( layerID ) << std::endl ;
1458  return no_intersection;
1459 
1460  }
1461 
1462  // int index_of_intersected;
1463  int error_code = this->findIntersection( meas_modules, site, point, detElementID, ml, mode ) ;
1464 
1465  if( error_code == success ){
1466 
1467 
1468  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::intersectionWithLayer intersection with layerID = "
1469  << layerID
1470  << ": at x = " << point.x()
1471  << " y = " << point.y()
1472  << " z = " << point.z()
1473  << " r = " << point.rho()
1474  << " detElementID = " << detElementID
1475  << " " << cellIDString( detElementID )
1476  << std::endl ;
1477 
1478  }
1479  else if( error_code == no_intersection ) {
1480 
1481  ml = 0;
1482  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::intersectionWithLayer No intersection with layerID = "
1483  << layerID
1484  << " " << cellIDString( layerID )
1485  << std::endl ;
1486 
1487  }
1488 
1489  return error_code ;
1490 
1491 
1492  }
1493 
1494 
1495  int MarlinDDKalTestTrack::findIntersection( const DDVMeasLayer& meas_module, const TKalTrackSite& site, Vector3D& point, double& dphi, int& detElementID, int mode ) {
1496 
1497 
1498  TKalTrackState& trkState = (TKalTrackState&) site.GetCurState();
1499 
1500 
1501  //--------- DEBUG --------------
1502  // TKalTrackState* tsSmoothed = ( &((TVKalSite&)site).GetState(TVKalSite::kSmoothed) != 0 ?
1503  // &(TKalTrackState&) ((TVKalSite&)site).GetState( TVKalSite::kSmoothed ) : 0 ) ;
1504  // if( tsSmoothed == &trkState )
1505  // streamlog_out(DEBUG2) << "************ MarlinDDKalTestTrack::intersectionWithLayer : using smoothed TrackState !!!!! " << std::endl ;
1506 
1507  // TKalTrackState* tsFiltered = ( &((TVKalSite&)site).GetState(TVKalSite::kFiltered) != 0 ?
1508  // &(TKalTrackState&) ((TVKalSite&)site).GetState( TVKalSite::kFiltered ) : 0 ) ;
1509  // if( tsFiltered == &trkState )
1510  // streamlog_out(DEBUG2) << "************ MarlinDDKalTestTrack::intersectionWithLayer : using filtered TrackState !!!!! " << std::endl ;
1511  // //------------------------------
1512 
1513 
1514  THelicalTrack helix = trkState.GetHelix() ;
1515 
1516  TVector3 xto; // reference point at destination to be returned by CalcXinPointWith
1517 
1518  int crossing_exist = meas_module.getIntersectionAndCellID(helix, xto, dphi, detElementID, mode);
1519  // int crossing_exist = surf->CalcXingPointWith(helix, xto, dphi, mode) ;
1520 
1521  streamlog_out(DEBUG1) << "MarlinDDKalTestTrack::intersectionWithLayer crossing_exist = " << crossing_exist << " dphi " << dphi << " with detElementIDs: " << detElementID ;
1522 
1523  streamlog_out(DEBUG1) << std::endl ;
1524 
1525 
1526  if( crossing_exist == 0 ) {
1527  return no_intersection ;
1528  }
1529  else {
1530 
1531  point[0] = xto.X();
1532  point[1] = xto.Y();
1533  point[2] = xto.Z();
1534 
1535  }
1536 
1537  return success ;
1538 
1539  }
1540 
1541 
1542 
1543  int MarlinDDKalTestTrack::findIntersection( std::vector<DDVMeasLayer const*>& meas_modules, const TKalTrackSite& site, Vector3D& point, int& detElementID, const DDVMeasLayer*& ml, int mode ) {
1544 
1545  unsigned int n_modules = meas_modules.size() ;
1546 
1547  double dphi_min = DBL_MAX; // use to store the min deflection angle found so that can avoid the crossing on the far side of the layer
1548  bool surf_found(false);
1549 
1550  for( unsigned int i = 0 ; i < n_modules ; ++i ){
1551 
1552  double dphi = 0;
1553  // need to send a temporary point as we may get the crossing point with the layer on the oposite side of the layer
1554  Vector3D point_temp ;
1555 
1556  int temp_detElementID;
1557 
1558  int error_code = findIntersection( *meas_modules[i], site, point_temp, dphi, temp_detElementID, mode ) ;
1559 
1560  if( error_code == success ) {
1561 
1562  // make sure we get the next crossing
1563  if( fabs(dphi) < dphi_min ) {
1564 
1565  dphi_min = fabs(dphi) ;
1566  surf_found = true ;
1567  ml = meas_modules[i];
1568  detElementID = temp_detElementID;
1569  point = point_temp ;
1570  }
1571 
1572  }
1573  else if( error_code != no_intersection ) { // in which case error_code is an error rather than simply a lack of intersection, so return
1574 
1575  return error_code ;
1576 
1577  }
1578 
1579  }
1580 
1581  // check if the surface was found and return accordingly
1582  if ( surf_found ) {
1583  return success ;
1584  }
1585  else {
1586  return no_intersection ;
1587  }
1588 
1589 
1590  }
1591 
1592 
1593 
1594  void MarlinDDKalTestTrack::ToLCIOTrackState( const THelicalTrack& helix, const TMatrixD& cov, IMPL::TrackStateImpl& ts, double& chi2, int& ndf) const {
1595 
1596  chi2 = _kaltrack->GetChi2();
1597  ndf = _kaltrack->GetNDF();
1598 
1599  //============== convert parameters to LCIO convention ====
1600 
1601  // fill 5x5 covariance matrix from the 6x6 covariance matrix above
1602  TMatrixD covK(5,5) ; for(int i=0;i<5;++i) for(int j=0;j<5;++j) covK[i][j] = cov[i][j] ;
1603 
1604  // this is for incomming tracks ...
1605  double phi = toBaseRange( helix.GetPhi0() + M_PI/2. ) ;
1606  double omega = 1. /helix.GetRho() ;
1607  double d0 = - helix.GetDrho() ;
1608  double z0 = helix.GetDz() ;
1609  double tanLambda = helix.GetTanLambda() ;
1610 
1611  ts.setD0( d0 ) ;
1612  ts.setPhi( phi ) ; // fi0 - M_PI/2. ) ;
1613  ts.setOmega( omega ) ;
1614  ts.setZ0( z0 ) ;
1615  ts.setTanLambda( tanLambda ) ;
1616 
1617  Double_t cpa = helix.GetKappa();
1618  double alpha = omega / cpa ; // conversion factor for omega (1/R) to kappa (1/Pt)
1619 
1620  EVENT::FloatVec covLCIO( 15 ) ;
1621  covLCIO[ 0] = covK( 0 , 0 ) ; // d0, d0
1622 
1623  covLCIO[ 1] = - covK( 1 , 0 ) ; // phi0, d0
1624  covLCIO[ 2] = covK( 1 , 1 ) ; // phi0, phi
1625 
1626  covLCIO[ 3] = - covK( 2 , 0 ) * alpha ; // omega, d0
1627  covLCIO[ 4] = covK( 2 , 1 ) * alpha ; // omega, phi
1628  covLCIO[ 5] = covK( 2 , 2 ) * alpha * alpha ; // omega, omega
1629 
1630  covLCIO[ 6] = - covK( 3 , 0 ) ; // z0 , d0
1631  covLCIO[ 7] = covK( 3 , 1 ) ; // z0 , phi
1632  covLCIO[ 8] = covK( 3 , 2 ) * alpha ; // z0 , omega
1633  covLCIO[ 9] = covK( 3 , 3 ) ; // z0 , z0
1634 
1635  covLCIO[10] = - covK( 4 , 0 ) ; // tanl, d0
1636  covLCIO[11] = covK( 4 , 1 ) ; // tanl, phi
1637  covLCIO[12] = covK( 4 , 2 ) * alpha ; // tanl, omega
1638  covLCIO[13] = covK( 4 , 3 ) ; // tanl, z0
1639  covLCIO[14] = covK( 4 , 4 ) ; // tanl, tanl
1640 
1641 
1642  ts.setCovMatrix( covLCIO ) ;
1643 
1644 
1645  float pivot[3] ;
1646 
1647  pivot[0] = helix.GetPivot().X() ;
1648  pivot[1] = helix.GetPivot().Y() ;
1649  pivot[2] = helix.GetPivot().Z() ;
1650 
1651  ts.setReferencePoint( pivot ) ;
1652 
1653  streamlog_out( DEBUG2 ) << " kaltest track parameters: "
1654  << " chi2/ndf " << chi2 / ndf
1655  << " chi2 " << chi2
1656  << " ndf " << ndf
1657  << " prob " << TMath::Prob(chi2, ndf)
1658  << std::endl
1659 
1660  << "\t D0 " << d0 << "[+/-" << sqrt( covLCIO[0] ) << "] "
1661  << "\t Phi :" << phi << "[+/-" << sqrt( covLCIO[2] ) << "] "
1662  << "\t Omega " << omega << "[+/-" << sqrt( covLCIO[5] ) << "] "
1663  << "\t Z0 " << z0 << "[+/-" << sqrt( covLCIO[9] ) << "] "
1664  << "\t tan(Lambda) " << tanLambda << "[+/-" << sqrt( covLCIO[14]) << "] "
1665 
1666  << "\t pivot : [" << pivot[0] << ", " << pivot[1] << ", " << pivot[2]
1667  << " - r: " << std::sqrt( pivot[0]*pivot[0]+pivot[1]*pivot[1] ) << "]"
1668  << std::endl ;
1669 
1670 
1671  }
1672 
1673 
1674  void MarlinDDKalTestTrack::ToLCIOTrackState( const TKalTrackSite& site, IMPL::TrackStateImpl& ts, double& chi2, int& ndf ) const {
1675 
1676  TKalTrackState& trkState = (TKalTrackState&) site.GetCurState(); // GetCutState will return the last added state to this site
1677  // Assuming everything has proceeded as expected
1678  // this will be Predicted -> Filtered -> Smoothed
1679 
1680 
1681  // streamlog_out( DEBUG3 ) << " MarlinDDKalTestTrack::ToLCIOTrackState : " << std::endl ;
1682  // trkState.DebugPrint() ;
1683 
1684  THelicalTrack helix = trkState.GetHelix() ;
1685 
1686  TMatrixD c0(trkState.GetCovMat());
1687 
1688  this->ToLCIOTrackState( helix, c0, ts, chi2, ndf );
1689 
1690  }
1691 
1692 
1694 
1695  std::stringstream str ;
1696 
1697  str << IMarlinTrack::toString() ;
1698 
1699  str << _kaltrack->toString() ;
1700 
1701  str << " --------------------- " << std::endl ;
1702 
1703  return str.str() ;
1704  }
1705 
1706  int MarlinDDKalTestTrack::getSiteFromLCIOHit( EVENT::TrackerHit* trkhit, TKalTrackSite*& site ) const {
1707 
1709 
1710  it = _hit_used_for_sites.find(trkhit) ;
1711 
1712  if( it == _hit_used_for_sites.end() ) { // hit not associated with any site
1713 
1714  bool found = false;
1715 
1716  for( unsigned int i = 0; i < _hit_not_used_for_sites.size(); ++i) {
1717  if( trkhit == _hit_not_used_for_sites[i] ) found = true ;
1718  }
1719 
1720  if( found ) {
1721  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::getSiteFromLCIOHit: hit was rejected during filtering" << std::endl ;
1722  return site_discarded ;
1723  }
1724  else {
1725  streamlog_out( DEBUG2 ) << "MarlinDDKalTestTrack::getSiteFromLCIOHit: hit " << trkhit << " not in list of supplied hits" << std::endl ;
1726  return bad_intputs ;
1727  }
1728  }
1729 
1730  site = it->second;
1731 
1732 
1733  streamlog_out( DEBUG1 ) << "MarlinDDKalTestTrack::getSiteFromLCIOHit: site " << site << " found for hit " << trkhit << std::endl ;
1734  return success ;
1735 
1736  }
1737 
1738 } // end of namespace MarlinTrk
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...
double r() const
MarlinDDKalTestTrack(MarlinDDKalTest *ktest)
int intersectionWithDetElement(int detElementID, Vector3D &point, int mode=modeClosest)
extrapolate the fit to numbered sensitive detector element, returning intersection point in global co...
int getSiteFromLCIOHit(EVENT::TrackerHit *trkhit, TKalTrackSite *&site) const
get the measurement site associated with the given lcio TrackerHit trkhit
T empty(T...args)
T copy(T...args)
virtual void setD0(float d0)
virtual const double * getPosition() const =0
double rho() const
virtual float getTanLambda() const =0
std::string toString()
Dump this track to a string for debugging.
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 ...
int findIntersection(std::vector< DDVMeasLayer const * > &meas_modules, const TKalTrackSite &site, Vector3D &point, int &detElementID, const DDVMeasLayer *&ml, int mode=modeClosest)
extrapolate the fit at the measurement site, to sensitive detector elements contained in the std::vec...
KalTrackFilter(double maxDeltaChi2=DBL_MAX)
C&#39;tor - takes as optional argument the maximum allowed delta chi2 for adding the hit (in IsAccepted()...
virtual void setTanLambda(float tanLambda)
virtual float getOmega() const =0
virtual const FloatVec & getCovMatrix() const =0
#define M_PI
std::string cellIDString(int detElementID)
std::map< EVENT::TrackerHit *, DDVTrackHit * > _lcio_hits_to_kaltest_hits
map to store relation between lcio hits kaltest hits
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...
Helper class for defining a filter condition based on the delta chi2 in the AddAndFilter step...
T endl(T...args)
static const bool forward
boolean constant for defining backward direction - to be used for intitialise
Definition: IMarlinTrack.h:44
static const unsigned useSmoothing
Use smoothing when calling fit( bool fitDirection )
const DDVMeasLayer * getLastMeasLayer(THelicalTrack const &helix, TVector3 const &point) const
bool _fitDirection
used to store the fit direction supplied to intialise
virtual std::string toString()
Dump this track to a string for debugging - implementation dependant.
Definition: IMarlinTrack.cc:40
void ToLCIOTrackState(const TKalTrackSite &site, IMPL::TrackStateImpl &ts, double &chi2, int &ndf) const
fill LCIO Track State with parameters from helix and cov matrix
int getNDF(int &ndf)
get the current number of degrees of freedom for the fit.
void getSensitiveMeasurementModulesForLayer(int layerID, std::vector< const DDVMeasLayer * > &measmodules) const
Store active measurement module IDs needed for navigation.
double y() const
T end(T...args)
static const int bad_intputs
Definition: IMarlinTrack.h:55
int fit(double maxChi2Increment=DBL_MAX)
perform the fit of all current hits, returns error code ( IMarlinTrack::success if no error ) ...
dd4hep::rec::Vector3D Vector3D
the Vector3D used for the tracking interface
Definition: IMarlinTrack.h:26
virtual void setReferencePoint(const float *rPnt)
STL class.
int addHit(EVENT::TrackerHit *hit)
add hit to track - the hits have to be added ordered in time ( i.e.
std::map< EVENT::TrackerHit *, TKalTrackSite * > _hit_used_for_sites
map to store relation between lcio hits and measurement sites
virtual float getD0() const =0
void setMass(double mass)
set the mass of the charged particle (GeV) that is used for energy loss and multiple scattering - def...
bool _initialised
used to store whether initial track state has been supplied or created
STL class.
int testChi2Increment(EVENT::TrackerHit *hit, double &chi2increment)
obtain the chi2 increment which would result in adding the hit to the fit.
T push_back(T...args)
void getSensitiveMeasurementModules(int detElementID, std::vector< const DDVMeasLayer * > &measmodules) const
Store active measurement module IDs needed for navigation.
bool passedLastFilterStep() const
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 ...
static const int all_sites_fail_fit
Definition: IMarlinTrack.h:59
virtual void setCovMatrix(const float *cov)
T str(T...args)
T make_pair(T...args)
static const std::string & encoding_string()
virtual const float * getReferencePoint() const =0
static const int site_discarded
Definition: IMarlinTrack.h:57
virtual void setZ0(float z0)
bool getOption(unsigned CFGOption)
Return the option&#39;s current value - false if option not defined.
virtual int getCellID0() const =0
double getMass()
return the of the charged particle (GeV) that is used for energy loss and multiple scattering...
const DDVMeasLayer * findMeasLayer(EVENT::TrackerHit *trkhit) const
T scientific(T...args)
static const int success
Definition: IMarlinTrack.h:53
virtual float getZ0() const =0
double z() const
static const int no_intersection
Definition: IMarlinTrack.h:56
int initialise(bool fitDirection)
initialise the fit using the hits added up to this point - the fit direction has to be specified usin...
int getTrackerHitAtPositiveNDF(EVENT::TrackerHit *&trkhit)
get TrackeHit at which fit became constrained, i.e.
virtual void setPhi(float phi)
T find(T...args)
T size(T...args)
EVENT::TrackerHit * _trackHitAtPositiveNDF
static const int site_fails_chi2_cut
Definition: IMarlinTrack.h:58
std::vector< std::pair< EVENT::TrackerHit *, double > > _outlier_chi2_values
vector to store the chi-sqaure increment for measurement sites
T begin(T...args)
T back_inserter(T...args)
double toBaseRange(double phi) const
helper function to restrict the range of the azimuthal angle to ]-pi,pi]
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
Interface to KaltTest Kalman fitter - instantiates and holds the detector geometry.
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()
smooth all track states
int getOutliers(std::vector< std::pair< EVENT::TrackerHit *, double > > &hits)
get the list of hits which have been rejected by from the fit due to the a chi2 increment greater tha...
virtual void setOmega(float omega)
double x() const
T sqrt(T...args)
Exception thrown in IMarlinTrk namespace (implemetations of IMarlinTrkSystem and IMarlinTrack).
int addAndFit(EVENT::TrackerHit *hit, double &chi2increment, double maxChi2Increment=DBL_MAX)
update the current fit using the supplied hit, return code via int.
std::vector< EVENT::TrackerHit * > _hit_not_used_for_sites
vector to store lcio hits rejected for measurement sites
virtual float getPhi() const =0
T setprecision(T...args)
const DDCylinderMeasLayer * getIPLayer() const
std::vector< std::pair< EVENT::TrackerHit *, double > > _hit_chi2_values
vector to store the chi-sqaure increment for measurement sites
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 ...
bool _smoothed
used to store whether smoothing has been performed
virtual Bool_t IsAccepted(const TKalTrackSite &site)
int getTrackState(IMPL::TrackStateImpl &ts, double &chi2, int &ndf)
get track state, returning TrackState, chi2 and ndf via reference
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...
static const int error
Definition: IMarlinTrack.h:54