CMS 3D CMS Logo

ElectronEnergyCalibratorRun2.cc
Go to the documentation of this file.
2 #include <CLHEP/Random/RandGaussQ.h>
6 
8  bool isMC,
9  bool synchronization,
11  : epCombinationTool_(&combinator),
12  isMC_(isMC),
13  synchronization_(synchronization),
14  rng_(nullptr),
15  _correctionRetriever(correctionFile) // here is opening the files and reading the corrections
16 {
17  if (isMC_) {
20  } else {
23  }
24 }
25 
27 
29 
31  unsigned int runNumber,
32  edm::StreamID const &id) const {
34  calibrate(simple, id);
35  simple.writeTo(electron);
36 }
38  assert(isMC_ == electron.isMC());
39  float smear = 0.0, scale = 1.0;
40  float aeta = std::abs(electron.getEta()); //, r9 = electron.getR9();
41  float et = electron.getNewEnergy() / cosh(aeta);
42 
43  scale = _correctionRetriever.ScaleCorrection(electron.getRunNumber(), electron.isEB(), electron.getR9(), aeta, et);
45  electron.getRunNumber(), electron.isEB(), electron.getR9(), aeta, et, 0., 0.);
46 
47  double newEcalEnergy, newEcalEnergyError;
48  if (isMC_) {
49  double corr = 1.0 + smear * gauss(id);
50  newEcalEnergy = electron.getNewEnergy() * corr;
51  newEcalEnergyError = std::hypot(electron.getNewEnergyError() * corr, smear * newEcalEnergy);
52  } else {
53  newEcalEnergy = electron.getNewEnergy() * scale;
54  newEcalEnergyError = std::hypot(electron.getNewEnergyError() * scale, smear * newEcalEnergy);
55  }
56  electron.setNewEnergy(newEcalEnergy);
57  electron.setNewEnergyError(newEcalEnergyError);
59 }
60 
62  if (synchronization_)
63  return 1.0;
64  if (rng_) {
65  return rng_->Gaus();
66  } else {
68  if (!rng.isAvailable()) {
69  throw cms::Exception("Configuration")
70  << "XXXXXXX requires the RandomNumberGeneratorService\n"
71  "which is not present in the configuration file. You must add the service\n"
72  "in the configuration file or remove the modules that require it.";
73  }
74  CLHEP::RandGaussQ gaussDistribution(rng->getEngine(id), 0.0, 1.0);
75  return gaussDistribution.fire();
76  }
77 }
edm::StreamID
Definition: StreamID.h:30
edm::RandomNumberGenerator::getEngine
virtual CLHEP::HepRandomEngine & getEngine(StreamID const &)=0
Use this engine in event methods.
ElectronEnergyCalibratorRun2::gauss
double gauss(edm::StreamID const &id) const
Definition: ElectronEnergyCalibratorRun2.cc:61
L1EGammaCrystalsEmulatorProducer_cfi.scale
scale
Definition: L1EGammaCrystalsEmulatorProducer_cfi.py:10
RandomNumberGenerator.h
ElectronEnergyCalibratorRun2::_correctionRetriever
EnergyScaleCorrection_class _correctionRetriever
Definition: ElectronEnergyCalibratorRun2.h:45
cms::cuda::assert
assert(be >=bs)
ElectronEnergyCalibratorRun2::synchronization_
bool synchronization_
Definition: ElectronEnergyCalibratorRun2.h:38
EpCombinationTool::combine
void combine(SimpleElectron &mySimpleElectron) const
Definition: EpCombinationTool.cc:58
ElectronEnergyCalibratorRun2::rng_
TRandom * rng_
Definition: ElectronEnergyCalibratorRun2.h:39
ElectronEnergyCalibratorRun2::ElectronEnergyCalibratorRun2
ElectronEnergyCalibratorRun2()
Definition: ElectronEnergyCalibratorRun2.h:15
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
SimpleElectron
Definition: SimpleElectron.h:8
submitPVValidationJobs.isMC
list isMC
Definition: submitPVValidationJobs.py:658
calibratedElectronsRun2_cfi.correctionFile
correctionFile
Definition: calibratedElectronsRun2_cfi.py:21
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
metsig::electron
Definition: SignAlgoResolutions.h:48
ElectronEnergyCalibratorRun2.h
EnergyScaleCorrection_class::doScale
bool doScale
Definition: EnergyScaleCorrection_class.h:124
reco::GsfElectron
Definition: GsfElectron.h:35
calibratedElectrons_cfi.synchronization
synchronization
Definition: calibratedElectrons_cfi.py:33
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ElectronEnergyCalibratorRun2::epCombinationTool_
EpCombinationTool * epCombinationTool_
Definition: ElectronEnergyCalibratorRun2.h:37
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
ElectronEnergyCalibratorRun2::~ElectronEnergyCalibratorRun2
~ElectronEnergyCalibratorRun2()
Definition: ElectronEnergyCalibratorRun2.cc:26
ElectronEnergyCalibratorRun2::isMC_
bool isMC_
Definition: ElectronEnergyCalibratorRun2.h:38
ElectronEnergyCalibratorRun2::calibrate
void calibrate(SimpleElectron &electron, edm::StreamID const &id=edm::StreamID::invalidStreamID()) const
Definition: ElectronEnergyCalibratorRun2.cc:37
SimpleElectron::writeTo
void writeTo(reco::GsfElectron &out) const
Definition: SimpleElectron.cc:25
ElectronEnergyCalibratorRun2::initPrivateRng
void initPrivateRng(TRandom *rnd)
Definition: ElectronEnergyCalibratorRun2.cc:28
edm::Service< edm::RandomNumberGenerator >
EgHLTOffHistBins_cfi.et
et
Definition: EgHLTOffHistBins_cfi.py:8
Exception
Definition: hltDiff.cc:246
Exception.h
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EpCombinationTool
Definition: EpCombinationTool.h:10