MINT2
HyperFunction.cpp
Go to the documentation of this file.
1 #include "Mint/HyperFunction.h"
2 
3 
5  _limits(HyperPoint(0), HyperPoint(0))
6 {
7 
8 
9 
10 
11 }
12 
14  _limits(limits)
15 {
16 
17 }
18 
19 
25 
26  int npoints = points.size();
27 
28  for (int i = 0; i < npoints; i++){
29 
30  HyperPoint& point = points.at(i);
31 
32  double val = this->getVal(point);
33 
34  int nW = point.numWeights();
35 
36  for (int w = 0; w < nW; w++){
37  double oldW = point.getWeight(w);
38  double newW = oldW*val;
39  point.setWeight(w, newW);
40  }
41 
42  if (nW == 0) point.addWeight(val);
43 
44  }
45 
46 
47 }
48 
50  _limits = limits;
51 }
52 
53 
54 TH2D HyperFunction::make2DFuncSlice (TString name, int sliceDimX, int sliceDimY, const HyperPoint& slicePoint, int nbins) const{
55 
56  if (_limits.getDimension() == 0){
57  ERROR_LOG << "You need to set the domain of the fuction with setFuncLimits(const HyperCuboid& limits) to draw slices" << std::endl;
58  }
59  if (slicePoint.getDimension() != _limits.getDimension()){
60  ERROR_LOG << "Your slice point has different dimensions to the function domain" << std::endl;
61  }
62  if (_limits.inVolume(slicePoint) == false){
63  ERROR_LOG << "Your slice point in not within the function domain" << std::endl;
64  }
65 
66  double minX = _limits.getLowCorner ().at(sliceDimX);
67  double maxX = _limits.getHighCorner().at(sliceDimX);
68 
69  double minY = _limits.getLowCorner ().at(sliceDimY);
70  double maxY = _limits.getHighCorner().at(sliceDimY);
71 
72  TH2D hist(name, name, nbins, minX, maxX, nbins, minY, maxY);
73 
74  for (int i = 1; i <= nbins; i++){
75  for (int j = 1; j <= nbins; j++){
76  double x = hist.GetXaxis()->GetBinCenter(i);
77  double y = hist.GetYaxis()->GetBinCenter(j);
78  HyperPoint point(slicePoint);
79  point.at(sliceDimX) = x;
80  point.at(sliceDimY) = y;
81  double val = getVal(point);
82  hist.SetBinContent(i,j,val);
83  }
84  }
85 
86  return hist;
87 
88 }
89 
90 void HyperFunction::draw2DFuncSlice (TString path, int sliceDimX, int sliceDimY, const HyperPoint& slicePoint, int nbins) const{
91 
92  TH2D hist = make2DFuncSlice("temp", sliceDimX, sliceDimY, slicePoint, nbins);
93  RootPlotter2D plotter(&hist);
94  plotter.plot(path, "COLZ");
95 
96 }
97 
98 void HyperFunction::draw2DFuncSliceSet(TString path, int sliceDimX, int sliceDimY, int sliceSetDim, int nSlices, const HyperPoint& slicePoint, int nbins) const{
99 
100  if (_limits.getDimension() == 0){
101  ERROR_LOG << "You need to set the domain of the fuction with setFuncLimits(const HyperCuboid& limits) to draw slices" << std::endl;
102  }
103  if (slicePoint.getDimension() != _limits.getDimension()){
104  ERROR_LOG << "Your slice point has different dimensions to the function domain" << std::endl;
105  }
106  if (_limits.inVolume(slicePoint) == false){
107  ERROR_LOG << "Your slice point in not within the function domain" << std::endl;
108  }
109 
110  HyperPoint slicePointCp(slicePoint);
111 
112  double min = _limits.getLowCorner ().at(sliceSetDim);
113  double max = _limits.getHighCorner().at(sliceSetDim);
114  double width = (max - min)/double(nSlices);
115 
116  for (int i = 0; i < nSlices; i++){
117  double val = min + width*(i + 0.5);
118  slicePointCp.at(sliceSetDim) = val;
119 
120  TString uniquePath = path;
121  uniquePath += "_sliceNum";
122  uniquePath += i;
123  draw2DFuncSlice(uniquePath, sliceDimX, sliceDimY, slicePointCp, nbins);
124 
125  }
126 
127 
128 }
129 
130 void HyperFunction::draw2DFuncSliceSet(TString path, int sliceDimX, int sliceDimY, int nSlices, const HyperPoint& slicePoint, int nbins) const{
131 
132 
133 
134  for (int i = 0; i < slicePoint.getDimension(); i++){
135 
136  if (i == sliceDimX) continue;
137  if (i == sliceDimY) continue;
138 
139  TString thsPath = path;
140  thsPath += "_scanDim";
141  thsPath += i;
142 
143  draw2DFuncSliceSet(thsPath, sliceDimX, sliceDimY, i, nSlices, slicePoint, nbins);
144 
145  }
146 
147 
148 }
149 
150 void HyperFunction::draw2DFuncSliceSet(TString path, int nSlices, const HyperPoint& slicePoint, int nbins) const{
151 
152 
153 
154  for (int i = 0; i < slicePoint.getDimension(); i++){
155  for (int j = 0; j < slicePoint.getDimension(); j++){
156 
157  if (i >= j) continue;
158 
159  TString thsPath = path;
160  thsPath += "_";
161  thsPath += i;
162  thsPath += "vs";
163  thsPath += j;
164 
165  draw2DFuncSliceSet(thsPath, i, j, nSlices, slicePoint, nbins);
166  }
167  }
168 
169 
170 }
171 
172 
173 
174 double HyperFunction::getDifference(const HyperFunction& other, const HyperPoint& point){
175  double val = getVal(point);
176  double valother = other.getVal(point);
177  return val - valother;
178 }
179 
180 
181 void HyperFunction::fillCorrelations(TH2D& hist, const HyperFunction& other, const HyperPointSet& points){
182 
183  for (unsigned i = 0; i < points.size(); i++){
184  double val = getVal(points.at(i));
185  double valother = other.getVal(points.at(i));
186  hist.Fill( val, valother, points.at(i).getWeight() );
187  }
188 
189  int nBinsX = hist.GetXaxis()->GetNbins();
190  int nBinsY = hist.GetYaxis()->GetNbins();
191 
192  for (int i = 1; i <= nBinsX; i++){
193  double sumY = 0.0;
194  for (int j = 1; j <= nBinsY; j++){
195  sumY += hist.GetBinContent(i,j);
196  }
197  for (int j = 1; j <= nBinsY; j++){
198  double val = hist.GetBinContent(i,j);
199  val = (val / sumY)*100.0;
200  if (sumY == 0.0) val = 0.0;
201  hist.SetBinContent(i, j, val);
202  }
203  }
204 
205 }
206 
207 
208 
209 
210 
211 
212 
213 
void draw2DFuncSliceSet(TString path, int sliceDimX, int sliceDimY, int sliceSetDim, int nSlices, const HyperPoint &slicePoint, int nbins=100) const
void setWeight(int i, double w)
Definition: Weights.cpp:52
void addWeight(const double &weight)
Definition: Weights.cpp:71
TH2D make2DFuncSlice(TString name, int sliceDimX, int sliceDimY, const HyperPoint &slicePoint, int nbins=100) const
#define ERROR_LOG
void reweightDataset(HyperPointSet &points)
const int & getDimension() const
Definition: HyperCuboid.h:45
void draw2DFuncSlice(TString path, int sliceDimX, int sliceDimY, const HyperPoint &slicePoint, int nbins=100) const
HyperCuboid _limits
Definition: HyperFunction.h:31
const HyperPoint & at(int i) const
double getDifference(const HyperFunction &other, const HyperPoint &point)
const HyperPoint & getHighCorner() const
Definition: HyperCuboid.h:89
virtual void plot(TString plotDirectory, TString plotOptions="", TPad *pad=0, double scaleFactor=1.0)
void fillCorrelations(TH2D &hist, const HyperFunction &other, const HyperPointSet &points)
int numWeights() const
Definition: Weights.cpp:20
virtual double getVal(const HyperPoint &point) const =0
const double & at(int i) const
Definition: HyperPoint.cpp:433
const HyperPoint & getLowCorner() const
Definition: HyperCuboid.h:87
unsigned int size() const
double getWeight(int i=0) const
Definition: Weights.cpp:40
void setFuncLimits(const HyperCuboid &limits)
int getDimension() const
Definition: HyperPoint.h:99
bool inVolume(const HyperPoint &coords) const