CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimpleTrackListMerger.cc
Go to the documentation of this file.
1 // Package: RecoTracker/FinalTrackSelectors
2 // Class: SimpleTrackListMerger
3 //
4 // Description: Hit Dumper
5 //
6 // Original Author: Steve Wagner, stevew@pizero.colorado.edu
7 // Created: Sat Jan 14 22:00:00 UTC 2006
8 //
9 //
10 
11 
16 
17 
26 
28 
29 
30 // this class is obsolete use TrackListMerger
32  public:
33 
35 
36  virtual ~SimpleTrackListMerger();
37 
38  virtual void produce(edm::Event& e, const edm::EventSetup& c) override;
39 
40  private:
42 
43  std::auto_ptr<reco::TrackCollection> outputTrks;
44  std::auto_ptr<reco::TrackExtraCollection> outputTrkExtras;
45  std::auto_ptr< TrackingRecHitCollection> outputTrkHits;
46  std::auto_ptr< std::vector<Trajectory> > outputTrajs;
47  std::auto_ptr< TrajTrackAssociationCollection > outputTTAss;
48  std::auto_ptr< TrajectorySeedCollection > outputSeeds;
49 
54  std::vector<reco::TrackRef> trackRefs;
56 
66  };
67 
68 
69 
70 
71 #include <memory>
72 #include <string>
73 #include <iostream>
74 #include <cmath>
75 #include <vector>
76 
77 
83 
85 
87 
92 
93 //#include "DataFormats/TrackReco/src/classes.h"
94 
96 
97 namespace {
98  // VI January 2012 to be migrated to omnicluster (or firstCluster)
99  edm::ProductID clusterProduct( const TrackingRecHit *hit){
100  edm::ProductID pID;
101  //cast it into the proper class and find productID
102  DetId detid = hit->geographicalId();
103  uint32_t subdet = detid.subdetId();
104  if ((subdet == PixelSubdetector::PixelBarrel) || (subdet == PixelSubdetector::PixelEndcap)) {
105  pID=reinterpret_cast<const SiPixelRecHit *>(hit)->cluster().id();
106  } else {
107  const std::type_info &type = typeid(*hit);
108  if (type == typeid(SiStripRecHit2D)) {
109  pID=reinterpret_cast<const SiStripRecHit2D *>(hit)->cluster().id();
110  } else if (type == typeid(SiStripRecHit1D)) {
111  pID=reinterpret_cast<const SiStripRecHit1D *>(hit)->cluster().id();
112  } else if (type == typeid(SiStripMatchedRecHit2D)) {
113  const SiStripMatchedRecHit2D *mhit = reinterpret_cast<const SiStripMatchedRecHit2D *>(hit);
114  pID=mhit->monoClusterRef().id();
115  } else if (type == typeid(ProjectedSiStripRecHit2D)) {
116  const ProjectedSiStripRecHit2D *phit = reinterpret_cast<const ProjectedSiStripRecHit2D *>(hit);
117  pID= phit->cluster().id();
118  } else throw cms::Exception("Unknown RecHit Type") << "RecHit of type " << type.name() << " not supported. (use c++filt to demangle the name)";
119  }
120 
121  return pID;
122  }
123 }
124 
125 
127  conf_(conf)
128  {
129 
130  edm::LogWarning("SimpleTrackListMerger") << "this class is obsolete, please use TrackListMerger";
131 
132  copyExtras_ = conf_.getUntrackedParameter<bool>("copyExtras", true);
133 
134  produces<reco::TrackCollection>();
135 
136  makeReKeyedSeeds_ = conf_.getUntrackedParameter<bool>("makeReKeyedSeeds",false);
137  if (makeReKeyedSeeds_){
138  copyExtras_=true;
139  produces<TrajectorySeedCollection>();
140  }
141 
142  if (copyExtras_) {
143  produces<reco::TrackExtraCollection>();
144  produces<TrackingRecHitCollection>();
145  }
146  produces< std::vector<Trajectory> >();
147  produces< TrajTrackAssociationCollection >();
148 
149  trackProducer1 = conf_.getParameter<std::string>("TrackProducer1");
150  trackProducer2 = conf_.getParameter<std::string>("TrackProducer2");
151 
152  trackProducer1Token = consumes<reco::TrackCollection>(trackProducer1);
153  trackProducer2Token = consumes<reco::TrackCollection>(trackProducer2);
154  trackProducer1TrajToken = consumes< std::vector<Trajectory> >(trackProducer1);
155  trackProducer2TrajToken = consumes< std::vector<Trajectory> >(trackProducer2);
156  trackProducer1AssToken = consumes< TrajTrackAssociationCollection >(trackProducer1);
157  trackProducer2AssToken = consumes< TrajTrackAssociationCollection >(trackProducer2);
158 
159  }
160 
161 
162  // Virtual destructor needed.
164 
165  // Functions that gets called by framework every event
167  {
168  // retrieve producer name of input TrackCollection(s)
169 
170  double maxNormalizedChisq = conf_.getParameter<double>("MaxNormalizedChisq");
171  double minPT = conf_.getParameter<double>("MinPT");
172  unsigned int minFound = (unsigned int)conf_.getParameter<int>("MinFound");
173  double epsilon = conf_.getParameter<double>("Epsilon");
174  bool use_sharesInput = true;
175  if ( epsilon > 0.0 )use_sharesInput = false;
176  double shareFrac = conf_.getParameter<double>("ShareFrac");
177  double foundHitBonus = conf_.getParameter<double>("FoundHitBonus");
178  double lostHitPenalty = conf_.getParameter<double>("LostHitPenalty");
179 
180  bool promoteQuality = conf_.getParameter<bool>("promoteTrackQuality");
181  bool allowFirstHitShare = conf_.getParameter<bool>("allowFirstHitShare");
182 //
183 
184  // New track quality should be read from the file
185  std::string qualityStr = conf_.getParameter<std::string>("newQuality");
186  reco::TrackBase::TrackQuality qualityToSet;
187  if (qualityStr != "") {
188  qualityToSet = reco::TrackBase::qualityByName(conf_.getParameter<std::string>("newQuality"));
189  }
190  else
191  qualityToSet = reco::TrackBase::undefQuality;
192 
193  // extract tracker geometry
194  //
196  es.get<TrackerDigiGeometryRecord>().get(theG);
197 
198 // using namespace reco;
199 
200  // get Inputs
201  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
202  // this allows SimpleTrackListMerger to be used as a cleaner only if handed just one list
203  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
204  //
205  const reco::TrackCollection *TC1 = 0;
206  static const reco::TrackCollection s_empty1, s_empty2;
207  edm::Handle<reco::TrackCollection> trackCollection1;
208  e.getByToken(trackProducer1Token, trackCollection1);
209  if (trackCollection1.isValid()) {
210  TC1 = trackCollection1.product();
211  //std::cout << "1st collection " << trackProducer1 << " has "<< TC1->size() << " tracks" << std::endl ;
212  } else {
213  TC1 = &s_empty1;
214  edm::LogWarning("SimpleTrackListMerger") << "1st TrackCollection " << trackProducer1 << " not found; will only clean 2nd TrackCollection " << trackProducer2 ;
215  }
216  const reco::TrackCollection tC1 = *TC1;
217 
218  const reco::TrackCollection *TC2 = 0;
219  edm::Handle<reco::TrackCollection> trackCollection2;
220  e.getByToken(trackProducer2Token, trackCollection2);
221  if (trackCollection2.isValid()) {
222  TC2 = trackCollection2.product();
223  //std::cout << "2nd collection " << trackProducer2 << " has "<< TC2->size() << " tracks" << std::endl ;
224  } else {
225  TC2 = &s_empty2;
226  edm::LogWarning("SimpleTrackListMerger") << "2nd TrackCollection " << trackProducer2 << " not found; will only clean 1st TrackCollection " << trackProducer1 ;
227  }
228  const reco::TrackCollection tC2 = *TC2;
229 
230  // Step B: create empty output collection
231  outputTrks = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection);
233 
234  if (copyExtras_) {
235  outputTrkExtras = std::auto_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection);
236  outputTrkExtras->reserve(TC1->size()+TC2->size());
238  outputTrkHits = std::auto_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection);
239  outputTrkHits->reserve((TC1->size()+TC2->size())*25);
241  if (makeReKeyedSeeds_){
242  outputSeeds = std::auto_ptr<TrajectorySeedCollection>(new TrajectorySeedCollection);
243  outputSeeds->reserve(TC1->size()+TC2->size());
245  }
246  }
247 
248  outputTrajs = std::auto_ptr< std::vector<Trajectory> >(new std::vector<Trajectory>());
249  outputTrajs->reserve(TC1->size()+TC2->size());
250  outputTTAss = std::auto_ptr< TrajTrackAssociationCollection >(new TrajTrackAssociationCollection());
251  //outputTTAss->reserve(TC1->size()+TC2->size());//how do I reserve space for an association map?
252 
253  //
254  // no input tracks
255  //
256 
257 // if ( tC1.empty() ){
258 // LogDebug("RoadSearch") << "Found " << output.size() << " clouds.";
259 // e.put(output);
260 // return;
261 // }
262 
263  //
264  // quality cuts first
265  //
266  int i;
267 
268  std::vector<int> selected1; for (unsigned int i=0; i<tC1.size(); ++i){selected1.push_back(1);}
269 
270  if ( 0<tC1.size() ){
271  i=-1;
272  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); track++){
273  i++;
274  if ((short unsigned)track->ndof() < 1){
275  selected1[i]=0;
276  //std::cout << "L1Track "<< i << " rejected in SimpleTrackListMerger; ndof() < 1" << std::endl ;
277  continue;
278  }
279  if (track->normalizedChi2() > maxNormalizedChisq){
280  selected1[i]=0;
281  //std::cout << "L1Track "<< i << " rejected in SimpleTrackListMerger; normalizedChi2() > maxNormalizedChisq " << track->normalizedChi2() << " " << maxNormalizedChisq << std::endl ;
282  continue;
283  }
284  if (track->found() < minFound){
285  selected1[i]=0;
286  //std::cout << "L1Track "<< i << " rejected in SimpleTrackListMerger; found() < minFound " << track->found() << " " << minFound << std::endl ;
287  continue;
288  }
289  if (track->pt() < minPT){
290  selected1[i]=0;
291  //std::cout << "L1Track "<< i << " rejected in SimpleTrackListMerger; pt() < minPT " << track->pt() << " " << minPT << std::endl ;
292  continue;
293  }
294  }//end loop over tracks
295  }//end more than 0 track
296 
297 
298  std::vector<int> selected2; for (unsigned int i=0; i<tC2.size(); ++i){selected2.push_back(1);}
299 
300  if ( 0<tC2.size() ){
301  i=-1;
302  for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); track++){
303  i++;
304  if ((short unsigned)track->ndof() < 1){
305  selected2[i]=0;
306  //std::cout << "L2Track "<< i << " rejected in SimpleTrackListMerger; ndof() < 1" << std::endl ;
307  continue;
308  }
309  if (track->normalizedChi2() > maxNormalizedChisq){
310  selected2[i]=0;
311  //std::cout << "L2Track "<< i << " rejected in SimpleTrackListMerger; normalizedChi2() > maxNormalizedChisq " << track->normalizedChi2() << " " << maxNormalizedChisq << std::endl ;
312  continue;
313  }
314  if (track->found() < minFound){
315  selected2[i]=0;
316  //std::cout << "L2Track "<< i << " rejected in SimpleTrackListMerger; found() < minFound " << track->found() << " " << minFound << std::endl ;
317  continue;
318  }
319  if (track->pt() < minPT){
320  selected2[i]=0;
321  //std::cout << "L2Track "<< i << " rejected in SimpleTrackListMerger; pt() < minPT " << track->pt() << " " << minPT << std::endl ;
322  continue;
323  }
324  }//end loop over tracks
325  }//end more than 0 track
326 
327  std::map<reco::TrackCollection::const_iterator, std::vector<const TrackingRecHit*> > rh1;
328  std::map<reco::TrackCollection::const_iterator, std::vector<const TrackingRecHit*> > rh2;
329  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); ++track){
330  trackingRecHit_iterator itB = track->recHitsBegin();
331  trackingRecHit_iterator itE = track->recHitsEnd();
332  for (trackingRecHit_iterator it = itB; it != itE; ++it) {
333  const TrackingRecHit* hit = &(**it);
334  rh1[track].push_back(hit);
335  }
336  }
337  for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end(); ++track){
338  trackingRecHit_iterator jtB = track->recHitsBegin();
339  trackingRecHit_iterator jtE = track->recHitsEnd();
340  for (trackingRecHit_iterator jt = jtB; jt != jtE; ++jt) {
341  const TrackingRecHit* hit = &(**jt);
342  rh2[track].push_back(hit);
343  }
344  }
345 
346  if ( (0<tC1.size())&&(0<tC2.size()) ){
347  i=-1;
348  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end(); ++track){
349  i++;
350  if (!selected1[i])continue;
351  std::vector<const TrackingRecHit*>& iHits = rh1[track];
352  unsigned nh1 = iHits.size();
353  int qualityMaskT1 = track->qualityMask();
354  int j=-1;
355  for (reco::TrackCollection::const_iterator track2=tC2.begin(); track2!=tC2.end(); ++track2){
356  j++;
357  if ((!selected2[j])||(!selected1[i]))continue;
358  std::vector<const TrackingRecHit*>& jHits = rh2[track2];
359  unsigned nh2 = jHits.size();
360  int noverlap=0;
361  int firstoverlap=0;
362  for ( unsigned ih=0; ih<nh1; ++ih ) {
363  const TrackingRecHit* it = iHits[ih];
364  if (it->isValid()){
365  int jj=-1;
366  for ( unsigned jh=0; jh<nh2; ++jh ) {
367  const TrackingRecHit* jt = jHits[jh];
368  jj++;
369  if (jt->isValid()){
370  if (!use_sharesInput){
371  float delta = fabs ( it->localPosition().x()-jt->localPosition().x() );
372  if ((it->geographicalId()==jt->geographicalId())&&(delta<epsilon)) {
373  noverlap++;
374  if ( allowFirstHitShare && ( ih == 0 ) && ( jh == 0 ) ) firstoverlap=1;
375  }
376  }else{
377  if ( it->sharesInput(jt,TrackingRecHit::some) ) {
378  noverlap++;
379  if ( allowFirstHitShare && ( ih == 0 ) && ( jh == 0 ) ) firstoverlap=1;
380  }
381  }
382  }
383  }
384  }
385  }
386  int newQualityMask = (qualityMaskT1 | track2->qualityMask()); // take OR of trackQuality
387  int nhit1 = track->numberOfValidHits();
388  int nhit2 = track2->numberOfValidHits();
389  if ( (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*shareFrac ) {
390  double score1 = foundHitBonus*nhit1 - lostHitPenalty*track->numberOfLostHits() - track->chi2();
391  double score2 = foundHitBonus*nhit2 - lostHitPenalty*track2->numberOfLostHits() - track2->chi2();
392  const double almostSame = 1.001;
393  if ( score1 > almostSame * score2 ){
394  selected2[j]=0;
395  selected1[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
396  }else if ( score2 > almostSame * score1 ){
397  selected1[i]=0;
398  selected2[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
399  }else{
400  if (track->algo() <= track2->algo()) {
401  selected2[j]=0;
402  selected1[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
403  }else{
404  selected1[i]=0;
405  selected2[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
406  }
407  }
408  }//end got a duplicate
409  }//end track2 loop
410  }//end track loop
411  }//end more than 1 track
412 
413  //
414  // output selected tracks - if any
415  //
416  trackRefs.resize(tC1.size()+tC2.size());
417  std::vector<edm::RefToBase<TrajectorySeed> > seedsRefs(tC1.size()+tC2.size());
418  size_t current = 0;
419 
420  if ( 0<tC1.size() ){
421  i=0;
422  for (reco::TrackCollection::const_iterator track=tC1.begin(); track!=tC1.end();
423  ++track, ++current, ++i){
424  if (!selected1[i]){
426  continue;
427  }
428  const reco::Track & theTrack = * track;
429  //fill the TrackCollection
430  outputTrks->push_back( reco::Track( theTrack ) );
431  if (selected1[i]>1 && promoteQuality){
432  outputTrks->back().setQualityMask(selected1[i]-10);
433  outputTrks->back().setQuality(qualityToSet);
434  }
435  if (copyExtras_) {
436  //--------NEW----------
437  edm::RefToBase<TrajectorySeed> origSeedRef = theTrack.seedRef();
438  //creating a seed with rekeyed clusters if required
439  if (makeReKeyedSeeds_){
440  bool doRekeyOnThisSeed=false;
441 
442  edm::InputTag clusterRemovalInfos("");
443  //grab on of the hits of the seed
444  if (origSeedRef->nHits()!=0){
445  TrajectorySeed::const_iterator firstHit=origSeedRef->recHits().first;
446  const TrackingRecHit *hit = &*firstHit;
447  if (firstHit->isValid()){
448  edm::ProductID pID=clusterProduct(hit);
449  // the cluster collection either produced a removalInfo or mot
450  //get the clusterremoval info from the provenance: will rekey if this is found
452  edm::Provenance prov=e.getProvenance(pID);
453  clusterRemovalInfos=edm::InputTag(prov.moduleLabel(),
454  prov.productInstanceName(),
455  prov.processName());
456  // In case this is switched on, will have to revist that, and declare mayConsumes...
457  doRekeyOnThisSeed=e.getByLabel(clusterRemovalInfos,CRIh);
458  }//valid hit
459  }//nhit!=0
460 
461  if (doRekeyOnThisSeed && !(clusterRemovalInfos==edm::InputTag("")))
462  {
463  ClusterRemovalRefSetter refSetter(e,clusterRemovalInfos);
464  TrajectorySeed::recHitContainer newRecHitContainer;
465  newRecHitContainer.reserve(origSeedRef->nHits());
466  TrajectorySeed::const_iterator iH=origSeedRef->recHits().first;
467  TrajectorySeed::const_iterator iH_end=origSeedRef->recHits().second;
468  for (;iH!=iH_end;++iH){
469  newRecHitContainer.push_back(*iH);
470  refSetter.reKey(&newRecHitContainer.back());
471  }
472  outputSeeds->push_back( TrajectorySeed( origSeedRef->startingState(),
473  newRecHitContainer,
474  origSeedRef->direction()));
475  }
476  //doRekeyOnThisSeed=true
477  else{
478  //just copy the one we had before
479  outputSeeds->push_back( TrajectorySeed(*origSeedRef));
480  }
482  origSeedRef=edm::RefToBase<TrajectorySeed>( pureRef);
483  }//creating a new seed and rekeying it rechit clusters.
484  //--------NEW----------
485  // Fill TrackExtra collection
486  outputTrkExtras->push_back( reco::TrackExtra(
487  theTrack.outerPosition(), theTrack.outerMomentum(), theTrack.outerOk(),
488  theTrack.innerPosition(), theTrack.innerMomentum(), theTrack.innerOk(),
489  theTrack.outerStateCovariance(), theTrack.outerDetId(),
490  theTrack.innerStateCovariance(), theTrack.innerDetId(),
491  theTrack.seedDirection(), origSeedRef ) );
492  seedsRefs[current]=origSeedRef;
493  outputTrks->back().setExtra( reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
494  reco::TrackExtra & tx = outputTrkExtras->back();
495  tx.setResiduals(theTrack.residuals());
496  // fill TrackingRecHits
497  std::vector<const TrackingRecHit*>& iHits = rh1[track];
498  unsigned nh1 = iHits.size();
499  auto const firstHitIndex = outputTrkHits->size();
500  for ( unsigned ih=0; ih<nh1; ++ih ) {
501  const TrackingRecHit* hit = iHits[ih];
502  //for( trackingRecHit_iterator hit = itB; hit != itE; ++hit ) {
503  outputTrkHits->push_back( hit->clone() );
504  }
505  tx.setHits( refTrkHits, firstHitIndex, nh1 );
506  }
507  trackRefs[current] = reco::TrackRef(refTrks, outputTrks->size() - 1);
508 
509 
510  }//end faux loop over tracks
511  }//end more than 0 track
512 
513  //Fill the trajectories, etc. for 1st collection
518  refTrajs = e.getRefBeforePut< std::vector<Trajectory> >();
519 
520  if (!hTraj1.failedToGet() && !hTTAss1.failedToGet()){
521  for (size_t i = 0, n = hTraj1->size(); i < n; ++i) {
522  edm::Ref< std::vector<Trajectory> > trajRef(hTraj1, i);
523  TrajTrackAssociationCollection::const_iterator match = hTTAss1->find(trajRef);
524  if (match != hTTAss1->end()) {
525  const edm::Ref<reco::TrackCollection> &trkRef = match->val;
526  short oldKey = static_cast<short>(trkRef.key());
527  if (trackRefs[oldKey].isNonnull()) {
528  outputTrajs->push_back( *trajRef );
529  //if making extras and the seeds at the same time, change the seed ref on the trajectory
531  outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
532  outputTTAss->insert ( edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),
533  trackRefs[oldKey] );
534  }
535  }
536  }
537  }
538 
539  short offset = current; //save offset into trackRefs
540 
541  if ( 0<tC2.size() ){
542  i=0;
543  for (reco::TrackCollection::const_iterator track=tC2.begin(); track!=tC2.end();
544  ++track, ++current, ++i){
545  if (!selected2[i]){
547  continue;
548  }
549  const reco::Track & theTrack = * track;
550  //fill the TrackCollection
551  outputTrks->push_back( reco::Track( theTrack ) );
552  if (selected2[i]>1 && promoteQuality){
553  outputTrks->back().setQualityMask(selected2[i]-10);
554  outputTrks->back().setQuality(qualityToSet);
555  }
556  if (copyExtras_) {
557  //--------NEW----------
558  edm::RefToBase<TrajectorySeed> origSeedRef = theTrack.seedRef();
559  //creating a seed with rekeyed clusters if required
560  if (makeReKeyedSeeds_){
561  bool doRekeyOnThisSeed=false;
562 
563  edm::InputTag clusterRemovalInfos("");
564  //grab on of the hits of the seed
565  if (origSeedRef->nHits()!=0){
566  TrajectorySeed::const_iterator firstHit=origSeedRef->recHits().first;
567  const TrackingRecHit *hit = &*firstHit;
568  if (firstHit->isValid()){
569  edm::ProductID pID=clusterProduct(hit);
570  // the cluster collection either produced a removalInfo or mot
571  //get the clusterremoval info from the provenance: will rekey if this is found
573  edm::Provenance prov=e.getProvenance(pID);
574  clusterRemovalInfos=edm::InputTag(prov.moduleLabel(),
575  prov.productInstanceName(),
576  prov.processName());
577  doRekeyOnThisSeed=e.getByLabel(clusterRemovalInfos,CRIh);
578  }//valid hit
579  }//nhit!=0
580 
581  if (doRekeyOnThisSeed && !(clusterRemovalInfos==edm::InputTag("")))
582  {
583  ClusterRemovalRefSetter refSetter(e,clusterRemovalInfos);
584  TrajectorySeed::recHitContainer newRecHitContainer;
585  newRecHitContainer.reserve(origSeedRef->nHits());
586  TrajectorySeed::const_iterator iH=origSeedRef->recHits().first;
587  TrajectorySeed::const_iterator iH_end=origSeedRef->recHits().second;
588  for (;iH!=iH_end;++iH){
589  newRecHitContainer.push_back(*iH);
590  refSetter.reKey(&newRecHitContainer.back());
591  }
592  outputSeeds->push_back( TrajectorySeed( origSeedRef->startingState(),
593  newRecHitContainer,
594  origSeedRef->direction()));
595  }//doRekeyOnThisSeed=true
596  else{
597  //just copy the one we had before
598  outputSeeds->push_back( TrajectorySeed(*origSeedRef));
599  }
601  origSeedRef=edm::RefToBase<TrajectorySeed>( pureRef);
602  }//creating a new seed and rekeying it rechit clusters.
603  //--------NEW----------
604  // Fill TrackExtra collection
605  outputTrkExtras->push_back( reco::TrackExtra(
606  theTrack.outerPosition(), theTrack.outerMomentum(), theTrack.outerOk(),
607  theTrack.innerPosition(), theTrack.innerMomentum(), theTrack.innerOk(),
608  theTrack.outerStateCovariance(), theTrack.outerDetId(),
609  theTrack.innerStateCovariance(), theTrack.innerDetId(),
610  theTrack.seedDirection(), origSeedRef ) );
611  seedsRefs[current]=origSeedRef;
612  outputTrks->back().setExtra( reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
613  reco::TrackExtra & tx = outputTrkExtras->back();
614  tx.setResiduals(theTrack.residuals());
615  // fill TrackingRecHits
616  std::vector<const TrackingRecHit*>& jHits = rh2[track];
617  unsigned nh2 = jHits.size();
618  auto const firstHitIndex2 = outputTrkHits->size();
619  for ( unsigned jh=0; jh<nh2; ++jh ) {
620  const TrackingRecHit* hit = jHits[jh];
621  outputTrkHits->push_back( hit->clone() );
622  }
623  tx.setHits( refTrkHits, firstHitIndex2, nh2 );
624  }
625  trackRefs[current] = reco::TrackRef(refTrks, outputTrks->size() - 1);
626 
627  }//end faux loop over tracks
628  }//end more than 0 track
629 
630  //Fill the trajectories, etc. for 2nd collection
635 
636  if (!hTraj2.failedToGet() && !hTTAss2.failedToGet()){
637  for (size_t i = 0, n = hTraj2->size(); i < n; ++i) {
638  edm::Ref< std::vector<Trajectory> > trajRef(hTraj2, i);
639  TrajTrackAssociationCollection::const_iterator match = hTTAss2->find(trajRef);
640  if (match != hTTAss2->end()) {
641  const edm::Ref<reco::TrackCollection> &trkRef = match->val;
642  short oldKey = static_cast<short>(trkRef.key()) + offset;
643  if (trackRefs[oldKey].isNonnull()) {
644  outputTrajs->push_back( Trajectory(*trajRef) );
645  //if making extras and the seeds at the same time, change the seed ref on the trajectory
647  outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
648  outputTTAss->insert ( edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),
649  trackRefs[oldKey] );
650  }
651  }
652  }}
653 
654  e.put(outputTrks);
655  if (copyExtras_) {
656  e.put(outputTrkExtras);
657  e.put(outputTrkHits);
658  if (makeReKeyedSeeds_)
659  e.put(outputSeeds);
660  }
661  e.put(outputTrajs);
662  e.put(outputTTAss);
663  return;
664 
665  }//end produce
666 
669 
670 
672 
PropagationDirection direction() const
dbl * delta
Definition: mlp_gen.cc:36
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::auto_ptr< TrackingRecHitCollection > outputTrkHits
reference back()
Definition: OwnVector.h:327
virtual void produce(edm::Event &e, const edm::EventSetup &c) override
std::auto_ptr< TrajTrackAssociationCollection > outputTTAss
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:449
TrackQuality
track quality
Definition: TrackBase.h:133
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void setHits(TrackingRecHitRefProd const &prod, unsigned firstH, unsigned int nH)
void reKey(TrackingRecHit *hit) const
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
virtual bool sharesInput(const TrackingRecHit *other, SharedInputType what) const
TrackingRecHitRefProd refTrkHits
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:50
key_type key() const
Accessor for product key.
Definition: Ref.h:266
std::string const & processName() const
Definition: Provenance.h:61
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:65
edm::EDGetTokenT< std::vector< Trajectory > > trackProducer1TrajToken
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
std::auto_ptr< reco::TrackCollection > outputTrks
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:55
edm::EDGetTokenT< std::vector< Trajectory > > trackProducer2TrajToken
void push_back(D *&d)
Definition: OwnVector.h:280
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
std::auto_ptr< TrajectorySeedCollection > outputSeeds
std::vector< TrajectorySeed > TrajectorySeedCollection
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< TrajTrackAssociationCollection > trackProducer1AssToken
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
int j
Definition: DBlmapReader.cc:9
std::auto_ptr< reco::TrackExtraCollection > outputTrkExtras
T min(T a, T b)
Definition: MathUtil.h:58
OmniClusterRef const & monoClusterRef() const
bool isValid() const
Definition: HandleBase.h: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
edm::RefProd< std::vector< Trajectory > > refTrajs
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:405
reco::TrackRefProd refTrks
RefProd< PROD > getRefBeforePut()
Definition: Event.h:133
tuple conf
Definition: dbtoconf.py:185
virtual TrackingRecHit * clone() const =0
bool failedToGet() const
Definition: HandleBase.h:79
Definition: DetId.h:18
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
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
T const * product() const
Definition: Handle.h:81
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:45
const T & get() const
Definition: EventSetup.h:55
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:60
std::auto_ptr< std::vector< Trajectory > > outputTrajs
edm::EDGetTokenT< reco::TrackCollection > trackProducer1Token
unsigned int nHits() const
edm::ProductID id() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:60
SimpleTrackListMerger(const edm::ParameterSet &conf)
edm::EDGetTokenT< reco::TrackCollection > trackProducer2Token
const TrackResiduals & residuals() const
Definition: Track.h:220
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:204
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
std::vector< reco::TrackRef > trackRefs
DetId geographicalId() const
edm::EDGetTokenT< TrajTrackAssociationCollection > trackProducer2AssToken
std::string const & productInstanceName() const
Definition: Provenance.h:62
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:73
T x() const
Definition: PV3DBase.h:62
virtual LocalPoint localPosition() const =0
reco::TrackExtraRefProd refTrkExtras
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
void reserve(size_t)
Definition: OwnVector.h:274
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
Our base class.
Definition: SiPixelRecHit.h:23
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:178