CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/RecoEgamma/EgammaIsolationAlgos/plugins/EgammaTrackExtractor.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaIsolationAlgos/plugins/EgammaTrackExtractor.h"
00002 
00003 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaRange.h"
00004 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaRecHitIsolation.h"
00005 #include "RecoCaloTools/MetaCollections/interface/CaloRecHitMetaCollections.h"
00006 #include "DataFormats/RecoCandidate/interface/IsoDepositDirection.h"
00007 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTrackSelector.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "DataFormats/Common/interface/View.h"
00010 #include "DataFormats/TrackReco/interface/Track.h"
00011 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00014 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00015 #include "DataFormats/EgammaReco/interface/SuperCluster.h"
00016 #include "DataFormats/EgammaReco/interface/SuperClusterFwd.h"
00017 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00018 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00019 #include "DataFormats/GsfTrackReco/interface/GsfTrack.h"
00020 #include "DataFormats/GsfTrackReco/interface/GsfTrackFwd.h"
00021 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
00022 #include "CommonTools/Statistics/interface/ChiSquaredProbability.h"
00023 
00024 using namespace edm;
00025 using namespace std;
00026 using namespace reco;
00027 using namespace egammaisolation;
00028 using reco::isodeposit::Direction;
00029 
00030 EgammaTrackExtractor::EgammaTrackExtractor( const ParameterSet& par ) :
00031     theTrackCollectionTag(par.getParameter<edm::InputTag>("inputTrackCollection")),
00032     theDepositLabel(par.getUntrackedParameter<std::string>("DepositLabel")),
00033     theDiff_r(par.getParameter<double>("Diff_r")),
00034     theDiff_z(par.getParameter<double>("Diff_z")),
00035     theDR_Max(par.getParameter<double>("DR_Max")),
00036     theDR_Veto(par.getParameter<double>("DR_Veto")),
00037     theBeamlineOption(par.getParameter<std::string>("BeamlineOption")),
00038     theBeamSpotLabel(par.getParameter<edm::InputTag>("BeamSpotLabel")),
00039     theNHits_Min(par.getParameter<unsigned int>("NHits_Min")),
00040     theChi2Ndof_Max(par.getParameter<double>("Chi2Ndof_Max")),
00041     theChi2Prob_Min(par.getParameter<double>("Chi2Prob_Min")),
00042     thePt_Min(par.getParameter<double>("Pt_Min")),
00043     dzOptionString(par.getParameter<std::string>("dzOption"))
00044 {
00045     if( ! dzOptionString.compare("dz") )      dzOption = EgammaTrackSelector::dz;
00046     else if( ! dzOptionString.compare("vz") ) dzOption = EgammaTrackSelector::vz;
00047     else if( ! dzOptionString.compare("bs") ) dzOption = EgammaTrackSelector::bs;
00048     else if( ! dzOptionString.compare("vtx") )dzOption = EgammaTrackSelector::vtx;
00049     else                                      dzOption = EgammaTrackSelector::dz;
00050 
00051 }
00052 
00053 reco::IsoDeposit::Vetos EgammaTrackExtractor::vetos(const edm::Event & ev,
00054         const edm::EventSetup & evSetup, const reco::Track & track) const
00055 {
00056     reco::isodeposit::Direction dir(track.eta(),track.phi());
00057     return reco::IsoDeposit::Vetos(1,veto(dir));
00058 }
00059 
00060 reco::IsoDeposit::Veto EgammaTrackExtractor::veto(const reco::IsoDeposit::Direction & dir) const
00061 {
00062     reco::IsoDeposit::Veto result;
00063     result.vetoDir = dir;
00064     result.dR = theDR_Veto;
00065     return result;
00066 }
00067 
00068 IsoDeposit EgammaTrackExtractor::deposit(const Event & event, const EventSetup & eventSetup, const Candidate & candTk) const
00069 {
00070     static std::string metname = "EgammaIsolationAlgos|EgammaTrackExtractor";
00071 
00072     reco::isodeposit::Direction candDir;
00073     double dzCut=0; 
00074 
00075     reco::TrackBase::Point beamPoint(0,0, 0);
00076     if (theBeamlineOption.compare("BeamSpotFromEvent") == 0){
00077         //pick beamSpot
00078         reco::BeamSpot beamSpot;
00079         edm::Handle<reco::BeamSpot> beamSpotH;
00080 
00081         event.getByLabel(theBeamSpotLabel,beamSpotH);
00082 
00083         if (beamSpotH.isValid()){
00084             beamPoint = beamSpotH->position();  
00085         }
00086     }
00087 
00088     Handle<View<Track> > tracksH;
00089     event.getByLabel(theTrackCollectionTag, tracksH);
00090 
00091     if( candTk.isElectron() ){ 
00092         const reco::GsfElectron* elec = dynamic_cast<const reco::GsfElectron*>(&candTk);
00093         candDir = reco::isodeposit::Direction(elec->gsfTrack()->eta(), elec->gsfTrack()->phi());
00094     } else {
00095         candDir = reco::isodeposit::Direction(candTk.eta(), candTk.phi());
00096     }
00097 
00098     IsoDeposit deposit(candDir );
00099     deposit.setVeto( veto(candDir) );
00100     deposit.addCandEnergy(candTk.et());
00101 
00102     View<Track>::const_iterator itrTr = tracksH->begin();
00103     View<Track>::const_iterator trEnd = tracksH->end();
00104     for (itrTr = tracksH->begin();itrTr != trEnd; ++itrTr) {
00105 
00106         if(candDir.deltaR( reco::isodeposit::Direction(itrTr->eta(),itrTr->phi()) ) > theDR_Max ) 
00107             continue;
00108 
00109         if(itrTr->normalizedChi2() > theChi2Ndof_Max) 
00110             continue;
00111 
00112         if(itrTr->pt() < thePt_Min) 
00113             continue;
00114 
00115         if(theChi2Prob_Min > 0 && ChiSquaredProbability(itrTr->chi2(), itrTr->ndof()) < theChi2Prob_Min ) 
00116             continue;
00117 
00118         if(theNHits_Min > 0 && itrTr->numberOfValidHits() < theNHits_Min) 
00119             continue;
00120 
00121         if( candTk.isElectron() ){ 
00122             const reco::GsfElectron* elec = dynamic_cast<const reco::GsfElectron*>(&candTk);
00123             switch(dzOption) {
00124                 case EgammaTrackSelector::dz : dzCut = elec->gsfTrack()->dz() - itrTr->dz() ; break;
00125                 case EgammaTrackSelector::vz : dzCut = elec->gsfTrack()->vz() - itrTr->vz() ; break;
00126                 case EgammaTrackSelector::bs : dzCut = elec->gsfTrack()->dz(beamPoint) - itrTr->dz(beamPoint) ; break;
00127                 case EgammaTrackSelector::vtx: dzCut = itrTr->dz(elec->gsfTrack()->vertex()) ; break;
00128                 default: dzCut = elec->gsfTrack()->vz() - itrTr->vz() ; break;
00129             }
00130         } else {
00131             switch(dzOption) {
00132                 case EgammaTrackSelector::dz : dzCut = (*itrTr).dz() - candTk.vertex().z() ; break;
00133                 case EgammaTrackSelector::vz : dzCut = (*itrTr).vz() - candTk.vertex().z() ; break;
00134                 case EgammaTrackSelector::bs : dzCut = (*itrTr).dz(beamPoint) - candTk.vertex().z() ; break;
00135                 case EgammaTrackSelector::vtx: dzCut = (*itrTr).dz(candTk.vertex()); break;
00136                 default : dzCut = (*itrTr).vz() - candTk.vertex().z(); break;
00137             }
00138         }
00139 
00140         if(fabs(dzCut) > theDiff_z) 
00141             continue;
00142 
00143         if(fabs(itrTr->dxy(beamPoint) ) > theDiff_r) 
00144             continue;
00145         
00146         deposit.addDeposit(reco::isodeposit::Direction(itrTr->eta(), itrTr->phi()), itrTr->pt());
00147 
00148     }
00149 
00150     return deposit;
00151 }