CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
TrackGenAssociatorByChi2Impl Class Reference

#include <TrackGenAssociatorByChi2Impl.h>

Inheritance diagram for TrackGenAssociatorByChi2Impl:
reco::TrackToGenParticleAssociatorBaseImpl

Public Types

typedef std::map< double, SimTrackChi2SimMap
 
typedef std::pair< reco::Track, Chi2SimMapRecoToSimPair
 
typedef std::vector< RecoToSimPairRecoToSimPairAssociation
 

Public Member Functions

reco::GenToRecoCollection associateGenToReco (const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< reco::GenParticleCollection > &tPCH) const override
 compare reco to sim the handle of reco::Track and GenParticle collections More...
 
reco::GenToRecoCollection associateGenToReco (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
 Association Sim To Reco with Collections (Gen Particle version) More...
 
reco::RecoToGenCollection associateRecoToGen (const edm::Handle< edm::View< reco::Track > > &tCH, const edm::Handle< reco::GenParticleCollection > &tPCH) const override
 compare reco to sim the handle of reco::Track and GenParticle collections More...
 
reco::RecoToGenCollection associateRecoToGen (const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
 Association Sim To Reco with Collections (Gen Particle version) More...
 
 TrackGenAssociatorByChi2Impl (const MagneticField &mF, const reco::BeamSpot &bs, double chi2Cut, bool onlyDiag)
 Constructor with PSet. More...
 
- Public Member Functions inherited from reco::TrackToGenParticleAssociatorBaseImpl
virtual reco::GenToRecoCollection associateGenToReco (const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< reco::GenParticleCollection > &tPCH) const =0
 compare reco to sim the handle of reco::Track and GenParticle collections More...
 
virtual reco::RecoToGenCollection associateRecoToGen (const edm::Handle< edm::View< reco::Track >> &tCH, const edm::Handle< reco::GenParticleCollection > &tPCH) const =0
 compare reco to sim the handle of reco::Track and GenParticle collections More...
 
 TrackToGenParticleAssociatorBaseImpl ()
 Constructor. More...
 
virtual ~TrackToGenParticleAssociatorBaseImpl ()
 

Private Member Functions

double associateRecoToSim (reco::TrackCollection::const_iterator, TrackingParticleCollection::const_iterator, const reco::BeamSpot &) const
 compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2 More...
 
double getChi2 (const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const Basic3DVector< double > &momAtVtx, const Basic3DVector< double > &vert, int charge, const reco::BeamSpot &) const
 basic method where chi2 is computed More...
 

Private Attributes

double chi2cut
 
bool onlyDiagonal
 
const reco::BeamSpottheBeamSpot
 
const MagneticFieldtheMF
 

Detailed Description

Class that performs the association of reco::Tracks and TrackingParticles evaluating the chi2 of reco tracks parameters and sim tracks parameters. The cut can be tuned from the config file: see data/TrackGenAssociatorByChi2.cfi. Note that the Association Map is filled with -ch2 and not chi2 because it is ordered using std::greater: the track with the lowest association chi2 will be the first in the output map.It is possible to use only diagonal terms (associator by pulls) seeting onlyDiagonal = true in the PSet

Author
cerati, magni

Definition at line 35 of file TrackGenAssociatorByChi2Impl.h.

Member Typedef Documentation

◆ Chi2SimMap

Definition at line 37 of file TrackGenAssociatorByChi2Impl.h.

◆ RecoToSimPair

Definition at line 38 of file TrackGenAssociatorByChi2Impl.h.

◆ RecoToSimPairAssociation

Definition at line 39 of file TrackGenAssociatorByChi2Impl.h.

Constructor & Destructor Documentation

◆ TrackGenAssociatorByChi2Impl()

TrackGenAssociatorByChi2Impl::TrackGenAssociatorByChi2Impl ( const MagneticField mF,
const reco::BeamSpot bs,
double  chi2Cut,
bool  onlyDiag 
)
inline

Constructor with PSet.

Constructor with magnetic field, double, bool and InputTag

Definition at line 44 of file TrackGenAssociatorByChi2Impl.h.

45  : theMF(&mF), theBeamSpot(&bs), chi2cut(chi2Cut), onlyDiagonal(onlyDiag) {}

Member Function Documentation

◆ associateGenToReco() [1/2]

reco::GenToRecoCollection TrackGenAssociatorByChi2Impl::associateGenToReco ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< reco::GenParticleCollection > &  tPCH 
) const
inlineoverride

compare reco to sim the handle of reco::Track and GenParticle collections

Definition at line 70 of file TrackGenAssociatorByChi2Impl.h.

71  {
73  for (unsigned int j = 0; j < tCH->size(); j++)
74  tc.push_back(edm::RefToBase<reco::Track>(tCH, j));
75 
77  for (unsigned int j = 0; j < tPCH->size(); j++)
79 
80  return associateGenToReco(tc, tpc);
81  }

References associateGenToReco(), edm::HandleBase::id(), dqmiolumiharvest::j, edm::RefToBaseVector< T >::push_back(), and edm::RefVector< C, T, F >::push_back().

◆ associateGenToReco() [2/2]

GenToRecoCollection TrackGenAssociatorByChi2Impl::associateGenToReco ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< reco::GenParticleCollection > &  tPCH 
) const
overridevirtual

Association Sim To Reco with Collections (Gen Particle version)

Implements reco::TrackToGenParticleAssociatorBaseImpl.

Definition at line 81 of file TrackGenAssociatorByChi2Impl.cc.

82  {
83  reco::BeamSpot const& bs = *theBeamSpot;
84 
85  GenToRecoCollection outputCollection;
86 
87  int tpindex = 0;
88  for (auto tp = tPCH.begin(); tp != tPCH.end(); tp++, ++tpindex) {
89  //skip tps with a very small pt
90  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
91  int charge = (*tp)->charge();
92  if (charge == 0)
93  continue;
94 
95  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION==========="
96  << "\n"
97  << "TrackingParticle #" << tpindex << " with pt=" << sqrt((*tp)->momentum().perp2())
98  << "\n"
99  << "==========================================="
100  << "\n";
101 
102  Basic3DVector<double> momAtVtx((*tp)->momentum().x(), (*tp)->momentum().y(), (*tp)->momentum().z());
103  Basic3DVector<double> vert((*tp)->vertex().x(), (*tp)->vertex().y(), (*tp)->vertex().z());
104 
105  int tindex = 0;
106  for (RefToBaseVector<reco::Track>::const_iterator rt = tC.begin(); rt != tC.end(); rt++, tindex++) {
107  TrackBase::ParameterVector rParameters = (*rt)->parameters();
108  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
109  if (onlyDiagonal) {
110  for (unsigned int i = 0; i < 5; i++) {
111  for (unsigned int j = 0; j < 5; j++) {
112  if (i != j)
113  recoTrackCovMatrix(i, j) = 0;
114  }
115  }
116  }
117  recoTrackCovMatrix.Invert();
118 
119  double chi2 = getChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, bs);
120 
121  if (chi2 < chi2cut) {
122  outputCollection.insert(
123  *tp,
124  std::make_pair(tC[tindex],
125  -chi2)); //-chi2 because the Association Map is ordered using std::greater
126  }
127  }
128  }
129  outputCollection.post_insert();
130  return outputCollection;
131 }

References edm::RefToBaseVector< T >::begin(), edm::RefVector< C, T, F >::begin(), cms::cuda::bs, ALCARECOTkAlJpsiMuMu_cff::charge, hltPixelTracks_cff::chi2, trackAssociatorByChi2_cfi::chi2cut, edm::RefToBaseVector< T >::end(), edm::RefVector< C, T, F >::end(), mps_fire::i, edm::AssociationMap< Tag >::insert(), dqmiolumiharvest::j, LogDebug, trackAssociatorByChi2_cfi::onlyDiagonal, edm::AssociationMap< Tag >::post_insert(), hcal_runs::rt, mathSSE::sqrt(), and cmsswSequenceInfo::tp.

Referenced by associateGenToReco().

◆ associateRecoToGen() [1/2]

reco::RecoToGenCollection TrackGenAssociatorByChi2Impl::associateRecoToGen ( const edm::Handle< edm::View< reco::Track > > &  tCH,
const edm::Handle< reco::GenParticleCollection > &  tPCH 
) const
inlineoverride

compare reco to sim the handle of reco::Track and GenParticle collections

Definition at line 56 of file TrackGenAssociatorByChi2Impl.h.

57  {
59  for (unsigned int j = 0; j < tCH->size(); j++)
60  tc.push_back(edm::RefToBase<reco::Track>(tCH, j));
61 
63  for (unsigned int j = 0; j < tPCH->size(); j++)
65 
66  return associateRecoToGen(tc, tpc);
67  }

References associateRecoToGen(), edm::HandleBase::id(), dqmiolumiharvest::j, edm::RefToBaseVector< T >::push_back(), and edm::RefVector< C, T, F >::push_back().

◆ associateRecoToGen() [2/2]

RecoToGenCollection TrackGenAssociatorByChi2Impl::associateRecoToGen ( const edm::RefToBaseVector< reco::Track > &  tC,
const edm::RefVector< reco::GenParticleCollection > &  tPCH 
) const
overridevirtual

Association Sim To Reco with Collections (Gen Particle version)

Implements reco::TrackToGenParticleAssociatorBaseImpl.

Definition at line 21 of file TrackGenAssociatorByChi2Impl.cc.

22  {
23  reco::BeamSpot const& bs = *theBeamSpot;
24 
25  RecoToGenCollection outputCollection;
26 
27  //dereference the edm::Refs only once
28  std::vector<GenParticle const*> tPC;
29  tPC.reserve(tPCH.size());
30  for (auto const& ref : tPCH) {
31  tPC.push_back(&(*ref));
32  }
33 
34  int tindex = 0;
35  for (RefToBaseVector<reco::Track>::const_iterator rt = tC.begin(); rt != tC.end(); rt++, tindex++) {
36  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION==========="
37  << "\n"
38  << "rec::Track #" << tindex << " with pt=" << (*rt)->pt() << "\n"
39  << "==========================================="
40  << "\n";
41 
42  TrackBase::ParameterVector rParameters = (*rt)->parameters();
43 
44  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
45  if (onlyDiagonal) {
46  for (unsigned int i = 0; i < 5; i++) {
47  for (unsigned int j = 0; j < 5; j++) {
48  if (i != j)
49  recoTrackCovMatrix(i, j) = 0;
50  }
51  }
52  }
53 
54  recoTrackCovMatrix.Invert();
55 
56  int tpindex = 0;
57  for (auto tp = tPC.begin(); tp != tPC.end(); tp++, ++tpindex) {
58  //skip tps with a very small pt
59  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
60  int charge = (*tp)->charge();
61  if (charge == 0)
62  continue;
63  Basic3DVector<double> momAtVtx((*tp)->momentum().x(), (*tp)->momentum().y(), (*tp)->momentum().z());
64  Basic3DVector<double> vert = (Basic3DVector<double>)(*tp)->vertex();
65 
66  double chi2 = getChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, bs);
67 
68  if (chi2 < chi2cut) {
69  //NOTE: tPC and tPCH use the same index for the same object
70  outputCollection.insert(
71  tC[tindex],
72  std::make_pair(tPCH[tpindex],
73  -chi2)); //-chi2 because the Association Map is ordered using std::greater
74  }
75  }
76  }
77  outputCollection.post_insert();
78  return outputCollection;
79 }

References edm::RefToBaseVector< T >::begin(), cms::cuda::bs, ALCARECOTkAlJpsiMuMu_cff::charge, hltPixelTracks_cff::chi2, trackAssociatorByChi2_cfi::chi2cut, edm::RefToBaseVector< T >::end(), mps_fire::i, edm::AssociationMap< Tag >::insert(), dqmiolumiharvest::j, LogDebug, trackAssociatorByChi2_cfi::onlyDiagonal, edm::AssociationMap< Tag >::post_insert(), hcal_runs::rt, edm::RefVector< C, T, F >::size(), and cmsswSequenceInfo::tp.

Referenced by associateRecoToGen().

◆ associateRecoToSim()

double TrackGenAssociatorByChi2Impl::associateRecoToSim ( reco::TrackCollection::const_iterator  ,
TrackingParticleCollection::const_iterator  ,
const reco::BeamSpot  
) const
private

compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2

◆ getChi2()

double TrackGenAssociatorByChi2Impl::getChi2 ( const reco::TrackBase::ParameterVector rParameters,
const reco::TrackBase::CovarianceMatrix recoTrackCovMatrix,
const Basic3DVector< double > &  momAtVtx,
const Basic3DVector< double > &  vert,
int  charge,
const reco::BeamSpot bs 
) const
private

basic method where chi2 is computed

Definition at line 12 of file TrackGenAssociatorByChi2Impl.cc.

17  {
18  return track_associator::trackAssociationChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, *theMF, bs);
19 }

References cms::cuda::bs, ALCARECOTkAlJpsiMuMu_cff::charge, and track_associator::trackAssociationChi2().

Member Data Documentation

◆ chi2cut

double TrackGenAssociatorByChi2Impl::chi2cut
private

Definition at line 99 of file TrackGenAssociatorByChi2Impl.h.

◆ onlyDiagonal

bool TrackGenAssociatorByChi2Impl::onlyDiagonal
private

Definition at line 100 of file TrackGenAssociatorByChi2Impl.h.

◆ theBeamSpot

const reco::BeamSpot* TrackGenAssociatorByChi2Impl::theBeamSpot
private

Definition at line 98 of file TrackGenAssociatorByChi2Impl.h.

◆ theMF

const MagneticField* TrackGenAssociatorByChi2Impl::theMF
private

Definition at line 97 of file TrackGenAssociatorByChi2Impl.h.

edm::RefToBaseVector::end
const_iterator end() const
Definition: RefToBaseVector.h:186
mps_fire.i
i
Definition: mps_fire.py:428
hcal_runs.rt
rt
Definition: hcal_runs.py:76
edm::RefVector::begin
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
TrackGenAssociatorByChi2Impl::associateGenToReco
reco::GenToRecoCollection associateGenToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
Definition: TrackGenAssociatorByChi2Impl.cc:81
edm::RefVector
Definition: EDProductfwd.h:27
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
TrackGenAssociatorByChi2Impl::theBeamSpot
const reco::BeamSpot * theBeamSpot
Definition: TrackGenAssociatorByChi2Impl.h:98
edm::Ref
Definition: AssociativeIterator.h:58
edm::AssociationMap::post_insert
void post_insert()
post insert action
Definition: AssociationMap.h:229
cms::cuda::bs
bs
Definition: HistoContainer.h:76
edm::RefVector::end
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
reco::BeamSpot
Definition: BeamSpot.h:21
reco::TrackBase::ParameterVector
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:71
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
TrackGenAssociatorByChi2Impl::onlyDiagonal
bool onlyDiagonal
Definition: TrackGenAssociatorByChi2Impl.h:100
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::AssociationMap
Definition: AssociationMap.h:48
track_associator::trackAssociationChi2
double trackAssociationChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const reco::TrackBase::ParameterVector &sParameters)
basic method where chi2 is computed
Definition: trackAssociationChi2.cc:9
TrackGenAssociatorByChi2Impl::theMF
const MagneticField * theMF
Definition: TrackGenAssociatorByChi2Impl.h:97
edm::RefVector::push_back
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67
edm::RefToBaseVector< reco::Track >
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
edm::RefToBase< reco::Track >
edm::RefToBaseVector::begin
const_iterator begin() const
Definition: RefToBaseVector.h:181
PixelTripletNoTipGenerator_cfi.chi2Cut
chi2Cut
Definition: PixelTripletNoTipGenerator_cfi.py:10
TrackGenAssociatorByChi2Impl::getChi2
double getChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const Basic3DVector< double > &momAtVtx, const Basic3DVector< double > &vert, int charge, const reco::BeamSpot &) const
basic method where chi2 is computed
Definition: TrackGenAssociatorByChi2Impl.cc:12
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
reco::TrackBase::CovarianceMatrix
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
edm::RefVector::size
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
TrackGenAssociatorByChi2Impl::chi2cut
double chi2cut
Definition: TrackGenAssociatorByChi2Impl.h:99
edm::HandleBase::id
ProductID id() const
Definition: HandleBase.cc:29
TrackGenAssociatorByChi2Impl::associateRecoToGen
reco::RecoToGenCollection associateRecoToGen(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
Definition: TrackGenAssociatorByChi2Impl.cc:21
Basic3DVector
Definition: extBasic3DVector.h:30