CMS 3D CMS Logo

Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes

PhysicsTools::VarProcessor Class Reference

Common base class for variable processors. More...

#include <VarProcessor.h>

Inheritance diagram for PhysicsTools::VarProcessor:
PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory PhysicsTools::Interceptor

List of all members.

Classes

class  Config
 Helper class for discriminator computer set-up procedure. More...
class  ConfigCtx
class  ConfIterator
 Iterator to loop over the input/output variable configuration. More...
struct  Dummy
struct  ValueIterator

Public Types

enum  LoopStatus { kStop, kNext, kReset, kSkip }
typedef DummyPluginFunctionPrototype ()

Public Member Functions

void configure (ConfigCtx &config)
 called from the discriminator computer to configure processor
void deriv (double *input, int *conf, double *output, int *outConf, int *loop, unsigned int offset, unsigned int in, unsigned int out, std::vector< double > &deriv) const
 run the processor evaluation pass on this processor and compute derivatives
void eval (double *input, int *conf, double *output, int *outConf, int *loop, unsigned int offset) const
 run the processor evaluation pass on this processor
virtual LoopStatus loop (double *output, int *outConf, unsigned int nOutput, unsigned int &nOffset) const
virtual ~VarProcessor ()

Protected Types

typedef ProcessRegistry
< VarProcessor,
Calibration::VarProcessor,
const MVAComputer
Registry

Protected Member Functions

virtual void configure (ConfIterator iter, unsigned int n)=0
 virtual configure method, implemented in actual processor
virtual ConfigCtx::ContextconfigureLoop (ConfigCtx::Context *ctx, ConfigCtx::iterator begin, ConfigCtx::iterator cur, ConfigCtx::iterator end)
 virtual loop configure method
virtual std::vector< double > deriv (ValueIterator iter, unsigned int n) const
 virtual derivative evaluation method, implemented in actual processor
virtual void eval (ValueIterator iter, unsigned int n) const =0
 virtual evaluation method, implemented in actual processor
 VarProcessor (const char *name, const Calibration::VarProcessor *calib, const MVAComputer *computer)

Protected Attributes

const MVAComputercomputer

Private Attributes

BitSet inputVars
 bit set to select the input variables to be passed to this processor
unsigned int nInputVars

Detailed Description

Common base class for variable processors.

This base class for variable processors manages the common interface to the global discriminator class and how the individual variable processors are interconnected.

Definition at line 37 of file VarProcessor.h.


Member Typedef Documentation

Definition at line 119 of file VarProcessor.h.

Reimplemented in PhysicsTools::Interceptor.

Definition at line 274 of file VarProcessor.h.


Member Enumeration Documentation

Enumerator:
kStop 
kNext 
kReset 
kSkip 

Definition at line 110 of file VarProcessor.h.


Constructor & Destructor Documentation

PhysicsTools::VarProcessor::~VarProcessor ( ) [virtual]

Definition at line 48 of file VarProcessor.cc.

References inputVars, and nInputVars.

{
        inputVars = BitSet(0);
        nInputVars = 0;
}
PhysicsTools::VarProcessor::VarProcessor ( const char *  name,
const Calibration::VarProcessor calib,
const MVAComputer computer 
) [protected]

Definition at line 39 of file VarProcessor.cc.


Member Function Documentation

void PhysicsTools::VarProcessor::configure ( ConfigCtx config)

called from the discriminator computer to configure processor

Definition at line 54 of file VarProcessor.cc.

References PhysicsTools::VarProcessor::ConfigCtx::begin(), HDQMDatabaseProducer::config, configureLoop(), PhysicsTools::VarProcessor::ConfigCtx::ctx, PhysicsTools::VarProcessor::ConfigCtx::end(), inputVars, PhysicsTools::BitSet::iter(), loop(), PhysicsTools::VarProcessor::ConfigCtx::loop, nInputVars, pos, PhysicsTools::VarProcessor::ConfigCtx::size(), and PhysicsTools::BitSet::size().

Referenced by PhysicsTools::MVAComputer::setup().

{
        ConfigCtx::size_type pos = config.size();
        if (pos != inputVars.size())
                return;

        ConfIterator iter(inputVars.iter(), config);
        configure(iter, nInputVars);

        VarProcessor *loop = config.loop ? config.loop : this;
        ConfigCtx::Context *ctx =
                loop->configureLoop(config.ctx, config.begin(),
                                    config.begin() + pos, config.end());

        if (ctx != config.ctx) {
                delete config.ctx;
                config.ctx = ctx;
        }

        if (config.loop && !ctx)
                config.loop = 0;
        else if (!config.loop && ctx)
                config.loop = this;
}
virtual void PhysicsTools::VarProcessor::configure ( ConfIterator  iter,
unsigned int  n 
) [protected, pure virtual]

virtual configure method, implemented in actual processor

Implemented in PhysicsTools::Interceptor.

VarProcessor::ConfigCtx::Context * PhysicsTools::VarProcessor::configureLoop ( ConfigCtx::Context ctx,
ConfigCtx::iterator  begin,
ConfigCtx::iterator  cur,
ConfigCtx::iterator  end 
) [protected, virtual]

virtual loop configure method

Definition at line 88 of file VarProcessor.cc.

Referenced by configure().

{
        return 0;
}
virtual std::vector<double> PhysicsTools::VarProcessor::deriv ( ValueIterator  iter,
unsigned int  n 
) const [inline, protected, virtual]

virtual derivative evaluation method, implemented in actual processor

Definition at line 291 of file VarProcessor.h.

        { return std::vector<double>(); }
void PhysicsTools::VarProcessor::deriv ( double *  input,
int *  conf,
double *  output,
int *  outConf,
int *  loop,
unsigned int  offset,
unsigned int  in,
unsigned int  out,
std::vector< double > &  deriv 
) const

run the processor evaluation pass on this processor and compute derivatives

Definition at line 122 of file VarProcessor.cc.

References begin, dbtoconf::conf, gather_cfg::cout, ora::ClassUtils::demangledName(), relativeConstraints::empty, end, eval(), lumiContext::fill, i, recoMuon::in, LaserDQM_cfg::input, inputVars, PhysicsTools::BitSet::iter(), j, gen::k, loop(), m, makeMuonMisalignmentScenario::matrix, n, nInputVars, evf::evtn::offset(), dbtoconf::out, convertSQLitetoXML_cfg::output, AlCaHLTBitMon_ParallelJobs::p, pos, lumiQueryAPI::q, findQualityFiles::size, AlCaHLTBitMon_QueryRunRegistry::string, and edm::typeDemangle().

Referenced by PhysicsTools::MVAComputer::DerivContext::eval().

{
        ValueIterator iter(inputVars.iter(), input, conf,
                           output, outConf, loop, offset);

        eval(iter, nInputVars);

        std::vector<double> matrix = this->deriv(iter, nInputVars);

        unsigned int size = 0;
        while(iter)
                size += (iter++).size();
        bool empty = matrix.empty();
        assert(size != 0 || empty);
        unsigned int out = empty ? 0 : (matrix.size() / size);

        if (matrix.size() != out * size ||
            (out > 1 && (int)out != outConf[out_] - outConf[0]))
                throw cms::Exception("VarProcessor")
                        << "Derivative matrix implausible size in "
                        << typeid(*this).name() << "."
                        << std::endl;

#ifdef DEBUG_DERIV
        if (!matrix.empty()) {
                std::string demangledName;
                edm::typeDemangle(typeid(*this).name(), demangledName);
                std::cout << demangledName << std::endl;
                for(unsigned int i = 0; i < out; i++) {
                        for(unsigned int j = 0; j < size; j++)
                                std::cout << matrix.at(i*size+j) << "\t";
                        std::cout << std::endl;
                }
                std::cout << "----------------" << std::endl;
        }

        std::cout << "======= in = " << in << ", size = " << size
                  << ", out = " << out << ", matrix = " << matrix.size()
                  << std::endl;
#endif

        unsigned int sz = (outConf[out_] - in) * in;
        unsigned int oldSz = deriv.size();
        if (oldSz < sz)
                deriv.resize(sz);

        double *begin = &deriv.front() + (outConf[0] - in + offset) * in;
        double *end = begin + out * in;
        if (begin < &deriv.front() + oldSz)
                std::fill(begin, end, 0.0);

        if (matrix.empty())
                return;

        double *m0 = &matrix.front();
        BitSet::Iterator cur = inputVars.iter();
        for(unsigned int i = 0; i < nInputVars; i++, ++cur) {
#ifdef DEBUG_DERIV
                std::cout << " inputvar " << i << std::endl;
#endif
                int *curConf = conf + cur();
                unsigned int pos = *curConf;
#ifdef DEBUG_DERIV
                std::cout << " -> cur = " << cur() << ", pos = "
                          << pos << std::endl;
#endif
                if (loop && curConf >= loop) {
                        pos += offset;
                        loop = 0;
                }

                unsigned int n = loop ? (curConf[1] - curConf[0]) : 1;
                for(unsigned int j = 0; j < n; m0++, j++, pos++) {
#ifdef DEBUG_DERIV
                        std::cout << "  multip " << j << std::endl;
#endif
                        double *p = begin;
                        if (pos >= in) {
#ifdef DEBUG_DERIV
                                std::cout << "   deriv " << (pos - in)
                                          << std::endl;
#endif
                                const double *q = &deriv.front() +
                                                  (pos - in) * in;
                                for(const double *m = m0; p < end;
                                    m += size, q -= in)
                                        for(unsigned int k = 0; k < in; k++)
                                                *p++ += *m * *q++;
                        } else {
#ifdef DEBUG_DERIV
                                std::cout << "   in " << pos << std::endl;
#endif
                                for(const double *m = m0; p < end;
                                    m += size, p += in)
                                        p[pos] += *m;
                        }
                }
        }

#ifdef DEBUG_DERIV
        std::cout << "================" << std::endl;
        for(const double *p = &deriv.front();
            p != &deriv.front() + deriv.size();) {
                for(unsigned int j = 0; j < in; j++)
                        std::cout << *p++ << "\t";
                std::cout << std::endl;
        }
        std::cout << "================" << std::endl;
#endif
}
virtual void PhysicsTools::VarProcessor::eval ( ValueIterator  iter,
unsigned int  n 
) const [protected, pure virtual]

virtual evaluation method, implemented in actual processor

Implemented in PhysicsTools::Interceptor.

void PhysicsTools::VarProcessor::eval ( double *  input,
int *  conf,
double *  output,
int *  outConf,
int *  loop,
unsigned int  offset 
) const [inline]

run the processor evaluation pass on this processor

Definition at line 97 of file VarProcessor.h.

References dbtoconf::conf, LaserDQM_cfg::input, inputVars, PhysicsTools::BitSet::iter(), loop(), nInputVars, evf::evtn::offset(), and convertSQLitetoXML_cfg::output.

Referenced by deriv(), and PhysicsTools::MVAComputer::EvalContext::eval().

        {
                ValueIterator iter(inputVars.iter(), input, conf,
                                   output, outConf, loop, offset);
                eval(iter, nInputVars);
        }
virtual LoopStatus PhysicsTools::VarProcessor::loop ( double *  output,
int *  outConf,
unsigned int  nOutput,
unsigned int &  nOffset 
) const [inline, virtual]

Definition at line 112 of file VarProcessor.h.

References kStop.

Referenced by configure(), deriv(), and eval().

        { return kStop; }

Member Data Documentation

Definition at line 296 of file VarProcessor.h.

Referenced by PhysicsTools::Interceptor::configure().

bit set to select the input variables to be passed to this processor

Definition at line 300 of file VarProcessor.h.

Referenced by configure(), deriv(), eval(), and ~VarProcessor().

Definition at line 301 of file VarProcessor.h.

Referenced by configure(), deriv(), eval(), and ~VarProcessor().