CMS 3D CMS Logo

EGRegressionModifierDRN.cc
Go to the documentation of this file.
2 
5 
11 
13 
15 
18 
21 
25 
28 
29 /*
30  * EGRegressionModifierDRN
31  *
32  * Object modifier to apply DRN regression.
33  * Designed to be a drop-in replacement for EGRegressionModifierVX
34  *
35  * Requires the appropriate DRNCorrectionProducerX(s) to also be in the path
36  * You can specify which of reco::GsfElectron, reco::Photon, pat::Electron, pat::Photon
37  * to apply corrections to in the config
38  *
39  */
40 
42 public:
44 
45  void setEvent(const edm::Event&) final;
46  void setEventContent(const edm::EventSetup&) final;
47 
48  void modifyObject(reco::GsfElectron&) const final;
49  void modifyObject(reco::Photon&) const final;
50 
51  void modifyObject(pat::Electron&) const final;
52  void modifyObject(pat::Photon&) const final;
53 
54 private:
55  template <typename T>
56  struct partVars {
60 
64 
65  bool userFloat;
67 
68  unsigned i;
69 
71  source = config.getParameter<edm::InputTag>("source");
72  token = cc.consumes(source);
73 
74  correctionsSource = config.getParameter<edm::InputTag>("correctionsSource");
76 
77  if (config.exists("energyFloat")) {
78  userFloat = true;
79  energyFloat = config.getParameter<std::string>("energyFloat");
80  resFloat = config.getParameter<std::string>("resFloat");
81  } else {
82  userFloat = false;
83  }
84 
85  i = 0;
86  }
87 
88  const std::pair<float, float> getCorrection(T& part);
89 
90  const void doUserFloat(T& part, const std::pair<float, float>& correction) const {
91  part.addUserFloat(energyFloat, correction.first);
92  part.addUserFloat(resFloat, correction.second);
93  }
94  };
95 
96  std::unique_ptr<partVars<pat::Photon>> patPhotons_;
97  std::unique_ptr<partVars<pat::Electron>> patElectrons_;
98  std::unique_ptr<partVars<reco::Photon>> gedPhotons_;
99  std::unique_ptr<partVars<reco::GsfElectron>> gsfElectrons_;
100 };
101 
103  : ModifyObjectValueBase(conf) {
104  if (conf.exists("patPhotons")) {
105  patPhotons_ = std::make_unique<partVars<pat::Photon>>(conf.getParameterSet("patPhotons"), cc);
106  }
107 
108  if (conf.exists("gedPhotons")) {
109  gedPhotons_ = std::make_unique<partVars<reco::Photon>>(conf.getParameterSet("gedPhotons"), cc);
110  }
111 
112  if (conf.exists("patElectrons")) {
113  patElectrons_ = std::make_unique<partVars<pat::Electron>>(conf.getParameterSet("patElectrons"), cc);
114  }
115 
116  if (conf.exists("gsfElectrons")) {
117  gsfElectrons_ = std::make_unique<partVars<reco::GsfElectron>>(conf.getParameterSet("gsfElectrons"), cc);
118  }
119 }
120 
122  if (patElectrons_) {
123  patElectrons_->particles = &evt.get(patElectrons_->token);
124  patElectrons_->corrections = &evt.get(patElectrons_->correctionsToken);
125  patElectrons_->i = 0;
126  }
127 
128  if (patPhotons_) {
129  patPhotons_->particles = &evt.get(patPhotons_->token);
130  patPhotons_->corrections = &evt.get(patPhotons_->correctionsToken);
131  patPhotons_->i = 0;
132  }
133 
134  if (gsfElectrons_) {
135  gsfElectrons_->particles = &evt.get(gsfElectrons_->token);
136  gsfElectrons_->corrections = &evt.get(gsfElectrons_->correctionsToken);
137  gsfElectrons_->i = 0;
138  }
139 
140  if (gedPhotons_) {
141  gedPhotons_->particles = &evt.get(gedPhotons_->token);
142  gedPhotons_->corrections = &evt.get(gedPhotons_->correctionsToken);
143  gedPhotons_->i = 0;
144  }
145 }
146 
148 
150  if (!gsfElectrons_)
151  return;
152 
153  const std::pair<float, float>& correction = gsfElectrons_->getCorrection(ele);
154 
155  if (correction.first > 0 && correction.second > 0) {
156  ele.setCorrectedEcalEnergy(correction.first, true);
158  }
159 
160  throw cms::Exception("EGRegressionModifierDRN")
161  << "Electron energy corrections not fully implemented yet:" << std::endl
162  << "Still need E/p combination" << std::endl
163  << "Do not enable DRN for electrons" << std::endl;
164 }
165 
167  if (!patElectrons_)
168  return;
169 
170  const std::pair<float, float>& correction = patElectrons_->getCorrection(ele);
171 
172  if (patElectrons_->userFloat) {
173  patElectrons_->doUserFloat(ele, correction);
174  } else if (correction.first > 0 && correction.second > 0) {
175  ele.setCorrectedEcalEnergy(correction.first, true);
177  }
178 
179  throw cms::Exception("EGRegressionModifierDRN")
180  << "Electron energy corrections not fully implemented yet:" << std::endl
181  << "Still need E/p combination" << std::endl
182  << "Do not enable DRN for electrons" << std::endl;
183 }
184 
186  if (!patPhotons_)
187  return;
188 
189  const std::pair<float, float>& correction = patPhotons_->getCorrection(pho);
190 
191  if (patPhotons_->userFloat) {
192  patPhotons_->doUserFloat(pho, correction);
193  } else if (correction.first > 0 && correction.second > 0) {
194  pho.setCorrectedEnergy(pat::Photon::P4type::regression2, correction.first, correction.second, true);
195  }
196 }
197 
199  if (!gedPhotons_)
200  return;
201 
202  const std::pair<float, float>& correction = gedPhotons_->getCorrection(pho);
203 
204  if (correction.first > 0 && correction.second > 0) {
205  pho.setCorrectedEnergy(reco::Photon::P4type::regression2, correction.first, correction.second, true);
206  }
207 };
208 
209 template <typename T>
211  edm::Ptr<T> ptr = particles->ptrAt(i++);
212 
213  std::pair<float, float> correction = (*corrections)[ptr];
214 
215  return correction;
216 }
217 
const void doUserFloat(T &part, const std::pair< float, float > &correction) const
Analysis-level Photon class.
Definition: Photon.h:46
void modifyObject(reco::GsfElectron &) const final
bool get(ProductID const &oid, Handle< PROD > &result) const
Definition: Event.h:347
void setCorrectedEnergy(P4type type, float E, float dE, bool toCand=true)
std::unique_ptr< partVars< pat::Electron > > patElectrons_
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
bool exists(std::string const &parameterName) const
checks if a parameter exists
ParameterSet const & getParameterSet(std::string const &) const
void setEventContent(const edm::EventSetup &) final
Definition: config.py:1
edm::EDGetTokenT< edm::View< T > > token
partVars(const edm::ParameterSet &config, edm::ConsumesCollector &cc)
void setCorrectedEcalEnergyError(float newEnergyError)
Definition: GsfElectron.cc:170
std::unique_ptr< partVars< reco::GsfElectron > > gsfElectrons_
std::unique_ptr< partVars< pat::Photon > > patPhotons_
const edm::ValueMap< std::pair< float, float > > * corrections
std::unique_ptr< partVars< reco::Photon > > gedPhotons_
EGRegressionModifierDRN(const edm::ParameterSet &conf, edm::ConsumesCollector &cc)
edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > correctionsToken
part
Definition: HCALResponse.h:20
const std::pair< float, float > getCorrection(T &part)
Analysis-level electron class.
Definition: Electron.h:51
void setCorrectedEcalEnergy(float newEnergy)
Definition: GsfElectron.cc:174
void setEvent(const edm::Event &) final
#define DEFINE_EDM_PLUGIN(factory, type, name)
long double T