Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:02

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