CMS 3D CMS Logo

FFTJetCorrector.h
Go to the documentation of this file.
1 #ifndef JetMETCorrections_FFTJetObjects_FFTJetCorrector_h
2 #define JetMETCorrections_FFTJetObjects_FFTJetCorrector_h
3 
4 #include <memory>
5 #include <vector>
6 
10 
11 template<class Jet, class Adjustable>
13 {
14 public:
15  typedef Jet jet_type;
16  typedef Adjustable adjustable_type;
19 
20  inline FFTJetCorrector(std::shared_ptr<const AbsAdjuster> adjuster,
21  const std::vector<std::shared_ptr<const AbsScaler> >& scalers,
22  const unsigned i_level, const FFTJetCorrectorApp a)
23  : adjuster_(adjuster), scalers_(scalers),
24  level_(i_level), app_(a) {}
25 
26  inline void correct(const Jet& jet, const bool isMC,
27  const Adjustable& in, Adjustable* out) const
28  {
29  if ((isMC && app_ == FFTJetCorrectorApp::DATA_ONLY) ||
30  (!isMC && app_ == FFTJetCorrectorApp::MC_ONLY))
31  // Do not need to apply this corrector. Simply copy
32  // the transient data from the input to the output.
33  *out = in;
34  else
35  {
36  const unsigned nAdj = scalers_.size();
37  //If we only need a small buffer, use one on the stack
38  // else we will use a std::vector
39  constexpr size_t kStaticBufferSize = 10;
40  double staticBuffer[kStaticBufferSize];
41  std::vector<double> dynamicBuffer;
42  double* buf = nullptr;
43  if(nAdj<=kStaticBufferSize) {
44  buf = &(staticBuffer[0]);
45  } else {
46  dynamicBuffer.resize(nAdj);
47  buf = &(dynamicBuffer[0]);
48  }
49  for (unsigned i=0; i<nAdj; ++i)
50  buf[i] = scalers_[i]->scale(jet, in);
51  adjuster_->adjust(jet, in, buf, nAdj, out);
52  }
53  }
54 
55  inline unsigned level() const {return level_;}
56  inline FFTJetCorrectorApp app() const {return app_;}
57 
58 private:
59  std::shared_ptr<const AbsAdjuster> adjuster_;
60  std::vector<std::shared_ptr<const AbsScaler> > scalers_;
61  unsigned level_;
63 };
64 
65 #endif // JetMETCorrections_FFTJetObjects_FFTJetCorrector_h
std::shared_ptr< const AbsAdjuster > adjuster_
void correct(const Jet &jet, const bool isMC, const Adjustable &in, Adjustable *out) const
unsigned level() const
std::vector< std::shared_ptr< const AbsScaler > > scalers_
FFTJetCorrector(std::shared_ptr< const AbsAdjuster > adjuster, const std::vector< std::shared_ptr< const AbsScaler > > &scalers, const unsigned i_level, const FFTJetCorrectorApp a)
FFTJetCorrectorApp app_
FFTJetCorrectorApp
Definition: Jet.py:1
AbsFFTJetAdjuster< jet_type, adjustable_type > AbsAdjuster
Adjustable adjustable_type
AbsFFTJetScaleCalculator< jet_type, adjustable_type > AbsScaler
double a
Definition: hdecay.h:121
#define constexpr
FFTJetCorrectorApp app() const