Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-01-31 02:19:53

0001 #ifndef RecoBTau_JetTagComputer_GenericMVAJetTagComputerWrapper_h
0002 #define RecoBTau_JetTagComputer_GenericMVAJetTagComputerWrapper_h
0003 
0004 #include <memory>
0005 
0006 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0007 #include "DataFormats/BTauReco/interface/BaseTagInfo.h"
0008 #include "DataFormats/BTauReco/interface/TaggingVariable.h"
0009 #include "RecoBTau/JetTagComputer/interface/GenericMVAJetTagComputer.h"
0010 
0011 /*
0012  * This header defines a bunch of templated convenience wrappers
0013  *
0014  *      GenericMVAJetTagComputerWrapper<class Provider, ...>
0015  *
0016  * whereas ... dennotes argument pairs, with the
0017  *   first argument being a specific TagInfo class
0018  *   second argument being a constant string dennoting the cfg parameter
0019  *
0020  * If only one TagInfo is passed, the cfg parameter name can be ommited
0021  * (will default to "tagInfo"). 
0022  *
0023  * The wrapper will derive from the template argument class Provider,
0024  * pass the ParameterSet of the JetTagComputer to the (optional) constructor
0025  * and call "TaggingVariableList operator () (...) const" for every jet to
0026  * tag, with ... being the already casted and type-verified specific
0027  * TagInfo references (number of arguments matching the template instance).
0028  *
0029  * The TaggingVariables will be fed into the MVAComputer, which will compute
0030  * the final discriminator from an ES calibration object define in the cfg.
0031  */
0032 
0033 namespace btau_dummy {
0034   struct Null {};
0035   constexpr const char none[] = "";
0036 }  // namespace btau_dummy
0037 
0038 // 4 named TagInfos
0039 
0040 template <class Provider,
0041           class TI1,
0042           const char *ti1 = btau_dummy::none,
0043           class TI2 = btau_dummy::Null,
0044           const char *ti2 = btau_dummy::none,
0045           class TI3 = btau_dummy::Null,
0046           const char *ti3 = btau_dummy::none,
0047           class TI4 = btau_dummy::Null,
0048           const char *ti4 = btau_dummy::none>
0049 class GenericMVAJetTagComputerWrapper : public GenericMVAJetTagComputer, private Provider {
0050 public:
0051   GenericMVAJetTagComputerWrapper(const edm::ParameterSet &params, Tokens tokens)
0052       : GenericMVAJetTagComputer(params, tokens), Provider(params) {
0053     uses(0, ti1);
0054     uses(1, ti2);
0055     uses(2, ti3);
0056     uses(3, ti4);
0057   }
0058 
0059   static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0060     Provider::fillPSetDescription(desc);
0061     GenericMVAJetTagComputer::fillPSetDescription(desc);
0062   }
0063 
0064 protected:
0065   reco::TaggingVariableList taggingVariables(const TagInfoHelper &info) const override {
0066     return (static_cast<const Provider &>(*this))(
0067         info.get<TI1>(0), info.get<TI2>(1), info.get<TI3>(2), info.get<TI4>(3));
0068   }
0069 };
0070 
0071 // 3 named TagInfos
0072 
0073 template <class Provider, class TI1, const char *ti1, class TI2, const char *ti2, class TI3, const char *ti3>
0074 class GenericMVAJetTagComputerWrapper<Provider, TI1, ti1, TI2, ti2, TI3, ti3, btau_dummy::Null, btau_dummy::none>
0075     : public GenericMVAJetTagComputer, private Provider {
0076 public:
0077   GenericMVAJetTagComputerWrapper(const edm::ParameterSet &params, Tokens tokens)
0078       : GenericMVAJetTagComputer(params, tokens), Provider(params) {
0079     uses(0, ti1);
0080     uses(1, ti2);
0081     uses(2, ti3);
0082   }
0083 
0084   static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0085     Provider::fillPSetDescription(desc);
0086     GenericMVAJetTagComputer::fillPSetDescription(desc);
0087   }
0088 
0089 protected:
0090   reco::TaggingVariableList taggingVariables(const TagInfoHelper &info) const override {
0091     return (static_cast<const Provider &>(*this))(info.get<TI1>(0), info.get<TI2>(1), info.get<TI3>(2));
0092   }
0093 };
0094 
0095 // 2 named TagInfos
0096 
0097 template <class Provider, class TI1, const char *ti1, class TI2, const char *ti2>
0098 class GenericMVAJetTagComputerWrapper<Provider,
0099                                       TI1,
0100                                       ti1,
0101                                       TI2,
0102                                       ti2,
0103                                       btau_dummy::Null,
0104                                       btau_dummy::none,
0105                                       btau_dummy::Null,
0106                                       btau_dummy::none> : public GenericMVAJetTagComputer,
0107                                                           private Provider {
0108 public:
0109   GenericMVAJetTagComputerWrapper(const edm::ParameterSet &params, Tokens tokens)
0110       : GenericMVAJetTagComputer(params, tokens), Provider(params) {
0111     uses(0, ti1);
0112     uses(1, ti2);
0113   }
0114 
0115   static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0116     Provider::fillPSetDescription(desc);
0117     GenericMVAJetTagComputer::fillPSetDescription(desc);
0118   }
0119 
0120 protected:
0121   reco::TaggingVariableList taggingVariables(const TagInfoHelper &info) const override {
0122     return (static_cast<const Provider &>(*this))(info.get<TI1>(0), info.get<TI2>(1));
0123   }
0124 };
0125 
0126 // 1 named TagInfo
0127 
0128 template <class Provider, class TI1, const char *ti1>
0129 class GenericMVAJetTagComputerWrapper<Provider,
0130                                       TI1,
0131                                       ti1,
0132                                       btau_dummy::Null,
0133                                       btau_dummy::none,
0134                                       btau_dummy::Null,
0135                                       btau_dummy::none,
0136                                       btau_dummy::Null,
0137                                       btau_dummy::none> : public GenericMVAJetTagComputer,
0138                                                           private Provider {
0139 public:
0140   GenericMVAJetTagComputerWrapper(const edm::ParameterSet &params, Tokens tokens)
0141       : GenericMVAJetTagComputer(params, tokens), Provider(params) {
0142     uses(0, ti1);
0143   }
0144 
0145   static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0146     Provider::fillPSetDescription(desc);
0147     GenericMVAJetTagComputer::fillPSetDescription(desc);
0148   }
0149 
0150 protected:
0151   reco::TaggingVariableList taggingVariables(const TagInfoHelper &info) const override {
0152     return (static_cast<const Provider &>(*this))(info.get<TI1>(0));
0153   }
0154 };
0155 
0156 // default TagInfo
0157 
0158 template <class Provider, class TI1>
0159 class GenericMVAJetTagComputerWrapper<Provider,
0160                                       TI1,
0161                                       btau_dummy::none,
0162                                       btau_dummy::Null,
0163                                       btau_dummy::none,
0164                                       btau_dummy::Null,
0165                                       btau_dummy::none,
0166                                       btau_dummy::Null,
0167                                       btau_dummy::none> : public GenericMVAJetTagComputer,
0168                                                           private Provider {
0169 public:
0170   GenericMVAJetTagComputerWrapper(const edm::ParameterSet &params, Tokens tokens)
0171       : GenericMVAJetTagComputer(params, tokens), Provider(params) {}
0172 
0173   static void fillPSetDescription(edm::ParameterSetDescription &desc) {
0174     Provider::fillPSetDescription(desc);
0175     GenericMVAJetTagComputer::fillPSetDescription(desc);
0176   }
0177 
0178 protected:
0179   reco::TaggingVariableList taggingVariables(const TagInfoHelper &info) const override {
0180     return (static_cast<const Provider &>(*this))(info.get<TI1>(0));
0181   }
0182 };
0183 
0184 #endif  // RecoBTau_JetTagComputer_GenericMVAJetTagComputerWrapper_h