50 #include "tbb/parallel_for.h"
66 theTrackCandidateOutput(
true),
67 theTrajectoryOutput(
false),
68 useSplitting(conf.getParameter<bool>(
"useHitsSplitting")),
71 reverseTrajectories(conf.existsAs<bool>(
"reverseTrajectories") && conf.getParameter<bool>(
"reverseTrajectories")),
72 theMaxNSeeds(conf.getParameter<unsigned int>(
"maxNSeeds")),
73 theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
74 theTrajectoryCleanerName(conf.getParameter<std::
string>(
"TrajectoryCleaner")),
75 theTrajectoryCleaner(0),
77 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<std::
string>(
"SimpleMagneticField") :
""),
78 theNavigationSchoolName(conf.getParameter<std::
string>(
"NavigationSchool")),
79 theNavigationSchool(0),
81 maxSeedsBeforeCleaning_(0),
91 #ifndef VI_REPRODUCIBLE
92 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") {
109 int numHitsForSeedCleaner = conf.
existsAs<
int>(
"numHitsForSeedCleaner") ?
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::auto_ptr<MeasurementTrackerEvent> dataWithMasks;
202 std::auto_ptr<std::vector<Trajectory> > outputT (
new std::vector<Trajectory>());
205 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
212 if ((*collseed).size()>0){
214 unsigned int lastCleanResult=0;
215 std::vector<Trajectory> rawResult;
216 rawResult.reserve(collseed->size() * 4);
225 using Lock = std::unique_lock<std::mutex>;
228 size_t collseed_size = collseed->size();
230 unsigned int indeces[collseed_size];
for (
auto i=0U;
i< collseed_size; ++
i) indeces[
i]=
i;
240 auto const & seeds = *collseed;
243 float val[collseed_size];
244 for (
auto i=0U;
i< collseed_size; ++
i)
245 { val[
i] = seeds[
i].startingState().pt();};
261 std::sort(indeces,indeces+collseed_size, [&](
unsigned int i,
unsigned int j){
return val[
i]<val[
j];});
267 std::atomic<unsigned int> ntseed(0);
268 auto theLoop = [&](
size_t ii) {
269 auto j = indeces[
ii];
274 std::vector<Trajectory> theTmpTrajectories;
277 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " << j <<
" ========"<<endl;
279 { Lock
lock(theMutex);
282 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<
j;
287 theTmpTrajectories.clear();
288 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[j], theTmpTrajectories,
nullptr );
290 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
291 <<
" trajectories from seed " << j <<
" ========"<<endl
299 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following valid trajectories from seed "
300 << j <<
" ========"<<endl
310 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
311 <<
" valid/invalid trajectories from seed " << j <<
" ========"<<endl
319 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following valid trajectories from seed "
320 << j <<
" ========"<<endl
323 { Lock
lock(theMutex);
324 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
325 it!=theTmpTrajectories.end(); it++){
326 if( it->isValid() ) {
327 it->setSeedRef(collseed->refAt(j));
337 theTmpTrajectories.clear();
339 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
341 { Lock
lock(theMutex);
344 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
347 lastCleanResult=rawResult.size();
356 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
359 #pragma omp parallel for schedule(dynamic,4)
361 for (
size_t j = 0; j < collseed_size; j++){
365 assert(ntseed==collseed_size);
370 #ifdef VI_REPRODUCIBLE
381 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
382 <<
" valid/invalid trajectories ======="<<endl
385 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
387 vector<Trajectory> & unsmoothedResult(rawResult);
388 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
390 unsmoothedResult.end());
391 unsmoothedResult.shrink_to_fit();
394 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
396 if (it->lastMeasurement().updatedState().isValid() &&
397 it->lastMeasurement().recHit().get() != 0 &&
398 it->lastMeasurement().recHit()->isValid()) {
406 auto initId = it->lastMeasurement().recHitR().rawId();
409 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
418 trajectory.
reserve(meas.size());
419 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
425 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
435 output->reserve(unsmoothedResult.size());
438 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
439 it != unsmoothedResult.end(); ++it) {
441 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
443 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
446 viTotHits+=recHits.
size();
449 LogDebug(
"CkfPattern") <<
"getting initial state.";
451 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
457 LogDebug(
"CkfPattern") <<
"removing last hit";
458 trialTrajectory.
pop();
467 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
468 }
while(failed && trialTrajectory.
foundHits() > 3);
476 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
478 if (!propagated.
isValid())
continue;
483 initState.second->geographicalId().rawId());
484 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
485 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops(), (uint8_t)it->stopReason());
491 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info =========="
492 <<
"number of Seed: " << collseed->size()<<endl
virtual ~CkfTrackCandidateMakerBase()
T getParameter(std::string const &) const
virtual void deleteAssocDebugger()
tuple cleanTrajectoryAfterInOut
static std::string dumpCandidates(collection &candidates)
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::vector< TrackCandidate > TrackCandidateCollection
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
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
const GeomDet * det() const
virtual void produceBase(edm::Event &e, const edm::EventSetup &es)
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
virtual void clean(TrajectoryContainer &) const
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
unsigned int maxSeedsBeforeCleaning_
edm::RefToBase< TrajectorySeed > seedRef(void) const
tuple doSeedingRegionRebuilding
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)
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