44 #include "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 conf.getParameter<
bool>(
"reverseTrajectories")),
68 theMaxNSeeds(conf.getParameter<unsigned
int>(
"maxNSeeds")),
70 createBaseCkfTrajectoryBuilder(conf.getParameter<
edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
71 theTrajectoryCleanerName(conf.getParameter<
std::
string>(
"TrajectoryCleaner")),
74 conf.getParameter<
ParameterSet>(
"TransientInitialStateEstimatorParameters"))),
75 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<
std::
string>(
"SimpleMagneticField")
77 theNavigationSchoolName(conf.getParameter<
std::
string>(
"NavigationSchool")),
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",
114 #ifdef VI_REPRODUCIBLE 115 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
163 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
169 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
178 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
187 es, static_cast<TkTransientTrackingRecHitBuilder const*>(
theTrajectoryBuilder->hitBuilder())->cloner());
195 auto output = std::make_unique<TrackCandidateCollection>();
196 auto outputT = std::make_unique<std::vector<Trajectory>>();
197 auto outputSeedStopInfos = std::make_unique<std::vector<SeedStopInfo>>(collseed->size());
201 <<
" nSeed=" << (*collseed).size();
213 if (!(*collseed).empty()) {
214 unsigned int lastCleanResult = 0;
215 std::vector<Trajectory> rawResult;
216 rawResult.reserve(collseed->size() * 4);
226 using Lock = std::unique_lock<std::mutex>;
229 size_t collseed_size = collseed->size();
231 unsigned int indeces[collseed_size];
232 for (
auto i = 0
U;
i < collseed_size; ++
i)
240 auto const& seeds = *collseed;
242 float val[collseed_size];
243 for (
auto i = 0
U;
i < collseed_size; ++
i) {
244 val[
i] = seeds[
i].startingState().pt();
261 std::sort(indeces, indeces + collseed_size, [&](
unsigned int i,
unsigned int j) {
return val[
i] < val[
j]; });
266 std::atomic<unsigned int> ntseed(0);
267 auto theLoop = [&](
size_t ii) {
268 auto j = indeces[
ii];
273 std::vector<Trajectory> theTmpTrajectories;
275 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
281 LogDebug(
"CkfTrackCandidateMakerBase") <<
" Seed cleaning kills seed " <<
j;
288 theTmpTrajectories.clear();
289 unsigned int nCandPerSeed = 0;
290 auto const& startTraj =
291 theTrajectoryBuilder->buildTrajectories((*collseed)[j], theTmpTrajectories, nCandPerSeed,
nullptr);
294 (*outputSeedStopInfos)[
j].setCandidatesPerSeed(nCandPerSeed);
295 if (theTmpTrajectories.empty()) {
301 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
302 <<
" trajectories from seed " << j <<
" ========\n" 309 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " 310 << theTmpTrajectories.size() <<
" valid trajectories from seed " << j <<
" ========\n" 320 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
321 <<
" valid/invalid trajectories from seed " << j <<
" ========\n" 323 if (theTmpTrajectories.empty()) {
333 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size()
334 <<
" valid trajectories from seed " << j <<
" ========\n" 339 for (vector<Trajectory>::iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end(); it++) {
341 it->setSeedRef(collseed->refAt(j));
354 theTmpTrajectories.clear();
356 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
363 std::remove_if(rawResult.begin() + lastCleanResult, rawResult.end(), std::not_fn(&
Trajectory::isValid)),
365 lastCleanResult = rawResult.size();
372 tbb::parallel_for(0UL, collseed_size, 1UL, theLoop);
375 #pragma omp parallel for schedule(dynamic, 4) 377 for (
size_t j = 0; j < collseed_size; j++) {
381 assert(ntseed == collseed_size);
387 #ifdef VI_REPRODUCIBLE 399 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
400 <<
" valid/invalid trajectories =======" << endl
403 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
406 for (
const auto& traj : rawResult) {
407 if (!traj.isValid()) {
408 const auto seedIndex = traj.seedRef().key();
415 vector<Trajectory>& unsmoothedResult(rawResult);
416 unsmoothedResult.erase(
417 std::remove_if(unsmoothedResult.begin(), unsmoothedResult.end(), std::not_fn(&
Trajectory::isValid)),
418 unsmoothedResult.end());
419 unsmoothedResult.shrink_to_fit();
422 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
424 if (it->lastMeasurement().updatedState().isValid() && it->lastMeasurement().recHit().get() !=
nullptr &&
425 it->lastMeasurement().recHit()->isValid()) {
435 auto initId = it->lastMeasurement().recHitR().rawId();
438 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
447 trajectory.
reserve(meas.size());
448 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
455 <<
"Last measurement of the trajectory is invalid, cannot reverse it";
464 output->reserve(unsmoothedResult.size());
467 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); ++it) {
469 <<
" hits from trajectory";
472 LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
475 viTotHits += recHits.
size();
477 LogDebug(
"CkfPattern") <<
"getting initial state.";
479 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
485 LogDebug(
"CkfPattern") <<
"removing last hit";
486 trialTrajectory.
pop();
495 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
497 }
while (failed && trialTrajectory.
foundHits() > 3);
500 const auto seedIndex = it->seedRef().key();
507 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
516 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
517 output->emplace_back(recHits, it->seed(), state, it->seedRef(), it->nLoops(), (uint8_t)it->stopReason());
523 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info ==========" 524 <<
"number of Seed: " << collseed->size() <<
'\n' 527 assert(viTotHits >= 0);
531 outputT->swap(unsmoothedResult);
T getParameter(std::string const &) const
static boost::mutex mutex
virtual void deleteAssocDebugger()
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_
void setStopReason(StopReason s)
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)
edm::ESHandle< GeometricSearchTracker > theGeomSearchTracker
void reserve(unsigned int n)
const Plane & surface() const
The nominal surface of the GeomDet.
const std::string theMagFieldName
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
const TrajectoryCleaner * theTrajectoryCleaner
const NavigationSchool * theNavigationSchool
std::string theNavigationSchoolName
const GeomDet * det() const
virtual void produceBase(edm::Event &e, const edm::EventSetup &es)
virtual ~CkfTrackCandidateMakerBase()(false)
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
unsigned int maxSeedsBeforeCleaning_
edm::RefToBase< TrajectorySeed > seedRef(void) const
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
Namespace of DDCMS conversion namespace.
cleanTrajectoryAfterInOut
std::string theTrajectoryCleanerName
bool doSeedingRegionRebuilding
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
void setSeedRef(const edm::RefToBase< TrajectorySeed > &seedRef)
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]
doSeedingRegionRebuilding
virtual void countSeedsDebugger()
T const * product() const
void push(const TrajectoryMeasurement &tm)
bool cleanTrajectoryAfterInOut
edm::ESHandle< MagneticField > theMagField