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 
16 //--------------------------------------------------------------------------------------------------
17 bool ConversionTools::isGoodConversion(const Conversion &conv, const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
18 {
19 
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()) return false;
26 
27  //fit probability
28  if (TMath::Prob( vtx.chi2(), vtx.ndof() )<probMin) return false;
29 
30  //compute transverse decay length
32  double dbsx = vtx.x() - beamspot.x();
33  double dbsy = vtx.y() - beamspot.y();
34  double lxy = (mom.x()*dbsx + mom.y()*dbsy)/mom.rho();
35 
36  //transverse decay length
37  if ( lxy<lxyMin )
38  return false;
39 
40  //loop through daughters to check nhitsbeforevtx
41  for (std::vector<uint8_t>::const_iterator it = conv.nHitsBeforeVtx().begin(); it!=conv.nHitsBeforeVtx().end(); ++it) {
42  if ( (*it)>nHitsBeforeVtxMax ) return false;
43  }
44 
45  return true;
46 }
47 
48 //--------------------------------------------------------------------------------------------------
49 bool ConversionTools::matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch, bool allowAmbiguousGsfMatch)
50 {
51 
52  //check if a given GsfElectron matches a given conversion (no quality cuts applied)
53  //matching is always attempted through the gsf track ref, and optionally attempted through the
54  //closest ctf track ref
55 
56  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
57  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
58  if ( ele.reco::GsfElectron::gsfTrack().isNonnull() && ele.reco::GsfElectron::gsfTrack().id()==it->id() && ele.reco::GsfElectron::gsfTrack().key()==it->key()) return true;
59  else if ( allowCkfMatch && ele.reco::GsfElectron::closestCtfTrackRef().isNonnull() && ele.reco::GsfElectron::closestCtfTrackRef().id()==it->id() && ele.reco::GsfElectron::closestCtfTrackRef().key()==it->key() ) return true;
60  if (allowAmbiguousGsfMatch) {
62  if (tk->isNonnull() && tk->id()==it->id() && tk->key()==it->key()) return true;
63  }
64  }
65  }
66 
67  return false;
68 }
69 
70 //--------------------------------------------------------------------------------------------------
71 bool ConversionTools::matchesConversion(const reco::GsfElectronCore &eleCore, const reco::Conversion &conv, bool allowCkfMatch)
72 {
73 
74  //check if a given GsfElectronCore matches a given conversion (no quality cuts applied)
75  //matching is always attempted through the gsf track ref, and optionally attempted through the
76  //closest ctf track ref
77 
78  for (const auto& trkRef : conv.tracks() ){
79  if ( eleCore.gsfTrack().isNonnull() && eleCore.gsfTrack().id()==trkRef.id() &&
80  eleCore.gsfTrack().key()==trkRef.key()) return true;
81  else if ( allowCkfMatch && eleCore.ctfTrack().isNonnull() &&
82  eleCore.ctfTrack().id()==trkRef.id() &&
83  eleCore.ctfTrack().key()==trkRef.key() ) return true;
84  }
85 
86  return false;
87 }
88 
89 
90 //--------------------------------------------------------------------------------------------------
92 
93  //check if a given SuperCluster matches a given conversion (no quality cuts applied)
94  //matching is geometric between conversion momentum and vector joining conversion vertex
95  //to supercluster position
96 
97 
99 
100  const math::XYZPoint& scpos(sc.position());
102 
103 
104  math::XYZVector cscvector = scpos - cvtx;
105  float dR = reco::deltaR(mom,cscvector);
106  float dEta = mom.eta() - cscvector.eta();
107  float dPhi = reco::deltaPhi(mom.phi(),cscvector.phi());
108 
109  if (dR>dRMax) return false;
110  if (dEta>dEtaMax) return false;
111  if (dPhi>dPhiMax) return false;
112 
113  return true;
114 
115 }
116 
117 
118 //--------------------------------------------------------------------------------------------------
120 {
121 
122  //check if given track matches given conversion (matching by ref)
123 
124  if (trk.isNull()) return false;
125 
126  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
127  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
128  if (trk.id()==it->id() && trk.key()==it->key()) return true;
129  }
130 
131  return false;
132 }
133 
134 //--------------------------------------------------------------------------------------------------
136 {
137 
138  //check if given track matches given conversion (matching by ref)
139 
140  if (trk.isNull()) return false;
141 
142  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
143  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
144  if (trk.id()==it->id() && trk.key()==it->key()) return true;
145  }
146 
147  return false;
148 }
149 
150 //--------------------------------------------------------------------------------------------------
152 {
153 
154  //check if given track matches given conversion (matching by ref)
155 
156  if (trk.isNull()) return false;
157 
158  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
159  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
160  if (trk.id()==it->id() && trk.key()==it->key()) return true;
161  }
162 
163  return false;
164 }
165 
166 
167 //--------------------------------------------------------------------------------------------------
169  const reco::ConversionCollection &convCol,
170  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
171 {
172  //check if a given electron candidate matches to at least one conversion candidate in the
173  //collection which also passes the selection cuts, optionally match with the closestckf track in
174  //in addition to just the gsf track (enabled in default arguments)
175 
176  for(auto const& it : convCol) {
177  if (!matchesConversion(ele, it, allowCkfMatch)) continue;
178  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
179 
180  return true;
181  }
182 
183  return false;
184 
185 }
186 
187 //--------------------------------------------------------------------------------------------------
189  const reco::ConversionCollection &convCol,
190  const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
191 {
192  //check if a given track matches to at least one conversion candidate in the
193  //collection which also passes the selection cuts
194 
195  if (trk.isNull()) return false;
196 
197  for(auto const& it : convCol) {
198  if (!matchesConversion(trk, it)) continue;
199  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
200 
201  return true;
202  }
203 
204  return false;
205 
206 }
207 
208 //--------------------------------------------------------------------------------------------------
210  const reco::ConversionCollection &convCol,
211  const math::XYZPoint &beamspot, float dRMax, float dEtaMax, float dPhiMax, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
212 {
213 
214  //check if a given SuperCluster matches to at least one conversion candidate in the
215  //collection which also passes the selection cuts
216 
217  for(auto const& it : convCol) {
218  if (!matchesConversion(sc, it)) continue;
219  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
220 
221  return true;
222  }
223 
224  return false;
225 
226 }
227 
228 
229 //--------------------------------------------------------------------------------------------------
231  const reco::ConversionCollection &convCol,
232  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
233 {
234  //check if a given electron candidate matches to at least one conversion candidate in the
235  //collection which also passes the selection cuts, optionally match with the closestckf track in
236  //in addition to just the gsf track (enabled in default arguments)
237  //If multiple conversions are found, returned reference corresponds to minimum
238  //conversion radius
239 
240  reco::Conversion const* match = nullptr;
241 
242  double minRho = 999.;
243  for(auto const& it : convCol) {
244  float rho = it.conversionVertex().position().rho();
245  if (rho>minRho) continue;
246  if (!matchesConversion(ele, it, allowCkfMatch)) continue;
247  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
248 
249  minRho = rho;
250  match = &it;
251  }
252 
253  return match;
254 
255 }
256 
257 //--------------------------------------------------------------------------------------------------
259  const reco::ConversionCollection &convCol,
260  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
261 {
262  //check if a given electron candidate matches to at least one conversion candidate in the
263  //collection which also passes the selection cuts, optionally match with the closestckf track in
264  //in addition to just the gsf track (enabled in default arguments)
265  //If multiple conversions are found, returned reference corresponds to minimum
266  //conversion radius
267 
268  reco::Conversion const* match = nullptr;
269 
270  double minRho = 999.;
271  for(auto const& it : convCol) {
272  float rho = it.conversionVertex().position().rho();
273  if (rho>minRho) continue;
274  if (!matchesConversion(eleCore, it, allowCkfMatch)) continue;
275  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
276 
277  minRho = rho;
278  match = &it;
279  }
280 
281  return match;
282 
283 }
284 
285 //--------------------------------------------------------------------------------------------------
287  const reco::ConversionCollection &convCol,
288  const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
289 {
290  //check if a given track matches to at least one conversion candidate in the
291  //collection which also passes the selection cuts
292  //If multiple conversions are found, returned reference corresponds to minimum
293  //conversion radius
294 
295  reco::Conversion const* match = nullptr;
296 
297  if (trk.isNull()) return match;
298 
299  double minRho = 999.;
300  for(auto const& it : convCol) {
301  float rho = it.conversionVertex().position().rho();
302  if (rho>minRho) continue;
303  if (!matchesConversion(trk, it)) continue;
304  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
305 
306  minRho = rho;
307  match = &it;
308  }
309 
310  return match;
311 
312 }
313 
314 //--------------------------------------------------------------------------------------------------
316  const reco::ConversionCollection &convCol,
317  const math::XYZPoint &beamspot, float dRMax, float dEtaMax, float dPhiMax, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
318 {
319 
320  //check if a given SuperCluster matches to at least one conversion candidate in the
321  //collection which also passes the selection cuts
322  //If multiple conversions are found, returned reference corresponds to minimum
323  //conversion radius
324 
325  reco::Conversion const* match = nullptr;
326 
327  double minRho = 999.;
328  for(auto const& it : convCol) {
329  float rho = it.conversionVertex().position().rho();
330  if (rho>minRho) continue;
331  if (!matchesConversion(sc, it, dRMax,dEtaMax,dPhiMax)) continue;
332  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
333 
334  minRho = rho;
335  match = &it;
336  }
337 
338  return match;
339 
340 }
341 
342 //--------------------------------------------------------------------------------------------------
344  const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
345 {
346 
347  return !(matchedPromptElectron(sc, eleCol, convCol, beamspot,
348  allowCkfMatch, lxyMin, probMin, nHitsBeforeVtxMax) == nullptr);
349 }
350 
351 
352 //--------------------------------------------------------------------------------------------------
354  const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
355 {
356 
357  //check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
358  //and not matching any conversion in the collection passing the quality cuts
359 
360  reco::GsfElectron const* match = nullptr;
361 
362  if (sc.isNull()) return match;
363 
364  for(auto const& it : eleCol) {
365  //match electron to supercluster
366  if (it.superCluster()!=sc) continue;
367 
368  //check expected inner hits
369  if (it.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > 0) continue;
370 
371  //check if electron is matching to a conversion
372  if (hasMatchedConversion(it,convCol,beamspot,allowCkfMatch,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
373 
374 
375  match = &it;
376  }
377 
378  return match;
379 
380 
381 }
382 
383 //--------------------------------------------------------------------------------------------------
385 {
386  if (conv!=nullptr) {
387  const reco::Vertex& vtx = conv->conversionVertex();
388  if( vtx.isValid() ) {
389  return TMath::Prob(vtx.chi2(),vtx.ndof()) ;
390  }
391  }
392  return -1;
393 }
const reco::Vertex & conversionVertex() const
returns the reco conversion vertex
Definition: Conversion.h:98
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:22
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:131
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true, bool allowAmbiguousGsfMatch=false)
static reco::Conversion const * 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)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:251
GsfTrackRefVector::const_iterator ambiguousGsfTracksBegin() const
Definition: GsfElectron.h:723
static HepMC::IO_HEPEVT conv
double y() const
y coordinate
Definition: Vertex.h:113
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:68
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)
const GsfTrackRef & gsfTrack() const
key_type key() const
Accessor for product key.
Definition: Ref.h:263
const Point & position() const
position
Definition: Vertex.h:109
std::vector< GsfElectron > GsfElectronCollection
collection of GsfElectron objects
ProductID id() const
Definition: RefToBase.h:242
math::XYZVectorF refittedPairMomentum() const
Conversion tracks momentum from the tracks refitted with vertex constraint.
Definition: Conversion.cc:248
std::vector< Conversion > ConversionCollection
collectin of Conversion objects
Definition: ConversionFwd.h:9
ProductID id() const
Accessor for product ID.
Definition: Ref.h:257
GsfTrackRefVector::const_iterator ambiguousGsfTracksEnd() const
Definition: GsfElectron.h:724
static float getVtxFitProb(const reco::Conversion *conv)
size_t key() const
Definition: RefToBase.h:250
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)
double chi2() const
chi-squares
Definition: Vertex.h:98
static reco::GsfElectron const * 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)
bool isNull() const
Checks for null.
Definition: Ref.h:248
static bool isGoodConversion(const reco::Conversion &conv, const math::XYZPoint &beamspot, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=1)
double ndof() const
Definition: Vertex.h:105
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
double x() const
x coordinate
Definition: Vertex.h:111
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:12
bool isNull() const
Checks for null.
Definition: RefToBase.h:331
fixed size matrix
HLT enums.
TrackRef ctfTrack() const
const std::vector< uint8_t > & nHitsBeforeVtx() const
Vector of the number of hits before the vertex along each track trajector.
Definition: Conversion.h:162
ProductIndex id() const
Definition: ProductID.h:38
std::vector< edm::RefToBase< reco::Track > > const & tracks() const
vector of track to base references
Definition: Conversion.cc:176
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName)