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
ConversionTrackMerger Class Reference

#include <ConversionTrackMerger.h>

Inheritance diagram for ConversionTrackMerger:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 ConversionTrackMerger (const edm::ParameterSet &conf)
 
virtual void produce (edm::Event &e, const edm::EventSetup &c)
 
virtual ~ConversionTrackMerger ()
 
- 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_
 
std::auto_ptr
< reco::ConversionTrackCollection
outputTrks
 

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 34 of file ConversionTrackMerger.h.

Constructor & Destructor Documentation

ConversionTrackMerger::ConversionTrackMerger ( const edm::ParameterSet conf)
explicit

Definition at line 41 of file ConversionTrackMerger.cc.

41  :
42  conf_(conf)
43  {
44  produces<reco::ConversionTrackCollection>();
45 
46  }
ConversionTrackMerger::~ConversionTrackMerger ( )
virtual

Definition at line 50 of file ConversionTrackMerger.cc.

50 { }

Member Function Documentation

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

Implements edm::EDProducer.

Definition at line 53 of file ConversionTrackMerger.cc.

References conf_, edm::Event::getByLabel(), edm::ParameterSet::getParameter(), i, TrackingRecHit::isValid(), edm::HandleBase::isValid(), j, min, outputTrks, edm::Handle< T >::product(), edm::Event::put(), TrackingRecHit::sharesInput(), TrackingRecHit::some, and ExpressReco_HICollisions_FallBack::track.

54  {
55  // retrieve producer name of input TrackCollection(s)
56  std::string trackProducer1 = conf_.getParameter<std::string>("TrackProducer1");
57  std::string trackProducer2 = conf_.getParameter<std::string>("TrackProducer2");
58 
59  double shareFrac = conf_.getParameter<double>("ShareFrac");
60  bool allowFirstHitShare = conf_.getParameter<bool>("allowFirstHitShare");
61 
62  int outputPreferCollection = conf_.getParameter<int>("outputPreferCollection");
63  int trackerOnlyPreferCollection = conf_.getParameter<int>("trackerOnlyPreferCollection");
64  int arbitratedEcalSeededPreferCollection = conf_.getParameter<int>("arbitratedEcalSeededPreferCollection");
65  int arbitratedMergedPreferCollection = conf_.getParameter<int>("arbitratedMergedPreferCollection");
66  int arbitratedMergedEcalGeneralPreferCollection = conf_.getParameter<int>("arbitratedMergedEcalGeneralPreferCollection");
67 
68  // get Inputs
69  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
70  // this allows ConversionTrackMerger to be used as a cleaner only if handed just one list
71  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
72  //
73  const reco::ConversionTrackCollection *TC1 = 0;
74  static const reco::ConversionTrackCollection s_empty1, s_empty2;
76  e.getByLabel(trackProducer1, trackCollection1);
77  if (trackCollection1.isValid()) {
78  TC1 = trackCollection1.product();
79  //std::cout << "1st collection " << trackProducer1 << " has "<< TC1->size() << " tracks" << std::endl ;
80  } else {
81  TC1 = &s_empty1;
82  edm::LogWarning("ConversionTrackMerger") << "1st TrackCollection " << trackProducer1 << " not found; will only clean 2nd TrackCollection " << trackProducer2 ;
83  }
84  const reco::ConversionTrackCollection tC1 = *TC1;
85 
86  const reco::ConversionTrackCollection *TC2 = 0;
88  e.getByLabel(trackProducer2, trackCollection2);
89  if (trackCollection2.isValid()) {
90  TC2 = trackCollection2.product();
91  //std::cout << "2nd collection " << trackProducer2 << " has "<< TC2->size() << " tracks" << std::endl ;
92  } else {
93  TC2 = &s_empty2;
94  edm::LogWarning("ConversionTrackMerger") << "2nd TrackCollection " << trackProducer2 << " not found; will only clean 1st TrackCollection " << trackProducer1 ;
95  }
96  const reco::ConversionTrackCollection tC2 = *TC2;
97 
98  // Step B: create empty output collection
99  outputTrks = std::auto_ptr<reco::ConversionTrackCollection>(new reco::ConversionTrackCollection);
100  int i;
101 
102  std::vector<int> selected1; for (unsigned int i=0; i<tC1.size(); ++i){selected1.push_back(1);}
103  std::vector<int> selected2; for (unsigned int i=0; i<tC2.size(); ++i){selected2.push_back(1);}
104 
105 
106  std::map<reco::ConversionTrackCollection::const_iterator, std::vector<const TrackingRecHit*> > rh1;
107  std::map<reco::ConversionTrackCollection::const_iterator, std::vector<const TrackingRecHit*> > rh2;
108  for (reco::ConversionTrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); ++track){
109  trackingRecHit_iterator itB = track->track()->recHitsBegin();
110  trackingRecHit_iterator itE = track->track()->recHitsEnd();
111  for (trackingRecHit_iterator it = itB; it != itE; ++it) {
112  const TrackingRecHit* hit = &(**it);
113  rh1[track].push_back(hit);
114  }
115  }
116  for (reco::ConversionTrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); ++track){
117  trackingRecHit_iterator jtB = track->track()->recHitsBegin();
118  trackingRecHit_iterator jtE = track->track()->recHitsEnd();
119  for (trackingRecHit_iterator jt = jtB; jt != jtE; ++jt) {
120  const TrackingRecHit* hit = &(**jt);
121  rh2[track].push_back(hit);
122  }
123  }
124 
125  if ( (0<tC1.size())&&(0<tC2.size()) ){
126  i=-1;
127  for (reco::ConversionTrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); ++track){
128  i++;
129  std::vector<const TrackingRecHit*>& iHits = rh1[track];
130  unsigned nh1 = iHits.size();
131  int j=-1;
132  for (reco::ConversionTrackCollection::const_iterator track2=tC2.begin(); track2!=tC2.end(); ++track2){
133  j++;
134  std::vector<const TrackingRecHit*>& jHits = rh2[track2];
135  unsigned nh2 = jHits.size();
136  int noverlap=0;
137  int firstoverlap=0;
138  for ( unsigned ih=0; ih<nh1; ++ih ) {
139  const TrackingRecHit* it = iHits[ih];
140  if (it->isValid()){
141  int jj=-1;
142  for ( unsigned jh=0; jh<nh2; ++jh ) {
143  const TrackingRecHit* jt = jHits[jh];
144  jj++;
145  if (jt->isValid()){
146  if ( it->sharesInput(jt,TrackingRecHit::some) ) {
147  noverlap++;
148  if ( allowFirstHitShare && ( ih == 0 ) && ( jh == 0 ) ) firstoverlap=1;
149  }
150  }
151  }
152  }
153  }
154  int nhit1 = track->track()->numberOfValidHits();
155  int nhit2 = track2->track()->numberOfValidHits();
156  //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->numberOfValidHits() << " " << track2->numberOfValidHits() << " " << noverlap << " " << fi << " " << fj <<std::endl;
157  if ( (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*shareFrac ) {
158  if ( nhit1 > nhit2 ){
159  selected2[j]=0;
160  //std::cout << " removing L2 trk in pair " << std::endl;
161  }else{
162  if ( nhit1 < nhit2 ){
163  selected1[i]=0;
164  //std::cout << " removing L1 trk in pair " << std::endl;
165  }else{
166  //std::cout << " removing worst chisq in pair " << track->normalizedChi2() << " " << track2->normalizedChi2() << std::endl;
167  if (track->track()->normalizedChi2() > track2->track()->normalizedChi2()) {
168  selected1[i]=0;
169  }else {
170  selected2[j]=0;
171  }
172  }//end fi > or = fj
173  }//end fi < fj
174  }//end got a duplicate
175  }//end track2 loop
176  }//end track loop
177  }//end more than 1 track
178 
179  //
180  // output selected tracks - if any
181  //
182 
183  if ( 0<tC1.size() ){
184  i=0;
185  for (reco::ConversionTrackCollection::const_iterator track=tC1.begin(); track!=tC1.end();
186  ++track, ++i){
187  //don't store tracks rejected as duplicates
188  if ( outputPreferCollection==0 || ( (outputPreferCollection==3 || outputPreferCollection==2) && !selected1[i]) ){
189  continue;
190  }
191  //fill the TrackCollection
192  outputTrks->push_back(*track);
193  //clear flags for tracks rejected as duplicates
194  if ( trackerOnlyPreferCollection==0 || ( (trackerOnlyPreferCollection==3 || trackerOnlyPreferCollection==2) && !selected1[i]) ){
195  outputTrks->back().setIsTrackerOnly(false);
196  }
197  if ( arbitratedEcalSeededPreferCollection==0 || ( (arbitratedEcalSeededPreferCollection==3 || arbitratedEcalSeededPreferCollection==2) && !selected1[i]) ){
198  outputTrks->back().setIsArbitratedEcalSeeded(false);
199  }
200  if ( arbitratedMergedPreferCollection==0 || ( (arbitratedMergedPreferCollection==3 || arbitratedMergedPreferCollection==2) && !selected1[i]) ){
201  outputTrks->back().setIsArbitratedMerged(false);
202  }
203  if ( arbitratedMergedEcalGeneralPreferCollection==0 || ( (arbitratedMergedEcalGeneralPreferCollection==3 || arbitratedMergedEcalGeneralPreferCollection==2) && !selected1[i]) ){
204  outputTrks->back().setIsArbitratedMergedEcalGeneral(false);
205  }
206  }//end faux loop over tracks
207  }//end more than 0 track
208 
209  //Fill the trajectories, etc. for 1st collection
210 
211 
212  if ( 0<tC2.size() ){
213  i=0;
214  for (reco::ConversionTrackCollection::const_iterator track=tC2.begin(); track!=tC2.end();
215  ++track, ++i){
216  //don't store tracks rejected as duplicates
217  if ( outputPreferCollection==0 || ( (outputPreferCollection==3 || outputPreferCollection==1) && !selected2[i]) ){
218  continue;
219  }
220  //fill the TrackCollection
221  outputTrks->push_back(*track);
222  //clear flags for tracks rejected as duplicates
223  if ( trackerOnlyPreferCollection==0 || ( (trackerOnlyPreferCollection==3 || trackerOnlyPreferCollection==1) && !selected2[i]) ){
224  outputTrks->back().setIsTrackerOnly(false);
225  }
226  if ( arbitratedEcalSeededPreferCollection==0 || ( (arbitratedEcalSeededPreferCollection==3 || arbitratedEcalSeededPreferCollection==1) && !selected2[i]) ){
227  outputTrks->back().setIsArbitratedEcalSeeded(false);
228  }
229  if ( arbitratedMergedPreferCollection==0 || ( (arbitratedMergedPreferCollection==3 || arbitratedMergedPreferCollection==1) && !selected2[i]) ){
230  outputTrks->back().setIsArbitratedMerged(false);
231  }
232  if ( arbitratedMergedEcalGeneralPreferCollection==0 || ( (arbitratedMergedEcalGeneralPreferCollection==3 || arbitratedMergedEcalGeneralPreferCollection==1) && !selected2[i]) ){
233  outputTrks->back().setIsArbitratedMergedEcalGeneral(false);
234  }
235 
236  }//end faux loop over tracks
237  }//end more than 0 track
238 
239  e.put(outputTrks);
240  return;
241 
242  }//end produce
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< reco::ConversionTrackCollection > outputTrks
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< ConversionTrack > ConversionTrackCollection
collection of ConversionTracks
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:84
int j
Definition: DBlmapReader.cc:9
bool isValid() const
Definition: HandleBase.h:76
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:359
bool isValid() const
T const * product() const
Definition: Handle.h:74

Member Data Documentation

edm::ParameterSet ConversionTrackMerger::conf_
private

Definition at line 45 of file ConversionTrackMerger.h.

Referenced by produce().

std::auto_ptr<reco::ConversionTrackCollection> ConversionTrackMerger::outputTrks
private

Definition at line 47 of file ConversionTrackMerger.h.

Referenced by produce().