47 #include "tbb/parallel_for.h"
63 theTrackCandidateOutput(
true),
64 theTrajectoryOutput(
false),
65 useSplitting(conf.getParameter<bool>(
"useHitsSplitting")),
68 reverseTrajectories(conf.existsAs<bool>(
"reverseTrajectories") && conf.getParameter<bool>(
"reverseTrajectories")),
69 theMaxNSeeds(conf.getParameter<unsigned int>(
"maxNSeeds")),
70 theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
71 theTrajectoryCleanerName(conf.getParameter<std::
string>(
"TrajectoryCleaner")),
72 theTrajectoryCleaner(0),
74 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<std::
string>(
"SimpleMagneticField") :
""),
75 theNavigationSchoolName(conf.getParameter<std::
string>(
"NavigationSchool")),
76 theNavigationSchool(0),
78 maxSeedsBeforeCleaning_(0),
81 phase2skipClusters_(
false)
84 #ifndef VI_REPRODUCIBLE
85 if ( conf.
exists(
"maxSeedsBeforeCleaning") )
99 #ifndef VI_REPRODUCIBLE
101 if (cleaner ==
"SeedCleanerByHitPosition") {
103 }
else if (cleaner ==
"SeedCleanerBySharedInput") {
105 }
else if (cleaner ==
"CachingSeedCleanerByHitPosition") {
107 }
else if (cleaner ==
"CachingSeedCleanerBySharedInput") {
108 int numHitsForSeedCleaner = conf.
existsAs<
int>(
"numHitsForSeedCleaner") ?
110 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner") ?
111 conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner") :
false;
113 }
else if (cleaner ==
"none") {
120 #ifdef VI_REPRODUCIBLE
121 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
178 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
184 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
193 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
209 auto output = std::make_unique<TrackCandidateCollection>();
210 auto outputT = std::make_unique<std::vector<Trajectory>>();
213 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
220 if ((*collseed).size()>0){
222 unsigned int lastCleanResult=0;
223 std::vector<Trajectory> rawResult;
224 rawResult.reserve(collseed->size() * 4);
233 using Lock = std::unique_lock<std::mutex>;
236 size_t collseed_size = collseed->size();
238 unsigned int indeces[collseed_size];
for (
auto i=0U;
i< collseed_size; ++
i) indeces[
i]=
i;
248 auto const & seeds = *collseed;
251 float val[collseed_size];
252 for (
auto i=0U;
i< collseed_size; ++
i)
253 { val[
i] = seeds[
i].startingState().pt();};
269 std::sort(indeces,indeces+collseed_size, [&](
unsigned int i,
unsigned int j){
return val[
i]<val[
j];});
275 std::atomic<unsigned int> ntseed(0);
276 auto theLoop = [&](
size_t ii) {
277 auto j = indeces[
ii];
282 std::vector<Trajectory> theTmpTrajectories;
285 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
287 { Lock
lock(theMutex);
290 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<
j;
296 theTmpTrajectories.clear();
297 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories,
nullptr );
299 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
300 <<
" trajectories from seed " << j <<
" ========\n"
308 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " << theTmpTrajectories.size()
309 <<
" valid trajectories from seed "
310 << j <<
" ========\n"
320 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
321 <<
" valid/invalid trajectories from seed " << j <<
" ========\n"
329 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size() <<
" valid trajectories from seed "
330 << j <<
" ========\n"
333 { Lock
lock(theMutex);
334 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
335 it!=theTmpTrajectories.end(); it++){
336 if( it->isValid() ) {
337 it->setSeedRef(collseed->refAt(j));
347 theTmpTrajectories.clear();
349 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
351 { Lock
lock(theMutex);
354 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
357 lastCleanResult=rawResult.size();
366 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
369 #pragma omp parallel for schedule(dynamic,4)
371 for (
size_t j = 0; j < collseed_size; j++){
375 assert(ntseed==collseed_size);
380 #ifdef VI_REPRODUCIBLE
391 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
392 <<
" valid/invalid trajectories ======="<<endl
395 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
397 vector<Trajectory> & unsmoothedResult(rawResult);
398 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
400 unsmoothedResult.end());
401 unsmoothedResult.shrink_to_fit();
404 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
406 if (it->lastMeasurement().updatedState().isValid() &&
407 it->lastMeasurement().recHit().get() != 0 &&
408 it->lastMeasurement().recHit()->isValid()) {
416 auto initId = it->lastMeasurement().recHitR().rawId();
419 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
428 trajectory.
reserve(meas.size());
429 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
435 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
445 output->reserve(unsmoothedResult.size());
448 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
449 it != unsmoothedResult.end(); ++it) {
451 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
453 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
456 viTotHits+=recHits.
size();
459 LogDebug(
"CkfPattern") <<
"getting initial state.";
461 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
467 LogDebug(
"CkfPattern") <<
"removing last hit";
468 trialTrajectory.
pop();
477 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
478 }
while(failed && trialTrajectory.
foundHits() > 3);
486 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
488 if (!propagated.
isValid())
continue;
493 initState.second->geographicalId().rawId());
494 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
495 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
501 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info =========="
502 <<
"number of Seed: " << collseed->size()<<
'\n'
T getParameter(std::string const &) const
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
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)
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)
tuple reverseTrajectories
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
tuple doSeedingRegionRebuilding
edm::EDGetTokenT< Phase2OTClusterMask > maskPhase2OTs_
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
std::string theTrajectoryCleanerName
T const * product() const
bool doSeedingRegionRebuilding
void setSeedRef(const edm::RefToBase< TrajectorySeed > &seedRef)
tuple MeasurementTrackerEvent
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]
volatile std::atomic< bool > shutdown_flag false
virtual void countSeedsDebugger()
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