CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
GroupedCkfTrajectoryBuilder.cc
Go to the documentation of this file.
1 
4 
5 
8 
23 
31 
32 // only included for RecHit comparison operator:
34 
35 #include <algorithm>
36 
37 using namespace std;
38 
39 //#define DBG2_GCTB
40 
41 //#define STANDARD_INTERMEDIARYCLEAN
42 
43 #ifdef STANDARD_INTERMEDIARYCLEAN
45 #endif
46 
47 /* ====== B.M. to be ported layer ===========
48 #ifdef DBG_GCTB
49 #include "RecoTracker/CkfPattern/src/ShowCand.h"
50 #endif
51 // #define DBG2_GCTB
52 #ifdef DBG2_GCTB
53 #include "RecoTracker/CkfPattern/src/SimIdPrinter.h"
54 #include "Tracker/TkDebugTools/interface/LayerFinderByDet.h"
55 #include "Tracker/TkLayout/interface/TkLayerName.h"
56 #endif
57 =================================== */
58 
59 
66  const TransientTrackingRecHitBuilder* recHitBuilder,
67  const MeasurementTracker* measurementTracker,
68  const TrajectoryFilter* filter,
69  const TrajectoryFilter* inOutFilter):
70 
71 
73  updator, propagatorAlong,propagatorOpposite,
74  estimator, recHitBuilder, measurementTracker, filter, inOutFilter)
75 {
76  // fill data members from parameters (eventually data members could be dropped)
77  //
78  theMaxCand = conf.getParameter<int>("maxCand");
79 
80  theLostHitPenalty = conf.getParameter<double>("lostHitPenalty");
81  theFoundHitBonus = conf.getParameter<double>("foundHitBonus");
82  theIntermediateCleaning = conf.getParameter<bool>("intermediateCleaning");
83  theAlwaysUseInvalid = conf.getParameter<bool>("alwaysUseInvalidHits");
84  theLockHits = conf.getParameter<bool>("lockHits");
85  theBestHitOnly = conf.getParameter<bool>("bestHitOnly");
87  theRequireSeedHitsInRebuild = conf.getParameter<bool>("requireSeedHitsInRebuild");
88  theMinNrOfHitsForRebuild = max(0,conf.getParameter<int>("minNrOfHitsForRebuild"));
89 
90  /* ======= B.M. to be ported layer ===========
91  bool setOK = thePropagator->setMaxDirectionChange(1.6);
92  if (!setOK)
93  cout << "GroupedCkfTrajectoryBuilder WARNING: "
94  << "propagator does not support setMaxDirectionChange"
95  << endl;
96  // addStopCondition(theMinPtStopCondition);
97 
98  theConfigurableCondition = createAlgo<TrajectoryFilter>(componentConfig("StopCondition"));
99  ===================================== */
100 
101 }
102 
103 
105 {
106  theMeasurementTracker->update(event);
107 }
108 
111 {
113  ret.reserve(10);
114  buildTrajectories(seed, ret, 0);
115  return ret;
116 }
117 
120  const TrackingRegion& region) const
121 {
123  ret.reserve(10);
124  RegionalTrajectoryFilter regionalCondition(region);
125  buildTrajectories(seed, ret, &regionalCondition);
126  return ret;
127 }
128 
129 void
131 {
132  buildTrajectories(seed,ret,0);
133 }
134 
135 void
138  const TrackingRegion& region) const
139 {
140  RegionalTrajectoryFilter regionalCondition(region);
141  buildTrajectories(seed,ret,&regionalCondition);
142 }
143 
144 void
146  TrajectoryContainer& result) const {
147  TempTrajectory startingTraj = createStartingTrajectory( seed);
149 
150  TrajectoryContainer final;
151 
152  work.reserve(result.size());
153  for (TrajectoryContainer::iterator traj=result.begin();
154  traj!=result.end(); ++traj) {
155  if(traj->isValid()) work.push_back(TempTrajectory(*traj));
156  }
157 
158  rebuildSeedingRegion(startingTraj,work);
159  final.reserve(work.size());
160 
161  for (TempTrajectoryContainer::iterator traj=work.begin();
162  traj!=work.end(); ++traj) {
163  final.push_back(traj->toTrajectory());
164  }
165 
166  result.swap(final);
167 
168 }
169 
170 void
173  const TrajectoryFilter* regionalCondition) const
174 {
175  //
176  // Build trajectory outwards from seed
177  //
178 
179  analyseSeed( seed);
180 
181  TempTrajectory startingTraj = createStartingTrajectory( seed);
182 
183  work_.clear();
184  const bool inOut = true;
185  groupedLimitedCandidates( startingTraj, regionalCondition, theForwardPropagator, inOut, work_);
186  if ( work_.empty() ) return ;
187 
188 
189 
190  /* rebuilding is de-coupled from standard building
191  //
192  // try to additional hits in the seeding region
193  //
194  if ( theMinNrOfHitsForRebuild>0 ) {
195  // reverse direction
196  //thePropagator->setPropagationDirection(oppositeDirection(seed.direction()));
197  // rebuild part of the trajectory
198  rebuildSeedingRegion(startingTraj,work);
199  }
200 
201  */
202 
203  result.reserve(work_.size());
204  for (TempTrajectoryContainer::const_iterator it = work_.begin(), ed = work_.end(); it != ed; ++it) {
205  result.push_back( it->toTrajectory() );
206  }
207 
208  work_.clear();
209  if (work_.capacity() > work_MaxSize_) { TempTrajectoryContainer().swap(work_); work_.reserve(work_MaxSize_/2); }
210 
211  analyseResult(result);
212 
213  LogDebug("CkfPattern")<< "GroupedCkfTrajectoryBuilder: returning result of size " << result.size();
214 
215 }
216 
217 
218 void
220  const TrajectoryFilter* regionalCondition,
221  const Propagator* propagator,
222  bool inOut,
224 {
225  unsigned int nIter=1;
226  TempTrajectoryContainer candidates;
227  TempTrajectoryContainer newCand;
228  candidates.push_back( startingTraj);
229 
230  while ( !candidates.empty()) {
231 
232  newCand.clear();
233  for (TempTrajectoryContainer::iterator traj=candidates.begin();
234  traj!=candidates.end(); traj++) {
235  if ( !advanceOneLayer(*traj, regionalCondition, propagator, inOut, newCand, result) ) {
236  LogDebug("CkfPattern")<< "GCTB: terminating after advanceOneLayer==false";
237  continue;
238  }
239 
240  LogDebug("CkfPattern")<<"newCand(1): after advanced one layer:\n"<<PrintoutHelper::dumpCandidates(newCand);
241 
242  if ((int)newCand.size() > theMaxCand) {
243  //ShowCand()(newCand);
244 
245  sort( newCand.begin(), newCand.end(), GroupedTrajCandLess(theLostHitPenalty,theFoundHitBonus));
246  newCand.erase( newCand.begin()+theMaxCand, newCand.end());
247  }
248  LogDebug("CkfPattern")<<"newCand(2): after removing extra candidates.\n"<<PrintoutHelper::dumpCandidates(newCand);
249  }
250 
251  LogDebug("CkfPattern") << "newCand.size() at end = " << newCand.size();
252 /*
253  if (theIntermediateCleaning) {
254  candidates.clear();
255  candidates = groupedIntermediaryClean(newCand);
256  } else {
257  candidates.swap(newCand);
258  }
259 */
261 #ifdef STANDARD_INTERMEDIARYCLEAN
263 #else
264  groupedIntermediaryClean(newCand);
265 #endif
266 
267  }
268  candidates.swap(newCand);
269 
270  LogDebug("CkfPattern") <<"candidates(3): "<<result.size()<<" candidates after "<<nIter++<<" groupedCKF iteration: \n"
272  <<"\n "<<candidates.size()<<" running candidates are: \n"
273  <<PrintoutHelper::dumpCandidates(candidates);
274  }
275 }
276 
277 std::string whatIsTheNextStep(TempTrajectory& traj , std::pair<TrajectoryStateOnSurface,std::vector<const DetLayer*> >& stateAndLayers){
278  std::stringstream buffer;
279  vector<const DetLayer*> & nl = stateAndLayers.second;
282  //B.M. TkLayerName layerName;
283  //B.M. buffer << "Started from " << layerName(traj.lastLayer())
284  const BarrelDetLayer* sbdl = dynamic_cast<const BarrelDetLayer*>(traj.lastLayer());
285  const ForwardDetLayer* sfdl = dynamic_cast<const ForwardDetLayer*>(traj.lastLayer());
286  if (sbdl) {
287  buffer << "Started from " << traj.lastLayer() << " r=" << sbdl->specificSurface().radius()
288  << " phi=" << sbdl->specificSurface().phi() << endl;
289  } else if (sfdl) {
290  buffer << "Started from " << traj.lastLayer() << " z " << sfdl->specificSurface().position().z()
291  << " phi " << sfdl->specificSurface().phi() << endl;
292  }
293  buffer << "Trying to go to";
294  for ( vector<const DetLayer*>::iterator il=nl.begin();
295  il!=nl.end(); il++){
296  //B.M. buffer << " " << layerName(*il) << " " << *il << endl;
297  const BarrelDetLayer* bdl = dynamic_cast<const BarrelDetLayer*>(*il);
298  const ForwardDetLayer* fdl = dynamic_cast<const ForwardDetLayer*>(*il);
299 
300  if (bdl) buffer << " r " << bdl->specificSurface().radius() << endl;
301  if (fdl) buffer << " z " << fdl->specificSurface().position().z() << endl;
302  //buffer << " " << *il << endl;
303  }
304  return buffer.str();
305 }
306 
308  std::stringstream buffer;
309  buffer << "GCTB: starting from "
310  << " r / phi / z = " << stateToUse.globalPosition().perp()
311  << " / " << stateToUse.globalPosition().phi()
312  << " / " << stateToUse.globalPosition().z()
313  << " , pt / phi / pz /charge = "
314  << stateToUse.globalMomentum().perp() << " / "
315  << stateToUse.globalMomentum().phi() << " / "
316  << stateToUse.globalMomentum().z() << " / "
317  << stateToUse.charge()
318  << " for layer at "<< l << endl;
319  buffer << " errors:";
320  for ( int i=0; i<5; i++ ) buffer << " " << sqrt(stateToUse.curvilinearError().matrix()(i,i));
321  buffer << endl;
322 
323  //buffer << "GCTB: starting from r / phi / z = " << initial.globalPosition().perp()
324  //<< " / " << initial.globalPosition().phi()
325  //<< " / " << initial.globalPosition().z() << " , pt / pz = "
326  //<< initial.globalMomentum().perp() << " / "
327  //<< initial.globalMomentum().z() << " for layer at "
328  //<< l << endl;
329  //buffer << " errors:";
330  //for ( int i=0; i<5; i++ ) buffer << " " << sqrt(initial.curvilinearError().matrix()(i,i));
331  //buffer << endl;
332  return buffer.str();
333 }
334 
335 
336 bool
338  const TrajectoryFilter* regionalCondition,
339  const Propagator* propagator,
340  bool inOut,
341  TempTrajectoryContainer& newCand,
343 {
344  std::pair<TSOS,std::vector<const DetLayer*> > stateAndLayers = findStateAndLayers(traj);
345  vector<const DetLayer*>::iterator layerBegin = stateAndLayers.second.begin();
346  vector<const DetLayer*>::iterator layerEnd = stateAndLayers.second.end();
347 
348  // if (nl.empty()) {
349  // addToResult(traj,result,inOut);
350  // return false;
351  // }
352 
353  LogDebug("CkfPattern")<<whatIsTheNextStep(traj, stateAndLayers);
354 
355  bool foundSegments(false);
356  bool foundNewCandidates(false);
357  for ( vector<const DetLayer*>::iterator il=layerBegin;
358  il!=layerEnd; il++) {
359 
360  TSOS stateToUse = stateAndLayers.first;
361  if ((*il)==traj.lastLayer())
362  {
363  LogDebug("CkfPattern")<<" self propagating in advanceOneLayer.\n from: \n"<<stateToUse;
364  //self navigation case
365  // go to a middle point first
367  GlobalPoint center(0,0,0);
368  stateToUse = middle.extrapolate(stateToUse, center, *theForwardPropagator);
369 
370  if (!stateToUse.isValid()) continue;
371  LogDebug("CkfPattern")<<"to: "<<stateToUse;
372  }
373 
376  **il,*propagator,
379 
380  LogDebug("CkfPattern")<<whatIsTheStateToUse(stateAndLayers.first,stateToUse,*il);
381 
382  TempTrajectoryContainer segments=
383  layerBuilder.segments(stateToUse);
384 
385  LogDebug("CkfPattern")<< "GCTB: number of segments = " << segments.size();
386 
387  if ( !segments.empty() ) foundSegments = true;
388 
389  for ( TempTrajectoryContainer::const_iterator is=segments.begin();
390  is!=segments.end(); is++ ) {
391  //
392  // assume "invalid hit only" segment is last in list
393  //
394  const TempTrajectory::DataContainer & measurements = is->measurements();
395  if ( !theAlwaysUseInvalid && is!=segments.begin() && measurements.size()==1 &&
396  (measurements.front().recHit()->getType() == TrackingRecHit::missing) ) break;
397  //
398  // create new candidate
399  //
400  TempTrajectory newTraj(traj);
401 
402  newTraj.push(*is);
403  //GIO// for ( vector<TM>::const_iterator im=measurements.begin();
404  //GIO// im!=measurements.end(); im++ ) newTraj.push(*im);
405  //if ( toBeContinued(newTraj,regionalCondition) ) { TOBE FIXED
406  if ( toBeContinued(newTraj, inOut) ) {
407  // Have added one more hit to track candidate
408 
409  LogDebug("CkfPattern")<<"GCTB: adding updated trajectory to candidates: inOut="<<inOut<<" hits="<<newTraj.foundHits();
410 
411  newCand.push_back(newTraj);
412  foundNewCandidates = true;
413  }
414  else {
415  // Have finished building this track. Check if it passes cuts.
416 
417  LogDebug("CkfPattern")<< "GCTB: adding completed trajectory to results if passes cuts: inOut="<<inOut<<" hits="<<newTraj.foundHits();
418 
419  addToResult(newTraj, result, inOut);
420  }
421  }
422  }
423 
424  if ( !foundSegments ){
425  LogDebug("CkfPattern")<< "GCTB: adding input trajectory to result";
426  addToResult(traj, result, inOut);
427  }
428  return foundNewCandidates;
429 }
430 
431 //TempTrajectoryContainer
432 void
434 {
435  //if (theTrajectories.empty()) return TrajectoryContainer();
436  //TrajectoryContainer result;
437  if (theTrajectories.empty()) return;
438  //RecHitEqualByChannels recHitEqualByChannels(false, false);
439  int firstLayerSize, secondLayerSize;
440  vector<const DetLayer*> firstLayers, secondLayers;
441 
442  for (TempTrajectoryContainer::iterator firstTraj=theTrajectories.begin();
443  firstTraj!=(theTrajectories.end()-1); firstTraj++) {
444 
445  if ( (!firstTraj->isValid()) ||
446  (!firstTraj->lastMeasurement().recHit()->isValid()) ) continue;
447  const TempTrajectory::DataContainer & firstMeasurements = firstTraj->measurements();
448  layers(firstMeasurements, firstLayers);
449  firstLayerSize = firstLayers.size();
450  if ( firstLayerSize<4 ) continue;
451 
452  for (TempTrajectoryContainer::iterator secondTraj=(firstTraj+1);
453  secondTraj!=theTrajectories.end(); secondTraj++) {
454 
455  if ( (!secondTraj->isValid()) ||
456  (!secondTraj->lastMeasurement().recHit()->isValid()) ) continue;
457  const TempTrajectory::DataContainer & secondMeasurements = secondTraj->measurements();
458  layers(secondMeasurements, secondLayers);
459  secondLayerSize = secondLayers.size();
460  //
461  // only candidates using the same last 3 layers are compared
462  //
463  if ( firstLayerSize!=secondLayerSize ) continue;
464  if ( firstLayers[0]!=secondLayers[0] ||
465  firstLayers[1]!=secondLayers[1] ||
466  firstLayers[2]!=secondLayers[2] ) continue;
467 
468  TempTrajectory::DataContainer::const_iterator im1 = firstMeasurements.rbegin();
469  TempTrajectory::DataContainer::const_iterator im2 = secondMeasurements.rbegin();
470  //
471  // check for identical hits in the last layer
472  //
473  bool unequal(false);
474  const DetLayer* layerPtr = firstLayers[0];
475  while ( im1!=firstMeasurements.rend()&&im2!=secondMeasurements.rend() ) {
476  if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr ) break;
477  if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
479  !im1->recHit()->hit()->sharesInput(im2->recHit()->hit(), TrackingRecHit::some) ) {
480  unequal = true;
481  break;
482  }
483  --im1;
484  --im2;
485  }
486  if ( im1==firstMeasurements.rend() || im2==secondMeasurements.rend() ||
487  im1->layer()==layerPtr || im2->layer()==layerPtr || unequal ) continue;
488  //
489  // check for invalid hits in the layer -2
490  // compare only candidates with invalid / valid combination
491  //
492  layerPtr = firstLayers[1];
493  bool firstValid(true);
494  while ( im1!=firstMeasurements.rend()&&im1->layer()==layerPtr ) {
495  if ( !im1->recHit()->isValid() ) firstValid = false;
496  --im1;
497  }
498  bool secondValid(true);
499  while ( im2!=secondMeasurements.rend()&&im2->layer()==layerPtr ) {
500  if ( !im2->recHit()->isValid() ) secondValid = false;
501  --im2;
502  }
503  if ( !tkxor(firstValid,secondValid) ) continue;
504  //
505  // ask for identical hits in layer -3
506  //
507  unequal = false;
508  layerPtr = firstLayers[2];
509  while ( im1!=firstMeasurements.rend()&&im2!=secondMeasurements.rend() ) {
510  if ( im1->layer()!=layerPtr || im2->layer()!=layerPtr ) break;
511  if ( !(im1->recHit()->isValid()) || !(im2->recHit()->isValid()) ||
513  !im1->recHit()->hit()->sharesInput(im2->recHit()->hit(), TrackingRecHit::some) ) {
514  unequal = true;
515  break;
516  }
517  --im1;
518  --im2;
519  }
520  if ( im1==firstMeasurements.rend() || im2==secondMeasurements.rend() ||
521  im1->layer()==layerPtr || im2->layer()==layerPtr || unequal ) continue;
522 
523  if ( !firstValid ) {
524  firstTraj->invalidate();
525  break;
526  }
527  else {
528  secondTraj->invalidate();
529  break;
530  }
531  }
532  }
533 /*
534  for (TempTrajectoryContainer::const_iterator it = theTrajectories.begin();
535  it != theTrajectories.end(); it++) {
536  if(it->isValid()) result.push_back( *it);
537  }
538 
539  return result;
540 */
541  theTrajectories.erase(std::remove_if( theTrajectories.begin(),theTrajectories.end(),
542  std::not1(std::mem_fun_ref(&TempTrajectory::isValid))),
543  // boost::bind(&TempTrajectory::isValid,_1)),
544  theTrajectories.end());
545 }
546 
547 void
549  vector<const DetLayer*> &result) const
550 {
551  result.clear();
552 
553  if ( measurements.empty() ) return ;
554 
555  result.push_back(measurements.back().layer());
557  --ifirst;
559  im!=measurements.rend(); --im ) {
560  if ( im->layer()!=result.back() ) result.push_back(im->layer());
561  }
562 
563  for (vector<const DetLayer*>::const_iterator iter = result.begin(); iter != result.end(); iter++){
564  if (!*iter) edm::LogWarning("CkfPattern")<< "Warning: null det layer!! ";
565  }
566 }
567 
568 void
571 {
572  //
573  // Rebuilding of trajectories. Candidates are taken from result,
574  // which will be replaced with the solutions after rebuild
575  // (assume vector::swap is more efficient than building new container)
576  //
577  LogDebug("CkfPattern")<< "Starting to rebuild " << result.size() << " tracks";
578  //
579  // Fitter (need to create it here since the propagation direction
580  // might change between different starting trajectories)
581  //
583  //
584  TempTrajectoryContainer reFitted;
585  TrajectorySeed::range rseedHits = startingTraj.seed().recHits();
586  std::vector<const TrackingRecHit*> seedHits;
587  //seedHits.insert(seedHits.end(), rseedHits.first, rseedHits.second);
588  //for (TrajectorySeed::recHitContainer::const_iterator iter = rseedHits.first; iter != rseedHits.second; iter++){
589  // seedHits.push_back(&*iter);
590  //}
591 
592  //unsigned int nSeed(seedHits.size());
593  unsigned int nSeed(rseedHits.second-rseedHits.first);
594  //seedHits.reserve(nSeed);
595  TempTrajectoryContainer rebuiltTrajectories;
596  for ( TempTrajectoryContainer::iterator it=result.begin();
597  it!=result.end(); it++ ) {
598  //
599  // skip candidates which are not exceeding the seed size
600  // (e.g. because no Tracker layers outside seeding region)
601  //
602 
603  if ( it->measurements().size()<=startingTraj.measurements().size() ) {
604  rebuiltTrajectories.push_back(*it);
605  LogDebug("CkfPattern")<< "RebuildSeedingRegion skipped as in-out trajectory does not exceed seed size.";
606  continue;
607  }
608  //
609  // Refit - keep existing trajectory in case fit is not possible
610  // or fails
611  //
612  backwardFit(*it,nSeed,fitter,reFitted,seedHits);
613  if ( reFitted.size()!=1 ) {
614  rebuiltTrajectories.push_back(*it);
615  LogDebug("CkfPattern")<< "RebuildSeedingRegion skipped as backward fit failed";
616  // << "after reFitted.size() " << reFitted.size();
617  continue;
618  }
619  //LogDebug("CkfPattern")<<"after reFitted.size() " << reFitted.size();
620  //
621  // Rebuild seeding part. In case it fails: keep initial trajectory
622  // (better to drop it??)
623  //
624  int nRebuilt =
625  rebuildSeedingRegion (seedHits,reFitted.front(),rebuiltTrajectories);
626 
627  if ( nRebuilt==0 ) it->invalidate(); // won't use original in-out track
628 
629  if ( nRebuilt<=0 ) rebuiltTrajectories.push_back(*it);
630 
631  }
632  //
633  // Replace input trajectories with new ones
634  //
635  result.swap(rebuiltTrajectories);
636  result.erase(std::remove_if( result.begin(),result.end(),
637  std::not1(std::mem_fun_ref(&TempTrajectory::isValid))),
638  result.end());
639 }
640 
641 int
642 GroupedCkfTrajectoryBuilder::rebuildSeedingRegion(const std::vector<const TrackingRecHit*>& seedHits,
643  TempTrajectory& candidate,
645 {
646  //
647  // Starting from track found by in-out tracking phase, extrapolate it inwards through
648  // the seeding region if possible in towards smaller Tracker radii, searching for additional
649  // hits.
650  // The resulting trajectories are returned in result,
651  // the count is the return value.
652  //
653  TempTrajectoryContainer rebuiltTrajectories;
654 #ifdef DBG2_GCTB
655 /* const LayerFinderByDet layerFinder;
656  if ( !seedHits.empty() && seedHits.front().isValid() ) {
657  DetLayer* seedLayer = layerFinder(seedHits.front().det());
658  cout << "Seed hit at " << seedHits.front().globalPosition()
659  << " " << seedLayer << endl;
660  cout << "Started from "
661  << candidate.lastMeasurement().updatedState().globalPosition().perp() << " "
662  << candidate.lastMeasurement().updatedState().globalPosition().z() << endl;
663  pair<bool,TrajectoryStateOnSurface> layerComp(false,TrajectoryStateOnSurface());
664  if ( seedLayer ) layerComp =
665  seedLayer->compatible(candidate.lastMeasurement().updatedState(),
666  propagator(),estimator());
667  pair<bool,TrajectoryStateOnSurface> detComp =
668  seedHits.front().det().compatible(candidate.lastMeasurement().updatedState(),
669  propagator(),estimator());
670  cout << " layer compatibility = " << layerComp.first;
671  cout << " det compatibility = " << detComp.first;
672  if ( detComp.first ) {
673  cout << " estimate = "
674  << estimator().estimate(detComp.second,seedHits.front()).second ;
675  }
676  cout << endl;
677  }*/
678  cout << "Before backward building: #measurements = "
679  << candidate.measurements().size() ; //<< endl;;
680 #endif
681  //
682  // Use standard building with standard cuts. Maybe better to use different
683  // cuts from "forward" building (e.g. no check on nr. of invalid hits)?
684  //
685  const bool inOut = false;
686  groupedLimitedCandidates(candidate, (const TrajectoryFilter*)0, theBackwardPropagator, inOut, rebuiltTrajectories);
687 
688  LogDebug("CkfPattern")<<" After backward building: "<<PrintoutHelper::dumpCandidates(rebuiltTrajectories);
689 
690  //
691  // Check & count resulting candidates
692  //
693  int nrOfTrajectories(0);
694  bool orig_ok = false;
695  //const RecHitEqualByChannels recHitEqual(false,false);
696  //vector<TM> oldMeasurements(candidate.measurements());
697  for ( TempTrajectoryContainer::iterator it=rebuiltTrajectories.begin();
698  it!=rebuiltTrajectories.end(); it++ ) {
699 
700  TempTrajectory::DataContainer newMeasurements(it->measurements());
701  //
702  // Verify presence of seeding hits?
703  //
705  orig_ok = true;
706  // no hits found (and possibly some invalid hits discarded): drop track
707  if ( newMeasurements.size()<=candidate.measurements().size() ){
708  LogDebug("CkfPattern") << "newMeasurements.size()<=candidate.measurements().size()";
709  continue;
710  }
711  // verify presence of hits
712  //GIO//if ( !verifyHits(newMeasurements.begin()+candidate.measurements().size(),
713  //GIO// newMeasurements.end(),seedHits) ){
714  if ( !verifyHits(newMeasurements.rbegin(),
715  newMeasurements.size() - candidate.measurements().size(),
716  seedHits) ){
717  LogDebug("CkfPattern")<< "seed hits not found in rebuild";
718  continue;
719  }
720  }
721  //
722  // construct final trajectory in the right order
723  //
724  TempTrajectory reversedTrajectory(it->seed(),it->seed().direction());
725  for (TempTrajectory::DataContainer::const_iterator im=newMeasurements.rbegin(), ed = newMeasurements.rend();
726  im != ed; --im ) {
727  reversedTrajectory.push(*im);
728  }
729  // save & count result
730  result.push_back(reversedTrajectory);
731  nrOfTrajectories++;
732 
733  LogDebug("CkgPattern")<<"New traj direction = " << reversedTrajectory.direction()<<"\n"
734  <<PrintoutHelper::dumpMeasurements(reversedTrajectory.measurements());
735  }
736  // If nrOfTrajectories = 0 and orig_ok = true, this means that a track was actually found on the
737  // out-in step (meeting those requirements) but did not have the seed hits in it.
738  // In this case when we return we will go ahead and use the original in-out track.
739 
740  // If nrOfTrajectories = 0 and orig_ok = false, this means that the out-in step failed to
741  // find any track. Two cases are a technical failure in fitting the original seed hits or
742  // because the track did not meet the out-in criteria (which may be stronger than the out-in
743  // criteria). In this case we will NOT allow the original in-out track to be used.
744 
745  if ( (nrOfTrajectories == 0) && orig_ok ) {
746  nrOfTrajectories = -1;
747  }
748  return nrOfTrajectories;
749 }
750 
751 void
753  const TrajectoryFitter& fitter,
754  TempTrajectoryContainer& fittedTracks,
755  std::vector<const TrackingRecHit*>& remainingHits) const
756 {
757  //
758  // clear array of non-fitted hits
759  //
760  remainingHits.clear();
761  fittedTracks.clear();
762  //
763  // skip candidates which are not exceeding the seed size
764  // (e.g. Because no Tracker layers exist outside seeding region)
765  //
766  if ( candidate.measurements().size()<=nSeed ) {
767  fittedTracks.clear();
768  return;
769  }
770 
771  LogDebug("CkfPattern")<<"nSeed " << nSeed << endl
772  << "Old traj direction = " << candidate.direction() << endl
774 
775  //
776  // backward fit trajectory.
777  // (Will try to fit only hits outside the seeding region. However,
778  // if there are not enough of these, it will also use the seeding hits).
779  //
780  TempTrajectory::DataContainer oldMeasurements(candidate.measurements());
781 // int nOld(oldMeasurements.size());
782 // const unsigned int nHitAllMin(5);
783 // const unsigned int nHit2dMin(2);
784  unsigned int nHit(0); // number of valid hits after seeding region
785  //unsigned int nHit2d(0); // number of valid hits after seeding region with 2D info
786  // use all hits except the first n (from seed), but require minimum
787  // specified in configuration.
788  // Swapped over next two lines.
789  unsigned int nHitMin = max(candidate.foundHits()-nSeed,theMinNrOfHitsForRebuild);
790  // unsigned int nHitMin = oldMeasurements.size()-nSeed;
791  // we want to rebuild only if the number of VALID measurements excluding the seed measurements is higher than the cut
792  if (nHitMin<theMinNrOfHitsForRebuild){
793  fittedTracks.clear();
794  return;
795  }
796 
797  LogDebug("CkfPattern")/* << "nHitMin " << nHitMin*/ <<"Sizes: " << oldMeasurements.size() << " / ";
798  //
799  // create input trajectory for backward fit
800  //
801  Trajectory fwdTraj(candidate.seed(),oppositeDirection(candidate.direction()));
802  //const TrajectorySeed seed = TrajectorySeed(PTrajectoryStateOnDet(), TrajectorySeed::recHitContainer(), oppositeDirection(candidate.direction()));
803  //Trajectory fwdTraj(seed, oppositeDirection(candidate.direction()));
804  std::vector<const DetLayer*> bwdDetLayer;
805  for ( TempTrajectory::DataContainer::const_iterator im=oldMeasurements.rbegin();
806  im!=oldMeasurements.rend(); --im) {
807  const TrackingRecHit* hit = im->recHit()->hit();
808  //
809  // add hits until required number is reached
810  //
811  if ( nHit<nHitMin ){//|| nHit2d<theMinNrOf2dHitsForRebuild ) {
812  fwdTraj.push(*im);
813  bwdDetLayer.push_back(im->layer());
814  //
815  // count valid / 2D hits
816  //
817  if ( hit->isValid() ) {
818  nHit++;
819  //if ( hit.isMatched() ||
820  // hit.det().detUnits().front()->type().module()==pixel )
821  //nHit2d++;
822  }
823  }
824  //if (nHit==nHitMin) lastBwdDetLayer=im->layer();
825  //
826  // keep remaining (valid) hits for verification
827  //
828  else if ( hit->isValid() ) {
829  //std::cout << "Adding a remaining hit" << std::endl;
830  remainingHits.push_back(hit);
831  }
832  }
833  //
834  // Fit only if required number of valid hits can be used
835  //
836  if ( nHit<nHitMin ){ //|| nHit2d<theMinNrOf2dHitsForRebuild ) {
837  fittedTracks.clear();
838  return;
839  }
840  //
841  // Do the backward fit (important: start from scaled, not random cov. matrix!)
842  //
844  //cout << "firstTsos "<< firstTsos << endl;
845  firstTsos.rescaleError(10.);
846  //TrajectoryContainer bwdFitted(fitter.fit(fwdTraj.seed(),fwdTraj.recHits(),firstTsos));
847  TrajectoryContainer bwdFitted(fitter.fit(
849  fwdTraj.recHits(),firstTsos));
850  if (bwdFitted.size()){
851  LogDebug("CkfPattern")<<"Obtained " << bwdFitted.size() << " bwdFitted trajectories with measurement size " << bwdFitted.front().measurements().size();
852  TempTrajectory fitted(fwdTraj.seed(), fwdTraj.direction());
853  vector<TM> tmsbf = bwdFitted.front().measurements();
854  int iDetLayer=0;
855  //this is ugly but the TM in the fitted track do not contain the DetLayer.
856  //So we have to cache the detLayer pointers and replug them in.
857  //For the backward building it would be enaugh to cache the last DetLayer,
858  //but for the intermediary cleaning we need all
859  for ( vector<TM>::const_iterator im=tmsbf.begin();im!=tmsbf.end(); im++ ) {
860  fitted.push(TM( (*im).forwardPredictedState(),
861  (*im).backwardPredictedState(),
862  (*im).updatedState(),
863  (*im).recHit(),
864  (*im).estimate(),
865  bwdDetLayer[iDetLayer]));
866 
867  LogDebug("CkfPattern")<<PrintoutHelper::dumpMeasurement(*im);
868  iDetLayer++;
869  }
870 /*
871  TM lastMeas = bwdFitted.front().lastMeasurement();
872  fitted.pop();
873  fitted.push(TM(lastMeas.forwardPredictedState(),
874  lastMeas.backwardPredictedState(),
875  lastMeas.updatedState(),
876  lastMeas.recHit(),
877  lastMeas.estimate(),
878  lastBwdDetLayer));*/
879  fittedTracks.push_back(fitted);
880  }
881  //
882  // save result
883  //
884  //fittedTracks.swap(bwdFitted);
885  //cout << "Obtained " << fittedTracks.size() << " fittedTracks trajectories with measurement size " << fittedTracks.front().measurements().size() << endl;
886 }
887 
888 bool
890  size_t maxDepth,
891  const std::vector<const TrackingRecHit*>& hits) const
892 {
893  //
894  // verify presence of the seeding hits
895  //
896  LogDebug("CkfPattern")<<"Checking for " << hits.size() << " hits in "
897  << maxDepth << " measurements" << endl;
898 
900  while (maxDepth > 0) { --maxDepth; --rend; }
901  for ( vector<const TrackingRecHit*>::const_iterator ir=hits.begin();
902  ir!=hits.end(); ir++ ) {
903  // assume that all seeding hits are valid!
904  bool foundHit(false);
905  for ( TempTrajectory::DataContainer::const_iterator im=rbegin; im!=rend; --im ) {
906  if ( im->recHit()->isValid() && (*ir)->sharesInput(im->recHit()->hit(), TrackingRecHit::some) ) {
907  foundHit = true;
908  break;
909  }
910  }
911  if ( !foundHit ) return false;
912  }
913  return true;
914 }
915 
916 
917 
918 
#define LogDebug(id)
T getParameter(std::string const &) const
const TrajectorySeed & seed() const
Access to the seed used to reconstruct the Trajectory.
const_iterator rend() const
Definition: bqueue.h:142
int i
Definition: DBlmapReader.cc:9
virtual void setEvent(const edm::Event &event) const
set Event for the internal MeasurementTracker data member
static std::string dumpCandidates(collection &candidates)
T perp() const
Definition: PV3DBase.h:66
const Propagator * theBackwardPropagator
TrajectorySeed const & seed() const
Access to the seed used to reconstruct the Trajectory.
Definition: Trajectory.h:231
bool empty() const
Definition: bqueue.h:144
static void clean(TempTrajectoryContainer &tracks)
TrajectoryContainer trajectories(const TrajectorySeed &) const
trajectories building starting from a seed
const CurvilinearTrajectoryError & curvilinearError() const
void addToResult(TempTrajectory &traj, TrajectoryContainer &result, bool inOut=false) const
PropagationDirection oppositeDirection(PropagationDirection dir) const
change of propagation direction
const DataContainer & measurements() const
GroupedCkfTrajectoryBuilder(const edm::ParameterSet &conf, const TrajectoryStateUpdator *updator, const Propagator *propagatorAlong, const Propagator *propagatorOpposite, const Chi2MeasurementEstimatorBase *estimator, const TransientTrackingRecHitBuilder *RecHitBuilder, const MeasurementTracker *measurementTracker, const TrajectoryFilter *filter, const TrajectoryFilter *inOutFilter)
constructor from ParameterSet
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
const TrajectoryStateUpdator * theUpdator
virtual void analyseSeed(const TrajectorySeed &seed) const
GlobalPoint globalPosition() const
ConstRecHitPointer recHit() const
int foundHits() const
obsolete name, use measurements() instead.
TempTrajectoryContainer segments(const TSOS startingState)
new segments within layer
std::string whatIsTheNextStep(TempTrajectory &traj, std::pair< TrajectoryStateOnSurface, std::vector< const DetLayer * > > &stateAndLayers)
static std::string dumpMeasurement(const TrajectoryMeasurement &tm)
static std::string dumpMeasurements(const std::vector< TrajectoryMeasurement > &v)
ConstRecHitContainer recHits(bool splitting=false) const
Definition: Trajectory.cc:67
PropagationDirection const & direction() const
Definition: Trajectory.cc:195
const LayerMeasurements * theLayerMeasurements
PropagationDirection direction() const
virtual void analyseResult(const TrajectoryContainer &result) const
void groupedLimitedCandidates(TempTrajectory &startingTraj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &result) const
Scalar radius() const
Radius of the cylinder.
Definition: Cylinder.h:55
const T & max(const T &a, const T &b)
bool verifyHits(TempTrajectory::DataContainer::const_iterator rbegin, size_t maxDepth, const std::vector< const TrackingRecHit * > &hits) const
Verifies presence of a RecHits in a range of TrajectoryMeasurements.
T sqrt(T t)
Definition: SSEVec.h:28
T z() const
Definition: PV3DBase.h:58
void groupedIntermediaryClean(TempTrajectoryContainer &theTrajectories) const
intermediate cleaning in the case of grouped measurements
tuple result
Definition: query.py:137
virtual const BoundDisk & specificSurface() const
void backwardFit(TempTrajectory &candidate, unsigned int nSeed, const TrajectoryFitter &fitter, TempTrajectoryContainer &fittedTracks, std::vector< const TrackingRecHit * > &remainingHits) const
const Chi2MeasurementEstimatorBase & estimator() const
std::string whatIsTheStateToUse(TrajectoryStateOnSurface &initial, TrajectoryStateOnSurface &stateToUse, const DetLayer *l)
std::pair< const_iterator, const_iterator > range
void rebuildSeedingRegion(const TrajectorySeed &, TrajectoryContainer &result) const
const DetLayer * layer() const
void buildTrajectories(const TrajectorySeed &, TrajectoryContainer &ret, const TrajectoryFilter *) const
common part of both public trajectory building methods
bool advanceOneLayer(TempTrajectory &traj, const TrajectoryFilter *regionalCondition, const Propagator *propagator, bool inOut, TempTrajectoryContainer &newCand, TempTrajectoryContainer &result) const
TrajectoryStateOnSurface updatedState() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
tuple conf
Definition: dbtoconf.py:185
bool isValid() const
const MeasurementTracker * theMeasurementTracker
TrajectoryMeasurement const & firstMeasurement() const
Definition: Trajectory.h:160
tuple filter
USE THIS FOR SKIMMED TRACKS process.p = cms.Path(process.hltLevel1GTSeed*process.skimming*process.offlineBeamSpot*process.TrackRefitter2) OTHERWISE USE THIS.
Definition: align_tpl.py:86
std::vector< TempTrajectory > TempTrajectoryContainer
iterator rbegin()
Definition: bqueue.h:140
range recHits() const
bool isValid() const
virtual const BoundCylinder & specificSurface() const
Extension of the interface.
const TrajectoryStateUpdator & updator() const
TrajectoryStateOnSurface extrapolate(const FreeTrajectoryState &fts, const GlobalPoint &vtx) const
extrapolation with default (=geometrical) propagator
virtual std::vector< Trajectory > fit(const Trajectory &) const =0
const AlgebraicSymMatrix55 & matrix() const
GlobalVector globalMomentum() const
bool toBeContinued(TempTrajectory &traj, bool inOut=false) const
bool tkxor(bool a, bool b) const
StateAndLayers findStateAndLayers(const TempTrajectory &traj) const
tuple cout
Definition: gather_cfg.py:41
size_type size() const
Definition: bqueue.h:143
const DetLayer * lastLayer() const
Redundant method, returns the layer of lastMeasurement() .
const PositionType & position() const
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
std::vector< Trajectory > TrajectoryContainer
void layers(const TempTrajectory::DataContainer &measurements, std::vector< const DetLayer * > &fillme) const
const Chi2MeasurementEstimatorBase * theEstimator
TempTrajectory createStartingTrajectory(const TrajectorySeed &seed) const
void push(const TrajectoryMeasurement &tm)
const Propagator * theForwardPropagator