Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:19:16

0001 #ifndef JetMETCorrections_FFTJetModules_FFTJetESParameterParser_h
0002 #define JetMETCorrections_FFTJetModules_FFTJetESParameterParser_h
0003 
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005 #include "FWCore/Utilities/interface/Exception.h"
0006 
0007 #include "JetMETCorrections/FFTJetObjects/interface/FFTJetAdjusters.h"
0008 #include "JetMETCorrections/FFTJetObjects/interface/FFTJetScaleCalculators.h"
0009 #include "JetMETCorrections/FFTJetObjects/interface/FFTJetCorrectionsTypemap.h"
0010 #include "JetMETCorrections/FFTJetObjects/interface/loadFFTJetInterpolationTable.h"
0011 
0012 #include "JetMETCorrections/InterpolationTables/interface/CoordinateSelector.h"
0013 class parseFFTJetCorrectorApp;
0014 
0015 // Parser for the adjuster of the adjustable :-)
0016 template <class Jet, class Adjustable>
0017 std::shared_ptr<AbsFFTJetAdjuster<Jet, Adjustable> > parseFFTJetAdjuster(const edm::ParameterSet& ps,
0018                                                                          const bool /* verbose */) {
0019   typedef std::shared_ptr<AbsFFTJetAdjuster<Jet, Adjustable> > Result;
0020 
0021   const std::string& adjuster_type = ps.getParameter<std::string>("Class");
0022 
0023   if (!adjuster_type.compare("FFTSimpleScalingAdjuster"))
0024     return Result(new FFTSimpleScalingAdjuster<Jet, Adjustable>());
0025 
0026   else if (!adjuster_type.compare("FFTUncertaintyAdjuster"))
0027     return Result(new FFTUncertaintyAdjuster<Jet, Adjustable>());
0028 
0029   else if (!adjuster_type.compare("FFTScalingAdjusterWithUncertainty"))
0030     return Result(new FFTScalingAdjusterWithUncertainty<Jet, Adjustable>());
0031 
0032   else
0033     throw cms::Exception("FFTJetBadConfig")
0034         << "In parseFFTJetAdjuster: unknown adjuster type \"" << adjuster_type << "\"\n";
0035 }
0036 
0037 // Parser for the mapper/scaler
0038 template <class Jet, class Adjustable>
0039 std::shared_ptr<AbsFFTJetScaleCalculator<Jet, Adjustable> > parseFFTJetScaleCalculator(const edm::ParameterSet& ps,
0040                                                                                        gs::StringArchive& ar,
0041                                                                                        const bool verbose) {
0042   typedef std::shared_ptr<AbsFFTJetScaleCalculator<Jet, Adjustable> > Result;
0043 
0044   std::string mapper_type(ps.getParameter<std::string>("Class"));
0045 
0046   // Initially, check for mappers which do not need to load
0047   // a data table from the archive
0048   //     if (!mapper_type.compare("SomeClass"))
0049   //     {
0050   //         Do something ....
0051   //         return Result(...);
0052   //     }
0053 
0054   // Load the table from the archive
0055   std::unique_ptr<npstat::StorableMultivariateFunctor> autof = loadFFTJetInterpolationTable(ps, ar, verbose);
0056   std::shared_ptr<npstat::StorableMultivariateFunctor> f(autof.release());
0057 
0058   // Swap the class name if it is supposed to be determined
0059   // from the table description
0060   if (!mapper_type.compare("auto"))
0061     mapper_type = f->description();
0062 
0063   if (!mapper_type.compare("FFTEtaLogPtConeRadiusMapper"))
0064     return Result(new FFTEtaLogPtConeRadiusMapper<Jet, Adjustable>(f));
0065 
0066   else if (!mapper_type.compare("FFTSpecificScaleCalculator")) {
0067     const edm::ParameterSet& subclass = ps.getParameter<edm::ParameterSet>("Subclass");
0068     AbsFFTSpecificScaleCalculator* p = parseFFTSpecificScaleCalculator(subclass, f->description());
0069     return Result(new FFTSpecificScaleCalculator<Jet, Adjustable>(f, p));
0070   }
0071 
0072   else
0073     throw cms::Exception("FFTJetBadConfig")
0074         << "In parseFFTJetScaleCalculator: unknown mapper type \"" << mapper_type << '"' << std::endl;
0075 }
0076 
0077 // Parser for a single corrector of FFTJets
0078 template <class Corrector>
0079 Corrector parseFFTJetCorrector(const edm::ParameterSet& ps, gs::StringArchive& ar, const bool verbose) {
0080   typedef typename Corrector::jet_type MyJet;
0081   typedef typename Corrector::adjustable_type Adjustable;
0082 
0083   // "level" is an unsigned
0084   const unsigned level(ps.getParameter<unsigned>("level"));
0085 
0086   // "applyTo" is a string
0087   const std::string& applyTo(ps.getParameter<std::string>("applyTo"));
0088 
0089   // "adjuster" is a PSet
0090   const edm::ParameterSet& adjuster = ps.getParameter<edm::ParameterSet>("adjuster");
0091   std::shared_ptr<const AbsFFTJetAdjuster<MyJet, Adjustable> > adj =
0092       parseFFTJetAdjuster<MyJet, Adjustable>(adjuster, verbose);
0093 
0094   // "scalers" is a VPSet
0095   const std::vector<edm::ParameterSet>& scalers = ps.getParameter<std::vector<edm::ParameterSet> >("scalers");
0096   const unsigned nScalers = scalers.size();
0097   std::vector<std::shared_ptr<const AbsFFTJetScaleCalculator<MyJet, Adjustable> > > sVec;
0098   sVec.reserve(nScalers);
0099   for (unsigned i = 0; i < nScalers; ++i) {
0100     std::shared_ptr<AbsFFTJetScaleCalculator<MyJet, Adjustable> > s =
0101         parseFFTJetScaleCalculator<MyJet, Adjustable>(scalers[i], ar, verbose);
0102     sVec.push_back(s);
0103   }
0104   return Corrector(adj, sVec, level, parseFFTJetCorrectorApp(applyTo));
0105 }
0106 
0107 #endif  // JetMETCorrections_FFTJetModules_FFTJetESParameterParser_h