48 #include "tbb/parallel_for.h" 64 theTrackCandidateOutput(
true),
65 theTrajectoryOutput(
false),
66 useSplitting(conf.getParameter<
bool>(
"useHitsSplitting")),
70 theMaxNSeeds(conf.getParameter<unsigned
int>(
"maxNSeeds")),
71 theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<
edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
72 theTrajectoryCleanerName(conf.getParameter<
std::
string>(
"TrajectoryCleaner")),
75 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<
std::
string>(
"SimpleMagneticField") :
""),
76 theNavigationSchoolName(conf.getParameter<
std::
string>(
"NavigationSchool")),
79 maxSeedsBeforeCleaning_(0),
82 phase2skipClusters_(
false)
85 #ifndef VI_REPRODUCIBLE 86 if ( conf.
exists(
"maxSeedsBeforeCleaning") )
100 #ifndef VI_REPRODUCIBLE 102 if (cleaner ==
"SeedCleanerByHitPosition") {
104 }
else if (cleaner ==
"SeedCleanerBySharedInput") {
106 }
else if (cleaner ==
"CachingSeedCleanerByHitPosition") {
108 }
else if (cleaner ==
"CachingSeedCleanerBySharedInput") {
111 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner") ?
112 conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner") :
false;
114 }
else if (cleaner ==
"none") {
121 #ifdef VI_REPRODUCIBLE 122 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
179 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
185 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
194 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
210 auto output = std::make_unique<TrackCandidateCollection>();
211 auto outputT = std::make_unique<std::vector<Trajectory>>();
212 auto outputSeedStopInfos = std::make_unique<std::vector<SeedStopInfo> >(collseed->size());
215 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
223 if (!(*collseed).empty()){
225 unsigned int lastCleanResult=0;
226 std::vector<Trajectory> rawResult;
227 rawResult.reserve(collseed->size() * 4);
236 using Lock = std::unique_lock<std::mutex>;
239 size_t collseed_size = collseed->size();
241 unsigned int indeces[collseed_size];
for (
auto i=0
U;
i< collseed_size; ++
i) indeces[
i]=
i;
251 auto const & seeds = *collseed;
254 float val[collseed_size];
255 for (
auto i=0
U;
i< collseed_size; ++
i)
256 { val[
i] = seeds[
i].startingState().pt();};
272 std::sort(indeces,indeces+collseed_size, [&](
unsigned int i,
unsigned int j){
return val[
i]<val[j];});
278 std::atomic<unsigned int> ntseed(0);
279 auto theLoop = [&](
size_t ii) {
280 auto j = indeces[
ii];
285 std::vector<Trajectory> theTmpTrajectories;
288 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
290 { Lock
lock(theMutex);
293 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<j;
300 theTmpTrajectories.clear();
301 unsigned int nCandPerSeed = 0;
302 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories, nCandPerSeed,
nullptr );
305 (*outputSeedStopInfos)[j].setCandidatesPerSeed(nCandPerSeed);
306 if(theTmpTrajectories.empty()) {
312 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
313 <<
" trajectories from seed " << j <<
" ========\n" 321 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " << theTmpTrajectories.size()
322 <<
" valid trajectories from seed " 323 << j <<
" ========\n" 333 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
334 <<
" valid/invalid trajectories from seed " << j <<
" ========\n" 336 if(theTmpTrajectories.empty()) {
347 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size() <<
" valid trajectories from seed " 348 << j <<
" ========\n" 351 { Lock
lock(theMutex);
352 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
353 it!=theTmpTrajectories.end(); it++){
354 if( it->isValid() ) {
355 it->setSeedRef(collseed->refAt(j));
366 theTmpTrajectories.clear();
368 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
370 { Lock
lock(theMutex);
373 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
376 lastCleanResult=rawResult.size();
385 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
388 #pragma omp parallel for schedule(dynamic,4) 390 for (
size_t j = 0; j < collseed_size; j++){
394 assert(ntseed==collseed_size);
399 #ifdef VI_REPRODUCIBLE 410 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
411 <<
" valid/invalid trajectories ======="<<endl
414 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
417 for(
const auto& traj: rawResult) {
418 if(!traj.isValid()) {
419 const auto seedIndex = traj.seedRef().key();
426 vector<Trajectory> & unsmoothedResult(rawResult);
427 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
429 unsmoothedResult.end());
430 unsmoothedResult.shrink_to_fit();
433 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
435 if (it->lastMeasurement().updatedState().isValid() &&
436 it->lastMeasurement().recHit().get() !=
nullptr &&
437 it->lastMeasurement().recHit()->isValid()) {
445 auto initId = it->lastMeasurement().recHitR().rawId();
448 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
457 trajectory.
reserve(meas.size());
458 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
464 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
474 output->reserve(unsmoothedResult.size());
477 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
478 it != unsmoothedResult.end(); ++it) {
480 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
482 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
485 viTotHits+=recHits.
size();
488 LogDebug(
"CkfPattern") <<
"getting initial state.";
490 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
496 LogDebug(
"CkfPattern") <<
"removing last hit";
497 trialTrajectory.
pop();
506 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
507 }
while(failed && trialTrajectory.
foundHits() > 3);
510 const auto seedIndex = it->seedRef().key();
519 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
521 if (!propagated.
isValid())
continue;
526 initState.second->geographicalId().rawId());
527 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
528 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
534 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info ==========" 535 <<
"number of Seed: " << collseed->size()<<
'\n' 538 assert(viTotHits>=0);
T getParameter(std::string const &) const
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
static boost::mutex mutex
bool getByToken(EDGetToken token, Handle< PROD > &result) const
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
virtual void done()=0
Tells the cleaner that the seeds are finished, and so it can clear any cache it has.
void reserve(unsigned int n)
const Plane & surface() const
The nominal surface of the GeomDet.
const std::string theMagFieldName
unsigned int theMaxNSeeds
virtual void add(const Trajectory *traj)=0
Informs the cleaner that a new trajectory has been made, in case the cleaner keeps a local collection...
virtual bool good(const TrajectorySeed *seed)=0
Returns true if the seed is not overlapping with another trajectory.
static std::string regressionTest(const TrackerGeometry &tracker, std::vector< Trajectory > &unsmoothedResult)
edm::EDGetTokenT< PixelClusterMask > maskPixels_
std::vector< TrajectoryMeasurement > DataContainer
reverseTrajectories
reverse trajectories after pattern-reco creating new seed on last hit
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
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)
virtual void init(const std::vector< Trajectory > *vect)=0
Provides the cleaner a pointer to the vector where trajectories are stored, in case it does not want ...
bool cleanTrajectoryAfterInOut
T get(const Candidate &c)
RedundantSeedCleaner * theSeedCleaner
edm::ESHandle< MagneticField > theMagField