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 }
PhotonEnergyCalibratorRun2::rng_
TRandom * rng_
Definition: PhotonEnergyCalibratorRun2.h:38
PhotonEnergyCalibratorRun2.h
edm::StreamID
Definition: StreamID.h:30
muons2muons_cfi.photon
photon
Definition: muons2muons_cfi.py:28
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
RandomNumberGenerator.h
cms::cuda::assert
assert(be >=bs)
SimplePhoton::writeTo
void writeTo(reco::Photon &out) const
Definition: SimplePhoton.cc:20
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
PhotonEnergyCalibratorRun2::isMC_
bool isMC_
Definition: PhotonEnergyCalibratorRun2.h:37
submitPVValidationJobs.isMC
list isMC
Definition: submitPVValidationJobs.py:658
calibratedElectronsRun2_cfi.correctionFile
correctionFile
Definition: calibratedElectronsRun2_cfi.py:21
PhotonEnergyCalibratorRun2::gauss
double gauss(edm::StreamID const &id) const
Definition: PhotonEnergyCalibratorRun2.cc:56
EnergyScaleCorrection_class::doSmearings
bool doSmearings
Definition: EnergyScaleCorrection_class.h:124
EnergyScaleCorrection_class::getSmearingSigma
float getSmearingSigma(int runNumber, bool isEBEle, float R9Ele, float etaSCEle, float EtEle, paramSmear_t par, float nSigma=0.) const
Definition: EnergyScaleCorrection_class.cc:336
alignCSCRings.corr
dictionary corr
Definition: alignCSCRings.py:124
Service.h
EnergyScaleCorrection_class::doScale
bool doScale
Definition: EnergyScaleCorrection_class.h:124
calibratedElectrons_cfi.synchronization
synchronization
Definition: calibratedElectrons_cfi.py:33
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
EnergyScaleCorrection_class::ScaleCorrection
float ScaleCorrection(unsigned int runNumber, bool isEBEle, double R9Ele, double etaSCEle, double EtEle) const
method to get energy scale corrections
Definition: EnergyScaleCorrection_class.cc:44
PhotonEnergyCalibratorRun2::synchronization_
bool synchronization_
Definition: PhotonEnergyCalibratorRun2.h:37
edm::Service< edm::RandomNumberGenerator >
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
reco::Photon
Definition: Photon.h:21
Exception
Definition: hltDiff.cc:246
SimplePhoton
Definition: SimplePhoton.h:8
Exception.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
PhotonEnergyCalibratorRun2::calibrate
void calibrate(SimplePhoton &photon, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
Definition: PhotonEnergyCalibratorRun2.cc:34
PhotonEnergyCalibratorRun2::_correctionRetriever
EnergyScaleCorrection_class _correctionRetriever
Definition: PhotonEnergyCalibratorRun2.h:46
PhotonEnergyCalibratorRun2::initPrivateRng
void initPrivateRng(TRandom *rnd)
Definition: PhotonEnergyCalibratorRun2.cc:24
PhotonEnergyCalibratorRun2::~PhotonEnergyCalibratorRun2
~PhotonEnergyCalibratorRun2()
Definition: PhotonEnergyCalibratorRun2.cc:22
PhotonEnergyCalibratorRun2::PhotonEnergyCalibratorRun2
PhotonEnergyCalibratorRun2()
Definition: PhotonEnergyCalibratorRun2.h:14