CMS 3D CMS Logo

ProcMultiply.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: MVAComputer
4 // Class :
5 //
6 
7 // Implementation:
8 // Multiplies n input variables to produce one output variable.
9 //
10 // Author: Christophe Saout
11 // Created: Sat Apr 24 15:18 CEST 2007
12 //
13 
14 #include <cstdlib>
15 #include <algorithm>
16 #include <iterator>
17 #include <vector>
18 
20 
23 
24 using namespace PhysicsTools;
25 
26 namespace { // anonymous
27 
28  class ProcMultiply : public VarProcessor {
29  public:
31 
32  ProcMultiply(const char *name, const Calibration::ProcMultiply *calib, const MVAComputer *computer);
33  ~ProcMultiply() override {}
34 
35  void configure(ConfIterator iter, unsigned int n) override;
36  void eval(ValueIterator iter, unsigned int n) const override;
37  std::vector<double> deriv(ValueIterator iter, unsigned int n) const override;
38 
39  private:
40  typedef std::vector<unsigned int> Config;
41 
42  unsigned int in;
43  std::vector<Config> out;
44  };
45 
46  ProcMultiply::Registry registry("ProcMultiply");
47 
48  ProcMultiply::ProcMultiply(const char *name, const Calibration::ProcMultiply *calib, const MVAComputer *computer)
50  std::copy(calib->out.begin(), calib->out.end(), std::back_inserter(out));
51  }
52 
53  void ProcMultiply::configure(ConfIterator iter, unsigned int n) {
54  if (in != n)
55  return;
56 
57  for (unsigned int i = 0; i < in; i++)
58  iter++(Variable::FLAG_NONE);
59 
60  for (unsigned int i = 0; i < out.size(); i++)
61  iter << Variable::FLAG_NONE;
62  }
63 
64  void ProcMultiply::eval(ValueIterator iter, unsigned int n) const {
65  double *values = (double *)alloca(in * sizeof(double));
66  for (double *pos = values; iter; iter++, pos++) {
67  if (iter.size() != 1)
68  throw cms::Exception("ProcMultiply") << "Special input variable encountered "
69  "at index "
70  << (pos - values) << "." << std::endl;
71  *pos = *iter;
72  }
73 
74  for (std::vector<Config>::const_iterator config = out.begin(); config != out.end(); ++config) {
75  double product = 1.0;
76  for (std::vector<unsigned int>::const_iterator var = config->begin(); var != config->end(); var++)
77  product *= values[*var];
78 
79  iter(product);
80  }
81  }
82 
83  std::vector<double> ProcMultiply::deriv(ValueIterator iter, unsigned int n) const {
84  std::vector<double> values;
85  std::vector<unsigned int> offsets;
86  unsigned int size = 0;
87  while (iter) {
88  offsets.push_back(size);
89  size += iter.size();
90  values.push_back(*iter++);
91  }
92 
93  std::vector<double> result(out.size() * size, 0.0);
94  unsigned int k = 0;
95  for (std::vector<Config>::const_iterator config = out.begin(); config != out.end(); ++config, k++) {
96  for (unsigned int i = 0; i < config->size(); i++) {
97  double product = 1.0;
98  for (unsigned int j = 0; j < config->size(); j++)
99  if (i != j)
100  product *= values[(*config)[j]];
101 
102  result[k * size + offsets[i]] = product;
103  }
104  }
105 
106  return result;
107  }
108 
109 } // anonymous namespace
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PhysicsTools::Calibration::ProcMultiply
Definition: MVAComputer.h:178
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
pos
Definition: PixelAliasList.h:18
PhysicsTools::MVAComputer
Main interface class to the generic discriminator computer framework.
Definition: MVAComputer.h:39
trigObjTnPSource_cfi.var
var
Definition: trigObjTnPSource_cfi.py:21
config
Definition: config.py:1
PhysicsTools::VarProcessor
Common base class for variable processors.
Definition: VarProcessor.h:36
submitPVResolutionJobs.config
config
parse the configuration file
Definition: submitPVResolutionJobs.py:281
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
dqmdumpme.k
k
Definition: dqmdumpme.py:60
calib
Definition: CalibElectron.h:12
recoMuon::in
Definition: RecoMuonEnumerators.h:6
PhysicsTools
Definition: Histogram.h:13
VarProcessor.h
PhysicsTools::ProcessRegistryImpl
template to generate a registry singleton for a type.
Definition: ProcessRegistry.h:25
Calibration.h
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
Exception.h
unpackBuffers-CaloStage1.offsets
offsets
Definition: unpackBuffers-CaloStage1.py:127
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
mps_fire.result
result
Definition: mps_fire.py:311
cms::Exception
Definition: Exception.h:70
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HLT_FULL_cff.computer
computer
Definition: HLT_FULL_cff.py:52112
helper.Config
Config
Definition: helper.py:10
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443