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 = 0U;
i < collseed_size; ++
i)
234 auto const&
seeds = *collseed;
236 float val[collseed_size];
237 for (
auto i = 0U;
i < collseed_size; ++
i) {
238 val[
i] =
seeds[
i].startingState().pt();
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;
284 auto const& startTraj =
285 theTrajectoryBuilder->buildTrajectories((*collseed)[j], theTmpTrajectories, nCandPerSeed,
nullptr);
288 (*outputSeedStopInfos)[
j].setCandidatesPerSeed(nCandPerSeed);
289 if (theTmpTrajectories.empty()) {
295 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
296 <<
" trajectories from seed " << j <<
" ========\n"
303 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following "
304 << theTmpTrajectories.size() <<
" valid trajectories from seed " << j <<
" ========\n"
314 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
315 <<
" valid/invalid trajectories from seed " << j <<
" ========\n"
317 if (theTmpTrajectories.empty()) {
327 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size()
328 <<
" valid trajectories from seed " << j <<
" ========\n"
333 for (vector<Trajectory>::iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end(); it++) {
335 it->setSeedRef(collseed->refAt(j));
348 theTmpTrajectories.clear();
350 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
357 std::remove_if(rawResult.begin() + lastCleanResult, rawResult.end(), std::not_fn(&
Trajectory::isValid)),
359 lastCleanResult = rawResult.size();
366 tbb::parallel_for(0UL, collseed_size, 1UL, theLoop);
369 #pragma omp parallel for schedule(dynamic, 4)
371 for (
size_t j = 0; j < collseed_size; j++) {
375 assert(ntseed == collseed_size);
381 #ifdef VI_REPRODUCIBLE
393 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
394 <<
" valid/invalid trajectories =======" << endl
397 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
400 for (
const auto& traj : rawResult) {
401 if (!traj.isValid()) {
402 const auto seedIndex = traj.seedRef().key();
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();
416 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
418 if (it->lastMeasurement().updatedState().isValid() && it->lastMeasurement().recHit().get() !=
nullptr &&
419 it->lastMeasurement().recHit()->isValid()) {
429 auto initId = it->lastMeasurement().recHitR().rawId();
432 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
436 trajectory.setSeedRef(it->seedRef());
437 trajectory.setStopReason(it->stopReason());
440 trajectory.reserve(meas.size());
441 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
448 <<
"Last measurement of the trajectory is invalid, cannot reverse it";
457 output->reserve(unsmoothedResult.size());
460 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); ++it) {
462 <<
" hits from trajectory";
465 LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
468 viTotHits += recHits.
size();
470 LogDebug(
"CkfPattern") <<
"getting initial state.";
472 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
478 LogDebug(
"CkfPattern") <<
"removing last hit";
479 trialTrajectory.
pop();
488 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
490 }
while (failed && trialTrajectory.
foundHits() > 3);
493 const auto seedIndex = it->seedRef().key();
500 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
509 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
510 output->emplace_back(recHits, it->seed(),
state, it->seedRef(), it->nLoops(), (uint8_t)it->stopReason());
514 LogTrace(
"CkfPattern|TrackingRegressionTest")
515 <<
"========== CkfTrackCandidateMaker Info =========="
516 <<
"number of Seed: " << collseed->size() <<
'\n'
523 outputT->swap(unsmoothedResult);
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);
558 psd1.
add<
std::string>(
"propagatorAlongTISE",
"PropagatorWithMaterial");
559 psd1.add<
std::string>(
"propagatorOppositeTISE",
"PropagatorWithMaterialOpposite");
560 psd1.add<
int>(
"numberMeasurementsForFit", 4);
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);
virtual void deleteAssocDebugger()
tuple cleanTrajectoryAfterInOut
static std::string dumpCandidates(collection &candidates)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
virtual void clean(TempTrajectoryContainer &) const
bool theTrackCandidateOutput
bool getByToken(EDGetToken token, Handle< PROD > &result) const
constexpr bool isNotFinite(T x)
edm::EDGetTokenT< StripClusterMask > maskStrips_
std::unique_ptr< TransientInitialStateEstimator > theInitialState
void setNLoops(signed char value)
virtual void printHitsDebugger(edm::Event &e)
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
edm::InputTag const clustersToSkipTag_
Log< level::Error, false > LogError
virtual ~CkfTrackCandidateMakerBase() noexcept(false)
const Plane & surface() const
The nominal surface of the GeomDet.
unsigned int theMaxNSeeds
std::unique_ptr< RedundantSeedCleaner > theSeedCleaner
static std::string regressionTest(const TrackerGeometry &tracker, std::vector< Trajectory > &unsmoothedResult)
bool getData(T &iHolder) const
tuple reverseTrajectories
edm::EDGetTokenT< PixelClusterMask > maskPixels_
std::vector< TrajectoryMeasurement > DataContainer
edm::ESGetToken< TrajectoryCleaner, TrajectoryCleaner::Record > theTrajectoryCleanerToken
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
const GeomDet * det() const
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::RefToBase< TrajectorySeed > seedRef(void) const
tuple doSeedingRegionRebuilding
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerToken
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
static void fillPSetDescription(edm::ParameterSetDescription &desc)
bool const skipPhase2Clusters_
T getParameter(std::string const &) const
bool doSeedingRegionRebuilding
tuple numHitsForSeedCleaner
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_
tuple MeasurementTrackerEvent
Log< level::Warning, false > LogWarning
virtual void countSeedsDebugger()
bool cleanTrajectoryAfterInOut
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavigationSchoolToken