CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Attributes
PhysicsTools::VarProcessor Class Referenceabstract

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

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
edmplugin::PluginFactory
< Dummy *()> 
PluginFactory
 

Public Member Functions

void configure (ConfigCtx &config)
 called from the discriminator computer to configure processor More...
 
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 More...
 
void eval (double *input, int *conf, double *output, int *outConf, int *loop, unsigned int offset) const
 run the processor evaluation pass on this processor More...
 
virtual LoopStatus loop (double *output, int *outConf, unsigned int nOutput, unsigned int &nOffset) const
 
virtual ~VarProcessor ()
 
- Public Member Functions inherited from PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory
template<>
VarProcessorcreate (const char *name, const Calibration::VarProcessor *calib, const MVAComputer *parent)
 
template<>
TrainProcessorcreate (const char *, const AtomicId *, MVATrainer *)
 
template<>
TrainProcessorcreate (const char *name, const AtomicId *id, MVATrainer *trainer)
 
template<>
VarProcessorcreate (const char *, const Calibration::VarProcessor *, const MVAComputer *)
 

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 More...
 
virtual ConfigCtx::ContextconfigureLoop (ConfigCtx::Context *ctx, ConfigCtx::iterator begin, ConfigCtx::iterator cur, ConfigCtx::iterator end)
 virtual loop configure method More...
 
virtual std::vector< double > deriv (ValueIterator iter, unsigned int n) const
 virtual derivative evaluation method, implemented in actual processor More...
 
virtual void eval (ValueIterator iter, unsigned int n) const =0
 virtual evaluation method, implemented in actual processor More...
 
 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 More...
 
unsigned int nInputVars
 

Additional Inherited Members

- Static Public Member Functions inherited from PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::Factory
static Base_t * create (const char *name, const CalibBase_t *calib, Parent_t *parent=0)
 

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 39 of file VarProcessor.h.

Member Typedef Documentation

Definition at line 120 of file VarProcessor.h.

Definition at line 275 of file VarProcessor.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

PhysicsTools::VarProcessor::~VarProcessor ( )
virtual

Definition at line 46 of file VarProcessor.cc.

References inputVars, and nInputVars.

47 {
48  inputVars = BitSet(0);
49  nInputVars = 0;
50 }
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:301
PhysicsTools::VarProcessor::VarProcessor ( const char *  name,
const Calibration::VarProcessor calib,
const MVAComputer computer 
)
protected

Definition at line 37 of file VarProcessor.cc.

39  :
43 {
44 }
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:301
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
const MVAComputer * computer
Definition: VarProcessor.h:297
PhysicsTools::BitSet convert(const BitSet &bitSet)
constructs BitSet container from persistent representation
Definition: BitSet.cc:38

Member Function Documentation

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

called from the discriminator computer to configure processor

Definition at line 52 of file VarProcessor.cc.

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

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

53 {
55  if (pos != inputVars.size())
56  return;
57 
58  ConfIterator iter(inputVars.iter(), config);
59  configure(iter, nInputVars);
60 
61  VarProcessor *loop = config.loop ? config.loop : this;
62  ConfigCtx::Context *ctx =
63  loop->configureLoop(config.ctx, config.begin(),
64  config.begin() + pos, config.end());
65 
66  if (ctx != config.ctx) {
67  delete config.ctx;
68  config.ctx = ctx;
69  }
70 
71  if (config.loop && !ctx)
72  config.loop = 0;
73  else if (!config.loop && ctx)
74  config.loop = this;
75 }
void configure(ConfigCtx &config)
called from the discriminator computer to configure processor
Definition: VarProcessor.cc:52
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:301
size_t size() const
returns the number of all bits in the container
Definition: BitSet.h:174
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, unsigned int &nOffset) const
Definition: VarProcessor.h:114
VarProcessor(const char *name, const Calibration::VarProcessor *calib, const MVAComputer *computer)
Definition: VarProcessor.cc:37
tuple config
Definition: cmsDriver.py:17
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:180
virtual void PhysicsTools::VarProcessor::configure ( ConfIterator  iter,
unsigned int  n 
)
protectedpure 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 
)
protectedvirtual

virtual loop configure method

Definition at line 86 of file VarProcessor.cc.

Referenced by configure().

88 {
89  return 0;
90 }
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 120 of file VarProcessor.cc.

References begin, dbtoconf::conf, gather_cfg::cout, end, eval(), i, recoMuon::in, collect_tpl::input, inputVars, PhysicsTools::BitSet::iter(), j, gen::k, loop(), m, n, nInputVars, evf::evtn::offset(), dbtoconf::out, convertSQLitetoXML_cfg::output, L1TEmulatorMonitor_cff::p, pos, lumiQueryAPI::q, and findQualityFiles::size.

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

124 {
125  ValueIterator iter(inputVars.iter(), input, conf,
126  output, outConf, loop, offset);
127 
128  eval(iter, nInputVars);
129 
130  std::vector<double> matrix = this->deriv(iter, nInputVars);
131 
132  unsigned int size = 0;
133  while(iter)
134  size += (iter++).size();
135  unsigned int out = matrix.empty() ? 0 : (matrix.size() / size);
136 
137  if (matrix.size() != out * size ||
138  (out > 1 && (int)out != outConf[out_] - outConf[0]))
139  throw cms::Exception("VarProcessor")
140  << "Derivative matrix implausible size in "
141  << typeid(*this).name() << "."
142  << std::endl;
143 
144 #ifdef DEBUG_DERIV
145  if (!matrix.empty()) {
146  std::cout << "---------------- "
147  << ROOT::Reflex::Tools::Demangle(typeid(*this))
148  << std::endl;
149  for(unsigned int i = 0; i < out; i++) {
150  for(unsigned int j = 0; j < size; j++)
151  std::cout << matrix.at(i*size+j) << "\t";
152  std::cout << std::endl;
153  }
154  std::cout << "----------------" << std::endl;
155  }
156 
157  std::cout << "======= in = " << in << ", size = " << size
158  << ", out = " << out << ", matrix = " << matrix.size()
159  << std::endl;
160 #endif
161 
162  unsigned int sz = (outConf[out_] - in) * in;
163  unsigned int oldSz = deriv.size();
164  if (oldSz < sz)
165  deriv.resize(sz);
166 
167  double *begin = &deriv.front() + (outConf[0] - in + offset) * in;
168  double *end = begin + out * in;
169  if (begin < &deriv.front() + oldSz)
170  std::fill(begin, end, 0.0);
171 
172  if (matrix.empty())
173  return;
174 
175  double *m0 = &matrix.front();
176  BitSet::Iterator cur = inputVars.iter();
177  for(unsigned int i = 0; i < nInputVars; i++, ++cur) {
178 #ifdef DEBUG_DERIV
179  std::cout << " inputvar " << i << std::endl;
180 #endif
181  int *curConf = conf + cur();
182  unsigned int pos = *curConf;
183 #ifdef DEBUG_DERIV
184  std::cout << " -> cur = " << cur() << ", pos = "
185  << pos << std::endl;
186 #endif
187  if (loop && curConf >= loop) {
188  pos += offset;
189  loop = 0;
190  }
191 
192  unsigned int n = loop ? (curConf[1] - curConf[0]) : 1;
193  for(unsigned int j = 0; j < n; m0++, j++, pos++) {
194 #ifdef DEBUG_DERIV
195  std::cout << " multip " << j << std::endl;
196 #endif
197  double *p = begin;
198  if (pos >= in) {
199 #ifdef DEBUG_DERIV
200  std::cout << " deriv " << (pos - in)
201  << std::endl;
202 #endif
203  const double *q = &deriv.front() +
204  (pos - in) * in;
205  for(const double *m = m0; p < end;
206  m += size, q -= in)
207  for(unsigned int k = 0; k < in; k++)
208  *p++ += *m * *q++;
209  } else {
210 #ifdef DEBUG_DERIV
211  std::cout << " in " << pos << std::endl;
212 #endif
213  for(const double *m = m0; p < end;
214  m += size, p += in)
215  p[pos] += *m;
216  }
217  }
218  }
219 
220 #ifdef DEBUG_DERIV
221  std::cout << "================" << std::endl;
222  for(const double *p = &deriv.front();
223  p != &deriv.front() + deriv.size();) {
224  for(unsigned int j = 0; j < in; j++)
225  std::cout << *p++ << "\t";
226  std::cout << std::endl;
227  }
228  std::cout << "================" << std::endl;
229 #endif
230 }
int i
Definition: DBlmapReader.cc:9
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
Definition: VarProcessor.h:99
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:301
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:38
unsigned int offset(bool)
tuple conf
Definition: dbtoconf.py:185
tuple input
Definition: collect_tpl.py:10
int k[5][pyjets_maxn]
tuple out
Definition: dbtoconf.py:99
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, unsigned int &nOffset) const
Definition: VarProcessor.h:114
#define begin
Definition: vmac.h:31
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:180
tuple cout
Definition: gather_cfg.py:41
tuple size
Write out results.
virtual std::vector<double> PhysicsTools::VarProcessor::deriv ( ValueIterator  iter,
unsigned int  n 
) const
inlineprotectedvirtual

virtual derivative evaluation method, implemented in actual processor

Definition at line 292 of file VarProcessor.h.

294  { return std::vector<double>(); }
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 99 of file VarProcessor.h.

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

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

101  {
102  ValueIterator iter(inputVars.iter(), input, conf,
103  output, outConf, loop, offset);
104  eval(iter, nInputVars);
105  }
void eval(double *input, int *conf, double *output, int *outConf, int *loop, unsigned int offset) const
run the processor evaluation pass on this processor
Definition: VarProcessor.h:99
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:301
unsigned int offset(bool)
tuple conf
Definition: dbtoconf.py:185
tuple input
Definition: collect_tpl.py:10
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, unsigned int &nOffset) const
Definition: VarProcessor.h:114
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:180
virtual void PhysicsTools::VarProcessor::eval ( ValueIterator  iter,
unsigned int  n 
) const
protectedpure virtual

virtual evaluation method, implemented in actual processor

Implemented in PhysicsTools::Interceptor.

virtual LoopStatus PhysicsTools::VarProcessor::loop ( double *  output,
int *  outConf,
unsigned int  nOutput,
unsigned int &  nOffset 
) const
inlinevirtual

Definition at line 114 of file VarProcessor.h.

References kStop.

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

Member Data Documentation

const MVAComputer* PhysicsTools::VarProcessor::computer
protected

Definition at line 297 of file VarProcessor.h.

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

BitSet PhysicsTools::VarProcessor::inputVars
private

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

Definition at line 301 of file VarProcessor.h.

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

unsigned int PhysicsTools::VarProcessor::nInputVars
private

Definition at line 302 of file VarProcessor.h.

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