CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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,
40  typename OutputCollection = edm::ValueMap<float>,
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
Master< F > master(const F &f)
Definition: FunctClone.h:63
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
tuple cfg
Definition: looper.py:296
static void init(Alg &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:539
int init
Definition: HydjetWrapper.h:64
S make(const edm::ParameterSet &cfg)
dictionary elements
def move
Definition: eostools.py:511
IsolationProducer(const edm::ParameterSet &)
void produce(edm::Event &, const edm::EventSetup &) override
NullIsolationAlgorithmSetup< Alg > type
def template
Definition: svgfig.py:521