ex-4: fit plot added
This commit is contained in:
parent
2864d9e524
commit
9641c0a39b
41
ex-4/main.c
41
ex-4/main.c
@ -9,13 +9,14 @@
|
|||||||
|
|
||||||
// Process CLI arguments.
|
// Process CLI arguments.
|
||||||
//
|
//
|
||||||
int parser(size_t *N, size_t *n, double *p_max, char argc, char **argv)
|
int parser(size_t *N, size_t *n, double *p_max, char argc, char **argv, size_t *go)
|
||||||
{
|
{
|
||||||
for (size_t i = 1; i < argc; i++)
|
for (size_t i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (!strcmp(argv[i], "-n")) *N = atol(argv[++i]);
|
if (!strcmp(argv[i], "-n")) *N = atol(argv[++i]);
|
||||||
else if (!strcmp(argv[i], "-b")) *n = atol(argv[++i]);
|
else if (!strcmp(argv[i], "-b")) *n = atol(argv[++i]);
|
||||||
else if (!strcmp(argv[i], "-p")) *p_max = atof(argv[++i]);
|
else if (!strcmp(argv[i], "-p")) *p_max = atof(argv[++i]);
|
||||||
|
else if (!strcmp(argv[i], "-o")) *go = 1;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s -[hnbp]\n", argv[0]);
|
fprintf(stderr, "Usage: %s -[hnbp]\n", argv[0]);
|
||||||
@ -23,6 +24,7 @@ int parser(size_t *N, size_t *n, double *p_max, char argc, char **argv)
|
|||||||
fprintf(stderr, "\t-n N\tThe number of events to generate. (default: 50000)\n");
|
fprintf(stderr, "\t-n N\tThe number of events to generate. (default: 50000)\n");
|
||||||
fprintf(stderr, "\t-b N\tThe number of bins of the histogram. (default: 50)\n");
|
fprintf(stderr, "\t-b N\tThe number of bins of the histogram. (default: 50)\n");
|
||||||
fprintf(stderr, "\t-p PMAX\tThe maximum value of momentum. (default: 10)\n");
|
fprintf(stderr, "\t-p PMAX\tThe maximum value of momentum. (default: 10)\n");
|
||||||
|
fprintf(stderr, "\t-o \tPrint histogram to stdout.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,18 +37,19 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
// Set default options.
|
// Set default options.
|
||||||
//
|
//
|
||||||
size_t N = 50000; // number of events.
|
size_t N = 50000;
|
||||||
size_t n = 50; // number of bins.
|
size_t n = 50;
|
||||||
double p_max = 10; // maximum value of momentum module.
|
double p_max = 10;
|
||||||
int res = parser(&N, &n, &p_max, argc, argv);
|
size_t go = 0;
|
||||||
if (res == 1)
|
int res = parser(&N, &n, &p_max, argc, argv, &go);
|
||||||
|
if (go == 0)
|
||||||
{
|
{
|
||||||
printf("\nGenerating histogram with:\n"
|
printf("\nGenerating histogram with:\n"
|
||||||
"%ld points\n"
|
"%ld points\n"
|
||||||
"%ld bins\n"
|
"%ld bins\n"
|
||||||
"p_max = %.3f\n\n", N, n, p_max);
|
"p_max = %.3f\n\n", N, n, p_max);
|
||||||
}
|
}
|
||||||
else return EXIT_FAILURE;
|
else if (res == 0) return EXIT_FAILURE;
|
||||||
|
|
||||||
// printf("step: \t%.5f\n", step);
|
// printf("step: \t%.5f\n", step);
|
||||||
|
|
||||||
@ -116,12 +119,15 @@ int main(int argc, char **argv)
|
|||||||
// Compute the mean value of each bin and print it to stodut
|
// Compute the mean value of each bin and print it to stodut
|
||||||
// together with other useful things to make the histogram.
|
// together with other useful things to make the histogram.
|
||||||
//
|
//
|
||||||
// printf("bins: \t%ld\n", n);
|
if (go == 1)
|
||||||
// printf("step: \t%.5f\n", step);
|
{
|
||||||
|
printf("bins: \t%ld\n", n);
|
||||||
|
printf("step: \t%.5f\n", step);
|
||||||
|
}
|
||||||
for (size_t i = 0; i < n; i++)
|
for (size_t i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
histo[i].sum = histo[i].sum / histo[i].amo; // Average P_v
|
histo[i].sum = histo[i].sum / histo[i].amo; // Average P_v
|
||||||
//printf("\n%.5f", histo[i].sum);
|
if (go == 1) printf("\n%.5f", histo[i].sum);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Compare the histigram with the expected function:
|
// Compare the histigram with the expected function:
|
||||||
@ -165,9 +171,12 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
double result = x;
|
double result = x;
|
||||||
double res_chi = chi2(result, ¶ms);
|
double res_chi = chi2(result, ¶ms);
|
||||||
|
if (go == 0)
|
||||||
|
{
|
||||||
printf("Results:\n");
|
printf("Results:\n");
|
||||||
printf("χ² = %.3f\n", res_chi);
|
printf("χ² = %.3f\n", res_chi);
|
||||||
printf("p_max = %.3f\n", result);
|
printf("p_max = %.3f\n", result);
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the second derivative of χ² in its minimum for the result error.
|
// Compute the second derivative of χ² in its minimum for the result error.
|
||||||
//
|
//
|
||||||
@ -196,8 +205,18 @@ int main(int argc, char **argv)
|
|||||||
error = error + A + B;
|
error = error + A + B;
|
||||||
};
|
};
|
||||||
error = 1/error;
|
error = 1/error;
|
||||||
printf("ΔP_max = %.3f\n\n", error);
|
if (go == 0) printf("ΔP_max = %.3f\n", error);
|
||||||
|
|
||||||
|
// Check compatibility
|
||||||
|
//
|
||||||
|
double t = fabs(result - p_max)/error;
|
||||||
|
double alpha = 1 - erf(t/sqrt(2));
|
||||||
|
if (go == 0)
|
||||||
|
{
|
||||||
|
printf("\nCompatibility:\n");
|
||||||
|
printf("t = %.3f\n", t);
|
||||||
|
printf("α = %.3f\n\n", alpha);
|
||||||
|
}
|
||||||
|
|
||||||
// Free memory.
|
// Free memory.
|
||||||
//
|
//
|
||||||
|
@ -12,7 +12,6 @@ def main():
|
|||||||
y = f(x)
|
y = f(x)
|
||||||
|
|
||||||
plt.rcParams['font.size'] = 20
|
plt.rcParams['font.size'] = 20
|
||||||
plt.figure()
|
|
||||||
plt.title('Expected distribution', loc='right')
|
plt.title('Expected distribution', loc='right')
|
||||||
plt.ylabel('$\\langle |P_v| \\rangle$')
|
plt.ylabel('$\\langle |P_v| \\rangle$')
|
||||||
plt.xlabel('$P_h$')
|
plt.xlabel('$P_h$')
|
||||||
|
BIN
notes/images/fit.pdf
Normal file
BIN
notes/images/fit.pdf
Normal file
Binary file not shown.
@ -247,8 +247,11 @@ where $\Delta p_{\text{max}}$ is the absolute error of $p_{\text{max}}$. At 95%
|
|||||||
confidence level, the values are compatible if $p > 0.05$.
|
confidence level, the values are compatible if $p > 0.05$.
|
||||||
In this case:
|
In this case:
|
||||||
|
|
||||||
- t = 0.278
|
- t = 0.295
|
||||||
- p = 0.781
|
- p = 0.768
|
||||||
|
|
||||||
which allows to assert that the sampled points actually follow the predicted
|
which allows to assert that the sampled points actually follow the predicted
|
||||||
distribution.
|
distribution. In @fig:fit, the fit function superimposed on the histogram is
|
||||||
|
shown.
|
||||||
|
|
||||||
|
![Fitted data.](images/fit.pdf){#fig:fit}
|
||||||
|
Loading…
Reference in New Issue
Block a user