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 *, const Calibration::VarProcessor *, const MVAComputer *)
 
template<>
VarProcessorcreate (const char *name, const Calibration::VarProcessor *calib, const MVAComputer *parent)
 

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

Enumerator
kStop 
kNext 
kReset 
kSkip 

Definition at line 132 of file VarProcessor.h.

132 { kStop, kNext, kReset, kSkip };

Constructor & Destructor Documentation

◆ ~VarProcessor()

PhysicsTools::VarProcessor::~VarProcessor ( )
virtual

Definition at line 40 of file VarProcessor.cc.

40  {
41  inputVars = BitSet(0);
42  nInputVars = 0;
43  }

References inputVars, and nInputVars.

◆ VarProcessor()

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

Definition at line 37 of file VarProcessor.cc.

Member Function Documentation

◆ configure() [1/2]

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

called from the discriminator computer to configure processor

Definition at line 45 of file VarProcessor.cc.

45  {
47  if (pos != inputVars.size())
48  return;
49 
50  ConfIterator iter(inputVars.iter(), config);
51  configure(iter, nInputVars);
52 
53  VarProcessor *loop = config.loop ? config.loop : this;
54  ConfigCtx::Context *ctx = loop->configureLoop(config.ctx, config.begin(), config.begin() + pos, config.end());
55 
56  if (ctx != config.ctx) {
57  delete config.ctx;
58  config.ctx = ctx;
59  }
60 
61  if (config.loop && !ctx)
62  config.loop = nullptr;
63  else if (!config.loop && ctx)
64  config.loop = this;
65  }

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

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

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

75  {
76  return nullptr;
77  }

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

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

References cms::cuda::assert(), begin, gather_cfg::cout, relativeConstraints::empty, end, 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, data-class-funcs::q, findQualityFiles::size, AlCaHLTBitMon_QueryRunRegistry::string, and edm::typeDemangle().

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

115  {
116  ValueIterator iter(inputVars.iter(), input, conf, output, outConf, loop, loopCtx, offset);
117  eval(iter, nInputVars);
118  }

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

Referenced by deriv().

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

135  {
136  return kStop;
137  }

References kStop.

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

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

PhysicsTools::Calibration::convert
PhysicsTools::BitSet convert(const BitSet &bitSet)
constructs BitSet container from persistent representation
Definition: BitSet.cc:25
mps_fire.i
i
Definition: mps_fire.py:355
input
static const std::string input
Definition: EdmProvDump.cc:48
PhysicsTools::VarProcessor::deriv
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
Definition: VarProcessor.cc:103
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
makeMuonMisalignmentScenario.matrix
list matrix
Definition: makeMuonMisalignmentScenario.py:141
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
edm::typeDemangle
std::string typeDemangle(char const *mangledName)
Definition: TypeDemangler.cc:93
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
PhysicsTools::BitSet::size
size_t size() const
returns the number of all bits in the container
Definition: BitSet.h:173
PhysicsTools::VarProcessor::computer
const MVAComputer * computer
Definition: VarProcessor.h:333
data-class-funcs.q
q
Definition: data-class-funcs.py:169
cms::cuda::assert
assert(be >=bs)
PhysicsTools::VarProcessor::eval
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
end
#define end
Definition: vmac.h:39
PhysicsTools::VarProcessor::kReset
Definition: VarProcessor.h:132
config
Definition: config.py:1
cms::Iterator
TGeoIterator Iterator
Definition: DDFilteredView.h:49
PhysicsTools::VarProcessor::VarProcessor
VarProcessor(const char *name, const Calibration::VarProcessor *calib, const MVAComputer *computer)
Definition: VarProcessor.cc:37
visualization-live-secondInstance_cfg.m
m
Definition: visualization-live-secondInstance_cfg.py:72
PhysicsTools::BitSet::iter
Iterator iter() const
create iterator over all set bits
Definition: BitSet.h:179
PhysicsTools::VarProcessor::loop
virtual LoopStatus loop(double *output, int *outConf, unsigned int nOutput, LoopCtx &ctx, unsigned int &nOffset) const
Definition: VarProcessor.h:134
dqmdumpme.k
k
Definition: dqmdumpme.py:60
looper.config
config
Definition: looper.py:291
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
calib
Definition: CalibElectron.h:12
ntuplemaker.fill
fill
Definition: ntuplemaker.py:304
PhysicsTools::VarProcessor::nInputVars
unsigned int nInputVars
Definition: VarProcessor.h:338
PhysicsTools::VarProcessor::kSkip
Definition: VarProcessor.h:132
recoMuon::in
Definition: RecoMuonEnumerators.h:6
createfilelist.int
int
Definition: createfilelist.py:10
PhysicsTools::VarProcessor::ConfigCtx::size_type
Config_t::size_type size_type
Definition: VarProcessor.h:60
PhysicsTools::VarProcessor::configure
void configure(ConfigCtx &config)
called from the discriminator computer to configure processor
Definition: VarProcessor.cc:45
PhysicsTools::BitSet::bits
size_t bits() const
returns the number of set bits in the container
Definition: BitSet.cc:6
PhysicsTools::VarProcessor::kStop
Definition: VarProcessor.h:132
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
PhysicsTools::VarProcessor::kNext
Definition: VarProcessor.h:132
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
cms::Exception
Definition: Exception.h:70
PhysicsTools::VarProcessor::inputVars
BitSet inputVars
bit set to select the input variables to be passed to this processor
Definition: VarProcessor.h:337
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:78
begin
#define begin
Definition: vmac.h:32
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443