00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <stdlib.h>
00018
00019 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
00020 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
00021
00022 using namespace PhysicsTools;
00023
00024 namespace {
00025
00026 class ProcMatrix : public VarProcessor {
00027 public:
00028 typedef VarProcessor::Registry::Registry<ProcMatrix,
00029 Calibration::ProcMatrix> Registry;
00030
00031 ProcMatrix(const char *name,
00032 const Calibration::ProcMatrix *calib,
00033 const MVAComputer *computer);
00034 virtual ~ProcMatrix() {}
00035
00036 virtual void configure(ConfIterator iter, unsigned int n);
00037 virtual void eval(ValueIterator iter, unsigned int n) const;
00038
00039 private:
00040 class Matrix {
00041 public:
00042 inline Matrix(const Calibration::Matrix *calib) :
00043 rows(calib->rows), cols(calib->columns),
00044 coeffs(calib->elements) {}
00045
00046 inline unsigned int getRows() const { return rows; }
00047 inline unsigned int getCols() const { return cols; }
00048
00049 inline double operator () (unsigned int row,
00050 unsigned int col) const
00051 { return coeffs[row * cols + col]; }
00052
00053 private:
00054 unsigned int rows;
00055 unsigned int cols;
00056 std::vector<double> coeffs;
00057 };
00058
00059 Matrix matrix;
00060 };
00061
00062 static ProcMatrix::Registry registry("ProcMatrix");
00063
00064 ProcMatrix::ProcMatrix(const char *name,
00065 const Calibration::ProcMatrix *calib,
00066 const MVAComputer *computer) :
00067 VarProcessor(name, calib, computer),
00068 matrix(&calib->matrix)
00069 {
00070 }
00071
00072 void ProcMatrix::configure(ConfIterator iter, unsigned int n)
00073 {
00074 if (n != matrix.getCols())
00075 return;
00076
00077 for(unsigned int col = 0; col < matrix.getCols(); col++)
00078 iter++(Variable::FLAG_NONE);
00079
00080 for(unsigned int row = 0; row < matrix.getRows(); row++)
00081 iter << Variable::FLAG_NONE;
00082 }
00083
00084 void ProcMatrix::eval(ValueIterator iter, unsigned int n) const
00085 {
00086 double *sums = (double*)alloca(matrix.getRows() * sizeof(double));
00087 for(unsigned int row = 0; row < matrix.getRows(); row++)
00088 sums[row] = 0.0;
00089
00090 for(unsigned int col = 0; col < matrix.getCols(); col++) {
00091 double val = *iter++;
00092 for(unsigned int row = 0; row < matrix.getRows(); row++)
00093 sums[row] += matrix(row, col) * val;
00094 }
00095
00096 for(unsigned int row = 0; row < matrix.getRows(); row++)
00097 iter(sums[row]);
00098 }
00099
00100 }