Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:41

0001 // -*- C++ -*-
0002 //
0003 // Package:     MVAComputer
0004 // Class  :     ProcClassed
0005 //
0006 
0007 // Implementation:
0008 //     Variable processor that splits an input variable into n output
0009 //     variables depending on the integer value of the input variable.
0010 //     If the input variable has the value n, the nth output variable
0011 //     is set to 1, all others to 0.
0012 //
0013 // Author:      Christophe Saout
0014 // Created:     Sat Apr 24 15:18 CEST 2007
0015 //
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 ProcClassed : public VarProcessor {
0025   public:
0026     typedef VarProcessor::Registry::Registry<ProcClassed, Calibration::ProcClassed> Registry;
0027 
0028     ProcClassed(const char *name, const Calibration::ProcClassed *calib, const MVAComputer *computer);
0029     ~ProcClassed() override {}
0030 
0031     void configure(ConfIterator iter, unsigned int n) override;
0032     void eval(ValueIterator iter, unsigned int n) const override;
0033 
0034   private:
0035     unsigned int nClasses;
0036   };
0037 
0038   ProcClassed::Registry registry("ProcClassed");
0039 
0040   ProcClassed::ProcClassed(const char *name, const Calibration::ProcClassed *calib, const MVAComputer *computer)
0041       : VarProcessor(name, calib, computer), nClasses(calib->nClasses) {}
0042 
0043   void ProcClassed::configure(ConfIterator iter, unsigned int n) {
0044     if (n != 1)
0045       return;
0046 
0047     iter(Variable::FLAG_NONE);
0048     for (unsigned int i = 0; i < nClasses; i++)
0049       iter << Variable::FLAG_NONE;
0050   }
0051 
0052   void ProcClassed::eval(ValueIterator iter, unsigned int n) const {
0053     unsigned int value = (unsigned int)(*iter + 0.5);
0054 
0055     for (unsigned int i = 0; i < nClasses; i++)
0056       iter(i == value ? 1.0 : 0.0);
0057   }
0058 
0059 }  // anonymous namespace