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