CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
TrackListMerger Class Reference
Inheritance diagram for TrackListMerger:
edm::stream::EDProducer<>

Classes

struct  TkEDGetTokenss
 

Public Member Functions

void produce (edm::Event &e, const edm::EventSetup &c) override
 
 TrackListMerger (const edm::ParameterSet &conf)
 
 ~TrackListMerger () override
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
bool hasAbilityToProduceInLumis () const final
 
bool hasAbilityToProduceInRuns () const final
 

Private Types

using MVACollection = std::vector< float >
 
using QualityMaskCollection = std::vector< unsigned char >
 

Private Member Functions

TkEDGetTokenss edTokens (const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
 
TkEDGetTokenss edTokens (const edm::InputTag &tag, const edm::InputTag &mvatag)
 

Private Attributes

bool allowFirstHitShare_
 
bool copyExtras_
 
bool copyMVA_
 
float epsilon_
 
float foundHitBonus_
 
std::vector< int > hasSelector_
 
std::vector< double > indivShareFrac_
 
std::vector< std::vector< int > > listsToMerge_
 
float lostHitPenalty_
 
bool makeReKeyedSeeds_
 
double maxNormalizedChisq_
 
unsigned int minFound_
 
double minPT_
 
std::unique_ptr< TrajectorySeedCollectionoutputSeeds
 
std::unique_ptr< std::vector< Trajectory > > outputTrajs
 
std::unique_ptr< reco::TrackExtraCollectionoutputTrkExtras
 
std::unique_ptr< TrackingRecHitCollectionoutputTrkHits
 
std::unique_ptr< reco::TrackCollectionoutputTrks
 
std::unique_ptr< TrajTrackAssociationCollectionoutputTTAss
 
std::string priorityName_
 
std::vector< bool > promoteQuality_
 
reco::TrackBase::TrackQuality qualityToSet_
 
edm::RefProd< std::vector< Trajectory > > refTrajs
 
edm::RefProd< TrajectorySeedCollectionrefTrajSeeds
 
reco::TrackExtraRefProd refTrkExtras
 
TrackingRecHitRefProd refTrkHits
 
reco::TrackRefProd refTrks
 
float shareFrac_
 
std::vector< TkEDGetTokensstrackProducers_
 
bool trkQualMod_
 
bool use_sharesInput_
 

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 31 of file TrackListMerger.cc.

Member Typedef Documentation

using TrackListMerger::MVACollection = std::vector<float>
private

Definition at line 43 of file TrackListMerger.cc.

using TrackListMerger::QualityMaskCollection = std::vector<unsigned char>
private

Definition at line 44 of file TrackListMerger.cc.

Constructor & Destructor Documentation

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

Definition at line 207 of file TrackListMerger.cc.

References Exception, edm::ParameterSet::exists(), edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), mps_fire::i, createfilelist::int, label, convertSQLiteXML::ok, reco::TrackBase::qualityByName(), TrackValidation_cff::selectors, hiMuonIterativeTk_cff::setsToMerge, AlCaHLTBitMon_QueryRunRegistry::string, and reco::TrackBase::undefQuality.

207  {
208  copyExtras_ = conf.getUntrackedParameter<bool>("copyExtras", true);
209 
210  std::vector<edm::InputTag> trackProducerTags(conf.getParameter<std::vector<edm::InputTag> >("TrackProducers"));
211  //which of these do I need to turn into vectors?
212  maxNormalizedChisq_ = conf.getParameter<double>("MaxNormalizedChisq");
213  minPT_ = conf.getParameter<double>("MinPT");
214  minFound_ = (unsigned int)conf.getParameter<int>("MinFound");
215  epsilon_ = conf.getParameter<double>("Epsilon");
216  shareFrac_ = conf.getParameter<double>("ShareFrac");
217  allowFirstHitShare_ = conf.getParameter<bool>("allowFirstHitShare");
218  foundHitBonus_ = conf.getParameter<double>("FoundHitBonus");
219  lostHitPenalty_ = conf.getParameter<double>("LostHitPenalty");
220  indivShareFrac_=conf.getParameter<std::vector<double> >("indivShareFrac");
221  std::string qualityStr = conf.getParameter<std::string>("newQuality");
222 
223  if (!qualityStr.empty()) {
225  }
226  else
228 
229  use_sharesInput_ = true;
230  if ( epsilon_ > 0.0 )use_sharesInput_ = false;
231 
233 
234  for ( unsigned int i=0; i<setsToMerge.size(); i++) {
235  listsToMerge_.push_back(setsToMerge[i].getParameter<std::vector< int> >("tLists"));
236  promoteQuality_.push_back(setsToMerge[i].getParameter<bool>("pQual"));
237  }
238  hasSelector_ = conf.getParameter<std::vector<int> > ("hasSelector");
239  copyMVA_ = conf.getParameter<bool>("copyMVA");
240 
241  std::vector<edm::InputTag> selectors(conf.getParameter<std::vector<edm::InputTag> >("selectedTrackQuals"));
242  std::vector<edm::InputTag> mvaStores;
243  if(conf.exists("mvaValueTags")){
244  mvaStores = conf.getParameter<std::vector<edm::InputTag> >("mvaValueTags");
245  }else{
246  for (int i = 0; i < (int)selectors.size(); i++){
247  edm::InputTag ntag(selectors[i].label(),"MVAVals");
248  mvaStores.push_back(ntag);
249  }
250  }
251  unsigned int numTrkColl = trackProducerTags.size();
252  if (numTrkColl != hasSelector_.size() || numTrkColl != selectors.size()) {
253  throw cms::Exception("Inconsistent size") << "need same number of track collections and selectors";
254  }
255  if (numTrkColl != hasSelector_.size() || numTrkColl != mvaStores.size()) {
256  throw cms::Exception("Inconsistent size") << "need same number of track collections and MVA stores";
257  }
258  for (unsigned int i = indivShareFrac_.size(); i < numTrkColl; i++) {
259  // edm::LogWarning("TrackListMerger") << "No indivShareFrac for " << trackProducersTags <<". Using default value of 1";
260  indivShareFrac_.push_back(1.0);
261  }
262 
263  trkQualMod_=conf.getParameter<bool>("writeOnlyTrkQuals");
264  if ( trkQualMod_) {
265  bool ok=true;
266  for ( unsigned int i=1; i<numTrkColl; i++) {
267  if (!(trackProducerTags[i]==trackProducerTags[0])) ok=false;
268  }
269  if ( !ok) {
270  throw cms::Exception("Bad input") << "to use writeOnlyTrkQuals=True all input InputTags must be the same";
271  }
272  produces<edm::ValueMap<int> >();
273  produces<QualityMaskCollection>("QualityMasks");
274  }
275  else{
276  produces<reco::TrackCollection>();
277 
278  makeReKeyedSeeds_ = conf.getUntrackedParameter<bool>("makeReKeyedSeeds",false);
279  if (makeReKeyedSeeds_){
280  copyExtras_=true;
281  produces<TrajectorySeedCollection>();
282  }
283 
284  if (copyExtras_) {
285  produces<reco::TrackExtraCollection>();
286  produces<TrackingRecHitCollection>();
287  }
288  produces< std::vector<Trajectory> >();
289  produces< TrajTrackAssociationCollection >();
290  }
291  produces<edm::ValueMap<float> >("MVAVals");
292  produces<MVACollection>("MVAValues");
293 
294  // Do all the consumes
295  trackProducers_.resize(numTrkColl);
296  for (unsigned int i = 0; i < numTrkColl; ++i) {
297  trackProducers_[i] = hasSelector_[i]>0 ? edTokens(trackProducerTags[i], selectors[i], mvaStores[i]) : edTokens(trackProducerTags[i], mvaStores[i]);
298  }
299 
300  priorityName_ = conf.getParameter<std::string>("trackAlgoPriorityOrder");
301 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::vector< bool > promoteQuality_
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
reco::TrackBase::TrackQuality qualityToSet_
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< double > indivShareFrac_
char const * label
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
std::vector< int > hasSelector_
double maxNormalizedChisq_
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:134
unsigned int minFound_
std::vector< TkEDGetTokenss > trackProducers_
std::string priorityName_
std::vector< std::vector< int > > listsToMerge_
TrackListMerger::~TrackListMerger ( )
override

Definition at line 305 of file TrackListMerger.cc.

305 { }

Member Function Documentation

TkEDGetTokenss TrackListMerger::edTokens ( const edm::InputTag tag,
const edm::InputTag seltag,
const edm::InputTag mvatag 
)
inlineprivate

Definition at line 75 of file TrackListMerger.cc.

75  {
76  return TkEDGetTokenss(tag, consumes<reco::TrackCollection>(tag),
77  consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
78  consumes<edm::ValueMap<int> >(seltag), consumes<edm::ValueMap<float> >(mvatag));
79  }
TkEDGetTokenss TrackListMerger::edTokens ( const edm::InputTag tag,
const edm::InputTag mvatag 
)
inlineprivate

Definition at line 80 of file TrackListMerger.cc.

80  {
81  return TkEDGetTokenss(tag, consumes<reco::TrackCollection>(tag),
82  consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
84  }
void TrackListMerger::produce ( edm::Event e,
const edm::EventSetup c 
)
override

Definition at line 308 of file TrackListMerger.cc.

References funct::abs(), patPFMETCorrections_cff::algo, reco::TrackBase::algo(), edm::OwnVector< T, P >::back(), begin, reco::TrackBase::chi2(), edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > >::const_iterator, constexpr, DEFINE_FWK_MODULE, delta, TrajectorySeed::direction(), end, edm::AssociationMap< Tag >::end(), reco::Track::extra(), edm::HandleBase::failedToGet(), objects.autophobj::filler, spr::find(), edm::AssociationMap< Tag >::find(), plotBeamSpotDB::first, objects.autophobj::float, TrackingRecHit::geographicalId(), edm::EventSetup::get(), edm::Event::getByLabel(), edm::Event::getByToken(), edm::Event::getProvenance(), edm::Event::getRefBeforePut(), reco::TrackBase::highPurity, reco::TrackBase::hitPattern(), mps_fire::i, edm::ProductID::id(), edm::Ref< C, T, F >::id(), globals_cff::id1, globals_cff::id2, cuy::ii, reco::Track::innerDetId(), reco::Track::innerMomentum(), reco::Track::innerOk(), reco::Track::innerPosition(), reco::Track::innerStateCovariance(), TrackingRecHit::isValid(), findQualityFiles::jj, edm::Ref< C, T, F >::key(), LIKELY, TrackingRecHit::localPosition(), reco::TrackBase::loose, electrons_cff::lostHits, match(), SiStripPI::max, min(), edm::Provenance::moduleLabel(), eostools::move(), RecoTauHPSTancTauProdcuer_cfi::mvas, gen::n, TrajectorySeed::nHits(), reco::TrackBase::numberOfLostHits(), reco::TrackBase::numberOfValidHits(), reco::HitPattern::numberOfValidPixelHits(), reco::Track::outerDetId(), reco::Track::outerMomentum(), reco::Track::outerOk(), reco::Track::outerPosition(), reco::Track::outerStateCovariance(), edm::Provenance::processName(), edm::Provenance::productInstanceName(), edm::OwnVector< T, P >::push_back(), edm::Event::put(), lumiQueryAPI::q, TrackingRecHit::rawId(), TrajectorySeed::recHits(), reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), reco::TrackExtraBase::recHitsSize(), reco::Track::recHitsSize(), ClusterRemovalRefSetter::reKey(), edm::OwnVector< T, P >::reserve(), reco::Track::residuals(), offlineSlimmedPrimaryVertices_cfi::score, reco::Track::seedDirection(), reco::Track::seedRef(), reco::TrackExtraBase::setHits(), reco::TrackExtra::setResiduals(), reco::TrackExtraBase::setTrajParams(), TrackingRecHit::some, TrajectorySeed::startingState(), DetId::subdetId(), reco::TrackBase::tight, HiIsolationCommonParameters_cff::track, trackAlgoPriorityOrder, reco::TrackExtraBase::trajParams(), reco::TrackBase::undefAlgorithm, UNLIKELY, and PV3DBase< T, PVType, FrameType >::x().

309  {
310  // extract tracker geometry
311  //
312  //edm::ESHandle<TrackerGeometry> theG;
313  //es.get<TrackerDigiGeometryRecord>().get(theG);
314 
315  // using namespace reco;
316 
318  es.get<CkfComponentsRecord>().get(priorityName_, priorityH);
319  auto const & trackAlgoPriorityOrder = *priorityH;
320 
321  // get Inputs
322  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
323  // this allows TrackListMerger to be used as a cleaner only if handed just one list
324  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
325  //
326  static const reco::TrackCollection s_empty;
327 
328  std::vector<const reco::TrackCollection *> trackColls;
329  std::vector<edm::Handle<reco::TrackCollection> > trackHandles(trackProducers_.size());
330  for ( unsigned int i=0; i<trackProducers_.size(); i++) {
331  trackColls.push_back(nullptr);
332  //edm::Handle<reco::TrackCollection> trackColl;
333  e.getByToken(trackProducers_[i].tk, trackHandles[i]);
334  if (trackHandles[i].isValid()) {
335  trackColls[i]= trackHandles[i].product();
336  } else {
337  edm::LogWarning("TrackListMerger") << "TrackCollection " << trackProducers_[i].tag <<" not found";
338  trackColls[i]=&s_empty;
339  }
340  }
341 
342  unsigned int collsSize =trackColls.size();
343  unsigned int rSize=0;
344  unsigned int trackCollSizes[collsSize];
345  unsigned int trackCollFirsts[collsSize];
346  for (unsigned int i=0; i!=collsSize; i++) {
347  trackCollSizes[i]=trackColls[i]->size();
348  trackCollFirsts[i]=rSize;
349  rSize+=trackCollSizes[i];
350  }
351 
352  statCount.begin(rSize);
353 
354  //
355  // quality cuts first
356  //
357  int i=-1;
358 
359  int selected[rSize];
360  int indexG[rSize];
361  bool trkUpdated[rSize];
362  int trackCollNum[rSize];
363  int trackQuals[rSize];
364  float trackMVAs[rSize];
365  reco::TrackBase::TrackAlgorithm oriAlgo[rSize];
366  std::vector<reco::TrackBase::AlgoMask> algoMask(rSize);
367  for (unsigned int j=0; j<rSize;j++) {
368  indexG[j]=-1; selected[j]=1; trkUpdated[j]=false; trackCollNum[j]=0; trackQuals[j]=0;trackMVAs[j] = -998.0;oriAlgo[j]=reco::TrackBase::undefAlgorithm;
369  }
370 
371  int ngood=0;
372  for (unsigned int j=0; j!= collsSize; j++) {
373  const reco::TrackCollection *tC1=trackColls[j];
374 
375  edm::Handle<edm::ValueMap<int> > trackSelColl;
376  edm::Handle<edm::ValueMap<float> > trackMVAStore;
377  if ( copyMVA_ )
378  e.getByToken(trackProducers_[j].tmva, trackMVAStore);
379  if ( hasSelector_[j]>0 ){
380  e.getByToken(trackProducers_[j].tsel, trackSelColl);
381  }
382 
383  if ( !tC1->empty() ){
384  unsigned int iC=0;
385  for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
386  i++;
387  trackCollNum[i]=j;
388  trackQuals[i]=track->qualityMask();
389  oriAlgo[i]=track->originalAlgo();
390  algoMask[i]=track->algoMask();
391 
392  reco::TrackRef trkRef=reco::TrackRef(trackHandles[j],iC);
393  if ( copyMVA_ )
394  if( (*trackMVAStore).contains(trkRef.id()) ) trackMVAs[i] = (*trackMVAStore)[trkRef];
395  if ( hasSelector_[j]>0 ) {
396  int qual=(*trackSelColl)[trkRef];
397  if ( qual < 0 ) {
398  selected[i]=0;
399  iC++;
400  continue;
401  }else{
402  trackQuals[i]=qual;
403  }
404  }
405  iC++;
406  selected[i]=trackQuals[i]+10;//10 is magic number used throughout...
407  if ((short unsigned)track->ndof() < 1){
408  selected[i]=0;
409  continue;
410  }
411  if (track->normalizedChi2() > maxNormalizedChisq_){
412  selected[i]=0;
413  continue;
414  }
415  if (track->found() < minFound_){
416  selected[i]=0;
417  continue;
418  }
419  if (track->pt() < minPT_){
420  selected[i]=0;
421  continue;
422  }
423  // good!
424  indexG[i] = ngood++;
425  //if ( beVerb) std::cout << "inverb " << track->pt() << " " << selected[i] << std::endl;
426  }//end loop over tracks
427  }//end more than 0 track
428  } // loop over trackcolls
429 
430 
431  statCount.pre(ngood);
432 
433  //cache the id and rechits of valid hits
434  typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
435  std::vector<std::vector<IHit>> rh1(ngood); // "not an array" of vectors!
436  //const TrackingRecHit* fh1[ngood]; // first hit...
438  float score[ngood];
439 
440 
441  for ( unsigned int j=0; j<rSize; j++) {
442  if (selected[j]==0) continue;
443  int i = indexG[j];
444  assert(i>=0);
445  unsigned int collNum=trackCollNum[j];
446  unsigned int trackNum=j-trackCollFirsts[collNum];
447  const reco::Track *track=&((trackColls[collNum])->at(trackNum));
448 
449  algo[i]=track->algo();
450  int validHits=track->numberOfValidHits();
451  int validPixelHits=track->hitPattern().numberOfValidPixelHits();
452  int lostHits=track->numberOfLostHits();
453  score[i] = foundHitBonus_*validPixelHits+foundHitBonus_*validHits - lostHitPenalty_*lostHits - track->chi2();
454 
455 
456  rh1[i].reserve(validHits) ;
457  auto compById = [](IHit const & h1, IHit const & h2) {return h1.first < h2.first;};
458  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); ++it) {
459  const TrackingRecHit* hit = (*it);
460  unsigned int id = hit->rawId() ;
461  if(hit->geographicalId().subdetId()>2) id &= (~3); // mask mono/stereo in strips...
462  if LIKELY(hit->isValid()) { rh1[i].emplace_back(id,hit); std::push_heap(rh1[i].begin(),rh1[i].end(),compById); }
463  }
464  std::sort_heap(rh1[i].begin(),rh1[i].end(),compById);
465  }
466 
467  //DL here
468  if LIKELY(ngood>1 && collsSize>1)
469  for ( unsigned int ltm=0; ltm<listsToMerge_.size(); ltm++) {
470  int saveSelected[rSize];
471  bool notActive[collsSize];
472  for (unsigned int cn=0;cn!=collsSize;++cn)
473  notActive[cn]= find(listsToMerge_[ltm].begin(),listsToMerge_[ltm].end(),cn)==listsToMerge_[ltm].end();
474 
475  for ( unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
476 
477  //DL protect against 0 tracks?
478  for ( unsigned int i=0; i<rSize-1; i++) {
479  if (selected[i]==0) continue;
480  unsigned int collNum=trackCollNum[i];
481 
482  //check that this track is in one of the lists for this iteration
483  if (notActive[collNum]) continue;
484 
485  int k1 = indexG[i];
486  unsigned int nh1=rh1[k1].size();
487  int qualityMaskT1 = trackQuals[i];
488 
489  int nhit1 = nh1; // validHits[k1];
490  float score1 = score[k1];
491 
492  // start at next collection
493  for ( unsigned int j=i+1; j<rSize; j++) {
494  if (selected[j]==0) continue;
495  unsigned int collNum2=trackCollNum[j];
496  if ( (collNum == collNum2) && indivShareFrac_[collNum] > 0.99) continue;
497  //check that this track is in one of the lists for this iteration
498  if (notActive[collNum2]) continue;
499 
500  int k2 = indexG[j];
501 
502  int newQualityMask = -9; //avoid resetting quality mask if not desired 10+ -9 =1
503  if (promoteQuality_[ltm]) {
504  int maskT1= saveSelected[i]>1? saveSelected[i]-10 : qualityMaskT1;
505  int maskT2= saveSelected[j]>1? saveSelected[j]-10 : trackQuals[j];
506  newQualityMask =(maskT1 | maskT2); // take OR of trackQuality
507  }
508  unsigned int nh2=rh1[k2].size();
509  int nhit2 = nh2;
510 
511 
512  auto share = use_sharesInput_ ?
513  [](const TrackingRecHit* it,const TrackingRecHit* jt, float)->bool { return it->sharesInput(jt,TrackingRecHit::some); } :
514  [](const TrackingRecHit* it,const TrackingRecHit* jt, float eps)->bool {
515  float delta = std::abs ( it->localPosition().x()-jt->localPosition().x() );
516  return (it->geographicalId()==jt->geographicalId())&&(delta<eps);
517  };
518 
519  statCount.start();
520 
521  //loop over rechits
522  int noverlap=0;
523  int firstoverlap=0;
524  // check first hit (should use REAL first hit?)
525  if UNLIKELY(allowFirstHitShare_ && rh1[k1][0].first==rh1[k2][0].first ) {
526  const TrackingRecHit* it = rh1[k1][0].second;
527  const TrackingRecHit* jt = rh1[k2][0].second;
528  if (share(it,jt,epsilon_)) firstoverlap=1;
529  }
530 
531 
532  // exploit sorting
533  unsigned int jh=0;
534  unsigned int ih=0;
535  while (ih!=nh1 && jh!=nh2) {
536  // break if not enough to go...
537  // if ( nprecut-noverlap+firstoverlap > int(nh1-ih)) break;
538  // if ( nprecut-noverlap+firstoverlap > int(nh2-jh)) break;
539  auto const id1 = rh1[k1][ih].first;
540  auto const id2 = rh1[k2][jh].first;
541  if (id1<id2) ++ih;
542  else if (id2<id1) ++jh;
543  else {
544  // in case of split-hit do full conbinatorics
545  auto li=ih; while( (++li)!=nh1 && id1 == rh1[k1][li].first);
546  auto lj=jh; while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
547  for (auto ii=ih; ii!=li; ++ii)
548  for (auto jj=jh; jj!=lj; ++jj) {
549  const TrackingRecHit* it = rh1[k1][ii].second;
550  const TrackingRecHit* jt = rh1[k2][jj].second;
551  if (share(it,jt,epsilon_)) noverlap++;
552  }
553  jh=lj; ih=li;
554  } // equal ids
555 
556  } //loop over ih & jh
557 
558  bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*shareFrac_ :
559  (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*indivShareFrac_[collNum];
560 
561  auto seti = [&](unsigned int ii, unsigned int jj) {
562  selected[jj]=0;
563  selected[ii]=10+newQualityMask; // add 10 to avoid the case where mask = 1
564  trkUpdated[ii]=true;
565  if (trackAlgoPriorityOrder.priority(oriAlgo[jj]) < trackAlgoPriorityOrder.priority(oriAlgo[ii])) oriAlgo[ii] = oriAlgo[jj];
566  algoMask[ii] |= algoMask[jj];
567  algoMask[jj] = algoMask[ii]; // in case we keep discarded
568  };
569 
570  if ( dupfound ) {
571  float score2 = score[k2];
572  constexpr float almostSame = 0.01f; // difference rather than ratio due to possible negative values for score
573  if ( score1 - score2 > almostSame ) {
574  seti(i,j);
575  } else if ( score2 - score1 > almostSame ) {
576  seti(j,i);
577  }else{
578  // If tracks from both iterations are virtually identical, choose the one with the best quality or with lower algo
581  //same quality, pick earlier algo
582  if (trackAlgoPriorityOrder.priority(algo[k1]) <= trackAlgoPriorityOrder.priority(algo[k2])) {
583  seti(i,j);
584  } else {
585  seti(j,i);
586  }
587  } else if ((trackQuals[j] & (1<<reco::TrackBase::loose|1<<reco::TrackBase::tight|1<<reco::TrackBase::highPurity) ) <
589  seti(i,j);
590  }else{
591  seti(j,i);
592  }
593  }//end fi < fj
594  statCount.overlap();
595  /*
596  if (at0[k1]&&at0[k2]) {
597  statCount.dp(dphi);
598  if (dz<1.f) statCount.de(deta);
599  }
600  */
601  }//end got a duplicate
602  else {
603  statCount.noOverlap();
604  }
605  //stop if the ith track is now unselected
606  if (selected[i]==0) break;
607  }//end track2 loop
608  }//end track loop
609  } //end loop over track list sets
610 
611 
612 
613  auto vmMVA = std::make_unique<edm::ValueMap<float>>();
614  edm::ValueMap<float>::Filler fillerMVA(*vmMVA);
615 
616 
617 
618  // special case - if just doing the trkquals
619  if (trkQualMod_) {
620  unsigned int tSize=trackColls[0]->size();
621  auto vm = std::make_unique<edm::ValueMap<int>>();
623 
624  std::vector<int> finalQuals(tSize,-1); //default is unselected
625  for ( unsigned int i=0; i<rSize; i++) {
626  unsigned int tNum=i%tSize;
627 
628  if (selected[i]>1 ) {
629  finalQuals[tNum]=selected[i]-10;
630  if (trkUpdated[i])
631  finalQuals[tNum]=(finalQuals[tNum] | (1<<qualityToSet_));
632  }
633  if ( selected[i]==1 )
634  finalQuals[tNum]=trackQuals[i];
635  }
636 
637  filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
638  filler.fill();
639 
640  e.put(std::move(vm));
641  for (auto & q : finalQuals) q=std::max(q,0);
642  auto quals = std::make_unique<QualityMaskCollection>(finalQuals.begin(),finalQuals.end());
643  e.put(std::move(quals),"QualityMasks");
644 
645  std::vector<float> mvaVec(tSize,-99);
646 
647  for(unsigned int i = 0; i < rSize; i++){
648  unsigned int tNum = i % tSize;
649  mvaVec[tNum] = trackMVAs[tNum];
650  }
651 
652  fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
653  fillerMVA.fill();
654  if ( copyMVA_) {
655  e.put(std::move(vmMVA),"MVAVals");
656  auto mvas = std::make_unique<MVACollection>(mvaVec.begin(),mvaVec.end());
657  e.put(std::move(mvas),"MVAValues");
658  }
659  return;
660  }
661 
662 
663  //
664  // output selected tracks - if any
665  //
666 
667  std::vector<reco::TrackRef> trackRefs(rSize);
668  std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
669 
670  unsigned int nToWrite=0;
671  for ( unsigned int i=0; i<rSize; i++)
672  if (selected[i]!=0) nToWrite++;
673 
674  std::vector<float> mvaVec;
675 
676  outputTrks = std::make_unique<reco::TrackCollection>();
677  outputTrks->reserve(nToWrite);
679 
680  if (copyExtras_) {
681  outputTrkExtras = std::make_unique<reco::TrackExtraCollection>();
682  outputTrkExtras->reserve(nToWrite);
684  outputTrkHits = std::make_unique<TrackingRecHitCollection>();
685  outputTrkHits->reserve(nToWrite*25);
687  if (makeReKeyedSeeds_){
688  outputSeeds = std::make_unique<TrajectorySeedCollection>();
689  outputSeeds->reserve(nToWrite);
691  }
692  }
693 
694 
695  outputTrajs = std::make_unique<std::vector<Trajectory>>();
696  outputTrajs->reserve(rSize);
697 
698  for ( unsigned int i=0; i<rSize; i++) {
699  if (selected[i]==0) {
700  trackRefs[i]=reco::TrackRef();
701  continue;
702  }
703 
704  unsigned int collNum=trackCollNum[i];
705  unsigned int trackNum=i-trackCollFirsts[collNum];
706  const reco::Track *track=&((trackColls[collNum])->at(trackNum));
707  outputTrks->push_back( reco::Track( *track ) );
708  mvaVec.push_back(trackMVAs[i]);
709  if (selected[i]>1 ) {
710  outputTrks->back().setQualityMask(selected[i]-10);
711  if (trkUpdated[i])
712  outputTrks->back().setQuality(qualityToSet_);
713  }
714  //might duplicate things, but doesnt hurt
715  if ( selected[i]==1 )
716  outputTrks->back().setQualityMask(trackQuals[i]);
717  outputTrks->back().setOriginalAlgorithm(oriAlgo[i]);
718  outputTrks->back().setAlgoMask(algoMask[i]);
719 
720  // if ( beVerb ) std::cout << "selected " << outputTrks->back().pt() << " " << outputTrks->back().qualityMask() << " " << selected[i] << std::endl;
721 
722  //fill the TrackCollection
723  if (copyExtras_) {
724  edm::RefToBase<TrajectorySeed> origSeedRef = track->seedRef();
725  //creating a seed with rekeyed clusters if required
726  if (makeReKeyedSeeds_){
727  bool doRekeyOnThisSeed=false;
728 
729  edm::InputTag clusterRemovalInfos("");
730  //grab on of the hits of the seed
731  if (origSeedRef->nHits()!=0){
732  TrajectorySeed::const_iterator firstHit=origSeedRef->recHits().first;
733  const TrackingRecHit *hit = &*firstHit;
734  if (firstHit->isValid()){
735  edm::ProductID pID=clusterProductB(hit);
736  // the cluster collection either produced a removalInfo or mot
737  //get the clusterremoval info from the provenance: will rekey if this is found
739  edm::Provenance prov=e.getProvenance(pID);
740  clusterRemovalInfos=edm::InputTag(prov.moduleLabel(),
741  prov.productInstanceName(),
742  prov.processName());
743  doRekeyOnThisSeed=e.getByLabel(clusterRemovalInfos,CRIh);
744  }//valid hit
745  }//nhit!=0
746 
747  if (doRekeyOnThisSeed && !(clusterRemovalInfos==edm::InputTag(""))) {
748  ClusterRemovalRefSetter refSetter(e,clusterRemovalInfos);
749  TrajectorySeed::recHitContainer newRecHitContainer;
750  newRecHitContainer.reserve(origSeedRef->nHits());
751  TrajectorySeed::const_iterator iH=origSeedRef->recHits().first;
752  TrajectorySeed::const_iterator iH_end=origSeedRef->recHits().second;
753  for (;iH!=iH_end;++iH){
754  newRecHitContainer.push_back(*iH);
755  refSetter.reKey(&newRecHitContainer.back());
756  }
757  outputSeeds->push_back( TrajectorySeed( origSeedRef->startingState(),
758  newRecHitContainer,
759  origSeedRef->direction()));
760  }
761  //doRekeyOnThisSeed=true
762  else{
763  //just copy the one we had before
764  outputSeeds->push_back( TrajectorySeed(*origSeedRef));
765  }
767  origSeedRef=edm::RefToBase<TrajectorySeed>( pureRef);
768  }//creating a new seed and rekeying it rechit clusters.
769 
770  // Fill TrackExtra collection
771  outputTrkExtras->push_back( reco::TrackExtra(
772  track->outerPosition(), track->outerMomentum(), track->outerOk(),
773  track->innerPosition(), track->innerMomentum(), track->innerOk(),
774  track->outerStateCovariance(), track->outerDetId(),
775  track->innerStateCovariance(), track->innerDetId(),
776  track->seedDirection(), origSeedRef ) );
777  seedsRefs[i]=origSeedRef;
778  outputTrks->back().setExtra( reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
779  reco::TrackExtra & tx = outputTrkExtras->back();
780  tx.setResiduals(track->residuals());
781 
782  // fill TrackingRecHits
783  unsigned nh1=track->recHitsSize();
784  tx.setHits(refTrkHits,outputTrkHits->size(),nh1);
785  tx.setTrajParams(track->extra()->trajParams(),track->extra()->chi2sX5());
786  assert(tx.trajParams().size()==tx.recHitsSize());
787  for (auto hh = track->recHitsBegin(), eh=track->recHitsEnd(); hh!=eh; ++hh ) {
788  outputTrkHits->push_back( (*hh)->clone() );
789  }
790  }
791  trackRefs[i] = reco::TrackRef(refTrks, outputTrks->size() - 1);
792 
793 
794  }//end faux loop over tracks
795 
796  //Fill the trajectories, etc. for 1st collection
797  refTrajs = e.getRefBeforePut< std::vector<Trajectory> >();
798 
799  outputTTAss = std::make_unique<TrajTrackAssociationCollection>(refTrajs, refTrks);
800 
801  for (unsigned int ti=0; ti<trackColls.size(); ti++) {
804  e.getByToken(trackProducers_[ti].traj, hTraj1);
805  e.getByToken(trackProducers_[ti].tass, hTTAss1);
806 
807  if (hTraj1.failedToGet() || hTTAss1.failedToGet()) continue;
808 
809  for (size_t i = 0, n = hTraj1->size(); i < n; ++i) {
810  edm::Ref< std::vector<Trajectory> > trajRef(hTraj1, i);
812  if (match != hTTAss1->end()) {
813  const edm::Ref<reco::TrackCollection> &trkRef = match->val;
814  uint32_t oldKey = trackCollFirsts[ti]+static_cast<uint32_t>(trkRef.key());
815  if (trackRefs[oldKey].isNonnull()) {
816  outputTrajs->push_back( *trajRef );
817  //if making extras and the seeds at the same time, change the seed ref on the trajectory
819  outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
820  outputTTAss->insert ( edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),
821  trackRefs[oldKey] );
822  }
823  }
824  }
825  }
826 
827  statCount.end(outputTrks->size());
828 
829  edm::ProductID nPID = refTrks.id();
831  fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
832  fillerMVA.fill();
833 
835  if ( copyMVA_ ) {
836  e.put(std::move(vmMVA),"MVAVals");
837  auto mvas = std::make_unique<MVACollection>(mvaVec.begin(),mvaVec.end());
838  e.put(std::move(mvas),"MVAValues");
839  }
840  if (copyExtras_) {
842  e.put(std::move(outputTrkHits));
843  if (makeReKeyedSeeds_)
845  }
846  e.put(std::move(outputTrajs));
847  e.put(std::move(outputTTAss));
848  return;
849 
850  }//end produce
PropagationDirection direction() const
size
Write out results.
dbl * delta
Definition: mlp_gen.cc:36
const edm::RefToBase< TrajectorySeed > & seedRef() const
Definition: Track.h:218
std::unique_ptr< TrajTrackAssociationCollection > outputTTAss
reference back()
Definition: OwnVector.h:395
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
std::vector< bool > promoteQuality_
const TrackExtraRef & extra() const
reference to "extra" object
Definition: Track.h:194
const_iterator end() const
last iterator over the map (read only)
reco::TrackRefProd refTrks
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
edm::RefProd< std::vector< Trajectory > > refTrajs
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:124
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
const_iterator find(const key_type &k) const
find element with specified reference key
size_type size() const
Definition: OwnVector.h:264
reco::TrackBase::TrackQuality qualityToSet_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
#define LIKELY(x)
Definition: Likely.h:20
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:52
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:895
std::unique_ptr< TrajectorySeedCollection > outputSeeds
key_type key() const
Accessor for product key.
Definition: Ref.h:263
std::string const & processName() const
Definition: Provenance.h:55
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:67
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
std::unique_ptr< std::vector< Trajectory > > outputTrajs
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
TrackAlgorithm
track algorithm
Definition: TrackBase.h:99
TrackingRecHitRefProd refTrkHits
std::vector< double > indivShareFrac_
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:57
TrackAlgorithm algo() const
Definition: TrackBase.h:530
void push_back(D *&d)
Definition: OwnVector.h:290
std::unique_ptr< TrackingRecHitCollection > outputTrkHits
std::vector< TrajectorySeed > TrajectorySeedCollection
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:582
recHitContainer::const_iterator const_iterator
unsigned int recHitsSize() const
number of RecHits
TrajParams const & trajParams() const
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:77
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:96
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:889
#define end
Definition: vmac.h:39
T min(T a, T b)
Definition: MathUtil.h:58
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:109
virtual LocalPoint localPosition() const =0
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:480
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
std::unique_ptr< reco::TrackExtraCollection > outputTrkExtras
std::vector< int > hasSelector_
ii
Definition: cuy.py:590
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:137
bool failedToGet() const
Definition: HandleBase.h:78
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
double maxNormalizedChisq_
PTrajectoryStateOnDet const & startingState() const
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:72
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:47
const PropagationDirection & seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:209
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:479
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:21
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:82
range recHits() const
bool isValid() const
std::string const & moduleLabel() const
Definition: Provenance.h:53
unsigned int nHits() const
#define begin
Definition: vmac.h:32
unsigned int minFound_
std::vector< TkEDGetTokenss > trackProducers_
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:62
const TrackResiduals & residuals() const
get the residuals
Definition: Track.h:223
int numberOfValidPixelHits() const
Definition: HitPattern.h:916
std::unique_ptr< reco::TrackCollection > outputTrks
std::array< unsigned int, reco::TrackBase::algoSize > trackAlgoPriorityOrder
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
DetId geographicalId() const
#define UNLIKELY(x)
Definition: Likely.h:21
std::string const & productInstanceName() const
Definition: Provenance.h:56
std::string priorityName_
std::vector< std::vector< int > > listsToMerge_
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:105
T x() const
Definition: PV3DBase.h:62
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:101
def move(src, dest)
Definition: eostools.py:511
id_type rawId() const
#define constexpr
void reserve(size_t)
Definition: OwnVector.h:284
void setTrajParams(TrajParams tmps, Chi2sFive chi2s)
reco::TrackExtraRefProd refTrkExtras
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:114
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:174

Member Data Documentation

bool TrackListMerger::allowFirstHitShare_
private

Definition at line 103 of file TrackListMerger.cc.

bool TrackListMerger::copyExtras_
private

Definition at line 59 of file TrackListMerger.cc.

bool TrackListMerger::copyMVA_
private

Definition at line 101 of file TrackListMerger.cc.

float TrackListMerger::epsilon_
private

Definition at line 92 of file TrackListMerger.cc.

float TrackListMerger::foundHitBonus_
private

Definition at line 94 of file TrackListMerger.cc.

std::vector<int> TrackListMerger::hasSelector_
private

Definition at line 100 of file TrackListMerger.cc.

std::vector<double> TrackListMerger::indivShareFrac_
private

Definition at line 96 of file TrackListMerger.cc.

std::vector< std::vector< int> > TrackListMerger::listsToMerge_
private

Definition at line 98 of file TrackListMerger.cc.

float TrackListMerger::lostHitPenalty_
private

Definition at line 95 of file TrackListMerger.cc.

bool TrackListMerger::makeReKeyedSeeds_
private

Definition at line 60 of file TrackListMerger.cc.

double TrackListMerger::maxNormalizedChisq_
private

Definition at line 89 of file TrackListMerger.cc.

unsigned int TrackListMerger::minFound_
private

Definition at line 91 of file TrackListMerger.cc.

double TrackListMerger::minPT_
private

Definition at line 90 of file TrackListMerger.cc.

std::unique_ptr<TrajectorySeedCollection > TrackListMerger::outputSeeds
private

Definition at line 51 of file TrackListMerger.cc.

std::unique_ptr<std::vector<Trajectory> > TrackListMerger::outputTrajs
private

Definition at line 49 of file TrackListMerger.cc.

std::unique_ptr<reco::TrackExtraCollection> TrackListMerger::outputTrkExtras
private

Definition at line 47 of file TrackListMerger.cc.

std::unique_ptr<TrackingRecHitCollection> TrackListMerger::outputTrkHits
private

Definition at line 48 of file TrackListMerger.cc.

std::unique_ptr<reco::TrackCollection> TrackListMerger::outputTrks
private

Definition at line 46 of file TrackListMerger.cc.

std::unique_ptr<TrajTrackAssociationCollection > TrackListMerger::outputTTAss
private

Definition at line 50 of file TrackListMerger.cc.

std::string TrackListMerger::priorityName_
private

Definition at line 87 of file TrackListMerger.cc.

std::vector<bool> TrackListMerger::promoteQuality_
private

Definition at line 99 of file TrackListMerger.cc.

reco::TrackBase::TrackQuality TrackListMerger::qualityToSet_
private

Definition at line 104 of file TrackListMerger.cc.

edm::RefProd< std::vector<Trajectory> > TrackListMerger::refTrajs
private

Definition at line 56 of file TrackListMerger.cc.

edm::RefProd< TrajectorySeedCollection > TrackListMerger::refTrajSeeds
private

Definition at line 57 of file TrackListMerger.cc.

reco::TrackExtraRefProd TrackListMerger::refTrkExtras
private

Definition at line 54 of file TrackListMerger.cc.

TrackingRecHitRefProd TrackListMerger::refTrkHits
private

Definition at line 55 of file TrackListMerger.cc.

reco::TrackRefProd TrackListMerger::refTrks
private

Definition at line 53 of file TrackListMerger.cc.

float TrackListMerger::shareFrac_
private

Definition at line 93 of file TrackListMerger.cc.

std::vector<TkEDGetTokenss> TrackListMerger::trackProducers_
private

Definition at line 85 of file TrackListMerger.cc.

bool TrackListMerger::trkQualMod_
private

Definition at line 106 of file TrackListMerger.cc.

bool TrackListMerger::use_sharesInput_
private

Definition at line 105 of file TrackListMerger.cc.