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_2024v14_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*/ }

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

539  {
540  desc.add<bool>("cleanTrajectoryAfterInOut", true);
541  desc.add<bool>("doSeedingRegionRebuilding", true);
542  desc.add<bool>("onlyPixelHitsForSeedCleaner", false);
543  desc.add<bool>("reverseTrajectories", false);
544  desc.add<bool>("useHitsSplitting", true);
545  desc.add<edm::InputTag>("MeasurementTrackerEvent", edm::InputTag("MeasurementTrackerEvent"));
546  desc.add<edm::InputTag>("src", edm::InputTag("globalMixedSeeds"));
547 
548  desc.add<edm::InputTag>("clustersToSkip", edm::InputTag(""));
549  desc.add<edm::InputTag>("phase2clustersToSkip", edm::InputTag(""));
550 
553  desc.add<edm::ParameterSetDescription>("TrajectoryBuilderPSet", psdTB);
554 
556  psd1.add<std::string>("propagatorAlongTISE", "PropagatorWithMaterial");
557  psd1.add<std::string>("propagatorOppositeTISE", "PropagatorWithMaterialOpposite");
558  psd1.add<int>("numberMeasurementsForFit", 4);
559  desc.add<edm::ParameterSetDescription>("TransientInitialStateEstimatorParameters", psd1);
560 
561  desc.add<int>("numHitsForSeedCleaner", 4);
562  desc.add<std::string>("NavigationSchool", "SimpleNavigationSchool");
563  desc.add<std::string>("RedundantSeedCleaner", "CachingSeedCleanerBySharedInput");
564  desc.add<std::string>("TrajectoryCleaner", "TrajectoryCleanerBySharedHits");
565  desc.add<unsigned int>("maxNSeeds", 500000);
566  desc.add<unsigned int>("maxSeedsBeforeCleaning", 0);
567  }
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 139 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_2024v14_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().

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

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

Referenced by produceBase().

130  {
131  //services
133 
135  theTrajectoryBuilder->setNavigationSchool(theNavigationSchool);
136  }
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().