CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
RandPoissonT.cc
Go to the documentation of this file.
1//
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- RandPoissonT ---
7// class implementation file
8// -----------------------------------------------------------------------
9
10// =======================================================================
11// M. Fischler - Implemented new, much faster table-driven algorithm
12// applicable for mu < 100 (Nov 1999), using these as
13// implementation of RandPoisson.
14// M. Fischler - Moved the table driven algorithms into RandPoissonT (here)
15// 1/26/00.
16// M. Fischler - Removed mean=100 from the table-driven set, since it
17// uses a value just off the end of the table. (April 2004)
18// M Fischler - put and get to/from streams 12/15/04
19// M Fischler - fireArray using defaultMean 2/10/05
20// M Fischler - put/get to/from streams uses pairs of ulongs when
21// + storing doubles avoid problems with precision
22// -- appears not to need modification, relying on
23// RandPoisson::put() instead 4/14/05
24//
25// =======================================================================
26
27#include "CLHEP/Random/defs.h"
28#include "CLHEP/Random/RandPoissonT.h"
29#include "CLHEP/Random/RandPoissonQ.h"
30#include "CLHEP/Random/DoubConv.h"
31
32#include <iostream>
33#include <string>
34#include <vector>
35
36//
37// Constructors and destructors:
38//
39
40namespace CLHEP {
41
42std::string RandPoissonT::name() const {return "RandPoissonT";}
44
46: RandPoisson(anEngine, m)
47{}
48
50: RandPoisson(anEngine, m)
51{}
52
54}
55
56//
57// fire, operator(), and shoot methods:
58//
59
60long RandPoissonT::shoot(double xm) {
62 return shoot ( e, xm );
63} // shoot()
64
66 return double( fire() );
67}
68
69double RandPoissonT::operator()( double mean ) {
70 return double( fire( mean ) );
71}
72
73long RandPoissonT::fire(double mean) {
74 return shoot (getLocalEngine(), mean);
75}
76
78
81 } else {
83 }
84
85} // fire()
86
87long RandPoissonT::shoot(HepRandomEngine* anEngine, double mean) {
88
89 if ( mean < RandPoissonQ::tableBoundary() ) {
90 return RandPoissonQ::shoot ( anEngine, mean );
91 } else {
92 return RandPoisson::shoot( anEngine, mean );
93 }
94
95} // shoot (anEngine, mean)
96
97void RandPoissonT::shootArray(const int size, long* vect, double m) {
98 int i;
99 for (i=0; i<size; ++i)
100 vect[i] = shoot(m);
101}
102
103void RandPoissonT::fireArray(const int size, long* vect, double m) {
104 int i;
105 for (i=0; i<size; ++i) {
106 vect[i] = fire( m );
107 }
108}
109
110void RandPoissonT::fireArray(const int size, long* vect) {
111 int i;
112 for (i=0; i<size; ++i) {
113 vect[i] = fire( defaultMean );
114 }
115}
116
117
118std::ostream & RandPoissonT::put ( std::ostream & os ) const {
119 long pr=os.precision(20);
120 os << " " << name() << "\n";
122 os.precision(pr);
123 return os;
124}
125
126std::istream & RandPoissonT::get ( std::istream & is ) {
127 std::string inName;
128 is >> inName;
129 if (inName != name()) {
130 is.clear(std::ios::badbit | is.rdstate());
131 std::cerr << "Mismatch when expecting to read state of a "
132 << name() << " distribution\n"
133 << "Name found was " << inName
134 << "\nistream is left in the badbit state\n";
135 return is;
136 }
138 return is;
139}
140
141
142} // namespace CLHEP
static HepRandomEngine * getTheEngine()
Definition: Random.cc:270
static int tableBoundary()
static long shoot(double mean=1.0)
virtual ~RandPoissonT()
Definition: RandPoissonT.cc:53
RandPoissonT(HepRandomEngine &anEngine, double mean=1.0)
Definition: RandPoissonT.cc:45
std::istream & get(std::istream &is)
void fireArray(const int size, long *vect)
std::ostream & put(std::ostream &os) const
std::string name() const
Definition: RandPoissonT.cc:42
static long shoot(double mean=1.0)
Definition: RandPoissonT.cc:60
HepRandomEngine & engine()
Definition: RandPoissonT.cc:43
static void shootArray(const int size, long *vect, double mean=1.0)
Definition: RandPoissonT.cc:97
std::ostream & put(std::ostream &os) const
Definition: RandPoisson.cc:285
HepRandomEngine * getLocalEngine()
static long shoot(double mean=1.0)
Definition: RandPoisson.cc:95
std::istream & get(std::istream &is)
Definition: RandPoisson.cc:314
HepRandomEngine & engine()
Definition: RandPoisson.cc:40
#define double(obj)
Definition: excDblThrow.cc:32