File indexing completed on 2023-03-17 11:18:00
0001 #include "PhysicsTools/SelectorUtils/interface/CutApplicatorWithEventContentBase.h"
0002 #include "DataFormats/EgammaCandidates/interface/Photon.h"
0003 #include "CommonTools/Egamma/interface/EffectiveAreas.h"
0004
0005 class PhoAnyPFIsoWithEAAndExpoScalingEBCut : public CutApplicatorWithEventContentBase {
0006 public:
0007 PhoAnyPFIsoWithEAAndExpoScalingEBCut(const edm::ParameterSet& c);
0008
0009 result_type operator()(const reco::PhotonPtr&) const final;
0010
0011 void setConsumes(edm::ConsumesCollector&) final;
0012 void getEventContent(const edm::EventBase&) final;
0013
0014 double value(const reco::CandidatePtr& cand) const final;
0015
0016 CandidateType candidateType() const final { return PHOTON; }
0017
0018 private:
0019
0020 float _C1_EB;
0021 float _C2_EB;
0022 float _C3_EB;
0023 float _C1_EE;
0024 float _C2_EE;
0025
0026 float _barrelCutOff;
0027 bool _useRelativeIso;
0028
0029 EffectiveAreas _effectiveAreas;
0030
0031 edm::Handle<edm::ValueMap<float> > _anyPFIsoMap;
0032
0033 edm::Handle<double> _rhoHandle;
0034
0035 constexpr static char anyPFIsoWithEA_[] = "anyPFIsoWithEA";
0036 constexpr static char rhoString_[] = "rho";
0037 };
0038
0039 constexpr char PhoAnyPFIsoWithEAAndExpoScalingEBCut::anyPFIsoWithEA_[];
0040 constexpr char PhoAnyPFIsoWithEAAndExpoScalingEBCut::rhoString_[];
0041
0042 DEFINE_EDM_PLUGIN(CutApplicatorFactory, PhoAnyPFIsoWithEAAndExpoScalingEBCut, "PhoAnyPFIsoWithEAAndExpoScalingEBCut");
0043
0044 PhoAnyPFIsoWithEAAndExpoScalingEBCut::PhoAnyPFIsoWithEAAndExpoScalingEBCut(const edm::ParameterSet& c)
0045 : CutApplicatorWithEventContentBase(c),
0046 _C1_EB(c.getParameter<double>("C1_EB")),
0047 _C2_EB(c.getParameter<double>("C2_EB")),
0048 _C3_EB(c.getParameter<double>("C3_EB")),
0049 _C1_EE(c.getParameter<double>("C1_EE")),
0050 _C2_EE(c.getParameter<double>("C2_EE")),
0051 _barrelCutOff(c.getParameter<double>("barrelCutOff")),
0052 _useRelativeIso(c.getParameter<bool>("useRelativeIso")),
0053 _effectiveAreas((c.getParameter<edm::FileInPath>("effAreasConfigFile")).fullPath()) {
0054 edm::InputTag maptag = c.getParameter<edm::InputTag>("anyPFIsoMap");
0055 contentTags_.emplace(anyPFIsoWithEA_, maptag);
0056
0057 edm::InputTag rhoTag = c.getParameter<edm::InputTag>("rho");
0058 contentTags_.emplace(rhoString_, rhoTag);
0059 }
0060
0061 void PhoAnyPFIsoWithEAAndExpoScalingEBCut::setConsumes(edm::ConsumesCollector& cc) {
0062 auto anyPFIsoWithEA = cc.consumes<edm::ValueMap<float> >(contentTags_[anyPFIsoWithEA_]);
0063 contentTokens_.emplace(anyPFIsoWithEA_, anyPFIsoWithEA);
0064
0065 auto rho = cc.consumes<double>(contentTags_[rhoString_]);
0066 contentTokens_.emplace(rhoString_, rho);
0067 }
0068
0069 void PhoAnyPFIsoWithEAAndExpoScalingEBCut::getEventContent(const edm::EventBase& ev) {
0070 ev.getByLabel(contentTags_[anyPFIsoWithEA_], _anyPFIsoMap);
0071 ev.getByLabel(contentTags_[rhoString_], _rhoHandle);
0072 }
0073
0074 CutApplicatorBase::result_type PhoAnyPFIsoWithEAAndExpoScalingEBCut::operator()(const reco::PhotonPtr& cand) const {
0075
0076 const std::string& inst_name = contentTags_.find(anyPFIsoWithEA_)->second.instance();
0077 edm::Ptr<pat::Photon> pat(cand);
0078 float anyisoval = -1.0;
0079 if (_anyPFIsoMap.isValid() && _anyPFIsoMap->contains(cand.id())) {
0080 anyisoval = (*_anyPFIsoMap)[cand];
0081 } else if (_anyPFIsoMap.isValid() && _anyPFIsoMap->idSize() == 1 && cand.id() == edm::ProductID()) {
0082
0083
0084 anyisoval = _anyPFIsoMap->begin()[cand.key()];
0085 } else if (_anyPFIsoMap.isValid()) {
0086 anyisoval = (*_anyPFIsoMap)[cand];
0087 }
0088
0089
0090
0091 const float pt = cand->pt();
0092
0093
0094
0095
0096 double absEta = std::abs(cand->superCluster()->eta());
0097 const float isolationCutValue = (absEta < _barrelCutOff ? _C1_EB + exp(pt * _C2_EB + _C3_EB) : _C1_EE + pt * _C2_EE);
0098
0099
0100 float anyPFIso = _anyPFIsoMap.isValid() ? anyisoval : pat->userFloat(inst_name);
0101
0102
0103 double eA = _effectiveAreas.getEffectiveArea(absEta);
0104 double rho = *_rhoHandle;
0105 float anyPFIsoWithEA = std::max(0.0, anyPFIso - rho * eA);
0106
0107
0108 if (_useRelativeIso)
0109 anyPFIsoWithEA /= pt;
0110
0111
0112 return anyPFIsoWithEA < isolationCutValue;
0113 }
0114
0115 double PhoAnyPFIsoWithEAAndExpoScalingEBCut::value(const reco::CandidatePtr& cand) const {
0116 reco::PhotonPtr pho(cand);
0117
0118
0119 const std::string& inst_name = contentTags_.find(anyPFIsoWithEA_)->second.instance();
0120 edm::Ptr<pat::Photon> pat(cand);
0121 float anyisoval = -1.0;
0122 if (_anyPFIsoMap.isValid() && _anyPFIsoMap->contains(cand.id())) {
0123 anyisoval = (*_anyPFIsoMap)[cand];
0124 } else if (_anyPFIsoMap.isValid() && _anyPFIsoMap->idSize() == 1 && cand.id() == edm::ProductID()) {
0125
0126
0127 anyisoval = _anyPFIsoMap->begin()[cand.key()];
0128 } else if (_anyPFIsoMap.isValid()) {
0129 anyisoval = (*_anyPFIsoMap)[cand];
0130 }
0131
0132
0133
0134 const float pt = pho->pt();
0135
0136
0137
0138
0139 double absEta = std::abs(pho->superCluster()->eta());
0140
0141
0142 float anyPFIso = _anyPFIsoMap.isValid() ? anyisoval : pat->userFloat(inst_name);
0143
0144
0145 double eA = _effectiveAreas.getEffectiveArea(absEta);
0146 double rho = *_rhoHandle;
0147 float anyPFIsoWithEA = std::max(0.0, anyPFIso - rho * eA);
0148
0149
0150 if (_useRelativeIso)
0151 anyPFIsoWithEA /= pt;
0152
0153
0154 return anyPFIsoWithEA;
0155 }