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>
31  };
32 }
33 
34 namespace reco {
35  namespace modulesNew {
36 
37  template <typename C1, typename C2, typename Alg,
38  typename OutputCollection = edm::ValueMap<float>,
39  typename Setup = typename helper::IsolationAlgorithmSetup<Alg>::type>
41  public:
43  ~IsolationProducer() override;
44 
45  private:
46  void produce( edm::Event&, const edm::EventSetup& ) override;
49  Alg alg_;
50  };
51 
52  template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
54  srcToken_( consumes<C1>( cfg.template getParameter<edm::InputTag>( "src" ) ) ),
55  elementsToken_( consumes<C2>( cfg.template getParameter<edm::InputTag>( "elements" ) ) ),
56  alg_( reco::modules::make<Alg>( cfg ) ) {
57  produces<OutputCollection>();
58  }
59 
60  template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
62  }
63 
64  template <typename C1, typename C2, typename Alg, typename OutputCollection, typename Setup>
66  using namespace edm;
67  using namespace std;
70  evt.getByToken( srcToken_, src );
71  evt.getByToken( elementsToken_, elements );
72 
73  Setup::init(alg_, es);
74 
76  auto isolations = std::make_unique<OutputCollection>();
77  if(!src->empty()) {
78  typename OutputCollection::Filler filler(*isolations);
79  vector<double> iso(master.size(),-1);
80  size_t i = 0;
81  for( typename C1::const_iterator lep = src->begin(); lep != src->end(); ++ lep )
82  iso[master.index(i++)] = alg_(*lep, *elements);
83  filler.insert(master.get(), iso.begin(), iso.end());
84  filler.fill();
85  }
86  evt.put(std::move(isolations) );
87  }
88 
89  }
90 }
91 
92 #endif
const edm::Handle< C1 > & get() const
Master< F > master(const F &f)
Definition: FunctClone.h:68
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
Definition: helper.py:1
static void init(Alg &, const edm::EventSetup &)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
int init
Definition: HydjetWrapper.h:67
S make(const edm::ParameterSet &cfg)
size_t index(size_t i) const
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
void produce(edm::Event &, const edm::EventSetup &) override
fixed size matrix
HLT enums.
IsolationProducer(const edm::ParameterSet &)
NullIsolationAlgorithmSetup< Alg > type
def move(src, dest)
Definition: eostools.py:511