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:
art::EDAnalyzer art::detail::Analyzer art::detail::LegacyModule art::Observer art::ModuleBase

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 Types inherited from art::EDAnalyzer
using WorkerType = WorkerT< EDAnalyzer >
 
using ModuleType = EDAnalyzer
 

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...
 
- Public Member Functions inherited from art::EDAnalyzer
 EDAnalyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 EDAnalyzer (Table< Config > const &config)
 
std::string workerType () const
 
- Public Member Functions inherited from art::detail::Analyzer
virtual ~Analyzer () noexcept
 
 Analyzer (fhicl::ParameterSet const &pset)
 
template<typename Config >
 Analyzer (Table< Config > const &config)
 
void doBeginJob (SharedResources const &resources)
 
void doEndJob ()
 
void doRespondToOpenInputFile (FileBlock const &fb)
 
void doRespondToCloseInputFile (FileBlock const &fb)
 
void doRespondToOpenOutputFiles (FileBlock const &fb)
 
void doRespondToCloseOutputFiles (FileBlock const &fb)
 
bool doBeginRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doEndRun (RunPrincipal &rp, ModuleContext const &mc)
 
bool doBeginSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEndSubRun (SubRunPrincipal &srp, ModuleContext const &mc)
 
bool doEvent (EventPrincipal &ep, ModuleContext const &mc, std::atomic< std::size_t > &counts_run, std::atomic< std::size_t > &counts_passed, std::atomic< std::size_t > &counts_failed)
 
- Public Member Functions inherited from art::Observer
 ~Observer () noexcept
 
 Observer (Observer const &)=delete
 
 Observer (Observer &&)=delete
 
Observeroperator= (Observer const &)=delete
 
Observeroperator= (Observer &&)=delete
 
void registerProducts (ProductDescriptions &, ModuleDescription const &)
 
void fillDescriptions (ModuleDescription const &)
 
fhicl::ParameterSetID selectorConfig () const
 
- Public Member Functions inherited from art::ModuleBase
virtual ~ModuleBase () noexcept
 
 ModuleBase ()
 
ModuleDescription const & moduleDescription () const
 
void setModuleDescription (ModuleDescription const &)
 
std::array< std::vector< ProductInfo >, NumBranchTypes > const & getConsumables () const
 
void sortConsumables (std::string const &current_process_name)
 
template<typename T , BranchType BT>
ViewToken< T > consumesView (InputTag const &tag)
 
template<typename T , BranchType BT>
ViewToken< T > mayConsumeView (InputTag const &tag)
 

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...
 

Additional Inherited Members

- Protected Member Functions inherited from art::Observer
std::string const & processName () const
 
bool wantAllEvents () const noexcept
 
bool wantEvent (ScheduleID id, Event const &e) const
 
Handle< TriggerResultsgetTriggerResults (Event const &e) const
 
 Observer (fhicl::ParameterSet const &config)
 
 Observer (std::vector< std::string > const &select_paths, std::vector< std::string > const &reject_paths, fhicl::ParameterSet const &config)
 
- Protected Member Functions inherited from art::ModuleBase
ConsumesCollectorconsumesCollector ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > consumes (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > consumesView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void consumesMany ()
 
template<typename T , BranchType = InEvent>
ProductToken< T > mayConsume (InputTag const &)
 
template<typename Element , BranchType = InEvent>
ViewToken< Element > mayConsumeView (InputTag const &)
 
template<typename T , BranchType = InEvent>
void mayConsumeMany ()
 

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()
MaybeLogger_< ELseverityLevel::ELsev_info, false > LogInfo
std::default_random_engine generator
random generator
unsigned long long Counter_t
type used for integral counters
EDAnalyzer(fhicl::ParameterSet const &pset)
Definition: EDAnalyzer.h:25
bool bFixed
whether the random sequence is always the same
p
Definition: test.py:223
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)
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
Q_EXPORT QTSManip setprecision(int p)
Definition: qtextstream.h:343
Counter_t hits
total number of hits
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
list x
Definition: train.py:276
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: