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
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
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::ProcessRegistryImpl
template to generate a registry singleton for a type.
Definition: ProcessRegistry.h:25
Calibration.h
HLT_2018_cff.computer
computer
Definition: HLT_2018_cff.py:50520
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
mps_fire.result
result
Definition: mps_fire.py:303
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
PhysicsTools::Calibration::ProcLinear
Definition: MVAComputer.h:169