MINT2
HyperBinningMaker.h
Go to the documentation of this file.
1 
8 #ifndef HYPERBINNINGMAKER_HH
9 #define HYPERBINNINGMAKER_HH
10 
11 // HyperPlot includes
12 #include "Mint/MessageService.h"
13 #include "Mint/HyperCuboid.h"
14 #include "Mint/HyperPointSet.h"
16 #include "Mint/RootPlotter1D.h"
17 #include "Mint/RootPlotter2D.h"
18 #include "Mint/HyperFunction.h"
19 
20 // Root includes
21 #include "TH1D.h"
22 #include "TH2D.h"
23 #include "TRandom3.h"
24 #include "TMath.h"
25 
26 // std includes
27 #include <algorithm>
28 #include <sstream>
29 
30 class HyperHistogram;
31 
32 
44 
45  private:
46 
48 
49  protected:
50 
51 
52  static bool s_printBinning;
54  //each bin has:
55  // o a hyper cuboid defining it
56  // o a set of data which is contained within it
57  // o a status
58 
59  std::vector<HyperCuboid> _hyperCuboids;
61  std::vector< std::vector<int> > _linkedBins;
67  std::vector<HyperPointSet> _hyperPointSets;
71  std::vector<HyperPointSet> _shadowHyperPointSets;
76  struct VolumeStatus{
77  enum Type { DONE, CONTINUE };
78  };
79 
80  std::vector<int> _status;
84  std::vector< std::vector<int> > _dimSpecificStatus;
90  std::vector<int> _binningDimensions;
110  TRandom* _random;
135  public:
136 
137  HyperBinningMaker(const HyperCuboid& binningRange, const HyperPointSet& data);
138 
139  HyperBinningMaker(const HyperBinning& binning , const HyperPointSet& data);
140 
141 
142  /* ----------------------------------------------------------------*/
143 
144  virtual void makeBinning() = 0;
149  /* ----------------------------------------------------------------*/
150 
151  //The following functions should be called before any binning
152  //binning algorithms commence.
153 
154  static void setOutputLevel(bool val){s_printBinning = val;}
157  void setBinningDimensions(std::vector<int> dims){_binningDimensions = dims;}
160  void addShadowHyperPointSet(const HyperPointSet& data);
161 
162  void setSeed(int seed);
163 
164  void useSnapToGrid(bool val);
165  void setGridMultiplier(HyperPoint& multipliers);
166  void setGridMultiplier(double multiplier);
167 
168 
169  void useEventWeights(bool val = true){_useEventWeights = val;}
172  void setMinimumBinContent(double val);
173  void setShadowMinimumBinContent(double val);
174  void setMinimumEdgeLength(double val);
175  void setMinimumEdgeLength(HyperPoint val);
176 
177  void setHyperFunction(HyperFunction* fnc);
178 
179  void drawAfterEachIteration(TString path);
180 
181  void updateFromExistingHyperBinning( const HyperBinning& binning );
182 
183  void setNames(HyperName names){_names = names;}
186  /*----------------------------------------------------------------*/
187 
188 
189  int& getGlobalVolumeStatus(int volumeNumber){return _status.at(volumeNumber);}
190  int& getDimensionSpecificVolumeStatus(int volumeNumber, int dimension){return _dimSpecificStatus.at(volumeNumber).at(dimension);}
191 
192  const int& getGlobalVolumeStatus(int volumeNumber) const {return _status.at(volumeNumber);}
193  const int& getDimensionSpecificVolumeStatus(int volumeNumber, int dimension) const {return _dimSpecificStatus.at(volumeNumber).at(dimension);}
194 
195  int getNumContinueBins(int dimension = -1) const;
196  int getNumBins () const;
197  int getNumHyperVolumes() const;
198 
199 
200  /*----------------------------------------------------------------*/
201 
202  //These functions are common to all the HyperBinning makers
203  //and used to divide bins and update their status, and check that
204  //the resulting bins are OK.
205 
206  int split(int volumeNumber, int dimension, double splitPoint);
207 
208  HyperCuboid splitBelowPoint(int dim, double splitPoint, const HyperCuboid& original, bool noSnapToGrid = false) const;
209  HyperCuboid splitAbovePoint(int dim, double splitPoint, const HyperCuboid& original, bool noSnapToGrid = false) const;
210 
211  double getSumOfWeights(const HyperPointSet& hyperPointSet) const;
212  double getWeight(const HyperPoint& hyperPoint) const; //Will return 1 if _useEventWeights is false. If not, get event weight 0.
213  bool isValidBinningDimension(int dimension);
214  virtual bool passFunctionCriteria(HyperCuboid& cuboid1, HyperCuboid& cuboid2);
215 
216  HyperPointSet filterHyperPointSet(const HyperPointSet& hyperPointSet, const HyperCuboid& hyperCuboid, bool print = false) const;
217 
218  void addBin(const HyperCuboid& hyperCuboid, const HyperPointSet& hyperPointSet, const HyperPointSet& shadowHyperPointSet, int status);
219 
220  void setDimSpecStatusFromMinBinWidths (int volumeNumber);
221  void updateGlobalStatusFromDimSpecific(int volumeNumber);
222 
223  bool snapToGrid(const HyperCuboid& cuboid, int dimension, double& splitCoord) const;
224 
225  /* ----------------------------------------------------------------*/
226 
227  virtual void startedAlgorithm();
228  virtual void startedIteration();
229 
230  void drawCurrentState(TString path) const;
231 
232  virtual void finishedIteration();
233  virtual void finishedAlgorithm();
234 
235 
236  /* ----------------------------------------------------------------*/
237 
238  // These functions can be used to get a
239  // HyperBinningHistogram of the current state
240 
245 
246  virtual ~HyperBinningMaker();
247 
248 
249  /********************* NON ESSENTIAL ************************/
250 
251 
252  double countEventsBelowSplitPoint(int binNumber, int dimension, double splitPoint) const;
253  double countEventsInHyperCuboid(const HyperPointSet& hyperPointSet, const HyperCuboid& hyperCuboid) const;
254  double countShadowEventsBelowSplitPoint(int binNumber, int dimension, double splitPoint) const;
255 
256  //split the bin in a chosen dimension to give a chosen fraction of events in the resulting bin
257  double findSmartSplitPoint(int binNumber, int dimension, double dataFraction) const;
258 
259  int smartSplit (int binNumber, int dimension, double dataFraction);
260  int smartSplitAll(int dimension, double dataFraction);
261  int smartSplitAllRandomise(double dataFraction = 0.5);
262 
263 
264  int smartMultiSplit(int binNumber, int dimension, int parts);
265  int smartMultiSplit(int binNumber, int dimension);
266  int smartMultiSplitAll(int dimension);
267 
268 
269  double findSmartSplitPointInt(int binNumber, int dimension, double dataFraction) const;
270 
271  int smartSplitInt(int binNumber, int dimension, double dataFraction);
272  int smartSplitAllInt(int dimension, double dataFraction);
273 
274  int splitAll(int dimension, double splitPoint);
275  int splitAllRandomise(double splitPoint = 0.5);
276 
277 
278 
279 
280  //Likelihood shit
281 
282  int likelihoodSplit(int binNumber);
283  int likelihoodSplitAll();
284 
285  int smartLikelihoodSplit(int binNumber);
287 
288  void getSplitToMinNeg2LLH(double& split, double& sig, int binNumber, int dimension, bool useConstraints = true);
289 
290  void getDimWithLargestSplitSignificance(int& dim, double& split, int binNumber, bool useConstraints = true);
291 
292  TH1D* scanSig(int binNumber, int dimension, int nbins, bool useConstraints = true);
293 
294  double neg2LLH(int binNumber, int dimension, double splitPoint, bool useConstraints = true);
295  double nullNeg2LLH(int binNumber);
296 
297 
298 
299 
300 
301 };
302 
303 
304 
305 #endif
306 
void addShadowHyperPointSet(const HyperPointSet &data)
virtual ~HyperBinningMaker()
destructor
void setShadowMinimumBinContent(double val)
int getNumContinueBins(int dimension=-1) const
void setBinningDimensions(std::vector< int > dims)
HyperPoint _minimumEdgeLength
void getDimWithLargestSplitSignificance(int &dim, double &split, int binNumber, bool useConstraints=true)
int smartMultiSplitAll(int dimension)
bool snapToGrid(const HyperCuboid &cuboid, int dimension, double &splitCoord) const
HyperHistogram * getShadowHyperBinningHistogram() const
std::vector< std::vector< int > > _linkedBins
virtual void startedIteration()
static bool s_printBinning
void getSplitToMinNeg2LLH(double &split, double &sig, int binNumber, int dimension, bool useConstraints=true)
void setNames(HyperName names)
int smartSplitAllInt(int dimension, double dataFraction)
virtual void startedAlgorithm()
void drawAfterEachIteration(TString path)
std::vector< int > _status
void setGridMultiplier(HyperPoint &multipliers)
double findSmartSplitPointInt(int binNumber, int dimension, double dataFraction) const
HyperPoint _gridMultiplier
void setMinimumEdgeLength(double val)
double countEventsBelowSplitPoint(int binNumber, int dimension, double splitPoint) const
int smartSplit(int binNumber, int dimension, double dataFraction)
bool isValidBinningDimension(int dimension)
void useSnapToGrid(bool val)
void updateFromExistingHyperBinning(const HyperBinning &binning)
virtual void finishedAlgorithm()
void drawCurrentState(TString path) const
void setDimSpecStatusFromMinBinWidths(int volumeNumber)
std::vector< HyperPointSet > _shadowHyperPointSets
HyperBinningMemRes getHyperVolumeBinning() const
void addBin(const HyperCuboid &hyperCuboid, const HyperPointSet &hyperPointSet, const HyperPointSet &shadowHyperPointSet, int status)
HyperCuboid splitAbovePoint(int dim, double splitPoint, const HyperCuboid &original, bool noSnapToGrid=false) const
double nullNeg2LLH(int binNumber)
virtual void finishedIteration()
HyperHistogram * getHyperBinningHistogram() const
HyperFunction * _func
HyperPointSet filterHyperPointSet(const HyperPointSet &hyperPointSet, const HyperCuboid &hyperCuboid, bool print=false) const
static void setOutputLevel(bool val)
double getSumOfWeights(const HyperPointSet &hyperPointSet) const
void updateGlobalStatusFromDimSpecific(int volumeNumber)
int likelihoodSplit(int binNumber)
int splitAll(int dimension, double splitPoint)
TH1D * scanSig(int binNumber, int dimension, int nbins, bool useConstraints=true)
virtual void makeBinning()=0
int smartLikelihoodSplit(int binNumber)
int splitAllRandomise(double splitPoint=0.5)
void setHyperFunction(HyperFunction *fnc)
Set the HyperFunction - only used by some binning Algs.
int smartSplitInt(int binNumber, int dimension, double dataFraction)
int smartMultiSplit(int binNumber, int dimension, int parts)
int & getGlobalVolumeStatus(int volumeNumber)
void setSeed(int seed)
int & getDimensionSpecificVolumeStatus(int volumeNumber, int dimension)
int getNumHyperVolumes() const
std::vector< HyperCuboid > _hyperCuboids
void useEventWeights(bool val=true)
double countShadowEventsBelowSplitPoint(int binNumber, int dimension, double splitPoint) const
std::vector< int > _binningDimensions
double getWeight(const HyperPoint &hyperPoint) const
HyperHistogram * getRatioHyperBinningHistogram() const
const int & getDimensionSpecificVolumeStatus(int volumeNumber, int dimension) const
int smartSplitAllRandomise(double dataFraction=0.5)
double findSmartSplitPoint(int binNumber, int dimension, double dataFraction) const
void setMinimumBinContent(double val)
int split(int volumeNumber, int dimension, double splitPoint)
const int & getGlobalVolumeStatus(int volumeNumber) const
std::vector< std::vector< int > > _dimSpecificStatus
double countEventsInHyperCuboid(const HyperPointSet &hyperPointSet, const HyperCuboid &hyperCuboid) const
std::vector< HyperPointSet > _hyperPointSets
HyperCuboid splitBelowPoint(int dim, double splitPoint, const HyperCuboid &original, bool noSnapToGrid=false) const
int smartSplitAll(int dimension, double dataFraction)
virtual bool passFunctionCriteria(HyperCuboid &cuboid1, HyperCuboid &cuboid2)
double neg2LLH(int binNumber, int dimension, double splitPoint, bool useConstraints=true)