CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: ProcOptional.cc,v 1.4 2009/06/03 09:50:14 saout Exp $
13 //
14 
16 
19 
20 using namespace PhysicsTools;
21 
22 namespace { // anonymous
23 
24 class ProcOptional : public VarProcessor {
25  public:
26  typedef VarProcessor::Registry::Registry<ProcOptional,
28 
29  ProcOptional(const char *name,
31  const MVAComputer *computer);
32  virtual ~ProcOptional() {}
33 
34  virtual void configure(ConfIterator iter, unsigned int n);
35  virtual void eval(ValueIterator iter, unsigned int n) const;
36  virtual std::vector<double> deriv(
37  ValueIterator iter, unsigned int n) const;
38 
39  private:
40  std::vector<double> neutralPos;
41 };
42 
43 static ProcOptional::Registry registry("ProcOptional");
44 
45 ProcOptional::ProcOptional(const char *name,
47  const MVAComputer *computer) :
48  VarProcessor(name, calib, computer),
49  neutralPos(calib->neutralPos)
50 {
51 }
52 
53 void ProcOptional::configure(ConfIterator iter, unsigned int n)
54 {
55  if (n != neutralPos.size())
56  return;
57 
58  while(iter)
59  iter++(Variable::FLAG_OPTIONAL) << Variable::FLAG_NONE;
60 }
61 
62 void ProcOptional::eval(ValueIterator iter, unsigned int n) const
63 {
64  for(std::vector<double>::const_iterator pos = neutralPos.begin();
65  pos != neutralPos.end(); pos++, ++iter) {
66  switch(iter.size()) {
67  case 0:
68  iter(*pos);
69  break;
70  case 1:
71  iter(*iter);
72  break;
73  default:
74  throw cms::Exception("ProcOptional")
75  << "Multiple input variables encountered."
76  << std::endl;
77  }
78  }
79 }
80 
81 std::vector<double> ProcOptional::deriv(
82  ValueIterator iter, unsigned int n) const
83 {
84  unsigned int size = 0;
85  for(ValueIterator iter2 = iter; iter2; ++iter2)
86  size += iter2.size();
87 
88  std::vector<double> result;
89 
90  unsigned int column = 0;
91  for(std::vector<double>::const_iterator pos = neutralPos.begin();
92  pos != neutralPos.end(); pos++, ++iter) {
93  unsigned int row = result.size();
94  result.resize(row + size);
95  switch(iter.size()) {
96  case 0:
97  break;
98  case 1:
99  result[row + column++] = 1.0;
100  break;
101  default:
102  throw cms::Exception("ProcOptionalError")
103  << "Multiple input variables encountered."
104  << std::endl;
105  }
106  }
107 
108  return result;
109 }
110 
111 } // 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
template to generate a registry singleton for a type.
static Interceptor::Registry registry("Interceptor")
tuple size
Write out results.
Common base class for variable processors.
Definition: VarProcessor.h:39