CMS 3D CMS Logo

ElectronEnergyCalibratorRun2.cc
Go to the documentation of this file.
2 #include <CLHEP/Random/RandGaussQ.h>
6 
8  bool isMC,
9  bool synchronization,
11  : epCombinationTool_(&combinator),
12  isMC_(isMC),
13  synchronization_(synchronization),
14  rng_(nullptr),
15  _correctionRetriever(correctionFile) // here is opening the files and reading the corrections
16 {
17  if (isMC_) {
20  } else {
23  }
24 }
25 
27 
29 
31  unsigned int runNumber,
32  edm::StreamID const &id) const {
34  calibrate(simple, id);
35  simple.writeTo(electron);
36 }
38  assert(isMC_ == electron.isMC());
39  float smear = 0.0, scale = 1.0;
40  float aeta = std::abs(electron.getEta()); //, r9 = electron.getR9();
41  float et = electron.getNewEnergy() / cosh(aeta);
42 
43  scale = _correctionRetriever.ScaleCorrection(electron.getRunNumber(), electron.isEB(), electron.getR9(), aeta, et);
45  electron.getRunNumber(), electron.isEB(), electron.getR9(), aeta, et, 0., 0.);
46 
47  double newEcalEnergy, newEcalEnergyError;
48  if (isMC_) {
49  double corr = 1.0 + smear * gauss(id);
50  newEcalEnergy = electron.getNewEnergy() * corr;
51  newEcalEnergyError = std::hypot(electron.getNewEnergyError() * corr, smear * newEcalEnergy);
52  } else {
53  newEcalEnergy = electron.getNewEnergy() * scale;
54  newEcalEnergyError = std::hypot(electron.getNewEnergyError() * scale, smear * newEcalEnergy);
55  }
56  electron.setNewEnergy(newEcalEnergy);
57  electron.setNewEnergyError(newEcalEnergyError);
59 }
60 
62  if (synchronization_)
63  return 1.0;
64  if (rng_) {
65  return rng_->Gaus();
66  } else {
68  if (!rng.isAvailable()) {
69  throw cms::Exception("Configuration")
70  << "XXXXXXX requires the RandomNumberGeneratorService\n"
71  "which is not present in the configuration file. You must add the service\n"
72  "in the configuration file or remove the modules that require it.";
73  }
74  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
75  return gaussDistribution.fire();
76  }
77 }
MPlex< T, D1, D2, N > hypot(const MPlex< T, D1, D2, N > &a, const MPlex< T, D1, D2, N > &b)
Definition: Matriplex.h:417
void combine(SimpleElectron &mySimpleElectron) const
assert(be >=bs)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
void writeTo(reco::GsfElectron &out) const
dictionary corr
dictionary isMC
Definition: PV_cfg.py:29
EnergyScaleCorrection_class _correctionRetriever
float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, paramSmear_t par, float nSigma=0.) const
double gauss(edm::StreamID const &id) const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float ScaleCorrection(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const
method to get energy scale corrections
void calibrate(SimpleElectron &electron, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
bool isAvailable() const
Definition: Service.h:40