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,
10  std::string correctionFile
11  ) :
12  epCombinationTool_(&combinator),
13  isMC_(isMC), synchronization_(synchronization),
14  rng_(0),
15  _correctionRetriever(correctionFile) // here is opening the files and reading the corrections
16 {
17  if(isMC_) {
20  } else {
23  }
24 }
25 
27 {}
28 
30 {
31  rng_ = rnd;
32 }
33 
35 {
36  SimpleElectron simple(electron, runNumber, isMC_);
37  calibrate(simple, id);
38  simple.writeTo(electron);
39 }
41 {
42  assert(isMC_ == electron.isMC());
43  float smear = 0.0, scale = 1.0;
44  float aeta = std::abs(electron.getEta()); //, r9 = electron.getR9();
45  float et = electron.getNewEnergy()/cosh(aeta);
46 
47  scale = _correctionRetriever.ScaleCorrection(electron.getRunNumber(), electron.isEB(), electron.getR9(), aeta, et);
48  smear = _correctionRetriever.getSmearingSigma(electron.getRunNumber(), electron.isEB(), electron.getR9(), aeta, et, 0., 0.);
49 
50  double newEcalEnergy, newEcalEnergyError;
51  if (isMC_) {
52  double corr = 1.0 + smear * gauss(id);
53  newEcalEnergy = electron.getNewEnergy() * corr;
54  newEcalEnergyError = std::hypot(electron.getNewEnergyError() * corr, smear * newEcalEnergy);
55  } else {
56  newEcalEnergy = electron.getNewEnergy() * scale;
57  newEcalEnergyError = std::hypot(electron.getNewEnergyError() * scale, smear * newEcalEnergy);
58  }
59  electron.setNewEnergy(newEcalEnergy);
60  electron.setNewEnergyError(newEcalEnergyError);
61  epCombinationTool_->combine(electron);
62 }
63 
65 {
66  if (synchronization_) return 1.0;
67  if (rng_) {
68  return rng_->Gaus();
69  } else {
71  if ( !rng.isAvailable() ) {
72  throw cms::Exception("Configuration")
73  << "XXXXXXX requires the RandomNumberGeneratorService\n"
74  "which is not present in the configuration file. You must add the service\n"
75  "in the configuration file or remove the modules that require it.";
76  }
77  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
78  return gaussDistribution.fire();
79  }
80 }
81 
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
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:46
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double getEta() const
float getR9() const
JetCorrectorParameters corr
Definition: classes.h:5
et
define resolution functions of each parameter
bool isEB() const