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  :     ProcSplitter
0005 //
0006 
0007 // Implementation:
0008 //     Splits the first n instances of the input variables into separate
0009 //     output variables.
0010 //
0011 // Author:      Christophe Saout
0012 // Created:     Sat Apr 24 15:18 CEST 2007
0013 //
0014 
0015 #include "FWCore/Utilities/interface/Exception.h"
0016 
0017 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
0018 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
0019 
0020 using namespace PhysicsTools;
0021 
0022 namespace {  // anonymous
0023 
0024   class ProcSplitter : public VarProcessor {
0025   public:
0026     typedef VarProcessor::Registry::Registry<ProcSplitter, Calibration::ProcSplitter> Registry;
0027 
0028     ProcSplitter(const char *name, const Calibration::ProcSplitter *calib, const MVAComputer *computer);
0029     ~ProcSplitter() override {}
0030 
0031     void configure(ConfIterator iter, unsigned int n) override;
0032     void eval(ValueIterator iter, unsigned int n) const override;
0033     std::vector<double> deriv(ValueIterator iter, unsigned int n) const override;
0034 
0035   private:
0036     unsigned int count;
0037   };
0038 
0039   ProcSplitter::Registry registry("ProcSplitter");
0040 
0041   ProcSplitter::ProcSplitter(const char *name, const Calibration::ProcSplitter *calib, const MVAComputer *computer)
0042       : VarProcessor(name, calib, computer), count(calib->nFirst) {}
0043 
0044   void ProcSplitter::configure(ConfIterator iter, unsigned int n) {
0045     while (iter) {
0046       for (unsigned int i = 0; i < count; i++)
0047         iter << Variable::FLAG_OPTIONAL;
0048       iter << iter++(Variable::FLAG_ALL);
0049     }
0050   }
0051 
0052   void ProcSplitter::eval(ValueIterator iter, unsigned int n) const {
0053     while (iter) {
0054       unsigned int i = 0;
0055       while (i < iter.size()) {
0056         iter << iter[i];
0057         if (i++ < count)
0058           iter();
0059       }
0060       while (i++ < count)
0061         iter();
0062       iter();
0063       iter++;
0064     }
0065   }
0066 
0067   std::vector<double> ProcSplitter::deriv(ValueIterator iter, unsigned int n) const {
0068     unsigned int size = 0;
0069     for (ValueIterator iter2 = iter; iter2; ++iter2)
0070       size += iter2.size();
0071 
0072     std::vector<double> result(size * size);
0073     for (unsigned int i = 0; i < size; i++)
0074       result[i * size + i] = 1.0;
0075 
0076     return result;
0077   }
0078 
0079 }  // anonymous namespace