#include <BCIntegrate.h>
Definition at line 45 of file BCIntegrate.h.
Member functions (miscellaneous methods) | |
double | CubaIntegrate () |
double | CubaIntegrate (int method, std::vector< double > parameters_double, std::vector< double > parameters_int) |
void | DeleteVarList () |
virtual double | Eval (std::vector< double > x) |
double | EvalPrint (std::vector< double > x) |
virtual double | EvalSampling (std::vector< double > x) |
void | FindModeMCMC () |
void | FindModeMinuit (std::vector< double > start=std::vector< double >(0), int printlevel=1) |
virtual double | FitFunction (std::vector< double > x, std::vector< double > parameters) |
TH1D * | GetH1D (int parIndex) |
TH2D * | GetH2D (int parIndex1, int parIndex2) |
int | GetH2DIndex (int parIndex1, int parIndex2) |
void | InitMetro () |
double | IntegralImportance (std::vector< double > x) |
double | IntegralMC (std::vector< double > x) |
double | IntegralMC (std::vector< double > x, int *varlist) |
double | IntegralMetro (std::vector< double > x) |
double | Integrate () |
virtual double | LogEval (std::vector< double > x) |
double | LogEvalSampling (std::vector< double > x) |
TH2D * | Marginalize (BCParameter *parameter1, BCParameter *parameter2) |
TH1D * | Marginalize (BCParameter *parameter) |
int | MarginalizeAllByMetro (const char *name) |
TH2D * | MarginalizeByIntegrate (BCParameter *parameter1, BCParameter *parameter2) |
TH1D * | MarginalizeByIntegrate (BCParameter *parameter) |
TH2D * | MarginalizeByMetro (BCParameter *parameter1, BCParameter *parameter2) |
TH1D * | MarginalizeByMetro (BCParameter *parameter) |
virtual void | MCMCUserIterationInterface () |
void | ResetVarlist (int v) |
void | UnsetVar (int index) |
static void | CubaIntegrand (const int *ndim, const double xx[], const int *ncomp, double ff[]) |
static void | FCNLikelihood (int &npar, double *grad, double &fval, double *par, int flag) |
Public Types | |
Enumerators | |
enum | BCIntegrationMethod { kIntMonteCarlo, kIntImportance, kIntMetropolis, kIntCuba } |
enum | BCMarginalizationMethod { kMargMonteCarlo, kMargMetropolis } |
enum | BCOptimizationMethod { kOptSimulatedAnnealing, kOptMetropolis, kOptMinuit } |
Public Member Functions | |
Constructors and destructors | |
BCIntegrate (BCParameterSet *par) | |
BCIntegrate () | |
virtual | ~BCIntegrate () |
Member functions (get) | |
double | GetError () |
BCIntegrate::BCIntegrationMethod | GetIntegrationMethod () |
BCIntegrate::BCMarginalizationMethod | GetMarginalizationMethod () |
std::vector< double > * | GetMarkovChainPoint () |
TTree * | GetMarkovChainTree () |
double * | GetMarkovChainValue () |
int * | GetMCMCIteration () |
TMinuit * | GetMinuit () |
int | GetMinuitErrorFlag () |
int | GetNbins () |
int | GetNIterations () |
int | GetNIterationsMax () |
int | GetNiterationsPerDimension () |
int | GetNSamplesPer2DBin () |
int | GetNvar () |
BCIntegrate::BCOptimizationMethod | GetOptimizationMethod () |
double | GetRandomPoint (std::vector< double > &x) |
double | GetRandomPointImportance (std::vector< double > &x) |
void | GetRandomPointMetro (std::vector< double > &x) |
void | GetRandomPointSamplingMetro (std::vector< double > &x) |
void | GetRandomVector (std::vector< double > &x) |
virtual void | GetRandomVectorMetro (std::vector< double > &x) |
double | GetRelativePrecision () |
Member functions (set) | |
void | SetDataPointLowerBoundaries (BCDataPoint *datasetlowerboundaries) |
void | SetDataPointLowerBoundary (int index, double lowerboundary) |
void | SetDataPointUpperBoundaries (BCDataPoint *datasetupperboundaries) |
void | SetDataPointUpperBoundary (int index, double upperboundary) |
void | SetErrorBandHisto (TH2D *h) |
void | SetFillErrorBand (bool flag=true) |
void | SetFitFunctionIndexX (int index) |
void | SetFitFunctionIndexY (int index) |
void | SetFitFunctionIndices (int indexx, int indexy) |
void | SetIntegrationMethod (BCIntegrate::BCIntegrationMethod method) |
void | SetMarginalizationMethod (BCIntegrate::BCMarginalizationMethod method) |
void | SetMarkovChainAutoN (bool flag) |
void | SetMarkovChainInitialPosition (std::vector< double > position) |
void | SetMarkovChainNIterations (int niterations) |
void | SetMarkovChainStepSize (double stepsize) |
void | SetMarkovChainTree (TTree *tree) |
void | SetMinuitArlist (double *arglist) |
void | SetMode (std::vector< double > mode) |
void | SetNbins (int nbins, int index=-1) |
void | SetNIterationsMax (int niterations) |
void | SetNiterationsPerDimension (int niterations) |
void | SetNSamplesPer2DBin (int n) |
void | SetOptimizationMethod (BCIntegrate::BCOptimizationMethod method) |
void | SetParameters (BCParameterSet *par) |
void | SetRelativePrecision (double relprecision) |
void | SetVar (int index) |
void | SetVarList (int *varlist) |
void | UnsetFillErrorBand () |
void | WriteMarkovChain (bool flag) |
Protected Attributes | |
std::vector< double > | fBestFitParameters |
std::vector< double > | fBestFitParametersMarginalized |
std::vector< bool > | fDataFixedValues |
BCDataPoint * | fDataPointLowerBoundaries |
BCDataPoint * | fDataPointUpperBoundaries |
bool | fErrorBandContinuous |
int | fErrorBandNbinsX |
int | fErrorBandNbinsY |
std::vector< double > | fErrorBandX |
TH2D * | fErrorBandXY |
bool | fFillErrorBand |
int | fFitFunctionIndexX |
int | fFitFunctionIndexY |
bool | fFlagWriteMarkovChain |
std::vector< TH1D * > | fHProb1D |
std::vector< TH2D * > | fHProb2D |
bool | fMarkovChainAutoN |
int | fMarkovChainNIterations |
double | fMarkovChainStepSize |
TTree * | fMarkovChainTree |
int | fMCMCIteration |
TMinuit * | fMinuit |
double | fMinuitArglist [2] |
int | fMinuitErrorFlag |
int | fNbins |
int | fNSamplesPer2DBin |
int | fNvar |
TRandom3 * | fRandom |
Private Member Functions | |
void | MCMCFillErrorBand () |
void | MCMCIterationInterface () |
Private Attributes | |
double | fError |
BCIntegrate::BCIntegrationMethod | fIntegrationMethod |
BCIntegrate::BCMarginalizationMethod | fMarginalizationMethod |
double | fMarkovChainValue |
double * | fMax |
double * | fMin |
int | fNacceptedMCMC |
int | fNIterations |
int | fNIterationsMax |
int | fNiterPerDimension |
int | fNmetro |
BCIntegrate::BCOptimizationMethod | fOptimizationMethod |
double | fRelativePrecision |
int * | fVarlist |
BCParameterSet * | fx |
std::vector< double > | fXmetro0 |
std::vector< double > | fXmetro1 |
An enumerator for the integration algorithm
Definition at line 55 of file BCIntegrate.h.
00055 { kIntMonteCarlo, kIntImportance, kIntMetropolis, kIntCuba };
An enumerator for the marginalization algorithm
Definition at line 59 of file BCIntegrate.h.
00059 { kMargMonteCarlo, kMargMetropolis };
An enumerator for the mode finding algorithm
Definition at line 63 of file BCIntegrate.h.
00063 { kOptSimulatedAnnealing, kOptMetropolis, kOptMinuit };
BCIntegrate::BCIntegrate | ( | ) |
The default constructor
Definition at line 31 of file BCIntegrate.cxx.
00031 : BCEngineMCMC() 00032 { 00033 fNvar=0; 00034 fNiterPerDimension = 100; 00035 fNSamplesPer2DBin = 100; 00036 fRandom = new TRandom3(0); 00037 00038 fNIterationsMax = 1000000; 00039 fRelativePrecision = 1e-3; 00040 00041 #ifdef HAVE_CUBA_H 00042 fIntegrationMethod = BCIntegrate::kIntCuba; 00043 #else 00044 fIntegrationMethod = BCIntegrate::kIntMonteCarlo; 00045 #endif 00046 fMarginalizationMethod = BCIntegrate::kMargMetropolis; 00047 fOptimizationMethod = BCIntegrate::kOptMinuit; 00048 00049 fNbins=100; 00050 00051 fDataPointLowerBoundaries = 0; 00052 fDataPointUpperBoundaries = 0; 00053 00054 fFillErrorBand = false; 00055 00056 fFitFunctionIndexX = -1; 00057 fFitFunctionIndexY = -1; 00058 00059 fErrorBandNbinsX = 100; 00060 fErrorBandNbinsY = 500; 00061 00062 fErrorBandContinuous = true; 00063 00064 fMinuit = 0; 00065 fMinuitArglist[0] = 20000; 00066 fMinuitArglist[1] = 0.01; 00067 00068 fFlagWriteMarkovChain = false; 00069 fMarkovChainTree = 0; 00070 00071 fMarkovChainStepSize = 0.1; 00072 00073 fMarkovChainAutoN = true; 00074 }
BCIntegrate::BCIntegrate | ( | BCParameterSet * | par | ) |
A constructor
Definition at line 77 of file BCIntegrate.cxx.
00077 : BCEngineMCMC(1) 00078 { 00079 fNvar=0; 00080 fNiterPerDimension = 100; 00081 fNSamplesPer2DBin = 100; 00082 fRandom = new TRandom3(0); 00083 00084 fNbins=100; 00085 00086 this->SetParameters(par); 00087 00088 fDataPointLowerBoundaries = 0; 00089 fDataPointUpperBoundaries = 0; 00090 00091 fFillErrorBand = false; 00092 00093 fFitFunctionIndexX = -1; 00094 fFitFunctionIndexY = -1; 00095 00096 fErrorBandNbinsX = 100; 00097 fErrorBandNbinsY = 200; 00098 00099 fErrorBandContinuous = true; 00100 00101 fMinuit = 0; 00102 fMinuitArglist[0] = 20000; 00103 fMinuitArglist[1] = 0.01; 00104 00105 fFlagWriteMarkovChain = false; 00106 fMarkovChainTree = 0; 00107 00108 fMarkovChainStepSize = 0.1; 00109 00110 fMarkovChainAutoN = true; 00111 }
BCIntegrate::~BCIntegrate | ( | ) | [virtual] |
The default destructor
Definition at line 114 of file BCIntegrate.cxx.
00115 { 00116 DeleteVarList(); 00117 00118 fx=0; 00119 00120 delete fRandom; 00121 fRandom=0; 00122 00123 if (fMinuit) 00124 delete fMinuit; 00125 00126 int n1 = fHProb1D.size(); 00127 if(n1>0) 00128 { 00129 for (int i=0;i<n1;i++) 00130 delete fHProb1D.at(i); 00131 } 00132 00133 int n2 = fHProb2D.size(); 00134 if(n2>0) 00135 { 00136 for (int i=0;i<n2;i++) 00137 delete fHProb2D.at(i); 00138 } 00139 }
void BCIntegrate::CubaIntegrand | ( | const int * | ndim, | |
const double | xx[], | |||
const int * | ncomp, | |||
double | ff[] | |||
) | [static] |
Integrand for the Cuba library.
ndim | The number of dimensions to integrate over | |
xx | The point in parameter space to integrate over (scaled to 0 - 1 per dimension) | |
ncomp | The number of components of the integrand (usually 1) | |
ff | The function value |
Definition at line 1444 of file BCIntegrate.cxx.
01446 { 01447 #ifdef HAVE_CUBA_H 01448 // scale variables 01449 double jacobian = 1.0; 01450 01451 std::vector<double> scaled_parameters; 01452 01453 for (int i = 0; i < *ndim; i++) 01454 { 01455 double range = global_this -> fx -> at(i) -> GetUpperLimit() - global_this -> fx -> at(i) -> GetLowerLimit(); 01456 01457 // multiply range to jacobian 01458 jacobian *= range; 01459 01460 // get the scaled parameter value 01461 scaled_parameters.push_back(global_this -> fx -> at(i) -> GetLowerLimit() + xx[i] * range); 01462 } 01463 01464 // call function to integrate 01465 ff[0] = global_this -> Eval(scaled_parameters); 01466 01467 // multiply jacobian 01468 ff[0] *= jacobian; 01469 01470 // multiply fudge factor 01471 ff[0] *= 1e99; 01472 01473 // remove parameter vector 01474 scaled_parameters.clear(); 01475 #else 01476 BCLog::Out(BCLog::error,BCLog::error,"!!! This version of BAT is compiled without Cuba."); 01477 BCLog::Out(BCLog::error,BCLog::error," Use other integration methods or install Cuba and recompile BAT."); 01478 #endif 01479 }
double BCIntegrate::CubaIntegrate | ( | ) |
Definition at line 1482 of file BCIntegrate.cxx.
01483 { 01484 #ifdef HAVE_CUBA_H 01485 double EPSREL = 1e-3; 01486 double EPSABS = 1e-12; 01487 double VERBOSE = 0; 01488 double MINEVAL = 0; 01489 double MAXEVAL = 2000000; 01490 double NSTART = 25000; 01491 double NINCREASE = 25000; 01492 01493 std::vector<double> parameters_double; 01494 std::vector<double> parameters_int; 01495 01496 parameters_double.push_back(EPSREL); 01497 parameters_double.push_back(EPSABS); 01498 01499 parameters_int.push_back(VERBOSE); 01500 parameters_int.push_back(MINEVAL); 01501 parameters_int.push_back(MAXEVAL); 01502 parameters_int.push_back(NSTART); 01503 parameters_int.push_back(NINCREASE); 01504 01505 // print to log 01506 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Running Cuba/Vegas integation over %i dimensions.", fNvar)); 01507 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Maximum number of iterations: %i", (int)MAXEVAL)); 01508 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Aimed relative precision: %e", EPSREL)); 01509 01510 return this -> CubaIntegrate(0, parameters_double, parameters_int); 01511 #else 01512 BCLog::Out(BCLog::error,BCLog::error,"!!! This version of BAT is compiled without Cuba."); 01513 BCLog::Out(BCLog::error,BCLog::error," Use other integration methods or install Cuba and recompile BAT."); 01514 return 0.; 01515 #endif 01516 }
double BCIntegrate::CubaIntegrate | ( | int | method, | |
std::vector< double > | parameters_double, | |||
std::vector< double > | parameters_int | |||
) |
Calculate integral using the Cuba library. For details see documentation.
method | A short cut for the method | |
parameters_double | A vector of parameters (double) | |
parameters_int | A vector of parameters (int) |
Definition at line 1519 of file BCIntegrate.cxx.
01520 { 01521 #ifdef HAVE_CUBA_H 01522 const int NDIM = int(fx ->size()); 01523 const int NCOMP = 1; 01524 01525 const double EPSREL = parameters_double[0]; 01526 const double EPSABS = parameters_double[1]; 01527 const int VERBOSE = int(parameters_int[0]); 01528 const int MINEVAL = int(parameters_int[1]); 01529 const int MAXEVAL = int(parameters_int[2]); 01530 01531 int neval; 01532 int fail; 01533 int nregions; 01534 double integral[NCOMP]; 01535 double error[NCOMP]; 01536 double prob[NCOMP]; 01537 01538 global_this = this; 01539 01540 integrand_t an_integrand = &BCIntegrate::CubaIntegrand; 01541 01542 if (method == 0) 01543 { 01544 // set VEGAS specific parameters 01545 const int NSTART = int(parameters_int[3]); 01546 const int NINCREASE = int(parameters_int[4]); 01547 01548 // call VEGAS integration method 01549 Vegas(NDIM, NCOMP, an_integrand, 01550 EPSREL, EPSABS, VERBOSE, MINEVAL, MAXEVAL, 01551 NSTART, NINCREASE, 01552 &neval, &fail, integral, error, prob); 01553 } 01554 else if (method == 1) 01555 { 01556 // set SUAVE specific parameters 01557 const int LAST = int(parameters_int[3]); 01558 const int NNEW = int(parameters_int[4]); 01559 const int FLATNESS = int(parameters_int[5]); 01560 01561 // call SUAVE integration method 01562 Suave(NDIM, NCOMP, an_integrand, 01563 EPSREL, EPSABS, VERBOSE | LAST, MINEVAL, MAXEVAL, 01564 NNEW, FLATNESS, 01565 &nregions, &neval, &fail, integral, error, prob); 01566 } 01567 else if (method == 2) 01568 { 01569 // set DIVONNE specific parameters 01570 const int KEY1 = int(parameters_int[3]); 01571 const int KEY2 = int(parameters_int[4]); 01572 const int KEY3 = int(parameters_int[5]); 01573 const int MAXPASS = int(parameters_int[6]); 01574 const int BORDER = int(parameters_int[7]); 01575 const int MAXCHISQ = int(parameters_int[8]); 01576 const int MINDEVIATION = int(parameters_int[9]); 01577 const int NGIVEN = int(parameters_int[10]); 01578 const int LDXGIVEN = int(parameters_int[11]); 01579 const int NEXTRA = int(parameters_int[12]); 01580 01581 // call DIVONNE integration method 01582 Divonne(NDIM, NCOMP, an_integrand, 01583 EPSREL, EPSABS, VERBOSE, MINEVAL, MAXEVAL, 01584 KEY1, KEY2, KEY3, MAXPASS, BORDER, MAXCHISQ, MINDEVIATION, 01585 NGIVEN, LDXGIVEN, NULL, NEXTRA, NULL, 01586 &nregions, &neval, &fail, integral, error, prob); 01587 } 01588 else if (method == 3) 01589 { 01590 // set CUHRE specific parameters 01591 const int LAST = int(parameters_int[3]); 01592 const int KEY = int(parameters_int[4]); 01593 01594 // call CUHRE integration method 01595 Cuhre(NDIM, NCOMP, an_integrand, 01596 EPSREL, EPSABS, VERBOSE | LAST, MINEVAL, MAXEVAL, KEY, 01597 &nregions, &neval, &fail, integral, error, prob); 01598 } 01599 else 01600 { 01601 std::cout << " Integration method not available. " << std::endl; 01602 integral[0] = -1e99; 01603 } 01604 01605 if (fail != 0) 01606 { 01607 std::cout << " Warning, integral did not converge with the given set of parameters. "<< std::endl; 01608 std::cout << " neval = " << neval << std::endl; 01609 std::cout << " fail = " << fail << std::endl; 01610 std::cout << " integral = " << integral[0] << std::endl; 01611 std::cout << " error = " << error[0] << std::endl; 01612 std::cout << " prob = " << prob[0] << std::endl; 01613 } 01614 01615 return integral[0] / 1e99; 01616 #else 01617 BCLog::Out(BCLog::error,BCLog::error,"!!! This version of BAT is compiled without Cuba."); 01618 BCLog::Out(BCLog::error,BCLog::error," Use other integration methods or install Cuba and recompile BAT."); 01619 return 0.; 01620 #endif 01621 }
void BCIntegrate::DeleteVarList | ( | ) |
double BCIntegrate::Eval | ( | std::vector< double > | x | ) | [virtual] |
Evaluate the unnormalized probability at a point in parameter space. Method needs to be overloaded by the user.
x | The point in parameter space |
Reimplemented in BCModel.
Definition at line 293 of file BCIntegrate.cxx.
00294 { 00295 BCLog::Out(BCLog::warning, BCLog::warning, "BCIntegrate::Eval. No function. Function needs to be overloaded."); 00296 return 0; 00297 }
double BCIntegrate::EvalPrint | ( | std::vector< double > | x | ) |
Evaluate the un-normalized probability at a point in parameter space and prints the result to the log.
x | The point in parameter space |
Definition at line 320 of file BCIntegrate.cxx.
00321 { 00322 double val=this->Eval(x); 00323 00324 BCLog::Out(BCLog::detail, BCLog::detail, Form("BCIntegrate::EvalPrint. Value: %d.", val)); 00325 00326 return val; 00327 }
double BCIntegrate::EvalSampling | ( | std::vector< double > | x | ) | [virtual] |
Evaluate the sampling function at a point in parameter space. Method needs to be overloaded by the user.
x | The point in parameter space |
Reimplemented in BCModel.
Definition at line 307 of file BCIntegrate.cxx.
00308 { 00309 BCLog::Out(BCLog::warning, BCLog::warning, "BCIntegrate::EvalSampling. No function. Function needs to be overloaded."); 00310 return 0; 00311 }
void BCIntegrate::FCNLikelihood | ( | int & | npar, | |
double * | grad, | |||
double & | fval, | |||
double * | par, | |||
int | flag | |||
) | [static] |
Definition at line 1391 of file BCIntegrate.cxx.
01392 { 01393 01394 // copy parameters 01395 std::vector <double> parameters; 01396 01397 int n = global_this -> GetNvar(); 01398 01399 for (int i = 0; i < n; i++) 01400 parameters.push_back(par[i]); 01401 01402 fval = - global_this -> LogEval(parameters); 01403 01404 // delete parameters 01405 01406 parameters.clear(); 01407 01408 }
void BCIntegrate::FindModeMCMC | ( | ) |
Does the mode finding using Markov Chain Monte Carlo
Definition at line 1413 of file BCIntegrate.cxx.
01414 { 01415 01416 // call PreRun 01417 // if (flag_run == 0) 01418 // if (!fMCMCFlagPreRun) 01419 // this -> MCMCMetropolisPreRun(); 01420 01421 // find global maximum 01422 double probmax = (this -> MCMCGetMaximumLogProb()).at(0); 01423 fBestFitParameters = this -> MCMCGetMaximumPoint(0); 01424 01425 // loop over all chains and find the maximum point 01426 for (int i = 1; i < fMCMCNChains; ++i) 01427 { 01428 double prob = (this -> MCMCGetMaximumLogProb()).at(i); 01429 01430 // copy the point into the vector 01431 if (prob > probmax) 01432 { 01433 probmax = prob; 01434 01435 fBestFitParameters.clear(); 01436 01437 fBestFitParameters = this -> MCMCGetMaximumPoint(i); 01438 } 01439 } 01440 01441 }
void BCIntegrate::FindModeMinuit | ( | std::vector< double > | start = std::vector<double>(0) , |
|
int | printlevel = 1 | |||
) |
Does the mode finding Does the mode finding using Minuit. If starting point is not specified, finding will start from the center of the parameter space.
start | point in parameter space from which the mode finding is started. | |
printlevel | The print level. |
Definition at line 1315 of file BCIntegrate.cxx.
01316 { 01317 bool have_start = true; 01318 01319 // check start values 01320 if (int(start.size()) != fNvar) 01321 have_start = false; 01322 01323 // set global this 01324 global_this = this; 01325 01326 // define minuit 01327 if (fMinuit) 01328 delete fMinuit; 01329 fMinuit = new TMinuit(fNvar); 01330 01331 // set function 01332 fMinuit -> SetFCN(&BCIntegrate::FCNLikelihood); 01333 01334 // set print level 01335 fMinuit -> SetPrintLevel(printlevel); 01336 01337 // set parameters 01338 int flag; 01339 for (int i = 0; i < fNvar; i++) 01340 { 01341 double starting_point = (fMin[i]+fMax[i])/2.; 01342 if(have_start) 01343 starting_point = start[i]; 01344 fMinuit -> mnparm(i, 01345 fx -> at(i) -> GetName().data(), 01346 starting_point, 01347 (fMax[i]-fMin[i])/100.0, 01348 fMin[i], 01349 fMax[i], 01350 flag); 01351 } 01352 01353 // do minimization 01354 fMinuit -> mnexcm("MIGRAD", fMinuitArglist, 2, flag); 01355 01356 // copy flag 01357 fMinuitErrorFlag = flag; 01358 01359 // set best fit parameters 01360 fBestFitParameters.clear(); 01361 01362 for (int i = 0; i < fNvar; i++) 01363 { 01364 double par; 01365 double parerr; 01366 fMinuit -> GetParameter(i, par, parerr); 01367 fBestFitParameters.push_back(par); 01368 } 01369 01370 // delete minuit 01371 delete fMinuit; 01372 fMinuit = 0; 01373 01374 return; 01375 }
virtual double BCIntegrate::FitFunction | ( | std::vector< double > | x, | |
std::vector< double > | parameters | |||
) | [inline, virtual] |
Defines a fit function.
parameters | A set of parameter values | |
x | A vector of x-values |
Reimplemented in BCEfficiencyFitter, BCGraphFitter, and BCHistogramFitter.
Definition at line 428 of file BCIntegrate.h.
double BCIntegrate::GetError | ( | ) | [inline] |
TH1D * BCIntegrate::GetH1D | ( | int | parIndex | ) |
parIndex1 | Index of parameter |
Definition at line 1014 of file BCIntegrate.cxx.
01015 { 01016 if(fHProb1D.size()==0) 01017 { 01018 BCLog::Out(BCLog::warning, BCLog::warning, 01019 "BCModel::GetH1D. MarginalizeAll() has to be run prior to this to fill the distributions."); 01020 return 0; 01021 } 01022 01023 if(parIndex<0 || parIndex>fNvar) 01024 { 01025 BCLog::Out(BCLog::warning, BCLog::warning, 01026 Form("BCIntegrate::GetH1D. Parameter index %d is invalid.",parIndex)); 01027 return 0; 01028 } 01029 01030 return fHProb1D[parIndex]; 01031 }
TH2D * BCIntegrate::GetH2D | ( | int | parIndex1, | |
int | parIndex2 | |||
) |
parIndex1 | Index of first parameter | |
parIndex2 | Index of second parameter, with parIndex2>parIndex1 |
Definition at line 1080 of file BCIntegrate.cxx.
01081 { 01082 if(fHProb2D.size()==0) 01083 { 01084 BCLog::Out(BCLog::warning, BCLog::warning, 01085 "BCModel::GetH2D. MarginalizeAll() has to be run prior to this to fill the distributions."); 01086 return 0; 01087 } 01088 01089 int hindex = this -> GetH2DIndex(parIndex1, parIndex2); 01090 if(hindex==-1) 01091 return 0; 01092 01093 if(hindex>(int)fHProb2D.size()-1) 01094 { 01095 BCLog::Out(BCLog::warning, BCLog::warning, 01096 "BCIntegrate::GetH2D. Got invalid index from GetH2DIndex(). Something went wrong."); 01097 return 0; 01098 } 01099 01100 return fHProb2D[hindex]; 01101 }
int BCIntegrate::GetH2DIndex | ( | int | parIndex1, | |
int | parIndex2 | |||
) |
parIndex1 | Index of first parameter | |
parIndex2 | Index of second parameter, with parIndex2>parIndex1 |
Definition at line 1034 of file BCIntegrate.cxx.
01035 { 01036 if(parIndex1>fNvar-1 || parIndex1<0) 01037 { 01038 BCLog::Out(BCLog::warning, BCLog::warning, 01039 Form("BCIntegrate::GetH2DIndex. Parameter index %d is invalid", parIndex1)); 01040 return -1; 01041 } 01042 01043 if(parIndex2>fNvar-1 || parIndex2<0) 01044 { 01045 BCLog::Out(BCLog::warning, BCLog::warning, 01046 Form("BCIntegrate::GetH2DIndex. Parameter index %d is invalid", parIndex2)); 01047 return -1; 01048 } 01049 01050 if(parIndex1==parIndex2) 01051 { 01052 BCLog::Out(BCLog::warning, BCLog::warning, 01053 Form("BCIntegrate::GetH2DIndex. Parameters have equal indeces: %d , %d", parIndex1, parIndex2)); 01054 return -1; 01055 } 01056 01057 if(parIndex1>parIndex2) 01058 { 01059 BCLog::Out(BCLog::warning, BCLog::warning, 01060 "BCIntegrate::GetH2DIndex. First parameters must be smaller than second (sorry)."); 01061 return -1; 01062 } 01063 01064 int index=0; 01065 for(int i=0;i<fNvar-1;i++) 01066 for(int j=i+1;j<fNvar;j++) 01067 { 01068 if(i==parIndex1 && j==parIndex2) 01069 return index; 01070 index++; 01071 } 01072 01073 BCLog::Out(BCLog::warning, BCLog::warning, 01074 "BCIntegrate::GetH2DIndex. Invalid index combination."); 01075 01076 return -1; 01077 }
BCIntegrate::BCIntegrationMethod BCIntegrate::GetIntegrationMethod | ( | ) | [inline] |
Definition at line 89 of file BCIntegrate.h.
00090 { return fIntegrationMethod; };
BCIntegrate::BCMarginalizationMethod BCIntegrate::GetMarginalizationMethod | ( | ) | [inline] |
Definition at line 94 of file BCIntegrate.h.
00095 { return fMarginalizationMethod; };
std::vector<double>* BCIntegrate::GetMarkovChainPoint | ( | ) | [inline] |
TTree* BCIntegrate::GetMarkovChainTree | ( | ) | [inline] |
double* BCIntegrate::GetMarkovChainValue | ( | ) | [inline] |
Returns the value of the loglikelihood at the point fXmetro1
Definition at line 199 of file BCIntegrate.h.
00200 { return &fMarkovChainValue; };
int* BCIntegrate::GetMCMCIteration | ( | ) | [inline] |
Returns the iteration of the MCMC
Definition at line 194 of file BCIntegrate.h.
00195 { return &fMCMCIteration; };
TMinuit * BCIntegrate::GetMinuit | ( | ) |
Definition at line 1303 of file BCIntegrate.cxx.
01304 { 01305 01306 if (!fMinuit) 01307 fMinuit = new TMinuit(); 01308 01309 return fMinuit; 01310 01311 }
int BCIntegrate::GetMinuitErrorFlag | ( | ) | [inline] |
int BCIntegrate::GetNbins | ( | ) | [inline] |
int BCIntegrate::GetNIterations | ( | ) | [inline] |
Definition at line 157 of file BCIntegrate.h.
00158 { return fNIterations; };
int BCIntegrate::GetNIterationsMax | ( | ) | [inline] |
Definition at line 152 of file BCIntegrate.h.
00153 { return fNIterationsMax; };
int BCIntegrate::GetNiterationsPerDimension | ( | ) | [inline] |
Definition at line 137 of file BCIntegrate.h.
00138 { return fNiterPerDimension; };
int BCIntegrate::GetNSamplesPer2DBin | ( | ) | [inline] |
Definition at line 142 of file BCIntegrate.h.
00143 { return fNSamplesPer2DBin; };
int BCIntegrate::GetNvar | ( | ) | [inline] |
Definition at line 147 of file BCIntegrate.h.
00148 { return fNvar; };
BCIntegrate::BCOptimizationMethod BCIntegrate::GetOptimizationMethod | ( | ) | [inline] |
Definition at line 99 of file BCIntegrate.h.
00100 { return fOptimizationMethod; };
double BCIntegrate::GetRandomPoint | ( | std::vector< double > & | x | ) |
Fills a vector of (flat) random numbers in the limits of the parameters and returns the probability at that point
x | A vector of doubles |
Definition at line 1104 of file BCIntegrate.cxx.
01105 { 01106 this->GetRandomVector(x); 01107 01108 for(int i=0;i<fNvar;i++) 01109 x[i]=fMin[i]+x[i]*(fMax[i]-fMin[i]); 01110 01111 return this->Eval(x); 01112 }
double BCIntegrate::GetRandomPointImportance | ( | std::vector< double > & | x | ) |
Fills a vector of random numbers in the limits of the parameters sampled by the sampling function and returns the probability at that point
x | A vector of doubles |
Definition at line 1115 of file BCIntegrate.cxx.
01116 { 01117 double p = 1.1; 01118 double g = 1.0; 01119 01120 while (p>g) 01121 { 01122 this->GetRandomVector(x); 01123 01124 for(int i=0;i<fNvar;i++) 01125 x[i] = fMin[i] + x[i] * (fMax[i]-fMin[i]); 01126 01127 p = fRandom->Rndm(); 01128 01129 g = this -> EvalSampling(x); 01130 } 01131 01132 return this->Eval(x); 01133 }
void BCIntegrate::GetRandomPointMetro | ( | std::vector< double > & | x | ) |
Fills a vector of random numbers in the limits of the parameters sampled by the probality function and returns the probability at that point (Metropolis)
x | A vector of doubles |
Definition at line 1161 of file BCIntegrate.cxx.
01162 { 01163 // get new point 01164 this->GetRandomVectorMetro(fXmetro1); 01165 01166 // scale the point to the allowed region and stepsize 01167 int in=1; 01168 for(int i=0;i<fNvar;i++) 01169 { 01170 fXmetro1[i] = fXmetro0[i] + fXmetro1[i] * (fMax[i]-fMin[i]); 01171 01172 // check whether the generated point is inside the allowed region 01173 if( fXmetro1[i]<fMin[i] || fXmetro1[i]>fMax[i] ) 01174 in=0; 01175 } 01176 01177 // calculate the log probabilities and compare old and new point 01178 01179 double p0 = fMarkovChainValue; // old point 01180 double p1 = 0; // new point 01181 int accept=0; 01182 01183 if(in) 01184 { 01185 p1 = this -> LogEval(fXmetro1); 01186 01187 if(p1>=p0) 01188 accept=1; 01189 else 01190 { 01191 double r=log(fRandom->Rndm()); 01192 if(r<p1-p0) 01193 accept=1; 01194 } 01195 } 01196 01197 // fill the return point after the decision 01198 if(accept) 01199 { 01200 // increase counter 01201 fNacceptedMCMC++; 01202 01203 for(int i=0;i<fNvar;i++) 01204 { 01205 fXmetro0[i]=fXmetro1[i]; 01206 x[i]=fXmetro1[i]; 01207 fMarkovChainValue = p1; 01208 } 01209 01210 } 01211 else 01212 for(int i=0;i<fNvar;i++) 01213 { 01214 x[i]=fXmetro0[i]; 01215 fXmetro1[i] = x[i]; 01216 fMarkovChainValue = p0; 01217 } 01218 01219 fNmetro++; 01220 01221 }
void BCIntegrate::GetRandomPointSamplingMetro | ( | std::vector< double > & | x | ) |
Fills a vector of random numbers in the limits of the parameters sampled by the sampling function and returns the probability at that point (Metropolis)
x | A vector of doubles |
Definition at line 1224 of file BCIntegrate.cxx.
01225 { 01226 // get new point 01227 this->GetRandomVectorMetro(fXmetro1); 01228 01229 // scale the point to the allowed region and stepsize 01230 int in=1; 01231 for(int i=0;i<fNvar;i++) 01232 { 01233 fXmetro1[i] = fXmetro0[i] + fXmetro1[i] * (fMax[i]-fMin[i]); 01234 01235 // check whether the generated point is inside the allowed region 01236 if( fXmetro1[i]<fMin[i] || fXmetro1[i]>fMax[i] ) 01237 in=0; 01238 } 01239 01240 // calculate the log probabilities and compare old and new point 01241 double p0 = this -> LogEvalSampling(fXmetro0); // old point 01242 double p1=0; // new point 01243 if(in) 01244 p1= this -> LogEvalSampling(fXmetro1); 01245 01246 // compare log probabilities 01247 int accept=0; 01248 if(in) 01249 { 01250 if(p1>=p0) 01251 accept=1; 01252 else 01253 { 01254 double r=log(fRandom->Rndm()); 01255 if(r<p1-p0) 01256 accept=1; 01257 } 01258 } 01259 01260 // fill the return point after the decision 01261 if(accept) 01262 for(int i=0;i<fNvar;i++) 01263 { 01264 fXmetro0[i]=fXmetro1[i]; 01265 x[i]=fXmetro1[i]; 01266 } 01267 else 01268 for(int i=0;i<fNvar;i++) 01269 x[i]=fXmetro0[i]; 01270 01271 fNmetro++; 01272 }
void BCIntegrate::GetRandomVector | ( | std::vector< double > & | x | ) |
Fills a vector of random numbers between 0 and 1 into a vector
A | vector of doubles |
Definition at line 1275 of file BCIntegrate.cxx.
01276 { 01277 double * randx = new double[fNvar]; 01278 01279 fRandom -> RndmArray(fNvar, randx); 01280 01281 for(int i=0;i<fNvar;i++) 01282 x[i] = randx[i]; 01283 01284 delete[] randx; 01285 randx = 0; 01286 }
void BCIntegrate::GetRandomVectorMetro | ( | std::vector< double > & | x | ) | [virtual] |
Definition at line 1289 of file BCIntegrate.cxx.
01290 { 01291 double * randx = new double[fNvar]; 01292 01293 fRandom -> RndmArray(fNvar, randx); 01294 01295 for(int i=0;i<fNvar;i++) 01296 x[i] = 2.0 * (randx[i] - 0.5) * fMarkovChainStepSize; 01297 01298 delete[] randx; 01299 randx = 0; 01300 }
double BCIntegrate::GetRelativePrecision | ( | ) | [inline] |
Definition at line 162 of file BCIntegrate.h.
00163 { return fRelativePrecision; };
void BCIntegrate::InitMetro | ( | ) |
Initializes the Metropolis algorithm (for details see manual)
Definition at line 1136 of file BCIntegrate.cxx.
01137 { 01138 fNmetro=0; 01139 01140 if (fXmetro0.size() <= 0) 01141 { 01142 // start in the center of the phase space 01143 for(int i=0;i<fNvar;i++) 01144 fXmetro0.push_back((fMin[i]+fMax[i])/2.0); 01145 } 01146 01147 fMarkovChainValue = this -> LogEval(fXmetro0); 01148 01149 // run metropolis for a few times and dump the result... (to forget the initial position) 01150 std::vector <double> x; 01151 x.assign(fNvar,0.); 01152 01153 for(int i=0;i<1000;i++) 01154 GetRandomPointMetro(x); 01155 01156 fNmetro = 0; 01157 01158 }
double BCIntegrate::IntegralImportance | ( | std::vector< double > | x | ) |
Perfoms the importance sampling Monte Carlo integration. For details see documentation.
x | An initial point in parameter space |
Definition at line 548 of file BCIntegrate.cxx.
00549 { 00550 // print debug information 00551 BCLog::Out(BCLog::debug, BCLog::debug, Form("BCIntegrate::IntegralImportance. Integate over %i dimensions.", fNvar)); 00552 00553 // get total number of iterations 00554 double Niter = pow(fNiterPerDimension, fNvar); 00555 00556 // print if more than 100,000 iterations 00557 if(Niter>1e5) 00558 BCLog::Out(BCLog::detail, BCLog::detail, Form("BCIntegrate::IntegralImportance. Total number of iterations: %d.", Niter)); 00559 00560 // reset sum 00561 double sumI = 0; 00562 00563 std::vector <double> randx; 00564 randx.assign(fNvar,0.); 00565 00566 // prepare maximum value 00567 double pmax = 0.0; 00568 00569 // loop over iterations 00570 for(int i = 0; i <= Niter; i++) 00571 { 00572 // get random point from sampling distribution 00573 this -> GetRandomPointImportance(randx); 00574 00575 // calculate probability at random point 00576 double val_f = this -> Eval(randx); 00577 00578 // calculate sampling distributions at that point 00579 double val_g = this -> EvalSampling(randx); 00580 00581 // add ratio to sum 00582 if (val_g > 0) 00583 sumI += val_f / val_g; 00584 00585 // search for maximum probability 00586 if (val_f > pmax) 00587 { 00588 // set new maximum value 00589 pmax = val_f; 00590 00591 // delete old best fit parameter values 00592 fBestFitParameters.clear(); 00593 00594 // write best fit parameters 00595 for(int i = 0; i < fNvar; i++) 00596 fBestFitParameters.push_back(randx.at(i)); 00597 } 00598 00599 // write intermediate results 00600 if((i+1)%100000 == 0) 00601 BCLog::Out(BCLog::debug, BCLog::debug, 00602 Form("BCIntegrate::IntegralImportance. Iteration %d, integral: %d.", i+1, sumI/(i+1))); 00603 } 00604 00605 // calculate integral 00606 double result=sumI/Niter; 00607 00608 // print debug information 00609 BCLog::Out(BCLog::debug, BCLog::debug, Form("BCIntegrate::IntegralImportance. Integral %f in %i iterations.", result, Niter)); 00610 00611 return result; 00612 }
double BCIntegrate::IntegralMC | ( | std::vector< double > | x | ) |
Definition at line 381 of file BCIntegrate.cxx.
00382 { 00383 // count the variables to integrate over 00384 int NvarNow=0; 00385 00386 for(int i = 0; i < fNvar; i++) 00387 if(fVarlist[i]) 00388 NvarNow++; 00389 00390 // print to log 00391 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Running MC integation over %i dimensions.", NvarNow)); 00392 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Maximum number of iterations: %i", this->GetNIterationsMax())); 00393 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Aimed relative precision: %e", this->GetRelativePrecision())); 00394 00395 // calculate D (the integrated volume) 00396 double D = 1.0; 00397 for(int i = 0; i < fNvar; i++) 00398 if (fVarlist[i]) 00399 D = D * (fMax[i] - fMin[i]); 00400 00401 // reset variables 00402 double pmax = 0.0; 00403 double sumW = 0.0; 00404 double sumW2 = 0.0; 00405 double integral = 0.0; 00406 double variance = 0.0; 00407 double relprecision = 1.0; 00408 00409 std::vector <double> randx; 00410 randx.assign(fNvar, 0.0); 00411 00412 // reset number of iterations 00413 fNIterations = 0; 00414 00415 // iterate while precision is not reached and the number of iterations is lower than maximum number of iterations 00416 while ((fRelativePrecision < relprecision && fNIterationsMax > fNIterations) || fNIterations < 10) 00417 { 00418 // increase number of iterations 00419 fNIterations++; 00420 00421 // get random numbers 00422 this -> GetRandomVector(randx); 00423 00424 // scale random numbers 00425 for(int i = 0; i < fNvar; i++) 00426 { 00427 if(fVarlist[i]) 00428 randx[i]=fMin[i]+randx[i]*(fMax[i]-fMin[i]); 00429 else 00430 randx[i]=x[i]; 00431 } 00432 00433 // evaluate function at sampled point 00434 double value = this->Eval(randx); 00435 00436 // add value to sum and sum of squares 00437 sumW += value; 00438 sumW2 += value * value; 00439 00440 // search for maximum probability 00441 if (value > pmax) 00442 { 00443 // set new maximum value 00444 pmax = value; 00445 00446 // delete old best fit parameter values 00447 fBestFitParameters.clear(); 00448 00449 // write best fit parameters 00450 for(int i = 0; i < fNvar; i++) 00451 fBestFitParameters.push_back(randx.at(i)); 00452 } 00453 00454 // calculate integral and variance 00455 integral = D * sumW / fNIterations; 00456 00457 if (fNIterations%10000 == 0) 00458 { 00459 variance = (1.0 / double(fNIterations)) * (D * D * sumW2 / double(fNIterations) - integral * integral); 00460 double error = sqrt(variance); 00461 relprecision = error / integral; 00462 00463 BCLog::Out(BCLog::debug, BCLog::debug, 00464 Form("BCIntegrate::IntegralMC. Iteration %i, integral: %e +- %e.", fNIterations, integral, error)); 00465 } 00466 } 00467 00468 fError = variance / fNIterations; 00469 00470 // print to log 00471 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Result of integration: %e +- %e in %i iterations.", integral, sqrt(variance), fNIterations)); 00472 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Obtained relative precision: %e. ", sqrt(variance) / integral)); 00473 00474 return integral; 00475 }
double BCIntegrate::IntegralMC | ( | std::vector< double > | x, | |
int * | varlist | |||
) |
Perfoms the Monte Carlo integration. For details see documentation.
x | An initial point in parameter space | |
varlist | A list of variables |
Definition at line 374 of file BCIntegrate.cxx.
00375 { 00376 this->SetVarList(varlist); 00377 return IntegralMC(x); 00378 }
double BCIntegrate::IntegralMetro | ( | std::vector< double > | x | ) |
Perfoms the Metropolis Monte Carlo integration. For details see documentation.
x | An initial point in parameter space |
Definition at line 479 of file BCIntegrate.cxx.
00480 { 00481 // print debug information 00482 BCLog::Out(BCLog::debug, BCLog::debug, Form("BCIntegrate::IntegralMetro. Integate over %i dimensions.", fNvar)); 00483 00484 // get total number of iterations 00485 double Niter = pow(fNiterPerDimension, fNvar); 00486 00487 // print if more than 100,000 iterations 00488 if(Niter>1e5) 00489 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Total number of iterations in Metropolis: %d.", Niter)); 00490 00491 // reset sum 00492 double sumI = 0; 00493 00494 // prepare Metropolis algorithm 00495 std::vector <double> randx; 00496 randx.assign(fNvar,0.); 00497 InitMetro(); 00498 00499 // prepare maximum value 00500 double pmax = 0.0; 00501 00502 // loop over iterations 00503 for(int i = 0; i <= Niter; i++) 00504 { 00505 // get random point from sampling distribution 00506 this -> GetRandomPointSamplingMetro(randx); 00507 00508 // calculate probability at random point 00509 double val_f = this -> Eval(randx); 00510 00511 // calculate sampling distributions at that point 00512 double val_g = this -> EvalSampling(randx); 00513 00514 // add ratio to sum 00515 if (val_g > 0) 00516 sumI += val_f / val_g; 00517 00518 // search for maximum probability 00519 if (val_f > pmax) 00520 { 00521 // set new maximum value 00522 pmax = val_f; 00523 00524 // delete old best fit parameter values 00525 fBestFitParameters.clear(); 00526 00527 // write best fit parameters 00528 for(int i = 0; i < fNvar; i++) 00529 fBestFitParameters.push_back(randx.at(i)); 00530 } 00531 00532 // write intermediate results 00533 if((i+1)%100000 == 0) 00534 BCLog::Out(BCLog::debug, BCLog::debug, 00535 Form("BCIntegrate::IntegralMetro. Iteration %d, integral: %d.", i+1, sumI/(i+1))); 00536 } 00537 00538 // calculate integral 00539 double result=sumI/Niter; 00540 00541 // print debug information 00542 BCLog::Out(BCLog::detail, BCLog::detail, Form(" --> Integral is %f in %i iterations.", result, Niter)); 00543 00544 return result; 00545 }
double BCIntegrate::Integrate | ( | ) |
Does the integration over the un-normalized probability.
Definition at line 342 of file BCIntegrate.cxx.
00343 { 00344 std::vector <double> parameter; 00345 parameter.assign(fNvar, 0.0); 00346 00347 switch(fIntegrationMethod) 00348 { 00349 case BCIntegrate::kIntMonteCarlo: 00350 return IntegralMC(parameter); 00351 00352 case BCIntegrate::kIntMetropolis: 00353 return this -> IntegralMetro(parameter); 00354 00355 case BCIntegrate::kIntImportance: 00356 return this -> IntegralImportance(parameter); 00357 00358 case BCIntegrate::kIntCuba: 00359 #ifdef HAVE_CUBA_H 00360 return this -> CubaIntegrate(); 00361 #else 00362 BCLog::Out(BCLog::error,BCLog::error,"!!! This version of BAT is compiled without Cuba."); 00363 BCLog::Out(BCLog::error,BCLog::error," Use other integration methods or install Cuba and recompile BAT."); 00364 #endif 00365 } 00366 00367 BCLog::Out(BCLog::error, BCLog::error, 00368 Form("BCIntegrate::Integrate : Invalid integration method: %d", fIntegrationMethod)); 00369 00370 return 0; 00371 }
double BCIntegrate::LogEval | ( | std::vector< double > | x | ) | [virtual] |
Evaluate the natural logarithm of the Eval function. For better numerical stability, this method should also be overloaded by the user.
x | The point in parameter space |
Reimplemented from BCEngineMCMC.
Reimplemented in BCModel.
Definition at line 300 of file BCIntegrate.cxx.
00301 { 00302 // this method should better also be overloaded 00303 return log(this->Eval(x)); 00304 }
double BCIntegrate::LogEvalSampling | ( | std::vector< double > | x | ) |
Evaluate the natural logarithm of the EvalSampling function. Method needs to be overloaded by the user.
x | The point in parameter space |
Definition at line 314 of file BCIntegrate.cxx.
00315 { 00316 return log(this->EvalSampling(x)); 00317 }
TH2D * BCIntegrate::Marginalize | ( | BCParameter * | parameter1, | |
BCParameter * | parameter2 | |||
) |
Performs the marginalization with respect to two parameters.
parameter1 | The first parameter w.r.t. which the marginalization is performed | |
parameter2 | The second parameter w.r.t. which the marginalization is performed |
Definition at line 636 of file BCIntegrate.cxx.
00637 { 00638 switch(fMarginalizationMethod) 00639 { 00640 case BCIntegrate::kMargMonteCarlo: 00641 return MarginalizeByIntegrate(parameter1,parameter2); 00642 00643 case BCIntegrate::kMargMetropolis: 00644 return MarginalizeByMetro(parameter1,parameter2); 00645 } 00646 00647 BCLog::Out(BCLog::warning, BCLog::warning, 00648 Form("BCIntegrate::Marginalize. Invalid marginalization method: %d. Return 0.", fMarginalizationMethod)); 00649 00650 return 0; 00651 }
TH1D * BCIntegrate::Marginalize | ( | BCParameter * | parameter | ) |
Performs the marginalization with respect to one parameter.
parameter | The parameter w.r.t. which the marginalization is performed |
Definition at line 615 of file BCIntegrate.cxx.
00616 { 00617 BCLog::Out(BCLog::detail, BCLog::detail, 00618 Form(" --> Marginalizing model wrt. parameter %s using method %d.", parameter->GetName().data(), fMarginalizationMethod)); 00619 00620 switch(fMarginalizationMethod) 00621 { 00622 case BCIntegrate::kMargMonteCarlo: 00623 return MarginalizeByIntegrate(parameter); 00624 00625 case BCIntegrate::kMargMetropolis: 00626 return MarginalizeByMetro(parameter); 00627 } 00628 00629 BCLog::Out(BCLog::warning, BCLog::warning, 00630 Form("BCIntegrate::Marginalize. Invalid marginalization method: %d. Return 0.", fMarginalizationMethod)); 00631 00632 return 0; 00633 }
int BCIntegrate::MarginalizeAllByMetro | ( | const char * | name = "" |
) |
Performs the marginalization with respect to every single parameter as well as with respect all combinations to two parameters using the Metropolis algorithm.
name | Basename for the histograms (e.g. model name) |
Definition at line 804 of file BCIntegrate.cxx.
00805 { 00806 int niter=fNbins*fNbins*fNSamplesPer2DBin*fNvar; 00807 00808 BCLog::Out(BCLog::detail, BCLog::detail, 00809 Form(" --> Number of samples in Metropolis marginalization: %d.", niter)); 00810 00811 // define 1D histograms 00812 for(int i=0;i<fNvar;i++) 00813 { 00814 double hmin1 = fx->at(i) -> GetLowerLimit(); 00815 double hmax1 = fx->at(i) -> GetUpperLimit(); 00816 00817 TH1D * h1 = new TH1D( 00818 TString::Format("h%s_%s", name, fx->at(i) -> GetName().data()),"", 00819 fNbins, hmin1, hmax1); 00820 00821 fHProb1D.push_back(h1); 00822 } 00823 00824 // define 2D histograms 00825 for(int i=0;i<fNvar-1;i++) 00826 for(int j=i+1;j<fNvar;j++) 00827 { 00828 double hmin1 = fx->at(i) -> GetLowerLimit(); 00829 double hmax1 = fx->at(i) -> GetUpperLimit(); 00830 00831 double hmin2 = fx->at(j) -> GetLowerLimit(); 00832 double hmax2 = fx->at(j) -> GetUpperLimit(); 00833 00834 TH2D * h2 = new TH2D( 00835 TString::Format("h%s_%s_%s", name, fx->at(i) -> GetName().data(), fx->at(j) -> GetName().data()),"", 00836 fNbins, hmin1, hmax1, 00837 fNbins, hmin2, hmax2); 00838 00839 fHProb2D.push_back(h2); 00840 } 00841 00842 // get number of 2d distributions 00843 int nh2d = fHProb2D.size(); 00844 00845 BCLog::Out(BCLog::detail, BCLog::detail, 00846 Form(" --> Marginalizing %d 1D distributions and %d 2D distributions.", fNvar, nh2d)); 00847 00848 // prepare function fitting 00849 double dx = 0.0; 00850 double dy = 0.0; 00851 00852 if (fFitFunctionIndexX >= 0) 00853 { 00854 dx = (fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexX) - 00855 fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexX)) 00856 / double(fErrorBandNbinsX); 00857 00858 dx = (fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexY) - 00859 fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexY)) 00860 / double(fErrorBandNbinsY); 00861 00862 fErrorBandXY = new TH2D( 00863 TString::Format("errorbandxy_%d",BCLog::GetHIndex()), "", 00864 fErrorBandNbinsX, 00865 fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexX) - 0.5 * dx, 00866 fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexX) + 0.5 * dx, 00867 fErrorBandNbinsY, 00868 fDataPointLowerBoundaries -> GetValue(fFitFunctionIndexY) - 0.5 * dy, 00869 fDataPointUpperBoundaries -> GetValue(fFitFunctionIndexY) + 0.5 * dy); 00870 fErrorBandXY -> SetStats(kFALSE); 00871 00872 for (int ix = 1; ix <= fErrorBandNbinsX; ++ix) 00873 for (int iy = 1; iy <= fErrorBandNbinsX; ++iy) 00874 fErrorBandXY -> SetBinContent(ix, iy, 0.0); 00875 } 00876 00877 // prepare Metro 00878 std::vector <double> randx; 00879 00880 randx.assign(fNvar, 0.0); 00881 InitMetro(); 00882 00883 // reset counter 00884 fNacceptedMCMC = 0; 00885 00886 // run Metro and fill histograms 00887 for(int i=0;i<=niter;i++) 00888 { 00889 GetRandomPointMetro(randx); 00890 00891 // save this point to the markov chain in the ROOT file 00892 if (fFlagWriteMarkovChain) 00893 { 00894 fMCMCIteration = i; 00895 fMarkovChainTree -> Fill(); 00896 } 00897 00898 for(int j=0;j<fNvar;j++) 00899 fHProb1D[j] -> Fill( randx[j] ); 00900 00901 int ih=0; 00902 for(int j=0;j<fNvar-1;j++) 00903 for(int k=j+1;k<fNvar;k++) 00904 { 00905 fHProb2D[ih] -> Fill(randx[j],randx[k]); 00906 ih++; 00907 } 00908 00909 if((i+1)%100000==0) 00910 BCLog::Out(BCLog::debug, BCLog::debug, 00911 Form("BCIntegrate::MarginalizeAllByMetro. %d samples done.",i+1)); 00912 00913 // function fitting 00914 00915 if (fFitFunctionIndexX >= 0) 00916 { 00917 00918 // loop over all possible x values ... 00919 00920 if (fErrorBandContinuous) 00921 { 00922 double x = 0; 00923 00924 for (int ix = 0; ix < fErrorBandNbinsX; ix++) 00925 { 00926 // calculate x 00927 00928 x = fErrorBandXY -> GetXaxis() -> GetBinCenter(ix + 1); 00929 00930 // calculate y 00931 00932 std::vector <double> xvec; 00933 xvec.push_back(x); 00934 00935 double y = this -> FitFunction(xvec, randx); 00936 00937 xvec.clear(); 00938 00939 // fill histogram 00940 00941 fErrorBandXY -> Fill(x, y); 00942 } 00943 } 00944 00945 // ... or evaluate at the data point x-values 00946 00947 else 00948 { 00949 00950 int ndatapoints = int(fErrorBandX.size()); 00951 00952 double x = 0; 00953 00954 for (int ix = 0; ix < ndatapoints; ++ix) 00955 { 00956 // calculate x 00957 00958 x = fErrorBandX.at(ix); 00959 00960 // calculate y 00961 00962 std::vector <double> xvec; 00963 xvec.push_back(x); 00964 00965 double y = this -> FitFunction(xvec, randx); 00966 00967 xvec.clear(); 00968 00969 // fill histogram 00970 00971 fErrorBandXY -> Fill(x, y); 00972 } 00973 00974 } 00975 } 00976 } 00977 00978 // normalize histograms 00979 00980 for(int i=0;i<fNvar;i++) 00981 fHProb1D[i] -> Scale( 1./fHProb1D[i]->Integral("width") ); 00982 00983 for (int i=0;i<nh2d;i++) 00984 fHProb2D[i] -> Scale( 1./fHProb2D[i]->Integral("width") ); 00985 00986 if (fFitFunctionIndexX >= 0) 00987 fErrorBandXY -> Scale(1.0/fErrorBandXY -> Integral() * fErrorBandXY -> GetNbinsX()); 00988 00989 if (fFitFunctionIndexX >= 0) 00990 { 00991 for (int ix = 1; ix <= fErrorBandNbinsX; ix++) 00992 { 00993 double sum = 0; 00994 00995 for (int iy = 1; iy <= fErrorBandNbinsY; iy++) 00996 sum += fErrorBandXY -> GetBinContent(ix, iy); 00997 00998 for (int iy = 1; iy <= fErrorBandNbinsY; iy++) 00999 { 01000 double newvalue = fErrorBandXY -> GetBinContent(ix, iy) / sum; 01001 fErrorBandXY -> SetBinContent(ix, iy, newvalue); 01002 } 01003 } 01004 } 01005 01006 BCLog::Out(BCLog::detail, BCLog::detail, 01007 Form("BCIntegrate::MarginalizeAllByMetro done with %i trials and %i accepted trials. Efficiency is %f",fNmetro, fNacceptedMCMC, double(fNacceptedMCMC)/double(fNmetro))); 01008 01009 return fNvar+nh2d; 01010 01011 }
TH2D * BCIntegrate::MarginalizeByIntegrate | ( | BCParameter * | parameter1, | |
BCParameter * | parameter2 | |||
) |
Performs the marginalization with respect to two parameters using the simple Monte Carlo technique.
parameter1 | The first parameter w.r.t. which the marginalization is performed | |
parameter2 | The second parameter w.r.t. which the marginalization is performed |
Definition at line 686 of file BCIntegrate.cxx.
00687 { 00688 // set parameter to marginalize 00689 this->ResetVarlist(1); 00690 int index1 = parameter1->GetIndex(); 00691 this->UnsetVar(index1); 00692 int index2 = parameter2->GetIndex(); 00693 this->UnsetVar(index2); 00694 00695 // define histogram 00696 double hmin1 = parameter1 -> GetLowerLimit(); 00697 double hmax1 = parameter1 -> GetUpperLimit(); 00698 double hdx1 = (hmax1 - hmin1) / double(fNbins); 00699 00700 double hmin2 = parameter2 -> GetLowerLimit(); 00701 double hmax2 = parameter2 -> GetUpperLimit(); 00702 double hdx2 = (hmax2 - hmin2) / double(fNbins); 00703 00704 TH2D * hist = new TH2D(Form("hist_%s_%s", parameter1 -> GetName().data(), parameter2 -> GetName().data()),"", 00705 fNbins, hmin1, hmax1, 00706 fNbins, hmin2, hmax2); 00707 00708 // integrate 00709 std::vector <double> randx; 00710 randx.assign(fNvar, 0.0); 00711 00712 for(int i=0;i<=fNbins;i++) 00713 { 00714 randx[index1] = hmin1 + (double)i * hdx1; 00715 for(int j=0;j<=fNbins;j++) 00716 { 00717 randx[index2] = hmin2 + (double)j * hdx2; 00718 00719 double val = IntegralMC(randx); 00720 hist->Fill(randx[index1],randx[index2], val); 00721 } 00722 } 00723 00724 // normalize 00725 hist -> Scale(1.0/hist->Integral("width")); 00726 00727 return hist; 00728 }
TH1D * BCIntegrate::MarginalizeByIntegrate | ( | BCParameter * | parameter | ) |
Performs the marginalization with respect to one parameter using the simple Monte Carlo technique.
parameter | The parameter w.r.t. which the marginalization is performed |
Definition at line 654 of file BCIntegrate.cxx.
00655 { 00656 // set parameter to marginalize 00657 this->ResetVarlist(1); 00658 int index = parameter->GetIndex(); 00659 this->UnsetVar(index); 00660 00661 // define histogram 00662 double hmin = parameter -> GetLowerLimit(); 00663 double hmax = parameter -> GetUpperLimit(); 00664 double hdx = (hmax - hmin) / double(fNbins); 00665 TH1D * hist = new TH1D("hist","", fNbins, hmin, hmax); 00666 00667 // integrate 00668 std::vector <double> randx; 00669 randx.assign(fNvar, 0.0); 00670 00671 for(int i=0;i<=fNbins;i++) 00672 { 00673 randx[index] = hmin + (double)i * hdx; 00674 00675 double val = IntegralMC(randx); 00676 hist->Fill(randx[index], val); 00677 } 00678 00679 // normalize 00680 hist -> Scale( 1./hist->Integral("width") ); 00681 00682 return hist; 00683 }
TH2D * BCIntegrate::MarginalizeByMetro | ( | BCParameter * | parameter1, | |
BCParameter * | parameter2 | |||
) |
Performs the marginalization with respect to two parameters using the Metropolis algorithm.
parameter1 | The first parameter w.r.t. which the marginalization is performed | |
parameter2 | The second parameter w.r.t. which the marginalization is performed |
Definition at line 767 of file BCIntegrate.cxx.
00768 { 00769 int niter=fNbins*fNbins*fNSamplesPer2DBin*fNvar; 00770 00771 // set parameter to marginalize 00772 int index1 = parameter1->GetIndex(); 00773 int index2 = parameter2->GetIndex(); 00774 00775 // define histogram 00776 double hmin1 = parameter1 -> GetLowerLimit(); 00777 double hmax1 = parameter1 -> GetUpperLimit(); 00778 00779 double hmin2 = parameter2 -> GetLowerLimit(); 00780 double hmax2 = parameter2 -> GetUpperLimit(); 00781 00782 TH2D * hist = new TH2D(Form("hist_%s_%s", parameter1 -> GetName().data(), parameter2 -> GetName().data()),"", 00783 fNbins, hmin1, hmax1, 00784 fNbins, hmin2, hmax2); 00785 00786 // prepare Metro 00787 std::vector <double> randx; 00788 randx.assign(fNvar, 0.0); 00789 InitMetro(); 00790 00791 for(int i=0;i<=niter;i++) 00792 { 00793 GetRandomPointMetro(randx); 00794 hist->Fill(randx[index1],randx[index2]); 00795 } 00796 00797 // normalize 00798 hist -> Scale(1.0/hist->Integral("width")); 00799 00800 return hist; 00801 }
TH1D * BCIntegrate::MarginalizeByMetro | ( | BCParameter * | parameter | ) |
Performs the marginalization with respect to one parameter using the Metropolis algorithm.
parameter | The parameter w.r.t. which the marginalization is performed |
Definition at line 731 of file BCIntegrate.cxx.
00732 { 00733 int niter = fMarkovChainNIterations; 00734 00735 if (fMarkovChainAutoN == true) 00736 niter = fNbins*fNbins*fNSamplesPer2DBin*fNvar; 00737 00738 BCLog::Out(BCLog::detail, BCLog::detail, 00739 Form(" --> Number of samples in Metropolis marginalization: %d.", niter)); 00740 00741 // set parameter to marginalize 00742 int index = parameter->GetIndex(); 00743 00744 // define histogram 00745 double hmin = parameter -> GetLowerLimit(); 00746 double hmax = parameter -> GetUpperLimit(); 00747 TH1D * hist = new TH1D("hist","", fNbins, hmin, hmax); 00748 00749 // prepare Metro 00750 std::vector <double> randx; 00751 randx.assign(fNvar, 0.0); 00752 InitMetro(); 00753 00754 for(int i=0;i<=niter;i++) 00755 { 00756 GetRandomPointMetro(randx); 00757 hist->Fill(randx[index]); 00758 } 00759 00760 // normalize 00761 hist -> Scale(1.0/hist->Integral("width")); 00762 00763 return hist; 00764 }
void BCIntegrate::MCMCFillErrorBand | ( | ) | [private] |
Definition at line 1637 of file BCIntegrate.cxx.
01638 { 01639 if (!fFillErrorBand) 01640 return; 01641 01642 // function fitting 01643 if (fFitFunctionIndexX < 0) 01644 return; 01645 01646 // loop over all possible x values ... 01647 if (fErrorBandContinuous) 01648 { 01649 double x = 0; 01650 for (int ix = 0; ix < fErrorBandNbinsX; ix++) 01651 { 01652 // calculate x 01653 x = fErrorBandXY -> GetXaxis() -> GetBinCenter(ix + 1); 01654 01655 // calculate y 01656 std::vector <double> xvec; 01657 xvec.push_back(x); 01658 01659 // loop over all chains 01660 for (int ichain = 0; ichain < this -> MCMCGetNChains(); ++ichain) 01661 { 01662 // calculate y 01663 double y = this -> FitFunction(xvec, this -> MCMCGetx(ichain)); 01664 01665 // fill histogram 01666 fErrorBandXY -> Fill(x, y); 01667 } 01668 01669 xvec.clear(); 01670 } 01671 } 01672 // ... or evaluate at the data point x-values 01673 else 01674 { 01675 int ndatapoints = int(fErrorBandX.size()); 01676 double x = 0; 01677 01678 for (int ix = 0; ix < ndatapoints; ++ix) 01679 { 01680 // calculate x 01681 x = fErrorBandX.at(ix); 01682 01683 // calculate y 01684 std::vector <double> xvec; 01685 xvec.push_back(x); 01686 01687 // loop over all chains 01688 for (int ichain = 0; ichain < this -> MCMCGetNChains(); ++ichain) 01689 { 01690 // calculate y 01691 double y = this -> FitFunction(xvec, this -> MCMCGetx(ichain)); 01692 01693 // fill histogram 01694 fErrorBandXY -> Fill(x, y); 01695 } 01696 01697 xvec.clear(); 01698 } 01699 } 01700 }
void BCIntegrate::MCMCIterationInterface | ( | ) | [private, virtual] |
Reimplemented from BCEngineMCMC.
Definition at line 1624 of file BCIntegrate.cxx.
01625 { 01626 // what's within this method will be executed 01627 // for every iteration of the MCMC 01628 01629 // fill error band 01630 this -> MCMCFillErrorBand(); 01631 01632 // do user defined stuff 01633 this -> MCMCUserIterationInterface(); 01634 }
virtual void BCIntegrate::MCMCUserIterationInterface | ( | ) | [inline, virtual] |
void BCIntegrate::ResetVarlist | ( | int | v | ) |
Sets all values of the variable list to a particular value The value
Definition at line 286 of file BCIntegrate.cxx.
void BCIntegrate::SetDataPointLowerBoundaries | ( | BCDataPoint * | datasetlowerboundaries | ) | [inline] |
Sets the data point containing the lower boundaries of possible data values
Definition at line 306 of file BCIntegrate.h.
00307 { fDataPointLowerBoundaries = datasetlowerboundaries; };
void BCIntegrate::SetDataPointLowerBoundary | ( | int | index, | |
double | lowerboundary | |||
) | [inline] |
Sets the lower boundary of possible data values for a particular variable
Definition at line 318 of file BCIntegrate.h.
00319 { fDataPointLowerBoundaries -> SetValue(index, lowerboundary); };
void BCIntegrate::SetDataPointUpperBoundaries | ( | BCDataPoint * | datasetupperboundaries | ) | [inline] |
Sets the data point containing the upper boundaries of possible data values
Definition at line 312 of file BCIntegrate.h.
00313 { fDataPointUpperBoundaries = datasetupperboundaries; };
void BCIntegrate::SetDataPointUpperBoundary | ( | int | index, | |
double | upperboundary | |||
) | [inline] |
Sets the upper boundary of possible data values for a particular variable
Definition at line 324 of file BCIntegrate.h.
00325 { fDataPointUpperBoundaries -> SetValue(index, upperboundary); };
void BCIntegrate::SetErrorBandHisto | ( | TH2D * | h | ) | [inline] |
void BCIntegrate::SetFillErrorBand | ( | bool | flag = true |
) | [inline] |
void BCIntegrate::SetFitFunctionIndexX | ( | int | index | ) | [inline] |
Sets index of the x values in function fits.
index | Index of the x values |
Definition at line 290 of file BCIntegrate.h.
00291 { fFitFunctionIndexX = index; };
void BCIntegrate::SetFitFunctionIndexY | ( | int | index | ) | [inline] |
Sets index of the y values in function fits.
index | Index of the y values |
Definition at line 296 of file BCIntegrate.h.
00297 { fFitFunctionIndexY = index; };
void BCIntegrate::SetFitFunctionIndices | ( | int | indexx, | |
int | indexy | |||
) | [inline] |
Definition at line 299 of file BCIntegrate.h.
00300 { this -> SetFitFunctionIndexX(indexx); 00301 this -> SetFitFunctionIndexY(indexy); };
void BCIntegrate::SetIntegrationMethod | ( | BCIntegrate::BCIntegrationMethod | method | ) |
method | The integration method |
Definition at line 330 of file BCIntegrate.cxx.
00331 { 00332 #ifdef HAVE_CUBA_H 00333 fIntegrationMethod = method; 00334 #else 00335 BCLog::Out(BCLog::warning,BCLog::warning,"!!! This version of BAT is compiled without Cuba."); 00336 BCLog::Out(BCLog::warning,BCLog::warning," Monte Carlo Sampled Mean integration method will be used."); 00337 BCLog::Out(BCLog::warning,BCLog::warning," To be able to use Cuba integration, install Cuba and recompile BAT."); 00338 #endif 00339 }
void BCIntegrate::SetMarginalizationMethod | ( | BCIntegrate::BCMarginalizationMethod | method | ) | [inline] |
method | The marginalization method |
Definition at line 230 of file BCIntegrate.h.
00231 { fMarginalizationMethod = method; };
void BCIntegrate::SetMarkovChainAutoN | ( | bool | flag | ) | [inline] |
Sets a flag for automatically calculating the number of iterations
Definition at line 355 of file BCIntegrate.h.
00356 { fMarkovChainAutoN = flag; };
void BCIntegrate::SetMarkovChainInitialPosition | ( | std::vector< double > | position | ) |
Sets the initial position for the Markov chain
Definition at line 183 of file BCIntegrate.cxx.
00184 { 00185 int n = position.size(); 00186 00187 fXmetro0.clear(); 00188 00189 for (int i = 0; i < n; ++i) 00190 fXmetro0.push_back(position.at(i)); 00191 }
void BCIntegrate::SetMarkovChainNIterations | ( | int | niterations | ) | [inline] |
Sets the number of iterations in the markov chain
Definition at line 349 of file BCIntegrate.h.
00350 { fMarkovChainNIterations = niterations; 00351 fMarkovChainAutoN = false; }
void BCIntegrate::SetMarkovChainStepSize | ( | double | stepsize | ) | [inline] |
Sets the step size for Markov chains
Definition at line 344 of file BCIntegrate.h.
00345 { fMarkovChainStepSize = stepsize; };
void BCIntegrate::SetMarkovChainTree | ( | TTree * | tree | ) | [inline] |
Sets the ROOT tree containing the Markov chain
Definition at line 335 of file BCIntegrate.h.
00336 { fMarkovChainTree = tree; };
void BCIntegrate::SetMinuitArlist | ( | double * | arglist | ) | [inline] |
Definition at line 207 of file BCIntegrate.h.
00208 { fMinuitArglist[0] = arglist[0]; 00209 fMinuitArglist[1] = arglist[1]; };
void BCIntegrate::SetMode | ( | std::vector< double > | mode | ) |
Sets mode
Definition at line 1379 of file BCIntegrate.cxx.
01380 { 01381 if((int)mode.size() == fNvar) 01382 { 01383 fBestFitParameters.clear(); 01384 for (int i = 0; i < fNvar; i++) 01385 fBestFitParameters.push_back(mode[i]); 01386 } 01387 }
void BCIntegrate::SetNbins | ( | int | nbins, | |
int | index = -1 | |||
) |
n | Number of bins per dimension for the marginalized distributions. Default is 100. Minimum number allowed is 2. Set the number of bins for the marginalized distribution of a parameter. | |
nbins | Number of bins (default = 100) | |
index | Index of the parameter. |
Definition at line 213 of file BCIntegrate.cxx.
00214 { 00215 if (fNvar == 0) 00216 return; 00217 00218 // check if index is in range 00219 if (index >= fNvar) 00220 { 00221 BCLog::Out(BCLog::warning, BCLog::warning,"BCIntegrate::SetNbins : Index out of range."); 00222 return; 00223 } 00224 // set for all parameters at once 00225 else if (index < 0) 00226 { 00227 for (int i = 0; i < fNvar; ++i) 00228 this -> SetNbins(nbins, i); 00229 return; 00230 } 00231 00232 // sanity check for nbins 00233 if (nbins <= 0) 00234 nbins = 10; 00235 00236 fMCMCH1NBins[index] = nbins; 00237 00238 return; 00239 00240 // if(n<2) 00241 // { 00242 // BCLog::Out(BCLog::warning, BCLog::warning,"BCIntegrate::SetNbins. Number of bins less than 2 makes no sense. Setting to 2."); 00243 // n=2; 00244 // } 00245 // this -> MCMCSetH1NBins(n, -1); 00246 00247 // fNbins=n; 00248 00249 // fMCMCH1NBins = n; 00250 // fMCMCH2NBinsX = n; 00251 // fMCMCH2NBinsY = n; 00252 }
void BCIntegrate::SetNIterationsMax | ( | int | niterations | ) | [inline] |
niterations | The maximum number of iterations for Monte Carlo integration |
Definition at line 251 of file BCIntegrate.h.
00252 { fNIterationsMax = niterations; };
void BCIntegrate::SetNiterationsPerDimension | ( | int | niterations | ) | [inline] |
niterations | Number of iterations per dimension for Monte Carlo integration. |
Definition at line 240 of file BCIntegrate.h.
00241 { fNiterPerDimension = niterations; };
void BCIntegrate::SetNSamplesPer2DBin | ( | int | n | ) | [inline] |
n | Number of samples per 2D bin per variable in the Metropolis marginalization. Default is 100. |
Definition at line 246 of file BCIntegrate.h.
00247 { fNSamplesPer2DBin = n; };
void BCIntegrate::SetOptimizationMethod | ( | BCIntegrate::BCOptimizationMethod | method | ) | [inline] |
method | The mode finding method |
Definition at line 235 of file BCIntegrate.h.
00236 { fOptimizationMethod = method; };
void BCIntegrate::SetParameters | ( | BCParameterSet * | par | ) |
par | The parameter set which gets translated into array needed for the Monte Carlo integration |
Definition at line 142 of file BCIntegrate.cxx.
00143 { 00144 DeleteVarList(); 00145 00146 fx = par; 00147 fNvar = fx->size(); 00148 fMin = new double[fNvar]; 00149 fMax = new double[fNvar]; 00150 fVarlist = new int[fNvar]; 00151 00152 this->ResetVarlist(1); 00153 00154 for(int i=0;i<fNvar;i++) 00155 { 00156 fMin[i]=(fx->at(i))->GetLowerLimit(); 00157 fMax[i]=(fx->at(i))->GetUpperLimit(); 00158 } 00159 00160 fXmetro0.clear(); 00161 for(int i=0;i<fNvar;i++) 00162 fXmetro0.push_back((fMin[i]+fMax[i])/2.0); 00163 00164 fXmetro1.clear(); 00165 fXmetro1.assign(fNvar,0.); 00166 00167 fMCMCBoundaryMin.clear(); 00168 fMCMCBoundaryMax.clear(); 00169 00170 for(int i=0;i<fNvar;i++) 00171 { 00172 fMCMCBoundaryMin.push_back(fMin[i]); 00173 fMCMCBoundaryMax.push_back(fMax[i]); 00174 } 00175 00176 for (int i = int(fMCMCH1NBins.size()); i<fNvar; ++i) 00177 fMCMCH1NBins.push_back(100); 00178 00179 fMCMCNParameters = fNvar; 00180 }
void BCIntegrate::SetRelativePrecision | ( | double | relprecision | ) | [inline] |
relprecision | The relative precision envisioned for Monte Carlo integration |
Definition at line 257 of file BCIntegrate.h.
00258 { fRelativePrecision = relprecision; };
void BCIntegrate::SetVar | ( | int | index | ) | [inline] |
index | The index of the variable to be set |
Definition at line 222 of file BCIntegrate.h.
00222 {fVarlist[index]=1;};
void BCIntegrate::SetVarList | ( | int * | varlist | ) |
void BCIntegrate::UnsetFillErrorBand | ( | ) | [inline] |
void BCIntegrate::UnsetVar | ( | int | index | ) | [inline] |
Set value of a particular integration variable to 0.
index | The index of the variable |
Definition at line 384 of file BCIntegrate.h.
00385 { fVarlist[index] = 0; };
void BCIntegrate::WriteMarkovChain | ( | bool | flag | ) | [inline] |
Flag for writing Markov chain to ROOT file (true) or not (false)
Definition at line 330 of file BCIntegrate.h.
00331 { fFlagWriteMarkovChain = flag; fMCMCFlagWriteChainToFile = flag;};
std::vector<double> BCIntegrate::fBestFitParameters [protected] |
A vector of best fit parameters estimated from the global probability
Definition at line 689 of file BCIntegrate.h.
std::vector<double> BCIntegrate::fBestFitParametersMarginalized [protected] |
A vector of best fit parameters estimated from the marginalized probability
Definition at line 693 of file BCIntegrate.h.
std::vector<bool> BCIntegrate::fDataFixedValues [protected] |
Definition at line 681 of file BCIntegrate.h.
BCDataPoint* BCIntegrate::fDataPointLowerBoundaries [protected] |
data point containing the lower boundaries of possible data values
Definition at line 675 of file BCIntegrate.h.
BCDataPoint* BCIntegrate::fDataPointUpperBoundaries [protected] |
data point containing the upper boundaries of possible data values
Definition at line 679 of file BCIntegrate.h.
double BCIntegrate::fError [private] |
The uncertainty in the most recent Monte Carlo integration
Definition at line 623 of file BCIntegrate.h.
bool BCIntegrate::fErrorBandContinuous [protected] |
A flag for single point evaluation of the error "band"
Definition at line 714 of file BCIntegrate.h.
int BCIntegrate::fErrorBandNbinsX [protected] |
Nnumber of X bins of the error band histogram
Definition at line 723 of file BCIntegrate.h.
int BCIntegrate::fErrorBandNbinsY [protected] |
Nnumber of Y bins of the error band histogram
Definition at line 727 of file BCIntegrate.h.
std::vector<double> BCIntegrate::fErrorBandX [protected] |
Definition at line 715 of file BCIntegrate.h.
TH2D* BCIntegrate::fErrorBandXY [protected] |
The error band histogram
Definition at line 719 of file BCIntegrate.h.
bool BCIntegrate::fFillErrorBand [protected] |
Flag whether or not to fill the error band
Definition at line 705 of file BCIntegrate.h.
int BCIntegrate::fFitFunctionIndexX [protected] |
The indeces for function fits
Definition at line 709 of file BCIntegrate.h.
int BCIntegrate::fFitFunctionIndexY [protected] |
Definition at line 710 of file BCIntegrate.h.
bool BCIntegrate::fFlagWriteMarkovChain [protected] |
Flag for writing Markov chain to file
Definition at line 738 of file BCIntegrate.h.
std::vector<TH1D *> BCIntegrate::fHProb1D [protected] |
Vector of TH1D histograms for marginalized probability distributions
Definition at line 697 of file BCIntegrate.h.
std::vector<TH2D *> BCIntegrate::fHProb2D [protected] |
Vector of TH2D histograms for marginalized probability distributions
Definition at line 701 of file BCIntegrate.h.
Current integration method
Definition at line 599 of file BCIntegrate.h.
Current marginalization method
Definition at line 603 of file BCIntegrate.h.
bool BCIntegrate::fMarkovChainAutoN [protected] |
Definition at line 671 of file BCIntegrate.h.
int BCIntegrate::fMarkovChainNIterations [protected] |
Definition at line 669 of file BCIntegrate.h.
double BCIntegrate::fMarkovChainStepSize [protected] |
Step size in the Markov chain relative to min and max
Definition at line 667 of file BCIntegrate.h.
TTree* BCIntegrate::fMarkovChainTree [protected] |
ROOT tree containing the Markov chain
Definition at line 742 of file BCIntegrate.h.
double BCIntegrate::fMarkovChainValue [private] |
A double containing the log likelihood value at the point fXmetro1
Definition at line 640 of file BCIntegrate.h.
double* BCIntegrate::fMax [private] |
Array containing the upper boundaries of the variables to integrate over.
Definition at line 587 of file BCIntegrate.h.
int BCIntegrate::fMCMCIteration [protected] |
Iteration of the MCMC
Definition at line 746 of file BCIntegrate.h.
double* BCIntegrate::fMin [private] |
Array containing the lower boundaries of the variables to integrate over.
Definition at line 583 of file BCIntegrate.h.
TMinuit* BCIntegrate::fMinuit [protected] |
Minuit
Definition at line 731 of file BCIntegrate.h.
double BCIntegrate::fMinuitArglist[2] [protected] |
Definition at line 733 of file BCIntegrate.h.
int BCIntegrate::fMinuitErrorFlag [protected] |
Definition at line 734 of file BCIntegrate.h.
int BCIntegrate::fNacceptedMCMC [private] |
Definition at line 628 of file BCIntegrate.h.
int BCIntegrate::fNbins [protected] |
Number of bins per dimension for the marginalized distributions
Definition at line 658 of file BCIntegrate.h.
int BCIntegrate::fNIterations [private] |
Number of iterations in the most recent Monte Carlo integation
Definition at line 615 of file BCIntegrate.h.
int BCIntegrate::fNIterationsMax [private] |
Maximum number of iterations
Definition at line 611 of file BCIntegrate.h.
int BCIntegrate::fNiterPerDimension [private] |
Number of iteration per dimension for Monte Carlo integration.
Definition at line 595 of file BCIntegrate.h.
int BCIntegrate::fNmetro [private] |
The number of iterations in the Metropolis integration
Definition at line 627 of file BCIntegrate.h.
int BCIntegrate::fNSamplesPer2DBin [protected] |
Number of samples per 2D bin per variable in the Metropolis marginalization.
Definition at line 663 of file BCIntegrate.h.
int BCIntegrate::fNvar [protected] |
Number of variables to integrate over.
Definition at line 654 of file BCIntegrate.h.
Current mode finding method
Definition at line 607 of file BCIntegrate.h.
TRandom3* BCIntegrate::fRandom [protected] |
A ROOT random number generator
Definition at line 685 of file BCIntegrate.h.
double BCIntegrate::fRelativePrecision [private] |
Relative precision aimed at in the Monte Carlo integation
Definition at line 619 of file BCIntegrate.h.
int* BCIntegrate::fVarlist [private] |
List of variables containing a flag whether to integrate over them or not.
Definition at line 591 of file BCIntegrate.h.
BCParameterSet* BCIntegrate::fx [private] |
Set of parameters for the integration.
Definition at line 571 of file BCIntegrate.h.
std::vector<double> BCIntegrate::fXmetro0 [private] |
A vector of points in parameter space used for the Metropolis algorithm
Definition at line 632 of file BCIntegrate.h.
std::vector<double> BCIntegrate::fXmetro1 [private] |
A vector of points in parameter space used for the Metropolis algorithm
Definition at line 636 of file BCIntegrate.h.