Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 //
0002 // A sequence of jet correction metods for FFTJet
0003 //
0004 // I. Volobouev, 08/02/2012
0005 //
0006 
0007 #ifndef JetMETCorrections_FFTJetObjects_FFTJetCorrectorSequence_h
0008 #define JetMETCorrections_FFTJetObjects_FFTJetCorrectorSequence_h
0009 
0010 #include "JetMETCorrections/FFTJetObjects/interface/FFTJetCorrector.h"
0011 
0012 //
0013 //  Both InitialConverter and FinalConverter must publish
0014 //  result_type typedef.
0015 //
0016 //  InitialConverter must have a method with the signature
0017 //  "result_type operator()(const Jet&) const". The
0018 //  variable of the type returned by this method will be
0019 //  propagated through the correction chain. This should
0020 //  be a simple type with copy constructor and assignment
0021 //  operator, for example "double" or "LorentzVector".
0022 //
0023 //  FinalConverter must have a method with the signature
0024 //  "result_type operator()(const Jet&, const T&) const",
0025 //  where T is now the result_type of InitialConverter.
0026 //  It can be a different result type from that defined
0027 //  in InitialConverter. result_type from FinalConverter
0028 //  will be the type of variable returned by the "correct"
0029 //  method of the FFTJetCorrectorSequence class.
0030 //
0031 template <class Jet, template <class> class InitialConverter, template <class> class FinalConverter>
0032 class FFTJetCorrectorSequence {
0033 public:
0034   typedef Jet jet_type;
0035   typedef typename InitialConverter<Jet>::result_type adjustable_type;
0036   typedef typename FinalConverter<Jet>::result_type result_type;
0037   typedef FFTJetCorrector<jet_type, adjustable_type> Corrector;
0038 
0039   inline FFTJetCorrectorSequence() {}
0040 
0041   inline FFTJetCorrectorSequence(const std::vector<Corrector>& s) : sequence_(s) {}
0042 
0043   inline FFTJetCorrectorSequence(const std::vector<Corrector>& s,
0044                                  const InitialConverter<Jet>& i,
0045                                  const FinalConverter<Jet>& f)
0046       : sequence_(s), cinit_(i), cfinal_(f) {}
0047 
0048   inline FFTJetCorrectorSequence(const InitialConverter<Jet>& i, const FinalConverter<Jet>& f)
0049       : cinit_(i), cfinal_(f) {}
0050 
0051   void clear() { sequence_.clear(); }
0052 
0053   inline void addCorrector(const Corrector& c) { sequence_.push_back(c); }
0054 
0055   inline unsigned nLevels() const { return sequence_.size(); }
0056 
0057   inline const std::vector<Corrector>& getCorrectors() const { return sequence_; }
0058 
0059   result_type correct(const Jet& jet, const bool isMC) const {
0060     adjustable_type a1(cinit_(jet));
0061     adjustable_type a2(a1);
0062     adjustable_type* first = &a1;
0063     adjustable_type* second = &a2;
0064 
0065     const unsigned nLevels = sequence_.size();
0066     for (unsigned level = 0; level < nLevels; ++level) {
0067       first = level % 2 ? &a2 : &a1;
0068       second = level % 2 ? &a1 : &a2;
0069       sequence_[level].correct(jet, isMC, *first, second);
0070     }
0071 
0072     return cfinal_(jet, *second);
0073   }
0074 
0075   const Corrector& operator[](const unsigned i) const { return sequence_.at(i); }
0076 
0077 private:
0078   std::vector<Corrector> sequence_;
0079   InitialConverter<Jet> cinit_;
0080   FinalConverter<Jet> cfinal_;
0081 };
0082 
0083 #endif  // JetMETCorrections_FFTJetObjects_FFTJetCorrectorSequence_h