CMS 3D CMS Logo

ProcLinear.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     MVAComputer
00004 // Class  :     ProcLinear
00005 // 
00006 
00007 // Implementation:
00008 //     Variable processor to compute a simple linear discriminant using
00009 //     coefficients for each input variable.
00010 //
00011 // Author:      Christophe Saout
00012 // Created:     Sat Apr 24 15:18 CEST 2007
00013 // $Id: ProcLinear.cc,v 1.4 2007/12/07 15:04:44 saout Exp $
00014 //
00015 
00016 #include <vector>
00017 
00018 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
00019 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
00020 
00021 using namespace PhysicsTools;
00022 
00023 namespace { // anonymous
00024 
00025 class ProcLinear : public VarProcessor {
00026     public:
00027         typedef VarProcessor::Registry::Registry<ProcLinear,
00028                                         Calibration::ProcLinear> Registry;
00029 
00030         ProcLinear(const char *name,
00031                    const Calibration::ProcLinear *calib,
00032                    const MVAComputer *computer);
00033         virtual ~ProcLinear() {}
00034 
00035         virtual void configure(ConfIterator iter, unsigned int n);
00036         virtual void eval(ValueIterator iter, unsigned int n) const;
00037 
00038     private:
00039         std::vector<double>     coeffs;
00040         double                  offset;
00041 };
00042 
00043 static ProcLinear::Registry registry("ProcLinear");
00044 
00045 ProcLinear::ProcLinear(const char *name,
00046                        const Calibration::ProcLinear *calib,
00047                        const MVAComputer *computer) :
00048         VarProcessor(name, calib, computer),
00049         coeffs(calib->coeffs),
00050         offset(calib->offset)
00051 {
00052 }
00053 
00054 void ProcLinear::configure(ConfIterator iter, unsigned int n)
00055 {
00056         while(iter)
00057                 iter++(Variable::FLAG_OPTIONAL);
00058 
00059         iter << Variable::FLAG_OPTIONAL;
00060 }
00061 
00062 void ProcLinear::eval(ValueIterator iter, unsigned int n) const
00063 {
00064         double sum = offset;
00065 
00066         for(std::vector<double>::const_iterator coeff = coeffs.begin();
00067             coeff != coeffs.end(); coeff++, ++iter) {
00068                 if (iter.empty()) {
00069                         iter();
00070                         return;
00071                 }
00072                 sum += *coeff * *iter;
00073         }
00074 
00075         iter(sum);
00076 }
00077 
00078 } // anonymous namespace

Generated on Tue Jun 9 17:41:28 2009 for CMSSW by  doxygen 1.5.4