CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
33  SimpleElectron simple(electron, runNumber, isMC_);
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);
58  epCombinationTool_->combine(electron);
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 }
float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, paramSmear_t par, float nSigma=0.) const
void setNewEnergyError(double newEnergyError)
void setNewEnergy(double newEnergy)
void combine(SimpleElectron &mySimpleElectron) const
double gauss(edm::StreamID const &id) const
float ScaleCorrection(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const
method to get energy scale corrections
assert(be >=bs)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
double getNewEnergy() const
void calibrate(SimpleElectron &electron, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
bool isMC() const
unsigned int getRunNumber() const
double getNewEnergyError() const
void writeTo(reco::GsfElectron &out) const
EnergyScaleCorrection_class _correctionRetriever
bool isAvailable() const
Definition: Service.h:40
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double getEta() const
float getR9() const
tuple correctionFile
bool isEB() const