CMS 3D CMS Logo

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