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 //--------------------------------------------------------------------------------------------------
72 
73  //check if a given SuperCluster matches a given conversion (no quality cuts applied)
74  //matching is geometric between conversion momentum and vector joining conversion vertex
75  //to supercluster position
76 
77 
79 
80  const math::XYZPoint& scpos(sc.position());
82 
83 
84  math::XYZVector cscvector = scpos - cvtx;
85  float dR = reco::deltaR(mom,cscvector);
86  float dEta = mom.eta() - cscvector.eta();
87  float dPhi = reco::deltaPhi(mom.phi(),cscvector.phi());
88 
89  if (dR>dRMax) return false;
90  if (dEta>dEtaMax) return false;
91  if (dPhi>dPhiMax) return false;
92 
93  return true;
94 
95 }
96 
97 
98 //--------------------------------------------------------------------------------------------------
100 {
101 
102  //check if given track matches given conversion (matching by ref)
103 
104  if (trk.isNull()) return false;
105 
106  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
107  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
108  if (trk.id()==it->id() && trk.key()==it->key()) return true;
109  }
110 
111  return false;
112 }
113 
114 //--------------------------------------------------------------------------------------------------
116 {
117 
118  //check if given track matches given conversion (matching by ref)
119 
120  if (trk.isNull()) return false;
121 
122  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
123  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
124  if (trk.id()==it->id() && trk.key()==it->key()) return true;
125  }
126 
127  return false;
128 }
129 
130 //--------------------------------------------------------------------------------------------------
132 {
133 
134  //check if given track matches given conversion (matching by ref)
135 
136  if (trk.isNull()) 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(); ++it) {
140  if (trk.id()==it->id() && trk.key()==it->key()) return true;
141  }
142 
143  return false;
144 }
145 
146 
147 //--------------------------------------------------------------------------------------------------
149  const reco::ConversionCollection &convCol,
150  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
151 {
152  //check if a given electron candidate matches to at least one conversion candidate in the
153  //collection which also passes the selection cuts, optionally match with the closestckf track in
154  //in addition to just the gsf track (enabled in default arguments)
155 
156  for(auto const& it : convCol) {
157  if (!matchesConversion(ele, it, allowCkfMatch)) continue;
158  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
159 
160  return true;
161  }
162 
163  return false;
164 
165 }
166 
167 //--------------------------------------------------------------------------------------------------
169  const reco::ConversionCollection &convCol,
170  const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
171 {
172  //check if a given track matches to at least one conversion candidate in the
173  //collection which also passes the selection cuts
174 
175  if (trk.isNull()) return false;
176 
177  for(auto const& it : convCol) {
178  if (!matchesConversion(trk, it)) continue;
179  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
180 
181  return true;
182  }
183 
184  return false;
185 
186 }
187 
188 //--------------------------------------------------------------------------------------------------
190  const reco::ConversionCollection &convCol,
191  const math::XYZPoint &beamspot, float dRMax, float dEtaMax, float dPhiMax, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
192 {
193 
194  //check if a given SuperCluster matches to at least one conversion candidate in the
195  //collection which also passes the selection cuts
196 
197  for(auto const& it : convCol) {
198  if (!matchesConversion(sc, it)) continue;
199  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
200 
201  return true;
202  }
203 
204  return false;
205 
206 }
207 
208 
209 //--------------------------------------------------------------------------------------------------
211  const reco::ConversionCollection &convCol,
212  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
213 {
214  //check if a given electron candidate matches to at least one conversion candidate in the
215  //collection which also passes the selection cuts, optionally match with the closestckf track in
216  //in addition to just the gsf track (enabled in default arguments)
217  //If multiple conversions are found, returned reference corresponds to minimum
218  //conversion radius
219 
220  reco::Conversion const* match = nullptr;
221 
222  double minRho = 999.;
223  for(auto const& it : convCol) {
224  float rho = it.conversionVertex().position().rho();
225  if (rho>minRho) continue;
226  if (!matchesConversion(ele, it, allowCkfMatch)) continue;
227  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
228 
229  minRho = rho;
230  match = &it;
231  }
232 
233  return match;
234 
235 }
236 
237 //--------------------------------------------------------------------------------------------------
239  const reco::ConversionCollection &convCol,
240  const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
241 {
242  //check if a given track matches to at least one conversion candidate in the
243  //collection which also passes the selection cuts
244  //If multiple conversions are found, returned reference corresponds to minimum
245  //conversion radius
246 
247  reco::Conversion const* match = nullptr;
248 
249  if (trk.isNull()) return match;
250 
251  double minRho = 999.;
252  for(auto const& it : convCol) {
253  float rho = it.conversionVertex().position().rho();
254  if (rho>minRho) continue;
255  if (!matchesConversion(trk, it)) continue;
256  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
257 
258  minRho = rho;
259  match = &it;
260  }
261 
262  return match;
263 
264 }
265 
266 //--------------------------------------------------------------------------------------------------
268  const reco::ConversionCollection &convCol,
269  const math::XYZPoint &beamspot, float dRMax, float dEtaMax, float dPhiMax, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
270 {
271 
272  //check if a given SuperCluster matches to at least one conversion candidate in the
273  //collection which also passes the selection cuts
274  //If multiple conversions are found, returned reference corresponds to minimum
275  //conversion radius
276 
277  reco::Conversion const* match = nullptr;
278 
279  double minRho = 999.;
280  for(auto const& it : convCol) {
281  float rho = it.conversionVertex().position().rho();
282  if (rho>minRho) continue;
283  if (!matchesConversion(sc, it, dRMax,dEtaMax,dPhiMax)) continue;
284  if (!isGoodConversion(it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
285 
286  minRho = rho;
287  match = &it;
288  }
289 
290  return match;
291 
292 }
293 
294 //--------------------------------------------------------------------------------------------------
296  const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
297 {
298 
299  return !(matchedPromptElectron(sc, eleCol, convCol, beamspot,
300  allowCkfMatch, lxyMin, probMin, nHitsBeforeVtxMax) == nullptr);
301 }
302 
303 
304 //--------------------------------------------------------------------------------------------------
306  const reco::ConversionCollection &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
307 {
308 
309  //check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
310  //and not matching any conversion in the collection passing the quality cuts
311 
312  reco::GsfElectron const* match = nullptr;
313 
314  if (sc.isNull()) return match;
315 
316  for(auto const& it : eleCol) {
317  //match electron to supercluster
318  if (it.superCluster()!=sc) continue;
319 
320  //check expected inner hits
321  if (it.gsfTrack()->hitPattern().numberOfLostHits(reco::HitPattern::MISSING_INNER_HITS) > 0) continue;
322 
323  //check if electron is matching to a conversion
324  if (hasMatchedConversion(it,convCol,beamspot,allowCkfMatch,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
325 
326 
327  match = &it;
328  }
329 
330  return match;
331 
332 
333 }
const reco::Vertex & conversionVertex() const
returns the reco conversion vertex
Definition: Conversion.h:97
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)
GsfTrackRefVector::const_iterator ambiguousGsfTracksBegin() const
Definition: GsfElectron.h:713
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)
key_type key() const
Accessor for product key.
Definition: Ref.h:265
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:259
GsfTrackRefVector::const_iterator ambiguousGsfTracksEnd() const
Definition: GsfElectron.h:714
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:250
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.
const std::vector< uint8_t > & nHitsBeforeVtx() const
Vector of the number of hits before the vertex along each track trajector.
Definition: Conversion.h:161
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)