Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:46

0001 #ifndef PhysicsTools_PatAlgos_EfficiencyLoader_h
0002 #define PhysicsTools_PatAlgos_EfficiencyLoader_h
0003 
0004 #include "DataFormats/PatCandidates/interface/PATObject.h"
0005 #include "DataFormats/PatCandidates/interface/LookupTableRecord.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/Common/interface/ValueMap.h"
0008 
0009 #include "FWCore/Framework/interface/Event.h"
0010 #include "FWCore/Framework/interface/ConsumesCollector.h"
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Utilities/interface/InputTag.h"
0013 
0014 namespace pat {
0015   namespace helper {
0016     class EfficiencyLoader {
0017     public:
0018       /// Empty constructor
0019       EfficiencyLoader() {}
0020 
0021       /// Constructor from a PSet
0022       EfficiencyLoader(const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC);
0023 
0024       /// 'true' if this there is at least one efficiency configured
0025       bool enabled() const { return !names_.empty(); }
0026 
0027       /// To be called for each new event, reads in the ValueMaps for efficiencies
0028       void newEvent(const edm::Event &event);
0029 
0030       /// Sets the efficiencies for this object, using the reference to the original objects
0031       template <typename T, typename R>
0032       void setEfficiencies(pat::PATObject<T> &obj, const R &originalRef) const;
0033 
0034     private:
0035       std::vector<std::string> names_;
0036       std::vector<edm::EDGetTokenT<edm::ValueMap<pat::LookupTableRecord> > > tokens_;
0037       std::vector<edm::Handle<edm::ValueMap<pat::LookupTableRecord> > > handles_;
0038     };  // class
0039 
0040     template <typename T, typename R>
0041     void EfficiencyLoader::setEfficiencies(pat::PATObject<T> &obj, const R &originalRef) const {
0042       for (size_t i = 0, n = names_.size(); i < n; ++i) {
0043         obj.setEfficiency(names_[i], (*handles_[i])[originalRef]);
0044       }
0045     }
0046 
0047   }  // namespace helper
0048 }  // namespace pat
0049 
0050 #endif