1 |
/* \class IsolationProducer
|
2 |
*
|
3 |
* template class to store isolation
|
4 |
*
|
5 |
*
|
6 |
*/
|
7 |
#include "FWCore/Framework/interface/EDProducer.h"
|
8 |
#include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
|
9 |
#include "FWCore/ParameterSet/interface/InputTag.h"
|
10 |
#include "DataFormats/Common/interface/AssociationVector.h"
|
11 |
#include "FWCore/ParameterSet/interface/ParameterSet.h"
|
12 |
#include "FWCore/Framework/interface/Event.h"
|
13 |
#include "DataFormats/Common/interface/Handle.h"
|
14 |
#include <vector>
|
15 |
|
16 |
template <typename C1, typename C2, typename Alg>
|
17 |
class IsolationProducer : public edm::EDProducer {
|
18 |
public:
|
19 |
IsolationProducer( const edm::ParameterSet & );
|
20 |
~IsolationProducer();
|
21 |
|
22 |
private:
|
23 |
void produce( edm::Event&, const edm::EventSetup& );
|
24 |
edm::InputTag src_, elements_;
|
25 |
Alg alg_;
|
26 |
typedef typename Alg::value_type value_type;
|
27 |
typedef edm::AssociationVector<edm::RefProd<C1>,
|
28 |
std::vector<value_type> > IsolationCollection;
|
29 |
};
|
30 |
|
31 |
template <typename C1, typename C2, typename Alg>
|
32 |
IsolationProducer<C1,C2,Alg>::IsolationProducer( const edm::ParameterSet & cfg ) :
|
33 |
src_( cfg.template getParameter<edm::InputTag>( "src" ) ),
|
34 |
elements_( cfg.template getParameter<edm::InputTag>( "elements" ) ),
|
35 |
alg_(cfg) {
|
36 |
// Quick fix for version CMSSW_1_3_1:
|
37 |
// produces<IsolationCollection>(); //CMSSW_1_5_0
|
38 |
produces<std::vector<value_type> >(); //CMSSW_1_3_x
|
39 |
}
|
40 |
|
41 |
template <typename C1, typename C2, typename Alg>
|
42 |
IsolationProducer<C1,C2,Alg>::~IsolationProducer() {
|
43 |
}
|
44 |
|
45 |
template <typename C1, typename C2, typename Alg>
|
46 |
void IsolationProducer<C1,C2,Alg>::produce( edm::Event& evt, const edm::EventSetup& setup ) {
|
47 |
using namespace edm;
|
48 |
using namespace std;
|
49 |
Handle<C1> src;
|
50 |
Handle<C2> elements;
|
51 |
evt.getByLabel( src_, src );
|
52 |
evt.getByLabel( elements_, elements );
|
53 |
// Quick fix fir version CMSSW_1_3_1:
|
54 |
// auto_ptr<IsolationCollection> isolations( new IsolationCollection( edm::RefProd<C1>( src ) ) );
|
55 |
auto_ptr<std::vector<value_type> > isolations( new std::vector<value_type>);
|
56 |
|
57 |
// size_t i = 0;
|
58 |
for( typename C1::const_iterator lep = src->begin(); lep != src->end(); ++ lep ) {
|
59 |
value_type iso = alg_(*lep,*elements, setup); //Changed alg_ interface!
|
60 |
|
61 |
//isolations->setValue( i++, iso ); //CMSSW_1_5_0
|
62 |
isolations->push_back( iso ); //CMSSW_1_3_x
|
63 |
}
|
64 |
evt.put( isolations );
|
65 |
}
|
66 |
|