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 DummyPluginFunctionPrototype ()
 

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

Member Typedef Documentation

typedef Dummy* PhysicsTools::VarProcessor::PluginFunctionPrototype()

Definition at line 118 of file VarProcessor.h.

Definition at line 273 of file VarProcessor.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

PhysicsTools::VarProcessor::~VarProcessor ( )
virtual

Definition at line 47 of file VarProcessor.cc.

References inputVars, and nInputVars.

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

Definition at line 38 of file VarProcessor.cc.

40  :
44 {
45 }
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:299
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
const MVAComputer * computer
Definition: VarProcessor.h:295
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 53 of file VarProcessor.cc.

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

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

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

Referenced by configure().

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

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

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

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

292  { 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 96 of file VarProcessor.h.

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

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

98  {
99  ValueIterator iter(inputVars.iter(), input, conf,
100  output, outConf, loop, offset);
101  eval(iter, nInputVars);
102  }
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:96
static std::string const input
Definition: EdmProvDump.cc:44
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:299
unsigned int offset(bool)
tuple conf
Definition: dbtoconf.py:185
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, unsigned int &nOffset) const
Definition: VarProcessor.h:111
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:179
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 111 of file VarProcessor.h.

References kStop.

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

Member Data Documentation

const MVAComputer* PhysicsTools::VarProcessor::computer
protected

Definition at line 295 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 299 of file VarProcessor.h.

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

unsigned int PhysicsTools::VarProcessor::nInputVars
private

Definition at line 300 of file VarProcessor.h.

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