CMS 3D CMS Logo

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