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 |
*/
|
10 |
#include "PhysicsTools/UtilAlgos/interface/ParameterAdapter.h"
|
11 |
#include "FWCore/Framework/interface/EDProducer.h"
|
12 |
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
|
13 |
#include "FWCore/ParameterSet/interface/InputTag.h"
|
14 |
#include "DataFormats/Common/interface/AssociationVector.h"
|
15 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
16 |
#include "FWCore/Framework/interface/Event.h"
|
17 |
#include "DataFormats/Common/interface/Handle.h"
|
18 |
#include <vector>
|
19 |
|
20 |
namespace helper {
|
21 |
|
22 |
template<typename Alg>
|
23 |
struct NullIsolationAlgorithmSetup {
|
24 |
static void init( Alg &, const edm::EventSetup& ) { }
|
25 |
};
|
26 |
|
27 |
template<typename Alg>
|
28 |
struct IsolationAlgorithmSetup {
|
29 |
typedef NullIsolationAlgorithmSetup<Alg> type;
|
30 |
};
|
31 |
}
|
32 |
|
33 |
template <typename C1, typename C2, typename Alg,
|
34 |
typename Setup = typename helper::IsolationAlgorithmSetup<Alg>::type>
|
35 |
class IsolationProducer : public edm::EDProducer {
|
36 |
public:
|
37 |
IsolationProducer( const edm::ParameterSet & );
|
38 |
~IsolationProducer();
|
39 |
|
40 |
private:
|
41 |
void produce( edm::Event&, const edm::EventSetup& );
|
42 |
edm::InputTag src_, elements_;
|
43 |
Alg alg_;
|
44 |
typedef typename Alg::value_type value_type;
|
45 |
typedef edm::AssociationVector<edm::RefProd<C1>,
|
46 |
std::vector<value_type> > IsolationCollection;
|
47 |
};
|
48 |
|
49 |
template <typename C1, typename C2, typename Alg, typename Setup>
|
50 |
IsolationProducer<C1, C2, Alg, Setup>::IsolationProducer( const edm::ParameterSet & cfg ) :
|
51 |
src_( cfg.template getParameter<edm::InputTag>( "src" ) ),
|
52 |
elements_( cfg.template getParameter<edm::InputTag>( "elements" ) ),
|
53 |
alg_( reco::modules::make<Alg>( cfg ) ) {
|
54 |
//produces<IsolationCollection>();
|
55 |
produces<std::vector<value_type> >(); //CMSSW_1_3_x
|
56 |
}
|
57 |
|
58 |
template <typename C1, typename C2, typename Alg, typename Setup>
|
59 |
IsolationProducer<C1, C2, Alg, Setup>::~IsolationProducer() {
|
60 |
}
|
61 |
|
62 |
template <typename C1, typename C2, typename Alg, typename Setup>
|
63 |
void IsolationProducer<C1, C2, Alg, Setup>::produce( edm::Event& evt, const edm::EventSetup& es ) {
|
64 |
using namespace edm;
|
65 |
using namespace std;
|
66 |
Handle<C1> src;
|
67 |
Handle<C2> elements;
|
68 |
evt.getByLabel( src_, src );
|
69 |
evt.getByLabel( elements_, elements );
|
70 |
|
71 |
Setup::init( alg_, es );
|
72 |
|
73 |
//auto_ptr<IsolationCollection> isolations( new IsolationCollection( edm::RefProd<C1>( src ) ) );
|
74 |
auto_ptr<std::vector<value_type> > isolations( new std::vector<value_type>); //CMSSW_1_3_x
|
75 |
|
76 |
//size_t i = 0;
|
77 |
for( typename C1::const_iterator lep = src->begin(); lep != src->end(); ++ lep ) {
|
78 |
value_type iso= alg_(*lep,*elements);
|
79 |
//isolations->setValue( i++, iso );
|
80 |
isolations->push_back( iso ); //CMSSW_1_3_x
|
81 |
}
|
82 |
evt.put( isolations );
|
83 |
}
|
84 |
|
85 |
#endif
|