CMS 3D CMS Logo

MultiIsolator.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_PatAlgos_interface_MultiIsolator_h
2 #define PhysicsTools_PatAlgos_interface_MultiIsolator_h
3 
9 
10 #include <memory>
11 #include <vector>
12 
13 namespace pat {
14  namespace helper {
15  class MultiIsolator {
16  public:
17  typedef std::vector<std::pair<pat::IsolationKeys, float>> IsolationValuePairs;
19  MultiIsolator(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC, bool cuts = true);
21 
22  // adds an isolator (and takes onwership of the pointer)
23  void addIsolator(BaseIsolator *iso, uint32_t mask, pat::IsolationKeys key);
24 
25  // parses an isolator and adds it to the list
26  void addIsolator(const edm::ParameterSet &conf,
28  bool withCut,
29  uint32_t mask,
31 
32  // Parses out an isolator, and returns a pointer to it.
33  // For an empty PSet, it returns a null pointer.
34  // You own the returned pointer!
35  static BaseIsolator *make(const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut);
36 
38  void endEvent();
39 
40  template <typename T>
41  uint32_t test(const edm::View<T> &coll, int idx) const;
42 
43  template <typename T>
44  void fill(const edm::View<T> &coll, int idx, IsolationValuePairs &isolations) const;
45 
47  template <typename RefType>
48  void fill(const RefType &ref, IsolationValuePairs &isolations) const;
49 
50  void print(std::ostream &out) const;
51 
52  std::string printSummary() const;
53 
55  bool enabled() const { return !isolators_.empty(); }
56 
57  private:
58  std::vector<std::unique_ptr<BaseIsolator>> isolators_;
59  std::vector<uint32_t> masks_;
60  std::vector<pat::IsolationKeys> keys_;
61  };
62 
63  template <typename T>
64  uint32_t MultiIsolator::test(const edm::View<T> &coll, int idx) const {
65  uint32_t retval = 0;
66  edm::RefToBase<T> rb = coll.refAt(idx); // edm::Ptr<T> in a shiny new future to come one remote day ;-)
67  for (size_t i = 0, n = isolators_.size(); i < n; ++i) {
68  if (!isolators_[i]->test(rb))
69  retval |= masks_[i];
70  }
71  return retval;
72  }
73 
74  template <typename RefType>
75  void MultiIsolator::fill(const RefType &rb, IsolationValuePairs &isolations) const {
76  isolations.resize(isolators_.size());
77  for (size_t i = 0, n = isolators_.size(); i < n; ++i) {
78  isolations[i].first = keys_[i];
79  isolations[i].second = isolators_[i]->getValue(rb);
80  }
81  }
82 
83  template <typename T>
84  void MultiIsolator::fill(const edm::View<T> &coll, int idx, IsolationValuePairs &isolations) const {
85  edm::RefToBase<T> rb = coll.refAt(idx);
86  fill(rb, isolations);
87  }
88 
89  } // namespace helper
90 } // namespace pat
91 
92 #endif
std::vector< uint32_t > masks_
Definition: MultiIsolator.h:59
Definition: helper.py:1
bool enabled() const
True if it has a non null configuration.
Definition: MultiIsolator.h:55
IsolationKeys
Enum defining isolation keys.
Definition: Isolation.h:9
constexpr uint32_t mask
Definition: gpuClustering.h:26
void fill(const edm::View< T > &coll, int idx, IsolationValuePairs &isolations) const
Definition: MultiIsolator.h:84
Definition: HeavyIon.h:7
void beginEvent(const edm::Event &event, const edm::EventSetup &eventSetup)
static BaseIsolator * make(const edm::ParameterSet &conf, edm::ConsumesCollector &iC, bool withCut)
std::string printSummary() const
std::vector< pat::IsolationKeys > keys_
Definition: MultiIsolator.h:60
std::vector< std::pair< pat::IsolationKeys, float > > IsolationValuePairs
Definition: MultiIsolator.h:17
void print(std::ostream &out) const
std::vector< std::unique_ptr< BaseIsolator > > isolators_
Definition: MultiIsolator.h:58
void addIsolator(BaseIsolator *iso, uint32_t mask, pat::IsolationKeys key)
Definition: event.py:1
uint32_t test(const edm::View< T > &coll, int idx) const
Definition: MultiIsolator.h:64