All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
lar::ComputePi Class Reference

Computes pi (but it does not make it available) More...

Inheritance diagram for lar::ComputePi:

Public Types

using Counter_t = unsigned long long
 type used for integral counters More...
 
using Seed_t = std::default_random_engine::result_type
 type for seed and random numbers More...
 

Public Member Functions

 ComputePi (fhicl::ParameterSet const &p)
 
virtual ~ComputePi ()=default
 
virtual void analyze (const art::Event &) override
 
double best_pi () const
 Returns the current best estimation of pi. More...
 
Counter_t best_pi_tries () const
 Returns the current best estimation of pi. More...
 

Static Public Attributes

static const char * VersionString = "1.0"
 version of the algorithm More...
 

Private Attributes

Counter_t samples
 number of samples to try on each event More...
 
Seed_t seed
 number of digits to compute More...
 
bool bFixed
 whether the random sequence is always the same More...
 
bool bVerbose
 whether to put stuff on screen More...
 
std::default_random_engine generator
 random generator More...
 
Counter_t hits = 0
 total number of hits More...
 
Counter_t tries = 0
 total number of tries (samples) More...
 

Detailed Description

Computes pi (but it does not make it available)

This module performs a extensive computation whose duration can be indirectly controlled by a parameter. The time taken is supposed to be independent from the framework. This is meant to help establish an absolute time scale.

The module performs some Monte Carlo integration to compute pi. The same number of cycles is used regardless the result. We use a simple pseudo-random generator (std::linear_congruential_engine) with a constant extraction time (and poor randomness quality, and a period so small that in about 20 events the sequence might repeat itself). The fluctuations of the result don't reflect a fluctuation in time.

A test performed on uboonegpvm06,fnal.gov on August 19th, 2014 on 1000 events with Ksamples=50000 (i.e., 50M samples per event), default seed and verbosity on took 0.9179 +/- 0.0009 s, with an RMS of ~3%. It was observed that processing time asymptotically decreased.

Parameters

Definition at line 52 of file ComputePi_module.cc.

Member Typedef Documentation

using lar::ComputePi::Counter_t = unsigned long long

type used for integral counters

Definition at line 54 of file ComputePi_module.cc.

using lar::ComputePi::Seed_t = std::default_random_engine::result_type

type for seed and random numbers

Definition at line 56 of file ComputePi_module.cc.

Constructor & Destructor Documentation

lar::ComputePi::ComputePi ( fhicl::ParameterSet const &  p)
explicit

Definition at line 100 of file ComputePi_module.cc.

100  :
101  EDAnalyzer(p),
102  samples(p.get<Counter_t>("Ksamples", 10000) * 1000),
103  seed(p.get<Seed_t>("Seed", 314159)),
104  bFixed(p.get<bool>("Fixed", false)),
105  bVerbose(p.get<bool>("Verbose", false)),
106  generator(seed)
107 {
108  mf::LogInfo("ComputePi")
109  << "version " << VersionString
110  << " using " << samples << " samples per event, random seed " << seed;
111 } // lar::ComputePi::ComputePi()
std::default_random_engine generator
random generator
pdgs p
Definition: selectors.fcl:22
unsigned long long Counter_t
type used for integral counters
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
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
virtual lar::ComputePi::~ComputePi ( )
virtualdefault

Member Function Documentation

void lar::ComputePi::analyze ( const art::Event &  )
overridevirtual

Definition at line 114 of file ComputePi_module.cc.

114  {
115 
116  // prepare our personal pseudo-random engine;
117  // we'll use always the same sequence!
118  std::uniform_real_distribution<float> flat(0.0, 1.0);
119 
120  // if we want to fix the random sequence, we reseed the generator
121  // with the same value over and over again
122  if (bFixed) generator.seed(seed);
123 
124  Counter_t local_hits = 0, tries_left = samples;
125  while (tries_left-- > 0) {
126  float x = flat(generator), y = flat(generator);
127  if (sqr(x) + sqr(y) < 1.0) ++local_hits;
128  } // while
129 
130  double local_pi = double(local_hits) / double(samples) * 4.0;
131  hits += local_hits;
132  tries += samples;
133 
134  if (bVerbose) {
135  mf::LogInfo("ComputePi") << "today's pi = "
136  << std::fixed << std::setprecision(9) << local_pi
137  << " (pi = "
138  << std::fixed << std::setprecision(12) << best_pi()
139  << " after " << best_pi_tries() << " samples)";
140  } // if verbose
141 
142 } // lar::ComputePi::analyze()
Counter_t tries
total number of tries (samples)
process_name opflash particleana ie x
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
process_name opflash particleana ie ie y
double best_pi() const
Returns the current best estimation of pi.
bool bFixed
whether the random sequence is always the same
constexpr T sqr(T v)
Seed_t seed
number of digits to compute
Counter_t samples
number of samples to try on each event
bool bVerbose
whether to put stuff on screen
double lar::ComputePi::best_pi ( ) const
inline

Returns the current best estimation of pi.

Definition at line 65 of file ComputePi_module.cc.

66  { return tries? 4. * double(hits) / double(tries): 3.0; }
Counter_t tries
total number of tries (samples)
Counter_t hits
total number of hits
Counter_t lar::ComputePi::best_pi_tries ( ) const
inline

Returns the current best estimation of pi.

Definition at line 69 of file ComputePi_module.cc.

69 { return tries; }
Counter_t tries
total number of tries (samples)

Member Data Documentation

bool lar::ComputePi::bFixed
private

whether the random sequence is always the same

Definition at line 77 of file ComputePi_module.cc.

bool lar::ComputePi::bVerbose
private

whether to put stuff on screen

Definition at line 78 of file ComputePi_module.cc.

std::default_random_engine lar::ComputePi::generator
private

random generator

Definition at line 80 of file ComputePi_module.cc.

Counter_t lar::ComputePi::hits = 0
private

total number of hits

Definition at line 81 of file ComputePi_module.cc.

Counter_t lar::ComputePi::samples
private

number of samples to try on each event

Definition at line 75 of file ComputePi_module.cc.

Seed_t lar::ComputePi::seed
private

number of digits to compute

Definition at line 76 of file ComputePi_module.cc.

Counter_t lar::ComputePi::tries = 0
private

total number of tries (samples)

Definition at line 82 of file ComputePi_module.cc.

const char * lar::ComputePi::VersionString = "1.0"
static

version of the algorithm

Definition at line 72 of file ComputePi_module.cc.


The documentation for this class was generated from the following file: