test
CMS 3D CMS Logo

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