CMS 3D CMS Logo

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