CMS 3D CMS Logo

TrackAssociatorByChi2Impl.cc
Go to the documentation of this file.
3 
8 
9 using namespace edm;
10 using namespace reco;
11 using namespace std;
12 using namespace track_associator;
13 
16  const BeamSpot& bs = *beamSpot_;
17 
18  RecoToSimCollection outputCollection(productGetter_);
19 
20  //dereference the Refs only once and precompute params
21  std::vector<TrackingParticle const*> tPC;
22  std::vector<std::pair<bool, TrackBase::ParameterVector>> tpParams;
23  tPC.reserve(tPCH.size());
24  tpParams.reserve(tPCH.size());
25  for (auto const& ref : tPCH) {
26  auto const& tp = *ref;
27  tPC.push_back(&tp);
28 
29  int charge = tp.charge();
30  if (charge == 0)
31  tpParams.emplace_back(false, TrackBase::ParameterVector());
32  else {
33  using BVec = Basic3DVector<double>;
34  tpParams.emplace_back(
35  trackingParametersAtClosestApproachToBeamSpot(BVec(tp.vertex()), BVec(tp.momentum()), charge, *mF_, bs));
36  }
37  }
38 
39  int tindex = 0;
40  for (RefToBaseVector<Track>::const_iterator rt = tC.begin(); rt != tC.end(); rt++, tindex++) {
41  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION==========="
42  << "\n"
43  << "rec::Track #" << tindex << " with pt=" << (*rt)->pt() << "\n"
44  << "==========================================="
45  << "\n";
46 
47  TrackBase::ParameterVector rParameters = (*rt)->parameters();
48 
49  TrackBase::CovarianceMatrix recoTrackCovMatrix = (*rt)->covariance();
50  if (onlyDiagonal_) {
51  for (unsigned int i = 0; i < 5; i++) {
52  for (unsigned int j = 0; j < 5; j++) {
53  if (i != j)
54  recoTrackCovMatrix(i, j) = 0;
55  }
56  }
57  }
58 
59  recoTrackCovMatrix.Invert();
60 
61  int tpindex = 0;
62  for (auto tp = tPC.begin(); tp != tPC.end(); tp++, ++tpindex) {
63  //skip tps with a very small pt
64  //if (sqrt((*tp)->momentum().perp2())<0.5) continue;
65  if (!tpParams[tpindex].first)
66  continue;
67 
68  double chi2 = trackAssociationChi2(rParameters, recoTrackCovMatrix, tpParams[tpindex].second);
69 
70  if (chi2 < chi2cut_) {
71  //-chi2 because the Association Map is ordered using std::greater
72  outputCollection.insert(tC[tindex], std::make_pair(tPCH[tpindex], -chi2));
73  }
74  }
75  }
76  outputCollection.post_insert();
77  return outputCollection;
78 }
79 
82  const BeamSpot& bs = *beamSpot_;
83 
84  SimToRecoCollection outputCollection(productGetter_);
85 
86  //compute track parameters only once
87  std::vector<TrackBase::ParameterVector> tPars;
88  tPars.reserve(tC.size());
89  std::vector<TrackBase::CovarianceMatrix> tCovs;
90  tCovs.reserve(tC.size());
91  for (auto const& ref : tC) {
92  auto const& aTk = *ref;
93  tPars.emplace_back(aTk.parameters());
94 
95  TrackBase::CovarianceMatrix recoTrackCovMatrix = aTk.covariance();
96  if (onlyDiagonal_) {
97  for (unsigned int i = 0; i < 5; i++) {
98  for (unsigned int j = 0; j < 5; j++) {
99  if (i != j)
100  recoTrackCovMatrix(i, j) = 0;
101  }
102  }
103  }
104  recoTrackCovMatrix.Invert();
105  tCovs.emplace_back(recoTrackCovMatrix);
106  }
107 
108  int tpindex = 0;
109  for (auto tp = tPCH.begin(); tp != tPCH.end(); tp++, ++tpindex) {
110  //skip tps with a very small pt
111  //if (sqrt(tp->momentum().perp2())<0.5) continue;
112  auto const& aTP = **tp;
113  int charge = aTP.charge();
114  if (charge == 0)
115  continue;
116 
117  LogDebug("TrackAssociator") << "=========LOOKING FOR ASSOCIATION==========="
118  << "\n"
119  << "TrackingParticle #" << tpindex << " with pt=" << sqrt(aTP.momentum().perp2())
120  << "\n"
121  << "==========================================="
122  << "\n";
123 
124  using BVec = Basic3DVector<double>;
125  auto const tpBoolParams =
126  trackingParametersAtClosestApproachToBeamSpot(BVec(aTP.vertex()), BVec(aTP.momentum()), charge, *mF_, bs);
127  if (!tpBoolParams.first)
128  continue;
129 
130  for (unsigned int tindex = 0; tindex < tC.size(); tindex++) {
131  TrackBase::ParameterVector const& rParameters = tPars[tindex];
132  TrackBase::CovarianceMatrix const& recoTrackCovMatrix = tCovs[tindex];
133 
134  double chi2 = trackAssociationChi2(rParameters, recoTrackCovMatrix, tpBoolParams.second);
135 
136  if (chi2 < chi2cut_) {
137  //-chi2 because the Association Map is ordered using std::greater
138  outputCollection.insert(*tp, std::make_pair(tC[tindex], -chi2));
139  }
140  }
141  }
142  outputCollection.post_insert();
143  return outputCollection;
144 }
reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Reco To Sim with Collections.
reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector< reco::Track > &, const edm::RefVector< TrackingParticleCollection > &) const override
Association Sim To Reco with Collections.
math::Vector< dimension >::type ParameterVector
parameter vector
Definition: TrackBase.h:71
size_type size() const
U second(std::pair< T, U > const &p)
const_iterator begin() const
T sqrt(T t)
Definition: SSEVec.h:23
const_iterator end() const
size_type size() const
Size of the RefVector.
Definition: RefVector.h:102
std::pair< bool, reco::TrackBase::ParameterVector > trackingParametersAtClosestApproachToBeamSpot(const Basic3DVector< double > &vertex, const Basic3DVector< double > &momAtVtx, float charge, const MagneticField &magField, const BeamSpot &bs)
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:228
fixed size matrix
HLT enums.
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:223
T first(std::pair< T, U > const &p)
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)