CMS 3D CMS Logo

EgammaHLTTrackIsolation.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: EgammaHLTAlgos
4 // Class : EgammaHLTTrackIsolation
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Monica Vazquez Acosta
10 // Created: Tue Jun 13 12:17:19 CEST 2006
11 //
12 
13 // system include files
14 
15 // user include files
17 
18 std::pair<int, float> EgammaHLTTrackIsolation::electronIsolation(const reco::Track* const tr,
19  const reco::TrackCollection* isoTracks) {
20  GlobalPoint vtx(0, 0, tr->vertex().z());
21  const reco::Track::Vector& p = tr->momentum();
22  GlobalVector mom(p.x(), p.y(), p.z());
23  return findIsoTracks(mom, vtx, isoTracks, true);
24 }
25 
26 std::pair<int, float> EgammaHLTTrackIsolation::electronIsolation(const reco::Track* const tr,
27  const reco::TrackCollection* isoTracks,
28  GlobalPoint zvtx) {
29  // Just to insure consistency with no-vertex-code
30  GlobalPoint vtx(0, 0, zvtx.z());
31  const reco::Track::Vector& p = tr->momentum();
32  GlobalVector mom(p.x(), p.y(), p.z());
33  return findIsoTracks(mom, vtx, isoTracks, true);
34 }
35 
36 std::pair<int, float> EgammaHLTTrackIsolation::electronIsolation(const reco::Track* const tr,
37  const reco::ElectronCollection* allEle,
38  const reco::TrackCollection* isoTracks) {
39  GlobalPoint vtx(0, 0, tr->vertex().z());
40  const reco::Track::Vector& p = tr->momentum();
41  GlobalVector mom(p.x(), p.y(), p.z());
42  return findIsoTracksWithoutEle(mom, vtx, allEle, isoTracks);
43 }
44 
45 std::pair<int, float> EgammaHLTTrackIsolation::photonIsolation(const reco::RecoCandidate* const recocandidate,
46  const reco::TrackCollection* isoTracks,
47  bool useVertex) {
48  if (useVertex) {
49  GlobalPoint vtx(0, 0, recocandidate->vertex().z());
50  return photonIsolation(recocandidate, isoTracks, vtx);
51  } else {
52  reco::RecoCandidate::Point pos = recocandidate->superCluster()->position();
53  GlobalVector mom(pos.x(), pos.y(), pos.z());
54  return findIsoTracks(mom, GlobalPoint(), isoTracks, false, false);
55  }
56 }
57 
58 std::pair<int, float> EgammaHLTTrackIsolation::photonIsolation(const reco::RecoCandidate* const recocandidate,
59  const reco::TrackCollection* isoTracks,
60  GlobalPoint zvtx) {
61  // to insure consistency with no-free-vertex-code
62  GlobalPoint vtx(0, 0, zvtx.z());
63 
64  reco::RecoCandidate::Point pos = recocandidate->superCluster()->position();
65  GlobalVector mom(pos.x() - vtx.x(), pos.y() - vtx.y(), pos.z() - vtx.z());
66 
67  return findIsoTracks(mom, vtx, isoTracks, false);
68 }
69 
70 std::pair<int, float> EgammaHLTTrackIsolation::photonIsolation(const reco::RecoCandidate* const recocandidate,
71  const reco::ElectronCollection* allEle,
72  const reco::TrackCollection* isoTracks) {
73  reco::RecoCandidate::Point pos = recocandidate->superCluster()->position();
74  GlobalVector mom(pos.x(), pos.y(), pos.z());
75  return findIsoTracksWithoutEle(mom, GlobalPoint(), allEle, isoTracks);
76 }
77 
79  GlobalVector mom, GlobalPoint vtx, const reco::TrackCollection* isoTracks, bool isElectron, bool useVertex) {
80  // Check that reconstructed tracks fit within cone boundaries,
81  // (Note: tracks will not always stay within boundaries)
82  int ntrack = 0;
83  float ptSum = 0.;
84 
85  for (reco::TrackCollection::const_iterator trItr = isoTracks->begin(); trItr != isoTracks->end(); ++trItr) {
86  GlobalPoint ivtx(trItr->vertex().x(), trItr->vertex().y(), trItr->vertex().z());
87  reco::Track::Vector ip = trItr->momentum();
88  GlobalVector imom(ip.x(), ip.y(), ip.z());
89 
90  float pt = imom.perp();
91  float dperp = 0.;
92  float dz = 0.;
93  float deta = 0.;
94  float dphi = 0.;
95  if (useVertex) {
96  dperp = ivtx.perp() - vtx.perp();
97  dz = ivtx.z() - vtx.z();
98  deta = imom.eta() - mom.eta();
99  dphi = imom.phi() - mom.phi();
100  } else {
101  //in case of unkown photon vertex, modify direction of photon to point from
102  //current track vertex to sc instead of from (0.,0.,0.) to sc. In this
103  //way, all tracks are considered based on direction alone.
104  GlobalVector mom_temp = mom - GlobalVector(ivtx.x(), ivtx.y(), ivtx.z());
105  deta = imom.eta() - mom_temp.eta();
106  dphi = imom.phi() - mom_temp.phi();
107  }
108  // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
109  if (dphi > M_PI)
110  dphi = dphi - 2 * M_PI;
111  else if (dphi < -M_PI)
112  dphi = dphi + 2 * M_PI;
113 
114  float R = sqrt(dphi * dphi + deta * deta);
115 
116  // Apply boundary cut
117  // bool selected=false;
118 
119  // if (pt > ptMin && R < conesize &&
120  // fabs(dperp) < rspan && fabs(dz) < zspan) selected=true;
121 
122  // if (selected) {
123  // ntrack++;
124  // if (!isElectron || R > vetoConesize) ptSum+=pt; //to exclude electron track
125  // }
126  // float theVetoVar = R;
127  // if (isElectron) theVetoVar = R;
128 
129  //hmm how do I figure out if this is barrel or endcap?
130  //abs(mom.eta())<1.5 is the obvious choice but that will be electron not detector eta for electrons
131  //well lets leave it as that for now, its what reco does (well with eta=1.479)
132  double innerStrip = fabs(mom.eta()) < 1.479 ? stripBarrel : stripEndcap;
133 
134  if (pt > ptMin && R < conesize && R > vetoConesize && fabs(dperp) < rspan && fabs(dz) < zspan &&
135  fabs(deta) >= innerStrip) {
136  ntrack++;
137  ptSum += pt;
138  }
139  }
140 
141  // if (isElectron) ntrack-=1; //to exclude electron track
142 
143  return (std::pair<int, float>(ntrack, ptSum));
144 }
145 
148  const reco::ElectronCollection* allEle,
149  const reco::TrackCollection* isoTracks) {
150  // Check that reconstructed tracks fit within cone boundaries,
151  // (Note: tracks will not always stay within boundaries)
152  int ntrack = 0;
153  float ptSum = 0.;
154  std::vector<float> etaele;
155  std::vector<float> phiele;
156 
157  // std::cout << "allEle.size() = " << allEle->size() << std::endl;
158 
159  // Store ALL electrons eta and phi
160  for (reco::ElectronCollection::const_iterator iElectron = allEle->begin(); iElectron != allEle->end(); iElectron++) {
161  reco::TrackRef anothereletrackref = iElectron->track();
162  etaele.push_back(anothereletrackref->momentum().eta());
163  phiele.push_back(anothereletrackref->momentum().phi());
164  }
165 
166  for (reco::TrackCollection::const_iterator trItr = isoTracks->begin(); trItr != isoTracks->end(); ++trItr) {
167  GlobalPoint ivtx(trItr->vertex().x(), trItr->vertex().y(), trItr->vertex().z());
168  reco::Track::Vector ip = trItr->momentum();
169  GlobalVector imom(ip.x(), ip.y(), ip.z());
170 
171  float pt = imom.perp();
172  float dperp = ivtx.perp() - vtx.perp();
173  float dz = ivtx.z() - vtx.z();
174  float deta = imom.eta() - mom.eta();
175  float dphi = imom.phi() - mom.phi();
176 
177  // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
178  if (dphi > M_PI)
179  dphi = dphi - 2 * M_PI;
180  else if (dphi < -M_PI)
181  dphi = dphi + 2 * M_PI;
182 
183  float R = sqrt(dphi * dphi + deta * deta);
184 
185  // Apply boundary cut
186  bool selected = false;
187  bool passedconeveto = true;
188 
189  //hmm how do I figure out if this is barrel or endcap?
190  //abs(mom.eta())<1.5 is the obvious choice but that will be electron not detector eta for electrons
191  //well lets leave it as that for now, its what reco does (well with eta=1.479)
192  double innerStrip = fabs(mom.eta()) < 1.479 ? stripBarrel : stripEndcap;
193 
194  if (pt > ptMin && R < conesize && fabs(dperp) < rspan && fabs(dz) < zspan && fabs(deta) >= innerStrip)
195  selected = true;
196 
197  // Check that NO electron is counted in the isolation
198  for (unsigned int eleItr = 0; eleItr < etaele.size(); ++eleItr) {
199  deta = etaele[eleItr] - imom.eta();
200  dphi = phiele[eleItr] - imom.phi();
201 
202  // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
203  if (dphi > M_PI)
204  dphi = dphi - 2 * M_PI;
205  else if (dphi < -M_PI)
206  dphi = dphi + 2 * M_PI;
207 
208  R = sqrt(dphi * dphi + deta * deta);
209  if (R < vetoConesize)
210  passedconeveto = false;
211  }
212 
213  if (selected && passedconeveto) {
214  ntrack++;
215  ptSum += pt; //to exclude electron tracks
216  }
217  }
218 
219  // ntrack-=1; //to exclude electron track
220 
221  return (std::pair<int, float>(ntrack, ptSum));
222 }
T z() const
Definition: PV3DBase.h:61
std::pair< int, float > electronIsolation(const reco::Track *const tr, const reco::TrackCollection *isoTracks)
Get number of tracks and Pt sum of tracks inside an isolation cone for electrons. ...
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
T eta() const
Definition: PV3DBase.h:73
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:14
const Point & vertex() const override
vertex position (overwritten by PF...)
bool isElectron(const Candidate &part)
Definition: pdgIdUtils.h:7
T sqrt(T t)
Definition: SSEVec.h:19
const Point & vertex() const
reference point on the track. This method is DEPRECATED, please use referencePoint() instead ...
Definition: TrackBase.h:676
std::vector< Electron > ElectronCollection
collectin of Electron objects
Definition: ElectronFwd.h:9
std::pair< int, float > photonIsolation(const reco::RecoCandidate *const recocand, const reco::TrackCollection *isoTracks, bool useVertex)
#define M_PI
std::pair< int, float > findIsoTracks(GlobalVector mom, GlobalPoint vtx, const reco::TrackCollection *isoTracks, bool isElectron, bool useVertex=true)
const Vector & momentum() const
track momentum vector
Definition: TrackBase.h:664
virtual reco::SuperClusterRef superCluster() const
reference to a SuperCluster
std::pair< int, float > findIsoTracksWithoutEle(GlobalVector mom, GlobalPoint vtx, const reco::ElectronCollection *allEle, const reco::TrackCollection *isoTracks)
math::XYZPoint Point
point in the space
Definition: Candidate.h:40
#define ntrack
math::XYZVector Vector
spatial vector
Definition: TrackBase.h:77
Global3DVector GlobalVector
Definition: GlobalVector.h:10