46 #include "tbb/parallel_for.h"
62 theTrackCandidateOutput(
true),
63 theTrajectoryOutput(
false),
64 useSplitting(conf.getParameter<bool>(
"useHitsSplitting")),
67 reverseTrajectories(conf.existsAs<bool>(
"reverseTrajectories") && conf.getParameter<bool>(
"reverseTrajectories")),
68 theMaxNSeeds(conf.getParameter<unsigned int>(
"maxNSeeds")),
69 theTrajectoryBuilder(createBaseCkfTrajectoryBuilder(conf.getParameter<edm::
ParameterSet>(
"TrajectoryBuilderPSet"), iC)),
70 theTrajectoryCleanerName(conf.getParameter<std::
string>(
"TrajectoryCleaner")),
71 theTrajectoryCleaner(0),
73 theMagFieldName(conf.exists(
"SimpleMagneticField") ? conf.getParameter<std::
string>(
"SimpleMagneticField") :
""),
74 theNavigationSchoolName(conf.getParameter<std::
string>(
"NavigationSchool")),
75 theNavigationSchool(0),
77 maxSeedsBeforeCleaning_(0),
87 if ( conf.
exists(
"maxSeedsBeforeCleaning") )
97 if (cleaner ==
"SeedCleanerByHitPosition") {
99 }
else if (cleaner ==
"SeedCleanerBySharedInput") {
101 }
else if (cleaner ==
"CachingSeedCleanerByHitPosition") {
103 }
else if (cleaner ==
"CachingSeedCleanerBySharedInput") {
104 int numHitsForSeedCleaner = conf.
existsAs<
int>(
"numHitsForSeedCleaner") ?
106 int onlyPixelHits = conf.
existsAs<
bool>(
"onlyPixelHitsForSeedCleaner") ?
107 conf.
getParameter<
bool>(
"onlyPixelHitsForSeedCleaner") :
false;
109 }
else if (cleaner ==
"none") {
168 std::auto_ptr<MeasurementTrackerEvent> dataWithMasks;
191 std::auto_ptr<std::vector<Trajectory> > outputT (
new std::vector<Trajectory>());
194 LogError(
"TooManySeeds")<<
"Exceeded maximum numeber of seeds! theMaxNSeeds="<<
theMaxNSeeds<<
" nSeed="<<(*collseed).size();
201 if ((*collseed).size()>0){
203 unsigned int lastCleanResult=0;
204 std::vector<Trajectory> rawResult;
205 rawResult.reserve(collseed->size() * 4);
214 using Lock = std::unique_lock<std::mutex>;
217 size_t collseed_size = collseed->size();
219 unsigned int indeces[collseed_size];
for (
auto i=0U;
i< collseed_size; ++
i) indeces[
i]=
i;
254 auto theLoop = [&](
size_t ii) {
255 auto j = indeces[
ii];
258 std::vector<Trajectory> theTmpTrajectories;
261 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " <<
j <<
" ========"<<endl;
263 { Lock
lock(theMutex);
266 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<
j;
271 theTmpTrajectories.clear();
272 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[
j], theTmpTrajectories,
nullptr );
275 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
276 <<
" trajectories from seed " << j <<
" ========"<<endl
284 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following valid trajectories from seed "
285 << j <<
" ========"<<endl
295 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
296 <<
" valid/invalid trajectories from seed " << j <<
" ========"<<endl
304 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following valid trajectories from seed "
305 << j <<
" ========"<<endl
308 { Lock
lock(theMutex);
309 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
310 it!=theTmpTrajectories.end(); it++){
311 if( it->isValid() ) {
312 it->setSeedRef(collseed->refAt(j));
314 rawResult.push_back(std::move(*it));
322 theTmpTrajectories.clear();
324 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
326 { Lock
lock(theMutex);
329 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
332 lastCleanResult=rawResult.size();
341 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
344 #pragma omp parallel for schedule(dynamic,4)
346 for (
size_t j = 0;
j < collseed_size;
j++){
360 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
361 <<
" valid/invalid trajectories ======="<<endl
364 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
366 vector<Trajectory> & unsmoothedResult(rawResult);
367 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
369 unsmoothedResult.end());
370 unsmoothedResult.shrink_to_fit();
373 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
375 if (it->lastMeasurement().updatedState().isValid() &&
376 it->lastMeasurement().recHit().get() != 0 &&
377 it->lastMeasurement().recHit()->isValid()) {
385 auto initId = it->lastMeasurement().recHitR().rawId();
388 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
389 boost::shared_ptr<const TrajectorySeed>
seed(
new TrajectorySeed(state, std::move(hits), direction));
396 trajectory.
reserve(meas.size());
397 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
398 trajectory.
push(std::move(*itmeas));
401 (*it)= std::move(trajectory);
403 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
413 output->reserve(unsmoothedResult.size());
416 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
417 it != unsmoothedResult.end(); ++it) {
419 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
421 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
424 viTotHits+=recHits.
size();
427 LogDebug(
"CkfPattern") <<
"getting initial state.";
429 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState;
435 LogDebug(
"CkfPattern") <<
"removing last hit";
436 trialTrajectory.
pop();
445 failed = (!initState.first.isValid()) || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x());
446 }
while(failed && trialTrajectory.
foundHits() > 3);
454 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
456 if (!propagated.
isValid())
continue;
461 initState.second->geographicalId().rawId());
462 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
463 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops());
469 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info =========="
470 <<
"number of Seed: " << collseed->size()<<endl
virtual ~CkfTrackCandidateMakerBase()
T getParameter(std::string const &) const
virtual void deleteAssocDebugger()
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_
tuple cleanTrajectoryAfterInOut
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)
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)
tuple reverseTrajectories
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
virtual void clean(TrajectoryContainer &) const
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
unsigned int maxSeedsBeforeCleaning_
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)
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