Jpp
18.0.1-rc.2
the software that should make you happy
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JTools
JQuantile.cc
Go to the documentation of this file.
1
2
#include <string>
3
#include <iostream>
4
#include <iomanip>
5
#include <cmath>
6
7
#include "TRandom.h"
8
9
#include "
JTools/JQuantile.hh
"
10
11
#include "
Jeep/JParser.hh
"
12
#include "
Jeep/JMessage.hh
"
13
14
15
/**
16
* \file
17
*
18
* Example program to test JTOOLS::JQuantile calculation.
19
* \author mdejong
20
*/
21
int
main
(
int
argc,
char
**argv)
22
{
23
using namespace
std;
24
using namespace
JPP;
25
26
int
numberOfEvents;
27
double
x
;
28
double
sigma
;
29
UInt_t seed;
30
double
precision;
31
int
debug
;
32
33
try
{
34
35
JParser<>
zap(
"Example program to test quantile calculation."
);
36
37
zap[
'n'
] =
make_field
(numberOfEvents);
38
zap[
'x'
] =
make_field
(
x
) = 0.0;
39
zap[
's'
] =
make_field
(
sigma
) = 1.0;
40
zap[
'S'
] =
make_field
(seed) = 0;
41
zap[
'e'
] =
make_field
(precision) = 1.0e-2;
42
zap[
'd'
] =
make_field
(
debug
) = 3;
43
44
zap(argc, argv);
45
}
46
catch
(
const
exception &error) {
47
FATAL
(error.what() << endl);
48
}
49
50
if
(numberOfEvents < 2) {
51
FATAL
(
"Fatal error: number of events "
<< numberOfEvents << endl);
52
}
53
54
gRandom->SetSeed(seed);
55
56
{
57
JQuantile
Q
;
58
59
for
(
int
i
= 0;
i
!= numberOfEvents; ++
i
) {
60
Q.put(gRandom->Gaus(
x
,
sigma
));
61
}
62
63
NOTICE
(
"quantity "
<<
CENTER
(10) <<
"calculated"
<<
" | "
<<
CENTER
(10) <<
"true"
<< endl);
64
NOTICE
(
"mean "
<<
FIXED
(10,3) << Q.getMean() <<
" | "
<<
FIXED
(10,3) <<
x
<< endl);
65
NOTICE
(
"RMS "
<<
FIXED
(10,3) << Q.getSTDev() <<
" | "
<<
FIXED
(10,3) <<
sigma
<< endl);
66
67
ASSERT
(numberOfEvents > 0,
"Test number of events."
);
68
ASSERT
(fabs(Q.getMean() -
x
) <= precision,
"Test mean."
);
69
ASSERT
(fabs(Q.getSTDev() -
sigma
) <= precision,
"Test sigma."
);
70
}
71
{
72
JQuantile
Q
(
""
,
true
);
73
74
for
(
int
i
= 0;
i
!= numberOfEvents; ++
i
) {
75
Q.put(gRandom->Uniform(0.0, 1.0));
76
}
77
78
for
(
const
double
x
: { 0.1, 0.5, 0.9}) {
79
80
NOTICE
(
"forward quantile "
<<
FIXED
(6,3) <<
x
<<
' '
<<
FIXED
(6,3) << Q.getQuantile(
x
, JQuantile::forward_t) << endl);
81
NOTICE
(
"symmetric quantile "
<<
FIXED
(6,3) <<
x
<<
' '
<<
FIXED
(6,3) << Q.getQuantile(
x
, JQuantile::symmetric_t) << endl);
82
NOTICE
(
"backward quantile "
<<
FIXED
(6,3) <<
x
<<
' '
<<
FIXED
(6,3) << Q.getQuantile(
x
, JQuantile::backward_t) << endl);
83
84
ASSERT
(fabs(Q.getQuantile(
x
, JQuantile::forward_t) - (
x
)) <= precision,
"Test forward quantile "
);
85
ASSERT
(fabs(Q.getQuantile(
x
, JQuantile::symmetric_t) - (
x
)) <= precision,
"Test symmetric quantile "
);
86
ASSERT
(fabs(Q.getQuantile(
x
, JQuantile::backward_t) - (1.0 -
x
)) <= precision,
"Test backward quantile "
);
87
}
88
}
89
90
return
0;
91
}
92
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1514
i
then rm i
Definition:
JEvtReweightGSeaGenParameterScan.sh:337
Q
Q(UTCMax_s-UTCMin_s)-livetime_s
main
int main(int argc, char *argv[])
Definition:
Main.cc:15
FIXED
Auxiliary data structure for floating point format specification.
Definition:
JManip.hh:446
GAUSS_HERMITE::sigma
const double sigma[]
Definition:
JQuadrature.cc:74
CENTER
Auxiliary data structure for alignment of data.
Definition:
JManip.hh:366
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
makedeclinationtable.x
tuple x
Definition:
makedeclinationtable.py:44
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1989
NOTICE
#define NOTICE(A)
Definition:
JMessage.hh:64
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JQuantile.hh
debug
int debug
debug level
Definition:
archive-put-wiki-detectors.sh:92
Generated by
1.8.5