CMS 3D CMS Logo

TrackGenAssociatorByChi2Impl.cc
Go to the documentation of this file.
3 
5 
7 
8 using namespace edm;
9 using namespace reco;
10 using namespace std;
11 
13  const TrackBase::CovarianceMatrix& recoTrackCovMatrix,
14  const Basic3DVector<double>& momAtVtx,
15  const Basic3DVector<double>& vert,
16  int charge,
17  const reco::BeamSpot& bs) const {
18  return track_associator::trackAssociationChi2(rParameters, recoTrackCovMatrix, momAtVtx, vert, charge, *theMF, bs);
19 }
20 
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 }
80 
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 }
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
void post_insert()
post insert action
T sqrt(T t)
Definition: SSEVec.h:19
const_iterator end() const
reco::GenToRecoCollection associateGenToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
void insert(const key_type &k, const data_type &v)
insert an association
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
fixed size matrix
HLT enums.
reco::RecoToGenCollection associateRecoToGen(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< reco::GenParticleCollection > &) const override
Association Sim To Reco with Collections (Gen Particle version)
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
double trackAssociationChi2(const reco::TrackBase::ParameterVector &rParameters, const reco::TrackBase::CovarianceMatrix &recoTrackCovMatrix, const reco::TrackBase::ParameterVector &sParameters)
basic method where chi2 is computed
math::Error< dimension >::type CovarianceMatrix
5 parameter covariance matrix
Definition: TrackBase.h:74
#define LogDebug(id)