CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MatcherByPullsAlgorithm.cc
Go to the documentation of this file.
2 
3 // user include files
5 
6 /* ____ _ _
7  * / ___|___ _ __ ___| |_ _ __ _ _ ___| |_ ___ _ __
8  * | | / _ \| '_ \/ __| __| '__| | | |/ __| __/ _ \| '__|
9  * | |__| (_) | | | \__ \ |_| | | |_| | (__| || (_) | |
10  * \____\___/|_| |_|___/\__|_| \__,_|\___|\__\___/|_|
11  *
12  */
14  dr2_(std::pow(iConfig.getParameter<double>("maxDeltaR"),2)),
15  cut_(iConfig.getParameter<double>("maxPull")),
16  diagOnly_(iConfig.getParameter<bool>("diagonalElementsOnly")),
17  useVertex_(iConfig.getParameter<bool>("useVertexVariables"))
18 {
19  std::string track = iConfig.getParameter<std::string>("track");
20  if (track == "standAloneMuon") track_ = StaTrack;
21  else if (track == "combinedMuon") track_ = GlbTrack;
22  else if (track == "track") track_ = TrkTrack;
23  else throw cms::Exception("Configuration") << "MatcherByPullsAlgorithm: track '"<<track<<"' is not known\n" <<
24  "Allowed values are: 'track', 'combinedMuon', 'standAloneMuon' (as per reco::RecoCandidate object)\n";
25 }
26 
28 {
29 }
30 
31 /* __ __ _ _
32  * | \/ | __ _| |_ ___| |__ ___ _ __ ___
33  * | |\/| |/ _` | __/ __| '_ \ / _ \ '__/ __|
34  * | | | | (_| | || (__| | | | __/ | \__ \
35  * |_| |_|\__,_|\__\___|_| |_|\___|_| |___/
36  *
37  */
38 std::pair<bool,float>
40  if (::deltaR2(tk,c) <= dr2_) {
41  AlgebraicVector5 diff(tk.qoverp() - c.charge()/c.p(),
42  tk.theta() - c.theta(),
43  ::deltaPhi(tk.phi(), c.phi()),
44  tk.dxy(c.vertex()),
45  tk.dsz(c.vertex()));
46  double pull = ROOT::Math::Similarity(diff, invCov);
47 #if 0
48  std::cout << "Tk charge/pt/eta/phi/vx/vy/vz " << tk.charge() << "\t" << tk.pt() << "\t" << tk.eta() << "\t" << tk.phi() << "\t" << tk.vx() << "\t" << tk.vy() << "\t" << tk.vz() << std::endl;
49  std::cout << "MC charge/pt/eta/phi/vx/vy/vz " << c.charge() << "\t" << c.pt() << "\t" << c.eta() << "\t" << c.phi() << "\t" << c.vx() << "\t" << c.vy() << "\t" << c.vz() << std::endl;
50  std::cout << "Delta: " << diff << std::endl;
51  std::cout << "Sigmas: ";
52  for (size_t i = 0; i < 5; ++i) {
53  if (invCov(i,i) == 0) std::cout << "---\t";
54  else std::cout << std::sqrt(1.0/invCov(i,i)) << "\t";
55  }
56  std::cout << std::endl;
57  std::cout << "Items: ";
58  for (size_t i = 0; i < 5; ++i) {
59  if (invCov(i,i) == 0) std::cout << "---\t";
60  else std::cout << diff(i)*std::sqrt(invCov(i,i)) << "\t";
61  }
62  std::cout << std::endl;
63  std::cout << "Pull: " << pull << std::endl;
64 #endif
65  return std::pair<bool,float>(pull < cut_, pull);
66  }
67  return std::pair<bool,float>(false,9e9);
68 }
69 
70 
71 
72 std::pair<int,float>
74  const std::vector<reco::GenParticle> &cands,
75  const std::vector<uint8_t> &good) const
76 {
77  const reco::Track * tk = track(src);
78  return (tk == 0 ?
79  std::pair<int,float>(-1,9e9) :
80  match(*tk, cands, good));
81 }
82 
83 std::pair<int,float>
85  const std::vector<reco::GenParticle> &cands,
86  const std::vector<uint8_t> &good) const
87 {
88  std::pair<int,float> best(-1,9e9);
89 
90  AlgebraicSymMatrix55 invCov; fillInvCov(tk, invCov);
91  for (int i = 0, n = cands.size(); i < n; ++i) {
92  if (!good[i]) continue;
93  std::pair<bool,float> m = match(tk, cands[i], invCov);
94  if (m.first && (m.second < best.second)) {
95  best.first = i;
96  best.second = m.second;
97  }
98  }
99  return best;
100 }
101 
102 void
104  const std::vector<reco::GenParticle> &cands,
105  const std::vector<uint8_t> &good,
106  std::vector<std::pair<double,int> > &matchesToFill) const
107 {
108  const reco::Track * tk = track(src);
109  if (tk != 0) matchMany(*tk, cands, good, matchesToFill);
110 }
111 
112 void
114  const std::vector<reco::GenParticle> &cands,
115  const std::vector<uint8_t> &good,
116  std::vector<std::pair<double,int> > &matchesToFill) const
117 {
118 
119  AlgebraicSymMatrix55 invCov; fillInvCov(tk, invCov);
120  for (int i = 0, n = cands.size(); i < n; ++i) {
121  if (!good[i]) continue;
122  std::pair<bool,double> m = match(tk, cands[i], invCov);
123  if (m.first) matchesToFill.push_back(std::make_pair(m.second,i));
124  }
125  std::sort(matchesToFill.begin(),matchesToFill.end());
126 }
127 
128 /* _ _ _ _ _ _ _ _
129  * | | | | |_(_) (_) |_(_) ___ ___
130  * | | | | __| | | | __| |/ _ \/ __|
131  * | |_| | |_| | | | |_| | __/\__ \
132  * \___/ \__|_|_|_|\__|_|\___||___/
133  *
134  */
135 const reco::Track *
137  switch (track_) {
138  case StaTrack : return muon.standAloneMuon().isNonnull() ? muon.standAloneMuon().get() : 0;
139  case GlbTrack : return muon.combinedMuon().isNonnull() ? muon.combinedMuon().get() : 0;
140  case TrkTrack : return muon.track().isNonnull() ? muon.track().get() : 0;
141  }
142  assert(false);
143 }
144 
145 
146 void
148 {
149  if (useVertex_) {
150  invCov = tk.covariance();
151  if (diagOnly_) {
152  for (size_t i = 0; i < 5; ++i) { for (size_t j = i+1; j < 5; ++j) {
153  invCov(i,j) = 0;
154  } }
155  }
156  invCov.Invert();
157  } else {
158  AlgebraicSymMatrix33 momCov = tk.covariance().Sub<AlgebraicSymMatrix33>(0,0); // get 3x3 matrix
159  if (diagOnly_) { momCov(0,1) = 0; momCov(0,2) = 0; momCov(1,2) = 0; }
160  momCov.Invert();
161  invCov.Place_at(momCov,0,0);
162  }
163 }
double qoverp() const
q / p
Definition: TrackBase.h:560
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:252
virtual double pt() const =0
transverse momentum
double theta() const
polar angle
Definition: TrackBase.h:566
bool diagOnly_
Use only the diagonal terms of the covariance matrix.
assert(m_qm.get())
MatcherByPullsAlgorithm(const edm::ParameterSet &)
virtual double vx() const =0
x coordinate of vertex position
std::pair< bool, float > match(const reco::Track &tk, const reco::Candidate &mc, const AlgebraicSymMatrix55 &invertedCovariance) const
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:632
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
virtual reco::TrackRef standAloneMuon() const
reference to a stand-alone muon Track
double dsz() const
dsz parameter (THIS IS NOT the SZ impact parameter to (0,0,0) if refPoint is far from (0...
Definition: TrackBase.h:590
virtual double vy() const =0
y coordinate of vertex position
virtual reco::TrackRef track() const
reference to a Track
double dr2_
DeltaR of the matching cone.
bool useVertex_
Use also dxy / dsz in the matching.
virtual double p() const =0
magnitude of momentum vector
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:638
ROOT::Math::SMatrix< double, 3, 3, ROOT::Math::MatRepSym< double, 3 > > AlgebraicSymMatrix33
virtual double theta() const =0
momentum polar angle
CovarianceMatrix covariance() const
return track covariance matrix
Definition: TrackBase.h:718
T sqrt(T t)
Definition: SSEVec.h:48
void fillInvCov(const reco::Track &tk, AlgebraicSymMatrix55 &invCov) const
Fill the inverse covariance matrix for the match(track, candidate, invCov) method.
double pt() const
track transverse momentum
Definition: TrackBase.h:608
int j
Definition: DBlmapReader.cc:9
double deltaR2(const T1 &t1, const T2 &t2)
Definition: deltaR.h:36
virtual const Point & vertex() const =0
vertex position
virtual int charge() const =0
electric charge
T const * get() const
Returns C++ pointer to the item.
Definition: Ref.h:244
double cut_
Cut on the pull.
double vz() const
z coordinate of the reference point on track
Definition: TrackBase.h:656
ROOT::Math::SVector< double, 5 > AlgebraicVector5
virtual double vz() const =0
z coordinate of vertex position
double vy() const
y coordinate of the reference point on track
Definition: TrackBase.h:650
TrackChoice track_
Track to be used in matching.
tuple cout
Definition: gather_cfg.py:121
int charge() const
track electric charge
Definition: TrackBase.h:554
const reco::Track * track(const reco::RecoCandidate &src) const
Get track out of Candidate, NULL if missing.
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:578
void matchMany(const reco::RecoCandidate &src, const std::vector< reco::GenParticle > &cands, const std::vector< uint8_t > &good, std::vector< std::pair< double, int > > &matchesToFill) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
double vx() const
x coordinate of the reference point on track
Definition: TrackBase.h:644
virtual double phi() const =0
momentum azimuthal angle
virtual double eta() const =0
momentum pseudorapidity
virtual reco::TrackRef combinedMuon() const
reference to a stand-alone muon Track