CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CommonTools/ParticleFlow/interface/IPCutPFCandidateSelectorDefinition.h

Go to the documentation of this file.
00001 #ifndef CommonTools_ParticleFlow_IPCutPFCandidateSelectorDefinition
00002 #define CommonTools_ParticleFlow_IPCutPFCandidateSelectorDefinition
00003 
00012 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidateFwd.h"
00013 #include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
00014 #include "CommonTools/ParticleFlow/interface/PFCandidateSelectorDefinition.h"
00015 #include <DataFormats/VertexReco/interface/Vertex.h>
00016 #include <DataFormats/VertexReco/interface/VertexFwd.h>
00017 #include <DataFormats/GsfTrackReco/interface/GsfTrack.h>
00018 
00019 namespace pf2pat {
00020 
00021   struct IPCutPFCandidateSelectorDefinition : public PFCandidateSelectorDefinition {
00022 
00023     IPCutPFCandidateSelectorDefinition ( const edm::ParameterSet & cfg ) :
00024       vertices_( cfg.getParameter<edm::InputTag> ( "vertices" ) ),
00025       d0Cut_( cfg.getParameter<double>("d0Cut") ),
00026       dzCut_( cfg.getParameter<double>("dzCut") ),
00027       d0SigCut_( cfg.getParameter<double>("d0SigCut") ),
00028       dzSigCut_( cfg.getParameter<double>("dzSigCut") ) {}
00029     
00030     void select( const HandleToCollection & hc, 
00031                  const edm::Event & e,
00032                  const edm::EventSetup& s) {
00033       selected_.clear();
00034     
00035       edm::Handle<reco::VertexCollection> vertices;
00036       e.getByLabel(vertices_, vertices);
00037       if (vertices->empty()) return;
00038       const reco::Vertex &vtx = (*vertices)[0];
00039 
00040       unsigned key=0;
00041       for( collection::const_iterator pfc = hc->begin(); 
00042            pfc != hc->end(); ++pfc, ++key) {
00043         
00044         bool passing = true;
00045         const reco::Track *tk = 0;
00046         if (pfc->gsfTrackRef().isNonnull())   tk = pfc->gsfTrackRef().get();
00047         else if (pfc->trackRef().isNonnull()) tk = pfc->trackRef().get();
00048 
00049         if (tk != 0) {
00050           double d0 =  fabs(tk->dxy(vtx.position()));
00051           double dz =  fabs(tk->dz(vtx.position()));
00052           double d0e = hypot(tk->dxyError(), hypot(vtx.xError(), vtx.yError()));
00053           double dze = hypot(tk->dzError(),  vtx.zError());
00054           if (d0Cut_ > 0 && d0 > d0Cut_) passing = false;
00055           if (dzCut_ > 0 && dz > dzCut_) passing = false;
00056           if (d0SigCut_ > 0 && d0e > 0 && d0/d0e > d0SigCut_) passing = false;
00057           if (dzSigCut_ > 0 && dze > 0 && dz/dze > dzSigCut_) passing = false;
00058         }
00059         
00060         if( passing ) {
00061           selected_.push_back( reco::PFCandidate(*pfc) );
00062           reco::PFCandidatePtr ptrToMother( hc, key );
00063           selected_.back().setSourceCandidatePtr( ptrToMother );
00064         }
00065       }
00066     }
00067     
00068     private:
00069     edm::InputTag vertices_;
00070     double d0Cut_;
00071     double dzCut_;
00072     double d0SigCut_;
00073     double dzSigCut_;
00074   };
00075 }
00076 
00077 #endif