CMS 3D CMS Logo

PhotonEnergyCalibratorRun2.cc
Go to the documentation of this file.
2 #include <CLHEP/Random/RandGaussQ.h>
6 
9  ) :
10  isMC_(isMC), synchronization_(synchronization),
11  rng_(nullptr),
12  _correctionRetriever(correctionFile) // here is opening the files and reading thecorrections
13 {
14  if(isMC_) {
17  } else {
20  }
21 }
22 
24 {}
25 
27  rng_ = rnd;
28 }
29 
31  SimplePhoton simple(photon, runNumber, isMC_);
32  calibrate(simple, id);
33  simple.writeTo(photon);
34 }
35 
37  assert(isMC_ == photon.isMC());
38  float smear = 0.0, scale = 1.0;
39  float aeta = std::abs(photon.getEta()); //, r9 = photon.getR9();
40  float et = photon.getNewEnergy()/cosh(aeta);
41 
42  scale = _correctionRetriever.ScaleCorrection(photon.getRunNumber(), photon.isEB(), photon.getR9(), aeta, et);
43  smear = _correctionRetriever.getSmearingSigma(photon.getRunNumber(), photon.isEB(), photon.getR9(), aeta, et, 0., 0.);
44 
45  double newEcalEnergy, newEcalEnergyError;
46  if (isMC_) {
47  double corr = 1.0 + smear * gauss(id);
48  newEcalEnergy = photon.getNewEnergy() * corr;
49  newEcalEnergyError = std::hypot(photon.getNewEnergyError() * corr, smear * newEcalEnergy);
50  } else {
51  newEcalEnergy = photon.getNewEnergy() * scale;
52  newEcalEnergyError = std::hypot(photon.getNewEnergyError() * scale, smear * newEcalEnergy);
53  }
54  photon.setNewEnergy(newEcalEnergy);
55  photon.setNewEnergyError(newEcalEnergyError);
56 
57 }
58 
60  if (synchronization_) return 1.0;
61  if (rng_) {
62  return rng_->Gaus();
63  } else {
65  if ( !rng.isAvailable() ) {
66  throw cms::Exception("Configuration")
67  << "XXXXXXX requires the RandomNumberGeneratorService\n"
68  "which is not present in the configuration file. You must add the service\n"
69  "in the configuration file or remove the modules that require it.";
70  }
71  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
72  return gaussDistribution.fire();
73  }
74 }
75 
float getR9() const
Definition: SimplePhoton.h:53
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:44
int getRunNumber() const
Definition: SimplePhoton.h:55
#define nullptr
void setNewEnergyError(double newEnergyError)
Definition: SimplePhoton.h:61
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:52
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:45
double gauss(edm::StreamID const &id) const
JetCorrectorParameters corr
Definition: classes.h:5
void setNewEnergy(double newEnergy)
Definition: SimplePhoton.h:60
bool isEB() const
Definition: SimplePhoton.h:56
bool isMC() const
Definition: SimplePhoton.h:57
EnergyScaleCorrection_class _correctionRetriever
et
define resolution functions of each parameter
void calibrate(SimplePhoton &photon, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
void writeTo(reco::Photon &out) const
Definition: SimplePhoton.cc:20