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:
26  typedef VarProcessor::Registry::Registry<ProcLinear,
27  Calibration::ProcLinear> Registry;
28 
29  ProcLinear(const char *name,
31  const MVAComputer *computer);
32  ~ProcLinear() override {}
33 
34  void configure(ConfIterator iter, unsigned int n) override;
35  void eval(ValueIterator iter, unsigned int n) const override;
36  std::vector<double> deriv(
37  ValueIterator iter, unsigned int n) const override;
38 
39  private:
40  std::vector<double> coeffs;
41  double offset;
42 };
43 
44 ProcLinear::Registry registry("ProcLinear");
45 
46 ProcLinear::ProcLinear(const char *name,
48  const MVAComputer *computer) :
49  VarProcessor(name, calib, computer),
50  coeffs(calib->coeffs),
51  offset(calib->offset)
52 {
53 }
54 
55 void ProcLinear::configure(ConfIterator iter, unsigned int n)
56 {
57  while(iter)
58  iter++(Variable::FLAG_OPTIONAL);
59 
60  iter << Variable::FLAG_OPTIONAL;
61 }
62 
63 void ProcLinear::eval(ValueIterator iter, unsigned int n) const
64 {
65  double sum = offset;
66 
67  for(std::vector<double>::const_iterator coeff = coeffs.begin();
68  coeff != coeffs.end(); coeff++, ++iter) {
69  if (iter.empty()) {
70  iter();
71  return;
72  }
73  sum += *coeff * *iter;
74  }
75 
76  iter(sum);
77 }
78 
79 std::vector<double> ProcLinear::deriv(ValueIterator iter, unsigned int n) const
80 {
81  std::vector<double> result;
82 
83  for(std::vector<double>::const_iterator coeff = coeffs.begin();
84  coeff != coeffs.end(); coeff++, ++iter) {
85  if (!iter.empty())
86  result.push_back(*coeff);
87  }
88 
89  return result;
90 }
91 
92 } // anonymous namespace
template to generate a registry singleton for a type.
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
static Interceptor::Registry registry("Interceptor")
Common base class for variable processors.
Definition: VarProcessor.h:36