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

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<>
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

◆ PluginFunctionPrototype

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

Definition at line 141 of file VarProcessor.h.

◆ Registry

Definition at line 313 of file VarProcessor.h.

Member Enumeration Documentation

◆ LoopStatus

Constructor & Destructor Documentation

◆ ~VarProcessor()

PhysicsTools::VarProcessor::~VarProcessor ( )
virtual

Definition at line 42 of file VarProcessor.cc.

References inputVars, and nInputVars.

42  {
43  inputVars = BitSet(0);
44  nInputVars = 0;
45  }
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:337

◆ VarProcessor()

PhysicsTools::VarProcessor::VarProcessor ( const char *  name,
const Calibration::VarProcessor calib,
const MVAComputer computer 
)
protected

Definition at line 39 of file VarProcessor.cc.

size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:337
const MVAComputer * computer
Definition: VarProcessor.h:333
PhysicsTools::BitSet convert(const BitSet &bitSet)
constructs BitSet container from persistent representation
Definition: BitSet.cc:25

Member Function Documentation

◆ configure() [1/2]

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

called from the discriminator computer to configure processor

Definition at line 47 of file VarProcessor.cc.

References DMR_cfg::config, inputVars, PhysicsTools::BitSet::iter(), loop(), nInputVars, and PhysicsTools::BitSet::size().

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

47  {
49  if (pos != inputVars.size())
50  return;
51 
52  ConfIterator iter(inputVars.iter(), config);
53  configure(iter, nInputVars);
54 
55  VarProcessor *loop = config.loop ? config.loop : this;
56  ConfigCtx::Context *ctx = loop->configureLoop(config.ctx, config.begin(), config.begin() + pos, config.end());
57 
58  if (ctx != config.ctx) {
59  delete config.ctx;
60  config.ctx = ctx;
61  }
62 
63  if (config.loop && !ctx)
64  config.loop = nullptr;
65  else if (!config.loop && ctx)
66  config.loop = this;
67  }
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:179
dictionary config
Read in AllInOne config in JSON format.
Definition: DMR_cfg.py:21
void configure(ConfigCtx &config)
called from the discriminator computer to configure processor
Definition: VarProcessor.cc:47
Definition: config.py:1
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:337
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:39
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, unsigned int &nOffset) const
Definition: VarProcessor.h:134

◆ configure() [2/2]

virtual void PhysicsTools::VarProcessor::configure ( ConfIterator  iter,
unsigned int  n 
)
protectedpure virtual

virtual configure method, implemented in actual processor

◆ configureLoop()

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 74 of file VarProcessor.cc.

77  {
78  return nullptr;
79  }

◆ deriv() [1/2]

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 105 of file VarProcessor.cc.

References cms::cuda::assert(), gather_cfg::cout, relativeConstraints::empty, eval(), ntuplemaker::fill, mps_fire::i, recoMuon::in, input, inputVars, createfilelist::int, PhysicsTools::BitSet::iter(), dqmiolumiharvest::j, dqmdumpme::k, loop(), visualization-live-secondInstance_cfg::m, makeMuonMisalignmentScenario::matrix, dqmiodumpmetadata::n, nInputVars, hltrates_dqm_sourceclient-live_cfg::offset, MillePedeFileConverter_cfg::out, convertSQLitetoXML_cfg::output, AlCaHLTBitMon_ParallelJobs::p, submitPVResolutionJobs::q, AlCaHLTBitMon_QueryRunRegistry::string, and edm::typeDemangle().

114  {
115  ValueIterator iter(inputVars.iter(), input, conf, output, outConf, loop, ctx, offset);
116 
117  eval(iter, nInputVars);
118 
119  std::vector<double> matrix = this->deriv(iter, nInputVars);
120 
121  unsigned int size = 0;
122  while (iter)
123  size += (iter++).size();
124  bool empty = matrix.empty();
125  assert(size != 0 || empty);
126  unsigned int out = empty ? 0 : (matrix.size() / size);
127 
128  if (matrix.size() != out * size || (out > 1 && (int)out != outConf[out_] - outConf[0]))
129  throw cms::Exception("VarProcessor")
130  << "Derivative matrix implausible size in " << typeid(*this).name() << "." << std::endl;
131 
132 #ifdef DEBUG_DERIV
133  if (!matrix.empty()) {
134  std::string demangledName;
135  edm::typeDemangle(typeid(*this).name(), demangledName);
136  std::cout << demangledName << std::endl;
137  for (unsigned int i = 0; i < out; i++) {
138  for (unsigned int j = 0; j < size; j++)
139  std::cout << matrix.at(i * size + j) << "\t";
140  std::cout << std::endl;
141  }
142  std::cout << "----------------" << std::endl;
143  }
144 
145  std::cout << "======= in = " << in << ", size = " << size << ", out = " << out << ", matrix = " << matrix.size()
146  << std::endl;
147 #endif
148 
149  unsigned int sz = (outConf[out_] - in) * in;
150  unsigned int oldSz = deriv.size();
151  if (oldSz < sz)
152  deriv.resize(sz);
153 
154  double *begin = &deriv.front() + (outConf[0] - in + offset) * in;
155  double *end = begin + out * in;
156  if (begin < &deriv.front() + oldSz)
157  std::fill(begin, end, 0.0);
158 
159  if (matrix.empty())
160  return;
161 
162  double *m0 = &matrix.front();
164  for (unsigned int i = 0; i < nInputVars; i++, ++cur) {
165 #ifdef DEBUG_DERIV
166  std::cout << " inputvar " << i << std::endl;
167 #endif
168  int *curConf = conf + cur();
169  unsigned int pos = *curConf;
170 #ifdef DEBUG_DERIV
171  std::cout << " -> cur = " << cur() << ", pos = " << pos << std::endl;
172 #endif
173  if (loop && curConf >= loop) {
174  pos += offset;
175  loop = nullptr;
176  }
177 
178  unsigned int n = loop ? (curConf[1] - curConf[0]) : 1;
179  for (unsigned int j = 0; j < n; m0++, j++, pos++) {
180 #ifdef DEBUG_DERIV
181  std::cout << " multip " << j << std::endl;
182 #endif
183  double *p = begin;
184  if (pos >= in) {
185 #ifdef DEBUG_DERIV
186  std::cout << " deriv " << (pos - in) << std::endl;
187 #endif
188  const double *q = &deriv.front() + (pos - in) * in;
189  for (const double *m = m0; p < end; m += size, q -= in)
190  for (unsigned int k = 0; k < in; k++)
191  *p++ += *m * *q++;
192  } else {
193 #ifdef DEBUG_DERIV
194  std::cout << " in " << pos << std::endl;
195 #endif
196  for (const double *m = m0; p < end; m += size, p += in)
197  p[pos] += *m;
198  }
199  }
200  }
201 
202 #ifdef DEBUG_DERIV
203  std::cout << "================" << std::endl;
204  for (const double *p = &deriv.front(); p != &deriv.front() + deriv.size();) {
205  for (unsigned int j = 0; j < in; j++)
206  std::cout << *p++ << "\t";
207  std::cout << std::endl;
208  }
209  std::cout << "================" << std::endl;
210 #endif
211  }
size
Write out results.
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:179
assert(be >=bs)
TGeoIterator Iterator
static std::string const input
Definition: EdmProvDump.cc:50
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:337
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
std::string typeDemangle(char const *mangledName)
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, unsigned int &nOffset) const
Definition: VarProcessor.h:134
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:114

◆ deriv() [2/2]

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

330 { return std::vector<double>(); }

◆ eval() [1/2]

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

References input, inputVars, PhysicsTools::BitSet::iter(), loop(), nInputVars, hltrates_dqm_sourceclient-live_cfg::offset, and convertSQLitetoXML_cfg::output.

Referenced by deriv().

115  {
116  ValueIterator iter(inputVars.iter(), input, conf, output, outConf, loop, loopCtx, offset);
117  eval(iter, nInputVars);
118  }
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:179
static std::string const input
Definition: EdmProvDump.cc:50
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:337
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, unsigned int &nOffset) const
Definition: VarProcessor.h:134
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:114

◆ eval() [2/2]

virtual void PhysicsTools::VarProcessor::eval ( ValueIterator  iter,
unsigned int  n 
) const
protectedpure virtual

virtual evaluation method, implemented in actual processor

◆ loop()

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

Definition at line 134 of file VarProcessor.h.

References kStop.

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

135  {
136  return kStop;
137  }

Member Data Documentation

◆ computer

const MVAComputer* PhysicsTools::VarProcessor::computer
protected

Definition at line 333 of file VarProcessor.h.

◆ inputVars

BitSet PhysicsTools::VarProcessor::inputVars
private

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

Definition at line 337 of file VarProcessor.h.

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

◆ nInputVars

unsigned int PhysicsTools::VarProcessor::nInputVars
private

Definition at line 338 of file VarProcessor.h.

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