CMS 3D CMS Logo

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.5 2009/01/28 15:40:43 covarell 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     if (pt > ptMin && R < conesize && R > vetoConesize &&
00135         fabs(dperp) < rspan && fabs(dz) < zspan) {
00136       ntrack++;
00137       ptSum+=pt; 
00138     }
00139   }
00140 
00141   // if (isElectron) ntrack-=1; //to exclude electron track
00142 
00143   return (std::pair<int,float>(ntrack,ptSum));
00144 
00145 }
00146 
00147 std::pair<int,float> EgammaHLTTrackIsolation::findIsoTracksWithoutEle(GlobalVector mom, GlobalPoint vtx, const reco::ElectronCollection* allEle, const reco::TrackCollection* isoTracks)
00148 {
00149 
00150   // Check that reconstructed tracks fit within cone boundaries,
00151   // (Note: tracks will not always stay within boundaries)
00152   int iele = 0;
00153   int ntrack = 0;
00154   float ptSum = 0.;
00155   std::vector<float> etaele;
00156   std::vector<float> phiele;
00157 
00158   // std::cout << "allEle.size() = " << allEle->size() << std::endl;
00159 
00160   // Store ALL electrons eta and phi
00161   for (reco::ElectronCollection::const_iterator iElectron = allEle->begin(); iElectron != allEle->end(); iElectron++){
00162     iele++;
00163     reco::TrackRef anothereletrackref = iElectron->track();
00164     etaele.push_back(anothereletrackref->momentum().eta());
00165     phiele.push_back(anothereletrackref->momentum().phi());
00166     // std::cout << "Electron " << iele << ": phi = " << anothereletrackref->momentum().phi() << ", eta = " << anothereletrackref->momentum().eta() << std::endl; 
00167   }
00168   
00169   for(reco::TrackCollection::const_iterator trItr = isoTracks->begin(); trItr != isoTracks->end(); ++trItr){
00170 
00171     GlobalPoint ivtx(trItr->vertex().x(),trItr->vertex().y(),trItr->vertex().z());
00172     reco::Track::Vector ip = trItr->momentum();
00173     GlobalVector imom ( ip.x(), ip.y(), ip.z());
00174 
00175     float pt = imom.perp();
00176     float dperp = ivtx.perp()-vtx.perp();
00177     float dz = ivtx.z()-vtx.z();
00178     float deta = imom.eta()-mom.eta();
00179     float dphi = imom.phi()-mom.phi();
00180     
00181     // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
00182     if (dphi>M_PI) dphi = dphi - 2*M_PI;
00183     else if (dphi<-M_PI) dphi = dphi + 2*M_PI;
00184 
00185     float R = sqrt( dphi*dphi + deta*deta );
00186 
00187     // Apply boundary cut
00188     bool selected=false;
00189     bool passedconeveto=true;
00190 
00191     if (pt > ptMin && R < conesize &&
00192         fabs(dperp) < rspan && fabs(dz) < zspan) selected=true;
00193   
00194     // Check that NO electron is counted in the isolation
00195     for(unsigned int eleItr = 0; eleItr < etaele.size(); ++eleItr){
00196     
00197       deta = etaele[eleItr] - imom.eta();
00198       dphi = phiele[eleItr] - imom.phi();
00199 
00200       // Correct dmom_phi's from [-2pi,2pi] to [-pi,pi]
00201       if (dphi>M_PI) dphi = dphi - 2*M_PI;
00202       else if (dphi<-M_PI) dphi = dphi + 2*M_PI;
00203 
00204       R = sqrt( dphi*dphi + deta*deta );
00205       if (R < vetoConesize) passedconeveto=false;
00206     }
00207 
00208     if (selected && passedconeveto) {
00209       ntrack++;
00210       ptSum+=pt; //to exclude electron tracks
00211     }
00212 
00213   }
00214 
00215   // ntrack-=1; //to exclude electron track
00216 
00217   return (std::pair<int,float>(ntrack,ptSum));
00218 
00219 }

Generated on Tue Jun 9 17:43:22 2009 for CMSSW by  doxygen 1.5.4