CMS 3D CMS Logo

ProcMatrix.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MVAComputer
4 // Class : ProcMatrix
5 //
6 
7 // Implementation:
8 // Variable processor to apply a matrix transformation to the input
9 // variables. An n x m matrix applied to n input variables results in
10 // m output variables.
11 //
12 // Author: Christophe Saout
13 // Created: Sat Apr 24 15:18 CEST 2007
14 //
15 
16 #include <cstdlib>
17 
20 
21 using namespace PhysicsTools;
22 
23 namespace { // anonymous
24 
25  class ProcMatrix : public VarProcessor {
26  public:
28 
29  ProcMatrix(const char *name, const Calibration::ProcMatrix *calib, const MVAComputer *computer);
30  ~ProcMatrix() override {}
31 
32  void configure(ConfIterator iter, unsigned int n) override;
33  void eval(ValueIterator iter, unsigned int n) const override;
34  std::vector<double> deriv(ValueIterator iter, unsigned int n) const override;
35 
36  private:
37  class Matrix {
38  public:
39  inline Matrix(const Calibration::Matrix *calib)
40  : rows(calib->rows), cols(calib->columns), coeffs(calib->elements) {}
41 
42  inline unsigned int getRows() const { return rows; }
43  inline unsigned int getCols() const { return cols; }
44 
45  inline double operator()(unsigned int row, unsigned int col) const { return coeffs[row * cols + col]; }
46 
47  private:
48  unsigned int rows;
49  unsigned int cols;
50  std::vector<double> coeffs;
51  };
52 
53  Matrix matrix;
54  };
55 
56  ProcMatrix::Registry registry("ProcMatrix");
57 
58  ProcMatrix::ProcMatrix(const char *name, const Calibration::ProcMatrix *calib, const MVAComputer *computer)
60 
61  void ProcMatrix::configure(ConfIterator iter, unsigned int n) {
62  if (n != matrix.getCols())
63  return;
64 
65  for (unsigned int col = 0; col < matrix.getCols(); col++)
66  iter++(Variable::FLAG_NONE);
67 
68  for (unsigned int row = 0; row < matrix.getRows(); row++)
69  iter << Variable::FLAG_NONE;
70  }
71 
72  void ProcMatrix::eval(ValueIterator iter, unsigned int n) const {
73  double *sums = (double *)alloca(matrix.getRows() * sizeof(double));
74  for (unsigned int row = 0; row < matrix.getRows(); row++)
75  sums[row] = 0.0;
76 
77  for (unsigned int col = 0; col < matrix.getCols(); col++) {
78  double val = *iter++;
79  for (unsigned int row = 0; row < matrix.getRows(); row++)
80  sums[row] += matrix(row, col) * val;
81  }
82 
83  for (unsigned int row = 0; row < matrix.getRows(); row++)
84  iter(sums[row]);
85  }
86 
87  std::vector<double> ProcMatrix::deriv(ValueIterator iter, unsigned int n) const {
88  std::vector<double> result;
89  result.reserve(matrix.getRows() * matrix.getCols());
90 
91  for (unsigned int row = 0; row < matrix.getRows(); row++)
92  for (unsigned int col = 0; col < matrix.getCols(); col++)
93  result.push_back(matrix(row, col));
94 
95  return result;
96  }
97 
98 } // anonymous namespace
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
cuy.col
col
Definition: cuy.py:1010
PhysicsTools::MVAComputer
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
PhysicsTools::VarProcessor
Common base class for variable processors.
Definition: VarProcessor.h:36
calib
Definition: CalibElectron.h:12
PhysicsTools
Definition: Histogram.h:13
VarProcessor.h
PhysicsTools::Calibration::Matrix
Definition: MVAComputer.h:44
bookConverter.elements
elements
Definition: bookConverter.py:147
heppy_batch.val
val
Definition: heppy_batch.py:351
PhysicsTools::ProcessRegistryImpl
template to generate a registry singleton for a type.
Definition: ProcessRegistry.h:25
hitfit::Matrix
CLHEP::HepMatrix Matrix
Definition: matutil.h:62
mps_check.columns
columns
Definition: mps_check.py:244
Calibration.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
mps_fire.result
result
Definition: mps_fire.py:311
PhysicsTools::Calibration::ProcMatrix
Definition: MVAComputer.h:189
HLT_FULL_cff.computer
computer
Definition: HLT_FULL_cff.py:52057
postprocess-scan-build.rows
rows
Definition: postprocess-scan-build.py:20