CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/RecoEgamma/EgammaHLTAlgos/src/EgammaHLTTrackIsolation.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     EgammaHLTAlgos
00004 // Class  :     EgammaHLTTrackIsolation
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Monica Vazquez Acosta
00010 //         Created:  Tue Jun 13 12:17:19 CEST 2006
00011 // $Id: EgammaHLTTrackIsolation.cc,v 1.6 2010/08/12 15:25:02 sharper Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "RecoEgamma/EgammaHLTAlgos/interface/EgammaHLTTrackIsolation.h"
00018 
00019 
00020 std::pair<int,float> EgammaHLTTrackIsolation::electronIsolation(const reco::Track * const tr, const reco::TrackCollection* isoTracks)
00021 {
00022   GlobalPoint vtx(0,0,tr->vertex().z());
00023   reco::Track::Vector p = tr->momentum();
00024   GlobalVector mom( p.x(), p.y(), p.z() );
00025   return findIsoTracks(mom,vtx,isoTracks,true);
00026 }
00027 
00028 
00029 std::pair<int,float> EgammaHLTTrackIsolation::electronIsolation(const reco::Track *  const tr, const reco::TrackCollection* isoTracks, GlobalPoint zvtx)
00030 { 
00031   // Just to insure consistency with no-vertex-code
00032   GlobalPoint vtx(0,0,zvtx.z());
00033   reco::Track::Vector p = tr->momentum();
00034   GlobalVector mom( p.x(), p.y(), p.z() );
00035   return findIsoTracks(mom,vtx,isoTracks,true);
00036 }
00037 
00038 std::pair<int,float> EgammaHLTTrackIsolation::electronIsolation(const reco::Track * const tr, const reco::ElectronCollection* allEle, const reco::TrackCollection* isoTracks)
00039 {
00040   GlobalPoint vtx(0,0,tr->vertex().z());
00041   reco::Track::Vector p = tr->momentum();
00042   GlobalVector mom( p.x(), p.y(), p.z() );
00043   return findIsoTracksWithoutEle(mom,vtx,allEle,isoTracks);
00044 }
00045 
00046 std::pair<int,float> EgammaHLTTrackIsolation::photonIsolation(const reco::RecoCandidate * const recocandidate, const reco::TrackCollection* isoTracks, bool useVertex)
00047 {
00048 
00049   if (useVertex) {
00050     GlobalPoint vtx(0,0,recocandidate->vertex().z());
00051     return photonIsolation(recocandidate,isoTracks,vtx);
00052   } else {
00053     reco::RecoCandidate::Point pos = recocandidate->superCluster()->position();
00054     GlobalVector mom(pos.x(),pos.y(),pos.z());
00055     return findIsoTracks(mom,GlobalPoint(),isoTracks,false,false);
00056   }
00057 
00058 }
00059 
00060 std::pair<int,float> EgammaHLTTrackIsolation::photonIsolation(const reco::RecoCandidate * const recocandidate, const reco::TrackCollection* isoTracks, GlobalPoint zvtx)
00061 {
00062 
00063   // to insure consistency with no-free-vertex-code
00064   GlobalPoint vtx(0,0,zvtx.z());
00065 
00066   reco::RecoCandidate::Point pos = recocandidate->superCluster()->position();
00067   GlobalVector mom(pos.x()-vtx.x(),pos.y()-vtx.y(),pos.z()-vtx.z());
00068 
00069   return findIsoTracks(mom,vtx,isoTracks,false);
00070 
00071 }
00072 
00073 
00074 std::pair<int,float> EgammaHLTTrackIsolation::photonIsolation(const reco::RecoCandidate * const recocandidate, const reco::ElectronCollection* allEle, const reco::TrackCollection* isoTracks)
00075 {
00076 
00077   reco::RecoCandidate::Point pos = recocandidate->superCluster()->position();
00078   GlobalVector mom(pos.x(),pos.y(),pos.z());
00079   return findIsoTracksWithoutEle(mom,GlobalPoint(),allEle,isoTracks);
00080 
00081 }
00082 
00083 std::pair<int,float> EgammaHLTTrackIsolation::findIsoTracks(GlobalVector mom, GlobalPoint vtx,  const reco::TrackCollection* isoTracks, bool isElectron, bool useVertex)
00084 {
00085 
00086   // Check that reconstructed tracks fit within cone boundaries,
00087   // (Note: tracks will not always stay within boundaries)
00088   int ntrack = 0;
00089   float ptSum = 0.;
00090 
00091   for(reco::TrackCollection::const_iterator trItr = isoTracks->begin(); trItr != isoTracks->end(); ++trItr){
00092 
00093     GlobalPoint ivtx(trItr->vertex().x(),trItr->vertex().y(),trItr->vertex().z());
00094     reco::Track::Vector ip = trItr->momentum();
00095     GlobalVector imom ( ip.x(), ip.y(), ip.z());
00096 
00097     float pt = imom.perp();
00098     float dperp = 0.;
00099     float dz = 0.;
00100     float deta = 0.;
00101     float dphi = 0.;
00102     if (useVertex) {
00103       dperp = ivtx.perp()-vtx.perp();
00104       dz = ivtx.z()-vtx.z();
00105       deta = imom.eta()-mom.eta();
00106       dphi = imom.phi()-mom.phi();
00107     } else {
00108       //in case of unkown photon vertex, modify direction of photon to point from
00109       //current track vertex to sc instead of from (0.,0.,0.) to sc.  In this 
00110       //way, all tracks are considered based on direction alone.
00111       GlobalVector mom_temp = mom - GlobalVector(ivtx.x(),ivtx.y(),ivtx.z());
00112       deta = imom.eta()-mom_temp.eta();
00113       dphi = imom.phi()-mom_temp.phi();
00114     }
00115     // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
00116     if (dphi>M_PI) dphi = dphi - 2*M_PI;
00117     else if (dphi<-M_PI) dphi = dphi + 2*M_PI;
00118 
00119     float R = sqrt( dphi*dphi + deta*deta );
00120 
00121     // Apply boundary cut
00122     // bool selected=false;
00123 
00124     // if (pt > ptMin && R < conesize &&
00125     //  fabs(dperp) < rspan && fabs(dz) < zspan) selected=true;
00126   
00127     // if (selected) {
00128     //  ntrack++;
00129     //  if (!isElectron || R > vetoConesize) ptSum+=pt; //to exclude electron track
00130     // }
00131     // float theVetoVar = R;
00132     // if (isElectron) theVetoVar = R;  
00133     
00134     //hmm how do I figure out if this is barrel or endcap?
00135     //abs(mom.eta())<1.5 is the obvious choice but that will be electron not detector eta for electrons
00136     //well lets leave it as that for now, its what reco does (well with eta=1.479)
00137     double innerStrip = fabs(mom.eta())<1.479 ? stripBarrel : stripEndcap;
00138     
00139     if (pt > ptMin && R < conesize && R > vetoConesize &&
00140         fabs(dperp) < rspan && fabs(dz) < zspan &&
00141         fabs(deta) >=innerStrip) {
00142       ntrack++;
00143       ptSum+=pt; 
00144     }
00145   }
00146 
00147   // if (isElectron) ntrack-=1; //to exclude electron track
00148 
00149   return (std::pair<int,float>(ntrack,ptSum));
00150 
00151 }
00152 
00153 std::pair<int,float> EgammaHLTTrackIsolation::findIsoTracksWithoutEle(GlobalVector mom, GlobalPoint vtx, const reco::ElectronCollection* allEle, const reco::TrackCollection* isoTracks)
00154 {
00155 
00156   // Check that reconstructed tracks fit within cone boundaries,
00157   // (Note: tracks will not always stay within boundaries)
00158   int iele = 0;
00159   int ntrack = 0;
00160   float ptSum = 0.;
00161   std::vector<float> etaele;
00162   std::vector<float> phiele;
00163 
00164   // std::cout << "allEle.size() = " << allEle->size() << std::endl;
00165 
00166   // Store ALL electrons eta and phi
00167   for (reco::ElectronCollection::const_iterator iElectron = allEle->begin(); iElectron != allEle->end(); iElectron++){
00168     iele++;
00169     reco::TrackRef anothereletrackref = iElectron->track();
00170     etaele.push_back(anothereletrackref->momentum().eta());
00171     phiele.push_back(anothereletrackref->momentum().phi());
00172     // std::cout << "Electron " << iele << ": phi = " << anothereletrackref->momentum().phi() << ", eta = " << anothereletrackref->momentum().eta() << std::endl; 
00173   }
00174   
00175   for(reco::TrackCollection::const_iterator trItr = isoTracks->begin(); trItr != isoTracks->end(); ++trItr){
00176 
00177     GlobalPoint ivtx(trItr->vertex().x(),trItr->vertex().y(),trItr->vertex().z());
00178     reco::Track::Vector ip = trItr->momentum();
00179     GlobalVector imom ( ip.x(), ip.y(), ip.z());
00180 
00181     float pt = imom.perp();
00182     float dperp = ivtx.perp()-vtx.perp();
00183     float dz = ivtx.z()-vtx.z();
00184     float deta = imom.eta()-mom.eta();
00185     float dphi = imom.phi()-mom.phi();
00186     
00187     // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
00188     if (dphi>M_PI) dphi = dphi - 2*M_PI;
00189     else if (dphi<-M_PI) dphi = dphi + 2*M_PI;
00190 
00191     float R = sqrt( dphi*dphi + deta*deta );
00192 
00193     // Apply boundary cut
00194     bool selected=false;
00195     bool passedconeveto=true;
00196 
00197     //hmm how do I figure out if this is barrel or endcap?
00198     //abs(mom.eta())<1.5 is the obvious choice but that will be electron not detector eta for electrons
00199     //well lets leave it as that for now, its what reco does (well with eta=1.479)
00200     double innerStrip = fabs(mom.eta())<1.479 ? stripBarrel : stripEndcap;
00201 
00202     if (pt > ptMin && R < conesize &&
00203         fabs(dperp) < rspan && fabs(dz) < zspan && 
00204         fabs(deta) >=innerStrip) selected=true;
00205   
00206     // Check that NO electron is counted in the isolation
00207     for(unsigned int eleItr = 0; eleItr < etaele.size(); ++eleItr){
00208     
00209       deta = etaele[eleItr] - imom.eta();
00210       dphi = phiele[eleItr] - imom.phi();
00211 
00212       // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
00213       if (dphi>M_PI) dphi = dphi - 2*M_PI;
00214       else if (dphi<-M_PI) dphi = dphi + 2*M_PI;
00215 
00216       R = sqrt( dphi*dphi + deta*deta );
00217       if (R < vetoConesize) passedconeveto=false;
00218     }
00219 
00220     if (selected && passedconeveto) {
00221       ntrack++;
00222       ptSum+=pt; //to exclude electron tracks
00223     }
00224 
00225   }
00226 
00227   // ntrack-=1; //to exclude electron track
00228 
00229   return (std::pair<int,float>(ntrack,ptSum));
00230 
00231 }