CMS 3D CMS Logo

InOutConversionTrackFinder.cc
Go to the documentation of this file.
2 //
4 
5 //
8 //
13 //
15 //
17 
18 #include <sstream>
19 
21  const BaseCkfTrajectoryBuilder* trajectoryBuilder,
23  : ConversionTrackFinder(conf, trajectoryBuilder, iC) {
25 
26  // get the seed cleaner
27  std::string cleaner = conf.getParameter<std::string>("InOutRedundantSeedCleaner");
28  if (cleaner == "CachingSeedCleanerBySharedInput") {
30  } else if (cleaner == "none") {
31  theSeedCleaner_ = nullptr;
32  } else {
33  throw cms::Exception("InOutRedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput or none",
34  cleaner);
35  }
36 }
37 
39  delete theTrajectoryCleaner_;
40  if (theSeedCleaner_)
41  delete theSeedCleaner_;
42 }
43 
44 std::vector<Trajectory> InOutConversionTrackFinder::tracks(const TrajectorySeedCollection& inOutSeeds,
45  TrackCandidateCollection& output_p) const {
46  // std::cout << " InOutConversionTrackFinder::tracks getting " << inOutSeeds.size() << " In-Out seeds " << "\n";
47 
48  std::vector<Trajectory> tmpO;
49  tmpO.erase(tmpO.begin(), tmpO.end());
50 
51  std::vector<Trajectory> result;
52  result.erase(result.begin(), result.end());
53 
54  std::vector<Trajectory> rawResult;
55  if (theSeedCleaner_)
56  theSeedCleaner_->init(&rawResult);
57 
58  // Loop over the seeds
59  int goodSeed = 0;
60  for (TrajectorySeedCollection::const_iterator iSeed = inOutSeeds.begin(); iSeed != inOutSeeds.end(); iSeed++) {
61  if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
62  goodSeed++;
63 
64  LogDebug("InOutConversionTrackFinder")
65  << " InOutConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
66  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state position "
67  << iSeed->startingState().parameters().position() << " momentum "
68  << iSeed->startingState().parameters().momentum() << " charge "
69  << iSeed->startingState().parameters().charge() << "\n";
70  LogDebug("InOutConversionTrackFinder")
71  << " InOutConversionTrackFinder::tracks seed starting state para, vector "
72  << iSeed->startingState().parameters().vector() << "\n";
73 
74  std::vector<Trajectory> theTmpTrajectories;
75 
76  theTmpTrajectories = theCkfTrajectoryBuilder_->trajectories(*iSeed);
77 
78  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track returned "
79  << theTmpTrajectories.size() << " trajectories for this seed "
80  << "\n";
81 
82  theTrajectoryCleaner_->clean(theTmpTrajectories);
83 
84  for (std::vector<Trajectory>::const_iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end();
85  it++) {
86  if (it->isValid()) {
87  rawResult.push_back(*it);
88  if (theSeedCleaner_)
89  theSeedCleaner_->add(&(*it));
90  }
91  }
92  }
93  } // end loop over the seeds
94 
95  LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track Good seeds " << goodSeed << "\n";
96  LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track rawResult size after cleaning "
97  << rawResult.size() << "\n";
98 
99  if (theSeedCleaner_)
101 
102  std::vector<Trajectory> unsmoothedResult;
103  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Start second cleaning "
104  << "\n";
105  theTrajectoryCleaner_->clean(rawResult);
106  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult size after cleaning "
107  << rawResult.size() << "\n";
108 
109  int tra = 0;
110  for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
111  tra++;
112  LogDebug("InOutConversionTrackFinder")
113  << " InOutConversionTrackFinder looping of rawResult after cleaning " << tra << "\n";
114  if ((*itraw).isValid()) {
115  // unsmoothedResult.push_back( *itraw);
116  tmpO.push_back(*itraw);
117  LogDebug("InOutConversionTrackFinder")
118  << " InOutConversionTrackFinder::track rawResult num of valid recHits per trajectory " << (*itraw).foundHits()
119  << "\n";
120  }
121  }
122 
123  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO size " << tmpO.size()
124  << " before sorting "
125  << "\n";
126  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
127  // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO num of hits " << (*it).foundHits() << " before ordering " << "\n";
128  //}
129 
130  precomputed_value_sort(tmpO.begin(), tmpO.end(), ExtractNumOfHits());
131 
132  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO after sorting "
133  << "\n";
134  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
135  // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO num of hits " << (*it).foundHits() << "\n";
136  // }
137 
138  for (int i = tmpO.size() - 1; i >= 0; i--) {
139  unsmoothedResult.push_back(tmpO[i]);
140  }
141  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder unsmoothedResult size "
142  << unsmoothedResult.size() << "\n";
143 
144  // for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
145  // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder unsmoothedResult after reordering " <<(*it).foundHits() << "\n";
146  // }
147 
148  // Convert to TrackCandidates and fill in the output_p
150  for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
152  if (it->direction() != alongMomentum)
153  LogDebug("InOutConversionTrackFinder") << "InOutConv not along momentum... " << std::endl;
154 
155  t2t(*it, recHits, useSplitHits_);
156 
157  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState(*it);
158 
159  // temporary protection againt invalid initial states
160  if ((!initState.first.isValid()) | (initState.second == nullptr)) {
161  LogDebug("InOutConversionTrackFinder") << "invalid innerState, will not make TrackCandidate" << std::endl;
162  continue;
163  }
164 
166  if (useSplitHits_ && (initState.second != recHits.front().det()) && recHits.front().det()) {
167  TrajectoryStateOnSurface propagated =
168  thePropagator_->propagate(initState.first, recHits.front().det()->surface());
169  if (!propagated.isValid())
170  continue;
171  state = trajectoryStateTransform::persistentState(propagated, recHits.front().rawId());
172  } else
173  state = trajectoryStateTransform::persistentState(initState.first, initState.second->geographicalId().rawId());
174 
175  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Making the result: seed position "
176  << it->seed().startingState().parameters().position() << " seed momentum "
177  << it->seed().startingState().parameters().momentum() << " charge "
178  << it->seed().startingState().parameters().charge() << "\n";
179  LogDebug("InOutConversionTrackFinder")
180  << " InOutConversionTrackFinder::track TSOS charge " << initState.first.charge() << "\n";
181 
182  LogDebug("InOutConversionTrackFinder")
183  << " InOutConversionTrackFinder::track PTrajectoryStateOnDet* state position "
184  << state.parameters().position() << " momentum " << state.parameters().momentum() << " charge "
185  << state.parameters().charge() << "\n";
186 
187  result.push_back(*it);
188  output_p.push_back(TrackCandidate(recHits, it->seed(), state));
189  }
190  // assert(result.size()==output_p.size());
191  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Returning " << result.size()
192  << " valid In Out Trajectories "
193  << "\n";
194  return result;
195 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
TrajectoryCleanerBySharedHits * theTrajectoryCleaner_
edm::ESHandle< Propagator > thePropagator_
std::vector< TrackCandidate > TrackCandidateCollection
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
InOutConversionTrackFinder(const edm::ParameterSet &config, const BaseCkfTrajectoryBuilder *trajectoryBuilder, edm::ConsumesCollector iC)
std::unique_ptr< TransientInitialStateEstimator > theInitialState_
virtual void done()=0
Tells the cleaner that the seeds are finished, and so it can clear any cache it has.
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
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.
void clean(TrajectoryPointerContainer &) const override
std::vector< TrajectorySeed > TrajectorySeedCollection
RedundantSeedCleaner * theSeedCleaner_
virtual TrajectoryContainer trajectories(const TrajectorySeed &) const =0
const TransientTrackingRecHitBuilder * hitBuilder() const
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
std::vector< Trajectory > tracks(const TrajectorySeedCollection &seeds, TrackCandidateCollection &candidate) const override
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 ...
#define LogDebug(id)
const BaseCkfTrajectoryBuilder * theCkfTrajectoryBuilder_