CMS 3D CMS Logo

IsolationProducer.h
Go to the documentation of this file.
1 #ifndef IsolationAlgos_IsolationProducer_h
2 #define IsolationAlgos_IsolationProducer_h
3 /* \class IsolationProducer<C1, C2, Algo>
4  *
5  * \author Francesco Fabozzi, INFN
6  *
7  * template class to store isolation
8  *
9  */
18 #include <vector>
19 
20 namespace helper {
21 
22  template <typename Alg>
26  static void init(Alg&, const edm::EventSetup&, ESConsumesToken) {}
27  };
28 
29  template <typename Alg>
32  };
33 } // namespace helper
34 
35 template <typename C1,
36  typename C2,
37  typename Alg,
38  typename OutputCollection = edm::AssociationVector<edm::RefProd<C1>, std::vector<typename Alg::value_type> >,
41 public:
43  ~IsolationProducer() override;
44 
45 private:
46  void produce(edm::Event&, const edm::EventSetup&) override;
49  Alg alg_;
50  typename Setup::ESConsumesToken esToken_;
51 };
52 
53 template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
55  : srcToken_(consumes<C1>(cfg.template getParameter<edm::InputTag>("src"))),
56  elementsToken_(consumes<C2>(cfg.template getParameter<edm::InputTag>("elements"))),
57  alg_(reco::modules::make<Alg>(cfg)),
58  esToken_(Setup::esConsumes(consumesCollector())) {
59  produces<OutputCollection>();
60 }
61 
62 template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
64 
65 template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
67  using namespace edm;
68  using namespace std;
71  evt.getByToken(srcToken_, src);
72  evt.getByToken(elementsToken_, elements);
73 
74  Setup::init(alg_, es, esToken_);
75 
76  typename OutputCollection::refprod_type ref(src);
77  auto isolations = std::make_unique<OutputCollection>(ref);
78 
79  size_t i = 0;
80  for (typename C1::const_iterator lep = src->begin(); lep != src->end(); ++lep) {
81  typename Alg::value_type iso = alg_(*lep, *elements);
82  isolations->setValue(i++, iso);
83  }
84  evt.put(std::move(isolations));
85 }
86 
87 #endif
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
Definition: helper.py:1
int init
Definition: HydjetWrapper.h:64
S make(const edm::ParameterSet &cfg)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
static ESConsumesToken esConsumes(edm::ConsumesCollector)
Setup::ESConsumesToken esToken_
edm::EDGetTokenT< C1 > srcToken_
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
~IsolationProducer() override
static void init(Alg &, const edm::EventSetup &, ESConsumesToken)
edm::EDGetTokenT< C2 > elementsToken_
fixed size matrix
HLT enums.
IsolationProducer(const edm::ParameterSet &)
NullIsolationAlgorithmSetup< Alg > type
def move(src, dest)
Definition: eostools.py:511
void produce(edm::Event &, const edm::EventSetup &) override