13 #include "BAT/BCModel.h"
14 #include "BAT/BCDataPoint.h"
15 #include "BAT/BCDataSet.h"
16 #include "BAT/BCLog.h"
17 #include "BAT/BCH1D.h"
27 , fFlagFillErrorBand(true)
28 , fFitFunctionIndexX(-1)
29 , fFitFunctionIndexY(-1)
30 , fErrorBandContinuous(true)
31 , fErrorBandX(std::vector<double>(0))
32 , fErrorBandNbinsX(100)
33 , fErrorBandNbinsY(500)
41 , fFlagFillErrorBand(true)
42 , fFitFunctionIndexX(-1)
43 , fFitFunctionIndexY(-1)
44 , fErrorBandContinuous(true)
45 , fErrorBandX(std::vector<double>(0))
46 , fErrorBandNbinsX(100)
47 , fErrorBandNbinsY(500)
64 if (fFlagFillErrorBand)
75 if (fFitFunctionIndexX >= 0) {
78 / (
double) fErrorBandNbinsX;
82 / (
double) fErrorBandNbinsY;
94 for (
unsigned ix = 1; ix <= fErrorBandNbinsX; ++ix)
95 for (
unsigned iy = 1; iy <= fErrorBandNbinsX; ++iy)
105 if (fFitFunctionIndexX < 0)
109 if (fErrorBandContinuous) {
111 for (
unsigned ix = 0; ix < fErrorBandNbinsX; ix++) {
116 std::vector<double> xvec;
120 for (
unsigned ichain = 0; ichain < MCMCGetNChains(); ++ichain) {
133 unsigned ndatapoints = fErrorBandX.size();
136 for (
unsigned ix = 0; ix < ndatapoints; ++ix) {
138 x = fErrorBandX.at(ix);
141 std::vector<double> xvec;
145 for (
unsigned ichain = 0; ichain < MCMCGetNChains(); ++ichain) {
161 std::vector<double> errorband;
167 errorband.assign(nx, 0.);
170 for (
int ix = 1; ix <= nx; ix++) {
171 TH1D * temphist =
fErrorBandXY->ProjectionY(
"temphist", ix, ix);
178 temphist->GetQuantiles(nprobSum, q, probSum);
180 errorband[ix - 1] = q[0];
187 TGraph * BCFitter::GetErrorBandGraph(
double level1,
double level2)
const
195 TGraph * graph =
new TGraph(2 * nx);
196 graph->SetFillStyle(1001);
197 graph->SetFillColor(kYellow);
203 for (
int i = 0; i < nx; i++) {
204 graph->SetPoint(i,
fErrorBandXY->GetXaxis()->GetBinCenter(i + 1), ymin[i]);
205 graph->SetPoint(nx + i,
fErrorBandXY->GetXaxis()->GetBinCenter(nx - i), ymax[nx - i - 1]);
212 TH2D * BCFitter::GetErrorBandXY_yellow(
double level,
int nsmooth)
const
222 TString::Format(
"%s_sub_%f.2",
fErrorBandXY->GetName(), level));
223 hist_tempxy->Reset();
224 hist_tempxy->SetFillColor(kYellow);
227 for (
int ix = 1; ix < nx; ix++) {
230 TH1D * hproj =
fErrorBandXY->ProjectionY(
"temphist", ix, ix);
232 hproj->Smooth(nsmooth);
238 for (
int iy = 1; iy <= ny; ++iy)
239 hist_tempxy->SetBinContent(ix, iy, hist_temp_yellow->GetBinContent(iy));
241 delete hist_temp_yellow;
249 TGraph * BCFitter::GetFitFunctionGraph(
const std::vector<double> ¶meters)
256 TGraph * graph =
new TGraph(nx);
259 for (
int i = 0; i < nx; i++) {
260 double x =
fErrorBandXY->GetXaxis()->GetBinCenter(i + 1);
262 std::vector<double> xvec;
267 graph->SetPoint(i, x, y);
274 TGraph * BCFitter::GetFitFunctionGraph(
const std::vector<double> ¶meters,
double xmin,
double xmax,
int n)
277 TGraph * graph =
new TGraph(n + 1);
279 double dx = (xmax - xmin) / (
double) n;
282 for (
int i = 0; i <= n; i++) {
283 double x = (double) i * dx + xmin;
284 std::vector<double> xvec;
290 graph->SetPoint(i, x, y);
299 TFile * froot = TFile::Open(file);
300 if (!froot->IsOpen()) {
301 BCLog::OutError(Form(
"BCFitter::ReadErrorBandFromFile. Couldn't open file %s.", file));
307 TH2D * h2 = (TH2D*) froot->Get(
"errorbandxy");
316 Form(
"BCFitter::ReadErrorBandFromFile : Couldn't read histogram \"errorbandxy\" from file %s.",file));
324 void BCFitter::FixDataAxis(
unsigned int index,
bool fixed)
328 BCLog::OutError(
"BCFitter::FixDataAxis : Index out of range.");
332 if (fDataFixedValues.size() == 0)
336 fDataFixedValues[index] = fixed;
340 bool BCFitter::GetFixedDataAxis(
unsigned int index)
const
344 BCLog::OutError(
"BCFitter::GetFixedDataAxis : Index out of range.");
348 return fDataFixedValues[index];
354 fErrorBandContinuous = flag;
virtual double FitFunction(const std::vector< double > &, const std::vector< double > &)
void MarginalizePreprocess()
unsigned int GetNValues() const
The base class for all user-defined models.
BCDataPoint * fDataPointLowerBoundaries
int ReadErrorBandFromFile(const char *file)
TH1D * GetSmallestIntervalHistogram(double level)
void SetHistogram(TH1D *hist)
void SetErrorBandContinuous(bool flag)
void MCMCIterationInterface()
double GetValue(unsigned index) const
void SetErrorBandHisto(TH2D *h)
A class for handling 1D distributions.
BCDataPoint * GetDataPoint(unsigned int index)
unsigned int GetNDataPoints()
virtual void MCMCIterationInterface()
BCDataPoint * fDataPointUpperBoundaries