CMS 3D CMS Logo

PhotonXGBoostProducer.cc
Go to the documentation of this file.
16 
17 #include <memory>
18 #include <vector>
19 
21 public:
23  ~PhotonXGBoostProducer() = default;
24 
25  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
26 
27 private:
28  void produce(edm::StreamID, edm::Event&, edm::EventSetup const&) const override;
29 
38  const unsigned mvaNTreeLimitB_;
39  const unsigned mvaNTreeLimitE_;
40  const double mvaThresholdEt_;
41  std::unique_ptr<PhotonXGBoostEstimator> mvaEstimatorB_;
42  std::unique_ptr<PhotonXGBoostEstimator> mvaEstimatorE_;
43 };
44 
46  : candToken_(consumes<reco::RecoEcalCandidateCollection>(config.getParameter<edm::InputTag>("candTag"))),
47  tokenR9_(consumes<reco::RecoEcalCandidateIsolationMap>(config.getParameter<edm::InputTag>("inputTagR9"))),
48  tokenHoE_(consumes<reco::RecoEcalCandidateIsolationMap>(config.getParameter<edm::InputTag>("inputTagHoE"))),
49  tokenSigmaiEtaiEta_(
50  consumes<reco::RecoEcalCandidateIsolationMap>(config.getParameter<edm::InputTag>("inputTagSigmaiEtaiEta"))),
51  tokenE2x2_(consumes<reco::RecoEcalCandidateIsolationMap>(config.getParameter<edm::InputTag>("inputTagE2x2"))),
52  tokenIso_(consumes<reco::RecoEcalCandidateIsolationMap>(config.getParameter<edm::InputTag>("inputTagIso"))),
53  mvaFileXgbB_(config.getParameter<edm::FileInPath>("mvaFileXgbB")),
54  mvaFileXgbE_(config.getParameter<edm::FileInPath>("mvaFileXgbE")),
55  mvaNTreeLimitB_(config.getParameter<unsigned int>("mvaNTreeLimitB")),
56  mvaNTreeLimitE_(config.getParameter<unsigned int>("mvaNTreeLimitE")),
57  mvaThresholdEt_(config.getParameter<double>("mvaThresholdEt")) {
58  mvaEstimatorB_ = std::make_unique<PhotonXGBoostEstimator>(mvaFileXgbB_, mvaNTreeLimitB_);
59  mvaEstimatorE_ = std::make_unique<PhotonXGBoostEstimator>(mvaFileXgbE_, mvaNTreeLimitE_);
60  produces<reco::RecoEcalCandidateIsolationMap>();
61 }
62 
65  desc.add<edm::InputTag>("candTag", edm::InputTag("hltEgammaCandidatesUnseeded"));
66  desc.add<edm::InputTag>("inputTagR9", edm::InputTag("hltEgammaR9IDUnseeded", "r95x5"));
67  desc.add<edm::InputTag>("inputTagHoE", edm::InputTag("hltEgammaHoverEUnseeded"));
68  desc.add<edm::InputTag>("inputTagSigmaiEtaiEta",
69  edm::InputTag("hltEgammaClusterShapeUnseeded", "sigmaIEtaIEta5x5NoiseCleaned"));
70  desc.add<edm::InputTag>("inputTagE2x2", edm::InputTag("hltEgammaClusterShapeUnseeded", "e2x2"));
71  desc.add<edm::InputTag>("inputTagIso", edm::InputTag("hltEgammaEcalPFClusterIsoUnseeded"));
72  desc.add<edm::FileInPath>(
73  "mvaFileXgbB", edm::FileInPath("RecoEgamma/PhotonIdentification/data/XGBoost/Photon_NTL_168_Barrel_v1.bin"));
74  desc.add<edm::FileInPath>(
75  "mvaFileXgbE", edm::FileInPath("RecoEgamma/PhotonIdentification/data/XGBoost/Photon_NTL_158_Endcap_v1.bin"));
76  desc.add<unsigned int>("mvaNTreeLimitB", 168);
77  desc.add<unsigned int>("mvaNTreeLimitE", 158);
78  desc.add<double>("mvaThresholdEt", 0);
79  descriptions.addWithDefaultLabel(desc);
80 }
81 
83  const auto& recCollection = event.getHandle(candToken_);
84 
85  //get hold of r9 association map
86  const auto& r9Map = event.getHandle(tokenR9_);
87 
88  //get hold of HoE association map
89  const auto& hoEMap = event.getHandle(tokenHoE_);
90 
91  //get hold of isolated association map
92  const auto& sigmaiEtaiEtaMap = event.getHandle(tokenSigmaiEtaiEta_);
93 
94  //get hold of e2x2 (s4) association map
95  const auto& e2x2Map = event.getHandle(tokenE2x2_);
96 
97  //get hold of Ecal isolation association map
98  const auto& isoMap = event.getHandle(tokenIso_);
99 
100  //output
101  reco::RecoEcalCandidateIsolationMap mvaScoreMap(recCollection);
102 
103  for (size_t i = 0; i < recCollection->size(); i++) {
105 
106  float etaSC = ref->eta();
107 
108  float scEnergy = ref->superCluster()->energy();
109  float r9 = (*r9Map).find(ref)->val;
110  float hoe = (*hoEMap).find(ref)->val / scEnergy;
111  float siEtaiEta = (*sigmaiEtaiEtaMap).find(ref)->val;
112  float e2x2 = (*e2x2Map).find(ref)->val;
113  float s4 = e2x2 / scEnergy;
114  float iso = (*isoMap).find(ref)->val;
115 
116  float rawEnergy = ref->superCluster()->rawEnergy();
117  float etaW = ref->superCluster()->etaWidth();
118  float phiW = ref->superCluster()->phiWidth();
119 
120  float scEt = scEnergy / cosh(etaSC);
121  if (scEt < 0.)
122  scEt = 0.; /* first and second order terms assume non-negative energies */
123 
124  float xgbScore = -100.;
125  //compute only above threshold used for training and cand filter, else store negative value into the association map.
126  if (scEt >= mvaThresholdEt_) {
127  if (std::abs(etaSC) < 1.5)
128  xgbScore = mvaEstimatorB_->computeMva(rawEnergy, r9, siEtaiEta, etaW, phiW, s4, etaSC, hoe, iso);
129  else
130  xgbScore = mvaEstimatorE_->computeMva(rawEnergy, r9, siEtaiEta, etaW, phiW, s4, etaSC, hoe, iso);
131  }
132  mvaScoreMap.insert(ref, xgbScore);
133  }
134  event.put(std::make_unique<reco::RecoEcalCandidateIsolationMap>(mvaScoreMap));
135 }
136 
std::unique_ptr< PhotonXGBoostEstimator > mvaEstimatorB_
~PhotonXGBoostProducer()=default
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
const edm::EDGetTokenT< reco::RecoEcalCandidateIsolationMap > tokenR9_
const edm::FileInPath mvaFileXgbB_
edm::AssociationMap< edm::OneToValue< std::vector< reco::RecoEcalCandidate >, float > > RecoEcalCandidateIsolationMap
const edm::EDGetTokenT< reco::RecoEcalCandidateIsolationMap > tokenSigmaiEtaiEta_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const edm::FileInPath mvaFileXgbE_
Definition: config.py:1
PhotonXGBoostProducer(edm::ParameterSet const &)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void produce(edm::StreamID, edm::Event &, edm::EventSetup const &) const override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDGetTokenT< reco::RecoEcalCandidateIsolationMap > tokenE2x2_
std::unique_ptr< PhotonXGBoostEstimator > mvaEstimatorE_
void insert(const key_type &k, const data_type &v)
insert an association
const edm::EDGetTokenT< reco::RecoEcalCandidateIsolationMap > tokenIso_
std::vector< RecoEcalCandidate > RecoEcalCandidateCollection
collectin of RecoEcalCandidate objects
fixed size matrix
HLT enums.
const edm::EDGetTokenT< reco::RecoEcalCandidateCollection > candToken_
const edm::EDGetTokenT< reco::RecoEcalCandidateIsolationMap > tokenHoE_
Definition: event.py:1