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:
26 
27  ProcOptional(const char *name, const Calibration::ProcOptional *calib, const MVAComputer *computer);
28  ~ProcOptional() override {}
29 
30  void configure(ConfIterator iter, unsigned int n) override;
31  void eval(ValueIterator iter, unsigned int n) const override;
32  std::vector<double> deriv(ValueIterator iter, unsigned int n) const override;
33 
34  private:
35  std::vector<double> neutralPos;
36  };
37 
38  ProcOptional::Registry registry("ProcOptional");
39 
40  ProcOptional::ProcOptional(const char *name, const Calibration::ProcOptional *calib, const MVAComputer *computer)
41  : VarProcessor(name, calib, computer), neutralPos(calib->neutralPos) {}
42 
43  void ProcOptional::configure(ConfIterator iter, unsigned int n) {
44  if (n != neutralPos.size())
45  return;
46 
47  while (iter)
48  iter++(Variable::FLAG_OPTIONAL) << Variable::FLAG_NONE;
49  }
50 
51  void ProcOptional::eval(ValueIterator iter, unsigned int n) const {
52  for (std::vector<double>::const_iterator pos = neutralPos.begin(); pos != neutralPos.end(); pos++, ++iter) {
53  switch (iter.size()) {
54  case 0:
55  iter(*pos);
56  break;
57  case 1:
58  iter(*iter);
59  break;
60  default:
61  throw cms::Exception("ProcOptional") << "Multiple input variables encountered." << std::endl;
62  }
63  }
64  }
65 
66  std::vector<double> ProcOptional::deriv(ValueIterator iter, unsigned int n) const {
67  unsigned int size = 0;
68  for (ValueIterator iter2 = iter; iter2; ++iter2)
69  size += iter2.size();
70 
71  std::vector<double> result;
72 
73  unsigned int column = 0;
74  for (std::vector<double>::const_iterator pos = neutralPos.begin(); pos != neutralPos.end(); pos++, ++iter) {
75  unsigned int row = result.size();
76  result.resize(row + size);
77  switch (iter.size()) {
78  case 0:
79  break;
80  case 1:
81  result[row + column++] = 1.0;
82  break;
83  default:
84  throw cms::Exception("ProcOptionalError") << "Multiple input variables encountered." << std::endl;
85  }
86  }
87 
88  return result;
89  }
90 
91 } // anonymous namespace
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
pos
Definition: PixelAliasList.h:18
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
Exception
Definition: hltDiff.cc:246
Calibration.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
mps_fire.result
result
Definition: mps_fire.py:311
PhysicsTools::Calibration::ProcOptional
Definition: MVAComputer.h:79
HLT_FULL_cff.computer
computer
Definition: HLT_FULL_cff.py:52112
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443