CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RoadSearchTrackListCleaner.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/RoadSearchTrackListCleaner
3 // Class: RoadSearchHelixMaker
4 //
5 // Description: TrackListCleaner
6 //
7 // Original Author: Steve Wagner, stevew@pizero.colorado.edu
8 // Created: Sat Jan 14 22:00:00 UTC 2006
9 //
10 // $Author: stevew $
11 // $Date: 2007/07/16 20:25:35 $
12 // $Revision: 1.6 $
13 //
14 
15 #include <memory>
16 #include <string>
17 #include <iostream>
18 #include <cmath>
19 #include <vector>
20 
22 
27 
31 
36 
42 
43 namespace cms
44 {
45 
47  conf_(conf)
48  {
49  produces<reco::TrackCollection>();
50 // produces<reco::TrackExtraCollection>();
51  }
52 
53 
54  // Virtual destructor needed.
56 
57  // Functions that gets called by framework every event
59  {
60  // retrieve producer name of input SiStripRecHit2DCollection
61  std::string trackProducer = conf_.getParameter<std::string>("TrackProducer");
62  double maxNormalizedChisq = conf_.getParameter<double>("MaxNormalizedChisq");
63  double minPT = conf_.getParameter<double>("MinPT");
64  unsigned int minFound = (unsigned int)conf_.getParameter<int>("MinFound");
65 
66  //
67  // extract tracker geometry
68  //
70  es.get<TrackerDigiGeometryRecord>().get(theG);
71 
72 // using namespace reco;
73 
74  // get Inputs
75  edm::Handle<reco::TrackCollection> trackCollection;
76  e.getByLabel(trackProducer, trackCollection);
77 
78  const reco::TrackCollection tC = *(trackCollection.product());
79 
80  //std::cout << "Reconstructed "<< tC.size() << " tracks" << std::endl ;
81 
82  // Step B: create empty output collection
83  std::auto_ptr<reco::TrackCollection> output(new reco::TrackCollection);
84 
85  //
86  // no input tracks
87  //
88 
89  if ( tC.empty() ){
90 // LogDebug("RoadSearch") << "Found " << output.size() << " clouds.";
91  e.put(output);
92  return;
93  }
94 
95  //
96  // quality cuts first
97  //
98  std::vector<int> selected; for (unsigned int i=0; i<tC.size(); ++i){selected.push_back(1);}
99 
100  int i=-1;
101  for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++){
102  i++;
103  if ((short unsigned)track->ndof() < 1){
104  selected[i]=0;
105  //std::cout << "Track "<< i << " rejected in TrackListCleaner; ndof() < 1" << std::endl ;
106  continue;
107  }
108  if (track->normalizedChi2() > maxNormalizedChisq){
109  selected[i]=0;
110  //std::cout << "Track "<< i << " rejected in TrackListCleaner; normalizedChi2() > maxNormalizedChisq " << track->normalizedChi2() << " " << maxNormalizedChisq << std::endl ;
111  continue;
112  }
113  if (track->found() < minFound){
114  selected[i]=0;
115  //std::cout << "Track "<< i << " rejected in TrackListCleaner; found() < minFound " << track->found() << " " << minFound << std::endl ;
116  continue;
117  }
118  if (track->pt() < minPT){
119  selected[i]=0;
120  //std::cout << "Track "<< i << " rejected in TrackListCleaner; pt() < minPT " << track->pt() << " " << minPT << std::endl ;
121  continue;
122  }
123  }//end loop over tracks
124 
125  //
126  // > 1 track - try merging
127  //
128  if ( 1<tC.size() ){
129  int i=-1;
130  for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++){
131  i++;
132  //std::cout << "Track number "<< i << std::endl ;
133  if (!selected[i])continue;
134  int j=-1;
135  for (reco::TrackCollection::const_iterator track2=tC.begin(); track2!=tC.end(); track2++){
136  j++;
137  if ((j<=i)||(!selected[j])||(!selected[i]))continue;
138  int noverlap=0;
139  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
140  if ((*it)->isValid()){
141  for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
142  if ((*jt)->isValid()){
143  if (((*it)->geographicalId()==(*jt)->geographicalId())&&((*it)->localPosition().x()==(*jt)->localPosition().x()))noverlap++;
144  }
145  }
146  }
147  }
148  float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
149  //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->recHitsSize() << " " << track2->recHitsSize() << " " << noverlap << " " << fi << " " << fj <<std::endl;
150  if ((fi>0.66)||(fj>0.66)){
151  if (fi<fj){
152  selected[j]=0;
153  //std::cout << " removing 2nd trk in pair " << std::endl;
154  }else{
155  if (fi>fj){
156  selected[i]=0;
157  //std::cout << " removing 1st trk in pair " << std::endl;
158  }else{
159  //std::cout << " removing worst chisq in pair " << std::endl;
160  if (track->chi2() > track2->chi2()){selected[i]=0;}else{selected[j]=0;}
161  }//end fi > or = fj
162  }//end fi < fj
163  }//end got a duplicate
164  }//end track2 loop
165  }//end track loop
166  }//end more than 1 track
167 
168  //
169  // output selected tracks - if any
170  //
171  i=-1;
172  for (reco::TrackCollection::const_iterator track=tC.begin(); track!=tC.end(); track++){
173  i++; if (!selected[i])continue;
174  reco::Track * theTrack = new reco::Track(track->chi2(),
175  (short unsigned)track->ndof(),
176  track->innerPosition(),
177  track->innerMomentum(),
178  track->charge(),
179  track->innerStateCovariance());
180  //fill the TrackCollection
181  reco::TrackExtraRef theTrackExtraRef=track->extra();
182  theTrack->setExtra(theTrackExtraRef);
183  theTrack->setHitPattern((*theTrackExtraRef).recHits());
184  output->push_back(*theTrack);
185  delete theTrack;
186  }//end faux loop over tracks
187  e.put(output);
188  return;
189 
190  }//end produce
191 
192 }
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
int j
Definition: DBlmapReader.cc:9
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
tuple conf
Definition: dbtoconf.py:185
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:246
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:95
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: Handle.h:74
virtual void produce(edm::Event &e, const edm::EventSetup &c)
RoadSearchTrackListCleaner(const edm::ParameterSet &conf)