54 using Seed_t = std::default_random_engine::result_type;
92 inline constexpr T
sqr(T v)
106 <<
" samples per event, random seed " <<
seed;
114 std::uniform_real_distribution<float> flat(0.0, 1.0);
121 while (tries_left-- > 0) {
123 if (
sqr(x) +
sqr(
y) < 1.0) ++local_hits;
126 double local_pi = double(local_hits) / double(
samples) * 4.0;
131 mf::LogInfo(
"ComputePi") <<
"today's pi = " << std::fixed << std::setprecision(9) << local_pi
132 <<
" (pi = " << 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
EDAnalyzer(fhicl::ParameterSet const &pset)
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
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
decltype(auto) get(T &&obj)
ADL-aware version of std::to_string.
std::default_random_engine::result_type Seed_t
type for seed and random numbers
LArSoft-specific namespace.
ComputePi(fhicl::ParameterSet const &p)