CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: ProcLinear.cc,v 1.5 2009/06/03 09:50:14 saout Exp $
14 //
15 
16 #include <vector>
17 
20 
21 using namespace PhysicsTools;
22 
23 namespace { // anonymous
24 
25 class ProcLinear : public VarProcessor {
26  public:
27  typedef VarProcessor::Registry::Registry<ProcLinear,
29 
30  ProcLinear(const char *name,
32  const MVAComputer *computer);
33  virtual ~ProcLinear() {}
34 
35  virtual void configure(ConfIterator iter, unsigned int n);
36  virtual void eval(ValueIterator iter, unsigned int n) const;
37  virtual std::vector<double> deriv(
38  ValueIterator iter, unsigned int n) const;
39 
40  private:
41  std::vector<double> coeffs;
42  double offset;
43 };
44 
45 static ProcLinear::Registry registry("ProcLinear");
46 
47 ProcLinear::ProcLinear(const char *name,
49  const MVAComputer *computer) :
50  VarProcessor(name, calib, computer),
51  coeffs(calib->coeffs),
52  offset(calib->offset)
53 {
54 }
55 
56 void ProcLinear::configure(ConfIterator iter, unsigned int n)
57 {
58  while(iter)
59  iter++(Variable::FLAG_OPTIONAL);
60 
61  iter << Variable::FLAG_OPTIONAL;
62 }
63 
64 void ProcLinear::eval(ValueIterator iter, unsigned int n) const
65 {
66  double sum = offset;
67 
68  for(std::vector<double>::const_iterator coeff = coeffs.begin();
69  coeff != coeffs.end(); coeff++, ++iter) {
70  if (iter.empty()) {
71  iter();
72  return;
73  }
74  sum += *coeff * *iter;
75  }
76 
77  iter(sum);
78 }
79 
80 std::vector<double> ProcLinear::deriv(ValueIterator iter, unsigned int n) const
81 {
82  std::vector<double> result;
83 
84  for(std::vector<double>::const_iterator coeff = coeffs.begin();
85  coeff != coeffs.end(); coeff++, ++iter) {
86  if (!iter.empty())
87  result.push_back(*coeff);
88  }
89 
90  return result;
91 }
92 
93 } // anonymous namespace
detail::ThreadSafeRegistry< ParameterSetID, ParameterSet, ProcessParameterSetIDCache > Registry
Definition: Registry.h:37
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:40
tuple result
Definition: query.py:137
unsigned int offset(bool)
template to generate a registry singleton for a type.
static Interceptor::Registry registry("Interceptor")
Common base class for variable processors.
Definition: VarProcessor.h:39