CMS 3D CMS Logo

OutInConversionTrackFinder.cc
Go to the documentation of this file.
2 //
5 //
7 //
8 
12 
13 //
15 //
17 //
19 
21  const BaseCkfTrajectoryBuilder* trajectoryBuilder)
22  : ConversionTrackFinder(conf, trajectoryBuilder) {
24 
25  // get the seed cleaner
26  std::string cleaner = conf.getParameter<std::string>("OutInRedundantSeedCleaner");
27  if (cleaner == "CachingSeedCleanerBySharedInput") {
29  } else if (cleaner == "none") {
30  theSeedCleaner_ = nullptr;
31  } else {
32  throw cms::Exception("OutInRedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput or none",
33  cleaner);
34  }
35 }
36 
38  delete theTrajectoryCleaner_;
39  if (theSeedCleaner_)
40  delete theSeedCleaner_;
41 }
42 
43 std::vector<Trajectory> OutInConversionTrackFinder::tracks(const TrajectorySeedCollection& outInSeeds,
44  TrackCandidateCollection& output_p) const {
45  // std::cout << "OutInConversionTrackFinder::tracks getting " << outInSeeds.size() << " Out-In seeds " << "\n";;
46 
47  std::vector<Trajectory> tmpO;
48  tmpO.erase(tmpO.begin(), tmpO.end());
49 
50  std::vector<Trajectory> result;
51  result.erase(result.begin(), result.end());
52 
53  std::vector<Trajectory> rawResult;
54  if (theSeedCleaner_)
55  theSeedCleaner_->init(&rawResult);
56 
58  /*
59  for(TrajectorySeedCollection::const_iterator iSeed=outInSeeds.begin(); iSeed!=outInSeeds.end();iSeed++){
60  DetId tmpId = DetId( iSeed->startingState().detId());
61  const GeomDet* tmpDet = theMeasurementTracker_->geomTracker()->idToDet( tmpId );
62  GlobalVector gv = tmpDet->surface().toGlobal( iSeed->startingState().parameters().momentum() );
63 
64  LogDebug("OutInConversionTrackFinder") << " OutInConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
65  LogDebug("OutInConversionTrackFinder")<< " OutInConversionTrackFinder::tracks seed starting state position " << iSeed->startingState().parameters().position() << " momentum " << iSeed->startingState().parameters().momentum() << " charge " << iSeed->startingState().parameters().charge() << " R " << gv.perp() << " eta " << gv.eta() << " phi " << gv.phi() << "\n";
66 
67  TrajectorySeed::range hitRange = iSeed->recHits();
68  for (TrajectorySeed::const_iterator ihit = hitRange.first; ihit != hitRange.second; ihit++) {
69 
70  if ( ihit->isValid() ) {
71 
72  LogDebug("OutInConversionTrackFinder") << " Valid hit global position " << theMeasurementTracker_->geomTracker()->idToDet((ihit)->geographicalId())->surface().toGlobal((ihit)->localPosition()) << " R " << theMeasurementTracker_->geomTracker()->idToDet((ihit)->geographicalId())->surface().toGlobal((ihit)->localPosition()).perp() << " phi " << theMeasurementTracker_->geomTracker()->idToDet((ihit)->geographicalId())->surface().toGlobal((ihit)->localPosition()).phi() << " eta " << theMeasurementTracker_->geomTracker()->idToDet((ihit)->geographicalId())->surface().toGlobal((ihit)->localPosition()).eta() << "\n" ;
73 
74  }
75  }
76  }
77 
78  */
79 
80  int goodSeed = 0;
81  std::vector<Trajectory> theTmpTrajectories;
82  for (TrajectorySeedCollection::const_iterator iSeed = outInSeeds.begin(); iSeed != outInSeeds.end(); iSeed++) {
83  theTmpTrajectories.clear();
84 
85  if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
86  goodSeed++;
87 
88  DetId tmpId = DetId(iSeed->startingState().detId());
89  const GeomDet* tmpDet = theMeasurementTracker_->geomTracker()->idToDet(tmpId);
90  GlobalVector gv = tmpDet->surface().toGlobal(iSeed->startingState().parameters().momentum());
91 
92  // std::cout << " OutInConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
93  LogDebug("OutInConversionTrackFinder") << " OutInConversionTrackFinder::tracks seed starting state position "
94  << iSeed->startingState().parameters().position() << " momentum "
95  << iSeed->startingState().parameters().momentum() << " charge "
96  << iSeed->startingState().parameters().charge() << " R " << gv.perp()
97  << " eta " << gv.eta() << " phi " << gv.phi() << "\n";
98 
99  theCkfTrajectoryBuilder_->trajectories(*iSeed, theTmpTrajectories);
100 
101  LogDebug("OutInConversionTrackFinder")
102  << "OutInConversionTrackFinder::track returned " << theTmpTrajectories.size() << " trajectories"
103  << "\n";
104 
105  theTrajectoryCleaner_->clean(theTmpTrajectories);
106 
107  for (std::vector<Trajectory>::const_iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end();
108  it++) {
109  if (it->isValid()) {
110  rawResult.push_back(*it);
111  if (theSeedCleaner_)
112  theSeedCleaner_->add(&(*it));
113  }
114  }
115  }
116  } // end loop over the seeds
117  LogDebug("OutInConversionTrackFinder") << " OutInConversionTrackFinder::track Good seeds " << goodSeed << "\n";
118  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder::track rawResult size after cleaning "
119  << rawResult.size() << "\n";
120 
121  if (theSeedCleaner_)
123 
124  std::vector<Trajectory> unsmoothedResult;
125  theTrajectoryCleaner_->clean(rawResult);
126 
127  for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
128  if ((*itraw).isValid()) {
129  tmpO.push_back(*itraw);
130  LogDebug("OutInConversionTrackFinder") << " rawResult num hits " << (*itraw).foundHits() << "\n";
131  }
132  }
133 
134  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO size " << tmpO.size()
135  << " before sorting "
136  << "\n";
137  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
138  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO num of hits " << (*it).foundHits() << " before ordering " << "\n";
139  // }
140 
141  precomputed_value_sort(tmpO.begin(), tmpO.end(), ExtractNumOfHits());
142 
143  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO after sorting "
144  << "\n";
145  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
146  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO num of hits " << (*it).foundHits() << "\n";
147  // }
148 
149  for (int i = tmpO.size() - 1; i >= 0; i--) {
150  unsmoothedResult.push_back(tmpO[i]);
151  }
152  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder unsmoothedResult size "
153  << unsmoothedResult.size() << "\n";
154 
155  // for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
156  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder unsmoothedResult after reordering " <<(*it).foundHits() << "\n";
157  // }
158 
159  // Check if the inner state is valid
160  tmpO.clear();
161  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO size " << tmpO.size()
162  << " after clearing "
163  << "\n";
164  for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
165  if (!it->isValid())
166  continue;
167 
168  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState(*it);
169  // LogDebug("OutInConversionTrackFinder") << " Initial state parameters " << initState.first << "\n";
170 
171  // temporary protection againt invalid initial states
172  if (!initState.first.isValid() || initState.second == nullptr) {
173  LogDebug("OutInConversionTrackFinder") << "invalid innerState, will not make TrackCandidate"
174  << "\n";
175  ;
176  continue;
177  }
178  tmpO.push_back(*it);
179  }
180 
181  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO size " << tmpO.size() << " after filling "
182  << "\n";
183  if (!tmpO.empty()) {
184  std::vector<Trajectory>::iterator it = tmpO.begin();
185 
186  // only send out the two best tracks
187  result.push_back(*it);
188  if (tmpO.size() > 1)
189  result.push_back(*(++it));
190  }
191 
192  // for (std::vector<Trajectory>::const_iterator it =result.begin(); it != result.end(); it++) {
193  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder Result num of hits " << (*it).foundHits() << "\n";
194  //}
195 
196  // Convert to TrackCandidates and fill in the output_p
198  for (std::vector<Trajectory>::const_iterator it = result.begin(); it != result.end(); it++) {
200  if (it->direction() == alongMomentum)
201  LogDebug("OutInConversionTrackFinder") << "OutInConv along momentum... " << std::endl;
202  t2t(*it, recHits, useSplitHits_);
203 
204  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState(*it);
205 
206  assert(initState.second == recHits.front().det());
207 
208  // temporary protection againt invalid initial states
209  if (!initState.first.isValid() || initState.second == nullptr) {
210  LogDebug("OutInConversionTrackFinder") << "invalid innerState, will not make TrackCandidate" << std::endl;
211  continue;
212  }
213 
214  PTrajectoryStateOnDet state;
215  if (useSplitHits_ && (initState.second != recHits.front().det()) && recHits.front().det()) {
216  TrajectoryStateOnSurface propagated =
217  thePropagator_->propagate(initState.first, recHits.front().det()->surface());
218  if (!propagated.isValid())
219  continue;
220  state = trajectoryStateTransform::persistentState(propagated, recHits.front().rawId());
221  } else
222  state = trajectoryStateTransform::persistentState(initState.first, initState.second->geographicalId().rawId());
223 
224  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder Number of hits for the track candidate "
225  << recHits.size() << " TSOS charge " << initState.first.charge() << "\n";
226 
227  output_p.push_back(TrackCandidate(recHits, it->seed(), state));
228  }
229 
230  // std::cout << " Returning " << result.size() << "Out In Trajectories " << "\n";
231 
232  return result;
233 }
#define LogDebug(id)
T getParameter(std::string const &) const
T perp() const
Definition: PV3DBase.h:69
edm::ESHandle< Propagator > thePropagator_
std::vector< TrackCandidate > TrackCandidateCollection
OutInConversionTrackFinder(const edm::ParameterSet &config, const BaseCkfTrajectoryBuilder *trajectoryBuilder)
size_type size() const
Definition: OwnVector.h:300
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
std::unique_ptr< TransientInitialStateEstimator > theInitialState_
virtual const GeomDet * idToDet(DetId) const =0
virtual void done()=0
Tells the cleaner that the seeds are finished, and so it can clear any cache it has.
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
virtual TrajectoryContainer trajectories(const TrajectorySeed &) const =0
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.
const TransientTrackingRecHitBuilder * hitBuilder() const
std::vector< TrajectorySeed > TrajectorySeedCollection
const GeomDet * det() const
void clean(TrajectoryPointerContainer &) const override
const TrackingGeometry * geomTracker() const
Definition: DetId.h:17
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr, const Compare &comp)
RedundantSeedCleaner * theSeedCleaner_
TrajectoryCleanerBySharedHits * theTrajectoryCleaner_
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
T eta() const
Definition: PV3DBase.h:73
std::vector< Trajectory > tracks(const TrajectorySeedCollection &seeds, TrackCandidateCollection &candidates) const override
const MeasurementTracker * theMeasurementTracker_
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 ...
reference front()
Definition: OwnVector.h:459
id_type rawId() const
const BaseCkfTrajectoryBuilder * theCkfTrajectoryBuilder_