CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutInConversionTrackFinder.cc
Go to the documentation of this file.
2 //
9 //
11 //
12 
16 //
19 //
21 //
23 
24 
25 
27  const edm::ParameterSet& conf ) : ConversionTrackFinder( es, conf )
28 {
29 
30 
32 
33  // get the seed cleaner
34  std::string cleaner = conf_.getParameter<std::string>("OutInRedundantSeedCleaner");
35  if (cleaner == "SeedCleanerByHitPosition") {
37  } else if (cleaner == "CachingSeedCleanerByHitPosition") {
39  } else if (cleaner == "CachingSeedCleanerBySharedInput") {
41  } else if (cleaner == "none") {
42  theSeedCleaner_ = 0;
43  } else {
44  throw cms::Exception("OutInRedundantSeedCleaner not found", cleaner);
45  }
46 
47 
48 
49 
50 
51 }
52 
53 
54 
55 
57 
58  delete theTrajectoryCleaner_;
59  if (theSeedCleaner_) delete theSeedCleaner_;
60 
61 }
62 
63 
64 std::vector<Trajectory> OutInConversionTrackFinder::tracks(const TrajectorySeedCollection outInSeeds,
65  TrackCandidateCollection &output_p ) const {
66 
67 
68  // std::cout << "OutInConversionTrackFinder::tracks getting " << outInSeeds.size() << " Out-In seeds " << "\n";;
69 
70  std::vector<Trajectory> tmpO;
71  tmpO.erase(tmpO.begin(), tmpO.end() ) ;
72 
73  std::vector<Trajectory> result;
74  result.erase(result.begin(), result.end() ) ;
75 
76 
77  std::vector<Trajectory> rawResult;
78  if (theSeedCleaner_) theSeedCleaner_->init( &rawResult );
79 
80 
82  /*
83  for(TrajectorySeedCollection::const_iterator iSeed=outInSeeds.begin(); iSeed!=outInSeeds.end();iSeed++){
84  DetId tmpId = DetId( iSeed->startingState().detId());
85  const GeomDet* tmpDet = theMeasurementTracker_->geomTracker()->idToDet( tmpId );
86  GlobalVector gv = tmpDet->surface().toGlobal( iSeed->startingState().parameters().momentum() );
87 
88  LogDebug("OutInConversionTrackFinder") << " OutInConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
89  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";
90 
91  TrajectorySeed::range hitRange = iSeed->recHits();
92  for (TrajectorySeed::const_iterator ihit = hitRange.first; ihit != hitRange.second; ihit++) {
93 
94  if ( ihit->isValid() ) {
95 
96  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" ;
97 
98  }
99  }
100  }
101 
102  */
103 
104 
105 
106 
107 
108  int goodSeed=0;
109  std::vector<Trajectory> theTmpTrajectories;
110  for(TrajectorySeedCollection::const_iterator iSeed=outInSeeds.begin(); iSeed!=outInSeeds.end();iSeed++){
111 
112  theTmpTrajectories.clear();
113 
114  if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
115  goodSeed++;
116 
117 
118  DetId tmpId = DetId( iSeed->startingState().detId());
119  const GeomDet* tmpDet = theMeasurementTracker_->geomTracker()->idToDet( tmpId );
120  GlobalVector gv = tmpDet->surface().toGlobal( iSeed->startingState().parameters().momentum() );
121 
122  // std::cout << " OutInConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
123  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";
124 
125 
126  theCkfTrajectoryBuilder_->trajectories(*iSeed, theTmpTrajectories);
127 
128  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder::track returned " << theTmpTrajectories.size() << " trajectories" << "\n";
129 
130  theTrajectoryCleaner_->clean(theTmpTrajectories);
131 
132  for(std::vector<Trajectory>::const_iterator it=theTmpTrajectories.begin();
133  it!=theTmpTrajectories.end(); it++){
134  if( it->isValid() ) {
135  rawResult.push_back(*it);
136  if (theSeedCleaner_) theSeedCleaner_->add( & (*it) );
137  }
138  }
139 
140 
141  }
142  } // end loop over the seeds
143  LogDebug("OutInConversionTrackFinder") << " OutInConversionTrackFinder::track Good seeds " << goodSeed << "\n";
144  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";
145 
147 
148  std::vector<Trajectory> unsmoothedResult;
149  theTrajectoryCleaner_->clean(rawResult);
150 
151  for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
152  if((*itraw).isValid()) {
153  tmpO.push_back( *itraw );
154  LogDebug("OutInConversionTrackFinder") << " rawResult num hits " << (*itraw).foundHits() << "\n";
155  }
156  }
157 
158 
159 
160  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO size " << tmpO.size() << " before sorting " << "\n";
161  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
162  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO num of hits " << (*it).foundHits() << " before ordering " << "\n";
163  // }
164 
165  precomputed_value_sort( tmpO.begin(), tmpO.end(), ExtractNumOfHits() );
166 
167 
168  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO after sorting " << "\n";
169  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
170  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO num of hits " << (*it).foundHits() << "\n";
171  // }
172 
173  for (int i=tmpO.size()-1; i>=0; i--) {
174  unsmoothedResult.push_back( tmpO[i] );
175  }
176  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder unsmoothedResult size " << unsmoothedResult.size() << "\n";
177 
178  // for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
179  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder unsmoothedResult after reordering " <<(*it).foundHits() << "\n";
180  // }
181 
182 
183 
184  // Check if the inner state is valid
185  tmpO.clear();
186  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO size " << tmpO.size() << " after clearing " << "\n";
187  for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
188  if( !it->isValid() ) continue;
189 
190  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState( *it);
191  // LogDebug("OutInConversionTrackFinder") << " Initial state parameters " << initState.first << "\n";
192 
193  // temporary protection againt invalid initial states
194  if (! initState.first.isValid() || initState.second == 0) {
195  LogDebug("OutInConversionTrackFinder") << "invalid innerState, will not make TrackCandidate" << "\n";;
196  continue;
197  }
198  tmpO.push_back(*it);
199  }
200 
201 
202  LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder tmpO size " << tmpO.size() << " after filling " << "\n";
203  if ( tmpO.size() ) {
204  std::vector<Trajectory>::iterator it=tmpO.begin();
205 
206  // only send out the two best tracks
207  result.push_back(*it);
208  if ( tmpO.size() > 1) result.push_back(*(++it));
209  }
210 
211  // for (std::vector<Trajectory>::const_iterator it =result.begin(); it != result.end(); it++) {
212  // LogDebug("OutInConversionTrackFinder") << "OutInConversionTrackFinder Result num of hits " << (*it).foundHits() << "\n";
213  //}
214 
215 
216  // Converted to track candidates
217  for (std::vector<Trajectory>::const_iterator it = result.begin(); it != result.end(); it++) {
218  // if( !it->isValid() ) continue;
219 
222  it->recHitsV(thits,useSplitHits_);
223  recHits.reserve(thits.size());
224  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.begin(); hitIt != thits.end(); hitIt++) {
225  recHits.push_back( (**hitIt).hit()->clone());
226  }
227 
228 
229  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState( *it);
230  // temporary protection againt invalid initial states
231  if (! initState.first.isValid() || initState.second == 0) {
232  //cout << "invalid innerState, will not make TrackCandidate" << endl;
233  continue;
234  }
235 
237  if(useSplitHits_ && (initState.second != thits.front()->det()) && thits.front()->det() ){
238  TrajectoryStateOnSurface propagated = thePropagator_->propagate(initState.first,thits.front()->det()->surface());
239  if (!propagated.isValid()) continue;
240  state = TrajectoryStateTransform().persistentState(propagated,
241  thits.front()->det()->geographicalId().rawId());
242  }
243  if(!state) state = TrajectoryStateTransform().persistentState( initState.first,
244  initState.second->geographicalId().rawId());
245 
246  LogDebug("OutInConversionTrackFinder")<< "OutInConversionTrackFinder Number of hits for the track candidate " << recHits.size() << " TSOS charge " << initState.first.charge() << "\n";
247  output_p.push_back(TrackCandidate(recHits, it->seed(),*state ) );
248  delete state;
249  }
250 
251 
252  // std::cout << " Returning " << result.size() << "Out In Trajectories " << "\n";
253 
254 
255  return result;
256 
257 
258 
259 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const TrajectoryBuilder * theCkfTrajectoryBuilder_
T perp() const
Definition: PV3DBase.h:66
edm::ESHandle< Propagator > thePropagator_
std::vector< TrackCandidate > TrackCandidateCollection
size_type size() const
Definition: OwnVector.h:262
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
virtual void clean(TrajectoryPointerContainer &) const
virtual void done()=0
Tells the cleaner that the seeds are finished, and so it can clear any cache it has.
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.
TransientInitialStateEstimator * theInitialState_
void push_back(D *&d)
Definition: OwnVector.h:290
std::vector< TrajectorySeed > TrajectorySeedCollection
tuple result
Definition: query.py:137
const TrackingGeometry * geomTracker() const
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) const
tuple conf
Definition: dbtoconf.py:185
virtual TrajectoryContainer trajectories(const TrajectorySeed &) const =0
Definition: DetId.h:20
virtual const GeomDet * idToDet(DetId) const =0
RedundantSeedCleaner * theSeedCleaner_
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:44
TrajectoryCleanerBySharedHits * theTrajectoryCleaner_
char state
Definition: procUtils.cc:75
T eta() const
Definition: PV3DBase.h:70
OutInConversionTrackFinder(const edm::EventSetup &es, const edm::ParameterSet &config)
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection seeds, TrackCandidateCollection &candidates) const
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
const MeasurementTracker * theMeasurementTracker_
std::pair< TrajectoryStateOnSurface, const GeomDet * > innerState(const Trajectory &traj, bool doBackFit=true) const
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 ...
void reserve(size_t)
Definition: OwnVector.h:284