46 #include "tbb/parallel_for.h"
62 theTrackCandidateOutput(
true),
63 theTrajectoryOutput(
false),
64 useSplitting(conf.getParameter<bool>(
"useHitsSplitting")),
65 doSeedingRegionRebuilding(conf.getParameter<bool>(
"doSeedingRegionRebuilding")),
66 cleanTrajectoryAfterInOut(conf.getParameter<bool>(
"cleanTrajectoryAfterInOut")),
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 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 auto theLoop = [&](
size_t j) {
222 vector<Trajectory> theTmpTrajectories;
225 LogDebug(
"CkfPattern") <<
"======== Begin to look for trajectories from seed " <<
j <<
" ========"<<endl;
227 { Lock
lock(theMutex);
230 LogDebug(
"CkfTrackCandidateMakerBase")<<
" Seed cleaning kills seed "<<
j;
235 theTmpTrajectories.clear();
236 auto const & startTraj =
theTrajectoryBuilder->buildTrajectories( (*collseed)[
j], theTmpTrajectories,
nullptr );
239 LogDebug(
"CkfPattern") <<
"======== In-out trajectory building found " << theTmpTrajectories.size()
240 <<
" trajectories from seed " << j <<
" ========"<<endl
248 LogDebug(
"CkfPattern") <<
"======== In-out trajectory cleaning gave the following valid trajectories from seed "
249 << j <<
" ========"<<endl
259 LogDebug(
"CkfPattern") <<
"======== Out-in trajectory building found " << theTmpTrajectories.size()
260 <<
" valid/invalid trajectories from seed " << j <<
" ========"<<endl
268 LogDebug(
"CkfPattern") <<
"======== Trajectory cleaning gave the following valid trajectories from seed "
269 << j <<
" ========"<<endl
272 { Lock
lock(theMutex);
273 for(vector<Trajectory>::iterator it=theTmpTrajectories.begin();
274 it!=theTmpTrajectories.end(); it++){
275 if( it->isValid() ) {
276 it->setSeedRef(collseed->refAt(j));
278 rawResult.push_back(std::move(*it));
286 theTmpTrajectories.clear();
288 LogDebug(
"CkfPattern") <<
"rawResult trajectories found so far = " << rawResult.size();
290 { Lock
lock(theMutex);
293 rawResult.erase(std::remove_if(rawResult.begin()+lastCleanResult,rawResult.end(),
296 lastCleanResult=rawResult.size();
305 tbb::parallel_for(0UL,collseed_size,1UL,theLoop);
308 #pragma omp parallel for schedule(dynamic,4)
310 for (
size_t j = 0;
j < collseed_size;
j++){
324 LogDebug(
"CkfPattern") <<
"======== Final cleaning of entire event found " << rawResult.size()
325 <<
" valid/invalid trajectories ======="<<endl
328 LogDebug(
"CkfPattern") <<
"removing invalid trajectories.";
330 vector<Trajectory> & unsmoothedResult(rawResult);
331 unsmoothedResult.erase(std::remove_if(unsmoothedResult.begin(),unsmoothedResult.end(),
333 unsmoothedResult.end());
334 unsmoothedResult.shrink_to_fit();
337 for (
auto it = unsmoothedResult.begin(), ed = unsmoothedResult.end(); it != ed; ++it) {
339 if (it->lastMeasurement().updatedState().isValid() &&
340 it->lastMeasurement().recHit().get() != 0 &&
341 it->lastMeasurement().recHit()->isValid()) {
349 auto initId = it->lastMeasurement().recHitR().rawId();
352 hits.
push_back(it->lastMeasurement().recHit()->hit()->clone());
353 boost::shared_ptr<const TrajectorySeed>
seed(
new TrajectorySeed(state, std::move(hits), direction));
360 trajectory.
reserve(meas.size());
361 for (
auto itmeas = meas.rbegin(), endmeas = meas.rend(); itmeas != endmeas; ++itmeas) {
362 trajectory.
push(std::move(*itmeas));
365 (*it)= std::move(trajectory);
367 edm::LogWarning(
"CkfPattern_InvalidLastMeasurement") <<
"Last measurement of the trajectory is invalid, cannot reverse it";
377 output->reserve(unsmoothedResult.size());
380 for (vector<Trajectory>::const_iterator it = unsmoothedResult.begin();
381 it != unsmoothedResult.end(); ++it) {
383 LogDebug(
"CkfPattern") <<
"copying "<<(
useSplitting?
"splitted":
"un-splitted")<<
" hits from trajectory";
385 if(it->direction() !=
alongMomentum)
LogDebug(
"CkfPattern") <<
"not along momentum... " << std::endl;
388 viTotHits+=recHits.
size();
390 LogDebug(
"CkfPattern") <<
"getting initial state.";
392 std::pair<TrajectoryStateOnSurface, const GeomDet*> && initState =
theInitialState->innerState( *it , doBackFit);
395 if ( !initState.first.isValid() || initState.second ==
nullptr ||
edm::isNotFinite(initState.first.globalPosition().x())) {
402 LogDebug(
"CkfPattern") <<
"propagating to hit front in case of splitting.";
404 if (!propagated.
isValid())
continue;
409 initState.second->geographicalId().rawId());
410 LogDebug(
"CkfPattern") <<
"pushing a TrackCandidate.";
411 output->emplace_back(recHits,it->seed(),state,it->seedRef(),it->nLoops());
417 LogTrace(
"CkfPattern|TrackingRegressionTest") <<
"========== CkfTrackCandidateMaker Info =========="
418 <<
"number of Seed: " << collseed->size()<<endl
421 assert(viTotHits>=0);
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_
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
tuple MeasurementTrackerEvent
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)
std::unique_ptr< BaseCkfTrajectoryBuilder > theTrajectoryBuilder
virtual void clean(TrajectoryContainer &) const
edm::EDGetTokenT< MeasurementTrackerEvent > theMTELabel
unsigned int maxSeedsBeforeCleaning_
edm::EDGetTokenT< edm::View< TrajectorySeed > > theSeedLabel
std::string theTrajectoryCleanerName
T const * product() const
bool doSeedingRegionRebuilding
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]
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