-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
ElectronIsolatorFromEffectiveArea.cc
127 lines (105 loc) · 5.62 KB
/
ElectronIsolatorFromEffectiveArea.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/EDFilter.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/ValueMap.h"
#include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
#include "DataFormats/ParticleFlowCandidate/interface/PFCandidate.h"
#include "DataFormats/PatCandidates/interface/Electron.h"
#include "EgammaAnalysis/ElectronTools/interface/ElectronEffectiveArea.h"
class ElectronIsolatorFromEffectiveArea : public edm::EDFilter {
public:
typedef edm::ValueMap<double> CandDoubleMap;
typedef ElectronEffectiveArea EEA;
explicit ElectronIsolatorFromEffectiveArea(const edm::ParameterSet&);
private:
virtual bool filter(edm::Event&, const edm::EventSetup&);
edm::InputTag gsfElectronTag;
edm::InputTag pfElectronTag;
edm::InputTag patElectronTag;
edm::EDGetTokenT<reco::GsfElectronCollection> gsfElectronToken;
edm::EDGetTokenT<reco::PFCandidateCollection> pfElectronToken;
edm::EDGetTokenT<pat::ElectronCollection> patElectronToken;
edm::EDGetTokenT<double> rhoIsoToken;
const EEA::ElectronEffectiveAreaType modeEEA;
const EEA::ElectronEffectiveAreaTarget targetEEA;
static std::map<std::string,EEA::ElectronEffectiveAreaType> EEA_type();
static std::map<std::string,EEA::ElectronEffectiveAreaTarget> EEA_target();
};
ElectronIsolatorFromEffectiveArea::
ElectronIsolatorFromEffectiveArea(const edm::ParameterSet& config)
: gsfElectronTag( edm::InputTag( "" ) )
, pfElectronTag( edm::InputTag( "" ) )
, patElectronTag( edm::InputTag( "" ) )
, rhoIsoToken( consumes<double>( config.getParameter<edm::InputTag>("rhoIso") ) )
, modeEEA( EEA_type()[ config.getParameter<std::string>("EffectiveAreaType") ] )
, targetEEA( EEA_target()[ config.getParameter<std::string>("EffectiveAreaTarget") ] )
{
if ( config.existsAs<edm::InputTag>("gsfElectrons") ) gsfElectronTag = config.getParameter<edm::InputTag>("gsfElectrons");
if ( config.existsAs<edm::InputTag>("pfElectrons") ) pfElectronTag = config.getParameter<edm::InputTag>("pfElectrons");
if ( config.existsAs<edm::InputTag>("patElectrons") ) patElectronTag = config.getParameter<edm::InputTag>("patElectrons");
if ( !gsfElectronTag.label().empty() ) gsfElectronToken = consumes<reco::GsfElectronCollection>( gsfElectronTag );
if ( !pfElectronTag.label().empty() ) pfElectronToken = consumes<reco::PFCandidateCollection>( pfElectronTag );
if ( !patElectronTag.label().empty() ) patElectronToken = consumes<pat::ElectronCollection>( patElectronTag );
produces<CandDoubleMap>();
}
bool ElectronIsolatorFromEffectiveArea::
filter(edm::Event& event, const edm::EventSetup& )
{
std::unique_ptr<CandDoubleMap> product(new CandDoubleMap());
CandDoubleMap::Filler filler(*product);
edm::Handle<double> rho; event.getByToken(rhoIsoToken, rho);
if ( !gsfElectronTag.label().empty() ) {
edm::Handle<reco::GsfElectronCollection> gsfElectrons; event.getByToken(gsfElectronToken,gsfElectrons);
std::vector<double> gsfCorrectionsEA;
if(gsfElectrons.isValid()) {
for ( reco::GsfElectronCollection::const_iterator it = gsfElectrons->begin(); it != gsfElectrons->end(); ++it)
gsfCorrectionsEA.push_back( (*rho) * EEA::GetElectronEffectiveArea( modeEEA, it->superCluster()->eta(), targetEEA ) );
filler.insert(gsfElectrons, gsfCorrectionsEA.begin(), gsfCorrectionsEA.end() );
}
}
if ( !pfElectronTag.label().empty() ) {
edm::Handle<reco::PFCandidateCollection> pfElectrons; event.getByToken( pfElectronToken, pfElectrons);
std::vector<double> pfCorrectionsEA;
if(pfElectrons.isValid()) {
for ( reco::PFCandidateCollection::const_iterator it = pfElectrons->begin(); it != pfElectrons->end(); ++it)
pfCorrectionsEA.push_back( (*rho) * EEA::GetElectronEffectiveArea( modeEEA, it->gsfElectronRef()->superCluster()->eta(), targetEEA ) );
filler.insert( pfElectrons, pfCorrectionsEA.begin(), pfCorrectionsEA.end() );
}
}
if ( !patElectronTag.label().empty() ) {
edm::Handle<pat::ElectronCollection> patElectrons; event.getByToken( patElectronToken, patElectrons);
std::vector<double> patCorrectionsEA;
if(patElectrons.isValid()) {
for ( pat::ElectronCollection::const_iterator it = patElectrons->begin(); it != patElectrons->end(); ++it)
patCorrectionsEA.push_back( (*rho) * EEA::GetElectronEffectiveArea( modeEEA, it->superCluster()->eta(), targetEEA ) );
filler.insert( patElectrons, patCorrectionsEA.begin(), patCorrectionsEA.end() );
}
}
filler.fill();
event.put(std::move(product));
return true;
}
// These maps should really be static const members of interface/ElectronEffectiveArea.h
// Here mapping strings to only a subset of the enum
std::map<std::string,ElectronEffectiveArea::ElectronEffectiveAreaType>
ElectronIsolatorFromEffectiveArea::EEA_type()
{
std::map<std::string,EEA::ElectronEffectiveAreaType> m;
m["kEleGammaAndNeutralHadronIso03"] = EEA::kEleGammaAndNeutralHadronIso03;
m["kEleGammaAndNeutralHadronIso04"] = EEA::kEleGammaAndNeutralHadronIso04;
return m;
}
std::map<std::string,ElectronEffectiveArea::ElectronEffectiveAreaTarget>
ElectronIsolatorFromEffectiveArea::EEA_target()
{
std::map<std::string,EEA::ElectronEffectiveAreaTarget > m;
m["kEleEANoCorr"] = EEA::kEleEANoCorr;
m["kEleEAData2011"] = EEA::kEleEAData2011;
m["kEleEASummer11MC"] = EEA::kEleEASummer11MC;
m["kEleEAFall11MC"] = EEA::kEleEAFall11MC;
m["kEleEAData2012"] = EEA::kEleEAData2012;
return m;
}
DEFINE_FWK_MODULE(ElectronIsolatorFromEffectiveArea);