00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdlib.h>
00016 #include <algorithm>
00017 #include <iterator>
00018 #include <vector>
00019
00020 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
00021 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
00022
00023 using namespace PhysicsTools;
00024
00025 namespace {
00026
00027 class ProcMultiply : public VarProcessor {
00028 public:
00029 typedef VarProcessor::Registry::Registry<ProcMultiply,
00030 Calibration::ProcMultiply> Registry;
00031
00032 ProcMultiply(const char *name,
00033 const Calibration::ProcMultiply *calib,
00034 const MVAComputer *computer);
00035 virtual ~ProcMultiply() {}
00036
00037 virtual void configure(ConfIterator iter, unsigned int n);
00038 virtual void eval(ValueIterator iter, unsigned int n) const;
00039
00040 private:
00041 typedef std::vector<unsigned int> Config;
00042
00043 unsigned int in;
00044 std::vector<Config> out;
00045 };
00046
00047 static ProcMultiply::Registry registry("ProcMultiply");
00048
00049 ProcMultiply::ProcMultiply(const char *name,
00050 const Calibration::ProcMultiply *calib,
00051 const MVAComputer *computer) :
00052 VarProcessor(name, calib, computer),
00053 in(calib->in)
00054 {
00055 std::copy(calib->out.begin(), calib->out.end(),
00056 std::back_inserter(out));
00057 }
00058
00059 void ProcMultiply::configure(ConfIterator iter, unsigned int n)
00060 {
00061 if (in != n)
00062 return;
00063
00064 for(unsigned int i = 0; i < in; i++)
00065 iter++(Variable::FLAG_NONE);
00066
00067 for(unsigned int i = 0; i < out.size(); i++)
00068 iter << Variable::FLAG_NONE;
00069 }
00070
00071 void ProcMultiply::eval(ValueIterator iter, unsigned int n) const
00072 {
00073 double *values = (double*)alloca(in * sizeof(double));
00074 for(double *pos = values; iter; iter++, pos++)
00075 *pos = *iter;
00076
00077 for(std::vector<Config>::const_iterator config = out.begin();
00078 config != out.end(); config++) {
00079 double product = 1.0;
00080 for(std::vector<unsigned int>::const_iterator var =
00081 config->begin();
00082 var != config->end(); var++)
00083 product *= values[*var];
00084
00085 iter(product);
00086 }
00087 }
00088
00089 }