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::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
 Association Sim To Reco with Collections (Gen Particle version) More...
 
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::RecoToGenCollection associateRecoToGen (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...
 
 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...
 
const TrackToGenParticleAssociatorBaseImploperator= (const TrackToGenParticleAssociatorBaseImpl &)=delete
 
 TrackToGenParticleAssociatorBaseImpl ()
 Constructor. More...
 
 TrackToGenParticleAssociatorBaseImpl (const TrackToGenParticleAssociatorBaseImpl &)=delete
 
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.

Member Function Documentation

◆ associateGenToReco() [1/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.

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

Referenced by associateGenToReco().

82  {
83  reco::BeamSpot const& bs = *theBeamSpot;
84 
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 }
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:71
const_iterator begin() const
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
T sqrt(T t)
Definition: SSEVec.h:23
const_iterator end() const
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
#define LogDebug(id)

◆ associateGenToReco() [2/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.

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

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  }
ProductID id() const
Definition: HandleBase.cc:29
reco::GenToRecoCollection associateGenToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67

◆ associateRecoToGen() [1/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.

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

Referenced by associateRecoToGen().

22  {
23  reco::BeamSpot const& bs = *theBeamSpot;
24 
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 }
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:71
const_iterator begin() const
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
const_iterator end() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
#define LogDebug(id)

◆ associateRecoToGen() [2/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.

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

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  }
ProductID id() const
Definition: HandleBase.cc:29
reco::RecoToGenCollection associateRecoToGen(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
Definition: RefVector.h:67

◆ 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.

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

17  {
18  return track_associator::trackAssociationChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, *theMF, bs);
19 }
double trackAssociationChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const reco::TrackBase::ParameterVector &sParameters)
basic method where chi2 is computed

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.