CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ElectronIsolatorFromEffectiveArea.cc
Go to the documentation of this file.
6 
11 
13 
15 public:
19 
20 private:
21  bool filter(edm::Event&, const edm::EventSetup&) override;
31  static std::map<std::string, EEA::ElectronEffectiveAreaType> EEA_type();
32  static std::map<std::string, EEA::ElectronEffectiveAreaTarget> EEA_target();
33 };
34 
36  : gsfElectronTag(edm::InputTag("")),
37  pfElectronTag(edm::InputTag("")),
38  patElectronTag(edm::InputTag("")),
39  rhoIsoToken(consumes<double>(config.getParameter<edm::InputTag>("rhoIso"))),
40  modeEEA(EEA_type()[config.getParameter<std::string>("EffectiveAreaType")]),
41  targetEEA(EEA_target()[config.getParameter<std::string>("EffectiveAreaTarget")]) {
42  if (config.existsAs<edm::InputTag>("gsfElectrons"))
43  gsfElectronTag = config.getParameter<edm::InputTag>("gsfElectrons");
44  if (config.existsAs<edm::InputTag>("pfElectrons"))
45  pfElectronTag = config.getParameter<edm::InputTag>("pfElectrons");
46  if (config.existsAs<edm::InputTag>("patElectrons"))
47  patElectronTag = config.getParameter<edm::InputTag>("patElectrons");
48  if (!gsfElectronTag.label().empty())
49  gsfElectronToken = consumes<reco::GsfElectronCollection>(gsfElectronTag);
50  if (!pfElectronTag.label().empty())
51  pfElectronToken = consumes<reco::PFCandidateCollection>(pfElectronTag);
52  if (!patElectronTag.label().empty())
53  patElectronToken = consumes<pat::ElectronCollection>(patElectronTag);
54  produces<CandDoubleMap>();
55 }
56 
58  std::unique_ptr<CandDoubleMap> product(new CandDoubleMap());
59  CandDoubleMap::Filler filler(*product);
60 
62  event.getByToken(rhoIsoToken, rho);
63 
64  if (!gsfElectronTag.label().empty()) {
66  event.getByToken(gsfElectronToken, gsfElectrons);
67  std::vector<double> gsfCorrectionsEA;
68  if (gsfElectrons.isValid()) {
69  for (reco::GsfElectronCollection::const_iterator it = gsfElectrons->begin(); it != gsfElectrons->end(); ++it)
70  gsfCorrectionsEA.push_back((*rho) *
71  EEA::GetElectronEffectiveArea(modeEEA, it->superCluster()->eta(), targetEEA));
72  filler.insert(gsfElectrons, gsfCorrectionsEA.begin(), gsfCorrectionsEA.end());
73  }
74  }
75 
76  if (!pfElectronTag.label().empty()) {
78  event.getByToken(pfElectronToken, pfElectrons);
79  std::vector<double> pfCorrectionsEA;
80  if (pfElectrons.isValid()) {
81  for (reco::PFCandidateCollection::const_iterator it = pfElectrons->begin(); it != pfElectrons->end(); ++it)
82  pfCorrectionsEA.push_back(
83  (*rho) * EEA::GetElectronEffectiveArea(modeEEA, it->gsfElectronRef()->superCluster()->eta(), targetEEA));
84  filler.insert(pfElectrons, pfCorrectionsEA.begin(), pfCorrectionsEA.end());
85  }
86  }
87 
88  if (!patElectronTag.label().empty()) {
90  event.getByToken(patElectronToken, patElectrons);
91  std::vector<double> patCorrectionsEA;
92  if (patElectrons.isValid()) {
93  for (pat::ElectronCollection::const_iterator it = patElectrons->begin(); it != patElectrons->end(); ++it)
94  patCorrectionsEA.push_back((*rho) *
95  EEA::GetElectronEffectiveArea(modeEEA, it->superCluster()->eta(), targetEEA));
96  filler.insert(patElectrons, patCorrectionsEA.begin(), patCorrectionsEA.end());
97  }
98  }
99 
100  filler.fill();
101  event.put(std::move(product));
102  return true;
103 }
104 
105 // These maps should really be static const members of interface/ElectronEffectiveArea.h
106 // Here mapping strings to only a subset of the enum
107 std::map<std::string, ElectronEffectiveArea::ElectronEffectiveAreaType> ElectronIsolatorFromEffectiveArea::EEA_type() {
108  std::map<std::string, EEA::ElectronEffectiveAreaType> m;
109  m["kEleGammaAndNeutralHadronIso03"] = EEA::kEleGammaAndNeutralHadronIso03;
110  m["kEleGammaAndNeutralHadronIso04"] = EEA::kEleGammaAndNeutralHadronIso04;
111  return m;
112 }
113 
114 std::map<std::string, ElectronEffectiveArea::ElectronEffectiveAreaTarget>
116  std::map<std::string, EEA::ElectronEffectiveAreaTarget> m;
117  m["kEleEANoCorr"] = EEA::kEleEANoCorr;
118  m["kEleEAData2011"] = EEA::kEleEAData2011;
119  m["kEleEASummer11MC"] = EEA::kEleEASummer11MC;
120  m["kEleEAFall11MC"] = EEA::kEleEAFall11MC;
121  m["kEleEAData2012"] = EEA::kEleEAData2012;
122  return m;
123 }
124 
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:171
static std::map< std::string, EEA::ElectronEffectiveAreaTarget > EEA_target()
static std::map< std::string, EEA::ElectronEffectiveAreaType > EEA_type()
bool filter(edm::Event &, const edm::EventSetup &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
static Double_t GetElectronEffectiveArea(ElectronEffectiveAreaType type, Double_t SCEta, ElectronEffectiveAreaTarget EffectiveAreaTarget=kEleEAData2011)
edm::EDGetTokenT< pat::ElectronCollection > patElectronToken
const EEA::ElectronEffectiveAreaType modeEEA
def move
Definition: eostools.py:511
bool isValid() const
Definition: HandleBase.h:70
ElectronIsolatorFromEffectiveArea(const edm::ParameterSet &)
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EDGetTokenT< reco::PFCandidateCollection > pfElectronToken
std::string const & label() const
Definition: InputTag.h:36
tuple config
parse the configuration file
const EEA::ElectronEffectiveAreaTarget targetEEA
edm::EDGetTokenT< reco::GsfElectronCollection > gsfElectronToken