54 using Seed_t = std::default_random_engine::result_type;
96 inline constexpr T
sqr(T v) {
return v*v; }
103 bFixed(p.get<bool>(
"Fixed", false)),
104 bVerbose(p.get<bool>(
"Verbose", false)),
109 <<
" using " <<
samples <<
" samples per event, random seed " <<
seed;
117 std::uniform_real_distribution<float> flat(0.0, 1.0);
124 while (tries_left-- > 0) {
126 if (
sqr(x) +
sqr(
y) < 1.0) ++local_hits;
129 double local_pi = double(local_hits) / double(
samples) * 4.0;
135 << std::fixed << std::setprecision(9) << local_pi
137 << std::fixed << std::setprecision(12) <<
best_pi()
Counter_t tries
total number of tries (samples)
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::default_random_engine generator
random generator
Counter_t best_pi_tries() const
Returns the current best estimation of pi.
unsigned long long Counter_t
type used for integral counters
Counter_t hits
total number of hits
virtual ~ComputePi()=default
#define DEFINE_ART_MODULE(klass)
double best_pi() const
Returns the current best estimation of pi.
bool bFixed
whether the random sequence is always the same
Seed_t seed
number of digits to compute
Counter_t samples
number of samples to try on each event
virtual void analyze(const art::Event &) override
EDAnalyzer(Table< Config > const &config)
Computes pi (but it does not make it available)
static const char * VersionString
version of the algorithm
bool bVerbose
whether to put stuff on screen
std::default_random_engine::result_type Seed_t
type for seed and random numbers
LArSoft-specific namespace.
ComputePi(fhicl::ParameterSet const &p)