CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
cms::TrackListMerger Class Reference

#include <TrackListMerger.h>

Inheritance diagram for cms::TrackListMerger:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

virtual void produce (edm::Event &e, const edm::EventSetup &c) override
 
 TrackListMerger (const edm::ParameterSet &conf)
 
virtual ~TrackListMerger ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
 EDConsumerBase ()
 
ProductHolderIndex indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndex > &) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Attributes

bool allowFirstHitShare_
 
bool copyExtras_
 
float epsilon_
 
float foundHitBonus_
 
std::vector< int > hasSelector_
 
std::vector< double > indivShareFrac_
 
std::vector< std::vector< int > > listsToMerge_
 
float lostHitPenalty_
 
bool makeReKeyedSeeds_
 
double maxNormalizedChisq_
 
unsigned int minFound_
 
double minPT_
 
std::vector< edm::InputTagmvaStores_
 
std::auto_ptr
< TrajectorySeedCollection
outputSeeds
 
std::auto_ptr< std::vector
< Trajectory > > 
outputTrajs
 
std::auto_ptr
< reco::TrackExtraCollection
outputTrkExtras
 
std::auto_ptr
< TrackingRecHitCollection
outputTrkHits
 
std::auto_ptr
< reco::TrackCollection
outputTrks
 
std::auto_ptr
< TrajTrackAssociationCollection
outputTTAss
 
std::vector< bool > promoteQuality_
 
reco::TrackBase::TrackQuality qualityToSet_
 
edm::RefProd< std::vector
< Trajectory > > 
refTrajs
 
edm::RefProd
< TrajectorySeedCollection
refTrajSeeds
 
reco::TrackExtraRefProd refTrkExtras
 
TrackingRecHitRefProd refTrkHits
 
reco::TrackRefProd refTrks
 
std::vector< edm::InputTagselectors_
 
float shareFrac_
 
std::vector< edm::InputTagtrackProducers_
 
bool trkQualMod_
 
bool use_sharesInput_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 36 of file TrackListMerger.h.

Constructor & Destructor Documentation

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

Definition at line 110 of file TrackListMerger.cc.

References allowFirstHitShare_, copyExtras_, epsilon_, edm::hlt::Exception, edm::ParameterSet::exists(), foundHitBonus_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), hasSelector_, i, indivShareFrac_, diffTwoXMLs::label, listsToMerge_, lostHitPenalty_, makeReKeyedSeeds_, maxNormalizedChisq_, minFound_, minPT_, mvaStores_, convertSQLiteXML::ok, promoteQuality_, reco::TrackBase::qualityByName(), qualityToSet_, selectors_, shareFrac_, AlCaHLTBitMon_QueryRunRegistry::string, trackProducers_, trkQualMod_, reco::TrackBase::undefQuality, and use_sharesInput_.

110  {
111  copyExtras_ = conf.getUntrackedParameter<bool>("copyExtras", true);
112 
113  trackProducers_ = conf.getParameter<std::vector<edm::InputTag> >("TrackProducers");
114  //which of these do I need to turn into vectors?
115  maxNormalizedChisq_ = conf.getParameter<double>("MaxNormalizedChisq");
116  minPT_ = conf.getParameter<double>("MinPT");
117  minFound_ = (unsigned int)conf.getParameter<int>("MinFound");
118  epsilon_ = conf.getParameter<double>("Epsilon");
119  shareFrac_ = conf.getParameter<double>("ShareFrac");
120  allowFirstHitShare_ = conf.getParameter<bool>("allowFirstHitShare");
121  foundHitBonus_ = conf.getParameter<double>("FoundHitBonus");
122  lostHitPenalty_ = conf.getParameter<double>("LostHitPenalty");
123  indivShareFrac_=conf.getParameter<std::vector<double> >("indivShareFrac");
124  std::string qualityStr = conf.getParameter<std::string>("newQuality");
125 
126  if (qualityStr != "") {
128  }
129  else
131 
132  use_sharesInput_ = true;
133  if ( epsilon_ > 0.0 )use_sharesInput_ = false;
134 
135  edm::VParameterSet setsToMerge=conf.getParameter<edm::VParameterSet>("setsToMerge");
136 
137  for ( unsigned int i=0; i<setsToMerge.size(); i++) {
138  listsToMerge_.push_back(setsToMerge[i].getParameter<std::vector< int> >("tLists"));
139  promoteQuality_.push_back(setsToMerge[i].getParameter<bool>("pQual"));
140  }
141 
142  hasSelector_=conf.getParameter<std::vector<int> >("hasSelector");
143  selectors_=conf.getParameter<std::vector<edm::InputTag> >("selectedTrackQuals");
144  if(conf.exists("mvaValueTags")){
145  mvaStores_ = conf.getParameter<std::vector<edm::InputTag> >("mvaValueTags");
146  }else{
147  std::vector<edm::InputTag> mvaValueTags;
148  for (int i = 0; i < (int)selectors_.size(); i++){
149  edm::InputTag ntag(selectors_[i].label(),"MVAVals");
150  mvaValueTags.push_back(ntag);
151  }
152 
153  mvaStores_ = mvaValueTags;
154  }
155  unsigned int numTrkColl = trackProducers_.size();
156  if (numTrkColl != hasSelector_.size() || numTrkColl != selectors_.size()) {
157  throw cms::Exception("Inconsistent size") << "need same number of track collections and selectors";
158  }
159  if (numTrkColl != hasSelector_.size() || numTrkColl != mvaStores_.size()) {
160  throw cms::Exception("Inconsistent size") << "need same number of track collections and MVA stores";
161  }
162  for (unsigned int i = indivShareFrac_.size(); i < numTrkColl; i++) {
163  // edm::LogWarning("TrackListMerger") << "No indivShareFrac for " << trackProducers_[i] <<". Using default value of 1";
164  indivShareFrac_.push_back(1.0);
165  }
166 
167  trkQualMod_=conf.getParameter<bool>("writeOnlyTrkQuals");
168  if ( trkQualMod_) {
169  bool ok=true;
170  for ( unsigned int i=1; i<numTrkColl; i++) {
171  if (!(trackProducers_[i]==trackProducers_[0])) ok=false;
172  }
173  if ( !ok) {
174  throw cms::Exception("Bad input") << "to use writeOnlyTrkQuals=True all input InputTags must be the same";
175  }
176  produces<edm::ValueMap<int> >();
177  }
178  else{
179  produces<reco::TrackCollection>();
180 
181  makeReKeyedSeeds_ = conf.getUntrackedParameter<bool>("makeReKeyedSeeds",false);
182  if (makeReKeyedSeeds_){
183  copyExtras_=true;
184  produces<TrajectorySeedCollection>();
185  }
186 
187  if (copyExtras_) {
188  produces<reco::TrackExtraCollection>();
189  produces<TrackingRecHitCollection>();
190  }
191  produces< std::vector<Trajectory> >();
192  produces< TrajTrackAssociationCollection >();
193  }
194  produces<edm::ValueMap<float> >("MVAVals");
195 
196  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
std::vector< edm::InputTag > mvaStores_
std::vector< ParameterSet > VParameterSet
Definition: ParameterSet.h:33
bool exists(std::string const &parameterName) const
checks if a parameter exists
std::vector< std::vector< int > > listsToMerge_
unsigned int minFound_
std::vector< edm::InputTag > selectors_
std::vector< edm::InputTag > trackProducers_
std::vector< double > indivShareFrac_
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
std::vector< bool > promoteQuality_
reco::TrackBase::TrackQuality qualityToSet_
std::vector< int > hasSelector_
cms::TrackListMerger::~TrackListMerger ( )
virtual

Definition at line 200 of file TrackListMerger.cc.

200 { }

Member Function Documentation

void cms::TrackListMerger::produce ( edm::Event e,
const edm::EventSetup c 
)
overridevirtual

Implements edm::EDProducer.

Definition at line 203 of file TrackListMerger.cc.

References abs, reco::TrackExtraBase::add(), reco::TrackBase::algo(), allowFirstHitShare_, asciidump::at, edm::OwnVector< T, P >::back(), begin, reco::TrackBase::chi2(), cms::clusterProductB(), constexpr, copyExtras_, delta, TrajectorySeed::direction(), end, epsilon_, edm::HandleBase::failedToGet(), spr::find(), first, foundHitBonus_, TrackingRecHit::geographicalId(), edm::Event::getByLabel(), edm::Event::getProvenance(), edm::Event::getRefBeforePut(), hasSelector_, i, edm::RefProd< T >::id(), edm::Ref< C, T, F >::id(), cuy::ii, indivShareFrac_, reco::Track::innerDetId(), reco::Track::innerMomentum(), reco::Track::innerOk(), reco::Track::innerPosition(), reco::Track::innerStateCovariance(), TrackingRecHit::isValid(), j, findQualityFiles::jj, edm::Ref< C, T, F >::key(), likely, listsToMerge_, TrackingRecHit::localPosition(), lostHitPenalty_, makeReKeyedSeeds_, match(), maxNormalizedChisq_, min, minFound_, minPT_, edm::Provenance::moduleLabel(), mvaStores_, n, TrajectorySeed::nHits(), reco::TrackBase::numberOfLostHits(), reco::TrackBase::numberOfValidHits(), reco::Track::outerDetId(), reco::Track::outerMomentum(), reco::Track::outerOk(), reco::Track::outerPosition(), reco::Track::outerStateCovariance(), outputSeeds, outputTrajs, outputTrkExtras, outputTrkHits, outputTrks, outputTTAss, edm::Provenance::processName(), edm::Provenance::productInstanceName(), promoteQuality_, edm::OwnVector< T, P >::push_back(), edm::Event::put(), qualityToSet_, TrackingRecHit::rawId(), reco::Track::recHit(), TrajectorySeed::recHits(), reco::Track::recHitsBegin(), reco::Track::recHitsEnd(), reco::Track::recHitsSize(), refTrajs, refTrajSeeds, refTrkExtras, refTrkHits, refTrks, ClusterRemovalRefSetter::reKey(), edm::OwnVector< T, P >::reserve(), reco::Track::residuals(), reco::Track::seedDirection(), reco::Track::seedRef(), selectors_, reco::TrackExtra::setResiduals(), shareFrac_, TrackingRecHit::some, TrajectorySeed::startingState(), DetId::subdetId(), trackProducers_, trkQualMod_, unlikely, use_sharesInput_, edm::helpers::KeyVal< K, V >::val, and PV3DBase< T, PVType, FrameType >::x().

204  {
205  // extract tracker geometry
206  //
207  //edm::ESHandle<TrackerGeometry> theG;
208  //es.get<TrackerDigiGeometryRecord>().get(theG);
209 
210  // using namespace reco;
211 
212  // get Inputs
213  // if 1 input list doesn't exist, make an empty list, issue a warning, and continue
214  // this allows TrackListMerger to be used as a cleaner only if handed just one list
215  // if both input lists don't exist, will issue 2 warnings and generate an empty output collection
216  //
217  static const reco::TrackCollection s_empty;
218 
219  std::vector<const reco::TrackCollection *> trackColls;
220  std::vector<edm::Handle<reco::TrackCollection> > trackHandles(trackProducers_.size());
221  for ( unsigned int i=0; i<trackProducers_.size(); i++) {
222  trackColls.push_back(0);
223  //edm::Handle<reco::TrackCollection> trackColl;
224  e.getByLabel(trackProducers_[i], trackHandles[i]);
225  if (trackHandles[i].isValid()) {
226  trackColls[i]= trackHandles[i].product();
227  } else {
228  edm::LogWarning("TrackListMerger") << "TrackCollection " << trackProducers_[i] <<" not found";
229  trackColls[i]=&s_empty;
230  }
231  }
232 
233  unsigned int collsSize =trackColls.size();
234  unsigned int rSize=0;
235  unsigned int trackCollSizes[collsSize];
236  unsigned int trackCollFirsts[collsSize];
237  for (unsigned int i=0; i!=collsSize; i++) {
238  trackCollSizes[i]=trackColls[i]->size();
239  trackCollFirsts[i]=rSize;
240  rSize+=trackCollSizes[i];
241  }
242 
243  statCount.begin(rSize);
244 
245  //
246  // quality cuts first
247  //
248  int i=-1;
249 
250  int selected[rSize];
251  int indexG[rSize];
252  bool trkUpdated[rSize];
253  int trackCollNum[rSize];
254  int trackQuals[rSize];
255  float trackMVAs[rSize];
256  for (unsigned int j=0; j<rSize;j++) {
257  indexG[j]=-1; selected[j]=1; trkUpdated[j]=false; trackCollNum[j]=0; trackQuals[j]=0;trackMVAs[j] = -99.0;
258  }
259 
260  int ngood=0;
261  for (unsigned int j=0; j!= collsSize; j++) {
262  const reco::TrackCollection *tC1=trackColls[j];
263 
264  edm::Handle<edm::ValueMap<int> > trackSelColl;
265  edm::Handle<edm::ValueMap<float> > trackMVAStore;
266  e.getByLabel(mvaStores_[j], trackMVAStore);
267  if ( hasSelector_[j]>0 ){
268  e.getByLabel(selectors_[j], trackSelColl);
269  }
270 
271  if ( 0<tC1->size() ){
272  unsigned int iC=0;
273  for (reco::TrackCollection::const_iterator track=tC1->begin(); track!=tC1->end(); track++){
274  i++;
275  trackCollNum[i]=j;
276  trackQuals[i]=track->qualityMask();
277 
278  reco::TrackRef trkRef=reco::TrackRef(trackHandles[j],iC);
279  if((*trackMVAStore).contains(trkRef.id()))trackMVAs[i] = (*trackMVAStore)[trkRef];
280  if ( hasSelector_[j]>0 ) {
281  int qual=(*trackSelColl)[trkRef];
282  if ( qual < 0 ) {
283  selected[i]=0;
284  iC++;
285  continue;
286  }else{
287  trackQuals[i]=qual;
288  }
289  }
290  iC++;
291  selected[i]=trackQuals[i]+10;//10 is magic number used throughout...
292  if ((short unsigned)track->ndof() < 1){
293  selected[i]=0;
294  continue;
295  }
296  if (track->normalizedChi2() > maxNormalizedChisq_){
297  selected[i]=0;
298  continue;
299  }
300  if (track->found() < minFound_){
301  selected[i]=0;
302  continue;
303  }
304  if (track->pt() < minPT_){
305  selected[i]=0;
306  continue;
307  }
308  // good!
309  indexG[i] = ngood++;
310  //if ( beVerb) std::cout << "inverb " << track->pt() << " " << selected[i] << std::endl;
311  }//end loop over tracks
312  }//end more than 0 track
313  } // loop over trackcolls
314 
315 
316  statCount.pre(ngood);
317 
318  //cache the id and rechits of valid hits
319  typedef std::pair<unsigned int, const TrackingRecHit*> IHit;
320  std::vector<IHit> rh1[ngood]; // an array of vectors!
321  //const TrackingRecHit* fh1[ngood]; // first hit...
322  unsigned char algo[ngood];
323  float score[ngood];
324 
325 
326  for ( unsigned int j=0; j<rSize; j++) {
327  if (selected[j]==0) continue;
328  int i = indexG[j];
329  assert(i>=0);
330  unsigned int collNum=trackCollNum[j];
331  unsigned int trackNum=j-trackCollFirsts[collNum];
332  const reco::Track *track=&((trackColls[collNum])->at(trackNum));
333 
334  algo[i]=track->algo();
335  int validHits=track->numberOfValidHits();
336  int lostHits=track->numberOfLostHits();
337  score[i] = foundHitBonus_*validHits - lostHitPenalty_*lostHits - track->chi2();
338 
339 
340  rh1[i].reserve(validHits) ;
341  auto compById = [](IHit const & h1, IHit const & h2) {return h1.first < h2.first;};
342  // fh1[i] = &(**track->recHitsBegin());
343  for (trackingRecHit_iterator it = track->recHitsBegin(); it != track->recHitsEnd(); ++it) {
344  const TrackingRecHit* hit = &(**it);
345  unsigned int id = hit->rawId() ;
346  if(hit->geographicalId().subdetId()>2) id &= (~3); // mask mono/stereo in strips...
347  if likely(hit->isValid()) { rh1[i].emplace_back(id,hit); std::push_heap(rh1[i].begin(),rh1[i].end(),compById); }
348  }
349  std::sort_heap(rh1[i].begin(),rh1[i].end(),compById);
350  }
351 
352  //DL here
353  if likely(ngood>1 && collsSize>1)
354  for ( unsigned int ltm=0; ltm<listsToMerge_.size(); ltm++) {
355  int saveSelected[rSize];
356  bool notActive[collsSize];
357  for (unsigned int cn=0;cn!=collsSize;++cn)
358  notActive[cn]= find(listsToMerge_[ltm].begin(),listsToMerge_[ltm].end(),cn)==listsToMerge_[ltm].end();
359 
360  for ( unsigned int i=0; i<rSize; i++) saveSelected[i]=selected[i];
361 
362  //DL protect against 0 tracks?
363  for ( unsigned int i=0; i<rSize-1; i++) {
364  if (selected[i]==0) continue;
365  unsigned int collNum=trackCollNum[i];
366 
367  //check that this track is in one of the lists for this iteration
368  if (notActive[collNum]) continue;
369 
370  int k1 = indexG[i];
371  unsigned int nh1=rh1[k1].size();
372  int qualityMaskT1 = trackQuals[i];
373 
374  int nhit1 = nh1; // validHits[k1];
375  float score1 = score[k1];
376 
377  // start at next collection
378  for ( unsigned int j=i+1; j<rSize; j++) {
379  if (selected[j]==0) continue;
380  unsigned int collNum2=trackCollNum[j];
381  if ( (collNum == collNum2) && indivShareFrac_[collNum] > 0.99) continue;
382  //check that this track is in one of the lists for this iteration
383  if (notActive[collNum2]) continue;
384 
385  int k2 = indexG[j];
386 
387  int newQualityMask = -9; //avoid resetting quality mask if not desired 10+ -9 =1
388  if (promoteQuality_[ltm]) {
389  int maskT1= saveSelected[i]>1? saveSelected[i]-10 : qualityMaskT1;
390  int maskT2= saveSelected[j]>1? saveSelected[j]-10 : trackQuals[j];
391  newQualityMask =(maskT1 | maskT2); // take OR of trackQuality
392  }
393  unsigned int nh2=rh1[k2].size();
394  int nhit2 = nh2;
395 
396 
397  auto share = use_sharesInput_ ?
398  [](const TrackingRecHit* it,const TrackingRecHit* jt, float)->bool { return it->sharesInput(jt,TrackingRecHit::some); } :
399  [](const TrackingRecHit* it,const TrackingRecHit* jt, float eps)->bool {
400  float delta = std::abs ( it->localPosition().x()-jt->localPosition().x() );
401  return (it->geographicalId()==jt->geographicalId())&&(delta<eps);
402  };
403 
404  statCount.start();
405 
406  //loop over rechits
407  int noverlap=0;
408  int firstoverlap=0;
409  // check first hit (should use REAL first hit?)
410  if unlikely(allowFirstHitShare_ && rh1[k1][0].first==rh1[k2][0].first ) {
411  const TrackingRecHit* it = rh1[k1][0].second;
412  const TrackingRecHit* jt = rh1[k2][0].second;
413  if (share(it,jt,epsilon_)) firstoverlap=1;
414  }
415 
416 
417  // exploit sorting
418  unsigned int jh=0;
419  unsigned int ih=0;
420  while (ih!=nh1 && jh!=nh2) {
421  // break if not enough to go...
422  // if ( nprecut-noverlap+firstoverlap > int(nh1-ih)) break;
423  // if ( nprecut-noverlap+firstoverlap > int(nh2-jh)) break;
424  auto const id1 = rh1[k1][ih].first;
425  auto const id2 = rh1[k2][jh].first;
426  if (id1<id2) ++ih;
427  else if (id2<id1) ++jh;
428  else {
429  // in case of split-hit do full conbinatorics
430  auto li=ih; while( (++li)!=nh1 && id1 == rh1[k1][li].first);
431  auto lj=jh; while( (++lj)!=nh2 && id2 == rh1[k2][lj].first);
432  for (auto ii=ih; ii!=li; ++ii)
433  for (auto jj=jh; jj!=lj; ++jj) {
434  const TrackingRecHit* it = rh1[k1][ii].second;
435  const TrackingRecHit* jt = rh1[k2][jj].second;
436  if (share(it,jt,epsilon_)) noverlap++;
437  }
438  jh=lj; ih=li;
439  } // equal ids
440 
441  } //loop over ih & jh
442 
443  bool dupfound = (collNum != collNum2) ? (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*shareFrac_ :
444  (noverlap-firstoverlap) > (std::min(nhit1,nhit2)-firstoverlap)*indivShareFrac_[collNum];
445 
446  if ( dupfound ) {
447  float score2 = score[k2];
448  constexpr float almostSame = 0.01f; // difference rather than ratio due to possible negative values for score
449  if ( score1 - score2 > almostSame ) {
450  selected[j]=0;
451  selected[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
452  trkUpdated[i]=true;
453  } else if ( score2 - score1 > almostSame ) {
454  selected[i]=0;
455  selected[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
456  trkUpdated[j]=true;
457  }else{
458  // If tracks from both iterations are virtually identical, choose the one from the first iteration.
459  if (algo[k1] <= algo[k2]) {
460  selected[j]=0;
461  selected[i]=10+newQualityMask; // add 10 to avoid the case where mask = 1
462  trkUpdated[i]=true;
463  }else{
464  selected[i]=0;
465  selected[j]=10+newQualityMask; // add 10 to avoid the case where mask = 1
466  trkUpdated[j]=true;
467  }
468  }//end fi < fj
469  statCount.overlap();
470  /*
471  if (at0[k1]&&at0[k2]) {
472  statCount.dp(dphi);
473  if (dz<1.f) statCount.de(deta);
474  }
475  */
476  }//end got a duplicate
477  else {
478  statCount.noOverlap();
479  }
480  //stop if the ith track is now unselected
481  if (selected[i]==0) break;
482  }//end track2 loop
483  }//end track loop
484  } //end loop over track list sets
485 
486 
487 
488  std::auto_ptr<edm::ValueMap<float> > vmMVA = std::auto_ptr<edm::ValueMap<float> >(new edm::ValueMap<float>);
489  edm::ValueMap<float>::Filler fillerMVA(*vmMVA);
490 
491 
492 
493  // special case - if just doing the trkquals
494  if (trkQualMod_) {
495  unsigned int tSize=trackColls[0]->size();
496  std::auto_ptr<edm::ValueMap<int> > vm = std::auto_ptr<edm::ValueMap<int> >(new edm::ValueMap<int>);
497  edm::ValueMap<int>::Filler filler(*vm);
498 
499  std::vector<int> finalQuals(tSize,-1); //default is unselected
500  for ( unsigned int i=0; i<rSize; i++) {
501  unsigned int tNum=i%tSize;
502 
503  if (selected[i]>1 ) {
504  finalQuals[tNum]=selected[i]-10;
505  if (trkUpdated[i])
506  finalQuals[tNum]=(finalQuals[tNum] | (1<<qualityToSet_));
507  }
508  if ( selected[i]==1 )
509  finalQuals[tNum]=trackQuals[i];
510  }
511 
512  filler.insert(trackHandles[0], finalQuals.begin(),finalQuals.end());
513  filler.fill();
514 
515  e.put(vm);
516 
517  std::vector<float> mvaVec(tSize,-99);
518 
519  for(unsigned int i = 0; i < rSize; i++){
520  unsigned int tNum = i % tSize;
521  mvaVec[tNum] = trackMVAs[tNum];
522  }
523 
524  fillerMVA.insert(trackHandles[0],mvaVec.begin(),mvaVec.end());
525  fillerMVA.fill();
526  e.put(vmMVA,"MVAVals");
527  return;
528  }
529 
530 
531  //
532  // output selected tracks - if any
533  //
534 
535  reco::TrackRef trackRefs[rSize];
536  edm::RefToBase<TrajectorySeed> seedsRefs[rSize];
537 
538  unsigned int nToWrite=0;
539  for ( unsigned int i=0; i<rSize; i++)
540  if (selected[i]!=0) nToWrite++;
541 
542  std::vector<float> mvaVec;
543 
544  outputTrks = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection);
545  outputTrks->reserve(nToWrite);
547 
548  if (copyExtras_) {
549  outputTrkExtras = std::auto_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection);
550  outputTrkExtras->reserve(nToWrite);
552  outputTrkHits = std::auto_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection);
553  outputTrkHits->reserve(nToWrite*25);
555  if (makeReKeyedSeeds_){
556  outputSeeds = std::auto_ptr<TrajectorySeedCollection>(new TrajectorySeedCollection);
557  outputSeeds->reserve(nToWrite);
559  }
560  }
561 
562 
563  outputTrajs = std::auto_ptr< std::vector<Trajectory> >(new std::vector<Trajectory>());
564  outputTrajs->reserve(rSize);
565  outputTTAss = std::auto_ptr< TrajTrackAssociationCollection >(new TrajTrackAssociationCollection());
566 
567 
568 
569  for ( unsigned int i=0; i<rSize; i++) {
570  if (selected[i]==0) {
571  trackRefs[i]=reco::TrackRef();
572  continue;
573  }
574 
575  unsigned int collNum=trackCollNum[i];
576  unsigned int trackNum=i-trackCollFirsts[collNum];
577  const reco::Track *track=&((trackColls[collNum])->at(trackNum));
578  outputTrks->push_back( reco::Track( *track ) );
579  mvaVec.push_back(trackMVAs[i]);
580  if (selected[i]>1 ) {
581  outputTrks->back().setQualityMask(selected[i]-10);
582  if (trkUpdated[i])
583  outputTrks->back().setQuality(qualityToSet_);
584  }
585  //might duplicate things, but doesnt hurt
586  if ( selected[i]==1 )
587  outputTrks->back().setQualityMask(trackQuals[i]);
588 
589  // if ( beVerb ) std::cout << "selected " << outputTrks->back().pt() << " " << outputTrks->back().qualityMask() << " " << selected[i] << std::endl;
590 
591  //fill the TrackCollection
592  if (copyExtras_) {
593  edm::RefToBase<TrajectorySeed> origSeedRef = track->seedRef();
594  //creating a seed with rekeyed clusters if required
595  if (makeReKeyedSeeds_){
596  bool doRekeyOnThisSeed=false;
597 
598  edm::InputTag clusterRemovalInfos("");
599  //grab on of the hits of the seed
600  if (origSeedRef->nHits()!=0){
601  TrajectorySeed::const_iterator firstHit=origSeedRef->recHits().first;
602  const TrackingRecHit *hit = &*firstHit;
603  if (firstHit->isValid()){
605  // the cluster collection either produced a removalInfo or mot
606  //get the clusterremoval info from the provenance: will rekey if this is found
608  edm::Provenance prov=e.getProvenance(pID);
609  clusterRemovalInfos=edm::InputTag(prov.moduleLabel(),
610  prov.productInstanceName(),
611  prov.processName());
612  doRekeyOnThisSeed=e.getByLabel(clusterRemovalInfos,CRIh);
613  }//valid hit
614  }//nhit!=0
615 
616  if (doRekeyOnThisSeed && !(clusterRemovalInfos==edm::InputTag(""))) {
617  ClusterRemovalRefSetter refSetter(e,clusterRemovalInfos);
618  TrajectorySeed::recHitContainer newRecHitContainer;
619  newRecHitContainer.reserve(origSeedRef->nHits());
620  TrajectorySeed::const_iterator iH=origSeedRef->recHits().first;
621  TrajectorySeed::const_iterator iH_end=origSeedRef->recHits().second;
622  for (;iH!=iH_end;++iH){
623  newRecHitContainer.push_back(*iH);
624  refSetter.reKey(&newRecHitContainer.back());
625  }
626  outputSeeds->push_back( TrajectorySeed( origSeedRef->startingState(),
627  newRecHitContainer,
628  origSeedRef->direction()));
629  }
630  //doRekeyOnThisSeed=true
631  else{
632  //just copy the one we had before
633  outputSeeds->push_back( TrajectorySeed(*origSeedRef));
634  }
636  origSeedRef=edm::RefToBase<TrajectorySeed>( pureRef);
637  }//creating a new seed and rekeying it rechit clusters.
638 
639  // Fill TrackExtra collection
640  outputTrkExtras->push_back( reco::TrackExtra(
641  track->outerPosition(), track->outerMomentum(), track->outerOk(),
642  track->innerPosition(), track->innerMomentum(), track->innerOk(),
643  track->outerStateCovariance(), track->outerDetId(),
644  track->innerStateCovariance(), track->innerDetId(),
645  track->seedDirection(), origSeedRef ) );
646  seedsRefs[i]=origSeedRef;
647  outputTrks->back().setExtra( reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
648  reco::TrackExtra & tx = outputTrkExtras->back();
649  tx.setResiduals(track->residuals());
650 
651  // fill TrackingRecHits
652  unsigned nh1=track->recHitsSize();
653  for ( unsigned ih=0; ih<nh1; ++ih ) {
654  //const TrackingRecHit*hit=&((*(track->recHit(ih))));
655  outputTrkHits->push_back( track->recHit(ih)->clone() );
656  tx.add( TrackingRecHitRef( refTrkHits, outputTrkHits->size() - 1) );
657  }
658  }
659  trackRefs[i] = reco::TrackRef(refTrks, outputTrks->size() - 1);
660 
661 
662  }//end faux loop over tracks
663 
664  //Fill the trajectories, etc. for 1st collection
665  refTrajs = e.getRefBeforePut< std::vector<Trajectory> >();
666 
667  for (unsigned int ti=0; ti<trackColls.size(); ti++) {
670  e.getByLabel(trackProducers_[ti], hTraj1);
671  e.getByLabel(trackProducers_[ti], hTTAss1);
672 
673  if (hTraj1.failedToGet() || hTTAss1.failedToGet()) continue;
674 
675  for (size_t i = 0, n = hTraj1->size(); i < n; ++i) {
676  edm::Ref< std::vector<Trajectory> > trajRef(hTraj1, i);
677  TrajTrackAssociationCollection::const_iterator match = hTTAss1->find(trajRef);
678  if (match != hTTAss1->end()) {
679  const edm::Ref<reco::TrackCollection> &trkRef = match->val;
680  short oldKey = trackCollFirsts[ti]+static_cast<short>(trkRef.key());
681  if (trackRefs[oldKey].isNonnull()) {
682  outputTrajs->push_back( *trajRef );
683  //if making extras and the seeds at the same time, change the seed ref on the trajectory
685  outputTrajs->back().setSeedRef( seedsRefs[oldKey] );
686  outputTTAss->insert ( edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),
687  trackRefs[oldKey] );
688  }
689  }
690  }
691  }
692 
693  statCount.end(outputTrks->size());
694 
695  edm::ProductID nPID = refTrks.id();
697  fillerMVA.insert(outHandle,mvaVec.begin(),mvaVec.end());
698  fillerMVA.fill();
699 
700  e.put(outputTrks);
701  e.put(vmMVA,"MVAVals");
702  if (copyExtras_) {
703  e.put(outputTrkExtras);
704  e.put(outputTrkHits);
705  if (makeReKeyedSeeds_)
706  e.put(outputSeeds);
707  }
708  e.put(outputTrajs);
709  e.put(outputTTAss);
710  return;
711 
712  }//end produce
PropagationDirection direction() const
dbl * delta
Definition: mlp_gen.cc:36
int i
Definition: DBlmapReader.cc:9
reference back()
Definition: OwnVector.h:320
std::auto_ptr< TrajectorySeedCollection > outputSeeds
std::auto_ptr< std::vector< Trajectory > > outputTrajs
std::vector< edm::InputTag > mvaStores_
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:69
std::auto_ptr< reco::TrackCollection > outputTrks
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:10
#define abs(x)
Definition: mlp_lapack.h:159
bool innerOk() const
return true if the innermost hit is valid
Definition: Track.h:40
unsigned short numberOfLostHits() const
number of cases where track crossed a layer without getting a hit.
Definition: TrackBase.h:234
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< std::vector< int > > listsToMerge_
int ii
Definition: cuy.py:588
std::string const & processName() const
Definition: Provenance.h:63
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:47
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:42
TrackAlgorithm algo() const
Definition: TrackBase.h:332
#define unlikely(x)
Definition: Likely.h:21
void push_back(D *&d)
Definition: OwnVector.h:273
std::vector< TrajectorySeed > TrajectorySeedCollection
double chi2() const
chi-squared of the fit
Definition: TrackBase.h:107
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
recHitContainer::const_iterator const_iterator
edm::Ref< TrackingRecHitCollection > TrackingRecHitRef
persistent reference to a TrackingRecHit
TrackingRecHitRefProd refTrkHits
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
Definition: Track.h:51
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
unsigned int minFound_
int j
Definition: DBlmapReader.cc:9
edm::RefProd< TrajectorySeedCollection > refTrajSeeds
edm::ProductID clusterProductB(const TrackingRecHit *hit)
reco::TrackRefProd refTrks
unsigned short numberOfValidHits() const
number of valid hits found
Definition: TrackBase.h:232
#define end
Definition: vmac.h:38
std::auto_ptr< reco::TrackExtraCollection > outputTrkExtras
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
Definition: Track.h:63
bool first
Definition: L1TdeRCT.cc:94
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:39
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
RefProd< PROD > getRefBeforePut()
Definition: Event.h:106
std::vector< edm::InputTag > selectors_
std::vector< edm::InputTag > trackProducers_
std::vector< double > indivShareFrac_
bool failedToGet() const
Definition: HandleBase.h:80
reco::TrackExtraRefProd refTrkExtras
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:9
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
edm::RefToBase< TrajectorySeed > seedRef() const
Definition: Track.h:112
PTrajectoryStateOnDet const & startingState() const
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:49
bool outerOk() const
return true if the outermost hit is valid
Definition: Track.h:38
std::vector< bool > promoteQuality_
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
Definition: TrackFwd.h:14
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
Definition: Track.h:53
key_type key() const
Accessor for product key.
Definition: Ref.h:266
range recHits() const
bool isValid() const
void add(const TrackingRecHitRef &r)
add a reference to a RecHit
std::string const & moduleLabel() const
Definition: Provenance.h:62
unsigned int nHits() const
#define likely(x)
Definition: Likely.h:20
#define begin
Definition: vmac.h:31
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
Definition: Track.h:45
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:67
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:140
const TrackResiduals & residuals() const
Definition: Track.h:117
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
Definition: Track.h:105
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
std::auto_ptr< TrackingRecHitCollection > outputTrkHits
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
DetId geographicalId() const
std::string const & productInstanceName() const
Definition: Provenance.h:64
Provenance getProvenance(BranchID const &theID) const
Definition: Event.cc:68
reco::TrackBase::TrackQuality qualityToSet_
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:61
tuple size
Write out results.
id_type rawId() const
#define constexpr
void reserve(size_t)
Definition: OwnVector.h:267
edm::RefProd< std::vector< Trajectory > > refTrajs
std::vector< int > hasSelector_
list at
Definition: asciidump.py:428
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.
Definition: Track.h:65
std::auto_ptr< TrajTrackAssociationCollection > outputTTAss
void setResiduals(const TrackResiduals &r)
set the residuals
Definition: TrackExtra.h:131

Member Data Documentation

bool cms::TrackListMerger::allowFirstHitShare_
private

Definition at line 79 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::copyExtras_
private

Definition at line 60 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::epsilon_
private

Definition at line 67 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::foundHitBonus_
private

Definition at line 69 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 75 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 71 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 73 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::lostHitPenalty_
private

Definition at line 70 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::makeReKeyedSeeds_
private

Definition at line 61 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

double cms::TrackListMerger::maxNormalizedChisq_
private

Definition at line 64 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

unsigned int cms::TrackListMerger::minFound_
private

Definition at line 66 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

double cms::TrackListMerger::minPT_
private

Definition at line 65 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

std::vector<edm::InputTag> cms::TrackListMerger::mvaStores_
private

Definition at line 77 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

std::auto_ptr< TrajectorySeedCollection > cms::TrackListMerger::outputSeeds
private

Definition at line 52 of file TrackListMerger.h.

Referenced by produce().

std::auto_ptr< std::vector<Trajectory> > cms::TrackListMerger::outputTrajs
private

Definition at line 50 of file TrackListMerger.h.

Referenced by produce().

std::auto_ptr<reco::TrackExtraCollection> cms::TrackListMerger::outputTrkExtras
private

Definition at line 48 of file TrackListMerger.h.

Referenced by produce().

std::auto_ptr< TrackingRecHitCollection> cms::TrackListMerger::outputTrkHits
private

Definition at line 49 of file TrackListMerger.h.

Referenced by produce().

std::auto_ptr<reco::TrackCollection> cms::TrackListMerger::outputTrks
private

Definition at line 47 of file TrackListMerger.h.

Referenced by produce().

std::auto_ptr< TrajTrackAssociationCollection > cms::TrackListMerger::outputTTAss
private

Definition at line 51 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 74 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 80 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 57 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 58 of file TrackListMerger.h.

Referenced by produce().

reco::TrackExtraRefProd cms::TrackListMerger::refTrkExtras
private

Definition at line 55 of file TrackListMerger.h.

Referenced by produce().

TrackingRecHitRefProd cms::TrackListMerger::refTrkHits
private

Definition at line 56 of file TrackListMerger.h.

Referenced by produce().

reco::TrackRefProd cms::TrackListMerger::refTrks
private

Definition at line 54 of file TrackListMerger.h.

Referenced by produce().

std::vector<edm::InputTag> cms::TrackListMerger::selectors_
private

Definition at line 76 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::shareFrac_
private

Definition at line 68 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

std::vector<edm::InputTag> cms::TrackListMerger::trackProducers_
private

Definition at line 63 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::trkQualMod_
private

Definition at line 82 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::use_sharesInput_
private

Definition at line 81 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().