48 #include "tbb/parallel_for.h" 64 theTrackCandidateOutput(
true),
65 theTrajectoryOutput(
false),
66 useSplitting(conf.getParameter<bool>(
"useHitsSplitting")),
69 reverseTrajectories(conf.existsAs<bool>(
"reverseTrajectories") && conf.getParameter<bool>(
"reverseTrajectories")),
70 produceSeedStopReasons_(
false),
71 theMaxNSeeds(conf.getParameter<unsigned
int>(
"maxNSeeds")),
72 theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<
edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
73 theTrajectoryCleanerName(conf.getParameter<
std::
string>(
"TrajectoryCleaner")),
74 theTrajectoryCleaner(0),
76 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<
std::
string>(
"SimpleMagneticField") :
""),
77 theNavigationSchoolName(conf.getParameter<
std::
string>(
"NavigationSchool")),
78 theNavigationSchool(0),
80 maxSeedsBeforeCleaning_(0),
83 phase2skipClusters_(
false)
86 #ifndef VI_REPRODUCIBLE 87 if ( conf.
exists(
"maxSeedsBeforeCleaning") )
101 #ifndef VI_REPRODUCIBLE 103 if (cleaner ==
"SeedCleanerByHitPosition") {
105 }
else if (cleaner ==
"SeedCleanerBySharedInput") {
107 }
else if (cleaner ==
"CachingSeedCleanerByHitPosition") {
109 }
else if (cleaner ==
"CachingSeedCleanerBySharedInput") {
112 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner") ?
113 conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner") :
false;
115 }
else if (cleaner ==
"none") {
122 #ifdef VI_REPRODUCIBLE 123 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
180 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
186 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
195 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
211 auto output = std::make_unique<TrackCandidateCollection>();
212 auto outputT = std::make_unique<std::vector<Trajectory>>();
213 std::unique_ptr<std::vector<short> > outputSeedStopReasons;
219 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
227 if ((*collseed).size()>0){
229 unsigned int lastCleanResult=0;
230 std::vector<Trajectory> rawResult;
231 rawResult.reserve(collseed->size() * 4);
240 using Lock = std::unique_lock<std::mutex>;
243 size_t collseed_size = collseed->size();
245 unsigned int indeces[collseed_size];
for (
auto i=0
U;
i< collseed_size; ++
i) indeces[
i]=
i;
255 auto const & seeds = *collseed;
258 float val[collseed_size];
259 for (
auto i=0
U;
i< collseed_size; ++
i)
260 { val[
i] = seeds[
i].startingState().pt();};
276 std::sort(indeces,indeces+collseed_size, [&](
unsigned int i,
unsigned int j){
return val[
i]<val[j];});
282 std::atomic<unsigned int> ntseed(0);
283 auto theLoop = [&](
size_t ii) {
284 auto j = indeces[
ii];
289 std::vector<Trajectory> theTmpTrajectories;
292 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
294 { Lock
lock(theMutex);
297 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<j;
304 theTmpTrajectories.clear();
305 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories,
nullptr );
306 if(theTmpTrajectories.empty()) {
314 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
315 <<
" trajectories from seed " << j <<
" ========\n" 323 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " << theTmpTrajectories.size()
324 <<
" valid trajectories from seed " 325 << j <<
" ========\n" 335 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
336 <<
" valid/invalid trajectories from seed " << j <<
" ========\n" 344 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size() <<
" valid trajectories from seed " 345 << j <<
" ========\n" 348 { Lock
lock(theMutex);
349 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
350 it!=theTmpTrajectories.end(); it++){
351 if( it->isValid() ) {
352 it->setSeedRef(collseed->refAt(j));
363 theTmpTrajectories.clear();
365 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
367 { Lock
lock(theMutex);
370 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
373 lastCleanResult=rawResult.size();
382 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
385 #pragma omp parallel for schedule(dynamic,4) 387 for (
size_t j = 0; j < collseed_size; j++){
391 assert(ntseed==collseed_size);
396 #ifdef VI_REPRODUCIBLE 407 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
408 <<
" valid/invalid trajectories ======="<<endl
411 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
415 for(
const auto& traj: rawResult) {
416 if(!traj.isValid()) {
417 const auto seedIndex = traj.seedRef().key();
425 vector<Trajectory> & unsmoothedResult(rawResult);
426 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
428 unsmoothedResult.end());
429 unsmoothedResult.shrink_to_fit();
432 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
434 if (it->lastMeasurement().updatedState().isValid() &&
435 it->lastMeasurement().recHit().get() != 0 &&
436 it->lastMeasurement().recHit()->isValid()) {
444 auto initId = it->lastMeasurement().recHitR().rawId();
447 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
456 trajectory.
reserve(meas.size());
457 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
463 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
473 output->reserve(unsmoothedResult.size());
476 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
477 it != unsmoothedResult.end(); ++it) {
479 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
481 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
484 viTotHits+=recHits.
size();
487 LogDebug(
"CkfPattern") <<
"getting initial state.";
489 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
495 LogDebug(
"CkfPattern") <<
"removing last hit";
496 trialTrajectory.
pop();
505 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
506 }
while(failed && trialTrajectory.
foundHits() > 3);
510 const auto seedIndex = it->seedRef().key();
520 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
522 if (!propagated.
isValid())
continue;
527 initState.second->geographicalId().rawId());
528 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
529 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
535 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info ==========" 536 <<
"number of Seed: " << collseed->size()<<
'\n' 539 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
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)
bool produceSeedStopReasons_
RedundantSeedCleaner * theSeedCleaner
edm::ESHandle< MagneticField > theMagField