45 #include "tbb/parallel_for.h" 61 theTrackCandidateOutput(
true),
62 theTrajectoryOutput(
false),
63 useSplitting(conf.getParameter<
bool>(
"useHitsSplitting")),
67 theMaxNSeeds(conf.getParameter<unsigned
int>(
"maxNSeeds")),
68 theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<
edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
69 theTrajectoryCleanerName(conf.getParameter<
std::
string>(
"TrajectoryCleaner")),
72 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<
std::
string>(
"SimpleMagneticField") :
""),
73 theNavigationSchoolName(conf.getParameter<
std::
string>(
"NavigationSchool")),
75 maxSeedsBeforeCleaning_(0),
78 phase2skipClusters_(
false)
81 #ifndef VI_REPRODUCIBLE 82 if ( conf.
exists(
"maxSeedsBeforeCleaning") )
96 #ifndef VI_REPRODUCIBLE 98 if (cleaner ==
"CachingSeedCleanerBySharedInput") {
101 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner") ?
102 conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner") :
false;
104 }
else if (cleaner !=
"none") {
105 throw cms::Exception(
"RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none", cleaner);
109 #ifdef VI_REPRODUCIBLE 110 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
165 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
171 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
180 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
196 auto output = std::make_unique<TrackCandidateCollection>();
197 auto outputT = std::make_unique<std::vector<Trajectory>>();
198 auto outputSeedStopInfos = std::make_unique<std::vector<SeedStopInfo> >(collseed->size());
201 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
209 if (!(*collseed).empty()){
211 unsigned int lastCleanResult=0;
212 std::vector<Trajectory> rawResult;
213 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];
for (
auto i=0
U;
i< collseed_size; ++
i) indeces[
i]=
i;
237 auto const & seeds = *collseed;
240 float val[collseed_size];
241 for (
auto i=0
U;
i< collseed_size; ++
i)
242 { val[
i] = seeds[
i].startingState().pt();};
258 std::sort(indeces,indeces+collseed_size, [&](
unsigned int i,
unsigned int j){
return val[
i]<val[j];});
264 std::atomic<unsigned int> ntseed(0);
265 auto theLoop = [&](
size_t ii) {
266 auto j = indeces[
ii];
271 std::vector<Trajectory> theTmpTrajectories;
274 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
276 { Lock
lock(theMutex);
279 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<j;
286 theTmpTrajectories.clear();
287 unsigned int nCandPerSeed = 0;
288 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories, nCandPerSeed,
nullptr );
291 (*outputSeedStopInfos)[j].setCandidatesPerSeed(nCandPerSeed);
292 if(theTmpTrajectories.empty()) {
298 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
299 <<
" trajectories from seed " << j <<
" ========\n" 307 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " << theTmpTrajectories.size()
308 <<
" valid trajectories from seed " 309 << j <<
" ========\n" 319 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
320 <<
" valid/invalid trajectories from seed " << j <<
" ========\n" 322 if(theTmpTrajectories.empty()) {
333 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size() <<
" valid trajectories from seed " 334 << j <<
" ========\n" 337 { Lock
lock(theMutex);
338 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
339 it!=theTmpTrajectories.end(); it++){
340 if( it->isValid() ) {
341 it->setSeedRef(collseed->refAt(j));
352 theTmpTrajectories.clear();
354 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
356 { Lock
lock(theMutex);
359 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
362 lastCleanResult=rawResult.size();
371 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
374 #pragma omp parallel for schedule(dynamic,4) 376 for (
size_t j = 0; j < collseed_size; j++){
380 assert(ntseed==collseed_size);
385 #ifdef VI_REPRODUCIBLE 396 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
397 <<
" valid/invalid trajectories ======="<<endl
400 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
403 for(
const auto& traj: rawResult) {
404 if(!traj.isValid()) {
405 const auto seedIndex = traj.seedRef().key();
412 vector<Trajectory> & unsmoothedResult(rawResult);
413 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
415 unsmoothedResult.end());
416 unsmoothedResult.shrink_to_fit();
419 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
421 if (it->lastMeasurement().updatedState().isValid() &&
422 it->lastMeasurement().recHit().get() !=
nullptr &&
423 it->lastMeasurement().recHit()->isValid()) {
431 auto initId = it->lastMeasurement().recHitR().rawId();
434 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
443 trajectory.
reserve(meas.size());
444 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
450 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
460 output->reserve(unsmoothedResult.size());
463 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
464 it != unsmoothedResult.end(); ++it) {
466 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
468 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
471 viTotHits+=recHits.
size();
474 LogDebug(
"CkfPattern") <<
"getting initial state.";
476 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
482 LogDebug(
"CkfPattern") <<
"removing last hit";
483 trialTrajectory.
pop();
492 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
493 }
while(failed && trialTrajectory.
foundHits() > 3);
496 const auto seedIndex = it->seedRef().key();
505 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
507 if (!propagated.
isValid())
continue;
512 initState.second->geographicalId().rawId());
513 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
514 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
520 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info ==========" 521 <<
"number of Seed: " << collseed->size()<<
'\n' 524 assert(viTotHits>=0);
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)
doSeedingRegionRebuilding
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)
cleanTrajectoryAfterInOut
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.
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]
numHitsForSeedCleaner
these two parameters are relevant only for the CachingSeedCleanerBySharedInput
virtual void countSeedsDebugger()
T const * product() const
void push(const TrajectoryMeasurement &tm)
bool cleanTrajectoryAfterInOut
T get(const Candidate &c)
edm::ESHandle< MagneticField > theMagField