File indexing completed on 2021-11-15 04:14:47
0001 #ifndef CondFormats_PhysicsToolsObjects_MVAComputer_h
0002 #define CondFormats_PhysicsToolsObjects_MVAComputer_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include "CondFormats/Serialization/interface/Serializable.h"
0016
0017 #include <memory>
0018 #include <string>
0019 #include <vector>
0020 #include <map>
0021
0022 #include "CondFormats/PhysicsToolsObjects/interface/Histogram.h"
0023
0024 namespace PhysicsTools {
0025 namespace Calibration {
0026
0027
0028
0029 class BitSet {
0030 public:
0031
0032 BitSet &operator=(const BitSet &other) {
0033 store = other.store;
0034 bitsInLast = other.bitsInLast;
0035 return *this;
0036 }
0037
0038 std::vector<unsigned char> store;
0039 unsigned int bitsInLast;
0040
0041 COND_SERIALIZABLE;
0042 };
0043
0044 class Matrix {
0045 public:
0046 std::vector<double> elements;
0047 unsigned int rows;
0048 unsigned int columns;
0049
0050 COND_SERIALIZABLE;
0051 };
0052
0053
0054
0055 class VarProcessor {
0056 public:
0057 BitSet inputVars;
0058
0059 virtual ~VarProcessor() {}
0060 virtual std::string getInstanceName() const;
0061 virtual std::unique_ptr<VarProcessor> clone() const;
0062
0063 COND_SERIALIZABLE;
0064 };
0065
0066 class Variable {
0067 public:
0068 inline Variable() {}
0069 inline Variable(const std::string &name) : name(name) {}
0070 inline ~Variable() {}
0071
0072 std::string name;
0073
0074 COND_SERIALIZABLE;
0075 };
0076
0077
0078
0079 class ProcOptional : public VarProcessor {
0080 public:
0081 std::unique_ptr<VarProcessor> clone() const override;
0082 std::vector<double> neutralPos;
0083
0084 COND_SERIALIZABLE;
0085 };
0086
0087 class ProcCount : public VarProcessor {
0088 public:
0089 std::unique_ptr<VarProcessor> clone() const override;
0090 COND_SERIALIZABLE;
0091 };
0092
0093 class ProcClassed : public VarProcessor {
0094 public:
0095 std::unique_ptr<VarProcessor> clone() const override;
0096 unsigned int nClasses;
0097
0098 COND_SERIALIZABLE;
0099 };
0100
0101 class ProcSplitter : public VarProcessor {
0102 public:
0103 std::unique_ptr<VarProcessor> clone() const override;
0104 unsigned int nFirst;
0105
0106 COND_SERIALIZABLE;
0107 };
0108
0109 class ProcForeach : public VarProcessor {
0110 public:
0111 std::unique_ptr<VarProcessor> clone() const override;
0112 unsigned int nProcs;
0113
0114 COND_SERIALIZABLE;
0115 };
0116
0117 class ProcSort : public VarProcessor {
0118 public:
0119 std::unique_ptr<VarProcessor> clone() const override;
0120 unsigned int sortByIndex;
0121 bool descending;
0122
0123 COND_SERIALIZABLE;
0124 };
0125
0126 class ProcCategory : public VarProcessor {
0127 public:
0128 std::unique_ptr<VarProcessor> clone() const override;
0129 typedef std::vector<double> BinLimits;
0130
0131 std::vector<BinLimits> variableBinLimits;
0132 std::vector<int> categoryMapping;
0133
0134 COND_SERIALIZABLE;
0135 };
0136
0137 class ProcNormalize : public VarProcessor {
0138 public:
0139 std::unique_ptr<VarProcessor> clone() const override;
0140 std::vector<HistogramF> distr;
0141 int categoryIdx;
0142
0143 COND_SERIALIZABLE;
0144 };
0145
0146 class ProcLikelihood : public VarProcessor {
0147 public:
0148 std::unique_ptr<VarProcessor> clone() const override;
0149 class SigBkg {
0150 public:
0151 HistogramF background;
0152 HistogramF signal;
0153 bool useSplines;
0154
0155 COND_SERIALIZABLE;
0156 };
0157
0158 std::vector<SigBkg> pdfs;
0159 std::vector<double> bias;
0160 int categoryIdx;
0161 bool logOutput;
0162 bool individual;
0163 bool neverUndefined;
0164 bool keepEmpty;
0165
0166 COND_SERIALIZABLE;
0167 };
0168
0169 class ProcLinear : public VarProcessor {
0170 public:
0171 std::unique_ptr<VarProcessor> clone() const override;
0172 std::vector<double> coeffs;
0173 double offset;
0174
0175 COND_SERIALIZABLE;
0176 };
0177
0178 class ProcMultiply : public VarProcessor {
0179 public:
0180 std::unique_ptr<VarProcessor> clone() const override;
0181 typedef std::vector<unsigned int> Config;
0182
0183 unsigned int in;
0184 std::vector<Config> out;
0185
0186 COND_SERIALIZABLE;
0187 };
0188
0189 class ProcMatrix : public VarProcessor {
0190 public:
0191 std::unique_ptr<VarProcessor> clone() const override;
0192 Matrix matrix;
0193
0194 COND_SERIALIZABLE;
0195 };
0196
0197 class ProcExternal : public VarProcessor {
0198 public:
0199 std::unique_ptr<VarProcessor> clone() const override;
0200 std::string getInstanceName() const override;
0201
0202 std::string method;
0203 std::vector<unsigned char> store;
0204
0205 COND_SERIALIZABLE;
0206 };
0207
0208 class ProcMLP : public VarProcessor {
0209 public:
0210 std::unique_ptr<VarProcessor> clone() const override;
0211 typedef std::pair<double, std::vector<double> > Neuron;
0212 typedef std::pair<std::vector<Neuron>, bool> Layer;
0213
0214 std::vector<Layer> layers;
0215
0216 COND_SERIALIZABLE;
0217 };
0218
0219
0220
0221 class MVAComputer {
0222 public:
0223 MVAComputer();
0224 MVAComputer(const MVAComputer &orig);
0225 virtual ~MVAComputer();
0226
0227 MVAComputer &operator=(const MVAComputer &orig);
0228
0229 virtual std::vector<VarProcessor *> getProcessors();
0230 virtual std::vector<const VarProcessor *> getProcessors() const;
0231 void addProcessor(const VarProcessor *proc);
0232
0233
0234 typedef unsigned int CacheId;
0235 inline CacheId getCacheId() const { return cacheId; }
0236 inline bool changed(CacheId old) const { return old != cacheId; }
0237
0238 std::vector<Variable> inputSet;
0239 unsigned int output;
0240
0241 private:
0242 std::vector<VarProcessor *> processors;
0243
0244 CacheId cacheId COND_TRANSIENT;
0245
0246 COND_SERIALIZABLE;
0247 };
0248
0249
0250
0251 class MVAComputerContainer {
0252 public:
0253 typedef std::pair<std::string, MVAComputer> Entry;
0254
0255 MVAComputerContainer();
0256 virtual ~MVAComputerContainer() {}
0257
0258 MVAComputer &add(const std::string &label);
0259 virtual const MVAComputer &find(const std::string &label) const;
0260 virtual bool contains(const std::string &label) const;
0261
0262
0263 typedef unsigned int CacheId;
0264 inline CacheId getCacheId() const { return cacheId; }
0265 inline bool changed(CacheId old) const { return old != cacheId; }
0266
0267 private:
0268 std::vector<Entry> entries;
0269
0270 CacheId cacheId COND_TRANSIENT;
0271
0272 COND_SERIALIZABLE;
0273 };
0274
0275 }
0276 }
0277
0278 #endif