Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:26

0001 #ifndef JetMETCorrections_FFTJetObjects_FFTJetCorrector_h
0002 #define JetMETCorrections_FFTJetObjects_FFTJetCorrector_h
0003 
0004 #include <memory>
0005 #include <vector>
0006 
0007 #include "JetMETCorrections/FFTJetObjects/interface/AbsFFTJetAdjuster.h"
0008 #include "JetMETCorrections/FFTJetObjects/interface/AbsFFTJetScaleCalculator.h"
0009 #include "JetMETCorrections/FFTJetObjects/interface/FFTJetCorrectorApp.h"
0010 
0011 template <class Jet, class Adjustable>
0012 class FFTJetCorrector {
0013 public:
0014   typedef Jet jet_type;
0015   typedef Adjustable adjustable_type;
0016   typedef AbsFFTJetScaleCalculator<jet_type, adjustable_type> AbsScaler;
0017   typedef AbsFFTJetAdjuster<jet_type, adjustable_type> AbsAdjuster;
0018 
0019   inline FFTJetCorrector(std::shared_ptr<const AbsAdjuster> adjuster,
0020                          const std::vector<std::shared_ptr<const AbsScaler> >& scalers,
0021                          const unsigned i_level,
0022                          const FFTJetCorrectorApp a)
0023       : adjuster_(adjuster), scalers_(scalers), level_(i_level), app_(a) {}
0024 
0025   inline void correct(const Jet& jet, const bool isMC, const Adjustable& in, Adjustable* out) const {
0026     if ((isMC && app_ == FFTJetCorrectorApp::DATA_ONLY) || (!isMC && app_ == FFTJetCorrectorApp::MC_ONLY))
0027       // Do not need to apply this corrector. Simply copy
0028       // the transient data from the input to the output.
0029       *out = in;
0030     else {
0031       const unsigned nAdj = scalers_.size();
0032       //If we only need a small buffer, use one on the stack
0033       // else we will use a std::vector
0034       constexpr size_t kStaticBufferSize = 10;
0035       double staticBuffer[kStaticBufferSize];
0036       std::vector<double> dynamicBuffer;
0037       double* buf = nullptr;
0038       if (nAdj <= kStaticBufferSize) {
0039         buf = &(staticBuffer[0]);
0040       } else {
0041         dynamicBuffer.resize(nAdj);
0042         buf = &(dynamicBuffer[0]);
0043       }
0044       for (unsigned i = 0; i < nAdj; ++i)
0045         buf[i] = scalers_[i]->scale(jet, in);
0046       adjuster_->adjust(jet, in, buf, nAdj, out);
0047     }
0048   }
0049 
0050   inline unsigned level() const { return level_; }
0051   inline FFTJetCorrectorApp app() const { return app_; }
0052 
0053 private:
0054   std::shared_ptr<const AbsAdjuster> adjuster_;
0055   std::vector<std::shared_ptr<const AbsScaler> > scalers_;
0056   unsigned level_;
0057   FFTJetCorrectorApp app_;
0058 };
0059 
0060 #endif  // JetMETCorrections_FFTJetObjects_FFTJetCorrector_h