CMS 3D CMS Logo

MVAComputer.h
Go to the documentation of this file.
1 #ifndef CondFormats_PhysicsToolsObjects_MVAComputer_h
2 #define CondFormats_PhysicsToolsObjects_MVAComputer_h
3 // -*- C++ -*-
4 //
5 // Package: PhysicsToolsObjects
6 // Class : MVAComputer
7 //
8 
9 //
10 // Author: Christophe Saout <christophe.saout@cern.ch>
11 // Created: Sat Apr 24 15:18 CEST 2007
12 // $Id: MVAComputer.h,v 1.15 2010/01/26 19:40:03 saout Exp $
13 //
14 
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 #include <map>
21 
23 
24 namespace PhysicsTools {
25 namespace Calibration {
26 
27 // helper classes
28 
29 class BitSet {
30  public:
31  // help that poor ROOT to copy bitsets... (workaround)
33  { store = other.store; bitsInLast = other.bitsInLast; return *this; }
34 
35  std::vector<unsigned char> store;
36  unsigned int bitsInLast;
37 
39 };
40 
41 class Matrix {
42  public:
43  std::vector<double> elements;
44  unsigned int rows;
45  unsigned int columns;
46 
48 };
49 
50 // configuration base classes
51 
52 class VarProcessor {
53  public:
55 
56  virtual ~VarProcessor() {}
57  virtual std::string getInstanceName() const;
58  virtual std::unique_ptr<VarProcessor> clone() const;
59 
61 };
62 
63 class Variable {
64  public:
65  inline Variable() {}
66  inline Variable(const std::string &name) : name(name) {}
67  inline ~Variable() {}
68 
70 
72 };
73 
74 // variable processors
75 
76 class ProcOptional : public VarProcessor {
77  public:
78  std::unique_ptr<VarProcessor> clone() const override;
79  std::vector<double> neutralPos;
80 
82 };
83 
84 class ProcCount : public VarProcessor {
85  public:
86  std::unique_ptr<VarProcessor> clone() const override;
88 };
89 
90 class ProcClassed : public VarProcessor {
91  public:
92  std::unique_ptr<VarProcessor> clone() const override;
93  unsigned int nClasses;
94 
96 };
97 
98 class ProcSplitter : public VarProcessor {
99  public:
100  std::unique_ptr<VarProcessor> clone() const override;
101  unsigned int nFirst;
102 
104 };
105 
106 class ProcForeach : public VarProcessor {
107  public:
108  std::unique_ptr<VarProcessor> clone() const override;
109  unsigned int nProcs;
110 
112 };
113 
114 class ProcSort : public VarProcessor {
115  public:
116  std::unique_ptr<VarProcessor> clone() const override;
117  unsigned int sortByIndex;
119 
121 };
122 
123 class ProcCategory : public VarProcessor {
124  public:
125  std::unique_ptr<VarProcessor> clone() const override;
126  typedef std::vector<double> BinLimits;
127 
128  std::vector<BinLimits> variableBinLimits;
129  std::vector<int> categoryMapping;
130 
132 };
133 
134 class ProcNormalize : public VarProcessor {
135  public:
136  std::unique_ptr<VarProcessor> clone() const override;
137  std::vector<HistogramF> distr;
139 
141 };
142 
143 class ProcLikelihood : public VarProcessor {
144  public:
145  std::unique_ptr<VarProcessor> clone() const override;
146  class SigBkg {
147  public:
151 
153 };
154 
155  std::vector<SigBkg> pdfs;
156  std::vector<double> bias;
158  bool logOutput;
161  bool keepEmpty;
162 
164 };
165 
166 class ProcLinear : public VarProcessor {
167  public:
168  std::unique_ptr<VarProcessor> clone() const override;
169  std::vector<double> coeffs;
170  double offset;
171 
173 };
174 
175 class ProcMultiply : public VarProcessor {
176  public:
177  std::unique_ptr<VarProcessor> clone() const override;
178  typedef std::vector<unsigned int> Config;
179 
180  unsigned int in;
181  std::vector<Config> out;
182 
184 };
185 
186 class ProcMatrix : public VarProcessor {
187  public:
188  std::unique_ptr<VarProcessor> clone() const override;
190 
192 };
193 
194 class ProcExternal : public VarProcessor {
195  public:
196  std::unique_ptr<VarProcessor> clone() const override;
197  std::string getInstanceName() const override;
198 
200  std::vector<unsigned char> store;
201 
203 };
204 
205 class ProcMLP : public VarProcessor {
206  public:
207  std::unique_ptr<VarProcessor> clone() const override;
208  typedef std::pair<double, std::vector<double> > Neuron;
209  typedef std::pair<std::vector<Neuron>, bool> Layer;
210 
211  std::vector<Layer> layers;
212 
214 };
215 
216 // the discriminator computer
217 
218 class MVAComputer {
219  public:
220  MVAComputer();
221  MVAComputer(const MVAComputer &orig);
222  virtual ~MVAComputer();
223 
224  MVAComputer &operator = (const MVAComputer &orig);
225 
226  virtual std::vector<VarProcessor*> getProcessors() const;
227  void addProcessor(const VarProcessor *proc);
228 
229  // cacheId stuff to detect changes
230  typedef unsigned int CacheId;
231  inline CacheId getCacheId() const { return cacheId; }
232  inline bool changed(CacheId old) const { return old != cacheId; }
233 
234  std::vector<Variable> inputSet;
235  unsigned int output;
236 
237  private:
238  std::vector<VarProcessor*> processors;
239 
240  CacheId cacheId COND_TRANSIENT; // transient
241 
243 };
244 
245 // a collection of computers identified by name
246 
248  public:
249  typedef std::pair<std::string, MVAComputer> Entry;
250 
253 
254  MVAComputer &add(const std::string &label);
255  virtual const MVAComputer &find(const std::string &label) const;
256  virtual bool contains(const std::string &label) const;
257 
258  // cacheId stuff to detect changes
259  typedef unsigned int CacheId;
260  inline CacheId getCacheId() const { return cacheId; }
261  inline bool changed(CacheId old) const { return old != cacheId; }
262 
263  private:
264  std::vector<Entry> entries;
265 
266  CacheId cacheId COND_TRANSIENT; // transient
267 
269 };
270 
271 } // namespace Calibration
272 } // namespace PhysicsTools
273 
274 #endif // CondFormats_PhysicsToolsObjects_MVAComputer_h
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
TrainProcessor *const proc
Definition: MVATrainer.cc:101
std::vector< unsigned char > store
Definition: MVAComputer.h:35
std::vector< BinLimits > variableBinLimits
Definition: MVAComputer.h:128
std::pair< std::vector< Neuron >, bool > Layer
Definition: MVAComputer.h:209
std::vector< double > elements
Definition: MVAComputer.h:43
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
std::vector< VarProcessor * > processors
Definition: MVAComputer.h:238
char const * label
std::pair< double, std::vector< double > > Neuron
Definition: MVAComputer.h:208
BitSet & operator=(const BitSet &other)
Definition: MVAComputer.h:32
std::vector< unsigned int > Config
Definition: MVAComputer.h:178
std::pair< std::string, MVAComputer > Entry
Definition: MVAComputer.h:249
Variable(const std::string &name)
Definition: MVAComputer.h:66
bool changed(CacheId old) const
Definition: MVAComputer.h:232
void add(std::map< std::string, TH1 * > &h, TH1 *hist)
#define COND_TRANSIENT
Definition: Serializable.h:61
std::vector< Variable > inputSet
Definition: MVAComputer.h:234
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
#define COND_SERIALIZABLE
Definition: Serializable.h:38
std::vector< unsigned char > store
Definition: MVAComputer.h:200
std::vector< HistogramF > distr
Definition: MVAComputer.h:137