CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 () noexcept(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
< Phase2OTClusterMask
maskPhase2OTs_
 
edm::EDGetTokenT
< PixelClusterMask
maskPixels_
 
edm::EDGetTokenT
< StripClusterMask
maskStrips_
 
unsigned int maxSeedsBeforeCleaning_
 
bool phase2skipClusters_
 
bool produceSeedStopReasons_
 
bool reverseTrajectories
 
bool skipClusters_
 
std::unique_ptr
< TransientInitialStateEstimator
theInitialState
 
unsigned int theMaxNSeeds
 
edm::EDGetTokenT
< MeasurementTrackerEvent
theMTELabel
 
const NavigationSchooltheNavigationSchool
 
edm::ESGetToken
< NavigationSchool,
NavigationSchoolRecord
theNavigationSchoolToken
 
edm::ESGetToken< Propagator,
TrackingComponentsRecord
thePropagatorToken
 
std::unique_ptr
< RedundantSeedCleaner
theSeedCleaner
 
edm::EDGetTokenT< edm::View
< TrajectorySeed > > 
theSeedLabel
 
bool theTrackCandidateOutput
 
edm::ESGetToken
< TrackerGeometry,
TrackerDigiGeometryRecord
theTrackerToken
 
std::unique_ptr
< BaseCkfTrajectoryBuilder
theTrajectoryBuilder
 
const TrajectoryCleanertheTrajectoryCleaner
 
edm::ESGetToken
< TrajectoryCleaner,
TrajectoryCleaner::Record
theTrajectoryCleanerToken
 
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 80 of file CkfTrackCandidateMakerBase.h.

Definition at line 78 of file CkfTrackCandidateMakerBase.h.

Definition at line 79 of file CkfTrackCandidateMakerBase.h.

Constructor & Destructor Documentation

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

Definition at line 59 of file CkfTrackCandidateMakerBase.cc.

References cms::cuda::assert(), gather_cfg::cout, Exception, edm::ParameterSet::exists(), edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), maskPhase2OTs_, maskPixels_, maskStrips_, maxSeedsBeforeCleaning_, HLT_FULL_cff::numHitsForSeedCleaner, phase2skipClusters_, skipClusters_, AlCaHLTBitMon_QueryRunRegistry::string, theSeedCleaner, theSeedLabel, theTrackCandidateOutput, and theTrackerToken.

61  theTrajectoryOutput(false),
62  useSplitting(conf.getParameter<bool>("useHitsSplitting")),
63  doSeedingRegionRebuilding(conf.getParameter<bool>("doSeedingRegionRebuilding")),
64  cleanTrajectoryAfterInOut(conf.getParameter<bool>("cleanTrajectoryAfterInOut")),
65  reverseTrajectories(conf.existsAs<bool>("reverseTrajectories") &&
66  conf.getParameter<bool>("reverseTrajectories")),
67  theMaxNSeeds(conf.getParameter<unsigned int>("maxNSeeds")),
69  createBaseCkfTrajectoryBuilder(conf.getParameter<edm::ParameterSet>("TrajectoryBuilderPSet"), iC)),
71  iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("TrajectoryCleaner")))),
72  theTrajectoryCleaner(nullptr),
73  theInitialState(std::make_unique<TransientInitialStateEstimator>(
74  conf.getParameter<ParameterSet>("TransientInitialStateEstimatorParameters"), iC)),
76  iC.esConsumes(edm::ESInputTag("", conf.getParameter<std::string>("NavigationSchool")))),
77  theNavigationSchool(nullptr),
78  thePropagatorToken(iC.esConsumes(edm::ESInputTag("", "AnyDirectionAnalyticalPropagator"))),
80  theMTELabel(iC.consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
81  skipClusters_(false),
82  phase2skipClusters_(false) {
84 #ifndef VI_REPRODUCIBLE
85  if (conf.exists("maxSeedsBeforeCleaning"))
86  maxSeedsBeforeCleaning_ = conf.getParameter<unsigned int>("maxSeedsBeforeCleaning");
87 #endif
88  if (conf.existsAs<edm::InputTag>("clustersToSkip")) {
89  skipClusters_ = true;
90  maskPixels_ = iC.consumes<PixelClusterMask>(conf.getParameter<edm::InputTag>("clustersToSkip"));
91  maskStrips_ = iC.consumes<StripClusterMask>(conf.getParameter<edm::InputTag>("clustersToSkip"));
92  }
93  //FIXME:: just temporary solution for phase2!
94  if (conf.existsAs<edm::InputTag>("phase2clustersToSkip")) {
95  phase2skipClusters_ = true;
96  maskPixels_ = iC.consumes<PixelClusterMask>(conf.getParameter<edm::InputTag>("phase2clustersToSkip"));
97  maskPhase2OTs_ = iC.consumes<Phase2OTClusterMask>(conf.getParameter<edm::InputTag>("phase2clustersToSkip"));
98  }
99 #ifndef VI_REPRODUCIBLE
100  std::string cleaner = conf.getParameter<std::string>("RedundantSeedCleaner");
101  if (cleaner == "CachingSeedCleanerBySharedInput") {
103  conf.existsAs<int>("numHitsForSeedCleaner") ? conf.getParameter<int>("numHitsForSeedCleaner") : 4;
104  int onlyPixelHits = conf.existsAs<bool>("onlyPixelHitsForSeedCleaner")
105  ? conf.getParameter<bool>("onlyPixelHitsForSeedCleaner")
106  : false;
107  theSeedCleaner = std::make_unique<CachingSeedCleanerBySharedInput>(numHitsForSeedCleaner, onlyPixelHits);
108  } else if (cleaner != "none") {
109  throw cms::Exception("RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none",
110  cleaner);
111  }
112 #endif
113 
114 #ifdef EDM_ML_DEBUG
117  }
118 #endif
119 
120 #ifdef VI_REPRODUCIBLE
121  std::cout << "CkfTrackCandidateMaker in reproducible setting" << std::endl;
122  assert(nullptr == theSeedCleaner);
124 #endif
125  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
edm::EDGetTokenT< StripClusterMask > maskStrips_
std::unique_ptr< TransientInitialStateEstimator > theInitialState
bool exists(std::string const &parameterName) const
checks if a parameter exists
assert(be >=bs)
edm::ContainerMask< edmNew::DetSetVector< SiPixelCluster > > PixelClusterMask
std::unique_ptr< RedundantSeedCleaner > theSeedCleaner
edm::EDGetTokenT< PixelClusterMask > maskPixels_
edm::ESGetToken< TrajectoryCleaner, TrajectoryCleaner::Record > theTrajectoryCleanerToken
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerToken
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
edm::ContainerMask< edmNew::DetSetVector< Phase2TrackerCluster1D > > Phase2OTClusterMask
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
tuple numHitsForSeedCleaner
edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorToken
tuple MeasurementTrackerEvent
tuple cout
Definition: gather_cfg.py:144
edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > StripClusterMask
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavigationSchoolToken
cms::CkfTrackCandidateMakerBase::~CkfTrackCandidateMakerBase ( )
virtualnoexcept

Definition at line 128 of file CkfTrackCandidateMakerBase.cc.

128 {}

Member Function Documentation

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

Definition at line 130 of file CkfTrackCandidateMakerBase.cc.

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

130  { /* no op*/
131  }
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.

Referenced by produceBase().

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

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 86 of file CkfTrackCandidateMakerBase.h.

86  {
87  return theSeedColl.end();
88  }
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 142 of file CkfTrackCandidateMakerBase.cc.

References a, alongMomentum, cms::cuda::assert(), b, TrajectoryCleaner::clean(), cleanTrajectoryAfterInOut, countSeedsDebugger(), data, deleteAssocDebugger(), TrackingRecHit::det(), doSeedingRegionRebuilding, PrintoutHelper::dumpCandidates(), FINAL_CLEAN, Trajectory::foundHits(), edm::OwnVector< T, P >::front(), edm::Event::getByToken(), edm::EventSetup::getData(), mps_fire::i, cuy::ii, edm::isNotFinite(), TrajectoryStateOnSurface::isValid(), Trajectory::isValid(), dqmiolumiharvest::j, 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(), HLT_FULL_cff::propagator, edm::OwnVector< T, P >::push_back(), edm::Event::put(), TrackingRecHit::rawId(), HLT_FULL_cff::recHits, PrintoutHelper::regressionTest(), reverseTrajectories, SEED_CLEANING, SEED_REGION_REBUILD, Trajectory::seedRef(), DetachedQuadStep_cff::seeds, setEventSetup(), Trajectory::setNLoops(), edm::OwnVector< T, P >::size(), skipClusters_, SMOOTHING_FAILED, GeomDet::surface(), theInitialState, theMaxNSeeds, theMTELabel, thePropagatorToken, theSeedCleaner, theSeedLabel, theTrackCandidateOutput, theTrackerToken, theTrajectoryBuilder, theTrajectoryCleaner, theTrajectoryOutput, useSplitting, and hgcalPerformanceValidation::val.

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

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

Initialize EventSetup objects at each event.

Definition at line 133 of file CkfTrackCandidateMakerBase.cc.

References edm::EventSetup::getData(), theNavigationSchool, theNavigationSchoolToken, theTrajectoryBuilder, theTrajectoryCleaner, and theTrajectoryCleanerToken.

Referenced by produceBase().

133  {
134  //services
136 
138  theTrajectoryBuilder->setNavigationSchool(theNavigationSchool);
139  }
bool getData(T &iHolder) const
Definition: EventSetup.h:128
edm::ESGetToken< TrajectoryCleaner, TrajectoryCleaner::Record > theTrajectoryCleanerToken
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavigationSchoolToken

Member Data Documentation

bool cms::CkfTrackCandidateMakerBase::cleanTrajectoryAfterInOut
protected

Definition at line 50 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

bool cms::CkfTrackCandidateMakerBase::doSeedingRegionRebuilding
protected

Definition at line 49 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

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

Definition at line 83 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

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

Definition at line 81 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

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

Definition at line 82 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

unsigned int cms::CkfTrackCandidateMakerBase::maxSeedsBeforeCleaning_
protected

Definition at line 71 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

bool cms::CkfTrackCandidateMakerBase::phase2skipClusters_
protected

Definition at line 77 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

bool cms::CkfTrackCandidateMakerBase::produceSeedStopReasons_
protected

Definition at line 52 of file CkfTrackCandidateMakerBase.h.

bool cms::CkfTrackCandidateMakerBase::reverseTrajectories
protected

Definition at line 51 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

bool cms::CkfTrackCandidateMakerBase::skipClusters_
protected

Definition at line 76 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

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

Definition at line 61 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

unsigned int cms::CkfTrackCandidateMakerBase::theMaxNSeeds
protected

Definition at line 54 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

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

Definition at line 74 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

const NavigationSchool* cms::CkfTrackCandidateMakerBase::theNavigationSchool
protected

Definition at line 64 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

edm::ESGetToken<NavigationSchool, NavigationSchoolRecord> cms::CkfTrackCandidateMakerBase::theNavigationSchoolToken
protected

Definition at line 63 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

edm::ESGetToken<Propagator, TrackingComponentsRecord> cms::CkfTrackCandidateMakerBase::thePropagatorToken
protected

Definition at line 66 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

std::unique_ptr<RedundantSeedCleaner> cms::CkfTrackCandidateMakerBase::theSeedCleaner
protected

Definition at line 69 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

edm::EDGetTokenT<edm::View<TrajectorySeed> > cms::CkfTrackCandidateMakerBase::theSeedLabel
protected

Definition at line 73 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

bool cms::CkfTrackCandidateMakerBase::theTrackCandidateOutput
protected

Definition at line 46 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> cms::CkfTrackCandidateMakerBase::theTrackerToken
protected

Definition at line 67 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

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

Definition at line 59 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase(), and setEventSetup().

edm::ESGetToken<TrajectoryCleaner, TrajectoryCleaner::Record> cms::CkfTrackCandidateMakerBase::theTrajectoryCleanerToken
protected

Definition at line 58 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

bool cms::CkfTrackCandidateMakerBase::theTrajectoryOutput
protected

Definition at line 47 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

bool cms::CkfTrackCandidateMakerBase::useSplitting
protected

Definition at line 48 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().