73{
76
78 int numberOfEvents;
82
83 try {
84
85 JParser<> zap(
"Program to test JGandalf algorithm.");
86
92
93 zap(argc, argv);
94 }
95 catch(const exception& error) {
96 FATAL(error.what() << endl);
97 }
98
99
100 ASSERT(numberOfEvents > 0);
101
103
104 TF1 fs("fs", "exp(-0.5 * (x-[0])*(x-[0]) / ([1]*[1]))");
105 TF1 fb("fb", "1.0");
106
107 fs.FixParameter(0,
gauss.mean);
108 fs.FixParameter(1,
gauss.sigma);
109
110 const Int_t nx = 21;
111 const Double_t xmin = -5.0;
112 const Double_t xmax = +5.0;
113
119 };
120
122 TH1D("ha", "", 101, -0.1, +0.1),
123 TH1D("hb", "", 101, -0.1, +0.1),
124 TH1D("hc", "", 101, -100.0, +100.0),
125 TH1D("hd", "", 101, -100.0, +100.0)
126 };
127
129
130 for (int i = 0; i != numberOfEvents; ++i) {
131
132 STATUS(
"event: " << setw(10) << i <<
'\r');
DEBUG(endl);
133
134 TH1D h0("h0", NULL, nx, xmin, xmax);
135
136 h0.Sumw2();
137
138 h0.FillRandom(
"fs", (Int_t)
gauss.signal);
139 h0.FillRandom(
"fb", (Int_t)
gauss.background);
140
142
143 for (Int_t i = 1; i <= h0.GetNbinsX(); ++i) {
144 data.push_back(JElement_t(h0.GetBinCenter (i),
145 h0.GetBinContent(i)));
146 }
147
149
151
152 fit.parameters.resize(4);
153
154 fit.parameters[0] = &JGauss::mean;
155 fit.parameters[1] = &JGauss::sigma;
156 fit.parameters[2] = &JGauss::signal;
157 fit.parameters[3] = &JGauss::background;
158
159 fit.value =
JGauss(h0.GetMean(),
160 h0.GetRMS(),
161 h0.GetEntries() * (xmax - xmin) / nx - h0.GetMinimum(),
162 h0.GetMinimum());
163
164 DEBUG(
"Start value " << fit.value << endl);
165
167
168 const double chi2 = fit(
g1,
data.begin(),
data.end());
169
171
172 DEBUG(
"Final value " << fit.value << endl);
173 DEBUG(
"Chi2 " << chi2 << endl);
174
175 const double Y[] = { fit.value.mean -
gauss.mean,
176 fit.value.sigma -
gauss.sigma,
177 fit.value.signal * nx / (xmax - xmin) -
gauss.signal,
178 fit.value.background * nx -
gauss.background };
179
180 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
183 }
184 }
185
186 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
188 }
189
192 }
193
195
197
198 for (
int i = 0; i !=
sizeof(
H)/
sizeof(
H[0]); ++i) {
200 }
201
202 out.Write();
203 out.Close();
204 }
205
206 for (int i = 0; i != sizeof(Q)/sizeof(Q[0]); ++i) {
208 }
209
214
215 return 0;
216}
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).