CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConversionTools.cc
Go to the documentation of this file.
1 // $Id: ConversionTools.cc,v 1.3 2011/05/10 19:27:22 eulisse Exp $
2 
3 #include <TMath.h>
13 
14 using namespace edm;
15 using namespace reco;
16 
17 
18 //--------------------------------------------------------------------------------------------------
19 bool ConversionTools::isGoodConversion(const Conversion &conv, const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
20 {
21 
22  //Check if a given conversion candidate passes the conversion selection cuts
23 
24  const reco::Vertex &vtx = conv.conversionVertex();
25 
26  //vertex validity
27  if (!vtx.isValid()) return false;
28 
29  //fit probability
30  if (TMath::Prob( vtx.chi2(), vtx.ndof() )<probMin) return false;
31 
32  //compute transverse decay length
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(); ++it) {
44  if ( (*it)>nHitsBeforeVtxMax ) return false;
45  }
46 
47  return true;
48 }
49 
50 //--------------------------------------------------------------------------------------------------
51 bool ConversionTools::matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch)
52 {
53 
54  //check if a given GsfElectron matches a given conversion (no quality cuts applied)
55  //matching is always attempted through the gsf track ref, and optionally attempted through the
56  //closest ctf track ref
57 
58  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
59  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
60  if ( ele.gsfTrack().isNonnull() && ele.gsfTrack().id()==it->id() && ele.gsfTrack().key()==it->key()) return true;
61  else if ( allowCkfMatch && ele.closestCtfTrackRef().isNonnull() && ele.closestCtfTrackRef().id()==it->id() && ele.closestCtfTrackRef().key()==it->key() ) return true;
62  }
63 
64  return false;
65 }
66 
67 //--------------------------------------------------------------------------------------------------
68 bool ConversionTools::matchesConversion(const reco::SuperCluster &sc, const reco::Conversion &conv, float dRMax, float dEtaMax, float dPhiMax) {
69 
70  //check if a given SuperCluster matches a given conversion (no quality cuts applied)
71  //matching is geometric between conversion momentum and vector joining conversion vertex
72  //to supercluster position
73 
74 
76 
77  math::XYZPoint scpos(sc.position());
79 
80 
81  math::XYZVector cscvector = scpos - cvtx;
82  float dR = reco::deltaR(mom,cscvector);
83  float dEta = mom.eta() - cscvector.eta();
84  float dPhi = reco::deltaPhi(mom.phi(),cscvector.phi());
85 
86  if (dR>dRMax) return false;
87  if (dEta>dEtaMax) return false;
88  if (dPhi>dPhiMax) return false;
89 
90  return true;
91 
92 }
93 
94 
95 //--------------------------------------------------------------------------------------------------
97 {
98 
99  //check if given track matches given conversion (matching by ref)
100 
101  if (trk.isNull()) return false;
102 
103  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
104  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
105  if (trk.id()==it->id() && trk.key()==it->key()) return true;
106  }
107 
108  return false;
109 }
110 
111 //--------------------------------------------------------------------------------------------------
113 {
114 
115  //check if given track matches given conversion (matching by ref)
116 
117  if (trk.isNull()) return false;
118 
119  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
120  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
121  if (trk.id()==it->id() && trk.key()==it->key()) return true;
122  }
123 
124  return false;
125 }
126 
127 //--------------------------------------------------------------------------------------------------
129 {
130 
131  //check if given track matches given conversion (matching by ref)
132 
133  if (trk.isNull()) return false;
134 
135  const std::vector<edm::RefToBase<reco::Track> > &convTracks = conv.tracks();
136  for (std::vector<edm::RefToBase<reco::Track> >::const_iterator it=convTracks.begin(); it!=convTracks.end(); ++it) {
137  if (trk.id()==it->id() && trk.key()==it->key()) return true;
138  }
139 
140  return false;
141 }
142 
143 
144 //--------------------------------------------------------------------------------------------------
147  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
148 {
149  //check if a given electron candidate matches to at least one conversion candidate in the
150  //collection which also passes the selection cuts, optionally match with the closestckf track in
151  //in addition to just the gsf track (enabled in default arguments)
152 
153  for (ConversionCollection::const_iterator it = convCol->begin(); it!=convCol->end(); ++it) {
154  if (!matchesConversion(ele, *it, allowCkfMatch)) continue;
155  if (!isGoodConversion(*it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
156 
157  return true;
158  }
159 
160  return false;
161 
162 }
163 
164 //--------------------------------------------------------------------------------------------------
167  const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
168 {
169  //check if a given track matches to at least one conversion candidate in the
170  //collection which also passes the selection cuts
171 
172  if (trk.isNull()) return false;
173 
174  for (ConversionCollection::const_iterator it = convCol->begin(); it!=convCol->end(); ++it) {
175  if (!matchesConversion(trk, *it)) continue;
176  if (!isGoodConversion(*it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
177 
178  return true;
179  }
180 
181  return false;
182 
183 }
184 
185 //--------------------------------------------------------------------------------------------------
188  const math::XYZPoint &beamspot, float dRMax, float dEtaMax, float dPhiMax, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
189 {
190 
191  //check if a given SuperCluster matches to at least one conversion candidate in the
192  //collection which also passes the selection cuts
193 
194  for (ConversionCollection::const_iterator it = convCol->begin(); it!=convCol->end(); ++it) {
195  if (!matchesConversion(sc, *it)) continue;
196  if (!isGoodConversion(*it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
197 
198  return true;
199  }
200 
201  return false;
202 
203 }
204 
205 
206 //--------------------------------------------------------------------------------------------------
209  const math::XYZPoint &beamspot, bool allowCkfMatch, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
210 {
211  //check if a given electron candidate matches to at least one conversion candidate in the
212  //collection which also passes the selection cuts, optionally match with the closestckf track in
213  //in addition to just the gsf track (enabled in default arguments)
214  //If multiple conversions are found, returned reference corresponds to minimum
215  //conversion radius
216 
218 
219  double minRho = 999.;
220  for (ConversionCollection::const_iterator it = convCol->begin(); it!=convCol->end(); ++it) {
221  float rho = it->conversionVertex().position().rho();
222  if (rho>minRho) continue;
223  if (!matchesConversion(ele, *it, allowCkfMatch)) continue;
224  if (!isGoodConversion(*it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
225 
226  minRho = rho;
227  match = ConversionRef(convCol,it-convCol->begin());
228  }
229 
230  return match;
231 
232 }
233 
234 //--------------------------------------------------------------------------------------------------
237  const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
238 {
239  //check if a given track matches to at least one conversion candidate in the
240  //collection which also passes the selection cuts
241  //If multiple conversions are found, returned reference corresponds to minimum
242  //conversion radius
243 
245 
246  if (trk.isNull()) return match;
247 
248  double minRho = 999.;
249  for (ConversionCollection::const_iterator it = convCol->begin(); it!=convCol->end(); ++it) {
250  float rho = it->conversionVertex().position().rho();
251  if (rho>minRho) continue;
252  if (!matchesConversion(trk, *it)) continue;
253  if (!isGoodConversion(*it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
254 
255  minRho = rho;
256  match = ConversionRef(convCol,it-convCol->begin());
257  }
258 
259  return match;
260 
261 }
262 
263 //--------------------------------------------------------------------------------------------------
266  const math::XYZPoint &beamspot, float dRMax, float dEtaMax, float dPhiMax, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
267 {
268 
269  //check if a given SuperCluster matches to at least one conversion candidate in the
270  //collection which also passes the selection cuts
271  //If multiple conversions are found, returned reference corresponds to minimum
272  //conversion radius
273 
275 
276  double minRho = 999.;
277  for (ConversionCollection::const_iterator it = convCol->begin(); it!=convCol->end(); ++it) {
278  float rho = it->conversionVertex().position().rho();
279  if (rho>minRho) continue;
280  if (!matchesConversion(sc, *it, dRMax,dEtaMax,dPhiMax)) continue;
281  if (!isGoodConversion(*it,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
282 
283  minRho = rho;
284  match = ConversionRef(convCol,it-convCol->begin());
285  }
286 
287  return match;
288 
289 }
290 
291 //--------------------------------------------------------------------------------------------------
293  const edm::Handle<reco::ConversionCollection> &convCol, const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
294 {
295 
296  //check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
297  //and not matching any conversion in the collection passing the quality cuts
298 
299  if (sc.isNull()) return false;
300 
301  for (GsfElectronCollection::const_iterator it = eleCol->begin(); it!=eleCol->end(); ++it) {
302  //match electron to supercluster
303  if (it->superCluster()!=sc) continue;
304 
305  //check expected inner hits
306  if (it->gsfTrack()->trackerExpectedHitsInner().numberOfHits()>0) continue;
307 
308  //check if electron is matching to a conversion
309  if (hasMatchedConversion(*it,convCol,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
310 
311 
312  return true;
313  }
314 
315  return false;
316 
317 
318 }
319 
320 
321 //--------------------------------------------------------------------------------------------------
323  const edm::Handle<reco::ConversionCollection> &convCol, const math::XYZPoint &beamspot, float lxyMin, float probMin, unsigned int nHitsBeforeVtxMax)
324 {
325 
326  //check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
327  //and not matching any conversion in the collection passing the quality cuts
328 
330 
331  if (sc.isNull()) return match;
332 
333  for (GsfElectronCollection::const_iterator it = eleCol->begin(); it!=eleCol->end(); ++it) {
334  //match electron to supercluster
335  if (it->superCluster()!=sc) continue;
336 
337  //check expected inner hits
338  if (it->gsfTrack()->trackerExpectedHitsInner().numberOfHits()>0) continue;
339 
340  //check if electron is matching to a conversion
341  if (hasMatchedConversion(*it,convCol,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
342 
343 
344  match = GsfElectronRef(eleCol,it-eleCol->begin());
345  }
346 
347  return match;
348 
349 
350 }
const reco::Vertex & conversionVertex() const
returns the reco conversion vertex
Definition: Conversion.h:101
tuple convTracks
Definition: convBrem_cff.py:35
const math::XYZPoint & position() const
cluster centroid position
Definition: CaloCluster.h:123
static HepMC::IO_HEPEVT conv
double y() const
y coordinate
Definition: Vertex.h:97
bool isValid() const
Tells whether the vertex is valid.
Definition: Vertex.h:61
Definition: DDAxes.h:10
static bool hasMatchedPromptElectron(const reco::SuperClusterRef &sc, const edm::Handle< reco::GsfElectronCollection > &eleCol, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
bool isNull() const
Checks for null.
Definition: RefToBase.h:270
std::string match(BranchDescription const &a, BranchDescription const &b, std::string const &fileName, BranchDescription::MatchMode m)
ProductID id() const
Definition: RefToBase.h:220
const Point & position() const
position
Definition: Vertex.h:93
math::XYZVectorF refittedPairMomentum() const
Conversion tracks momentum from the tracks refitted with vertex constraint.
Definition: Conversion.cc:252
TrackRef closestCtfTrackRef() const
Definition: GsfElectron.h:185
std::vector< edm::RefToBase< reco::Track > > tracks() const
vector of track to base references
Definition: Conversion.cc:170
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
bool isNull() const
Checks for null.
Definition: Ref.h:247
double dPhi(double phi1, double phi2)
Definition: JetUtil.h:30
double chi2() const
chi-squares
Definition: Vertex.h:82
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
size_t key() const
Definition: RefToBase.h:228
static bool hasMatchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
static bool isGoodConversion(const reco::Conversion &conv, const math::XYZPoint &beamspot, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=1)
edm::Ref< GsfElectronCollection > GsfElectronRef
reference to an object in a collection of GsfElectron objects
double ndof() const
Definition: Vertex.h:89
static reco::GsfElectronRef matchedPromptElectron(const reco::SuperClusterRef &sc, const edm::Handle< reco::GsfElectronCollection > &eleCol, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:12
double x() const
x coordinate
Definition: Vertex.h:95
static bool matchesConversion(const reco::GsfElectron &ele, const reco::Conversion &conv, bool allowCkfMatch=true)
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:31
XYZPointD XYZPoint
point in space with cartesian internal representation
Definition: Point3D.h:13
key_type key() const
Accessor for product key.
Definition: Ref.h:266
const std::vector< uint8_t > & nHitsBeforeVtx() const
Vector of the number of hits before the vertex along each track trajector.
Definition: Conversion.h:165
edm::Ref< ConversionCollection > ConversionRef
reference to an object in a collection of Conversion objects
Definition: ConversionFwd.h:15
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
ProductIndex id() const
Definition: ProductID.h:38
static reco::ConversionRef matchedConversion(const reco::GsfElectron &ele, const edm::Handle< reco::ConversionCollection > &convCol, const math::XYZPoint &beamspot, bool allowCkfMatch=true, float lxyMin=2.0, float probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
virtual GsfTrackRef gsfTrack() const
reference to a GsfTrack
Definition: GsfElectron.h:169