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 }
edm::RefToBaseVector::end
const_iterator end() const
Definition: RefToBaseVector.h:186
mps_fire.i
i
Definition: mps_fire.py:428
TrackGenAssociatorByChi2Impl.h
trackAssociatorByChi2_cfi.chi2cut
chi2cut
Definition: trackAssociatorByChi2_cfi.py:4
edm
HLT enums.
Definition: AlignableModifier.h:19
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< GenParticleCollection >
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
hltPixelTracks_cff.chi2
chi2
Definition: hltPixelTracks_cff.py:25
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
Line.h
cmsswSequenceInfo.tp
tp
Definition: cmsswSequenceInfo.py:17
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
trackAssociatorByChi2_cfi.onlyDiagonal
onlyDiagonal
Definition: trackAssociatorByChi2_cfi.py:6
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
edm::RefToBaseVector< reco::Track >
edm::AssociationMap::insert
void insert(const key_type &k, const data_type &v)
insert an association
Definition: AssociationMap.h:166
TrackingParticle.h
std
Definition: JetResolutionObject.h:76
edm::RefToBaseVector::begin
const_iterator begin() const
Definition: RefToBaseVector.h:181
trackAssociationChi2.h
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::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