CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/PhysicsTools/PatAlgos/interface/VertexingHelper.h

Go to the documentation of this file.
00001 #ifndef PhysicsTools_PatAlgos_interface_VertexingHelper_h
00002 #define PhysicsTools_PatAlgos_interface_VertexingHelper_h
00003 
00015 #include "DataFormats/PatCandidates/interface/Vertexing.h"
00016 #include "DataFormats/Common/interface/ValueMap.h"
00017 #include "PhysicsTools/PatUtils/interface/VertexAssociationSelector.h"
00018 
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/Framework/interface/Event.h"
00021 
00022 #include "FWCore/Framework/interface/EventSetup.h"
00023 #include "FWCore/Framework/interface/ESHandle.h"
00024 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00025 
00026 #include "PhysicsTools/UtilAlgos/interface/ParameterAdapter.h"
00027 namespace reco {
00028     namespace modules {
00030         template<> 
00031         struct ParameterAdapter<pat::VertexAssociationSelector> { 
00032             static pat::VertexAssociationSelector make(const edm::ParameterSet & iConfig) {
00033                 pat::VertexAssociationSelector::Config assoconf;
00034                 if (iConfig.existsAs<double>("deltaZ"))  assoconf.dZ = iConfig.getParameter<double>("deltaZ");
00035                 if (iConfig.existsAs<double>("deltaR"))  assoconf.dR = iConfig.getParameter<double>("deltaR");
00036                 if (iConfig.existsAs<double>("sigmasZ")) assoconf.sigmasZ = iConfig.getParameter<double>("sigmasZ");
00037                 if (iConfig.existsAs<double>("sigmasR")) assoconf.sigmasR = iConfig.getParameter<double>("sigmasR");
00038                 return pat::VertexAssociationSelector(assoconf);
00039             }
00040         };
00041     }
00042 }
00043 
00044 namespace pat { namespace helper {
00045     class VertexingHelper {
00046         public:
00047             VertexingHelper() : enabled_(false) {}
00048             VertexingHelper(const edm::ParameterSet &iConfig) ;
00049     
00051             bool enabled() const {  return enabled_; }
00052 
00054             void newEvent(const edm::Event &event) ;
00055 
00058             void newEvent(const edm::Event &event, const edm::EventSetup & setup) ;
00059 
00062             template<typename AnyCandRef>
00063             pat::VertexAssociation  operator()(const AnyCandRef &) const ;
00064 
00065         private: 
00067             bool enabled_;
00068         
00070             bool playback_;
00071        
00073             pat::VertexAssociationSelector assoSelector_;
00074 
00075             //-------- Tools for production of vertex associations -------
00076             edm::InputTag vertices_;
00077             edm::Handle<reco::VertexCollection > vertexHandle_;
00079             bool useTracks_;
00080             edm::ESHandle<TransientTrackBuilder> ttBuilder_;
00081           
00082             //--------- Tools for reading vertex associations (playback mode) ----- 
00083             edm::InputTag vertexAssociations_;
00084             edm::Handle<edm::ValueMap<pat::VertexAssociation> > vertexAssoMap_;
00085 
00087             reco::TrackBaseRef  getTrack_(const reco::Candidate &c) const ;
00088             
00091             pat::VertexAssociation associate(const reco::Candidate &) const ;
00092 
00093     }; // class
00094 
00095     template<typename AnyCandRef>
00096     pat::VertexAssociation
00097     pat::helper::VertexingHelper::operator()(const AnyCandRef &cand) const 
00098     {
00099         if (playback_) {
00100             const pat::VertexAssociation &assoc = (*vertexAssoMap_)[cand];
00101             return assoSelector_(assoc) ? assoc : pat::VertexAssociation();
00102         } else {
00103             return associate( *cand );
00104         }
00105 
00106     }
00107 
00108 } }
00109 
00110 
00111 
00112 
00113 #endif