CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackListMerger.cc
Go to the documentation of this file.
1 //
2 // Package: RecoTracker/FinalTrackSelectors
3 // Class: TrackListMerger
4 //
5 // Description: Hit Dumper
6 //
7 // Original Author: Steve Wagner, stevew@pizero.colorado.edu
8 // Created: Sat Jan 14 22:00:00 UTC 2006
9 //
10 //
11 
16 
28 
30  {
31  public:
32 
33  explicit TrackListMerger(const edm::ParameterSet& conf);
34 
35  virtual ~TrackListMerger();
36 
37  virtual void produce(edm::Event& e, const edm::EventSetup& c) override;
38 
39  private:
40  std::auto_ptr<reco::TrackCollection> outputTrks;
41  std::auto_ptr<reco::TrackExtraCollection> outputTrkExtras;
42  std::auto_ptr< TrackingRecHitCollection> outputTrkHits;
43  std::auto_ptr< std::vector<Trajectory> > outputTrajs;
44  std::auto_ptr< TrajTrackAssociationCollection > outputTTAss;
45  std::auto_ptr< TrajectorySeedCollection > outputSeeds;
46 
52 
55 
56  struct TkEDGetTokenss {
65  edm::EDGetTokenT<std::vector<Trajectory> > && traj_, edm::EDGetTokenT<TrajTrackAssociationCollection > && tass_,
67  tag(tag_), tk(tk_), traj(traj_), tass(tass_), tsel(tsel_), tmva(tmva_) {}
68  };
69  TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag) {
70  return TkEDGetTokenss(tag, consumes<reco::TrackCollection>(tag),
71  consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
72  consumes<edm::ValueMap<int> >(seltag), consumes<edm::ValueMap<float> >(mvatag));
73  }
75  return TkEDGetTokenss(tag, consumes<reco::TrackCollection>(tag),
76  consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
78  }
79  std::vector<TkEDGetTokenss> trackProducers_;
80 
82  double minPT_;
83  unsigned int minFound_;
84  float epsilon_;
85  float shareFrac_;
88  std::vector<double> indivShareFrac_;
89 
90  std::vector< std::vector< int> > listsToMerge_;
91  std::vector<bool> promoteQuality_;
92  std::vector<int> hasSelector_;
93  bool copyMVA_;
94 
99 
100 
101  };
102 
103 
104 
105 #include <memory>
106 #include <string>
107 #include <iostream>
108 #include <cmath>
109 #include <vector>
110 
118 
120 
125 
126 //#include "DataFormats/TrackReco/src/classes.h"
127 
129 
130 #ifdef STAT_TSB
131 #include <x86intrin.h>
132 #endif
133 
134 namespace {
135 #ifdef STAT_TSB
136 inline volatile unsigned long long rdtsc() {
137  return __rdtsc();
138 }
139 
140  struct StatCount {
141  float maxDP=0.;
142  float maxDE=0.;
143  unsigned long long st;
144  long long totBegin=0;
145  long long totPre=0;
146  long long totEnd=0;
147  unsigned long long timeNo; // no-overlap
148  unsigned long long timeOv; // overlap
149  void begin(int tt) {
150  totBegin+=tt;
151  }
152  void start() { st=rdtsc(); }
153  void noOverlap() { timeNo += (rdtsc()-st);}
154  void overlap() { timeOv += (rdtsc()-st);}
155  void pre(int tt) { totPre+=tt;}
156  void end(int tt) { totEnd+=tt;}
157  void de(float d) { if (d>maxDE) maxDE=d;}
158  void dp(float d) { if (d>maxDP) maxDP=d;}
159 
160 
161  void print() const {
162  std::cout << "TrackListMerger stat\nBegin/Pre/End/maxDPhi/maxDEta/Overlap/NoOverlap "
163  << totBegin <<'/'<< totPre <<'/'<< totEnd <<'/'<< maxDP <<'/'<< maxDE
164  <<'/'<< timeOv/1000 <<'/'<< timeNo/1000
165  << std::endl;
166  }
167  StatCount() {}
168  ~StatCount() { print();}
169  };
170  StatCount statCount;
171 
172 #else
173  struct StatCount {
174  void begin(int){}
175  void pre(int){}
176  void end(int){}
177  void start(){}
178  void noOverlap(){}
179  void overlap(){}
180  void de(float){}
181  void dp(float){}
182 
183 
184  };
185  [[cms::thread_safe]] StatCount statCount;
186 #endif
187 
188 
189 }
190 
191 
192 
193 namespace {
194  edm::ProductID clusterProductB( const TrackingRecHit *hit){
195  return reinterpret_cast<const BaseTrackerRecHit *>(hit)->firstClusterRef().id();
196  }
197 }
198 
199 
201  copyExtras_ = conf.getUntrackedParameter<bool>("copyExtras", true);
202 
203  std::vector<edm::InputTag> trackProducerTags(conf.getParameter<std::vector<edm::InputTag> >("TrackProducers"));
204  //which of these do I need to turn into vectors?
205  maxNormalizedChisq_ = conf.getParameter<double>("MaxNormalizedChisq");
206  minPT_ = conf.getParameter<double>("MinPT");
207  minFound_ = (unsigned int)conf.getParameter<int>("MinFound");
208  epsilon_ = conf.getParameter<double>("Epsilon");
209  shareFrac_ = conf.getParameter<double>("ShareFrac");
210  allowFirstHitShare_ = conf.getParameter<bool>("allowFirstHitShare");
211  foundHitBonus_ = conf.getParameter<double>("FoundHitBonus");
212  lostHitPenalty_ = conf.getParameter<double>("LostHitPenalty");
213  indivShareFrac_=conf.getParameter<std::vector<double> >("indivShareFrac");
214  std::string qualityStr = conf.getParameter<std::string>("newQuality");
215 
216  if (qualityStr != "") {
218  }
219  else
221 
222  use_sharesInput_ = true;
223  if ( epsilon_ > 0.0 )use_sharesInput_ = false;
224 
225  edm::VParameterSet setsToMerge=conf.getParameter<edm::VParameterSet>("setsToMerge");
226 
227  for ( unsigned int i=0; i<setsToMerge.size(); i++) {
228  listsToMerge_.push_back(setsToMerge[i].getParameter<std::vector< int> >("tLists"));
229  promoteQuality_.push_back(setsToMerge[i].getParameter<bool>("pQual"));
230  }
231  hasSelector_ = conf.getParameter<std::vector<int> > ("hasSelector");
232  copyMVA_ = conf.getParameter<bool>("copyMVA");
233 
234  std::vector<edm::InputTag> selectors(conf.getParameter<std::vector<edm::InputTag> >("selectedTrackQuals"));
235  std::vector<edm::InputTag> mvaStores;
236  if(conf.exists("mvaValueTags")){
237  mvaStores = conf.getParameter<std::vector<edm::InputTag> >("mvaValueTags");
238  }else{
239  for (int i = 0; i < (int)selectors.size(); i++){
240  edm::InputTag ntag(selectors[i].label(),"MVAVals");
241  mvaStores.push_back(ntag);
242  }
243  }
244  unsigned int numTrkColl = trackProducerTags.size();
245  if (numTrkColl != hasSelector_.size() || numTrkColl != selectors.size()) {
246  throw cms::Exception("Inconsistent size") << "need same number of track collections and selectors";
247  }
248  if (numTrkColl != hasSelector_.size() || numTrkColl != mvaStores.size()) {
249  throw cms::Exception("Inconsistent size") << "need same number of track collections and MVA stores";
250  }
251  for (unsigned int i = indivShareFrac_.size(); i < numTrkColl; i++) {
252  // edm::LogWarning("TrackListMerger") << "No indivShareFrac for " << trackProducersTags <<". Using default value of 1";
253  indivShareFrac_.push_back(1.0);
254  }
255 
256  trkQualMod_=conf.getParameter<bool>("writeOnlyTrkQuals");
257  if ( trkQualMod_) {
258  bool ok=true;
259  for ( unsigned int i=1; i<numTrkColl; i++) {
260  if (!(trackProducerTags[i]==trackProducerTags[0])) ok=false;
261  }
262  if ( !ok) {
263  throw cms::Exception("Bad input") << "to use writeOnlyTrkQuals=True all input InputTags must be the same";
264  }
265  produces<edm::ValueMap<int> >();
266  }
267  else{
268  produces<reco::TrackCollection>();
269 
270  makeReKeyedSeeds_ = conf.getUntrackedParameter<bool>("makeReKeyedSeeds",false);
271  if (makeReKeyedSeeds_){
272  copyExtras_=true;
273  produces<TrajectorySeedCollection>();
274  }
275 
276  if (copyExtras_) {
277  produces<reco::TrackExtraCollection>();
278  produces<TrackingRecHitCollection>();
279  }
280  produces< std::vector<Trajectory> >();
281  produces< TrajTrackAssociationCollection >();
282  }
283  produces<edm::ValueMap<float> >("MVAVals");
284 
285  // Do all the consumes
286  trackProducers_.resize(numTrkColl);
287  for (unsigned int i = 0; i < numTrkColl; ++i) {
288  trackProducers_[i] = hasSelector_[i]>0 ? edTokens(trackProducerTags[i], selectors[i], mvaStores[i]) : edTokens(trackProducerTags[i], mvaStores[i]);
289  }
290 }
291 
292 
293 // Virtual destructor needed.
295 
296  // Functions that gets called by framework every event
298  {
299  // extract tracker geometry
300  //
301  //edm::ESHandle<TrackerGeometry> theG;
302  //es.get<TrackerDigiGeometryRecord>().get(theG);
303 
304  // using namespace reco;
305 
306  // get Inputs
307  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
308  // this allows TrackListMerger to be used as a cleaner only if handed just one list
309  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
310  //
311  static const reco::TrackCollection s_empty;
312 
313  std::vector<const reco::TrackCollection *> trackColls;
314  std::vector<edm::Handle<reco::TrackCollection> > trackHandles(trackProducers_.size());
315  for ( unsigned int i=0; i<trackProducers_.size(); i++) {
316  trackColls.push_back(0);
317  //edm::Handle<reco::TrackCollection> trackColl;
318  e.getByToken(trackProducers_[i].tk, trackHandles[i]);
319  if (trackHandles[i].isValid()) {
320  trackColls[i]= trackHandles[i].product();
321  } else {
322  edm::LogWarning("TrackListMerger") << "TrackCollection " << trackProducers_[i].tag <<" not found";
323  trackColls[i]=&s_empty;
324  }
325  }
326 
327  unsigned int collsSize =trackColls.size();
328  unsigned int rSize=0;
329  unsigned int trackCollSizes[collsSize];
330  unsigned int trackCollFirsts[collsSize];
331  for (unsigned int i=0; i!=collsSize; i++) {
332  trackCollSizes[i]=trackColls[i]->size();
333  trackCollFirsts[i]=rSize;
334  rSize+=trackCollSizes[i];
335  }
336 
337  statCount.begin(rSize);
338 
339  //
340  // quality cuts first
341  //
342  int i=-1;
343 
344  int selected[rSize];
345  int indexG[rSize];
346  bool trkUpdated[rSize];
347  int trackCollNum[rSize];
348  int trackQuals[rSize];
349  float trackMVAs[rSize];
350  for (unsigned int j=0; j<rSize;j++) {
351  indexG[j]=-1; selected[j]=1; trkUpdated[j]=false; trackCollNum[j]=0; trackQuals[j]=0;trackMVAs[j] = -99.0;
352  }
353 
354  int ngood=0;
355  for (unsigned int j=0; j!= collsSize; j++) {
356  const reco::TrackCollection *tC1=trackColls[j];
357 
358  edm::Handle<edm::ValueMap<int> > trackSelColl;
359  edm::Handle<edm::ValueMap<float> > trackMVAStore;
360  if ( copyMVA_ )
361  e.getByToken(trackProducers_[j].tmva, trackMVAStore);
362  if ( hasSelector_[j]>0 ){
363  e.getByToken(trackProducers_[j].tsel, trackSelColl);
364  }
365 
366  if ( 0<tC1->size() ){
367  unsigned int iC=0;
368  for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
369  i++;
370  trackCollNum[i]=j;
371  trackQuals[i]=track->qualityMask();
372 
373  reco::TrackRef trkRef=reco::TrackRef(trackHandles[j],iC);
374  if ( copyMVA_ )
375  if( (*trackMVAStore).contains(trkRef.id()) ) trackMVAs[i] = (*trackMVAStore)[trkRef];
376  if ( hasSelector_[j]>0 ) {
377  int qual=(*trackSelColl)[trkRef];
378  if ( qual < 0 ) {
379  selected[i]=0;
380  iC++;
381  continue;
382  }else{
383  trackQuals[i]=qual;
384  }
385  }
386  iC++;
387  selected[i]=trackQuals[i]+10;//10 is magic number used throughout...
388  if ((short unsigned)track->ndof() < 1){
389  selected[i]=0;
390  continue;
391  }
392  if (track->normalizedChi2() > maxNormalizedChisq_){
393  selected[i]=0;
394  continue;
395  }
396  if (track->found() < minFound_){
397  selected[i]=0;
398  continue;
399  }
400  if (track->pt() < minPT_){
401  selected[i]=0;
402  continue;
403  }
404  // good!
405  indexG[i] = ngood++;
406  //if ( beVerb) std::cout << "inverb " << track->pt() << " " << selected[i] << std::endl;
407  }//end loop over tracks
408  }//end more than 0 track
409  } // loop over trackcolls
410 
411 
412  statCount.pre(ngood);
413 
414  //cache the id and rechits of valid hits
415  typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
416  #ifdef __clang__
417  std::vector<std::vector<IHit>> rh1(ngood); // an array of vectors!
418  #else
419  std::vector<IHit> rh1[ngood]; // an array of vectors!
420  #endif
421  //const TrackingRecHit* fh1[ngood]; // first hit...
422  uint8_t algo[ngood];
423  float score[ngood];
424 
425 
426  for ( unsigned int j=0; j<rSize; j++) {
427  if (selected[j]==0) continue;
428  int i = indexG[j];
429  assert(i>=0);
430  unsigned int collNum=trackCollNum[j];
431  unsigned int trackNum=j-trackCollFirsts[collNum];
432  const reco::Track *track=&((trackColls[collNum])->at(trackNum));
433 
434  algo[i]=track->algo();
435  int validHits=track->numberOfValidHits();
436  int validPixelHits=track->hitPattern().numberOfValidPixelHits();
437  int lostHits=track->numberOfLostHits();
438  score[i] = foundHitBonus_*validPixelHits+foundHitBonus_*validHits - lostHitPenalty_*lostHits - track->chi2();
439 
440 
441  rh1[i].reserve(validHits) ;
442  auto compById = [](IHit const & h1, IHit const & h2) {return h1.first < h2.first;};
443  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); ++it) {
444  const TrackingRecHit* hit = (*it);
445  unsigned int id = hit->rawId() ;
446  if(hit->geographicalId().subdetId()>2) id &= (~3); // mask mono/stereo in strips...
447  if likely(hit->isValid()) { rh1[i].emplace_back(id,hit); std::push_heap(rh1[i].begin(),rh1[i].end(),compById); }
448  }
449  std::sort_heap(rh1[i].begin(),rh1[i].end(),compById);
450  }
451 
452  //DL here
453  if likely(ngood>1 && collsSize>1)
454  for ( unsigned int ltm=0; ltm<listsToMerge_.size(); ltm++) {
455  int saveSelected[rSize];
456  bool notActive[collsSize];
457  for (unsigned int cn=0;cn!=collsSize;++cn)
458  notActive[cn]= find(listsToMerge_[ltm].begin(),listsToMerge_[ltm].end(),cn)==listsToMerge_[ltm].end();
459 
460  for ( unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
461 
462  //DL protect against 0 tracks?
463  for ( unsigned int i=0; i<rSize-1; i++) {
464  if (selected[i]==0) continue;
465  unsigned int collNum=trackCollNum[i];
466 
467  //check that this track is in one of the lists for this iteration
468  if (notActive[collNum]) continue;
469 
470  int k1 = indexG[i];
471  unsigned int nh1=rh1[k1].size();
472  int qualityMaskT1 = trackQuals[i];
473 
474  int nhit1 = nh1; // validHits[k1];
475  float score1 = score[k1];
476 
477  // start at next collection
478  for ( unsigned int j=i+1; j<rSize; j++) {
479  if (selected[j]==0) continue;
480  unsigned int collNum2=trackCollNum[j];
481  if ( (collNum == collNum2) && indivShareFrac_[collNum] > 0.99) continue;
482  //check that this track is in one of the lists for this iteration
483  if (notActive[collNum2]) continue;
484 
485  int k2 = indexG[j];
486 
487  int newQualityMask = -9; //avoid resetting quality mask if not desired 10+ -9 =1
488  if (promoteQuality_[ltm]) {
489  int maskT1= saveSelected[i]>1? saveSelected[i]-10 : qualityMaskT1;
490  int maskT2= saveSelected[j]>1? saveSelected[j]-10 : trackQuals[j];
491  newQualityMask =(maskT1 | maskT2); // take OR of trackQuality
492  }
493  unsigned int nh2=rh1[k2].size();
494  int nhit2 = nh2;
495 
496 
497  auto share = use_sharesInput_ ?
498  [](const TrackingRecHit* it,const TrackingRecHit* jt, float)->bool { return it->sharesInput(jt,TrackingRecHit::some); } :
499  [](const TrackingRecHit* it,const TrackingRecHit* jt, float eps)->bool {
500  float delta = std::abs ( it->localPosition().x()-jt->localPosition().x() );
501  return (it->geographicalId()==jt->geographicalId())&&(delta<eps);
502  };
503 
504  statCount.start();
505 
506  //loop over rechits
507  int noverlap=0;
508  int firstoverlap=0;
509  // check first hit (should use REAL first hit?)
510  if unlikely(allowFirstHitShare_ && rh1[k1][0].first==rh1[k2][0].first ) {
511  const TrackingRecHit* it = rh1[k1][0].second;
512  const TrackingRecHit* jt = rh1[k2][0].second;
513  if (share(it,jt,epsilon_)) firstoverlap=1;
514  }
515 
516 
517  // exploit sorting
518  unsigned int jh=0;
519  unsigned int ih=0;
520  while (ih!=nh1 && jh!=nh2) {
521  // break if not enough to go...
522  // if ( nprecut-noverlap+firstoverlap > int(nh1-ih)) break;
523  // if ( nprecut-noverlap+firstoverlap > int(nh2-jh)) break;
524  auto const id1 = rh1[k1][ih].first;
525  auto const id2 = rh1[k2][jh].first;
526  if (id1<id2) ++ih;
527  else if (id2<id1) ++jh;
528  else {
529  // in case of split-hit do full conbinatorics
530  auto li=ih; while( (++li)!=nh1 && id1 == rh1[k1][li].first);
531  auto lj=jh; while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
532  for (auto ii=ih; ii!=li; ++ii)
533  for (auto jj=jh; jj!=lj; ++jj) {
534  const TrackingRecHit* it = rh1[k1][ii].second;
535  const TrackingRecHit* jt = rh1[k2][jj].second;
536  if (share(it,jt,epsilon_)) noverlap++;
537  }
538  jh=lj; ih=li;
539  } // equal ids
540 
541  } //loop over ih & jh
542 
543  bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*shareFrac_ :
544  (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*indivShareFrac_[collNum];
545 
546  if ( dupfound ) {
547  float score2 = score[k2];
548  constexpr float almostSame = 0.01f; // difference rather than ratio due to possible negative values for score
549  if ( score1 - score2 > almostSame ) {
550  selected[j]=0;
551  selected[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
552  trkUpdated[i]=true;
553  } else if ( score2 - score1 > almostSame ) {
554  selected[i]=0;
555  selected[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
556  trkUpdated[j]=true;
557  }else{
558  // If tracks from both iterations are virtually identical, choose the one with the best quality or with lower algo
561  //same quality, pick earlier algo
562  if (algo[k1] <= algo[k2]) {
563  selected[j]=0;
564  selected[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
565  trkUpdated[i]=true;
566  } else {
567  selected[i]=0;
568  selected[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
569  trkUpdated[j]=true;
570  }
571  } else if ((trackQuals[j] & (1<<reco::TrackBase::loose|1<<reco::TrackBase::tight|1<<reco::TrackBase::highPurity) ) <
573  selected[j]=0;
574  selected[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
575  trkUpdated[i]=true;
576  }else{
577  selected[i]=0;
578  selected[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
579  trkUpdated[j]=true;
580  }
581  }//end fi < fj
582  statCount.overlap();
583  /*
584  if (at0[k1]&&at0[k2]) {
585  statCount.dp(dphi);
586  if (dz<1.f) statCount.de(deta);
587  }
588  */
589  }//end got a duplicate
590  else {
591  statCount.noOverlap();
592  }
593  //stop if the ith track is now unselected
594  if (selected[i]==0) break;
595  }//end track2 loop
596  }//end track loop
597  } //end loop over track list sets
598 
599 
600 
601  std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(new edm::ValueMap<float>);
602  edm::ValueMap<float>::Filler fillerMVA(*vmMVA);
603 
604 
605 
606  // special case - if just doing the trkquals
607  if (trkQualMod_) {
608  unsigned int tSize=trackColls[0]->size();
609  std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(new edm::ValueMap<int>);
610  edm::ValueMap<int>::Filler filler(*vm);
611 
612  std::vector<int> finalQuals(tSize,-1); //default is unselected
613  for ( unsigned int i=0; i<rSize; i++) {
614  unsigned int tNum=i%tSize;
615 
616  if (selected[i]>1 ) {
617  finalQuals[tNum]=selected[i]-10;
618  if (trkUpdated[i])
619  finalQuals[tNum]=(finalQuals[tNum] | (1<<qualityToSet_));
620  }
621  if ( selected[i]==1 )
622  finalQuals[tNum]=trackQuals[i];
623  }
624 
625  filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
626  filler.fill();
627 
628  e.put(vm);
629 
630  std::vector<float> mvaVec(tSize,-99);
631 
632  for(unsigned int i = 0; i < rSize; i++){
633  unsigned int tNum = i % tSize;
634  mvaVec[tNum] = trackMVAs[tNum];
635  }
636 
637  fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
638  fillerMVA.fill();
639  if ( copyMVA_)
640  e.put(vmMVA,"MVAVals");
641  return;
642  }
643 
644 
645  //
646  // output selected tracks - if any
647  //
648 
649  #ifdef __clang__
650  std::vector<reco::TrackRef> trackRefs(rSize);
651  std::vector<edm::RefToBase<TrajectorySeed>> seedsRefs(rSize);
652  #else
653  reco::TrackRef trackRefs[rSize];
654  edm::RefToBase<TrajectorySeed> seedsRefs[rSize];
655  #endif
656 
657  unsigned int nToWrite=0;
658  for ( unsigned int i=0; i<rSize; i++)
659  if (selected[i]!=0) nToWrite++;
660 
661  std::vector<float> mvaVec;
662 
663  outputTrks = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection);
664  outputTrks->reserve(nToWrite);
666 
667  if (copyExtras_) {
668  outputTrkExtras = std::auto_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection);
669  outputTrkExtras->reserve(nToWrite);
671  outputTrkHits = std::auto_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection);
672  outputTrkHits->reserve(nToWrite*25);
674  if (makeReKeyedSeeds_){
675  outputSeeds = std::auto_ptr<TrajectorySeedCollection>(new TrajectorySeedCollection);
676  outputSeeds->reserve(nToWrite);
678  }
679  }
680 
681 
682  outputTrajs = std::auto_ptr< std::vector<Trajectory> >(new std::vector<Trajectory>());
683  outputTrajs->reserve(rSize);
684  outputTTAss = std::auto_ptr< TrajTrackAssociationCollection >(new TrajTrackAssociationCollection());
685 
686 
687 
688  for ( unsigned int i=0; i<rSize; i++) {
689  if (selected[i]==0) {
690  trackRefs[i]=reco::TrackRef();
691  continue;
692  }
693 
694  unsigned int collNum=trackCollNum[i];
695  unsigned int trackNum=i-trackCollFirsts[collNum];
696  const reco::Track *track=&((trackColls[collNum])->at(trackNum));
697  outputTrks->push_back( reco::Track( *track ) );
698  mvaVec.push_back(trackMVAs[i]);
699  if (selected[i]>1 ) {
700  outputTrks->back().setQualityMask(selected[i]-10);
701  if (trkUpdated[i])
702  outputTrks->back().setQuality(qualityToSet_);
703  }
704  //might duplicate things, but doesnt hurt
705  if ( selected[i]==1 )
706  outputTrks->back().setQualityMask(trackQuals[i]);
707 
708  // if ( beVerb ) std::cout << "selected " << outputTrks->back().pt() << " " << outputTrks->back().qualityMask() << " " << selected[i] << std::endl;
709 
710  //fill the TrackCollection
711  if (copyExtras_) {
712  edm::RefToBase<TrajectorySeed> origSeedRef = track->seedRef();
713  //creating a seed with rekeyed clusters if required
714  if (makeReKeyedSeeds_){
715  bool doRekeyOnThisSeed=false;
716 
717  edm::InputTag clusterRemovalInfos("");
718  //grab on of the hits of the seed
719  if (origSeedRef->nHits()!=0){
720  TrajectorySeed::const_iterator firstHit=origSeedRef->recHits().first;
721  const TrackingRecHit *hit = &*firstHit;
722  if (firstHit->isValid()){
723  edm::ProductID pID=clusterProductB(hit);
724  // the cluster collection either produced a removalInfo or mot
725  //get the clusterremoval info from the provenance: will rekey if this is found
727  edm::Provenance prov=e.getProvenance(pID);
728  clusterRemovalInfos=edm::InputTag(prov.moduleLabel(),
729  prov.productInstanceName(),
730  prov.processName());
731  doRekeyOnThisSeed=e.getByLabel(clusterRemovalInfos,CRIh);
732  }//valid hit
733  }//nhit!=0
734 
735  if (doRekeyOnThisSeed && !(clusterRemovalInfos==edm::InputTag(""))) {
736  ClusterRemovalRefSetter refSetter(e,clusterRemovalInfos);
737  TrajectorySeed::recHitContainer newRecHitContainer;
738  newRecHitContainer.reserve(origSeedRef->nHits());
739  TrajectorySeed::const_iterator iH=origSeedRef->recHits().first;
740  TrajectorySeed::const_iterator iH_end=origSeedRef->recHits().second;
741  for (;iH!=iH_end;++iH){
742  newRecHitContainer.push_back(*iH);
743  refSetter.reKey(&newRecHitContainer.back());
744  }
745  outputSeeds->push_back( TrajectorySeed( origSeedRef->startingState(),
746  newRecHitContainer,
747  origSeedRef->direction()));
748  }
749  //doRekeyOnThisSeed=true
750  else{
751  //just copy the one we had before
752  outputSeeds->push_back( TrajectorySeed(*origSeedRef));
753  }
755  origSeedRef=edm::RefToBase<TrajectorySeed>( pureRef);
756  }//creating a new seed and rekeying it rechit clusters.
757 
758  // Fill TrackExtra collection
759  outputTrkExtras->push_back( reco::TrackExtra(
760  track->outerPosition(), track->outerMomentum(), track->outerOk(),
761  track->innerPosition(), track->innerMomentum(), track->innerOk(),
762  track->outerStateCovariance(), track->outerDetId(),
763  track->innerStateCovariance(), track->innerDetId(),
764  track->seedDirection(), origSeedRef ) );
765  seedsRefs[i]=origSeedRef;
766  outputTrks->back().setExtra( reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
767  reco::TrackExtra & tx = outputTrkExtras->back();
768  tx.setResiduals(track->residuals());
769 
770  // fill TrackingRecHits
771  unsigned nh1=track->recHitsSize();
772  tx.setHits(refTrkHits,outputTrkHits->size(),nh1);
773  for (auto hh = track->recHitsBegin(), eh=track->recHitsEnd(); hh!=eh; ++hh ) {
774  outputTrkHits->push_back( (*hh)->clone() );
775  }
776  }
777  trackRefs[i] = reco::TrackRef(refTrks, outputTrks->size() - 1);
778 
779 
780  }//end faux loop over tracks
781 
782  //Fill the trajectories, etc. for 1st collection
783  refTrajs = e.getRefBeforePut< std::vector<Trajectory> >();
784 
785  for (unsigned int ti=0; ti<trackColls.size(); ti++) {
788  e.getByToken(trackProducers_[ti].traj, hTraj1);
789  e.getByToken(trackProducers_[ti].tass, hTTAss1);
790 
791  if (hTraj1.failedToGet() || hTTAss1.failedToGet()) continue;
792 
793  for (size_t i = 0, n = hTraj1->size(); i < n; ++i) {
794  edm::Ref< std::vector<Trajectory> > trajRef(hTraj1, i);
795  TrajTrackAssociationCollection::const_iterator match = hTTAss1->find(trajRef);
796  if (match != hTTAss1->end()) {
797  const edm::Ref<reco::TrackCollection> &trkRef = match->val;
798  short oldKey = trackCollFirsts[ti]+static_cast<short>(trkRef.key());
799  if (trackRefs[oldKey].isNonnull()) {
800  outputTrajs->push_back( *trajRef );
801  //if making extras and the seeds at the same time, change the seed ref on the trajectory
803  outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
804  outputTTAss->insert ( edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),
805  trackRefs[oldKey] );
806  }
807  }
808  }
809  }
810 
811  statCount.end(outputTrks->size());
812 
813  edm::ProductID nPID = refTrks.id();
815  fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
816  fillerMVA.fill();
817 
818  e.put(outputTrks);
819  if ( copyMVA_ )
820  e.put(vmMVA,"MVAVals");
821  if (copyExtras_) {
822  e.put(outputTrkExtras);
823  e.put(outputTrkHits);
824  if (makeReKeyedSeeds_)
825  e.put(outputSeeds);
826  }
827  e.put(outputTrajs);
828  e.put(outputTTAss);
829  return;
830 
831  }//end produce
832 
833 
836 
838 
PropagationDirection direction() const
std::auto_ptr< reco::TrackCollection > outputTrks
dbl * delta
Definition: mlp_gen.cc:36
T getParameter(std::string const &) const
#define dso_hidden
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
TrackListMerger(const edm::ParameterSet &conf)
reference back()
Definition: OwnVector.h:327
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
std::vector< bool > promoteQuality_
reco::TrackRefProd refTrks
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
edm::EDGetTokenT< TrajTrackAssociationCollection > tass
edm::RefProd< std::vector< Trajectory > > refTrajs
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &mvatag)
virtual void produce(Event &, EventSetup const &)=0
TrackQuality
track quality
Definition: TrackBase.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:119
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10
void reKey(TrackingRecHit *hit) const
reco::TrackBase::TrackQuality qualityToSet_
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
bool exists(std::string const &parameterName) const
checks if a parameter exists
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:50
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:874
key_type key() const
Accessor for product key.
Definition: Ref.h:266
int ii
Definition: cuy.py:588
std::string const & processName() const
Definition: Provenance.h:62
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
#define constexpr
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
TrackingRecHitRefProd refTrkHits
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
std::vector< double > indivShareFrac_
bool overlap(const reco::Muon &muon1, const reco::Muon &muon2, double pullX=1.0, double pullY=1.0, bool checkAdjacentChambers=false)
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
TrackAlgorithm algo() const
Definition: TrackBase.h:423
#define unlikely(x)
#define likely(x)
void push_back(D *&d)
Definition: OwnVector.h:280
std::auto_ptr< TrackingRecHitCollection > outputTrkHits
edm::EDGetTokenT< edm::ValueMap< int > > tsel
std::vector< TrajectorySeed > TrajectorySeedCollection
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:597
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
recHitContainer::const_iterator const_iterator
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:75
edm::EDGetTokenT< reco::TrackCollection > tk
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:868
#define end
Definition: vmac.h:37
T min(T a, T b)
Definition: MathUtil.h:58
std::auto_ptr< TrajTrackAssociationCollection > outputTTAss
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:104
virtual ~TrackListMerger()
bool first
Definition: L1TdeRCT.cc:75
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
std::auto_ptr< std::vector< Trajectory > > outputTrajs
std::auto_ptr< TrajectorySeedCollection > outputSeeds
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
RefProd< PROD > getRefBeforePut()
Definition: Event.h:133
tuple conf
Definition: dbtoconf.py:185
std::vector< int > hasSelector_
bool failedToGet() const
Definition: HandleBase.h:80
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
double maxNormalizedChisq_
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
edm::RefToBase< TrajectorySeed > seedRef() const
Definition: Track.h:213
PTrajectoryStateOnDet const & startingState() const
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:108
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:70
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:45
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:384
edm::EDGetTokenT< edm::ValueMap< float > > tmva
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:19
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:80
range recHits() const
bool isValid() const
std::string const & moduleLabel() const
Definition: Provenance.h:61
std::auto_ptr< reco::TrackExtraCollection > outputTrkExtras
unsigned int nHits() const
#define begin
Definition: vmac.h:30
unsigned int minFound_
std::vector< TkEDGetTokenss > trackProducers_
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:140
const TrackResiduals & residuals() const
Definition: Track.h:220
int numberOfValidPixelHits() const
Definition: HitPattern.h:749
edm::EDGetTokenT< std::vector< Trajectory > > traj
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:204
tuple cout
Definition: gather_cfg.py:121
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
TkEDGetTokenss(const edm::InputTag &tag_, edm::EDGetTokenT< reco::TrackCollection > &&tk_, edm::EDGetTokenT< std::vector< Trajectory > > &&traj_, edm::EDGetTokenT< TrajTrackAssociationCollection > &&tass_, edm::EDGetTokenT< edm::ValueMap< int > > &&tsel_, edm::EDGetTokenT< edm::ValueMap< float > > &&tmva_)
DetId geographicalId() const
std::string const & productInstanceName() const
Definition: Provenance.h:63
std::vector< std::vector< int > > listsToMerge_
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:73
T x() const
Definition: PV3DBase.h:62
virtual LocalPoint localPosition() const =0
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
id_type rawId() const
void reserve(size_t)
Definition: OwnVector.h:274
reco::TrackExtraRefProd refTrkExtras
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
list at
Definition: asciidump.py:428
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:109
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:178