File indexing completed on 2024-04-06 12:23:46
0001 #ifndef PhysicsTools_PatAlgos_interface_BaseIsolator_h
0002 #define PhysicsTools_PatAlgos_interface_BaseIsolator_h
0003
0004 #include "DataFormats/Common/interface/ValueMap.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/Framework/interface/Event.h"
0007 #include "FWCore/Framework/interface/ConsumesCollector.h"
0008
0009 #include <atomic>
0010
0011 namespace pat {
0012 namespace helper {
0013 class BaseIsolator {
0014 public:
0015 typedef edm::ValueMap<float> Isolation;
0016 BaseIsolator() {}
0017 BaseIsolator(const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut);
0018 virtual ~BaseIsolator() {}
0019 virtual void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup) = 0;
0020 virtual void endEvent() = 0;
0021
0022
0023 template <typename AnyRef>
0024 bool test(const AnyRef &ref) const {
0025 bool ok = (getValue(ref.id(), ref.key()) < cut_);
0026 try_++;
0027 if (!ok)
0028 fail_++;
0029 return ok;
0030 }
0031
0032 template <typename AnyRef>
0033 float getValue(const AnyRef &ref) const {
0034 return getValue(ref.id(), ref.key());
0035 }
0036
0037 virtual std::string description() const = 0;
0038 void print(std::ostream &out) const;
0039
0040 protected:
0041 virtual float getValue(const edm::ProductID &id, size_t index) const = 0;
0042 edm::InputTag input_;
0043 edm::EDGetTokenT<Isolation> inputToken_;
0044 float cut_;
0045 mutable std::atomic<uint64_t> try_, fail_;
0046 };
0047 }
0048 }
0049
0050 inline std::ostream &operator<<(std::ostream &stream, const pat::helper::BaseIsolator &iso) {
0051 iso.print(stream);
0052 return stream;
0053 }
0054 #endif