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