CMS 3D CMS Logo

IsolationProducerNew.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  */
19 #include <vector>
20 
21 namespace helper {
22 
23  template <typename Alg>
24  struct NullIsolationAlgorithmSetup {
25  static void init(Alg&, const edm::EventSetup&) {}
26  };
27 
28  template <typename Alg>
29  struct IsolationAlgorithmSetup {
31  };
32 } // namespace helper
33 
34 namespace reco {
35  namespace modulesNew {
36 
37  template <typename C1,
38  typename C2,
39  typename Alg,
43  public:
45  ~IsolationProducer() override;
46 
47  private:
48  void produce(edm::Event&, const edm::EventSetup&) override;
51  Alg alg_;
52  };
53 
54  template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
56  : srcToken_(consumes<C1>(cfg.template getParameter<edm::InputTag>("src"))),
57  elementsToken_(consumes<C2>(cfg.template getParameter<edm::InputTag>("elements"))),
58  alg_(reco::modules::make<Alg>(cfg)) {
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);
75 
76  ::helper::MasterCollection<C1> master(src, evt);
77  auto isolations = std::make_unique<OutputCollection>();
78  if (!src->empty()) {
79  typename OutputCollection::Filler filler(*isolations);
80  vector<double> iso(master.size(), -1);
81  size_t i = 0;
82  for (typename C1::const_iterator lep = src->begin(); lep != src->end(); ++lep)
83  iso[master.index(i++)] = alg_(*lep, *elements);
84  filler.insert(master.get(), iso.begin(), iso.end());
85  filler.fill();
86  }
87  evt.put(std::move(isolations));
88  }
89 
90  } // namespace modulesNew
91 } // namespace reco
92 
93 #endif
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
Definition: helper.py:1
static void init(Alg &, const edm::EventSetup &)
int init
Definition: HydjetWrapper.h:66
S make(const edm::ParameterSet &cfg)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
IsolationProducer(const edm::ParameterSet &)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
void produce(edm::Event &, const edm::EventSetup &) override
fixed size matrix
HLT enums.
NullIsolationAlgorithmSetup< Alg > type
def move(src, dest)
Definition: eostools.py:511