CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
ConversionTrackMerger Class Reference

#include <ConversionTrackMerger.h>

Inheritance diagram for ConversionTrackMerger:
edm::stream::EDProducer<>

Public Member Functions

 ConversionTrackMerger (const edm::ParameterSet &conf)
 
void produce (edm::Event &e, const edm::EventSetup &c) override
 
 ~ConversionTrackMerger () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndRuns () const final
 

Private Attributes

edm::ParameterSet conf_
 
std::unique_ptr< reco::ConversionTrackCollectionoutputTrks
 
edm::EDGetTokenT< reco::ConversionTrackCollectiontrackProducer1
 
edm::EDGetTokenT< reco::ConversionTrackCollectiontrackProducer2
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T... > CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T... > HasAbility
 
typedef CacheTypes::LuminosityBlockCache LuminosityBlockCache
 
typedef LuminosityBlockContextT< LuminosityBlockCache, RunCache, GlobalCacheLuminosityBlockContext
 
typedef CacheTypes::LuminosityBlockSummaryCache LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache, GlobalCacheRunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 

Detailed Description

Definition at line 29 of file ConversionTrackMerger.h.

Constructor & Destructor Documentation

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

Definition at line 37 of file ConversionTrackMerger.cc.

References conf_, edm::ParameterSet::getParameter(), trackProducer1, and trackProducer2.

37  : conf_(conf) {
38  // retrieve producer name of input TrackCollection(s)
39  trackProducer1 = consumes<reco::ConversionTrackCollection>(conf_.getParameter<edm::InputTag>("TrackProducer1"));
40  trackProducer2 = consumes<reco::ConversionTrackCollection>(conf_.getParameter<edm::InputTag>("TrackProducer2"));
41 
42  produces<reco::ConversionTrackCollection>();
43 }
T getParameter(std::string const &) const
edm::EDGetTokenT< reco::ConversionTrackCollection > trackProducer1
edm::EDGetTokenT< reco::ConversionTrackCollection > trackProducer2
ConversionTrackMerger::~ConversionTrackMerger ( )
override

Definition at line 46 of file ConversionTrackMerger.cc.

46 {}

Member Function Documentation

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

Definition at line 49 of file ConversionTrackMerger.cc.

References HLT_2018_cff::allowFirstHitShare, conversionTrackMerger_cfi::arbitratedEcalSeededPreferCollection, conversionTrackMerger_cfi::arbitratedMergedEcalGeneralPreferCollection, conversionTrackMerger_cfi::arbitratedMergedPreferCollection, PA_ZEESkim_cff::checkCharge, ChiSquaredProbability(), conf_, edm::Event::getByToken(), edm::ParameterSet::getParameter(), mps_fire::i, edm::HandleBase::isValid(), TrackingRecHit::isValid(), dqmiolumiharvest::j, findQualityFiles::jj, min(), conversionTrackMerger_cfi::minProb, eostools::move(), conversionTrackMerger_cfi::outputPreferCollection, outputTrks, edm::Handle< T >::product(), edm::Event::put(), HLT_FULL_cff::shareFrac, TrackingRecHit::sharesInput(), TrackingRecHit::some, HLT_2018_cff::track, conversionTrackMerger_cfi::trackerOnlyPreferCollection, trackProducer1, and trackProducer2.

49  {
50  double shareFrac = conf_.getParameter<double>("ShareFrac");
51  bool allowFirstHitShare = conf_.getParameter<bool>("allowFirstHitShare");
52  bool checkCharge = conf_.getParameter<bool>("checkCharge");
53  double minProb = conf_.getParameter<double>("minProb");
54 
55  int outputPreferCollection = conf_.getParameter<int>("outputPreferCollection");
56  int trackerOnlyPreferCollection = conf_.getParameter<int>("trackerOnlyPreferCollection");
57  int arbitratedEcalSeededPreferCollection = conf_.getParameter<int>("arbitratedEcalSeededPreferCollection");
58  int arbitratedMergedPreferCollection = conf_.getParameter<int>("arbitratedMergedPreferCollection");
60  conf_.getParameter<int>("arbitratedMergedEcalGeneralPreferCollection");
61 
62  // get Inputs
63  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
64  // this allows ConversionTrackMerger to be used as a cleaner only if handed just one list
65  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
66  //
67  const reco::ConversionTrackCollection* TC1 = nullptr;
68  static const reco::ConversionTrackCollection s_empty1, s_empty2;
70  e.getByToken(trackProducer1, trackCollection1);
71  if (trackCollection1.isValid()) {
72  TC1 = trackCollection1.product();
73  //std::cout << "1st collection " << trackProducer1 << " has "<< TC1->size() << " tracks" << std::endl ;
74  } else {
75  TC1 = &s_empty1;
76  edm::LogWarning("ConversionTrackMerger") << "1st TrackCollection not found;"
77  << " will only clean 2nd TrackCollection ";
78  }
80 
81  const reco::ConversionTrackCollection* TC2 = nullptr;
83  e.getByToken(trackProducer2, trackCollection2);
84  if (trackCollection2.isValid()) {
85  TC2 = trackCollection2.product();
86  //std::cout << "2nd collection " << trackProducer2 << " has "<< TC2->size() << " tracks" << std::endl ;
87  } else {
88  TC2 = &s_empty2;
89  edm::LogWarning("ConversionTrackMerger") << "2nd TrackCollection not found;"
90  << " will only clean 1st TrackCollection ";
91  }
93 
94  // Step B: create empty output collection
95  outputTrks = std::make_unique<reco::ConversionTrackCollection>();
96  int i;
97 
98  std::vector<int> selected1;
99  for (unsigned int i = 0; i < tC1.size(); ++i) {
100  selected1.push_back(1);
101  }
102  std::vector<int> selected2;
103  for (unsigned int i = 0; i < tC2.size(); ++i) {
104  selected2.push_back(1);
105  }
106 
107  std::map<reco::ConversionTrackCollection::const_iterator, std::vector<const TrackingRecHit*> > rh1;
108  std::map<reco::ConversionTrackCollection::const_iterator, std::vector<const TrackingRecHit*> > rh2;
109  for (reco::ConversionTrackCollection::const_iterator track = tC1.begin(); track != tC1.end(); ++track) {
110  trackingRecHit_iterator itB = track->track()->recHitsBegin();
111  trackingRecHit_iterator itE = track->track()->recHitsEnd();
112  for (trackingRecHit_iterator it = itB; it != itE; ++it) {
113  const TrackingRecHit* hit = &(**it);
114  rh1[track].push_back(hit);
115  }
116  }
117  for (reco::ConversionTrackCollection::const_iterator track = tC2.begin(); track != tC2.end(); ++track) {
118  trackingRecHit_iterator jtB = track->track()->recHitsBegin();
119  trackingRecHit_iterator jtE = track->track()->recHitsEnd();
120  for (trackingRecHit_iterator jt = jtB; jt != jtE; ++jt) {
121  const TrackingRecHit* hit = &(**jt);
122  rh2[track].push_back(hit);
123  }
124  }
125 
126  if ((!tC1.empty()) && (!tC2.empty())) {
127  i = -1;
128  for (reco::ConversionTrackCollection::iterator track = tC1.begin(); track != tC1.end(); ++track) {
129  i++;
130 
131  //clear flags if preferCollection was set to 0
132  selected1[i] = selected1[i] && outputPreferCollection != 0;
133  track->setIsTrackerOnly(track->isTrackerOnly() && trackerOnlyPreferCollection != 0);
134  track->setIsArbitratedEcalSeeded(track->isArbitratedEcalSeeded() && arbitratedEcalSeededPreferCollection != 0);
135  track->setIsArbitratedMerged(track->isArbitratedMerged() && arbitratedMergedPreferCollection != 0);
136  track->setIsArbitratedMergedEcalGeneral(track->isArbitratedMergedEcalGeneral() &&
137  arbitratedMergedEcalGeneralPreferCollection != 0);
138 
139  std::vector<const TrackingRecHit*>& iHits = rh1[track];
140  unsigned nh1 = iHits.size();
141  int j = -1;
142  for (reco::ConversionTrackCollection::iterator track2 = tC2.begin(); track2 != tC2.end(); ++track2) {
143  j++;
144 
145  //clear flags if preferCollection was set to 0
146  selected2[j] = selected2[j] && outputPreferCollection != 0;
147  track2->setIsTrackerOnly(track2->isTrackerOnly() && trackerOnlyPreferCollection != 0);
148  track2->setIsArbitratedEcalSeeded(track2->isArbitratedEcalSeeded() &&
149  arbitratedEcalSeededPreferCollection != 0);
150  track2->setIsArbitratedMerged(track2->isArbitratedMerged() && arbitratedMergedPreferCollection != 0);
151  track2->setIsArbitratedMergedEcalGeneral(track2->isArbitratedMergedEcalGeneral() &&
152  arbitratedMergedEcalGeneralPreferCollection != 0);
153 
154  std::vector<const TrackingRecHit*>& jHits = rh2[track2];
155  unsigned nh2 = jHits.size();
156  int noverlap = 0;
157  int firstoverlap = 0;
158  for (unsigned ih = 0; ih < nh1; ++ih) {
159  const TrackingRecHit* it = iHits[ih];
160  if (it->isValid()) {
161  int jj = -1;
162  for (unsigned jh = 0; jh < nh2; ++jh) {
163  const TrackingRecHit* jt = jHits[jh];
164  jj++;
165  if (jt->isValid()) {
166  if (it->sharesInput(jt, TrackingRecHit::some)) {
167  noverlap++;
168  if (allowFirstHitShare && (ih == 0) && (jh == 0))
169  firstoverlap = 1;
170  }
171  }
172  }
173  }
174  }
175  int nhit1 = track->track()->numberOfValidHits();
176  int nhit2 = track2->track()->numberOfValidHits();
177  //if (noverlap>0) printf("noverlap = %i, firstoverlap = %i, nhit1 = %i, nhit2 = %i, algo1 = %i, algo2 = %i, q1 = %i, q2 = %i\n",noverlap,firstoverlap,nhit1,nhit2,track->track()->algo(),track2->track()->algo(),track->track()->charge(),track2->track()->charge());
178  //std::cout << " trk1 trk2 nhits1 nhits2 nover " << i << " " << j << " " << track->numberOfValidHits() << " " << track2->numberOfValidHits() << " " << noverlap << " " << fi << " " << fj <<std::endl;
179  if ((noverlap - firstoverlap) > (std::min(nhit1, nhit2) - firstoverlap) * shareFrac &&
180  (!checkCharge || track->track()->charge() * track2->track()->charge() > 0)) {
181  //printf("overlapping tracks\n");
182  //printf ("ndof1 = %5f, chisq1 = %5f, ndof2 = %5f, chisq2 = %5f\n",track->track()->ndof(),track->track()->chi2(),track2->track()->ndof(),track2->track()->chi2());
183 
184  double probFirst = ChiSquaredProbability(track->track()->chi2(), track->track()->ndof());
185  double probSecond = ChiSquaredProbability(track2->track()->chi2(), track2->track()->ndof());
186 
187  //arbitrate by number of hits and reduced chisq
188  bool keepFirst = (nhit1 > nhit2 ||
189  (nhit1 == nhit2 && track->track()->normalizedChi2() < track2->track()->normalizedChi2()));
190 
191  //override decision in case one track is radically worse quality than the other
192  keepFirst |= (probFirst > minProb && probSecond <= minProb);
193  keepFirst &= !(probFirst <= minProb && probSecond > minProb);
194 
195  bool keepSecond = !keepFirst;
196 
197  //set flags based on arbitration decision and precedence settings
198 
199  selected1[i] = selected1[i] && ((keepFirst && outputPreferCollection == 3) || outputPreferCollection == -1 ||
200  outputPreferCollection == 1);
201  track->setIsTrackerOnly(track->isTrackerOnly() &&
202  ((keepFirst && trackerOnlyPreferCollection == 3) ||
203  trackerOnlyPreferCollection == -1 || trackerOnlyPreferCollection == 1));
204  track->setIsArbitratedEcalSeeded(track->isArbitratedEcalSeeded() &&
205  ((keepFirst && arbitratedEcalSeededPreferCollection == 3) ||
206  arbitratedEcalSeededPreferCollection == -1 ||
207  arbitratedEcalSeededPreferCollection == 1));
208  track->setIsArbitratedMerged(track->isArbitratedMerged() &&
209  ((keepFirst && arbitratedMergedPreferCollection == 3) ||
210  arbitratedMergedPreferCollection == -1 ||
211  arbitratedMergedPreferCollection == 1));
212  track->setIsArbitratedMergedEcalGeneral(track->isArbitratedMergedEcalGeneral() &&
213  ((keepFirst && arbitratedMergedEcalGeneralPreferCollection == 3) ||
214  arbitratedMergedEcalGeneralPreferCollection == -1 ||
215  arbitratedMergedEcalGeneralPreferCollection == 1));
216 
217  selected2[j] = selected2[j] && ((keepSecond && outputPreferCollection == 3) || outputPreferCollection == -1 ||
218  outputPreferCollection == 2);
219  track2->setIsTrackerOnly(track2->isTrackerOnly() &&
220  ((keepSecond && trackerOnlyPreferCollection == 3) ||
221  trackerOnlyPreferCollection == -1 || trackerOnlyPreferCollection == 2));
222  track2->setIsArbitratedEcalSeeded(track2->isArbitratedEcalSeeded() &&
223  ((keepSecond && arbitratedEcalSeededPreferCollection == 3) ||
224  arbitratedEcalSeededPreferCollection == -1 ||
225  arbitratedEcalSeededPreferCollection == 2));
226  track2->setIsArbitratedMerged(track2->isArbitratedMerged() &&
227  ((keepSecond && arbitratedMergedPreferCollection == 3) ||
228  arbitratedMergedPreferCollection == -1 ||
229  arbitratedMergedPreferCollection == 2));
230  track2->setIsArbitratedMergedEcalGeneral(track2->isArbitratedMergedEcalGeneral() &&
231  ((keepSecond && arbitratedMergedEcalGeneralPreferCollection == 3) ||
232  arbitratedMergedEcalGeneralPreferCollection == -1 ||
233  arbitratedMergedEcalGeneralPreferCollection == 2));
234 
235  } //end got a duplicate
236  } //end track2 loop
237  } //end track loop
238  } //end more than 1 track
239 
240  //
241  // output selected tracks - if any
242  //
243 
244  if (!tC1.empty()) {
245  i = 0;
246  for (reco::ConversionTrackCollection::const_iterator track = tC1.begin(); track != tC1.end(); ++track, ++i) {
247  //don't store tracks rejected as duplicates
248  if (!selected1[i]) {
249  continue;
250  }
251  //fill the TrackCollection
252  outputTrks->push_back(*track);
253  } //end faux loop over tracks
254  } //end more than 0 track
255 
256  //Fill the trajectories, etc. for 1st collection
257 
258  if (!tC2.empty()) {
259  i = 0;
260  for (reco::ConversionTrackCollection::const_iterator track = tC2.begin(); track != tC2.end(); ++track, ++i) {
261  //don't store tracks rejected as duplicates
262  if (!selected2[i]) {
263  continue;
264  }
265  //fill the TrackCollection
266  outputTrks->push_back(*track);
267  } //end faux loop over tracks
268  } //end more than 0 track
269 
271  return;
272 
273 } //end produce
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:131
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
edm::EDGetTokenT< reco::ConversionTrackCollection > trackProducer1
std::vector< ConversionTrack > ConversionTrackCollection
collection of ConversionTracks
std::unique_ptr< reco::ConversionTrackCollection > outputTrks
float ChiSquaredProbability(double chiSquared, double nrDOF)
T min(T a, T b)
Definition: MathUtil.h:58
bool isValid() const
Definition: HandleBase.h:70
T const * product() const
Definition: Handle.h:69
bool isValid() const
def move(src, dest)
Definition: eostools.py:511
edm::EDGetTokenT< reco::ConversionTrackCollection > trackProducer2

Member Data Documentation

edm::ParameterSet ConversionTrackMerger::conf_
private

Definition at line 38 of file ConversionTrackMerger.h.

Referenced by ConversionTrackMerger(), and produce().

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

Definition at line 43 of file ConversionTrackMerger.h.

Referenced by produce().

edm::EDGetTokenT<reco::ConversionTrackCollection> ConversionTrackMerger::trackProducer1
private

Definition at line 40 of file ConversionTrackMerger.h.

Referenced by ConversionTrackMerger(), and produce().

edm::EDGetTokenT<reco::ConversionTrackCollection> ConversionTrackMerger::trackProducer2
private

Definition at line 41 of file ConversionTrackMerger.h.

Referenced by ConversionTrackMerger(), and produce().