CMS 3D CMS Logo

PhotonEnergyCalibratorRun2.cc
Go to the documentation of this file.
2 #include <CLHEP/Random/RandGaussQ.h>
6 
8  : isMC_(isMC),
9  synchronization_(synchronization),
10  rng_(nullptr),
11  _correctionRetriever(correctionFile) // here is opening the files and reading thecorrections
12 {
13  if (isMC_) {
16  } else {
19  }
20 }
21 
23 
24 void PhotonEnergyCalibratorRun2::initPrivateRng(TRandom *rnd) { rng_ = rnd; }
25 
27  unsigned int runNumber,
28  edm::StreamID const &id) const {
29  SimplePhoton simple(photon, runNumber, isMC_);
30  calibrate(simple, id);
31  simple.writeTo(photon);
32 }
33 
35  assert(isMC_ == photon.isMC());
36  float smear = 0.0, scale = 1.0;
37  float aeta = std::abs(photon.getEta()); //, r9 = photon.getR9();
38  float et = photon.getNewEnergy() / cosh(aeta);
39 
40  scale = _correctionRetriever.ScaleCorrection(photon.getRunNumber(), photon.isEB(), photon.getR9(), aeta, et);
41  smear = _correctionRetriever.getSmearingSigma(photon.getRunNumber(), photon.isEB(), photon.getR9(), aeta, et, 0., 0.);
42 
43  double newEcalEnergy, newEcalEnergyError;
44  if (isMC_) {
45  double corr = 1.0 + smear * gauss(id);
46  newEcalEnergy = photon.getNewEnergy() * corr;
47  newEcalEnergyError = std::hypot(photon.getNewEnergyError() * corr, smear * newEcalEnergy);
48  } else {
49  newEcalEnergy = photon.getNewEnergy() * scale;
50  newEcalEnergyError = std::hypot(photon.getNewEnergyError() * scale, smear * newEcalEnergy);
51  }
52  photon.setNewEnergy(newEcalEnergy);
53  photon.setNewEnergyError(newEcalEnergyError);
54 }
55 
57  if (synchronization_)
58  return 1.0;
59  if (rng_) {
60  return rng_->Gaus();
61  } else {
63  if (!rng.isAvailable()) {
64  throw cms::Exception("Configuration")
65  << "XXXXXXX requires the RandomNumberGeneratorService\n"
66  "which is not present in the configuration file. You must add the service\n"
67  "in the configuration file or remove the modules that require it.";
68  }
69  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
70  return gaussDistribution.fire();
71  }
72 }
float getR9() const
Definition: SimplePhoton.h:52
float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, paramSmear_t par, float nSigma=0.) const
double getNewEnergy() const
Definition: SimplePhoton.h:43
int getRunNumber() const
Definition: SimplePhoton.h:54
#define nullptr
void setNewEnergyError(double newEnergyError)
Definition: SimplePhoton.h:60
float ScaleCorrection(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const
method to get energy scale corrections
double getEta() const
Definition: SimplePhoton.h:51
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
bool isAvailable() const
Definition: Service.h:40
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double getNewEnergyError() const
Definition: SimplePhoton.h:44
double gauss(edm::StreamID const &id) const
JetCorrectorParameters corr
Definition: classes.h:5
void setNewEnergy(double newEnergy)
Definition: SimplePhoton.h:59
bool isEB() const
Definition: SimplePhoton.h:55
bool isMC() const
Definition: SimplePhoton.h:56
EnergyScaleCorrection_class _correctionRetriever
void calibrate(SimplePhoton &photon, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
void writeTo(reco::Photon &out) const
Definition: SimplePhoton.cc:20