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_2022v15_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:303
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 541 of file CkfTrackCandidateMakerBase.cc.

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

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

541  {
542  desc.add<bool>("cleanTrajectoryAfterInOut", true);
543  desc.add<bool>("doSeedingRegionRebuilding", true);
544  desc.add<bool>("onlyPixelHitsForSeedCleaner", false);
545  desc.add<bool>("reverseTrajectories", false);
546  desc.add<bool>("useHitsSplitting", true);
547  desc.add<edm::InputTag>("MeasurementTrackerEvent", edm::InputTag("MeasurementTrackerEvent"));
548  desc.add<edm::InputTag>("src", edm::InputTag("globalMixedSeeds"));
549 
550  desc.add<edm::InputTag>("clustersToSkip", edm::InputTag(""));
551  desc.add<edm::InputTag>("phase2clustersToSkip", edm::InputTag(""));
552 
555  desc.add<edm::ParameterSetDescription>("TrajectoryBuilderPSet", psdTB);
556 
558  psd1.add<std::string>("propagatorAlongTISE", "PropagatorWithMaterial");
559  psd1.add<std::string>("propagatorOppositeTISE", "PropagatorWithMaterialOpposite");
560  psd1.add<int>("numberMeasurementsForFit", 4);
561  desc.add<edm::ParameterSetDescription>("TransientInitialStateEstimatorParameters", psd1);
562 
563  desc.add<int>("numHitsForSeedCleaner", 4);
564  desc.add<std::string>("NavigationSchool", "SimpleNavigationSchool");
565  desc.add<std::string>("RedundantSeedCleaner", "CachingSeedCleanerBySharedInput");
566  desc.add<std::string>("TrajectoryCleaner", "TrajectoryCleanerBySharedHits");
567  desc.add<unsigned int>("maxNSeeds", 500000);
568  desc.add<unsigned int>("maxSeedsBeforeCleaning", 0);
569  }
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(), dqmiolumiharvest::j, CommonMethods::lock(), LogDebug, LogTrace, maskPhase2OTs_, maskPixels_, maskStrips_, maxSeedsBeforeCleaning_, eostools::move(), mutex, NO_TRAJECTORY, NOT_STOPPED, oppositeToMomentum, convertSQLitetoXML_cfg::output, trajectoryStateTransform::persistentState(), Trajectory::pop(), printHitsDebugger(), TrackCandidateProducer_cfi::propagator, FastTrackerRecHitMaskProducer_cfi::recHits, PrintoutHelper::regressionTest(), reverseTrajectories, SEED_CLEANING, SEED_REGION_REBUILD, DetachedQuadStep_cff::seeds, setEventSetup(), Trajectory::setNLoops(), skipClusters_, skipPhase2Clusters_, SMOOTHING_FAILED, jetsAK4_CHS_cff::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  auto const& startTraj =
285  theTrajectoryBuilder->buildTrajectories((*collseed)[j], theTmpTrajectories, nCandPerSeed, nullptr);
286  {
287  Lock lock(theMutex);
288  (*outputSeedStopInfos)[j].setCandidatesPerSeed(nCandPerSeed);
289  if (theTmpTrajectories.empty()) {
290  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::NO_TRAJECTORY);
291  return; // from the lambda!
292  }
293  }
294 
295  LogDebug("CkfPattern") << "======== In-out trajectory building found " << theTmpTrajectories.size()
296  << " trajectories from seed " << j << " ========\n"
297  << PrintoutHelper::dumpCandidates(theTmpTrajectories);
298 
300  // Select the best trajectory from this seed (declare others invalid)
301  theTrajectoryCleaner->clean(theTmpTrajectories);
302 
303  LogDebug("CkfPattern") << "======== In-out trajectory cleaning gave the following "
304  << theTmpTrajectories.size() << " valid trajectories from seed " << j << " ========\n"
305  << PrintoutHelper::dumpCandidates(theTmpTrajectories);
306  }
307 
308  // Optionally continue building trajectory back through
309  // seed and if possible further inwards.
310 
312  theTrajectoryBuilder->rebuildTrajectories(startTraj, (*collseed)[j], theTmpTrajectories);
313 
314  LogDebug("CkfPattern") << "======== Out-in trajectory building found " << theTmpTrajectories.size()
315  << " valid/invalid trajectories from seed " << j << " ========\n"
316  << PrintoutHelper::dumpCandidates(theTmpTrajectories);
317  if (theTmpTrajectories.empty()) {
318  Lock lock(theMutex);
319  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::SEED_REGION_REBUILD);
320  return;
321  }
322  }
323 
324  // Select the best trajectory from this seed (after seed region rebuilding, can be more than one)
325  theTrajectoryCleaner->clean(theTmpTrajectories);
326 
327  LogDebug("CkfPattern") << "======== Trajectory cleaning gave the following " << theTmpTrajectories.size()
328  << " valid trajectories from seed " << j << " ========\n"
329  << PrintoutHelper::dumpCandidates(theTmpTrajectories);
330 
331  {
332  Lock lock(theMutex);
333  for (vector<Trajectory>::iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end(); it++) {
334  if (it->isValid()) {
335  it->setSeedRef(collseed->refAt(j));
336  (*outputSeedStopInfos)[j].setStopReason(SeedStopReason::NOT_STOPPED);
337  // Store trajectory
338  rawResult.push_back(std::move(*it));
339  // Tell seed cleaner which hits this trajectory used.
340  //TO BE FIXED: this cut should be configurable via cfi file
341  if (theSeedCleaner && rawResult.back().foundHits() > 3)
342  theSeedCleaner->add(&rawResult.back());
343  //if (theSeedCleaner ) theSeedCleaner->add( & (*it) );
344  }
345  }
346  }
347 
348  theTmpTrajectories.clear();
349 
350  LogDebug("CkfPattern") << "rawResult trajectories found so far = " << rawResult.size();
351 
352  {
353  Lock lock(theMutex);
354  if (maxSeedsBeforeCleaning_ > 0 && rawResult.size() > maxSeedsBeforeCleaning_ + lastCleanResult) {
355  theTrajectoryCleaner->clean(rawResult);
356  rawResult.erase(
357  std::remove_if(rawResult.begin() + lastCleanResult, rawResult.end(), std::not_fn(&Trajectory::isValid)),
358  rawResult.end());
359  lastCleanResult = rawResult.size();
360  }
361  }
362  };
363  // end of loop over seeds
364 
365 #ifdef VI_TBB
366  tbb::parallel_for(0UL, collseed_size, 1UL, theLoop);
367 #else
368 #ifdef VI_OMP
369 #pragma omp parallel for schedule(dynamic, 4)
370 #endif
371  for (size_t j = 0; j < collseed_size; j++) {
372  theLoop(j);
373  }
374 #endif
375  assert(ntseed == collseed_size);
376  if (theSeedCleaner)
377  theSeedCleaner->done();
378 
379  // std::cout << "VICkfPattern " << "rawResult trajectories found = " << rawResult.size() << " in " << ntseed << " seeds " << collseed_size << std::endl;
380 
381 #ifdef VI_REPRODUCIBLE
382  // sort trajectory
383  std::sort(rawResult.begin(), rawResult.end(), [](const Trajectory& a, const Trajectory& b) {
384  return a.seedRef().key() < b.seedRef().key();
385  });
386  //{ return a.chiSquared()*b.ndof() < b.chiSquared()*a.ndof();});
387 #endif
388 
389  // Step E: Clean the results to avoid duplicate tracks
390  // Rejected ones just flagged as invalid.
391  theTrajectoryCleaner->clean(rawResult);
392 
393  LogDebug("CkfPattern") << "======== Final cleaning of entire event found " << rawResult.size()
394  << " valid/invalid trajectories =======" << endl
395  << PrintoutHelper::dumpCandidates(rawResult);
396 
397  LogDebug("CkfPattern") << "removing invalid trajectories.";
398 
399  // Assuming here that theLoop() gives at most one Trajectory per seed
400  for (const auto& traj : rawResult) {
401  if (!traj.isValid()) {
402  const auto seedIndex = traj.seedRef().key();
403  if ((*outputSeedStopInfos)[seedIndex].stopReason() == SeedStopReason::NOT_STOPPED) {
404  (*outputSeedStopInfos)[seedIndex].setStopReason(SeedStopReason::FINAL_CLEAN);
405  }
406  }
407  }
408 
409  vector<Trajectory>& unsmoothedResult(rawResult);
410  unsmoothedResult.erase(
411  std::remove_if(unsmoothedResult.begin(), unsmoothedResult.end(), std::not_fn(&Trajectory::isValid)),
412  unsmoothedResult.end());
413  unsmoothedResult.shrink_to_fit();
414  // If requested, reverse the trajectories creating a new 1-hit seed on the last measurement of the track
415  if (reverseTrajectories) {
416  for (auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
417  // reverse the trajectory only if it has valid hit on the last measurement (should happen)
418  if (it->lastMeasurement().updatedState().isValid() && it->lastMeasurement().recHit().get() != nullptr &&
419  it->lastMeasurement().recHit()->isValid()) {
420  // I can't use reverse in place, because I want to change the seed
421  // 1) reverse propagation direction
422  PropagationDirection direction = it->direction();
423  if (direction == alongMomentum)
424  direction = oppositeToMomentum;
425  else if (direction == oppositeToMomentum)
426  direction = alongMomentum;
427  // 2) make a seed
428  TrajectoryStateOnSurface const& initState = it->lastMeasurement().updatedState();
429  auto initId = it->lastMeasurement().recHitR().rawId();
432  hits.push_back(it->lastMeasurement().recHit()->hit()->clone());
433  // 3) make a trajectory
434  Trajectory trajectory{std::make_shared<TrajectorySeed>(state, std::move(hits), direction), direction};
435  trajectory.setNLoops(it->nLoops());
436  trajectory.setSeedRef(it->seedRef());
437  trajectory.setStopReason(it->stopReason());
438  // 4) push states in reversed order
439  Trajectory::DataContainer& meas = it->measurements();
440  trajectory.reserve(meas.size());
441  for (auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
442  trajectory.push(std::move(*itmeas));
443  }
444  // replace
445  (*it) = std::move(trajectory);
446  } else {
447  edm::LogWarning("CkfPattern_InvalidLastMeasurement")
448  << "Last measurement of the trajectory is invalid, cannot reverse it";
449  }
450  }
451  }
452 
453  int viTotHits = 0;
454 
456  // Step F: Convert to TrackCandidates
457  output->reserve(unsmoothedResult.size());
458  Traj2TrackHits t2t(theTrajectoryBuilder->hitBuilder(), true);
459 
460  for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); ++it) {
461  LogDebug("CkfPattern") << "copying " << (useSplitting ? "splitted" : "un-splitted")
462  << " hits from trajectory";
464  if (it->direction() != alongMomentum)
465  LogDebug("CkfPattern") << "not along momentum... " << std::endl;
466  t2t(*it, recHits, useSplitting);
467 
468  viTotHits += recHits.size();
469 
470  LogDebug("CkfPattern") << "getting initial state.";
471  Trajectory trialTrajectory = (*it);
472  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
473  bool failed = false;
474 
475  do {
476  // Drop last hit if previous backFitter was not successful
477  if (failed) {
478  LogDebug("CkfPattern") << "removing last hit";
479  trialTrajectory.pop();
480  LogDebug("CkfPattern") << "hits remaining " << trialTrajectory.foundHits();
481  }
482 
483  // Get inner state
484  const bool doBackFit = (!doSeedingRegionRebuilding) & (!reverseTrajectories);
485  initState = theInitialState->innerState(trialTrajectory, doBackFit);
486 
487  // Check if that was successful
488  failed = (!initState.first.isValid()) || initState.second == nullptr ||
489  edm::isNotFinite(initState.first.globalPosition().x());
490  } while (failed && trialTrajectory.foundHits() > 3);
491 
492  if (failed) {
493  const auto seedIndex = it->seedRef().key();
494  (*outputSeedStopInfos)[seedIndex].setStopReason(SeedStopReason::SMOOTHING_FAILED);
495  continue;
496  }
497 
499  if (useSplitting && (initState.second != recHits.front().det()) && recHits.front().det()) {
500  LogDebug("CkfPattern") << "propagating to hit front in case of splitting.";
501  TrajectoryStateOnSurface&& propagated =
502  propagator.propagate(initState.first, recHits.front().det()->surface());
503  if (!propagated.isValid())
504  continue;
505  state = trajectoryStateTransform::persistentState(propagated, recHits.front().rawId());
506  } else
507  state =
508  trajectoryStateTransform::persistentState(initState.first, initState.second->geographicalId().rawId());
509  LogDebug("CkfPattern") << "pushing a TrackCandidate.";
510  output->emplace_back(recHits, it->seed(), state, it->seedRef(), it->nLoops(), (uint8_t)it->stopReason());
511  }
512  } //output trackcandidates
513 
514  LogTrace("CkfPattern|TrackingRegressionTest")
515  << "========== CkfTrackCandidateMaker Info =========="
516  << "number of Seed: " << collseed->size() << '\n'
517  << PrintoutHelper::regressionTest(es.getData(theTrackerToken), unsmoothedResult);
518 
519  assert(viTotHits >= 0); // just to use it...
520  // std::cout << "VICkfPattern result " << output->size() << " " << viTotHits << std::endl;
521 
522  if (theTrajectoryOutput) {
523  outputT->swap(unsmoothedResult);
524  }
525 
526  } // end of ((*collseed).size()>0)
527 
528  // method for debugging
530 
531  // Step G: write output to file
533  e.put(std::move(output));
534  }
535  if (theTrajectoryOutput) {
536  e.put(std::move(outputT));
537  }
538  e.put(std::move(outputSeedStopInfos));
539  }
static std::string dumpCandidates(collection &candidates)
bool isValid() const
Definition: Trajectory.h:257
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
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 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
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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
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
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  }
edm::ESGetToken< TrajectoryCleaner, TrajectoryCleaner::Record > theTrajectoryCleanerToken
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
bool getData(T &iHolder) const
Definition: EventSetup.h:122
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().