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 //
11 //
16 //
18 //
20 
21 #include <sstream>
22 
23 
25  const edm::ParameterSet& conf ) : ConversionTrackFinder (es, conf )
26 {
27 
29 
30 
31  // get the seed cleaner
32  std::string cleaner = conf_.getParameter<std::string>("InOutRedundantSeedCleaner");
33  if (cleaner == "SeedCleanerByHitPosition") {
35  } else if (cleaner == "CachingSeedCleanerByHitPosition") {
37  } else if (cleaner == "CachingSeedCleanerBySharedInput") {
38 
40  } else if (cleaner == "none") {
41  theSeedCleaner_ = 0;
42  } else {
43  throw cms::Exception("InOutRedundantSeedCleaner not found", cleaner);
44  }
45 
46 }
47 
48 
50 
51  delete theTrajectoryCleaner_;
52  if (theSeedCleaner_) delete theSeedCleaner_;
53 }
54 
55 
56 
57 
58 std::vector<Trajectory> InOutConversionTrackFinder::tracks(const TrajectorySeedCollection inOutSeeds,
59  TrackCandidateCollection &output_p ) const {
60 
61 
62 
63  // std::cout << " InOutConversionTrackFinder::tracks getting " << inOutSeeds.size() << " In-Out seeds " << "\n";
64 
65  std::vector<Trajectory> tmpO;
66  tmpO.erase(tmpO.begin(), tmpO.end() ) ;
67 
68  std::vector<Trajectory> result;
69  result.erase(result.begin(), result.end() ) ;
70 
71 
72  std::vector<Trajectory> rawResult;
73  if (theSeedCleaner_) theSeedCleaner_->init( &rawResult );
74 
75 
76 
77  // Loop over the seeds
78  int goodSeed=0;
79  for(TrajectorySeedCollection::const_iterator iSeed=inOutSeeds.begin(); iSeed!=inOutSeeds.end();iSeed++){
80  if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
81  goodSeed++;
82 
83  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
84  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state position " << iSeed->startingState().parameters().position() << " momentum " << iSeed->startingState().parameters().momentum() << " charge " << iSeed->startingState().parameters().charge() << "\n";
85  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state para, vector " << iSeed->startingState().parameters().vector() << "\n";
86 
87 
88 
89  std::vector<Trajectory> theTmpTrajectories;
90 
91  theTmpTrajectories = theCkfTrajectoryBuilder_->trajectories(*iSeed);
92 
93  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track returned " << theTmpTrajectories.size() << " trajectories for this seed " << "\n";
94 
95  theTrajectoryCleaner_->clean(theTmpTrajectories);
96 
97  for(std::vector<Trajectory>::const_iterator it=theTmpTrajectories.begin(); it!=theTmpTrajectories.end(); it++){
98  if( it->isValid() ) {
99  rawResult.push_back(*it);
100  if (theSeedCleaner_) theSeedCleaner_->add( & (*it) );
101  }
102  }
103  }
104  } // end loop over the seeds
105 
106 
107 
108  LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track Good seeds " << goodSeed << "\n" ;
109  LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";
110 
112 
113 
114  std::vector<Trajectory> unsmoothedResult;
115  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Start second cleaning " << "\n";
116  theTrajectoryCleaner_->clean(rawResult);
117  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";
118 
119 
120 
121  int tra=0;
122  for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
123  tra++;
124  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder looping of rawResult after cleaning " << tra << "\n";
125  if((*itraw).isValid()) {
126  // unsmoothedResult.push_back( *itraw);
127  tmpO.push_back( *itraw );
128  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult num of valid recHits per trajectory " << (*itraw).foundHits() << "\n";
129  }
130 
131  }
132 
133  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO size " << tmpO.size() << " before sorting " << "\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() << " before ordering " << "\n";
136  //}
137 
138  precomputed_value_sort( tmpO.begin(), tmpO.end(), ExtractNumOfHits() );
139 
140 
141  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO after sorting " << "\n";
142  // for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
143  // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO num of hits " << (*it).foundHits() << "\n";
144  // }
145 
146  for (int i=tmpO.size()-1; i>=0; i--) {
147  unsmoothedResult.push_back( tmpO[i] );
148  }
149  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder unsmoothedResult size " << unsmoothedResult.size() << "\n";
150 
151  // for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
152  // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder unsmoothedResult after reordering " <<(*it).foundHits() << "\n";
153  // }
154 
155 
156  // Convert to TrackCandidates and fill in the output_p
157  for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
158 
159  if( !it->isValid() ) continue;
160 
162  Trajectory::RecHitContainer thits = it->recHits();
163  for (Trajectory::RecHitContainer::const_iterator hitIt = thits.begin(); hitIt != thits.end(); hitIt++) {
164  recHits.push_back( (**hitIt).hit()->clone());
165  }
166 
167 
168  std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState( *it);
169 
170  // temporary protection againt invalid initial states
171  if (! initState.first.isValid() || initState.second == 0) {
172  //cout << "invalid innerState, will not make TrackCandidate" << endl;
173  continue;
174  }
175 
176  PTrajectoryStateOnDet* state = TrajectoryStateTransform().persistentState( initState.first, initState.second->geographicalId().rawId());
177 
178  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";
179  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track TSOS charge " << initState.first.charge() << "\n";
180 
181  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track PTrajectoryStateOnDet* state position " << state->parameters().position() << " momentum " << state->parameters().momentum() << " charge " << state->parameters().charge () << "\n";
182 
183 
184  result.push_back(*it);
185 
186  output_p.push_back(TrackCandidate(recHits, it->seed(),*state ) );
187  delete state;
188  }
189 
190  LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Returning " << result.size() << " valid In Out Trajectories " << "\n";
191  return result;
192 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
const TrajectoryBuilder * theCkfTrajectoryBuilder_
TrajectoryCleanerBySharedHits * theTrajectoryCleaner_
LocalPoint position() const
Local x and y position coordinates.
std::vector< TrackCandidate > TrackCandidateCollection
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:288
virtual std::vector< Trajectory > tracks(const TrajectorySeedCollection seeds, TrackCandidateCollection &candidate) const
std::vector< TrajectorySeed > TrajectorySeedCollection
tuple result
Definition: query.py:137
PTrajectoryStateOnDet * persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid) const
LocalVector momentum() const
Momentum vector in the local frame.
RedundantSeedCleaner * theSeedCleaner_
tuple conf
Definition: dbtoconf.py:185
virtual TrajectoryContainer trajectories(const TrajectorySeed &) const =0
ConstRecHitContainer RecHitContainer
Definition: Trajectory.h:44
TrackCharge charge() const
Charge (-1, 0 or 1)
char state
Definition: procUtils.cc:75
void precomputed_value_sort(RandomAccessIterator begin, RandomAccessIterator end, const Extractor &extr)
InOutConversionTrackFinder(const edm::EventSetup &es, const edm::ParameterSet &config)
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 ...
const LocalTrajectoryParameters & parameters() const