CMS 3D CMS Logo

List of all members | Public Member Functions | Static 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)
 

Static Public Member Functions

static void fillPSetDescription (edm::ParameterSetDescription &desc)
 

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
 
edm::InputTag const clustersToSkipTag_
 
bool doSeedingRegionRebuilding
 
edm::EDGetTokenT< Phase2OTClusterMaskmaskPhase2OTs_
 
edm::EDGetTokenT< PixelClusterMaskmaskPixels_
 
edm::EDGetTokenT< StripClusterMaskmaskStrips_
 
unsigned int maxSeedsBeforeCleaning_
 
edm::InputTag const phase2ClustersToSkipTag_
 
bool produceSeedStopReasons_
 
bool reverseTrajectories
 
bool const skipClusters_
 
bool const skipPhase2Clusters_
 
std::unique_ptr< TransientInitialStateEstimatortheInitialState
 
unsigned int theMaxNSeeds
 
edm::EDGetTokenT< MeasurementTrackerEventtheMTELabel
 
const NavigationSchooltheNavigationSchool
 
edm::ESGetToken< NavigationSchool, NavigationSchoolRecordtheNavigationSchoolToken
 
edm::ESGetToken< Propagator, TrackingComponentsRecordthePropagatorToken
 
std::unique_ptr< RedundantSeedCleanertheSeedCleaner
 
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
 
bool theTrackCandidateOutput
 
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecordtheTrackerToken
 
std::unique_ptr< BaseCkfTrajectoryBuildertheTrajectoryBuilder
 
const TrajectoryCleanertheTrajectoryCleaner
 
edm::ESGetToken< TrajectoryCleaner, TrajectoryCleaner::RecordtheTrajectoryCleanerToken
 
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 37 of file CkfTrackCandidateMakerBase.h.

Member Typedef Documentation

◆ Phase2OTClusterMask

Definition at line 88 of file CkfTrackCandidateMakerBase.h.

◆ PixelClusterMask

Definition at line 86 of file CkfTrackCandidateMakerBase.h.

◆ StripClusterMask

Definition at line 87 of file CkfTrackCandidateMakerBase.h.

Constructor & Destructor Documentation

◆ CkfTrackCandidateMakerBase()

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

Definition at line 60 of file CkfTrackCandidateMakerBase.cc.

References cms::cuda::assert(), clustersToSkipTag_, gather_cfg::cout, Exception, edm::ParameterSet::getParameter(), maskPhase2OTs_, maskPixels_, maskStrips_, maxSeedsBeforeCleaning_, HLT_2024v13_cff::numHitsForSeedCleaner, phase2ClustersToSkipTag_, skipClusters_, skipPhase2Clusters_, AlCaHLTBitMon_QueryRunRegistry::string, theSeedCleaner, theSeedLabel, theTrackCandidateOutput, and theTrackerToken.

62  theTrajectoryOutput(false),
63  useSplitting(conf.getParameter<bool>("useHitsSplitting")),
64  doSeedingRegionRebuilding(conf.getParameter<bool>("doSeedingRegionRebuilding")),
65  cleanTrajectoryAfterInOut(conf.getParameter<bool>("cleanTrajectoryAfterInOut")),
66  reverseTrajectories(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"))),
79 #ifdef VI_REPRODUCIBLE
81 #else
82  maxSeedsBeforeCleaning_(conf.getParameter<unsigned int>("maxSeedsBeforeCleaning")),
83 #endif
84  theMTELabel(iC.consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("MeasurementTrackerEvent"))),
85  clustersToSkipTag_(conf.getParameter<edm::InputTag>("clustersToSkip")),
87  phase2ClustersToSkipTag_(conf.getParameter<edm::InputTag>("phase2clustersToSkip")),
90 
91  if (skipClusters_) {
94  }
95  //FIXME:: just temporary solution for phase2!
96  if (skipPhase2Clusters_) {
99  }
100 #ifndef VI_REPRODUCIBLE
101  std::string cleaner = conf.getParameter<std::string>("RedundantSeedCleaner");
102  if (cleaner == "CachingSeedCleanerBySharedInput") {
103  int numHitsForSeedCleaner = conf.getParameter<int>("numHitsForSeedCleaner");
104  bool onlyPixelHits = conf.getParameter<bool>("onlyPixelHitsForSeedCleaner");
105  theSeedCleaner = std::make_unique<CachingSeedCleanerBySharedInput>(numHitsForSeedCleaner, onlyPixelHits);
106  } else if (cleaner != "none") {
107  throw cms::Exception("RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none",
108  cleaner);
109  }
110 #endif
111 
112 #ifdef EDM_ML_DEBUG
115  }
116 #endif
117 
118 #ifdef VI_REPRODUCIBLE
119  std::cout << "CkfTrackCandidateMaker in reproducible setting" << std::endl;
120  assert(nullptr == theSeedCleaner);
122 #endif
123  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::EDGetTokenT< StripClusterMask > maskStrips_
std::unique_ptr< TransientInitialStateEstimator > theInitialState
std::string const & label() const
Definition: InputTag.h:36
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
edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorToken
edm::ContainerMask< edmNew::DetSetVector< SiStripCluster > > StripClusterMask
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavigationSchoolToken

◆ ~CkfTrackCandidateMakerBase()

cms::CkfTrackCandidateMakerBase::~CkfTrackCandidateMakerBase ( )
virtualnoexcept

Definition at line 126 of file CkfTrackCandidateMakerBase.cc.

126 {}

Member Function Documentation

◆ beginRunBase()

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

Definition at line 128 of file CkfTrackCandidateMakerBase.cc.

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

128  { /* no op*/
129  }

◆ countSeedsDebugger()

virtual void cms::CkfTrackCandidateMakerBase::countSeedsDebugger ( )
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 98 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

98 { ; }

◆ deleteAssocDebugger()

virtual void cms::CkfTrackCandidateMakerBase::deleteAssocDebugger ( )
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 99 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

99 { ; }

◆ fillPSetDescription()

void cms::CkfTrackCandidateMakerBase::fillPSetDescription ( edm::ParameterSetDescription desc)
static

Definition at line 540 of file CkfTrackCandidateMakerBase.cc.

References edm::ParameterSetDescription::add(), edm::ParameterSetDescription::addNode(), submitPVResolutionJobs::desc, ProducerED_cfi::InputTag, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by cms::CkfTrackCandidateMaker::fillDescriptions(), and cms::CkfTrajectoryMaker::fillDescriptions().

540  {
541  desc.add<bool>("cleanTrajectoryAfterInOut", true);
542  desc.add<bool>("doSeedingRegionRebuilding", true);
543  desc.add<bool>("onlyPixelHitsForSeedCleaner", false);
544  desc.add<bool>("reverseTrajectories", false);
545  desc.add<bool>("useHitsSplitting", true);
546  desc.add<edm::InputTag>("MeasurementTrackerEvent", edm::InputTag("MeasurementTrackerEvent"));
547  desc.add<edm::InputTag>("src", edm::InputTag("globalMixedSeeds"));
548 
549  desc.add<edm::InputTag>("clustersToSkip", edm::InputTag(""));
550  desc.add<edm::InputTag>("phase2clustersToSkip", edm::InputTag(""));
551 
554  desc.add<edm::ParameterSetDescription>("TrajectoryBuilderPSet", psdTB);
555 
557  psd1.add<std::string>("propagatorAlongTISE", "PropagatorWithMaterial");
558  psd1.add<std::string>("propagatorOppositeTISE", "PropagatorWithMaterialOpposite");
559  psd1.add<int>("numberMeasurementsForFit", 4);
560  desc.add<edm::ParameterSetDescription>("TransientInitialStateEstimatorParameters", psd1);
561 
562  desc.add<int>("numHitsForSeedCleaner", 4);
563  desc.add<std::string>("NavigationSchool", "SimpleNavigationSchool");
564  desc.add<std::string>("RedundantSeedCleaner", "CachingSeedCleanerBySharedInput");
565  desc.add<std::string>("TrajectoryCleaner", "TrajectoryCleanerBySharedHits");
566  desc.add<unsigned int>("maxNSeeds", 500000);
567  desc.add<unsigned int>("maxSeedsBeforeCleaning", 0);
568  }
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
ParameterDescriptionBase * add(U const &iLabel, T const &value)

◆ lastSeed()

virtual TrajectorySeedCollection::const_iterator cms::CkfTrackCandidateMakerBase::lastSeed ( TrajectorySeedCollection const &  theSeedColl)
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 94 of file CkfTrackCandidateMakerBase.h.

94  {
95  return theSeedColl.end();
96  }

◆ printHitsDebugger()

virtual void cms::CkfTrackCandidateMakerBase::printHitsDebugger ( edm::Event e)
inlineprotectedvirtual

Reimplemented in cms::CkfDebugTrackCandidateMaker.

Definition at line 97 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

97 { ; }

◆ produceBase()

void cms::CkfTrackCandidateMakerBase::produceBase ( edm::Event e,
const edm::EventSetup es 
)
virtual

Definition at line 140 of file CkfTrackCandidateMakerBase.cc.

References a, alongMomentum, cms::cuda::assert(), b, TrajectoryCleaner::clean(), cleanTrajectoryAfterInOut, countSeedsDebugger(), data, deleteAssocDebugger(), doSeedingRegionRebuilding, PrintoutHelper::dumpCandidates(), MillePedeFileConverter_cfg::e, runEdmFileComparison::failed, FINAL_CLEAN, Trajectory::foundHits(), edm::EventSetup::getData(), hfClusterShapes_cfi::hits, mps_fire::i, cuy::ii, edm::isNotFinite(), TrajectoryStateOnSurface::isValid(), Trajectory::isValid(), ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it, dqmiolumiharvest::j, CommonMethods::lock(), LogDebug, LogTrace, maskPhase2OTs_, maskPixels_, maskStrips_, maxSeedsBeforeCleaning_, eostools::move(), mutex, NO_TRAJECTORY, NOT_STOPPED, oppositeToMomentum, trajectoryStateTransform::persistentState(), Trajectory::pop(), printHitsDebugger(), TrackCandidateProducer_cfi::propagator, FastTrackerRecHitMaskProducer_cfi::recHits, PrintoutHelper::regressionTest(), reverseTrajectories, SEED_CLEANING, SEED_REGION_REBUILD, HLT_2024v13_cff::seeds, setEventSetup(), Trajectory::setNLoops(), skipClusters_, skipPhase2Clusters_, SMOOTHING_FAILED, jetUpdater_cfi::sort, theInitialState, theMaxNSeeds, theMTELabel, thePropagatorToken, theSeedCleaner, theSeedLabel, theTrackCandidateOutput, theTrackerToken, theTrajectoryBuilder, theTrajectoryCleaner, theTrajectoryOutput, mitigatedMETSequence_cff::U, useSplitting, and heppy_batch::val.

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

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

◆ setEventSetup()

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::getData(), theNavigationSchool, theNavigationSchoolToken, theTrajectoryBuilder, theTrajectoryCleaner, and theTrajectoryCleanerToken.

Referenced by produceBase().

131  {
132  //services
134 
136  theTrajectoryBuilder->setNavigationSchool(theNavigationSchool);
137  }
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
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

◆ cleanTrajectoryAfterInOut

bool cms::CkfTrackCandidateMakerBase::cleanTrajectoryAfterInOut
protected

Definition at line 54 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ clustersToSkipTag_

edm::InputTag const cms::CkfTrackCandidateMakerBase::clustersToSkipTag_
protected

Definition at line 80 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase().

◆ doSeedingRegionRebuilding

bool cms::CkfTrackCandidateMakerBase::doSeedingRegionRebuilding
protected

Definition at line 53 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ maskPhase2OTs_

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

Definition at line 91 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ maskPixels_

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

Definition at line 89 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ maskStrips_

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

Definition at line 90 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ maxSeedsBeforeCleaning_

unsigned int cms::CkfTrackCandidateMakerBase::maxSeedsBeforeCleaning_
protected

Definition at line 75 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ phase2ClustersToSkipTag_

edm::InputTag const cms::CkfTrackCandidateMakerBase::phase2ClustersToSkipTag_
protected

Definition at line 83 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase().

◆ produceSeedStopReasons_

bool cms::CkfTrackCandidateMakerBase::produceSeedStopReasons_
protected

Definition at line 56 of file CkfTrackCandidateMakerBase.h.

◆ reverseTrajectories

bool cms::CkfTrackCandidateMakerBase::reverseTrajectories
protected

Definition at line 55 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ skipClusters_

bool const cms::CkfTrackCandidateMakerBase::skipClusters_
protected

Definition at line 81 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ skipPhase2Clusters_

bool const cms::CkfTrackCandidateMakerBase::skipPhase2Clusters_
protected

Definition at line 84 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ theInitialState

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

Definition at line 65 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ theMaxNSeeds

unsigned int cms::CkfTrackCandidateMakerBase::theMaxNSeeds
protected

Definition at line 58 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ theMTELabel

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

Definition at line 78 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ theNavigationSchool

const NavigationSchool* cms::CkfTrackCandidateMakerBase::theNavigationSchool
protected

Definition at line 68 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

◆ theNavigationSchoolToken

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

Definition at line 67 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

◆ thePropagatorToken

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

Definition at line 70 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ theSeedCleaner

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

Definition at line 73 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ theSeedLabel

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

Definition at line 77 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ theTrackCandidateOutput

bool cms::CkfTrackCandidateMakerBase::theTrackCandidateOutput
protected

Definition at line 50 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ theTrackerToken

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

Definition at line 71 of file CkfTrackCandidateMakerBase.h.

Referenced by CkfTrackCandidateMakerBase(), and produceBase().

◆ theTrajectoryBuilder

std::unique_ptr<BaseCkfTrajectoryBuilder> cms::CkfTrackCandidateMakerBase::theTrajectoryBuilder
protected

◆ theTrajectoryCleaner

const TrajectoryCleaner* cms::CkfTrackCandidateMakerBase::theTrajectoryCleaner
protected

Definition at line 63 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase(), and setEventSetup().

◆ theTrajectoryCleanerToken

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

Definition at line 62 of file CkfTrackCandidateMakerBase.h.

Referenced by setEventSetup().

◆ theTrajectoryOutput

bool cms::CkfTrackCandidateMakerBase::theTrajectoryOutput
protected

Definition at line 51 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().

◆ useSplitting

bool cms::CkfTrackCandidateMakerBase::useSplitting
protected

Definition at line 52 of file CkfTrackCandidateMakerBase.h.

Referenced by produceBase().