CMS 3D CMS Logo

ProcLinear.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MVAComputer
4 // Class : ProcLinear
5 //
6 
7 // Implementation:
8 // Variable processor to compute a simple linear discriminant using
9 // coefficients for each input variable.
10 //
11 // Author: Christophe Saout
12 // Created: Sat Apr 24 15:18 CEST 2007
13 //
14 
15 #include <vector>
16 
19 
20 using namespace PhysicsTools;
21 
22 namespace { // anonymous
23 
24  class ProcLinear : public VarProcessor {
25  public:
27 
28  ProcLinear(const char *name, const Calibration::ProcLinear *calib, const MVAComputer *computer);
29  ~ProcLinear() override {}
30 
31  void configure(ConfIterator iter, unsigned int n) override;
32  void eval(ValueIterator iter, unsigned int n) const override;
33  std::vector<double> deriv(ValueIterator iter, unsigned int n) const override;
34 
35  private:
36  std::vector<double> coeffs;
37  double offset;
38  };
39 
40  ProcLinear::Registry registry("ProcLinear");
41 
42  ProcLinear::ProcLinear(const char *name, const Calibration::ProcLinear *calib, const MVAComputer *computer)
43  : VarProcessor(name, calib, computer), coeffs(calib->coeffs), offset(calib->offset) {}
44 
45  void ProcLinear::configure(ConfIterator iter, unsigned int n) {
46  while (iter)
47  iter++(Variable::FLAG_OPTIONAL);
48 
49  iter << Variable::FLAG_OPTIONAL;
50  }
51 
52  void ProcLinear::eval(ValueIterator iter, unsigned int n) const {
53  double sum = offset;
54 
55  for (std::vector<double>::const_iterator coeff = coeffs.begin(); coeff != coeffs.end(); coeff++, ++iter) {
56  if (iter.empty()) {
57  iter();
58  return;
59  }
60  sum += *coeff * *iter;
61  }
62 
63  iter(sum);
64  }
65 
66  std::vector<double> ProcLinear::deriv(ValueIterator iter, unsigned int n) const {
67  std::vector<double> result;
68 
69  for (std::vector<double>::const_iterator coeff = coeffs.begin(); coeff != coeffs.end(); coeff++, ++iter) {
70  if (!iter.empty())
71  result.push_back(*coeff);
72  }
73 
74  return result;
75  }
76 
77 } // anonymous namespace
template to generate a registry singleton for a type.
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
Common base class for variable processors.
Definition: VarProcessor.h:36