test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PhotonEnergyCalibratorRun2.cc
Go to the documentation of this file.
2 #include <CLHEP/Random/RandGaussQ.h>
6 
8  std::string correctionFile
9  ) :
10  isMC_(isMC), synchronization_(synchronization),
11  rng_(0),
12  _correctionRetriever(correctionFile) // here is opening the files and reading thecorrections
13 {}
14 
16 {}
17 
19  rng_ = rnd;
20 }
21 
22 void PhotonEnergyCalibratorRun2::calibrate(reco::Photon &photon, unsigned int runNumber, edm::StreamID const &id) const {
23  SimplePhoton simple(photon, runNumber, isMC_);
24  calibrate(simple, id);
25  simple.writeTo(photon);
26 }
27 
29  assert(isMC_ == photon.isMC());
30  float smear = 0.0, scale = 1.0;
31  float aeta = std::abs(photon.getEta()); //, r9 = photon.getR9();
32  float et = photon.getNewEnergy()/cosh(aeta);
33 
34  scale = _correctionRetriever.ScaleCorrection(photon.getRunNumber(), photon.isEB(), photon.getR9(), aeta, et);
35  smear = _correctionRetriever.getSmearingSigma(photon.getRunNumber(), photon.isEB(), photon.getR9(), aeta, et, 0., 0.);
36 
37  double newEcalEnergy, newEcalEnergyError;
38  if (isMC_) {
39  double corr = 1.0 + smear * gauss(id);
40  newEcalEnergy = photon.getNewEnergy() * corr;
41  newEcalEnergyError = std::hypot(photon.getNewEnergyError() * corr, smear * newEcalEnergy);
42  } else {
43  newEcalEnergy = photon.getNewEnergy() * scale;
44  newEcalEnergyError = std::hypot(photon.getNewEnergyError() * scale, smear * newEcalEnergy);
45  }
46  photon.setNewEnergy(newEcalEnergy);
47  photon.setNewEnergyError(newEcalEnergyError);
48 
49 }
50 
52  if (synchronization_) return 1.0;
53  if (rng_) {
54  return rng_->Gaus();
55  } else {
57  if ( !rng.isAvailable() ) {
58  throw cms::Exception("Configuration")
59  << "XXXXXXX requires the RandomNumberGeneratorService\n"
60  "which is not present in the configuration file. You must add the service\n"
61  "in the configuration file or remove the modules that require it.";
62  }
63  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
64  return gaussDistribution.fire();
65  }
66 }
67 
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
assert(m_qm.get())
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:46
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
void calibrate(SimplePhoton &photon, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
void writeTo(reco::Photon &out) const
Definition: SimplePhoton.cc:20