44 #include "oneapi/tbb/parallel_for.h" 53 std::unique_ptr<BaseCkfTrajectoryBuilder> createBaseCkfTrajectoryBuilder(
const edm::ParameterSet&
pset,
61 : theTrackCandidateOutput(
true),
62 theTrajectoryOutput(
false),
63 useSplitting(conf.getParameter<
bool>(
"useHitsSplitting")),
67 theMaxNSeeds(conf.getParameter<unsigned
int>(
"maxNSeeds")),
69 createBaseCkfTrajectoryBuilder(conf.getParameter<
edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
70 theTrajectoryCleanerToken(
72 theTrajectoryCleaner(nullptr),
74 conf.getParameter<
ParameterSet>(
"TransientInitialStateEstimatorParameters"), iC)),
75 theNavigationSchoolToken(
77 theNavigationSchool(nullptr),
79 #ifdef VI_REPRODUCIBLE
80 maxSeedsBeforeCleaning_(0),
82 maxSeedsBeforeCleaning_(conf.getParameter<unsigned
int>(
"maxSeedsBeforeCleaning")),
85 clustersToSkipTag_(conf.getParameter<
edm::
InputTag>(
"clustersToSkip")),
86 skipClusters_(!clustersToSkipTag_.
label().
empty()),
87 phase2ClustersToSkipTag_(conf.getParameter<
edm::
InputTag>(
"phase2clustersToSkip")),
88 skipPhase2Clusters_(!phase2ClustersToSkipTag_.
label().
empty()) {
100 #ifndef VI_REPRODUCIBLE 102 if (cleaner ==
"CachingSeedCleanerBySharedInput") {
104 bool onlyPixelHits = conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner");
106 }
else if (cleaner !=
"none") {
107 throw cms::Exception(
"RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none",
118 #ifdef VI_REPRODUCIBLE 119 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
157 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
163 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
172 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
181 es, static_cast<TkTransientTrackingRecHitBuilder const*>(
theTrajectoryBuilder->hitBuilder())->cloner());
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());
195 <<
" nSeed=" << (*collseed).size();
207 if (!(*collseed).empty()) {
208 unsigned int lastCleanResult = 0;
209 std::vector<Trajectory> rawResult;
210 rawResult.reserve(collseed->size() * 4);
220 using Lock = std::unique_lock<std::mutex>;
223 size_t collseed_size = collseed->size();
225 unsigned int indeces[collseed_size];
226 for (
auto i = 0
U;
i < collseed_size; ++
i)
234 auto const&
seeds = *collseed;
236 float val[collseed_size];
237 for (
auto i = 0
U;
i < collseed_size; ++
i) {
255 std::sort(indeces, indeces + collseed_size, [&](
unsigned int i,
unsigned int j) {
return val[
i] <
val[
j]; });
260 std::atomic<unsigned int> ntseed(0);
261 auto theLoop = [&](
size_t ii) {
262 auto j = indeces[
ii];
267 std::vector<Trajectory> theTmpTrajectories;
269 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " <<
j <<
" ========\n";
275 LogDebug(
"CkfTrackCandidateMakerBase") <<
" Seed cleaning kills seed " <<
j;
282 theTmpTrajectories.clear();
283 unsigned int nCandPerSeed = 0;
287 (*outputSeedStopInfos)[
j].setCandidatesPerSeed(nCandPerSeed);
288 if (theTmpTrajectories.empty()) {
294 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
295 <<
" trajectories from seed " <<
j <<
" ========\n" 302 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " 303 << theTmpTrajectories.size() <<
" valid trajectories from seed " <<
j <<
" ========\n" 313 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
314 <<
" valid/invalid trajectories from seed " <<
j <<
" ========\n" 316 if (theTmpTrajectories.empty()) {
326 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size()
327 <<
" valid trajectories from seed " <<
j <<
" ========\n" 332 for (vector<Trajectory>::iterator
it = theTmpTrajectories.begin();
it != theTmpTrajectories.end();
it++) {
334 it->setSeedRef(collseed->refAt(
j));
347 theTmpTrajectories.clear();
349 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
356 std::remove_if(rawResult.begin() + lastCleanResult, rawResult.end(), std::not_fn(&
Trajectory::isValid)),
358 lastCleanResult = rawResult.size();
365 tbb::parallel_for(0UL, collseed_size, 1UL, theLoop);
368 #pragma omp parallel for schedule(dynamic, 4) 370 for (
size_t j = 0;
j < collseed_size;
j++) {
374 assert(ntseed == collseed_size);
380 #ifdef VI_REPRODUCIBLE 383 return a.seedRef().key() <
b.seedRef().key();
392 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
393 <<
" valid/invalid trajectories =======" << endl
396 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
399 for (
const auto& traj : rawResult) {
400 if (!traj.isValid()) {
401 const auto seedIndex = traj.seedRef().key();
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();
415 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end();
it != ed; ++
it) {
417 if (
it->lastMeasurement().updatedState().isValid() &&
it->lastMeasurement().recHit().get() !=
nullptr &&
418 it->lastMeasurement().recHit()->isValid()) {
428 auto initId =
it->lastMeasurement().recHitR().rawId();
431 hits.push_back(
it->lastMeasurement().recHit()->hit()->clone());
435 trajectory.setSeedRef(
it->seedRef());
436 trajectory.setStopReason(
it->stopReason());
439 trajectory.reserve(meas.size());
440 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
447 <<
"Last measurement of the trajectory is invalid, cannot reverse it";
456 output->reserve(unsmoothedResult.size());
459 for (vector<Trajectory>::const_iterator
it = unsmoothedResult.begin();
it != unsmoothedResult.end(); ++
it) {
461 <<
" hits from trajectory";
464 LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
469 LogDebug(
"CkfPattern") <<
"getting initial state.";
471 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
477 LogDebug(
"CkfPattern") <<
"removing last hit";
478 trialTrajectory.
pop();
487 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
492 const auto seedIndex =
it->seedRef().key();
499 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
508 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
513 LogTrace(
"CkfPattern|TrackingRegressionTest")
514 <<
"========== CkfTrackCandidateMaker Info ==========" 515 <<
"number of Seed: " << collseed->size() <<
'\n' 522 outputT->swap(unsmoothedResult);
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);
557 psd1.
add<
std::string>(
"propagatorAlongTISE",
"PropagatorWithMaterial");
558 psd1.add<
std::string>(
"propagatorOppositeTISE",
"PropagatorWithMaterialOpposite");
559 psd1.add<
int>(
"numberMeasurementsForFit", 4);
562 desc.add<
int>(
"numHitsForSeedCleaner", 4);
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);
virtual void deleteAssocDebugger()
T getParameter(std::string const &) const
static std::string dumpCandidates(collection &candidates)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
bool theTrackCandidateOutput
cleanTrajectoryAfterInOut
constexpr bool isNotFinite(T x)
edm::EDGetTokenT< StripClusterMask > maskStrips_
std::unique_ptr< TransientInitialStateEstimator > theInitialState
doSeedingRegionRebuilding
virtual void clean(TempTrajectoryContainer &) const
virtual void printHitsDebugger(edm::Event &e)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
edm::InputTag const clustersToSkipTag_
Log< level::Error, false > LogError
virtual ~CkfTrackCandidateMakerBase() noexcept(false)
unsigned int theMaxNSeeds
std::unique_ptr< RedundantSeedCleaner > theSeedCleaner
static std::string regressionTest(const TrackerGeometry &tracker, std::vector< Trajectory > &unsmoothedResult)
edm::EDGetTokenT< PixelClusterMask > maskPixels_
std::vector< TrajectoryMeasurement > DataContainer
edm::ESGetToken< TrajectoryCleaner, TrajectoryCleaner::Record > theTrajectoryCleanerToken
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
virtual void produceBase(edm::Event &e, const edm::EventSetup &es)
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
unsigned int maxSeedsBeforeCleaning_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerToken
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
static void fillPSetDescription(edm::ParameterSetDescription &desc)
Namespace of DDCMS conversion namespace.
bool const skipPhase2Clusters_
void setNLoops(int8_t value)
bool doSeedingRegionRebuilding
edm::ESGetToken< Propagator, TrackingComponentsRecord > thePropagatorToken
void setEventSetup(const edm::EventSetup &es)
Initialize EventSetup objects at each event.
virtual void beginRunBase(edm::Run const &, edm::EventSetup const &es)
char data[epos_bytes_allocation]
edm::InputTag const phase2ClustersToSkipTag_
Log< level::Warning, false > LogWarning
virtual void countSeedsDebugger()
bool cleanTrajectoryAfterInOut
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavigationSchoolToken