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")),
76 maxSeedsBeforeCleaning_(0),
79 phase2skipClusters_(
false)
82 #ifndef VI_REPRODUCIBLE 83 if ( conf.
exists(
"maxSeedsBeforeCleaning") )
97 #ifndef VI_REPRODUCIBLE 99 if (cleaner ==
"CachingSeedCleanerBySharedInput") {
102 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner") ?
103 conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner") :
false;
105 }
else if (cleaner ==
"none") {
108 throw cms::Exception(
"RedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput ro none", cleaner);
112 #ifdef VI_REPRODUCIBLE 113 std::cout <<
"CkfTrackCandidateMaker in reproducible setting" << std::endl;
170 std::unique_ptr<MeasurementTrackerEvent> dataWithMasks;
176 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *stripMask, *pixelMask);
185 dataWithMasks = std::make_unique<MeasurementTrackerEvent>(*
data, *pixelMask, *phase2OTMask);
201 auto output = std::make_unique<TrackCandidateCollection>();
202 auto outputT = std::make_unique<std::vector<Trajectory>>();
203 auto outputSeedStopInfos = std::make_unique<std::vector<SeedStopInfo> >(collseed->size());
206 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
214 if (!(*collseed).empty()){
216 unsigned int lastCleanResult=0;
217 std::vector<Trajectory> rawResult;
218 rawResult.reserve(collseed->size() * 4);
227 using Lock = std::unique_lock<std::mutex>;
230 size_t collseed_size = collseed->size();
232 unsigned int indeces[collseed_size];
for (
auto i=0
U;
i< collseed_size; ++
i) indeces[
i]=
i;
242 auto const & seeds = *collseed;
245 float val[collseed_size];
246 for (
auto i=0
U;
i< collseed_size; ++
i)
247 { val[
i] = seeds[
i].startingState().pt();};
263 std::sort(indeces,indeces+collseed_size, [&](
unsigned int i,
unsigned int j){
return val[
i]<val[j];});
269 std::atomic<unsigned int> ntseed(0);
270 auto theLoop = [&](
size_t ii) {
271 auto j = indeces[
ii];
276 std::vector<Trajectory> theTmpTrajectories;
279 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========\n";
281 { Lock
lock(theMutex);
284 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<j;
291 theTmpTrajectories.clear();
292 unsigned int nCandPerSeed = 0;
293 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories, nCandPerSeed,
nullptr );
296 (*outputSeedStopInfos)[j].setCandidatesPerSeed(nCandPerSeed);
297 if(theTmpTrajectories.empty()) {
303 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
304 <<
" trajectories from seed " << j <<
" ========\n" 312 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following " << theTmpTrajectories.size()
313 <<
" valid trajectories from seed " 314 << j <<
" ========\n" 324 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
325 <<
" valid/invalid trajectories from seed " << j <<
" ========\n" 327 if(theTmpTrajectories.empty()) {
338 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following " << theTmpTrajectories.size() <<
" valid trajectories from seed " 339 << j <<
" ========\n" 342 { Lock
lock(theMutex);
343 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
344 it!=theTmpTrajectories.end(); it++){
345 if( it->isValid() ) {
346 it->setSeedRef(collseed->refAt(j));
357 theTmpTrajectories.clear();
359 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
361 { Lock
lock(theMutex);
364 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
367 lastCleanResult=rawResult.size();
376 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
379 #pragma omp parallel for schedule(dynamic,4) 381 for (
size_t j = 0; j < collseed_size; j++){
385 assert(ntseed==collseed_size);
390 #ifdef VI_REPRODUCIBLE 401 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
402 <<
" valid/invalid trajectories ======="<<endl
405 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
408 for(
const auto& traj: rawResult) {
409 if(!traj.isValid()) {
410 const auto seedIndex = traj.seedRef().key();
417 vector<Trajectory> & unsmoothedResult(rawResult);
418 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
420 unsmoothedResult.end());
421 unsmoothedResult.shrink_to_fit();
424 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
426 if (it->lastMeasurement().updatedState().isValid() &&
427 it->lastMeasurement().recHit().get() !=
nullptr &&
428 it->lastMeasurement().recHit()->isValid()) {
436 auto initId = it->lastMeasurement().recHitR().rawId();
439 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
448 trajectory.
reserve(meas.size());
449 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
455 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
465 output->reserve(unsmoothedResult.size());
468 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
469 it != unsmoothedResult.end(); ++it) {
471 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
473 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
476 viTotHits+=recHits.
size();
479 LogDebug(
"CkfPattern") <<
"getting initial state.";
481 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
487 LogDebug(
"CkfPattern") <<
"removing last hit";
488 trialTrajectory.
pop();
497 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
498 }
while(failed && trialTrajectory.
foundHits() > 3);
501 const auto seedIndex = it->seedRef().key();
510 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
512 if (!propagated.
isValid())
continue;
517 initState.second->geographicalId().rawId());
518 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
519 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
525 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info ==========" 526 <<
"number of Seed: " << collseed->size()<<
'\n' 529 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)
RedundantSeedCleaner * theSeedCleaner
edm::ESHandle< MagneticField > theMagField