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);
48 const double f1 = fs + fb;
50 const double p = PoissonI(point.getY(), f1);
52 result.chi2 = -log(p);
54 result.gradient.mean = fs * u / gauss.
sigma;
55 result.gradient.sigma = fs * u*u / gauss.
sigma - fs / gauss.
sigma;
56 result.gradient.signal = fs / gauss.
signal;
57 result.gradient.background = 1.0;
59 result.gradient *= 1.0 - point.getY()/f1;
72 int 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;
120 TH1D
H[] = { TH1D(
"ha",
"", 101, -0.1, +0.1),
121 TH1D(
"hb",
"", 101, -0.1, +0.1),
122 TH1D(
"hc",
"", 101, -100.0, +100.0),
123 TH1D(
"hd",
"", 101, -100.0, +100.0) };
127 for (
int i = 0; i != numberOfEvents; ++i) {
129 STATUS(
"event: " << setw(10) << i <<
'\r');
DEBUG(endl);
131 TH1D h0(
"h0", NULL, nx, xmin, xmax);
135 h0.FillRandom(
"fs", (Int_t) gauss.
signal);
136 h0.FillRandom(
"fb", (Int_t) gauss.
background);
140 for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
141 data.push_back(JElement_t(h0.GetBinCenter (i),
142 h0.GetBinContent(i)));
147 fit.parameters.resize(4);
149 fit.parameters[0] = &JGauss::mean;
150 fit.parameters[1] = &JGauss::sigma;
151 fit.parameters[2] = &JGauss::signal;
152 fit.parameters[3] = &JGauss::background;
154 fit.value =
JGauss(h0.GetMean(),
156 h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
159 DEBUG(
"Start value " << fit.value << endl);
163 const double chi2 = fit(
g1, data.begin(), data.end());
167 DEBUG(
"Final value " << fit.value << endl);
168 DEBUG(
"Chi2 " << chi2 << endl);
170 const double Y[] = { fit.value.mean - gauss.
mean,
171 fit.value.sigma - gauss.
sigma,
172 fit.value.signal * nx / (xmax - xmin) - gauss.
signal,
173 fit.value.background * nx - gauss.
background };
175 for (
int i = 0; i !=
sizeof(
Q)/
sizeof(
Q[0]); ++i) {
181 for (
int i = 0; i !=
sizeof(
Q)/
sizeof(
Q[0]); ++i) {
186 timer.print(cout,
true,
micro_t);
193 for (
int i = 0; i !=
sizeof(
H)/
sizeof(
H[0]); ++i) {
201 for (
int i = 0; i !=
sizeof(
Q)/
sizeof(
Q[0]); ++i) {
205 ASSERT(
Q[0].getSTDev() < precision.mean);
206 ASSERT(
Q[1].getSTDev() < precision.sigma);
207 ASSERT(
Q[2].getSTDev() < precision.signal);
208 ASSERT(
Q[3].getSTDev() < precision.background);
Utility class to parse command line options.
Q(UTCMax_s-UTCMin_s)-livetime_s
int main(int argc, char *argv[])
The elements in a collection are sorted according to their abscissa values and a given distance opera...
static const double H
Planck constant [eV s].
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
double getMean(vector< double > &v)
get mean of vector content
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable STRING $argv[2] set_array QUANTILES set_variable FORMULA *[0] exp(-0.5 *(x-[1])*(x-[1])/([2]*[2]))" set_variable MODULE `getModule -a $DETECTOR -L "$STRING 0"` typeset -Z 4 STRING JOpera1D -f hydrophone.root
#define ASSERT(A,...)
Assert macro.
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Auxiliary class for CPU timing and usage.
static const double PI
Mathematical constants.
std::ostream & shortprint(std::ostream &out)
Set short printing.
General purpose messaging.
std::ostream & longprint(std::ostream &out)
Set long printing.
Utility class to parse command line options.
Data structure for return value of fit function.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
double gauss(const double x, const double sigma)
Gauss function (normalised to 1 at x = 0).
Double_t g1(const Double_t x)
Function.