CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes | Friends
mkfit::TrackExtra Class Reference

#include <TrackExtra.h>

Public Member Functions

void addAlgo (int algo)
 
int cmsswTrackID () const
 
float dPhi () const
 
int duplicateID () const
 
void findMatchingSeedHits (const Track &reco_trk, const Track &seed_trk, const std::vector< HitVec > &layerHits)
 
float fracHitsMatched () const
 
float helixChi2 () const
 
bool isDuplicate () const
 
bool isSeedHit (const int lyr, const int idx) const
 
int mcTrackID () const
 
int modifyRefTrackID (const int foundHits, const int minHits, const TrackVec &reftracks, const int trueID, const int duplicate, int refTrackID)
 
int nHitsMatched () const
 
int nMatchedSeedHits () const
 
const std::vector< int > seedAlgos () const
 
int seedID () const
 
void setCMSSWTrackIDInfoByHits (const Track &trk, const LayIdxIDVecMapMap &cmsswHitIDMap, const TrackVec &cmsswtracks, const TrackExtraVec &cmsswextras, const RedTrackVec &redcmsswtracks, const int cmsswlabel)
 
void setCMSSWTrackIDInfoByTrkParams (const Track &trk, const std::vector< HitVec > &layerHits, const TrackVec &cmsswtracks, const RedTrackVec &redcmsswtracks, const bool isBkFit)
 
void setDuplicateInfo (int duplicateID, bool isDuplicate)
 
void setmcTrackID (int mcTrackID)
 
void setMCTrackIDInfo (const Track &trk, const std::vector< HitVec > &layerHits, const MCHitInfoVec &globalHitInfo, const TrackVec &simtracks, const bool isSeed, const bool isPure)
 
void setseedID (int seedID)
 
 TrackExtra ()
 
 TrackExtra (int seedID)
 

Private Attributes

int cmsswTrackID_
 
float dPhi_
 
int duplicateID_
 
float fracHitsMatched_
 
float helixChi2_
 
bool isDuplicate_
 
HoTVec matchedSeedHits_
 
int mcTrackID_
 
int nHitsMatched_
 
std::vector< int > seedAlgos_
 
int seedID_
 

Friends

class Track
 

Detailed Description

Definition at line 51 of file TrackExtra.h.

Constructor & Destructor Documentation

◆ TrackExtra() [1/2]

mkfit::TrackExtra::TrackExtra ( )
inline

◆ TrackExtra() [2/2]

mkfit::TrackExtra::TrackExtra ( int  seedID)
inline

Definition at line 54 of file TrackExtra.h.

54 : seedID_(seedID) {}
int seedID() const
Definition: TrackExtra.h:82

Member Function Documentation

◆ addAlgo()

void mkfit::TrackExtra::addAlgo ( int  algo)
inline

Definition at line 99 of file TrackExtra.h.

References seedAlgos_.

99 { seedAlgos_.push_back(algo); }
std::vector< int > seedAlgos_
Definition: TrackExtra.h:115

◆ cmsswTrackID()

int mkfit::TrackExtra::cmsswTrackID ( ) const
inline

Definition at line 89 of file TrackExtra.h.

References cmsswTrackID_.

Referenced by setCMSSWTrackIDInfoByHits(), and setCMSSWTrackIDInfoByTrkParams().

89 { return cmsswTrackID_; }

◆ dPhi()

float mkfit::TrackExtra::dPhi ( ) const
inline

Definition at line 91 of file TrackExtra.h.

References dPhi_.

91 { return dPhi_; }

◆ duplicateID()

int mkfit::TrackExtra::duplicateID ( ) const
inline

Definition at line 84 of file TrackExtra.h.

References duplicateID_.

Referenced by setDuplicateInfo().

84 { return duplicateID_; }

◆ findMatchingSeedHits()

void mkfit::TrackExtra::findMatchingSeedHits ( const Track reco_trk,
const Track seed_trk,
const std::vector< HitVec > &  layerHits 
)

Definition at line 13 of file TrackExtra.cc.

References mkfit::Track::getHitIdx(), mkfit::Track::getHitLyr(), matchedSeedHits_, mkfit::Track::nTotalHits(), and findQualityFiles::size.

Referenced by mkfit::StdSeq::Quality::quality_process().

15  {
16  // outer loop over reco hits
17  for (int reco_ihit = 0; reco_ihit < reco_trk.nTotalHits(); ++reco_ihit) {
18  const int reco_lyr = reco_trk.getHitLyr(reco_ihit);
19  const int reco_idx = reco_trk.getHitIdx(reco_ihit);
20 
21  // ensure layer exists
22  if (reco_lyr < 0)
23  continue;
24 
25  // make sure it is a real hit
26  if ((reco_idx < 0) || (static_cast<size_t>(reco_idx) >= layerHits[reco_lyr].size()))
27  continue;
28 
29  // inner loop over seed hits
30  for (int seed_ihit = 0; seed_ihit < seed_trk.nTotalHits(); ++seed_ihit) {
31  const int seed_lyr = seed_trk.getHitLyr(seed_ihit);
32  const int seed_idx = seed_trk.getHitIdx(seed_ihit);
33 
34  // ensure layer exists
35  if (seed_lyr < 0)
36  continue;
37 
38  // check that lyrs are the same
39  if (reco_lyr != seed_lyr)
40  continue;
41 
42  // make sure it is a real hit
43  if ((seed_idx < 0) || (static_cast<size_t>(seed_idx) >= layerHits[seed_lyr].size()))
44  continue;
45 
46  // finally, emplace if idx is the same
47  if (reco_idx == seed_idx)
48  matchedSeedHits_.emplace_back(seed_idx, seed_lyr);
49  }
50  }
51  }
size
Write out results.
HoTVec matchedSeedHits_
Definition: TrackExtra.h:114

◆ fracHitsMatched()

float mkfit::TrackExtra::fracHitsMatched ( ) const
inline

Definition at line 81 of file TrackExtra.h.

References fracHitsMatched_.

81 { return fracHitsMatched_; }
float fracHitsMatched_
Definition: TrackExtra.h:107

◆ helixChi2()

float mkfit::TrackExtra::helixChi2 ( ) const
inline

Definition at line 90 of file TrackExtra.h.

References helixChi2_.

90 { return helixChi2_; }

◆ isDuplicate()

bool mkfit::TrackExtra::isDuplicate ( ) const
inline

Definition at line 83 of file TrackExtra.h.

References isDuplicate_.

Referenced by setDuplicateInfo().

83 { return isDuplicate_; }

◆ isSeedHit()

bool mkfit::TrackExtra::isSeedHit ( const int  lyr,
const int  idx 
) const

Definition at line 53 of file TrackExtra.cc.

References heavyIonCSV_trainingSettings::idx, and matchedSeedHits_.

Referenced by setCMSSWTrackIDInfoByHits(), setCMSSWTrackIDInfoByTrkParams(), and setMCTrackIDInfo().

53  {
54  return (std::find_if(matchedSeedHits_.begin(), matchedSeedHits_.end(), [=](const auto& matchedSeedHit) {
55  return ((matchedSeedHit.layer == lyr) && (matchedSeedHit.index == idx));
56  }) != matchedSeedHits_.end());
57  }
HoTVec matchedSeedHits_
Definition: TrackExtra.h:114

◆ mcTrackID()

int mkfit::TrackExtra::mcTrackID ( ) const
inline

Definition at line 79 of file TrackExtra.h.

References mcTrackID_.

Referenced by mkfit::StdSeq::Quality::quality_process(), setmcTrackID(), and setMCTrackIDInfo().

79 { return mcTrackID_; }

◆ modifyRefTrackID()

int mkfit::TrackExtra::modifyRefTrackID ( const int  foundHits,
const int  minHits,
const TrackVec reftracks,
const int  trueID,
const int  duplicate,
int  refTrackID 
)

Definition at line 59 of file TrackExtra.cc.

References reco_skim_cfg_mod::minHits.

Referenced by setCMSSWTrackIDInfoByHits(), setCMSSWTrackIDInfoByTrkParams(), and setMCTrackIDInfo().

64  {
65  // Modify refTrackID based on nMinHits and findability
66  if (duplicate) {
67  refTrackID = -10;
68  } else {
69  if (refTrackID >= 0) {
70  if (reftracks[refTrackID].isFindable()) {
71  if (foundHits < minHits)
72  refTrackID = -2;
73  //else refTrackID = refTrackID;
74  } else // ref track is not findable
75  {
76  if (foundHits < minHits)
77  refTrackID = -3;
78  else
79  refTrackID = -4;
80  }
81  } else if (refTrackID == -1) {
82  if (trueID >= 0) {
83  if (reftracks[trueID].isFindable()) {
84  if (foundHits < minHits)
85  refTrackID = -5;
86  //else refTrackID = refTrackID;
87  } else // sim track is not findable
88  {
89  if (foundHits < minHits)
90  refTrackID = -6;
91  else
92  refTrackID = -7;
93  }
94  } else {
95  if (foundHits < minHits)
96  refTrackID = -8;
97  else
98  refTrackID = -9;
99  }
100  }
101  }
102  return refTrackID;
103  }

◆ nHitsMatched()

int mkfit::TrackExtra::nHitsMatched ( ) const
inline

Definition at line 80 of file TrackExtra.h.

References nHitsMatched_.

Referenced by setCMSSWTrackIDInfoByHits(), and setCMSSWTrackIDInfoByTrkParams().

80 { return nHitsMatched_; }

◆ nMatchedSeedHits()

int mkfit::TrackExtra::nMatchedSeedHits ( ) const
inline

Definition at line 94 of file TrackExtra.h.

References matchedSeedHits_.

Referenced by setCMSSWTrackIDInfoByHits(), setCMSSWTrackIDInfoByTrkParams(), and setMCTrackIDInfo().

94 { return matchedSeedHits_.size(); }
HoTVec matchedSeedHits_
Definition: TrackExtra.h:114

◆ seedAlgos()

const std::vector<int> mkfit::TrackExtra::seedAlgos ( ) const
inline

Definition at line 100 of file TrackExtra.h.

References seedAlgos_.

100 { return seedAlgos_; }
std::vector< int > seedAlgos_
Definition: TrackExtra.h:115

◆ seedID()

int mkfit::TrackExtra::seedID ( ) const
inline

Definition at line 82 of file TrackExtra.h.

References seedID_.

Referenced by setseedID().

82 { return seedID_; }

◆ setCMSSWTrackIDInfoByHits()

void mkfit::TrackExtra::setCMSSWTrackIDInfoByHits ( const Track trk,
const LayIdxIDVecMapMap cmsswHitIDMap,
const TrackVec cmsswtracks,
const TrackExtraVec cmsswextras,
const RedTrackVec redcmsswtracks,
const int  cmsswlabel 
)

Definition at line 366 of file TrackExtra.cc.

References funct::abs(), cmsswTrackID(), cmsswTrackID_, mkfit::computeHelixChi2(), dPhi_, mkfit::TrackBase::errors(), f, dqmMemoryStats::float, fracHitsMatched_, mkfit::TrackBase::getDuplicateValue(), mkfit::Track::getHitIdx(), mkfit::Track::getHitLyr(), helixChi2_, heavyIonCSV_trainingSettings::idx, isSeedHit(), label, HLT_2022v14_cff::label1, HLT_2022v14_cff::label2, modifyRefTrackID(), mkfit::TrackBase::momPhi(), mkfit::Track::nFoundHits(), nHitsMatched(), nHitsMatched_, nMatchedSeedHits(), mkfit::Config::nMinFoundHits, mkfit::Track::nTotalHits(), mkfit::TrackBase::parameters(), jetUpdater_cfi::sort, mkfit::squashPhiGeneral(), mkfit::TrackBase::x(), and mkfit::TrackBase::y().

371  {
372  // reminder: cmsswlabel >= 0 indicates we are using pure seeds and matching by cmsswlabel
373 
374  // map of cmssw labels, and hits matched to that label
375  std::unordered_map<int, int> labelMatchMap;
376 
377  // loop over mkfit track hits
378  for (int ihit = 0; ihit < trk.nTotalHits(); ihit++) {
379  const int lyr = trk.getHitLyr(ihit);
380  const int idx = trk.getHitIdx(ihit);
381 
382  if (lyr < 0 || idx < 0)
383  continue; // standard check
384  if (isSeedHit(lyr, idx))
385  continue; // skip seed layers
386  if (!cmsswHitIDMap.count(lyr))
387  continue; // make sure at least one cmssw track has this hit lyr!
388  if (!cmsswHitIDMap.at(lyr).count(idx))
389  continue; // make sure at least one cmssw track has this hit id!
390  {
391  for (const auto label : cmsswHitIDMap.at(lyr).at(idx)) {
392  labelMatchMap[label]++;
393  }
394  }
395  }
396 
397  // make list of cmssw tracks that pass criteria --> could have multiple overlapping tracks!
398  std::vector<int> labelMatchVec;
399  for (const auto labelMatchPair : labelMatchMap) {
400  const auto cmsswlabel = labelMatchPair.first;
401  const auto nMatchedHits = labelMatchPair.second;
402 
403  // 50% matching criterion
404  if ((2 * nMatchedHits) >= (cmsswtracks[cmsswlabel].nUniqueLayers() - cmsswextras[cmsswlabel].nMatchedSeedHits()))
405  labelMatchVec.push_back(cmsswlabel);
406  }
407 
408  // initialize tmpID for later use
409  int cmsswTrackID = -1;
410 
411  // protect against no matches!
412  if (!labelMatchVec.empty()) {
413  // sort by best matched: most hits matched , then ratio of matches (i.e. which cmssw track is shorter)
414  std::sort(labelMatchVec.begin(), labelMatchVec.end(), [&](const int label1, const int label2) {
415  if (labelMatchMap[label1] == labelMatchMap[label2]) {
416  const auto& track1 = cmsswtracks[label1];
417  const auto& track2 = cmsswtracks[label2];
418 
419  const auto& extra1 = cmsswextras[label1];
420  const auto& extra2 = cmsswextras[label2];
421 
422  return ((track1.nUniqueLayers() - extra1.nMatchedSeedHits()) <
423  (track2.nUniqueLayers() - extra2.nMatchedSeedHits()));
424  }
425  return labelMatchMap[label1] > labelMatchMap[label2];
426  });
427 
428  // pick the longest track!
429  cmsswTrackID = labelMatchVec.front();
430 
431  // set cmsswTrackID_ (if cmsswlabel >= 0, we are matching by label and label exists!)
432  if (cmsswlabel >= 0) {
433  if (cmsswTrackID == cmsswlabel) {
435  } else {
436  cmsswTrackID = cmsswlabel; // use this for later
437  cmsswTrackID_ = -1;
438  }
439  } else // not matching by pure id
440  {
441  cmsswTrackID_ = cmsswTrackID; // the longest track is matched
442  }
443 
444  // set nHits matched to cmssw track
445  nHitsMatched_ = labelMatchMap[cmsswTrackID];
446  } else // did not match a single cmssw track with 50% hits shared
447  {
448  // by default sets to -1
450 
451  // tmp variable
452  int nHitsMatched = 0;
453 
454  // use truth info
455  if (cmsswlabel >= 0) {
456  cmsswTrackID = cmsswlabel;
457  nHitsMatched = labelMatchMap[cmsswTrackID];
458  } else {
459  // just get the cmssw track with the most matches!
460  for (const auto labelMatchPair : labelMatchMap) {
461  if (labelMatchPair.second > nHitsMatched) {
462  cmsswTrackID = labelMatchPair.first;
463  nHitsMatched = labelMatchPair.second;
464  }
465  }
466  }
467 
469  }
470 
471  // set chi2, dphi based on tmp cmsswTrackID
472  if (cmsswTrackID >= 0) {
473  // get tmps for chi2, dphi
474  const SVector6& trkParams = trk.parameters();
475  const SMatrixSym66& trkErrs = trk.errors();
476 
477  // temps needed for chi2
478  SVector2 trkParamsR;
479  trkParamsR[0] = trkParams[3];
480  trkParamsR[1] = trkParams[5];
481 
482  SMatrixSym22 trkErrsR;
483  trkErrsR[0][0] = trkErrs[3][3];
484  trkErrsR[1][1] = trkErrs[5][5];
485  trkErrsR[0][1] = trkErrs[3][5];
486  trkErrsR[1][0] = trkErrs[5][3];
487 
488  // set chi2 and dphi
489  helixChi2_ = std::abs(computeHelixChi2(redcmsswtracks[cmsswTrackID].parameters(), trkParamsR, trkErrsR, false));
490  dPhi_ = squashPhiGeneral(cmsswtracks[cmsswTrackID].swimPhiToR(trk.x(), trk.y()) - trk.momPhi());
491  } else {
492  helixChi2_ = -99.f;
493  dPhi_ = -99.f;
494  }
495 
496  // get nSeedHits
497  const int nSeedHits = nMatchedSeedHits();
498 
499  // Modify cmsswTrackID based on length and findability
500  cmsswTrackID_ = modifyRefTrackID(trk.nFoundHits() - nSeedHits,
501  Config::nMinFoundHits - nSeedHits,
502  cmsswtracks,
503  cmsswlabel,
504  trk.getDuplicateValue(),
505  cmsswTrackID_);
506 
507  // other important info
508  fracHitsMatched_ = (cmsswTrackID >= 0 ? (float(nHitsMatched_) / float(cmsswtracks[cmsswTrackID].nUniqueLayers() -
509  cmsswextras[cmsswTrackID].nMatchedSeedHits()))
510  : 0.f);
511  }
int modifyRefTrackID(const int foundHits, const int minHits, const TrackVec &reftracks, const int trueID, const int duplicate, int refTrackID)
Definition: TrackExtra.cc:59
ROOT::Math::SMatrix< float, 6, 6, ROOT::Math::MatRepSym< float, 6 > > SMatrixSym66
Definition: MatrixSTypes.h:8
float computeHelixChi2(const Vector &simV, const Vector &recoV, const Matrix &recoM, const bool diagOnly=false)
Definition: Track.h:664
ROOT::Math::SVector< float, 2 > SVector2
Definition: MatrixSTypes.h:18
float fracHitsMatched_
Definition: TrackExtra.h:107
float squashPhiGeneral(float phi)
Definition: Hit.h:22
char const * label
int nHitsMatched() const
Definition: TrackExtra.h:80
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
ROOT::Math::SMatrix< float, 2, 2, ROOT::Math::MatRepSym< float, 2 > > SMatrixSym22
Definition: MatrixSTypes.h:17
bool isSeedHit(const int lyr, const int idx) const
Definition: TrackExtra.cc:53
int cmsswTrackID() const
Definition: TrackExtra.h:89
ROOT::Math::SVector< float, 6 > SVector6
Definition: MatrixSTypes.h:10
int nMatchedSeedHits() const
Definition: TrackExtra.h:94

◆ setCMSSWTrackIDInfoByTrkParams()

void mkfit::TrackExtra::setCMSSWTrackIDInfoByTrkParams ( const Track trk,
const std::vector< HitVec > &  layerHits,
const TrackVec cmsswtracks,
const RedTrackVec redcmsswtracks,
const bool  isBkFit 
)

Definition at line 252 of file TrackExtra.cc.

References funct::abs(), newFWLiteAna::bin, HLT_2022v14_cff::cands, hltPixelTracks_cff::chi2, cmsswTrackID(), cmsswTrackID_, mkfit::computeHelixChi2(), dPhi_, mkfit::TrackBase::errors(), dqmMemoryStats::float, fracHitsMatched_, mkfit::TrackBase::getDuplicateValue(), mkfit::Track::getHitIdx(), mkfit::Track::getHitLyr(), mkfit::getMatchBin(), helixChi2_, heavyIonCSV_trainingSettings::idx, isSeedHit(), label, muonTagProbeFilters_cff::matched, mkfit::Config::minCMSSWMatchChi2, mkfit::Config::minCMSSWMatchdPhi, modifyRefTrackID(), mkfit::TrackBase::momPhi(), mkfit::Track::nFoundHits(), nHitsMatched(), nHitsMatched_, nMatchedSeedHits(), mkfit::Config::nMinFoundHits, mkfit::Track::nTotalHits(), mkfit::TrackBase::parameters(), mkfit::TrackBase::pT(), jetUpdater_cfi::sort, mkfit::sortIDsByChi2(), mkfit::squashPhiGeneral(), mkfit::TrackBase::x(), and mkfit::TrackBase::y().

256  {
257  // get temporary reco track params
258  const SVector6& trkParams = trk.parameters();
259  const SMatrixSym66& trkErrs = trk.errors();
260 
261  // get bin used for cuts in dphi, chi2 based on pt
262  const int bin = getMatchBin(trk.pT());
263 
264  // temps needed for chi2
265  SVector2 trkParamsR;
266  trkParamsR[0] = trkParams[3];
267  trkParamsR[1] = trkParams[5];
268 
269  SMatrixSym22 trkErrsR;
270  trkErrsR[0][0] = trkErrs[3][3];
271  trkErrsR[1][1] = trkErrs[5][5];
272  trkErrsR[0][1] = trkErrs[3][5];
273  trkErrsR[1][0] = trkErrs[5][3];
274 
275  // cands is vector of possible cmssw tracks we could match
277 
278  // first check for cmmsw tracks we match by chi2
279  for (const auto& redcmsswtrack : redcmsswtracks) {
280  const float chi2 = std::abs(computeHelixChi2(redcmsswtrack.parameters(), trkParamsR, trkErrsR, false));
282  cands.push_back(std::make_pair(redcmsswtrack.label(), chi2));
283  }
284 
285  // get min chi2
286  float minchi2 = -1e6;
287  if (!cands.empty()) {
288  std::sort(cands.begin(), cands.end(), sortIDsByChi2); // in case we just want to stop at the first dPhi match
289  minchi2 = cands.front().second;
290  }
291 
292  // set up defaults
293  int cmsswTrackID = -1;
294  int nHitsMatched = 0;
295  float bestdPhi = Config::minCMSSWMatchdPhi[bin];
296  float bestchi2 = minchi2;
297 
298  // loop over possible cmssw tracks
299  for (auto&& cand : cands) {
300  // get cmssw track
301  const auto label = cand.first;
302  const auto& cmsswtrack = cmsswtracks[label];
303 
304  // get diff in track mom. phi: swim phi of cmssw track to reco track R if forward built tracks
305  const float diffPhi =
306  squashPhiGeneral((isBkFit ? cmsswtrack.momPhi() : cmsswtrack.swimPhiToR(trk.x(), trk.y())) - trk.momPhi());
307 
308  // check for best matched track by phi
309  if (std::abs(diffPhi) < std::abs(bestdPhi)) {
310  const HitLayerMap& hitLayerMap = redcmsswtracks[label].hitLayerMap();
311  int matched = 0;
312 
313  // loop over hits on reco track
314  for (int ihit = 0; ihit < trk.nTotalHits(); ihit++) {
315  const int lyr = trk.getHitLyr(ihit);
316  const int idx = trk.getHitIdx(ihit);
317 
318  // skip seed layers
319  if (isSeedHit(lyr, idx))
320  continue;
321 
322  // skip if bad index or cmssw track does not have that layer
323  if (idx < 0 || !hitLayerMap.count(lyr))
324  continue;
325 
326  // loop over hits in layer for the cmssw track
327  for (auto cidx : hitLayerMap.at(lyr)) {
328  // since we can only pick up on hit on a layer, break loop after finding hit
329  if (cidx == idx) {
330  matched++;
331  break;
332  }
333  }
334  } // end loop over hits on reco track
335 
336  // now save the matched info
337  bestdPhi = diffPhi;
340  bestchi2 = cand.second;
341  } // end check over dPhi
342  } // end loop over cands
343 
344  // set cmsswTrackID
345  cmsswTrackID_ = cmsswTrackID; // defaults to -1!
346  helixChi2_ = bestchi2;
347  dPhi_ = bestdPhi;
348 
349  // get seed hits
350  const int nSeedHits = nMatchedSeedHits();
351 
352  // Modify cmsswTrackID based on length and findability
353  cmsswTrackID_ = modifyRefTrackID(trk.nFoundHits() - nSeedHits,
354  Config::nMinFoundHits - nSeedHits,
355  cmsswtracks,
356  -1,
357  trk.getDuplicateValue(),
358  cmsswTrackID_);
359 
360  // other important info
363  float(nHitsMatched_) / float(trk.nFoundHits() - nSeedHits); // seed hits may already be included!
364  }
int modifyRefTrackID(const int foundHits, const int minHits, const TrackVec &reftracks, const int trueID, const int duplicate, int refTrackID)
Definition: TrackExtra.cc:59
ROOT::Math::SMatrix< float, 6, 6, ROOT::Math::MatRepSym< float, 6 > > SMatrixSym66
Definition: MatrixSTypes.h:8
constexpr float minCMSSWMatchdPhi[6]
float computeHelixChi2(const Vector &simV, const Vector &recoV, const Matrix &recoM, const bool diagOnly=false)
Definition: Track.h:664
ROOT::Math::SVector< float, 2 > SVector2
Definition: MatrixSTypes.h:18
std::map< int, std::vector< int > > HitLayerMap
Definition: Track.h:16
float fracHitsMatched_
Definition: TrackExtra.h:107
float squashPhiGeneral(float phi)
Definition: Hit.h:22
char const * label
int nHitsMatched() const
Definition: TrackExtra.h:80
int getMatchBin(const float pt)
Definition: TrackExtra.cc:237
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< idchi2Pair > idchi2PairVec
Definition: TrackExtra.cc:233
ROOT::Math::SMatrix< float, 2, 2, ROOT::Math::MatRepSym< float, 2 > > SMatrixSym22
Definition: MatrixSTypes.h:17
constexpr float minCMSSWMatchChi2[6]
bool isSeedHit(const int lyr, const int idx) const
Definition: TrackExtra.cc:53
int cmsswTrackID() const
Definition: TrackExtra.h:89
ROOT::Math::SVector< float, 6 > SVector6
Definition: MatrixSTypes.h:10
int nMatchedSeedHits() const
Definition: TrackExtra.h:94
bool sortIDsByChi2(const idchi2Pair &cand1, const idchi2Pair &cand2)
Definition: TrackExtra.cc:235

◆ setDuplicateInfo()

void mkfit::TrackExtra::setDuplicateInfo ( int  duplicateID,
bool  isDuplicate 
)
inline

Definition at line 85 of file TrackExtra.h.

References duplicateID(), duplicateID_, isDuplicate(), and isDuplicate_.

85  {
88  }
int duplicateID() const
Definition: TrackExtra.h:84
bool isDuplicate() const
Definition: TrackExtra.h:83

◆ setmcTrackID()

void mkfit::TrackExtra::setmcTrackID ( int  mcTrackID)
inline

Definition at line 96 of file TrackExtra.h.

References mcTrackID(), and mcTrackID_.

96 { mcTrackID_ = mcTrackID; }
int mcTrackID() const
Definition: TrackExtra.h:79

◆ setMCTrackIDInfo()

void mkfit::TrackExtra::setMCTrackIDInfo ( const Track trk,
const std::vector< HitVec > &  layerHits,
const MCHitInfoVec globalHitInfo,
const TrackVec simtracks,
const bool  isSeed,
const bool  isPure 
)

Definition at line 106 of file TrackExtra.cc.

References dPhi_, dprint, dprintf, f, dqmMemoryStats::float, fracHitsMatched_, mkfit::TrackBase::getDuplicateValue(), mkfit::Track::getHitIdx(), mkfit::Track::getHitLyr(), mps_fire::i, l1ctLayer2EG_cff::id, heavyIonCSV_trainingSettings::idx, isSeedHit(), dqmiolumiharvest::j, mkfit::TrackBase::label(), mcTrackID(), mcTrackID_, modifyRefTrackID(), mkfit::TrackBase::momPhi(), mkfit::Config::mtvLikeValidation, dqmiodumpmetadata::n, mkfit::Track::nFoundHits(), nHitsMatched_, nMatchedSeedHits(), mkfit::Config::nMinFoundHits, mkfit::Track::nTotalHits(), seedID_, findQualityFiles::size, jetUpdater_cfi::sort, mkfit::squashPhiGeneral(), mkfit::TrackBase::x(), and mkfit::TrackBase::y().

Referenced by mkfit::StdSeq::Quality::quality_process().

111  {
112  dprintf("TrackExtra::setMCTrackIDInfo for track with label %d, total hits %d, found hits %d\n",
113  trk.label(),
114  trk.nTotalHits(),
115  trk.nFoundHits());
116 
117  std::vector<int> mcTrackIDs; // vector of found mcTrackIDs on reco track
118  int nSeedHits = nMatchedSeedHits(); // count seed hits
119 
120  // loop over all hits stored in reco track, storing valid mcTrackIDs
121  for (int ihit = 0; ihit < trk.nTotalHits(); ++ihit) {
122  const int lyr = trk.getHitLyr(ihit);
123  const int idx = trk.getHitIdx(ihit);
124 
125  // ensure layer exists
126  if (lyr < 0)
127  continue;
128 
129  // skip seed layers (unless, of course, we are validating the seed tracks themselves)
130  if (!Config::mtvLikeValidation && !isSeed && isSeedHit(lyr, idx))
131  continue;
132 
133  // make sure it is a real hit
134  if ((idx >= 0) && (static_cast<size_t>(idx) < layerHits[lyr].size())) {
135  // get mchitid and then get mcTrackID
136  const int mchitid = layerHits[lyr][idx].mcHitID();
137  mcTrackIDs.push_back(globalHitInfo[mchitid].mcTrackID());
138 
139  dprintf(" ihit=%3d trk.hit_idx=%4d trk.hit_lyr=%2d mchitid=%4d mctrkid=%3d\n",
140  ihit,
141  idx,
142  lyr,
143  mchitid,
144  globalHitInfo[mchitid].mcTrackID());
145  } else {
146  dprintf(" ihit=%3d trk.hit_idx=%4d trk.hit_lyr=%2d\n", ihit, idx, lyr);
147  }
148  }
149 
150  int mccount = 0; // count up the mcTrackID with the largest count
151  int mcTrackID = -1; // initialize mcTrackID
152  if (!mcTrackIDs.empty()) // protection against tracks which do not make it past the seed
153  {
154  // sorted list ensures that mcTrackIDs are counted properly
155  std::sort(mcTrackIDs.begin(), mcTrackIDs.end());
156 
157  // don't count bad mcTrackIDs (id < 0)
158  mcTrackIDs.erase(std::remove_if(mcTrackIDs.begin(), mcTrackIDs.end(), [](const int id) { return id < 0; }),
159  mcTrackIDs.end());
160 
161  int n_ids = mcTrackIDs.size();
162  int i = 0;
163  while (i < n_ids) {
164  int j = i + 1;
165  while (j < n_ids && mcTrackIDs[j] == mcTrackIDs[i])
166  ++j;
167 
168  int n = j - i;
169  if (mcTrackIDs[i] >= 0 && n > mccount) {
170  mcTrackID = mcTrackIDs[i];
171  mccount = n;
172  }
173  i = j;
174  }
175 
176  // total found hits in hit index array, excluding seed if necessary
177  const int nCandHits = ((Config::mtvLikeValidation || isSeed) ? trk.nFoundHits() : trk.nFoundHits() - nSeedHits);
178 
179  // 75% or 50% matching criterion
180  if ((Config::mtvLikeValidation ? (4 * mccount > 3 * nCandHits) : (2 * mccount >= nCandHits))) {
181  // require that most matched is the mcTrackID!
182  if (isPure) {
183  if (mcTrackID == seedID_)
185  else
186  mcTrackID_ = -1; // somehow, this guy followed another simtrack!
187  } else {
189  }
190  } else // failed 50% matching criteria
191  {
192  mcTrackID_ = -1;
193  }
194 
195  // recount matched hits for pure sim tracks if reco track is unmatched
196  if (isPure && mcTrackID == -1) {
197  mccount = 0;
198  for (auto id : mcTrackIDs) {
199  if (id == seedID_)
200  mccount++;
201  }
202  }
203 
204  // store matched hit info
205  nHitsMatched_ = mccount;
206  fracHitsMatched_ = float(nHitsMatched_) / float(nCandHits);
207 
208  // compute dPhi
209  dPhi_ =
210  (mcTrackID >= 0 ? squashPhiGeneral(simtracks[mcTrackID].swimPhiToR(trk.x(), trk.y()) - trk.momPhi()) : -99.f);
211  } else {
212  mcTrackID_ = mcTrackID; // defaults from -1!
213  nHitsMatched_ = -99;
214  fracHitsMatched_ = -99.f;
215  dPhi_ = -99.f;
216  }
217 
218  // Modify mcTrackID based on length of track (excluding seed tracks, of course) and findability
219  if (!isSeed) {
220  mcTrackID_ = modifyRefTrackID(trk.nFoundHits() - nSeedHits,
221  Config::nMinFoundHits - nSeedHits,
222  simtracks,
223  (isPure ? seedID_ : -1),
224  trk.getDuplicateValue(),
225  mcTrackID_);
226  }
227 
228  dprint("Track " << trk.label() << " best mc track " << mcTrackID_ << " count " << mccount << "/"
229  << trk.nFoundHits());
230  }
size
Write out results.
int modifyRefTrackID(const int foundHits, const int minHits, const TrackVec &reftracks, const int trueID, const int duplicate, int refTrackID)
Definition: TrackExtra.cc:59
int mcTrackID() const
Definition: TrackExtra.h:79
float fracHitsMatched_
Definition: TrackExtra.h:107
float squashPhiGeneral(float phi)
Definition: Hit.h:22
double f[11][100]
bool isSeedHit(const int lyr, const int idx) const
Definition: TrackExtra.cc:53
#define dprint(x)
Definition: Debug.h:90
#define dprintf(...)
Definition: Debug.h:93
int nMatchedSeedHits() const
Definition: TrackExtra.h:94

◆ setseedID()

void mkfit::TrackExtra::setseedID ( int  seedID)
inline

Definition at line 97 of file TrackExtra.h.

References seedID(), and seedID_.

97 { seedID_ = seedID; }
int seedID() const
Definition: TrackExtra.h:82

Friends And Related Function Documentation

◆ Track

friend class Track
friend

Definition at line 103 of file TrackExtra.h.

Member Data Documentation

◆ cmsswTrackID_

int mkfit::TrackExtra::cmsswTrackID_
private

◆ dPhi_

float mkfit::TrackExtra::dPhi_
private

◆ duplicateID_

int mkfit::TrackExtra::duplicateID_
private

Definition at line 109 of file TrackExtra.h.

Referenced by duplicateID(), and setDuplicateInfo().

◆ fracHitsMatched_

float mkfit::TrackExtra::fracHitsMatched_
private

◆ helixChi2_

float mkfit::TrackExtra::helixChi2_
private

◆ isDuplicate_

bool mkfit::TrackExtra::isDuplicate_
private

Definition at line 110 of file TrackExtra.h.

Referenced by isDuplicate(), and setDuplicateInfo().

◆ matchedSeedHits_

HoTVec mkfit::TrackExtra::matchedSeedHits_
private

Definition at line 114 of file TrackExtra.h.

Referenced by findMatchingSeedHits(), isSeedHit(), and nMatchedSeedHits().

◆ mcTrackID_

int mkfit::TrackExtra::mcTrackID_
private

Definition at line 105 of file TrackExtra.h.

Referenced by mcTrackID(), setmcTrackID(), and setMCTrackIDInfo().

◆ nHitsMatched_

int mkfit::TrackExtra::nHitsMatched_
private

◆ seedAlgos_

std::vector<int> mkfit::TrackExtra::seedAlgos_
private

Definition at line 115 of file TrackExtra.h.

Referenced by addAlgo(), and seedAlgos().

◆ seedID_

int mkfit::TrackExtra::seedID_
private

Definition at line 108 of file TrackExtra.h.

Referenced by seedID(), setMCTrackIDInfo(), and setseedID().