CMS 3D CMS Logo

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

#include <TrackListMerger.h>

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

Classes

struct  TkEDGetTokenss
 

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 ()
 
ModuleDescription const & moduleDescription () const
 
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 ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Member Functions

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

Private Attributes

bool allowFirstHitShare_
 
bool copyExtras_
 
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::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
 
float shareFrac_
 
std::vector< TkEDGetTokensstrackProducers_
 
bool trkQualMod_
 
bool use_sharesInput_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- 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::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 34 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_, edTokens(), 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_, convertSQLiteXML::ok, promoteQuality_, reco::TrackBase::qualityByName(), qualityToSet_, shareFrac_, AlCaHLTBitMon_QueryRunRegistry::string, trackProducers_, trkQualMod_, reco::TrackBase::undefQuality, and use_sharesInput_.

110  {
111  copyExtras_ = conf.getUntrackedParameter<bool>("copyExtras", true);
112 
113  std::vector<edm::InputTag> trackProducerTags(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  hasSelector_= conf.getParameter<std::vector<int> >("hasSelector");
142  std::vector<edm::InputTag> selectors(conf.getParameter<std::vector<edm::InputTag> >("selectedTrackQuals"));
143  std::vector<edm::InputTag> mvaStores;
144  if(conf.exists("mvaValueTags")){
145  mvaStores = conf.getParameter<std::vector<edm::InputTag> >("mvaValueTags");
146  }else{
147  for (int i = 0; i < (int)selectors.size(); i++){
148  edm::InputTag ntag(selectors[i].label(),"MVAVals");
149  mvaStores.push_back(ntag);
150  }
151  }
152  unsigned int numTrkColl = trackProducerTags.size();
153  if (numTrkColl != hasSelector_.size() || numTrkColl != selectors.size()) {
154  throw cms::Exception("Inconsistent size") << "need same number of track collections and selectors";
155  }
156  if (numTrkColl != hasSelector_.size() || numTrkColl != mvaStores.size()) {
157  throw cms::Exception("Inconsistent size") << "need same number of track collections and MVA stores";
158  }
159  for (unsigned int i = indivShareFrac_.size(); i < numTrkColl; i++) {
160  // edm::LogWarning("TrackListMerger") << "No indivShareFrac for " << trackProducersTags <<". Using default value of 1";
161  indivShareFrac_.push_back(1.0);
162  }
163 
164  trkQualMod_=conf.getParameter<bool>("writeOnlyTrkQuals");
165  if ( trkQualMod_) {
166  bool ok=true;
167  for ( unsigned int i=1; i<numTrkColl; i++) {
168  if (!(trackProducerTags[i]==trackProducerTags[0])) ok=false;
169  }
170  if ( !ok) {
171  throw cms::Exception("Bad input") << "to use writeOnlyTrkQuals=True all input InputTags must be the same";
172  }
173  produces<edm::ValueMap<int> >();
174  }
175  else{
176  produces<reco::TrackCollection>();
177 
178  makeReKeyedSeeds_ = conf.getUntrackedParameter<bool>("makeReKeyedSeeds",false);
179  if (makeReKeyedSeeds_){
180  copyExtras_=true;
181  produces<TrajectorySeedCollection>();
182  }
183 
184  if (copyExtras_) {
185  produces<reco::TrackExtraCollection>();
186  produces<TrackingRecHitCollection>();
187  }
188  produces< std::vector<Trajectory> >();
189  produces< TrajTrackAssociationCollection >();
190  }
191  produces<edm::ValueMap<float> >("MVAVals");
192 
193  // Do all the consumes
194  trackProducers_.resize(numTrkColl);
195  for (unsigned int i = 0; i < numTrkColl; ++i) {
196  trackProducers_[i] = hasSelector_[i]>0 ? edTokens(trackProducerTags[i], selectors[i], mvaStores[i]) : edTokens(trackProducerTags[i], mvaStores[i]);
197  }
198  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
TkEDGetTokenss edTokens(const edm::InputTag &tag, const edm::InputTag &seltag, const edm::InputTag &mvatag)
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< double > indivShareFrac_
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
std::vector< TkEDGetTokenss > trackProducers_
std::vector< bool > promoteQuality_
reco::TrackBase::TrackQuality qualityToSet_
std::vector< int > hasSelector_
cms::TrackListMerger::~TrackListMerger ( )
virtual

Definition at line 202 of file TrackListMerger.cc.

202 { }

Member Function Documentation

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

Definition at line 74 of file TrackListMerger.h.

References edm::EDConsumerBase::consumes().

Referenced by TrackListMerger().

74  {
75  return TkEDGetTokenss(tag, consumes<reco::TrackCollection>(tag),
76  consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
78  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
TkEDGetTokenss cms::TrackListMerger::edTokens ( const edm::InputTag tag,
const edm::InputTag mvatag 
)
inlineprivate

Definition at line 79 of file TrackListMerger.h.

References edm::EDConsumerBase::consumes().

79  {
80  return TkEDGetTokenss(tag, consumes<reco::TrackCollection>(tag),
81  consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag),
83  }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
void cms::TrackListMerger::produce ( edm::Event e,
const edm::EventSetup c 
)
overridevirtual

Implements edm::EDProducer.

Definition at line 205 of file TrackListMerger.cc.

References funct::abs(), reco::TrackExtraBase::add(), reco::TrackBase::algo(), allowFirstHitShare_, asciidump::at, edm::OwnVector< T, P >::back(), begin, reco::TrackBase::chi2(), cms::clusterProductB(), edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > >::const_iterator, constexpr, copyExtras_, delta, TrajectorySeed::direction(), end, epsilon_, edm::HandleBase::failedToGet(), spr::find(), first, foundHitBonus_, TrackingRecHit::geographicalId(), edm::Event::getByLabel(), edm::Event::getByToken(), edm::Event::getProvenance(), edm::Event::getRefBeforePut(), hasSelector_, reco::TrackBase::highPurity, 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(), reco::TrackBase::loose, lostHitPenalty_, makeReKeyedSeeds_, match(), maxNormalizedChisq_, bookConverter::min, minFound_, minPT_, edm::Provenance::moduleLabel(), 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(), reco::TrackExtra::setResiduals(), shareFrac_, TrackingRecHit::some, TrajectorySeed::startingState(), DetId::subdetId(), reco::TrackBase::tight, trackProducers_, trkQualMod_, unlikely, use_sharesInput_, and PV3DBase< T, PVType, FrameType >::x().

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

Member Data Documentation

bool cms::TrackListMerger::allowFirstHitShare_
private

Definition at line 99 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::copyExtras_
private

Definition at line 58 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::epsilon_
private

Definition at line 89 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::foundHitBonus_
private

Definition at line 91 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 97 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 93 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 95 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

float cms::TrackListMerger::lostHitPenalty_
private

Definition at line 92 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::makeReKeyedSeeds_
private

Definition at line 59 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

double cms::TrackListMerger::maxNormalizedChisq_
private

Definition at line 86 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

unsigned int cms::TrackListMerger::minFound_
private

Definition at line 88 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

double cms::TrackListMerger::minPT_
private

Definition at line 87 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 50 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 48 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 46 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 47 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 45 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 49 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 96 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 100 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 55 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 56 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 53 of file TrackListMerger.h.

Referenced by produce().

TrackingRecHitRefProd cms::TrackListMerger::refTrkHits
private

Definition at line 54 of file TrackListMerger.h.

Referenced by produce().

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

Definition at line 52 of file TrackListMerger.h.

Referenced by produce().

float cms::TrackListMerger::shareFrac_
private

Definition at line 90 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

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

Definition at line 84 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::trkQualMod_
private

Definition at line 102 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().

bool cms::TrackListMerger::use_sharesInput_
private

Definition at line 101 of file TrackListMerger.h.

Referenced by produce(), and TrackListMerger().