CMS 3D CMS Logo

ProcOptional.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MVAComputer
4 // Class : ProcOptional
5 //
6 
7 // Implementation:
8 // Variable processor to set empty input variables to a default value.
9 //
10 // Author: Christophe Saout
11 // Created: Sat Apr 24 15:18 CEST 2007
12 //
13 
15 
18 
19 using namespace PhysicsTools;
20 
21 namespace { // anonymous
22 
23 class ProcOptional : public VarProcessor {
24  public:
25  typedef VarProcessor::Registry::Registry<ProcOptional,
26  Calibration::ProcOptional> Registry;
27 
28  ProcOptional(const char *name,
30  const MVAComputer *computer);
31  virtual ~ProcOptional() {}
32 
33  virtual void configure(ConfIterator iter, unsigned int n) override;
34  virtual void eval(ValueIterator iter, unsigned int n) const override;
35  virtual std::vector<double> deriv(
36  ValueIterator iter, unsigned int n) const override;
37 
38  private:
39  std::vector<double> neutralPos;
40 };
41 
42 ProcOptional::Registry registry("ProcOptional");
43 
44 ProcOptional::ProcOptional(const char *name,
46  const MVAComputer *computer) :
47  VarProcessor(name, calib, computer),
48  neutralPos(calib->neutralPos)
49 {
50 }
51 
52 void ProcOptional::configure(ConfIterator iter, unsigned int n)
53 {
54  if (n != neutralPos.size())
55  return;
56 
57  while(iter)
58  iter++(Variable::FLAG_OPTIONAL) << Variable::FLAG_NONE;
59 }
60 
61 void ProcOptional::eval(ValueIterator iter, unsigned int n) const
62 {
63  for(std::vector<double>::const_iterator pos = neutralPos.begin();
64  pos != neutralPos.end(); pos++, ++iter) {
65  switch(iter.size()) {
66  case 0:
67  iter(*pos);
68  break;
69  case 1:
70  iter(*iter);
71  break;
72  default:
73  throw cms::Exception("ProcOptional")
74  << "Multiple input variables encountered."
75  << std::endl;
76  }
77  }
78 }
79 
80 std::vector<double> ProcOptional::deriv(
81  ValueIterator iter, unsigned int n) const
82 {
83  unsigned int size = 0;
84  for(ValueIterator iter2 = iter; iter2; ++iter2)
85  size += iter2.size();
86 
87  std::vector<double> result;
88 
89  unsigned int column = 0;
90  for(std::vector<double>::const_iterator pos = neutralPos.begin();
91  pos != neutralPos.end(); pos++, ++iter) {
92  unsigned int row = result.size();
93  result.resize(row + size);
94  switch(iter.size()) {
95  case 0:
96  break;
97  case 1:
98  result[row + column++] = 1.0;
99  break;
100  default:
101  throw cms::Exception("ProcOptionalError")
102  << "Multiple input variables encountered."
103  << std::endl;
104  }
105  }
106 
107  return result;
108 }
109 
110 } // anonymous namespace
size
Write out results.
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