00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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 {
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 }