CMS 3D CMS Logo

EgammaTrackExtractor.cc

Go to the documentation of this file.
00001 #include "RecoEgamma/EgammaIsolationAlgos/plugins/EgammaTrackExtractor.h"
00002 
00003 #include "RecoEgamma/EgammaIsolationAlgos/plugins/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/plugins/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 
00023 using namespace edm;
00024 using namespace std;
00025 using namespace reco;
00026 using namespace egammaisolation;
00027 using reco::isodeposit::Direction;
00028 
00029 EgammaTrackExtractor::EgammaTrackExtractor( const ParameterSet& par ) :
00030     theTrackCollectionTag(par.getParameter<edm::InputTag>("inputTrackCollection")),
00031     theDepositLabel(par.getUntrackedParameter<string>("DepositLabel")),
00032     minCandEt_(par.getParameter<double>("minCandEt")),
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<string>("BeamlineOption")),
00038     barrelEcalHitsTag_(par.getParameter<edm::InputTag>("barrelEcalHits")),
00039     endcapEcalHitsTag_(par.getParameter<edm::InputTag>("endcapEcalHits")),
00040     theBeamSpotLabel(par.getParameter<edm::InputTag>("BeamSpotLabel")),
00041     theNHits_Min(par.getParameter<uint>("NHits_Min")),
00042     theChi2Ndof_Max(par.getParameter<double>("Chi2Ndof_Max")),
00043     theChi2Prob_Min(par.getParameter<double>("Chi2Prob_Min")),
00044     thePt_Min(par.getParameter<double>("Pt_Min"))
00045 {
00046     paramForIsolBarrel_.push_back(par.getParameter<double>("checkIsoExtRBarrel"));
00047     paramForIsolBarrel_.push_back(par.getParameter<double>("checkIsoInnRBarrel"));
00048     paramForIsolBarrel_.push_back(par.getParameter<double>("checkIsoEtaStripBarrel"));
00049     paramForIsolBarrel_.push_back(par.getParameter<double>("checkIsoEtRecHitBarrel"));
00050     paramForIsolBarrel_.push_back(par.getParameter<double>("checkIsoEtCutBarrel"));
00051 
00052     paramForIsolEndcap_.push_back(par.getParameter<double>("checkIsoExtREndcap"));
00053     paramForIsolEndcap_.push_back(par.getParameter<double>("checkIsoInnREndcap"));
00054     paramForIsolEndcap_.push_back(par.getParameter<double>("checkIsoEtaStripEndcap"));
00055     paramForIsolEndcap_.push_back(par.getParameter<double>("checkIsoEtRecHitEndcap"));
00056     paramForIsolEndcap_.push_back(par.getParameter<double>("checkIsoEtCutEndcap"));
00057 }
00058 
00059 reco::IsoDeposit::Vetos EgammaTrackExtractor::vetos(const edm::Event & ev,
00060         const edm::EventSetup & evSetup, const reco::Track & track) const
00061 {
00062     reco::isodeposit::Direction dir(track.eta(),track.phi());
00063     return reco::IsoDeposit::Vetos(1,veto(dir));
00064 }
00065 
00066 reco::IsoDeposit::Veto EgammaTrackExtractor::veto(const reco::IsoDeposit::Direction & dir) const
00067 {
00068     reco::IsoDeposit::Veto result;
00069     result.vetoDir = dir;
00070     result.dR = theDR_Veto;
00071     return result;
00072 }
00073 
00074 IsoDeposit EgammaTrackExtractor::deposit(const Event & event, const EventSetup & eventSetup, const Candidate & candTk) const
00075 {
00076     static std::string metname = "EgammaIsolationAlgos|EgammaTrackExtractor";
00077 
00078     reco::isodeposit::Direction muonDir(candTk.eta(), candTk.phi());
00079 
00080     IsoDeposit deposit(muonDir );
00081     deposit.setVeto( veto(muonDir) );
00082     deposit.addCandEnergy(candTk.et());
00083 
00084     Handle<View<Track> > tracksH;
00085     event.getByLabel(theTrackCollectionTag, tracksH);
00086     //  const TrackCollection tracks = *(tracksH.product());
00087     LogTrace(metname)<<"***** TRACK COLLECTION SIZE: "<<tracksH->size();
00088 
00089     double vtx_z = candTk.vertex().z();
00090     LogTrace(metname)<<"***** Muon vz: "<<vtx_z;
00091     reco::TrackBase::Point beamPoint(0,0, 0);
00092 
00093     if (theBeamlineOption.compare("BeamSpotFromEvent") == 0){
00094         //pick beamSpot
00095         reco::BeamSpot beamSpot;
00096         edm::Handle<reco::BeamSpot> beamSpotH;
00097 
00098         event.getByLabel(theBeamSpotLabel,beamSpotH);
00099 
00100         if (beamSpotH.isValid()){
00101             beamPoint = beamSpotH->position();
00102             LogTrace(metname)<<"Extracted beam point at "<<beamPoint<<std::endl;
00103         }
00104     }
00105 
00106     LogTrace(metname)<<"Using beam point at "<<beamPoint<<std::endl;
00107 
00108     //Get barrel ECAL RecHits for Iso checking
00109     edm::Handle<EcalRecHitCollection> barrelEcalRecHitsH;
00110     event.getByLabel(barrelEcalHitsTag_, barrelEcalRecHitsH);
00111 
00112     //Get endcap ECAL RecHits for Iso checking
00113     edm::Handle<EcalRecHitCollection> endcapEcalRecHitsH;
00114     event.getByLabel(endcapEcalHitsTag_, endcapEcalRecHitsH);
00115 
00116     edm::ESHandle<CaloGeometry> pG;
00117     eventSetup.get<CaloGeometryRecord>().get(pG);
00118 
00119     std::auto_ptr<CaloRecHitMetaCollectionV> ecalRecHits(0);
00120     double extRadius, innRadius, etaStrip, minEtRecHit, isolEtCut;
00121     if( abs(candTk.eta()) < 1.5 ) {
00122         extRadius   = paramForIsolBarrel_[0];
00123         innRadius   = paramForIsolBarrel_[1];
00124         etaStrip    = paramForIsolBarrel_[2];
00125         minEtRecHit = paramForIsolBarrel_[3];
00126         isolEtCut   = paramForIsolBarrel_[4];
00127         ecalRecHits = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(*barrelEcalRecHitsH));
00128     } else {
00129         extRadius   = paramForIsolEndcap_[0];
00130         innRadius   = paramForIsolEndcap_[1];
00131         etaStrip    = paramForIsolEndcap_[2];
00132         minEtRecHit = paramForIsolEndcap_[3];
00133         isolEtCut   = paramForIsolEndcap_[4];
00134         ecalRecHits = std::auto_ptr<CaloRecHitMetaCollectionV>(new EcalRecHitMetaCollection(*endcapEcalRecHitsH));
00135     }
00136 
00137     EgammaRecHitIsolation candIso(extRadius,innRadius,etaStrip,minEtRecHit,pG,&(*ecalRecHits),DetId::Ecal);
00138     if ( candTk.et() < minCandEt_ || candIso.getEtSum(&candTk) > isolEtCut ) {
00139         deposit.addDeposit( Direction(candTk.eta(), candTk.phi()+0.15), 10000 );
00140         deposit.addDeposit( Direction(candTk.eta(), candTk.phi()+0.25), 100000 );
00141     } else {
00142         EgammaTrackSelector::Parameters pars(EgammaTrackSelector::Range(vtx_z-theDiff_z, vtx_z+theDiff_z),
00143                 theDiff_r, muonDir, theDR_Max, beamPoint);
00144 
00145         pars.nHitsMin = theNHits_Min;
00146         pars.chi2NdofMax = theChi2Ndof_Max;
00147         pars.chi2ProbMin = theChi2Prob_Min;
00148         pars.ptMin = thePt_Min;
00149 
00150         EgammaTrackSelector selection(pars);
00151         EgammaTrackSelector::result_type sel_tracks = selection(*tracksH);
00152         LogTrace(metname)<<"all tracks: "<<tracksH->size()<<" selected: "<<sel_tracks.size();
00153 
00154 
00155         EgammaTrackSelector::result_type::const_iterator tkI = sel_tracks.begin();
00156         for (; tkI != sel_tracks.end(); ++tkI) {
00157             const reco::Track* tk = *tkI;
00158             LogTrace(metname) << "This track has: pt= " << tk->pt() << ", eta= " 
00159                 << tk->eta() <<", phi= "<<tk->phi();
00160             reco::isodeposit::Direction dirTrk(tk->eta(), tk->phi());
00161             deposit.addDeposit(dirTrk, tk->pt());
00162         }
00163 
00164     }
00165     return deposit;
00166 }

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