29 using TMath::PoissonI;
41 inline result_type
g1(
const JGauss&
gauss,
const JElement_t& point)
45 const double u = (point.getX() -
gauss.mean) /
gauss.sigma;
46 const double fs =
gauss.signal * exp(-0.5*u*u) / (sqrt(2.0*PI) *
gauss.sigma);
47 const double fb =
gauss.background;
48 const double f1 = fs + fb;
50 const double p = PoissonI(point.getY(), f1);
57 result.gradient.background = 1.0;
59 result.gradient *= 1.0 - point.getY()/f1;
72int main(
int argc,
char **argv)
85 JParser<> zap(
"Program to test JGandalf algorithm.");
95 catch(
const exception& error) {
96 FATAL(error.what() << endl);
101 ASSERT(numberOfEvents > 0);
105 TF1 fs(
"fs",
"exp(-0.5 * (x-[0])*(x-[0]) / ([1]*[1]))");
108 fs.FixParameter(0,
gauss.mean);
109 fs.FixParameter(1,
gauss.sigma);
112 const Double_t xmin = -5.0;
113 const Double_t xmax = +5.0;
123 TH1D(
"ha",
"", 101, -0.1, +0.1),
124 TH1D(
"hb",
"", 101, -0.1, +0.1),
125 TH1D(
"hc",
"", 101, -100.0, +100.0),
126 TH1D(
"hd",
"", 101, -100.0, +100.0)
131 for (
int i = 0; i != numberOfEvents; ++i) {
133 STATUS(
"event: " << setw(10) << i <<
'\r');
DEBUG(endl);
135 TH1D h0(
"h0", NULL, nx, xmin, xmax);
139 h0.FillRandom(
"fs", (Int_t)
gauss.signal);
140 h0.FillRandom(
"fb", (Int_t)
gauss.background);
144 for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
145 data.push_back(JElement_t(h0.GetBinCenter (i),
146 h0.GetBinContent(i)));
153 fit.parameters.resize(4);
155 fit.parameters[0] = &JGauss::mean;
156 fit.parameters[1] = &JGauss::sigma;
157 fit.parameters[2] = &JGauss::signal;
158 fit.parameters[3] = &JGauss::background;
160 fit.value =
JGauss(h0.GetMean(),
162 h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
165 DEBUG(
"Start value " << fit.value << endl);
169 const double chi2 = fit(
g1, data.begin(), data.end());
173 DEBUG(
"Final value " << fit.value << endl);
174 DEBUG(
"Chi2 " << chi2 << endl);
176 const double Y[] = { fit.value.mean -
gauss.mean,
177 fit.value.sigma -
gauss.sigma,
178 fit.value.signal * nx / (xmax - xmin) -
gauss.signal,
179 fit.value.background * nx -
gauss.background };
181 for (
int i = 0; i !=
sizeof(Q)/
sizeof(Q[0]); ++i) {
187 for (
int i = 0; i !=
sizeof(Q)/
sizeof(Q[0]); ++i) {
199 for (
int i = 0; i !=
sizeof(
H)/
sizeof(
H[0]); ++i) {
207 for (
int i = 0; i !=
sizeof(Q)/
sizeof(Q[0]); ++i) {
double getMean(vector< double > &v)
get mean of vector content
The elements in a collection are sorted according to their abscissa values and a given distance opera...
int main(int argc, char **argv)
std::ostream & longprint(std::ostream &out)
Set long printing.
std::ostream & shortprint(std::ostream &out)
Set short printing.
General purpose messaging.
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
I/O formatting auxiliaries.
Double_t g1(const Double_t x)
Function.
Place holder for custom implementation.
Auxiliary class for CPU timing and usage.
void print(std::ostream &out, const JScale_t scale=milli_t) const
Print timer data.
Utility class to parse command line options.
Auxiliary classes and methods for linear and iterative data regression.
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
static const double H
Planck constant [eV s].
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Data structure for return value of fit function.