CMS 3D CMS Logo

List of all members | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions
cms::CkfTrackCandidateMakerBase Class Reference

#include <CkfTrackCandidateMakerBase.h>

Inheritance diagram for cms::CkfTrackCandidateMakerBase:
cms::CkfDebugTrackCandidateMaker cms::CkfTrackCandidateMaker cms::CkfTrajectoryMaker

Public Member Functions

virtual void beginRunBase (edm::Run const &, edm::EventSetup const &es)
 
 CkfTrackCandidateMakerBase (const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
 
virtual void produceBase (edm::Event &e, const edm::EventSetup &es)
 
virtual ~CkfTrackCandidateMakerBase ()(false)
 

Protected Types

typedef edm::ContainerMask< edmNew::DetSetVector< Phase2TrackerCluster1D > > Phase2OTClusterMask
 
typedef edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > PixelClusterMask
 
typedef edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > StripClusterMask
 

Protected Member Functions

virtual void countSeedsDebugger ()
 
virtual void deleteAssocDebugger ()
 
virtual TrajectorySeedCollection::const_iterator lastSeed (TrajectorySeedCollection const &theSeedColl)
 
virtual void printHitsDebugger (edm::Event &e)
 

Protected Attributes

bool cleanTrajectoryAfterInOut
 
bool doSeedingRegionRebuilding
 
edm::EDGetTokenT< Phase2OTClusterMaskmaskPhase2OTs_
 
edm::EDGetTokenT< PixelClusterMaskmaskPixels_
 
edm::EDGetTokenT< StripClusterMaskmaskStrips_
 
unsigned int maxSeedsBeforeCleaning_
 
bool phase2skipClusters_
 
bool produceSeedStopReasons_
 
bool reverseTrajectories
 
bool skipClusters_
 
edm::ESHandle< GeometricSearchTrackertheGeomSearchTracker
 
std::unique_ptr< TransientInitialStateEstimatortheInitialState
 
edm::ESHandle< MagneticFieldtheMagField
 
const std::string theMagFieldName
 
unsigned int theMaxNSeeds
 
edm::EDGetTokenT< MeasurementTrackerEventtheMTELabel
 
const NavigationSchooltheNavigationSchool
 
std::string theNavigationSchoolName
 
RedundantSeedCleanertheSeedCleaner
 
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
 
bool theTrackCandidateOutput
 
std::unique_ptr< BaseCkfTrajectoryBuildertheTrajectoryBuilder
 
const TrajectoryCleanertheTrajectoryCleaner
 
std::string theTrajectoryCleanerName
 
bool theTrajectoryOutput
 
bool useSplitting
 

Private Member Functions

void setEventSetup (const edm::EventSetup &es)
 Initialize EventSetup objects at each event. More...
 

Detailed Description

Definition at line 35 of file CkfTrackCandidateMakerBase.h.

Member Typedef Documentation

Definition at line 82 of file CkfTrackCandidateMakerBase.h.

Definition at line 80 of file CkfTrackCandidateMakerBase.h.

Definition at line 81 of file CkfTrackCandidateMakerBase.h.

Constructor & Destructor Documentation

cms::CkfTrackCandidateMakerBase::CkfTrackCandidateMakerBase ( const edm::ParameterSet conf,
edm::ConsumesCollector &&  iC 
)
explicit

Definition at line 60 of file CkfTrackCandidateMakerBase.cc.

References gather_cfg::cout, Exception, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), maskPhase2OTs_, maskPixels_, maskStrips_, maxSeedsBeforeCleaning_, hiDetachedQuadStep_cff::numHitsForSeedCleaner, phase2skipClusters_, skipClusters_, AlCaHLTBitMon_QueryRunRegistry::string, theSeedCleaner, and theSeedLabel.

60  :
62  theTrajectoryOutput(false),
63  useSplitting(conf.getParameter<bool>("useHitsSplitting")),
64  doSeedingRegionRebuilding(conf.getParameter<bool>("doSeedingRegionRebuilding")),
65  cleanTrajectoryAfterInOut(conf.getParameter<bool>("cleanTrajectoryAfterInOut")),
66  reverseTrajectories(conf.existsAs<bool>("reverseTrajectories") && conf.getParameter<bool>("reverseTrajectories")),
67  theMaxNSeeds(conf.getParameter<unsigned int>("maxNSeeds")),
68  theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<edm::ParameterSet>("TrajectoryBuilderPSet"), iC)),
69  theTrajectoryCleanerName(conf.getParameter<std::string>("TrajectoryCleaner")),
70  theTrajectoryCleaner(nullptr),
71  theInitialState(new TransientInitialStateEstimator(conf.getParameter<ParameterSet>("TransientInitialStateEstimatorParameters"))),
72  theMagFieldName(conf.exists("SimpleMagneticField") ? conf.getParameter<std::string>("SimpleMagneticField") : ""),
73  theNavigationSchoolName(conf.getParameter<std::string>("NavigationSchool")),
74  theNavigationSchool(nullptr),
75  theSeedCleaner(nullptr),
77  theMTELabel(iC.consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
78  skipClusters_(false),
79  phase2skipClusters_(false)
80  {
82 #ifndef VI_REPRODUCIBLE
83  if ( conf.exists("maxSeedsBeforeCleaning") )
84  maxSeedsBeforeCleaning_=conf.getParameter<unsigned int>("maxSeedsBeforeCleaning");
85 #endif
86  if (conf.existsAs<edm::InputTag>("clustersToSkip")) {
87  skipClusters_ = true;
88  maskPixels_ = iC.consumes<PixelClusterMask>(conf.getParameter<edm::InputTag>("clustersToSkip"));
89  maskStrips_ = iC.consumes<StripClusterMask>(conf.getParameter<edm::InputTag>("clustersToSkip"));
90  }
91  //FIXME:: just temporary solution for phase2!
92  if (conf.existsAs<edm::InputTag>("phase2clustersToSkip")) {
93  phase2skipClusters_ = true;
94  maskPixels_ = iC.consumes<PixelClusterMask>(conf.getParameter<edm::InputTag>("phase2clustersToSkip"));
95  maskPhase2OTs_ = iC.consumes<Phase2OTClusterMask>(conf.getParameter<edm::InputTag>("phase2clustersToSkip"));
96  }
97 #ifndef VI_REPRODUCIBLE
98  std::string cleaner = conf.getParameter<std::string>("RedundantSeedCleaner");
99  if (cleaner == "CachingSeedCleanerBySharedInput") {
100  int numHitsForSeedCleaner = conf.existsAs<int>("numHitsForSeedCleaner") ?
101  conf.getParameter<int>("numHitsForSeedCleaner") : 4;
102  int onlyPixelHits = conf.existsAs<bool>("onlyPixelHitsForSeedCleaner") ?
103  conf.getParameter<bool>("onlyPixelHitsForSeedCleaner") : false;
104  theSeedCleaner = new CachingSeedCleanerBySharedInput(numHitsForSeedCleaner,onlyPixelHits);
105  } else if (cleaner == "none") {
106  theSeedCleaner = nullptr;
107  } else {
108  throw cms::Exception("RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none", cleaner);
109  }
110 #endif
111 
112 #ifdef VI_REPRODUCIBLE
113  std::cout << "CkfTrackCandidateMaker in reproducible setting" << std::endl;
114  assert(nullptr==theSeedCleaner);
115  assert(0>=maxSeedsBeforeCleaning_);
116 #endif
117 
118  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:185
edm::EDGetTokenT< StripClusterMask > maskStrips_
std::unique_ptr< TransientInitialStateEstimator > theInitialState
bool exists(std::string const &parameterName) const
checks if a parameter exists
edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > PixelClusterMask
edm::EDGetTokenT< PixelClusterMask > maskPixels_
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
edm::ContainerMask< edmNew::DetSetVector< Phase2TrackerCluster1D > > Phase2OTClusterMask
numHitsForSeedCleaner
these two parameters are relevant only for the CachingSeedCleanerBySharedInput
edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > StripClusterMask
cms::CkfTrackCandidateMakerBase::~CkfTrackCandidateMakerBase ( )
virtual

Definition at line 122 of file CkfTrackCandidateMakerBase.cc.

References theSeedCleaner.

122  {
123  if (theSeedCleaner) delete theSeedCleaner;
124  }

Member Function Documentation

void cms::CkfTrackCandidateMakerBase::beginRunBase ( edm::Run const &  r,
edm::EventSetup const &  es 
)
virtual

Definition at line 126 of file CkfTrackCandidateMakerBase.cc.

Referenced by cms::CkfDebugTrackCandidateMaker::beginRun().

127  {
128  /* no op*/
129  }
virtual void cms::CkfTrackCandidateMakerBase::countSeedsDebugger ( )
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 90 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

90 {;}
virtual void cms::CkfTrackCandidateMakerBase::deleteAssocDebugger ( )
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 91 of file CkfTrackCandidateMakerBase.h.

References setEventSetup().

Referenced by produceBase().

91 {;}
virtual TrajectorySeedCollection::const_iterator cms::CkfTrackCandidateMakerBase::lastSeed ( TrajectorySeedCollection const &  theSeedColl)
inlineprotectedvirtual

Definition at line 88 of file CkfTrackCandidateMakerBase.h.

88 {return theSeedColl.end();}
virtual void cms::CkfTrackCandidateMakerBase::printHitsDebugger ( edm::Event e)
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 89 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

89 {;}
void cms::CkfTrackCandidateMakerBase::produceBase ( edm::Event e,
const edm::EventSetup es 
)
virtual

Definition at line 150 of file CkfTrackCandidateMakerBase.cc.

References a, RedundantSeedCleaner::add(), alongMomentum, b, TrajectoryCleaner::clean(), cleanTrajectoryAfterInOut, countSeedsDebugger(), data, deleteAssocDebugger(), TrackingRecHit::det(), RedundantSeedCleaner::done(), doSeedingRegionRebuilding, PrintoutHelper::dumpCandidates(), runEdmFileComparison::failed, FINAL_CLEAN, Trajectory::foundHits(), edm::OwnVector< T, P >::front(), edm::EventSetup::get(), edm::Event::getByToken(), RedundantSeedCleaner::good(), hfClusterShapes_cfi::hits, mps_fire::i, cuy::ii, RedundantSeedCleaner::init(), edm::isNotFinite(), TrajectoryStateOnSurface::isValid(), Trajectory::isValid(), edm::RefToBase< T >::key(), CommonMethods::lock(), LogDebug, LogTrace, maskPhase2OTs_, maskPixels_, maskStrips_, maxSeedsBeforeCleaning_, eostools::move(), mutex, NO_TRAJECTORY, NOT_STOPPED, oppositeToMomentum, convertSQLitetoXML_cfg::output, trajectoryStateTransform::persistentState(), phase2skipClusters_, Trajectory::pop(), printHitsDebugger(), Propagator::propagate(), Trajectory::push(), edm::OwnVector< T, P >::push_back(), edm::Event::put(), TrackingRecHit::rawId(), PrintoutHelper::regressionTest(), Trajectory::reserve(), reverseTrajectories, SurveyInfoScenario_cff::seed, SEED_CLEANING, SEED_REGION_REBUILD, Trajectory::seedRef(), setEventSetup(), Trajectory::setNLoops(), Trajectory::setSeedRef(), Trajectory::setStopReason(), edm::OwnVector< T, P >::size(), skipClusters_, SMOOTHING_FAILED, GeomDet::surface(), theInitialState, theMaxNSeeds, theMTELabel, theSeedCleaner, theSeedLabel, theTrackCandidateOutput, theTrajectoryBuilder, theTrajectoryCleaner, theTrajectoryOutput, trackingTruthProducer_cfi::tracker, mitigatedMETSequence_cff::U, useSplitting, and heppy_batch::val.

Referenced by cms::CkfDebugTrackCandidateMaker::produce().

151  {
152  // getting objects from the EventSetup
153  setEventSetup( es );
154 
155  // set the correct navigation
156  // NavigationSetter setter( *theNavigationSchool);
157 
158  // propagator
159  edm::ESHandle<Propagator> thePropagator;
160  es.get<TrackingComponentsRecord>().get("AnyDirectionAnalyticalPropagator",
161  thePropagator);
162 
163  // method for Debugging
165 
166  // Step A: set Event for the TrajectoryBuilder
168  e.getByToken(theMTELabel, data);
169 
170  std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
171  if (skipClusters_) {
173  e.getByToken(maskPixels_, pixelMask);
175  e.getByToken(maskStrips_, stripMask);
176  dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*data, *stripMask, *pixelMask);
177  //std::cout << "Trajectory builder " << conf_.getParameter<std::string>("@module_label") << " created with masks " << std::endl;
178  theTrajectoryBuilder->setEvent(e, es, &*dataWithMasks);
179  } else if (phase2skipClusters_) {
180  //FIXME:just temporary solution for phase2!
182  e.getByToken(maskPixels_, pixelMask);
184  e.getByToken(maskPhase2OTs_, phase2OTMask);
185  dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*data, *pixelMask, *phase2OTMask);
186  //std::cout << "Trajectory builder " << conf_.getParameter<std::string>("@module_label") << " created with phase2 masks " << std::endl;
187  theTrajectoryBuilder->setEvent(e, es, &*dataWithMasks);
188  } else {
189  //std::cout << "Trajectory builder " << conf_.getParameter<std::string>("@module_label") << " created without masks " << std::endl;
190  theTrajectoryBuilder->setEvent(e, es, &*data);
191  }
192  // TISE ES must be set here due to dependence on theTrajectoryBuilder
193  theInitialState->setEventSetup( es, static_cast<TkTransientTrackingRecHitBuilder const *>(theTrajectoryBuilder->hitBuilder())->cloner() );
194 
195  // Step B: Retrieve seeds
196 
198  e.getByToken(theSeedLabel, collseed);
199 
200  // Step C: Create empty output collection
201  auto output = std::make_unique<TrackCandidateCollection>();
202  auto outputT = std::make_unique<std::vector<Trajectory>>();
203  auto outputSeedStopInfos = std::make_unique<std::vector<SeedStopInfo> >(collseed->size());
204 
205  if ( (*collseed).size()>theMaxNSeeds ) {
206  LogError("TooManySeeds")<<"Exceeded maximum numeber of seeds! theMaxNSeeds="<<theMaxNSeeds<<" nSeed="<<(*collseed).size();
208  if (theTrajectoryOutput){e.put(std::move(outputT));}
209  e.put(std::move(outputSeedStopInfos));
210  return;
211  }
212 
213  // Step D: Invoke the building algorithm
214  if (!(*collseed).empty()){
215 
216  unsigned int lastCleanResult=0;
217  std::vector<Trajectory> rawResult;
218  rawResult.reserve(collseed->size() * 4);
219 
220  if (theSeedCleaner) theSeedCleaner->init( &rawResult );
221 
222  // method for debugging
224 
225  // the mutex
226  std::mutex theMutex;
227  using Lock = std::unique_lock<std::mutex>;
228 
229  // Loop over seeds
230  size_t collseed_size = collseed->size();
231 
232  unsigned int indeces[collseed_size]; for (auto i=0U; i< collseed_size; ++i) indeces[i]=i;
233 
234 
235 
236 
237 #ifdef VI_SORTSEED
238  // std::random_shuffle(indeces,indeces+collseed_size);
239 
240  // here only for reference: does not seems to help
241 
242  auto const & seeds = *collseed;
243 
244 
245  float val[collseed_size];
246  for (auto i=0U; i< collseed_size; ++i)
247  { val[i] = seeds[i].startingState().pt();};
248  // { val[i] = std::abs((*seeds[i].recHits().first).surface()->eta());}
249 
250  /*
251  unsigned long long val[collseed_size];
252  for (auto i=0U; i< collseed_size; ++i) {
253  if (seeds[i].nHits()<2) { val[i]=0; continue;}
254  auto h = seeds[i].recHits().first;
255  auto const & hit = static_cast<BaseTrackerRecHit const&>(*h);
256  val[i] = hit.firstClusterRef().key();
257  if (++h != seeds[i].recHits().second) {
258  auto const & hit = static_cast<BaseTrackerRecHit const&>(*h);
259  val[i] |= (unsigned long long)(hit.firstClusterRef().key())<<32;
260  }
261  }
262  */
263  std::sort(indeces,indeces+collseed_size, [&](unsigned int i, unsigned int j){return val[i]<val[j];});
264 
265 
266  // std::cout << spt(indeces[0]) << ' ' << spt(indeces[collseed_size-1]) << std::endl;
267 #endif
268 
269  std::atomic<unsigned int> ntseed(0);
270  auto theLoop = [&](size_t ii) {
271  auto j = indeces[ii];
272 
273  ntseed++;
274 
275  // to be moved inside a par section (how with tbb??)
276  std::vector<Trajectory> theTmpTrajectories;
277 
278 
279  LogDebug("CkfPattern") << "======== Begin to look for trajectories from seed " << j << " ========\n";
280 
281  { Lock lock(theMutex);
282  // Check if seed hits already used by another track
283  if (theSeedCleaner && !theSeedCleaner->good( &((*collseed)[j])) ) {
284  LogDebug("CkfTrackCandidateMakerBase")<<" Seed cleaning kills seed "<<j;
285  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::SEED_CLEANING);
286  return; // from the lambda!
287  }}
288 
289 
290  // Build trajectory from seed outwards
291  theTmpTrajectories.clear();
292  unsigned int nCandPerSeed = 0;
293  auto const & startTraj = theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories, nCandPerSeed, nullptr );
294  {
295  Lock lock(theMutex);
296  (*outputSeedStopInfos)[j].setCandidatesPerSeed(nCandPerSeed);
297  if(theTmpTrajectories.empty()) {
298  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::NO_TRAJECTORY);
299  return; // from the lambda!
300  }
301  }
302 
303  LogDebug("CkfPattern") << "======== In-out trajectory building found " << theTmpTrajectories.size()
304  << " trajectories from seed " << j << " ========\n"
305  <<PrintoutHelper::dumpCandidates(theTmpTrajectories);
306 
308 
309  // Select the best trajectory from this seed (declare others invalid)
310  theTrajectoryCleaner->clean(theTmpTrajectories);
311 
312  LogDebug("CkfPattern") << "======== In-out trajectory cleaning gave the following " << theTmpTrajectories.size()
313  << " valid trajectories from seed "
314  << j << " ========\n"
315  << PrintoutHelper::dumpCandidates(theTmpTrajectories);
316  }
317 
318  // Optionally continue building trajectory back through
319  // seed and if possible further inwards.
320 
322  theTrajectoryBuilder->rebuildTrajectories(startTraj,(*collseed)[j],theTmpTrajectories);
323 
324  LogDebug("CkfPattern") << "======== Out-in trajectory building found " << theTmpTrajectories.size()
325  << " valid/invalid trajectories from seed " << j << " ========\n"
326  <<PrintoutHelper::dumpCandidates(theTmpTrajectories);
327  if(theTmpTrajectories.empty()) {
328  Lock lock(theMutex);
329  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::SEED_REGION_REBUILD);
330  return;
331  }
332  }
333 
334 
335  // Select the best trajectory from this seed (after seed region rebuilding, can be more than one)
336  theTrajectoryCleaner->clean(theTmpTrajectories);
337 
338  LogDebug("CkfPattern") << "======== Trajectory cleaning gave the following " << theTmpTrajectories.size() << " valid trajectories from seed "
339  << j << " ========\n"
340  <<PrintoutHelper::dumpCandidates(theTmpTrajectories);
341 
342  { Lock lock(theMutex);
343  for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
344  it!=theTmpTrajectories.end(); it++){
345  if( it->isValid() ) {
346  it->setSeedRef(collseed->refAt(j));
347  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::NOT_STOPPED);
348  // Store trajectory
349  rawResult.push_back(std::move(*it));
350  // Tell seed cleaner which hits this trajectory used.
351  //TO BE FIXED: this cut should be configurable via cfi file
352  if (theSeedCleaner && rawResult.back().foundHits()>3) theSeedCleaner->add( &rawResult.back() );
353  //if (theSeedCleaner ) theSeedCleaner->add( & (*it) );
354  }
355  }}
356 
357  theTmpTrajectories.clear();
358 
359  LogDebug("CkfPattern") << "rawResult trajectories found so far = " << rawResult.size();
360 
361  { Lock lock(theMutex);
362  if ( maxSeedsBeforeCleaning_ >0 && rawResult.size() > maxSeedsBeforeCleaning_+lastCleanResult) {
363  theTrajectoryCleaner->clean(rawResult);
364  rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
365  std::not1(std::mem_fun_ref(&Trajectory::isValid))),
366  rawResult.end());
367  lastCleanResult=rawResult.size();
368  }
369  }
370 
371  };
372  // end of loop over seeds
373 
374 
375 #ifdef VI_TBB
376  tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
377 #else
378 #ifdef VI_OMP
379 #pragma omp parallel for schedule(dynamic,4)
380 #endif
381  for (size_t j = 0; j < collseed_size; j++){
382  theLoop(j);
383  }
384 #endif
385  assert(ntseed==collseed_size);
387 
388  // std::cout << "VICkfPattern " << "rawResult trajectories found = " << rawResult.size() << " in " << ntseed << " seeds " << collseed_size << std::endl;
389 
390 #ifdef VI_REPRODUCIBLE
391  // sort trajectory
392  std::sort(rawResult.begin(), rawResult.end(),[](const Trajectory & a, const Trajectory & b)
393  { return a.seedRef().key() < b.seedRef().key();});
394  //{ return a.chiSquared()*b.ndof() < b.chiSquared()*a.ndof();});
395 #endif
396 
397  // Step E: Clean the results to avoid duplicate tracks
398  // Rejected ones just flagged as invalid.
399  theTrajectoryCleaner->clean(rawResult);
400 
401  LogDebug("CkfPattern") << "======== Final cleaning of entire event found " << rawResult.size()
402  << " valid/invalid trajectories ======="<<endl
403  <<PrintoutHelper::dumpCandidates(rawResult);
404 
405  LogDebug("CkfPattern") << "removing invalid trajectories.";
406 
407  // Assuming here that theLoop() gives at most one Trajectory per seed
408  for(const auto& traj: rawResult) {
409  if(!traj.isValid()) {
410  const auto seedIndex = traj.seedRef().key();
411  if((*outputSeedStopInfos)[seedIndex].stopReason() == SeedStopReason::NOT_STOPPED) {
412  (*outputSeedStopInfos)[seedIndex].setStopReason(SeedStopReason::FINAL_CLEAN);
413  }
414  }
415  }
416 
417  vector<Trajectory> & unsmoothedResult(rawResult);
418  unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
419  std::not1(std::mem_fun_ref(&Trajectory::isValid))),
420  unsmoothedResult.end());
421  unsmoothedResult.shrink_to_fit();
422  // If requested, reverse the trajectories creating a new 1-hit seed on the last measurement of the track
423  if (reverseTrajectories) {
424  for (auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
425  // reverse the trajectory only if it has valid hit on the last measurement (should happen)
426  if (it->lastMeasurement().updatedState().isValid() &&
427  it->lastMeasurement().recHit().get() != nullptr &&
428  it->lastMeasurement().recHit()->isValid()) {
429  // I can't use reverse in place, because I want to change the seed
430  // 1) reverse propagation direction
431  PropagationDirection direction = it->direction();
432  if (direction == alongMomentum) direction = oppositeToMomentum;
433  else if (direction == oppositeToMomentum) direction = alongMomentum;
434  // 2) make a seed
435  TrajectoryStateOnSurface const & initState = it->lastMeasurement().updatedState();
436  auto initId = it->lastMeasurement().recHitR().rawId();
439  hits.push_back(it->lastMeasurement().recHit()->hit()->clone());
440  boost::shared_ptr<const TrajectorySeed> seed(new TrajectorySeed(state, std::move(hits), direction));
441  // 3) make a trajectory
442  Trajectory trajectory(seed, direction);
443  trajectory.setNLoops(it->nLoops());
444  trajectory.setSeedRef(it->seedRef());
445  trajectory.setStopReason(it->stopReason());
446  // 4) push states in reversed order
447  Trajectory::DataContainer &meas = it->measurements();
448  trajectory.reserve(meas.size());
449  for (auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
450  trajectory.push(std::move(*itmeas));
451  }
452  // replace
453  (*it)= std::move(trajectory);
454  } else {
455  edm::LogWarning("CkfPattern_InvalidLastMeasurement") << "Last measurement of the trajectory is invalid, cannot reverse it";
456  }
457  }
458  }
459 
460 
461  int viTotHits=0;
462 
464  // Step F: Convert to TrackCandidates
465  output->reserve(unsmoothedResult.size());
466  Traj2TrackHits t2t(theTrajectoryBuilder->hitBuilder(),true);
467 
468  for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
469  it != unsmoothedResult.end(); ++it) {
470 
471  LogDebug("CkfPattern") << "copying "<<(useSplitting?"splitted":"un-splitted")<<" hits from trajectory";
473  if(it->direction() != alongMomentum) LogDebug("CkfPattern") << "not along momentum... " << std::endl;
474  t2t(*it,recHits,useSplitting);
475 
476  viTotHits+=recHits.size();
477 
478 
479  LogDebug("CkfPattern") << "getting initial state.";
480  Trajectory trialTrajectory = (*it);
481  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
482  bool failed = false;
483 
484  do {
485  // Drop last hit if previous backFitter was not successful
486  if(failed) {
487  LogDebug("CkfPattern") << "removing last hit";
488  trialTrajectory.pop();
489  LogDebug("CkfPattern") << "hits remaining " << trialTrajectory.foundHits();
490  }
491 
492  // Get inner state
493  const bool doBackFit = (!doSeedingRegionRebuilding) & (!reverseTrajectories);
494  initState = theInitialState->innerState(trialTrajectory, doBackFit);
495 
496  // Check if that was successful
497  failed = (!initState.first.isValid()) || initState.second == nullptr || edm::isNotFinite(initState.first.globalPosition().x());
498  } while(failed && trialTrajectory.foundHits() > 3);
499 
500  if(failed) {
501  const auto seedIndex = it->seedRef().key();
502  (*outputSeedStopInfos)[seedIndex].setStopReason(SeedStopReason::SMOOTHING_FAILED);
503  continue;
504  }
505 
506 
507 
508  PTrajectoryStateOnDet state;
509  if(useSplitting && (initState.second != recHits.front().det()) && recHits.front().det() ){
510  LogDebug("CkfPattern") << "propagating to hit front in case of splitting.";
511  TrajectoryStateOnSurface && propagated = thePropagator->propagate(initState.first,recHits.front().det()->surface());
512  if (!propagated.isValid()) continue;
514  recHits.front().rawId());
515  }
516  else state = trajectoryStateTransform::persistentState( initState.first,
517  initState.second->geographicalId().rawId());
518  LogDebug("CkfPattern") << "pushing a TrackCandidate.";
519  output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
520  }
521  }//output trackcandidates
522 
524  es.get<TrackerDigiGeometryRecord>().get(tracker);
525  LogTrace("CkfPattern|TrackingRegressionTest") << "========== CkfTrackCandidateMaker Info =========="
526  << "number of Seed: " << collseed->size()<<'\n'
527  <<PrintoutHelper::regressionTest(*tracker,unsmoothedResult);
528 
529  assert(viTotHits>=0); // just to use it...
530  // std::cout << "VICkfPattern result " << output->size() << " " << viTotHits << std::endl;
531 
532  if (theTrajectoryOutput){ outputT->swap(unsmoothedResult);}
533 
534  }// end of ((*collseed).size()>0)
535 
536  // method for debugging
538 
539  // Step G: write output to file
541  if (theTrajectoryOutput){e.put(std::move(outputT));}
542  e.put(std::move(outputSeedStopInfos));
543  }
#define LogDebug(id)
static boost::mutex mutex
Definition: Proxy.cc:11
int foundHits() const
Definition: Trajectory.h:225
static std::string dumpCandidates(collection &candidates)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:137
virtual void clean(TempTrajectoryContainer &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:579
edm::EDGetTokenT< StripClusterMask > maskStrips_
std::unique_ptr< TransientInitialStateEstimator > theInitialState
size_type size() const
Definition: OwnVector.h:264
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
virtual void printHitsDebugger(edm::Event &e)
PropagationDirection
virtual void done()=0
Tells the cleaner that the seeds are finished, and so it can clear any cache it has.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:42
virtual void add(const Trajectory *traj)=0
Informs the cleaner that a new trajectory has been made, in case the cleaner keeps a local collection...
virtual bool good(const TrajectorySeed *seed)=0
Returns true if the seed is not overlapping with another trajectory.
static std::string regressionTest(const TrackerGeometry &tracker, std::vector< Trajectory > &unsmoothedResult)
void push_back(D *&d)
Definition: OwnVector.h:290
edm::EDGetTokenT< PixelClusterMask > maskPixels_
std::vector< TrajectoryMeasurement > DataContainer
Definition: Trajectory.h:44
bool isNotFinite(T x)
Definition: isFinite.h:10
const TrajectoryCleaner * theTrajectoryCleaner
const GeomDet * det() const
size_t key() const
Definition: RefToBase.h:250
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
edm::RefToBase< TrajectorySeed > seedRef(void) const
Definition: Trajectory.h:321
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
#define LogTrace(id)
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
ii
Definition: cuy.py:590
bool isValid() const
Definition: Trajectory.h:279
void pop()
Definition: Trajectory.cc:29
double b
Definition: hdecay.h:120
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
double a
Definition: hdecay.h:121
T get() const
Definition: EventSetup.h:62
virtual void init(const std::vector< Trajectory > *vect)=0
Provides the cleaner a pointer to the vector where trajectories are stored, in case it does not want ...
reference front()
Definition: OwnVector.h:423
def move(src, dest)
Definition: eostools.py:511
id_type rawId() const
void cms::CkfTrackCandidateMakerBase::setEventSetup ( const edm::EventSetup es)
private

Initialize EventSetup objects at each event.

Definition at line 131 of file CkfTrackCandidateMakerBase.cc.

References edm::EventSetup::get(), edm::ESHandle< T >::product(), theGeomSearchTracker, theMagField, theMagFieldName, theNavigationSchool, theNavigationSchoolName, theTrajectoryBuilder, theTrajectoryCleaner, and theTrajectoryCleanerName.

Referenced by deleteAssocDebugger(), and produceBase().

131  {
132 
133  //services
136  // edm::ESInputTag mfESInputTag(mfName);
137  // es.get<IdealMagneticFieldRecord>().get(mfESInputTag,theMagField );
138 
139  edm::ESHandle<TrajectoryCleaner> trajectoryCleanerH;
140  es.get<TrajectoryCleaner::Record>().get(theTrajectoryCleanerName, trajectoryCleanerH);
141  theTrajectoryCleaner= trajectoryCleanerH.product();
142 
143  edm::ESHandle<NavigationSchool> navigationSchoolH;
144  es.get<NavigationSchoolRecord>().get(theNavigationSchoolName, navigationSchoolH);
145  theNavigationSchool = navigationSchoolH.product();
146  theTrajectoryBuilder->setNavigationSchool(theNavigationSchool);
147  }
edm::ESHandle< GeometricSearchTracker > theGeomSearchTracker
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
T get() const
Definition: EventSetup.h:62
T const * product() const
Definition: ESHandle.h:86
edm::ESHandle< MagneticField > theMagField

Member Data Documentation

bool cms::CkfTrackCandidateMakerBase::cleanTrajectoryAfterInOut
protected

Definition at line 51 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

bool cms::CkfTrackCandidateMakerBase::doSeedingRegionRebuilding
protected

Definition at line 50 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

edm::EDGetTokenT<Phase2OTClusterMask> cms::CkfTrackCandidateMakerBase::maskPhase2OTs_
protected

Definition at line 85 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

edm::EDGetTokenT<PixelClusterMask> cms::CkfTrackCandidateMakerBase::maskPixels_
protected

Definition at line 83 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

edm::EDGetTokenT<StripClusterMask> cms::CkfTrackCandidateMakerBase::maskStrips_
protected

Definition at line 84 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

unsigned int cms::CkfTrackCandidateMakerBase::maxSeedsBeforeCleaning_
protected

Definition at line 73 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

bool cms::CkfTrackCandidateMakerBase::phase2skipClusters_
protected

Definition at line 79 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

bool cms::CkfTrackCandidateMakerBase::produceSeedStopReasons_
protected

Definition at line 53 of file CkfTrackCandidateMakerBase.h.

bool cms::CkfTrackCandidateMakerBase::reverseTrajectories
protected

Definition at line 52 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

bool cms::CkfTrackCandidateMakerBase::skipClusters_
protected

Definition at line 78 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

edm::ESHandle<GeometricSearchTracker> cms::CkfTrackCandidateMakerBase::theGeomSearchTracker
protected

Definition at line 66 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

std::unique_ptr<TransientInitialStateEstimator> cms::CkfTrackCandidateMakerBase::theInitialState
protected

Definition at line 62 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

edm::ESHandle<MagneticField> cms::CkfTrackCandidateMakerBase::theMagField
protected

Definition at line 65 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

const std::string cms::CkfTrackCandidateMakerBase::theMagFieldName
protected

Definition at line 64 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

unsigned int cms::CkfTrackCandidateMakerBase::theMaxNSeeds
protected

Definition at line 55 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

edm::EDGetTokenT<MeasurementTrackerEvent> cms::CkfTrackCandidateMakerBase::theMTELabel
protected

Definition at line 76 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

const NavigationSchool* cms::CkfTrackCandidateMakerBase::theNavigationSchool
protected

Definition at line 69 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

std::string cms::CkfTrackCandidateMakerBase::theNavigationSchoolName
protected

Definition at line 68 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

RedundantSeedCleaner* cms::CkfTrackCandidateMakerBase::theSeedCleaner
protected
edm::EDGetTokenT<edm::View<TrajectorySeed> > cms::CkfTrackCandidateMakerBase::theSeedLabel
protected

Definition at line 75 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

bool cms::CkfTrackCandidateMakerBase::theTrackCandidateOutput
protected

Definition at line 47 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

std::unique_ptr<BaseCkfTrajectoryBuilder> cms::CkfTrackCandidateMakerBase::theTrajectoryBuilder
protected
const TrajectoryCleaner* cms::CkfTrackCandidateMakerBase::theTrajectoryCleaner
protected

Definition at line 60 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase(), and setEventSetup().

std::string cms::CkfTrackCandidateMakerBase::theTrajectoryCleanerName
protected

Definition at line 59 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

bool cms::CkfTrackCandidateMakerBase::theTrajectoryOutput
protected

Definition at line 48 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

bool cms::CkfTrackCandidateMakerBase::useSplitting
protected

Definition at line 49 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().