CMS 3D CMS Logo

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
 
class  LoopCtx
 Hold context information for looping processors. More...
 
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, LoopCtx &ctx, 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, LoopCtx &loopCtx, unsigned int offset) const
 run the processor evaluation pass on this processor More...
 
virtual LoopStatus loop (double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, 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 MVAComputerRegistry
 

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

Definition at line 298 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:324
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 }
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:324
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
const MVAComputer * computer
Definition: VarProcessor.h:320
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(), looper::config, configureLoop(), PhysicsTools::VarProcessor::ConfigCtx::ctx, PhysicsTools::VarProcessor::ConfigCtx::end(), inputVars, PhysicsTools::BitSet::iter(), PhysicsTools::VarProcessor::ConfigCtx::loop, loop(), nInputVars, PhysicsTools::VarProcessor::ConfigCtx::size(), and PhysicsTools::BitSet::size().

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

54 {
56  if (pos != inputVars.size())
57  return;
58 
59  ConfIterator iter(inputVars.iter(), config);
60  configure(iter, nInputVars);
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 = nullptr;
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
Definition: config.py:1
config
Definition: looper.py:289
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:324
size_t size() const
returns the number of all bits in the container
Definition: BitSet.h:173
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 LoopStatus loop(double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, unsigned int &nOffset) const
Definition: VarProcessor.h:132
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.

References PhysicsTools::VarProcessor::ConfigCtx::VarProcessor.

Referenced by configure().

89 {
90  return nullptr;
91 }
void PhysicsTools::VarProcessor::deriv ( double *  input,
int *  conf,
double *  output,
int *  outConf,
int *  loop,
LoopCtx ctx,
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 PhysicsTools::VarProcessor::ConfigCtx::begin(), gather_cfg::cout, PhysicsTools::VarProcessor::ConfigCtx::ctx, relativeConstraints::empty, PhysicsTools::VarProcessor::ConfigCtx::end(), eval(), lumiContext::fill, mps_fire::i, recoMuon::in, input, inputVars, createfilelist::int, PhysicsTools::BitSet::iter(), gen::k, PhysicsTools::VarProcessor::ConfigCtx::loop, funct::m, makeMuonMisalignmentScenario::matrix, gen::n, nInputVars, PFRecoTauDiscriminationByIsolation_cfi::offset, MillePedeFileConverter_cfg::out, convertSQLitetoXML_cfg::output, AlCaHLTBitMon_ParallelJobs::p, lumiQueryAPI::q, PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::registerProcess(), PhysicsTools::VarProcessor::ConfigCtx::size(), AlCaHLTBitMon_QueryRunRegistry::string, edm::typeDemangle(), and PhysicsTools::ProcessRegistry< Base_t, CalibBase_t, Parent_t >::unregisterProcess().

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

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

317  { return std::vector<double>(); }
void PhysicsTools::VarProcessor::eval ( double *  input,
int *  conf,
double *  output,
int *  outConf,
int *  loop,
LoopCtx loopCtx,
unsigned int  offset 
) const
inline

run the processor evaluation pass on this processor

Definition at line 117 of file VarProcessor.h.

References deriv(), recoMuon::in, input, inputVars, PhysicsTools::BitSet::iter(), loop(), nInputVars, PFRecoTauDiscriminationByIsolation_cfi::offset, MillePedeFileConverter_cfg::out, and convertSQLitetoXML_cfg::output.

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

119  {
120  ValueIterator iter(inputVars.iter(), input, conf,
121  output, outConf, loop, loopCtx, offset);
122  eval(iter, nInputVars);
123  }
static std::string const input
Definition: EdmProvDump.cc:45
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:324
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:179
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, unsigned int &nOffset) const
Definition: VarProcessor.h:132
void eval(double *input, int *conf, double *output, int *outConf, int *loop, LoopCtx &loopCtx, unsigned int offset) const
run the processor evaluation pass on this processor
Definition: VarProcessor.h:117
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,
LoopCtx ctx,
unsigned int &  nOffset 
) const
inlinevirtual

Definition at line 132 of file VarProcessor.h.

References kStop.

Referenced by configure(), and eval().

Member Data Documentation

const MVAComputer* PhysicsTools::VarProcessor::computer
protected

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

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

unsigned int PhysicsTools::VarProcessor::nInputVars
private

Definition at line 325 of file VarProcessor.h.

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