110{
113
115 int numberOfEvents;
119
120 try {
121
122 JParser<> zap(
"Program to test JGandalf algorithm.");
123
129
130 zap(argc, argv);
131 }
132 catch(const exception& error) {
133 FATAL(error.what() << endl);
134 }
135
136
137 ASSERT(numberOfEvents > 0);
138
140
141 TF1 fs("fs", "exp(-0.5 * (x-[0])*(x-[0]) / ([1]*[1]))");
142 TF1 fb("fb", "1.0");
143
144 fs.FixParameter(0,
gauss[0]);
145 fs.FixParameter(1,
gauss[1]);
146
147 const Int_t nx = 21;
148 const Double_t xmin = -5.0;
149 const Double_t xmax = +5.0;
150
156 };
157
159 TH1D("ha", "", 101, -0.1, +0.1),
160 TH1D("hb", "", 101, -0.1, +0.1),
161 TH1D("hc", "", 101, -100.0, +100.0),
162 TH1D("hd", "", 101, -100.0, +100.0)
163 };
164
166
167 for (int i = 0; i != numberOfEvents; ++i) {
168
169 STATUS(
"event: " << setw(10) << i <<
'\r');
DEBUG(endl);
170
171 TH1D h0("h0", NULL, nx, xmin, xmax);
172
173 h0.Sumw2();
174
175 h0.FillRandom(
"fs", (Int_t)
gauss[2]);
176 h0.FillRandom(
"fb", (Int_t)
gauss[3]);
177
179
180 for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
181 data.push_back(JElement_t(h0.GetBinCenter (i),
182 h0.GetBinContent(i)));
183 }
184
186
187 fit.parameters.resize(4);
188
189 for (size_t i = 0; i != 4; ++i) {
190 fit.parameters[i] = i;
191 }
192
193 fit.value =
JGauss(h0.GetMean(),
194 h0.GetRMS(),
195 h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
196 h0.GetMinimum());
197
198 DEBUG(
"Start value " << fit.value << endl);
199
201
202 const double chi2 = fit(
g1,
data.begin(),
data.end());
203
205
206 DEBUG(
"Final value " << fit.value << endl);
207 DEBUG(
"Chi2 " << chi2 << endl);
208
209 const double Y[] = { fit.value[0] -
gauss[0],
210 fit.value[1] -
gauss[1],
211 fit.value[2] * nx / (xmax - xmin) -
gauss[2],
212 fit.value[3] * nx -
gauss[3] };
213
214 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
217 }
218 }
219
220 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
222 }
223
226 }
227
229
231
232 for (
int i = 0; i !=
sizeof(
H)/
sizeof(
H[0]); ++i) {
234 }
235
236 out.Write();
237 out.Close();
238 }
239
240 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
242 }
243
244 ASSERT(Q[0].getSTDev() < precision[0]);
245 ASSERT(Q[1].getSTDev() < precision[1]);
246 ASSERT(Q[2].getSTDev() < precision[2]);
247 ASSERT(Q[3].getSTDev() < precision[3]);
248
249 return 0;
250}
double getMean(vector< double > &v)
get mean of vector content
std::ostream & longprint(std::ostream &out)
Set long printing.
std::ostream & shortprint(std::ostream &out)
Set short printing.
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
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.
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).