Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:34:20

0001 #ifndef RecoEgamma_EgammaTools_ElectronEnergyCalibrator_h
0002 #define RecoEgamma_EgammaTools_ElectronEnergyCalibrator_h
0003 
0004 //author: Alan Smithee
0005 //description:
0006 //  this class allows the residual scale and smearing to be applied to electrons
0007 //  the scale and smearing is on the ecal part of the energy
0008 //  hence the E/p combination needs to be re-don, hence the E/p Combination Tools
0009 //  it re-applies the regression with the new corrected ecal energy
0010 //  returns a vector of calibrated energies and correction data, indexed by EGEnergySysIndex
0011 //  a port of EgammaAnalysis/ElectronTools/ElectronEnergyCalibratorRun2
0012 
0013 #include "FWCore/Utilities/interface/StreamID.h"
0014 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
0015 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
0016 #include "RecoEgamma/EgammaTools/interface/EnergyScaleCorrection.h"
0017 #include "RecoEgamma/EgammaTools/interface/EpCombinationTool.h"
0018 #include "RecoEgamma/EgammaTools/interface/EGEnergySysIndex.h"
0019 
0020 #include <TRandom.h>
0021 
0022 #include <vector>
0023 
0024 class ElectronEnergyCalibrator {
0025 public:
0026   enum class EventType {
0027     DATA,
0028     MC,
0029   };
0030 
0031   ElectronEnergyCalibrator() {}
0032   ElectronEnergyCalibrator(const EpCombinationTool& combinator, const std::string& correctionFile);
0033   ~ElectronEnergyCalibrator() {}
0034 
0035   /// Initialize with a random number generator (if not done, it will use the CMSSW service)
0036   /// Caller code owns the TRandom.
0037   void initPrivateRng(TRandom* rnd);
0038 
0039   //set the minimum et to apply the correction to
0040   void setMinEt(float val) { minEt_ = val; }
0041 
0042   /// Correct this electron.
0043   /// StreamID is needed when used with CMSSW Random Number Generator
0044   std::array<float, EGEnergySysIndex::kNrSysErrs> calibrate(reco::GsfElectron& ele,
0045                                                             const unsigned int runNumber,
0046                                                             const EcalRecHitCollection* recHits,
0047                                                             edm::StreamID const& id,
0048                                                             const EventType eventType) const;
0049 
0050   std::array<float, EGEnergySysIndex::kNrSysErrs> calibrate(reco::GsfElectron& ele,
0051                                                             const unsigned int runNumber,
0052                                                             const EcalRecHitCollection* recHits,
0053                                                             const float smearNrSigma,
0054                                                             const EventType eventType) const;
0055 
0056 private:
0057   void setEnergyAndSystVarations(const float scale,
0058                                  const float smearNrSigma,
0059                                  const float et,
0060                                  const EnergyScaleCorrection::ScaleCorrection& scaleCorr,
0061                                  const EnergyScaleCorrection::SmearCorrection& smearCorr,
0062                                  reco::GsfElectron& ele,
0063                                  std::array<float, EGEnergySysIndex::kNrSysErrs>& energyData) const;
0064 
0065   void setEcalEnergy(reco::GsfElectron& ele, const float scale, const float smear) const;
0066   std::pair<float, float> calCombinedMom(reco::GsfElectron& ele, const float scale, const float smear) const;
0067 
0068   /// Return a number distributed as a unit gaussian, drawn from the private RNG if initPrivateRng was called,
0069   /// or from the CMSSW RandomNumberGenerator service
0070   /// If synchronization is set to true, it returns a fixed number (1.0)
0071   double gauss(edm::StreamID const& id) const;
0072 
0073   // whatever data will be needed
0074   EnergyScaleCorrection correctionRetriever_;
0075   const EpCombinationTool* epCombinationTool_;  //this is not owned
0076   TRandom* rng_;                                //this is not owned
0077   float minEt_;
0078 
0079   //default values to access if no correction available
0080   static const EnergyScaleCorrection::ScaleCorrection defaultScaleCorr_;
0081   static const EnergyScaleCorrection::SmearCorrection defaultSmearCorr_;
0082 };
0083 
0084 #endif