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 63 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.

63  :
65  theTrajectoryOutput(false),
66  useSplitting(conf.getParameter<bool>("useHitsSplitting")),
67  doSeedingRegionRebuilding(conf.getParameter<bool>("doSeedingRegionRebuilding")),
68  cleanTrajectoryAfterInOut(conf.getParameter<bool>("cleanTrajectoryAfterInOut")),
69  reverseTrajectories(conf.existsAs<bool>("reverseTrajectories") && conf.getParameter<bool>("reverseTrajectories")),
71  theMaxNSeeds(conf.getParameter<unsigned int>("maxNSeeds")),
72  theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<edm::ParameterSet>("TrajectoryBuilderPSet"), iC)),
73  theTrajectoryCleanerName(conf.getParameter<std::string>("TrajectoryCleaner")),
75  theInitialState(new TransientInitialStateEstimator(conf.getParameter<ParameterSet>("TransientInitialStateEstimatorParameters"))),
76  theMagFieldName(conf.exists("SimpleMagneticField") ? conf.getParameter<std::string>("SimpleMagneticField") : ""),
77  theNavigationSchoolName(conf.getParameter<std::string>("NavigationSchool")),
79  theSeedCleaner(0),
81  theMTELabel(iC.consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
82  skipClusters_(false),
83  phase2skipClusters_(false)
84  {
86 #ifndef VI_REPRODUCIBLE
87  if ( conf.exists("maxSeedsBeforeCleaning") )
88  maxSeedsBeforeCleaning_=conf.getParameter<unsigned int>("maxSeedsBeforeCleaning");
89 #endif
90  if (conf.existsAs<edm::InputTag>("clustersToSkip")) {
91  skipClusters_ = true;
92  maskPixels_ = iC.consumes<PixelClusterMask>(conf.getParameter<edm::InputTag>("clustersToSkip"));
93  maskStrips_ = iC.consumes<StripClusterMask>(conf.getParameter<edm::InputTag>("clustersToSkip"));
94  }
95  //FIXME:: just temporary solution for phase2!
96  if (conf.existsAs<edm::InputTag>("phase2clustersToSkip")) {
97  phase2skipClusters_ = true;
98  maskPixels_ = iC.consumes<PixelClusterMask>(conf.getParameter<edm::InputTag>("phase2clustersToSkip"));
99  maskPhase2OTs_ = iC.consumes<Phase2OTClusterMask>(conf.getParameter<edm::InputTag>("phase2clustersToSkip"));
100  }
101 #ifndef VI_REPRODUCIBLE
102  std::string cleaner = conf.getParameter<std::string>("RedundantSeedCleaner");
103  if (cleaner == "SeedCleanerByHitPosition") {
105  } else if (cleaner == "SeedCleanerBySharedInput") {
107  } else if (cleaner == "CachingSeedCleanerByHitPosition") {
109  } else if (cleaner == "CachingSeedCleanerBySharedInput") {
110  int numHitsForSeedCleaner = conf.existsAs<int>("numHitsForSeedCleaner") ?
111  conf.getParameter<int>("numHitsForSeedCleaner") : 4;
112  int onlyPixelHits = conf.existsAs<bool>("onlyPixelHitsForSeedCleaner") ?
113  conf.getParameter<bool>("onlyPixelHitsForSeedCleaner") : false;
114  theSeedCleaner = new CachingSeedCleanerBySharedInput(numHitsForSeedCleaner,onlyPixelHits);
115  } else if (cleaner == "none") {
116  theSeedCleaner = 0;
117  } else {
118  throw cms::Exception("RedundantSeedCleaner not found", cleaner);
119  }
120 #endif
121 
122 #ifdef VI_REPRODUCIBLE
123  std::cout << "CkfTrackCandidateMaker in reproducible setting" << std::endl;
124  assert(nullptr==theSeedCleaner);
125  assert(0>=maxSeedsBeforeCleaning_);
126 #endif
127 
128  }
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:186
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 132 of file CkfTrackCandidateMakerBase.cc.

References theSeedCleaner.

132  {
133  if (theSeedCleaner) delete theSeedCleaner;
134  }

Member Function Documentation

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

Definition at line 136 of file CkfTrackCandidateMakerBase.cc.

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

137  {
138  /* no op*/
139  }
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 160 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, SeedStopReason::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, SeedStopReason::NO_TRAJECTORY, SeedStopReason::NOT_STOPPED, oppositeToMomentum, convertSQLitetoXML_cfg::output, trajectoryStateTransform::persistentState(), phase2skipClusters_, Trajectory::pop(), printHitsDebugger(), produceSeedStopReasons_, Propagator::propagate(), Trajectory::push(), edm::OwnVector< T, P >::push_back(), edm::Event::put(), TrackingRecHit::rawId(), PrintoutHelper::regressionTest(), Trajectory::reserve(), reverseTrajectories, SurveyInfoScenario_cff::seed, SeedStopReason::SEED_CLEANING, Trajectory::seedRef(), setEventSetup(), Trajectory::setNLoops(), Trajectory::setSeedRef(), Trajectory::setStopReason(), edm::OwnVector< T, P >::size(), skipClusters_, SeedStopReason::SMOOTHING_FAILED, GeomDet::surface(), theInitialState, theMaxNSeeds, theMTELabel, theSeedCleaner, theSeedLabel, theTrackCandidateOutput, theTrajectoryBuilder, theTrajectoryCleaner, theTrajectoryOutput, mixOne_simraw_on_sim_cfi::tracker, mitigatedMETSequence_cff::U, SeedStopReason::UNINITIALIZED, useSplitting, and heppy_batch::val.

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

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

Initialize EventSetup objects at each event.

Definition at line 141 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().

141  {
142 
143  //services
146  // edm::ESInputTag mfESInputTag(mfName);
147  // es.get<IdealMagneticFieldRecord>().get(mfESInputTag,theMagField );
148 
149  edm::ESHandle<TrajectoryCleaner> trajectoryCleanerH;
150  es.get<TrajectoryCleaner::Record>().get(theTrajectoryCleanerName, trajectoryCleanerH);
151  theTrajectoryCleaner= trajectoryCleanerH.product();
152 
153  edm::ESHandle<NavigationSchool> navigationSchoolH;
154  es.get<NavigationSchoolRecord>().get(theNavigationSchoolName, navigationSchoolH);
155  theNavigationSchool = navigationSchoolH.product();
156  theTrajectoryBuilder->setNavigationSchool(theNavigationSchool);
157  }
edm::ESHandle< GeometricSearchTracker > theGeomSearchTracker
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
const T & get() const
Definition: EventSetup.h:55
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.

Referenced by produceBase().

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().