Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:38

0001 // -*- C++ -*-
0002 //
0003 // Package:     MVAComputer
0004 // Class  :     ProcCategory
0005 //
0006 
0007 // Implementation:
0008 //     Categorizes the input variables given a set of ranges for each
0009 //     input variable. Output is an integer number.
0010 //
0011 // Author:      Christophe Saout
0012 // Created:     Sun Sep 16 04:05 CEST 2007
0013 //
0014 
0015 #include <algorithm>
0016 #include <vector>
0017 
0018 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
0019 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
0020 
0021 using namespace PhysicsTools;
0022 
0023 namespace {  // anonymous
0024 
0025   class ProcCategory : public VarProcessor {
0026   public:
0027     typedef VarProcessor::Registry::Registry<ProcCategory, Calibration::ProcCategory> Registry;
0028 
0029     ProcCategory(const char *name, const Calibration::ProcCategory *calib, const MVAComputer *computer);
0030     ~ProcCategory() override {}
0031 
0032     void configure(ConfIterator iter, unsigned int n) override;
0033     void eval(ValueIterator iter, unsigned int n) const override;
0034 
0035   private:
0036     typedef Calibration::ProcCategory::BinLimits BinLimits;
0037 
0038     const Calibration::ProcCategory *calib;
0039   };
0040 
0041   ProcCategory::Registry registry("ProcCategory");
0042 
0043   ProcCategory::ProcCategory(const char *name, const Calibration::ProcCategory *calib, const MVAComputer *computer)
0044       : VarProcessor(name, calib, computer), calib(calib) {}
0045 
0046   void ProcCategory::configure(ConfIterator iter, unsigned int n) {
0047     if (n != calib->variableBinLimits.size())
0048       return;
0049 
0050     unsigned int categories = 1;
0051     for (std::vector<BinLimits>::const_iterator bin = calib->variableBinLimits.begin();
0052          bin != calib->variableBinLimits.end();
0053          bin++)
0054       categories *= (bin->size() + 1);
0055 
0056     if (calib->categoryMapping.size() != categories)
0057       return;
0058 
0059     while (iter)
0060       iter++(Variable::FLAG_NONE);
0061 
0062     iter << Variable::FLAG_NONE;
0063   }
0064 
0065   void ProcCategory::eval(ValueIterator iter, unsigned int n) const {
0066     unsigned int category = 0;
0067     for (std::vector<BinLimits>::const_iterator vars = calib->variableBinLimits.begin();
0068          vars != calib->variableBinLimits.end();
0069          vars++, ++iter) {
0070       unsigned int idx = std::upper_bound(vars->begin(), vars->end(), *iter) - vars->begin();
0071       category *= vars->size() + 1;
0072       category += idx;
0073     }
0074 
0075     iter(calib->categoryMapping[category]);
0076   }
0077 
0078 }  // anonymous namespace