CMS 3D CMS Logo

ConversionTools.cc
Go to the documentation of this file.
1 #include <TMath.h>
11 
12 using namespace edm;
13 using namespace reco;
14 
15 //--------------------------------------------------------------------------------------------------
17  const math::XYZPoint &beamspot,
18  float lxyMin,
19  float probMin,
20  unsigned int nHitsBeforeVtxMax) {
21  //Check if a given conversion candidate passes the conversion selection cuts
22 
23  const reco::Vertex &vtx = conv.conversionVertex();
24 
25  //vertex validity
26  if (!vtx.isValid())
27  return false;
28 
29  //fit probability
30  if (TMath::Prob(vtx.chi2(), vtx.ndof()) < probMin)
31  return false;
32 
33  //compute transverse decay length
34  math::XYZVector mom(conv.refittedPairMomentum());
35  double dbsx = vtx.x() - beamspot.x();
36  double dbsy = vtx.y() - beamspot.y();
37  double lxy = (mom.x() * dbsx + mom.y() * dbsy) / mom.rho();
38 
39  //transverse decay length
40  if (lxy < lxyMin)
41  return false;
42 
43  //loop through daughters to check nhitsbeforevtx
44  for (std::vector<uint8_t>::const_iterator it = conv.nHitsBeforeVtx().begin(); it != conv.nHitsBeforeVtx().end();
45  ++it) {
46  if ((*it) > nHitsBeforeVtxMax)
47  return false;
48  }
49 
50  return true;
51 }
52 
53 //--------------------------------------------------------------------------------------------------
55  const reco::Conversion &conv,
56  bool allowCkfMatch,
57  bool allowAmbiguousGsfMatch) {
58  //check if a given GsfElectron matches a given conversion (no quality cuts applied)
59  //matching is always attempted through the gsf track ref, and optionally attempted through the
60  //closest ctf track ref
61 
62  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
63  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
64  ++it) {
65  if (ele.reco::GsfElectron::gsfTrack().isNonnull() && ele.reco::GsfElectron::gsfTrack().id() == it->id() &&
66  ele.reco::GsfElectron::gsfTrack().key() == it->key())
67  return true;
68  else if (allowCkfMatch && ele.reco::GsfElectron::closestCtfTrackRef().isNonnull() &&
69  ele.reco::GsfElectron::closestCtfTrackRef().id() == it->id() &&
70  ele.reco::GsfElectron::closestCtfTrackRef().key() == it->key())
71  return true;
72  if (allowAmbiguousGsfMatch) {
74  tk != ele.ambiguousGsfTracksEnd();
75  ++tk) {
76  if (tk->isNonnull() && tk->id() == it->id() && tk->key() == it->key())
77  return true;
78  }
79  }
80  }
81 
82  return false;
83 }
84 
85 //--------------------------------------------------------------------------------------------------
87  const reco::Conversion &conv,
88  bool allowCkfMatch) {
89  //check if a given GsfElectronCore matches a given conversion (no quality cuts applied)
90  //matching is always attempted through the gsf track ref, and optionally attempted through the
91  //closest ctf track ref
92 
93  for (const auto &trkRef : conv.tracks()) {
94  if (eleCore.gsfTrack().isNonnull() && eleCore.gsfTrack().id() == trkRef.id() &&
95  eleCore.gsfTrack().key() == trkRef.key())
96  return true;
97  else if (allowCkfMatch && eleCore.ctfTrack().isNonnull() && eleCore.ctfTrack().id() == trkRef.id() &&
98  eleCore.ctfTrack().key() == trkRef.key())
99  return true;
100  }
101 
102  return false;
103 }
104 
105 //--------------------------------------------------------------------------------------------------
107  const reco::SuperCluster &sc, const reco::Conversion &conv, float dRMax, float dEtaMax, float dPhiMax) {
108  //check if a given SuperCluster matches a given conversion (no quality cuts applied)
109  //matching is geometric between conversion momentum and vector joining conversion vertex
110  //to supercluster position
111 
112  math::XYZVector mom(conv.refittedPairMomentum());
113 
114  const math::XYZPoint &scpos(sc.position());
115  math::XYZPoint cvtx(conv.conversionVertex().position());
116 
117  math::XYZVector cscvector = scpos - cvtx;
118  float dR = reco::deltaR(mom, cscvector);
119  float dEta = mom.eta() - cscvector.eta();
120  float dPhi = reco::deltaPhi(mom.phi(), cscvector.phi());
121 
122  if (dR > dRMax)
123  return false;
124  if (dEta > dEtaMax)
125  return false;
126  if (dPhi > dPhiMax)
127  return false;
128 
129  return true;
130 }
131 
132 //--------------------------------------------------------------------------------------------------
134  //check if given track matches given conversion (matching by ref)
135 
136  if (trk.isNull())
137  return false;
138 
139  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
140  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
141  ++it) {
142  if (trk.id() == it->id() && trk.key() == it->key())
143  return true;
144  }
145 
146  return false;
147 }
148 
149 //--------------------------------------------------------------------------------------------------
151  //check if given track matches given conversion (matching by ref)
152 
153  if (trk.isNull())
154  return false;
155 
156  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
157  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
158  ++it) {
159  if (trk.id() == it->id() && trk.key() == it->key())
160  return true;
161  }
162 
163  return false;
164 }
165 
166 //--------------------------------------------------------------------------------------------------
168  //check if given track matches given conversion (matching by ref)
169 
170  if (trk.isNull())
171  return false;
172 
173  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
174  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it = convTracks.begin(); it != convTracks.end();
175  ++it) {
176  if (trk.id() == it->id() && trk.key() == it->key())
177  return true;
178  }
179 
180  return false;
181 }
182 
183 //--------------------------------------------------------------------------------------------------
185  const reco::ConversionCollection &convCol,
186  const math::XYZPoint &beamspot,
187  bool allowCkfMatch,
188  float lxyMin,
189  float probMin,
190  unsigned int nHitsBeforeVtxMax) {
191  //check if a given electron candidate matches to at least one conversion candidate in the
192  //collection which also passes the selection cuts, optionally match with the closestckf track in
193  //in addition to just the gsf track (enabled in default arguments)
194 
195  for (auto const &it : convCol) {
196  if (!matchesConversion(ele, it, allowCkfMatch))
197  continue;
198  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
199  continue;
200 
201  return true;
202  }
203 
204  return false;
205 }
206 
207 //--------------------------------------------------------------------------------------------------
209  const reco::ConversionCollection &convCol,
210  const math::XYZPoint &beamspot,
211  float lxyMin,
212  float probMin,
213  unsigned int nHitsBeforeVtxMax) {
214  //check if a given track matches to at least one conversion candidate in the
215  //collection which also passes the selection cuts
216 
217  if (trk.isNull())
218  return false;
219 
220  for (auto const &it : convCol) {
221  if (!matchesConversion(trk, it))
222  continue;
223  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
224  continue;
225 
226  return true;
227  }
228 
229  return false;
230 }
231 
232 //--------------------------------------------------------------------------------------------------
234  const reco::ConversionCollection &convCol,
235  const math::XYZPoint &beamspot,
236  float dRMax,
237  float dEtaMax,
238  float dPhiMax,
239  float lxyMin,
240  float probMin,
241  unsigned int nHitsBeforeVtxMax) {
242  //check if a given SuperCluster matches to at least one conversion candidate in the
243  //collection which also passes the selection cuts
244 
245  for (auto const &it : convCol) {
246  if (!matchesConversion(sc, it))
247  continue;
248  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
249  continue;
250 
251  return true;
252  }
253 
254  return false;
255 }
256 
257 //--------------------------------------------------------------------------------------------------
259  const reco::ConversionCollection &convCol,
260  const math::XYZPoint &beamspot,
261  bool allowCkfMatch,
262  float lxyMin,
263  float probMin,
264  unsigned int nHitsBeforeVtxMax) {
265  //check if a given electron candidate matches to at least one conversion candidate in the
266  //collection which also passes the selection cuts, optionally match with the closestckf track in
267  //in addition to just the gsf track (enabled in default arguments)
268  //If multiple conversions are found, returned reference corresponds to minimum
269  //conversion radius
270 
271  reco::Conversion const *match = nullptr;
272 
273  double minRho = 999.;
274  for (auto const &it : convCol) {
275  float rho = it.conversionVertex().position().rho();
276  if (rho > minRho)
277  continue;
278  if (!matchesConversion(ele, it, allowCkfMatch))
279  continue;
280  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
281  continue;
282 
283  minRho = rho;
284  match = &it;
285  }
286 
287  return match;
288 }
289 
290 //--------------------------------------------------------------------------------------------------
292  const reco::ConversionCollection &convCol,
293  const math::XYZPoint &beamspot,
294  bool allowCkfMatch,
295  float lxyMin,
296  float probMin,
297  unsigned int nHitsBeforeVtxMax) {
298  //check if a given electron candidate matches to at least one conversion candidate in the
299  //collection which also passes the selection cuts, optionally match with the closestckf track in
300  //in addition to just the gsf track (enabled in default arguments)
301  //If multiple conversions are found, returned reference corresponds to minimum
302  //conversion radius
303 
304  reco::Conversion const *match = nullptr;
305 
306  double minRho = 999.;
307  for (auto const &it : convCol) {
308  float rho = it.conversionVertex().position().rho();
309  if (rho > minRho)
310  continue;
311  if (!matchesConversion(eleCore, it, allowCkfMatch))
312  continue;
313  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
314  continue;
315 
316  minRho = rho;
317  match = &it;
318  }
319 
320  return match;
321 }
322 
323 //--------------------------------------------------------------------------------------------------
325  const reco::ConversionCollection &convCol,
326  const math::XYZPoint &beamspot,
327  float lxyMin,
328  float probMin,
329  unsigned int nHitsBeforeVtxMax) {
330  //check if a given track matches to at least one conversion candidate in the
331  //collection which also passes the selection cuts
332  //If multiple conversions are found, returned reference corresponds to minimum
333  //conversion radius
334 
335  reco::Conversion const *match = nullptr;
336 
337  if (trk.isNull())
338  return match;
339 
340  double minRho = 999.;
341  for (auto const &it : convCol) {
342  float rho = it.conversionVertex().position().rho();
343  if (rho > minRho)
344  continue;
345  if (!matchesConversion(trk, it))
346  continue;
347  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
348  continue;
349 
350  minRho = rho;
351  match = &it;
352  }
353 
354  return match;
355 }
356 
357 //--------------------------------------------------------------------------------------------------
359  const reco::ConversionCollection &convCol,
360  const math::XYZPoint &beamspot,
361  float dRMax,
362  float dEtaMax,
363  float dPhiMax,
364  float lxyMin,
365  float probMin,
366  unsigned int nHitsBeforeVtxMax) {
367  //check if a given SuperCluster matches to at least one conversion candidate in the
368  //collection which also passes the selection cuts
369  //If multiple conversions are found, returned reference corresponds to minimum
370  //conversion radius
371 
372  reco::Conversion const *match = nullptr;
373 
374  double minRho = 999.;
375  for (auto const &it : convCol) {
376  float rho = it.conversionVertex().position().rho();
377  if (rho > minRho)
378  continue;
379  if (!matchesConversion(sc, it, dRMax, dEtaMax, dPhiMax))
380  continue;
381  if (!isGoodConversion(it, beamspot, lxyMin, probMin, nHitsBeforeVtxMax))
382  continue;
383 
384  minRho = rho;
385  match = &it;
386  }
387 
388  return match;
389 }
390 
391 //--------------------------------------------------------------------------------------------------
393  const reco::GsfElectronCollection &eleCol,
394  const reco::ConversionCollection &convCol,
395  const math::XYZPoint &beamspot,
396  bool allowCkfMatch,
397  float lxyMin,
398  float probMin,
399  unsigned int nHitsBeforeVtxMax) {
400  return !(matchedPromptElectron(sc, eleCol, convCol, beamspot, allowCkfMatch, lxyMin, probMin, nHitsBeforeVtxMax) ==
401  nullptr);
402 }
403 
404 //--------------------------------------------------------------------------------------------------
406  const reco::GsfElectronCollection &eleCol,
407  const reco::ConversionCollection &convCol,
408  const math::XYZPoint &beamspot,
409  bool allowCkfMatch,
410  float lxyMin,
411  float probMin,
412  unsigned int nHitsBeforeVtxMax) {
413  //check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
414  //and not matching any conversion in the collection passing the quality cuts
415 
416  reco::GsfElectron const *match = nullptr;
417 
418  if (sc.isNull())
419  return match;
420 
421  for (auto const &it : eleCol) {
422  //match electron to supercluster
423  if (it.superCluster() != sc)
424  continue;
425 
426  //check expected inner hits
427  if (it.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > 0)
428  continue;
429 
430  //check if electron is matching to a conversion
431  if (hasMatchedConversion(it, convCol, beamspot, allowCkfMatch, lxyMin, probMin, nHitsBeforeVtxMax))
432  continue;
433 
434  match = &it;
435  }
436 
437  return match;
438 }
439 
440 //--------------------------------------------------------------------------------------------------
442  if (conv != nullptr) {
443  const reco::Vertex &vtx = conv->conversionVertex();
444  if (vtx.isValid()) {
445  return TMath::Prob(vtx.chi2(), vtx.ndof());
446  }
447  }
448  return -1;
449 }
edm::RefToBase::isNull
bool isNull() const
Checks for null.
Definition: RefToBase.h:295
photonValidator_cfi.dEtaMax
dEtaMax
Definition: photonValidator_cfi.py:76
reco::Conversion
Definition: Conversion.h:23
reco::GsfElectron::ambiguousGsfTracksBegin
GsfTrackRefVector::const_iterator ambiguousGsfTracksBegin() const
Definition: GsfElectron.h:691
ConversionTools.h
edm::RefToBase::key
size_t key() const
Definition: RefToBase.h:219
conv
static HepMC::IO_HEPEVT conv
Definition: BeamHaloProducer.cc:48
reco::SuperCluster
Definition: SuperCluster.h:18
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
recoSelectForWrite_cfi.probMin
probMin
Definition: recoSelectForWrite_cfi.py:8
edm::Ref::isNull
bool isNull() const
Checks for null.
Definition: Ref.h:235
edm
HLT enums.
Definition: AlignableModifier.h:19
ConversionTools::hasMatchedPromptElectron
static bool hasMatchedPromptElectron(const reco::SuperClusterRef &sc, const reco::GsfElectronCollection &eleCol, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
Definition: ConversionTools.cc:392
ConversionTools::getVtxFitProb
static float getVtxFitProb(const reco::Conversion *conv)
Definition: ConversionTools.cc:441
reco::GsfElectronCollection
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
Definition: GsfElectronFwd.h:14
reco::GsfElectronCore::ctfTrack
TrackRef ctfTrack() const
Definition: GsfElectronCore.h:52
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:45
HLT_2018_cff.dEta
dEta
Definition: HLT_2018_cff.py:12289
edm::Ref< TrackCollection >
reco::ConversionCollection
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
deltaR.h
Track.h
TrackFwd.h
ConversionTools::hasMatchedConversion
static bool hasMatchedConversion(const reco::GsfElectron &ele, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
Definition: ConversionTools.cc:184
HLT_2018_cff.dPhi
dPhi
Definition: HLT_2018_cff.py:12290
beamspot
Definition: BeamSpotWrite2Txt.h:8
reco::GsfElectron
Definition: GsfElectron.h:35
badGlobalMuonTaggersAOD_cff.vtx
vtx
Definition: badGlobalMuonTaggersAOD_cff.py:5
math::XYZPoint
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
ConversionTools::matchesConversion
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true, bool allowAmbiguousGsfMatch=false)
Definition: ConversionTools.cc:54
ConversionTools::isGoodConversion
static bool isGoodConversion(const reco::Conversion &conv, const math::XYZPoint &beamspot, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=1)
Definition: ConversionTools.cc:16
edm::Ref::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
math::XYZVector
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
reco::GsfElectronCore
Definition: GsfElectronCore.h:32
RefToPtr.h
GsfTrack.h
reco::CaloCluster::position
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:154
edm::RefToBase::id
ProductID id() const
Definition: RefToBase.h:214
edm::Ref::id
ProductID id() const
Accessor for product ID.
Definition: Ref.h:244
metBenchmark_cfi.dRMax
dRMax
Definition: metBenchmark_cfi.py:18
edm::match
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)
Definition: BranchDescription.cc:351
GsfTrackFwd.h
ConversionTools::matchedPromptElectron
static const reco::GsfElectron * matchedPromptElectron(const reco::SuperClusterRef &sc, const reco::GsfElectronCollection &eleCol, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
Definition: ConversionTools.cc:405
reco::GsfElectronCore::gsfTrack
const GsfTrackRef & gsfTrack() const
Definition: GsfElectronCore.h:48
edm::RefVectorIterator
Definition: EDProductfwd.h:33
reco::HitPattern::MISSING_INNER_HITS
Definition: HitPattern.h:155
ConversionTools::matchedConversion
static const reco::Conversion * matchedConversion(const reco::GsfElectron &ele, const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
Definition: ConversionTools.cc:258
reco::deltaR
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
edm::RefToBase< reco::Track >
edm::Ref::key
key_type key() const
Accessor for product key.
Definition: Ref.h:250
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
cscSegments_cfi.dPhiMax
dPhiMax
Definition: cscSegments_cfi.py:11
reco::GsfElectron::ambiguousGsfTracksEnd
GsfTrackRefVector::const_iterator ambiguousGsfTracksEnd() const
Definition: GsfElectron.h:692
reco::Vertex
Definition: Vertex.h:35
deltaPhi.h
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35
Conversion.h