CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
cms::TrackListMerger Class Reference

#include <TrackListMerger.h>

Inheritance diagram for cms::TrackListMerger:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

virtual void produce (edm::Event &e, const edm::EventSetup &c)
 
 TrackListMerger (const edm::ParameterSet &conf)
 
virtual ~TrackListMerger ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Attributes

edm::ParameterSet conf_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Definition at line 29 of file TrackListMerger.h.

Constructor & Destructor Documentation

cms::TrackListMerger::TrackListMerger ( const edm::ParameterSet conf)
explicit

Definition at line 47 of file TrackListMerger.cc.

47  :
48  conf_(conf)
49  {
50  produces<reco::TrackCollection>();
51 // produces<reco::TrackExtraCollection>();
52  }
edm::ParameterSet conf_
cms::TrackListMerger::~TrackListMerger ( )
virtual

Definition at line 56 of file TrackListMerger.cc.

56 { }

Member Function Documentation

void cms::TrackListMerger::produce ( edm::Event e,
const edm::EventSetup c 
)
virtual

Implements edm::EDProducer.

Definition at line 59 of file TrackListMerger.cc.

References edm::Exception::categoryCode(), conf_, delta, epsilon, edm::EventSetup::get(), edm::Event::getByLabel(), edm::ParameterSet::getParameter(), cms::Exception::history(), i, j, convertSQLitetoXML_cfg::output, edm::Handle< T >::product(), edm::errors::ProductNotFound, edm::Event::put(), reco::Track::setExtra(), reco::TrackBase::setHitPattern(), ExpressReco_HICollisions_FallBack::track, and ExpressReco_HICollisions_FallBack::x.

60  {
61  // retrieve producer name of input TrackCollection(s)
62  std::string trackProducer1 = conf_.getParameter<std::string>("TrackProducer1");
63  std::string trackProducer2 = conf_.getParameter<std::string>("TrackProducer2");
64 
65  double maxNormalizedChisq = conf_.getParameter<double>("MaxNormalizedChisq");
66  double minPT = conf_.getParameter<double>("MinPT");
67  unsigned int minFound = (unsigned int)conf_.getParameter<int>("MinFound");
68  double epsilon = conf_.getParameter<double>("Epsilon");
69  double shareFrac = conf_.getParameter<double>("ShareFrac");
70 
71  //
72  // extract tracker geometry
73  //
75  es.get<TrackerDigiGeometryRecord>().get(theG);
76 
77 // using namespace reco;
78 
79  // get Inputs
80  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
81  // this allows TrackListMerger to be used as a cleaner only if handed just one list
82  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
83  //
84  const reco::TrackCollection *TC1 = 0;
85  try {
86  edm::Handle<reco::TrackCollection> trackCollection1;
87  e.getByLabel(trackProducer1, trackCollection1);
88  TC1 = trackCollection1.product();
89  //std::cout << "1st collection " << trackProducer1 << " has "<< TC1->size() << " tracks" << std::endl ;
90  }
91  catch (edm::Exception const& x) {
93  if ( x.history().size() == 1 ) {
94  static const reco::TrackCollection s_empty;
95  TC1 = &s_empty;
96  edm::LogWarning("TrackListMerger") << "1st TrackCollection " << trackProducer1 << " not found; will only clean 2nd TrackCollection " << trackProducer2 ;
97  }
98  }
99  }
100  const reco::TrackCollection tC1 = *TC1;
101 
102  const reco::TrackCollection *TC2 = 0;
103  try {
104  edm::Handle<reco::TrackCollection> trackCollection2;
105  e.getByLabel(trackProducer2, trackCollection2);
106  TC2 = trackCollection2.product();
107  //std::cout << "2nd collection " << trackProducer2 << " has "<< TC2->size() << " tracks" << std::endl ;
108  }
109  catch (edm::Exception const& x) {
111  if ( x.history().size() == 1 ) {
112  static const reco::TrackCollection s_empty;
113  TC2 = &s_empty;
114  edm::LogWarning("TrackListMerger") << "2nd TrackCollection " << trackProducer2 << " not found; will only clean 1st TrackCollection " << trackProducer1 ;
115  }
116  }
117  }
118  const reco::TrackCollection tC2 = *TC2;
119 
120  // Step B: create empty output collection
121  std::auto_ptr<reco::TrackCollection> output(new reco::TrackCollection);
122 
123  //
124  // no input tracks
125  //
126 
127 // if ( tC1.empty() ){
128 // LogDebug("RoadSearch") << "Found " << output.size() << " clouds.";
129 // e.put(output);
130 // return;
131 // }
132 
133  //
134  // quality cuts first
135  //
136  int i;
137 
138  std::vector<int> selected1; for (unsigned int i=0; i<tC1.size(); ++i){selected1.push_back(1);}
139 
140  if ( 0<tC1.size() ){
141  i=-1;
142  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
143  i++;
144  if ((short unsigned)track->ndof() < 1){
145  selected1[i]=0;
146  //std::cout << "L1Track "<< i << " rejected in TrackListMerger; ndof() < 1" << std::endl ;
147  continue;
148  }
149  if (track->normalizedChi2() > maxNormalizedChisq){
150  selected1[i]=0;
151  //std::cout << "L1Track "<< i << " rejected in TrackListMerger; normalizedChi2() > maxNormalizedChisq " << track->normalizedChi2() << " " << maxNormalizedChisq << std::endl ;
152  continue;
153  }
154  if (track->found() < minFound){
155  selected1[i]=0;
156  //std::cout << "L1Track "<< i << " rejected in TrackListMerger; found() < minFound " << track->found() << " " << minFound << std::endl ;
157  continue;
158  }
159  if (track->pt() < minPT){
160  selected1[i]=0;
161  //std::cout << "L1Track "<< i << " rejected in TrackListMerger; pt() < minPT " << track->pt() << " " << minPT << std::endl ;
162  continue;
163  }
164  }//end loop over tracks
165  }//end more than 0 track
166 
167 
168  std::vector<int> selected2; for (unsigned int i=0; i<tC2.size(); ++i){selected2.push_back(1);}
169 
170  if ( 0<tC2.size() ){
171  i=-1;
172  for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
173  i++;
174  if ((short unsigned)track->ndof() < 1){
175  selected2[i]=0;
176  //std::cout << "L2Track "<< i << " rejected in TrackListMerger; ndof() < 1" << std::endl ;
177  continue;
178  }
179  if (track->normalizedChi2() > maxNormalizedChisq){
180  selected2[i]=0;
181  //std::cout << "L2Track "<< i << " rejected in TrackListMerger; normalizedChi2() > maxNormalizedChisq " << track->normalizedChi2() << " " << maxNormalizedChisq << std::endl ;
182  continue;
183  }
184  if (track->found() < minFound){
185  selected2[i]=0;
186  //std::cout << "L2Track "<< i << " rejected in TrackListMerger; found() < minFound " << track->found() << " " << minFound << std::endl ;
187  continue;
188  }
189  if (track->pt() < minPT){
190  selected2[i]=0;
191  //std::cout << "L2Track "<< i << " rejected in TrackListMerger; pt() < minPT " << track->pt() << " " << minPT << std::endl ;
192  continue;
193  }
194  }//end loop over tracks
195  }//end more than 0 track
196 
197  //
198  // L1 has > 1 track - try merging
199  //
200  if ( 1<tC1.size() ){
201  i=-1;
202  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
203  i++;
204  //std::cout << "Track number "<< i << std::endl ;
205  if (!selected1[i])continue;
206  int j=-1;
207  for (reco::TrackCollection::const_iterator track2=tC1.begin(); track2!=tC1.end(); track2++){
208  j++;
209  if ((j<=i)||(!selected1[j])||(!selected1[i]))continue;
210  int noverlap=0;
211  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
212  if ((*it)->isValid()){
213  for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
214  if ((*jt)->isValid()){
215  if (((*it)->geographicalId()==(*jt)->geographicalId())&&((*it)->localPosition().x()==(*jt)->localPosition().x()))noverlap++;
216  }
217  }
218  }
219  }
220  float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
221  //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->recHitsSize() << " " << track2->recHitsSize() << " " << noverlap << " " << fi << " " << fj <<std::endl;
222  if ((fi>shareFrac)||(fj>shareFrac)){
223  if (fi<fj){
224  selected1[j]=0;
225  //std::cout << " removing 2nd trk in pair " << std::endl;
226  }else{
227  if (fi>fj){
228  selected1[i]=0;
229  //std::cout << " removing 1st trk in pair " << std::endl;
230  }else{
231  //std::cout << " removing worst chisq in pair " << std::endl;
232  if (track->normalizedChi2() > track2->normalizedChi2()){selected1[i]=0;}else{selected1[j]=0;}
233  }//end fi > or = fj
234  }//end fi < fj
235  }//end got a duplicate
236  }//end track2 loop
237  }//end track loop
238  }//end more than 1 track
239 
240  //
241  // L2 has > 1 track - try merging
242  //
243  if ( 1<tC2.size() ){
244  int i=-1;
245  for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
246  i++;
247  //std::cout << "Track number "<< i << std::endl ;
248  if (!selected2[i])continue;
249  int j=-1;
250  for (reco::TrackCollection::const_iterator track2=tC2.begin(); track2!=tC2.end(); track2++){
251  j++;
252  if ((j<=i)||(!selected2[j])||(!selected2[i]))continue;
253  int noverlap=0;
254  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
255  if ((*it)->isValid()){
256  for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
257  if ((*jt)->isValid()){
258  if (((*it)->geographicalId()==(*jt)->geographicalId())&&((*it)->localPosition().x()==(*jt)->localPosition().x()))noverlap++;
259  }
260  }
261  }
262  }
263  float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
264  //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->recHitsSize() << " " << track2->recHitsSize() << " " << noverlap << " " << fi << " " << fj <<std::endl;
265  if ((fi>shareFrac)||(fj>shareFrac)){
266  if (fi<fj){
267  selected2[j]=0;
268  //std::cout << " removing 2nd trk in pair " << std::endl;
269  }else{
270  if (fi>fj){
271  selected2[i]=0;
272  //std::cout << " removing 1st trk in pair " << std::endl;
273  }else{
274  //std::cout << " removing worst chisq in pair " << std::endl;
275  if (track->normalizedChi2() > track2->normalizedChi2()){selected2[i]=0;}else{selected2[j]=0;}
276  }//end fi > or = fj
277  }//end fi < fj
278  }//end got a duplicate
279  }//end track2 loop
280  }//end track loop
281  }//end more than 1 track
282 
283  //
284  // L1 and L2 both have > 0 track - try merging
285  //
286  if ( (0<tC1.size())&&(0<tC2.size()) ){
287  i=-1;
288  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
289  i++;
290  //std::cout << "L1 Track number "<< i << std::endl ;
291  if (!selected1[i])continue;
292  int j=-1;
293  for (reco::TrackCollection::const_iterator track2=tC2.begin(); track2!=tC2.end(); track2++){
294  j++;
295  if ((!selected2[j])||(!selected1[i]))continue;
296  int noverlap=0;
297  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); it++){
298  if ((*it)->isValid()){
299  for (trackingRecHit_iterator jt = track2->recHitsBegin(); jt != track2->recHitsEnd(); jt++){
300  if ((*jt)->isValid()){
301  float delta = fabs ( (*it)->localPosition().x()-(*jt)->localPosition().x() );
302  if (((*it)->geographicalId()==(*jt)->geographicalId())&&(delta<epsilon))noverlap++;
303  }
304  }
305  }
306  }
307  float fi=float(noverlap)/float(track->recHitsSize()); float fj=float(noverlap)/float(track2->recHitsSize());
308  //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->recHitsSize() << " " << track2->recHitsSize() << " " << noverlap << " " << fi << " " << fj <<std::endl;
309  if ((fi>shareFrac)||(fj>shareFrac)){
310  if (fi<fj){
311  selected2[j]=0;
312  //std::cout << " removing L2 trk in pair " << std::endl;
313  }else{
314  if (fi>fj){
315  selected1[i]=0;
316  //std::cout << " removing L1 trk in pair " << std::endl;
317  }else{
318  //std::cout << " removing worst chisq in pair " << track->normalizedChi2() << " " << track2->normalizedChi2() << std::endl;
319  if (track->normalizedChi2() > track2->normalizedChi2()){selected1[i]=0;}else{selected2[j]=0;}
320  }//end fi > or = fj
321  }//end fi < fj
322  }//end got a duplicate
323  }//end track2 loop
324  }//end track loop
325  }//end more than 1 track
326 
327  //
328  // output selected tracks - if any
329  //
330  if ( 0<tC1.size() ){
331  i=-1;
332  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
333  i++; if (!selected1[i])continue;
334  reco::Track * theTrack = new reco::Track(track->chi2(),
335  (short unsigned)track->ndof(),
336  track->innerPosition(),
337  track->innerMomentum(),
338  track->charge(),
339  track->innerStateCovariance());
340  //fill the TrackCollection
341  reco::TrackExtraRef theTrackExtraRef=track->extra();
342  theTrack->setExtra(theTrackExtraRef);
343  theTrack->setHitPattern((*theTrackExtraRef).recHits());
344  output->push_back(*theTrack);
345  delete theTrack;
346  }//end faux loop over tracks
347  }//end more than 0 track
348  if ( 0<tC2.size() ){
349  i=-1;
350  for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
351  i++; if (!selected2[i])continue;
352  reco::Track * theTrack = new reco::Track(track->chi2(),
353  (short unsigned)track->ndof(),
354  track->innerPosition(),
355  track->innerMomentum(),
356  track->charge(),
357  track->innerStateCovariance());
358  //fill the TrackCollection
359  reco::TrackExtraRef theTrackExtraRef=track->extra();
360  theTrack->setExtra(theTrackExtraRef);
361  theTrack->setHitPattern((*theTrackExtraRef).recHits());
362  output->push_back(*theTrack);
363  delete theTrack;
364  }//end faux loop over tracks
365  }//end more than 0 track
366 
367 
368  e.put(output);
369  return;
370 
371  }//end produce
Code categoryCode() const
Definition: EDMException.h:88
dbl * delta
Definition: mlp_gen.cc:36
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:84
int j
Definition: DBlmapReader.cc:9
edm::ParameterSet conf_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
CategoryList const & history() const
Definition: Exception.cc:70
void setHitPattern(const C &c)
set hit patterns from vector of hit references
Definition: TrackBase.h:230
void setExtra(const TrackExtraRef &ref)
set reference to &quot;extra&quot; object
Definition: Track.h:95
T const * product() const
Definition: Handle.h:74
const double epsilon

Member Data Documentation

edm::ParameterSet cms::TrackListMerger::conf_
private

Definition at line 40 of file TrackListMerger.h.

Referenced by produce().