43 #include "tbb/parallel_for.h"
52 std::unique_ptr<BaseCkfTrajectoryBuilder> createBaseCkfTrajectoryBuilder(
const edm::ParameterSet&
pset,
60 : theTrackCandidateOutput(
true),
61 theTrajectoryOutput(
false),
62 useSplitting(conf.getParameter<bool>(
"useHitsSplitting")),
66 conf.getParameter<bool>(
"reverseTrajectories")),
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 maxSeedsBeforeCleaning_(0),
82 phase2skipClusters_(
false) {
84 #ifndef VI_REPRODUCIBLE
85 if (conf.
exists(
"maxSeedsBeforeCleaning"))
99 #ifndef VI_REPRODUCIBLE
101 if (cleaner ==
"CachingSeedCleanerBySharedInput") {
103 conf.
existsAs<
int>(
"numHitsForSeedCleaner") ? conf.
getParameter<
int>(
"numHitsForSeedCleaner") : 4;
104 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner")
105 ? conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner")
108 }
else if (cleaner !=
"none") {
109 throw cms::Exception(
"RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none",
120 #ifdef VI_REPRODUCIBLE
121 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
159 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
165 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
174 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
183 es, static_cast<TkTransientTrackingRecHitBuilder const*>(
theTrajectoryBuilder->hitBuilder())->cloner());
191 auto output = std::make_unique<TrackCandidateCollection>();
192 auto outputT = std::make_unique<std::vector<Trajectory>>();
193 auto outputSeedStopInfos = std::make_unique<std::vector<SeedStopInfo>>(collseed->size());
197 <<
" nSeed=" << (*collseed).size();
209 if (!(*collseed).empty()) {
210 unsigned int lastCleanResult = 0;
211 std::vector<Trajectory> rawResult;
212 rawResult.reserve(collseed->size() * 4);
222 using Lock = std::unique_lock<std::mutex>;
225 size_t collseed_size = collseed->size();
227 unsigned int indeces[collseed_size];
228 for (
auto i = 0U;
i < collseed_size; ++
i)
236 auto const&
seeds = *collseed;
238 float val[collseed_size];
239 for (
auto i = 0U;
i < collseed_size; ++
i) {
240 val[
i] =
seeds[
i].startingState().pt();
257 std::sort(indeces, indeces + collseed_size, [&](
unsigned int i,
unsigned int j) {
return val[
i] < val[
j]; });
262 std::atomic<unsigned int> ntseed(0);
263 auto theLoop = [&](
size_t ii) {
264 auto j = indeces[
ii];
269 std::vector<Trajectory> theTmpTrajectories;
271 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
277 LogDebug(
"CkfTrackCandidateMakerBase") <<
" Seed cleaning kills seed " <<
j;
284 theTmpTrajectories.clear();
285 unsigned int nCandPerSeed = 0;
286 auto const& startTraj =
287 theTrajectoryBuilder->buildTrajectories((*collseed)[j], theTmpTrajectories, nCandPerSeed,
nullptr);
290 (*outputSeedStopInfos)[
j].setCandidatesPerSeed(nCandPerSeed);
291 if (theTmpTrajectories.empty()) {
297 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
298 <<
" trajectories from seed " << j <<
" ========\n"
305 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following "
306 << theTmpTrajectories.size() <<
" valid trajectories from seed " << j <<
" ========\n"
316 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
317 <<
" valid/invalid trajectories from seed " << j <<
" ========\n"
319 if (theTmpTrajectories.empty()) {
329 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size()
330 <<
" valid trajectories from seed " << j <<
" ========\n"
335 for (vector<Trajectory>::iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end(); it++) {
337 it->setSeedRef(collseed->refAt(j));
350 theTmpTrajectories.clear();
352 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
359 std::remove_if(rawResult.begin() + lastCleanResult, rawResult.end(), std::not_fn(&
Trajectory::isValid)),
361 lastCleanResult = rawResult.size();
368 tbb::parallel_for(0UL, collseed_size, 1UL, theLoop);
371 #pragma omp parallel for schedule(dynamic, 4)
373 for (
size_t j = 0; j < collseed_size; j++) {
377 assert(ntseed == collseed_size);
383 #ifdef VI_REPRODUCIBLE
395 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
396 <<
" valid/invalid trajectories =======" << endl
399 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
402 for (
const auto& traj : rawResult) {
403 if (!traj.isValid()) {
404 const auto seedIndex = traj.seedRef().key();
411 vector<Trajectory>& unsmoothedResult(rawResult);
412 unsmoothedResult.erase(
413 std::remove_if(unsmoothedResult.begin(), unsmoothedResult.end(), std::not_fn(&
Trajectory::isValid)),
414 unsmoothedResult.end());
415 unsmoothedResult.shrink_to_fit();
418 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
420 if (it->lastMeasurement().updatedState().isValid() && it->lastMeasurement().recHit().get() !=
nullptr &&
421 it->lastMeasurement().recHit()->isValid()) {
431 auto initId = it->lastMeasurement().recHitR().rawId();
434 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
438 trajectory.setSeedRef(it->seedRef());
439 trajectory.setStopReason(it->stopReason());
442 trajectory.reserve(meas.size());
443 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
450 <<
"Last measurement of the trajectory is invalid, cannot reverse it";
459 output->reserve(unsmoothedResult.size());
462 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); ++it) {
464 <<
" hits from trajectory";
467 LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
470 viTotHits += recHits.
size();
472 LogDebug(
"CkfPattern") <<
"getting initial state.";
474 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
480 LogDebug(
"CkfPattern") <<
"removing last hit";
481 trialTrajectory.
pop();
490 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
492 }
while (failed && trialTrajectory.
foundHits() > 3);
495 const auto seedIndex = it->seedRef().key();
502 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
511 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
512 output->emplace_back(recHits, it->seed(),
state, it->seedRef(), it->nLoops(), (uint8_t)it->stopReason());
516 LogTrace(
"CkfPattern|TrackingRegressionTest")
517 <<
"========== CkfTrackCandidateMaker Info =========="
518 <<
"number of Seed: " << collseed->size() <<
'\n'
525 outputT->swap(unsmoothedResult);
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 existsAs(std::string const ¶meterName, bool trackiness=true) const
checks if a parameter exists as a given type
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)
bool exists(std::string const ¶meterName) const
checks if a parameter exists
virtual void printHitsDebugger(edm::Event &e)
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_
edm::RefToBase< TrajectorySeed > seedRef(void) const
tuple doSeedingRegionRebuilding
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > theTrackerToken
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
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]
tuple MeasurementTrackerEvent
Log< level::Warning, false > LogWarning
virtual void countSeedsDebugger()
bool cleanTrajectoryAfterInOut
edm::ESGetToken< NavigationSchool, NavigationSchoolRecord > theNavigationSchoolToken