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 {
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 }
void calibrate(SimplePhoton &photon, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
assert(be >=bs)
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
double gauss(edm::StreamID const &id) const
dictionary corr
float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, paramSmear_t par, float nSigma=0.) 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 writeTo(reco::Photon &out) const
Definition: SimplePhoton.cc:20
EnergyScaleCorrection_class _correctionRetriever
bool isAvailable() const
Definition: Service.h:40