CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/PhysicsTools/MVATrainer/src/Interceptor.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Discriminator
00004 // Class  :     Interceptor
00005 // 
00006 
00007 // Implementation:
00008 //     Pseudo variable processor that just intercepts all the incoming
00009 //     variables and forwards them to the calibration class.
00010 //
00011 // Author:      Christophe Saout
00012 // Created:     Sat May 05 09:05 CEST 2007
00013 // $Id: Interceptor.cc,v 1.3 2009/03/27 14:33:39 saout Exp $
00014 //
00015 
00016 #include <vector>
00017 #include <algorithm>
00018 
00019 #include "PhysicsTools/MVAComputer/interface/VarProcessor.h"
00020 #include "PhysicsTools/MVAComputer/interface/Variable.h"
00021 
00022 #include "PhysicsTools/MVATrainer/interface/Interceptor.h"
00023 
00024 namespace PhysicsTools {
00025 
00026 class Interceptor : public VarProcessor {
00027     public:
00028         typedef VarProcessor::Registry::Registry<Interceptor,
00029                                         Calibration::Interceptor> Registry;
00030 
00031         Interceptor(const char *name,
00032                     const Calibration::Interceptor *calib,
00033                     const MVAComputer *computer);
00034         virtual ~Interceptor();
00035 
00036         virtual void configure(ConfIterator iter, unsigned int n);
00037         virtual void eval(ValueIterator iter, unsigned int n) const;
00038 
00039     private:
00040         Calibration::Interceptor        *interceptor;
00041         std::vector<double>             *values;
00042 };
00043 
00044 static Interceptor::Registry registry("Interceptor");
00045 
00046 Interceptor::Interceptor(const char *name,
00047                          const Calibration::Interceptor *calib,
00048                          const MVAComputer *computer) :
00049         VarProcessor(name, calib, computer),
00050         interceptor(const_cast<Calibration::Interceptor*>(calib)),
00051         values(0)
00052 {
00053 }
00054 
00055 Interceptor::~Interceptor()
00056 {
00057         delete[] values;
00058 }
00059 
00060 void Interceptor::configure(ConfIterator iter, unsigned int n)
00061 {
00062         std::vector<Variable::Flags> flags;
00063         for(ConfIterator iter2 = iter; iter2; iter2++)
00064                 flags.push_back(*iter2);
00065 
00066         flags = interceptor->configure(computer, n, flags);
00067         if (flags.size() != n)
00068                 return;
00069 
00070         for(unsigned int i = 0; i < n; i++)
00071                 iter++(flags[i]);
00072 
00073         iter << Variable::FLAG_NONE;
00074 
00075         values = new std::vector<double>[n];
00076 }
00077 
00078 void Interceptor::eval(ValueIterator iter, unsigned int n) const
00079 {
00080         std::vector<double> *var = values;
00081 
00082         for(unsigned int i = 0; i < n; i++) {
00083                 var->resize(iter.size());
00084                 std::copy(iter.begin(), iter.end(), var->begin());
00085                 iter++;
00086                 var++;
00087         }
00088 
00089         interceptor->intercept(values);
00090 
00091         iter(0.0);
00092 }
00093 
00094 } // namespace PhysicsTools