ATLAS Offline Software
Simulation
Tools
AtlasCLHEP_RandomGenerators
src
RandBinomialFixedP.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
6
#include <cmath>
7
#include <iostream>
8
#include <algorithm>
9
10
#include "
AtlasCLHEP_RandomGenerators/RandBinomialFixedP.h
"
11
12
namespace
CLHEP
{
13
14
std::string
RandBinomialFixedP::name
()
const
{
return
"RandBinomialFixedP"
;}
15
16
RandBinomialFixedP::~RandBinomialFixedP
() {
17
}
18
19
inline
double
binom
(
int
n
,
int
k
) {
20
return
1/((
n
+1)*
std::beta
(
n
-
k
+1,
k
+1));
21
}
22
23
void
RandBinomialFixedP::initLookupTable
(
long
Nmaxlookup,
double
p
) {
24
defaultP=
p
;
25
LookupTable
.resize(Nmaxlookup);
26
for
(
unsigned
int
n
=1;
n
<=Nmaxlookup;++
n
) {
27
unsigned
int
in=
n
-1;
28
double
q
=1-
p
;
29
LookupTable
[in].resize(
n
);
30
//LookupTable[in][n]=1 always, so don't need to store
31
for
(
unsigned
int
k
=0;
k
<
n
;++
k
) {
32
//p(k;n,p)=n!/(k!*(n-k)!)*p^k*(1-p)^(n-k)
33
double
prop=
binom
(
n
,
k
)*
std::pow
(
p
,
k
)*
std::pow
(
q
,
n
-
k
);
34
if
(
k
>0) prop+=
LookupTable
[in][
k
-1];
35
LookupTable
[in][
k
]=prop;
36
}
37
}
38
}
39
40
double
RandBinomialFixedP::fire
( HepRandomEngine* anEngine,
long
n
) {
41
if
(
n
==1) {
42
double
prop=anEngine->flat();
43
if
(prop>defaultP)
return
0;
44
return
1;
45
}
46
if
(
n
>(
long
)
LookupTable
.size())
return
genBinomial( anEngine,
n
, defaultP );
47
48
auto
&
table
=
LookupTable
[
n
-1];
49
50
double
prop=anEngine->flat();
51
auto
itk = std::upper_bound(
table
.begin(),
table
.end(),prop);
52
return
std::distance
(
table
.begin(),itk);
53
}
54
55
void
RandBinomialFixedP::fireArray
(
const
int
size
,
double
* vect)
56
{
57
for
(
double
*
v
= vect;
v
!= vect+
size
; ++
v
)
58
*
v
=
fire
(defaultN);
59
}
60
61
void
RandBinomialFixedP::fireArray
(
const
int
size
,
double
* vect,
62
long
n
)
63
{
64
for
(
double
*
v
= vect;
v
!= vect+
size
; ++
v
)
65
*
v
=
fire
(
n
);
66
}
67
68
}
// namespace CLHEP
CLHEP::binom
double binom(int n, int k)
Definition:
RandBinomialFixedP.cxx:19
conifer::pow
constexpr int pow(int x)
Definition:
conifer.h:20
CLHEP::RandBinomialFixedP::LookupTable
std::vector< std::vector< double > > LookupTable
Definition:
RandBinomialFixedP.h:74
CLHEP::RandBinomialFixedP::~RandBinomialFixedP
virtual ~RandBinomialFixedP()
Definition:
RandBinomialFixedP.cxx:16
CLHEP::RandBinomialFixedP::initLookupTable
void initLookupTable(long Nmaxlookup, double p)
Definition:
RandBinomialFixedP.cxx:23
python.setupRTTAlg.size
int size
Definition:
setupRTTAlg.py:39
python.utils.AtlRunQueryDQUtils.p
p
Definition:
AtlRunQueryDQUtils.py:210
CLHEP::RandBinomialFixedP::fire
double fire()
beamspotman.n
n
Definition:
beamspotman.py:731
CLHEP
STD'S.
Definition:
IAtRndmGenSvc.h:19
RandBinomialFixedP.h
python.ext.table_printer.table
list table
Definition:
table_printer.py:81
python.PyAthena.v
v
Definition:
PyAthena.py:154
extractSporadic.q
list q
Definition:
extractSporadic.py:98
CLHEP::RandBinomialFixedP::fireArray
void fireArray(const int size, double *vect)
Definition:
RandBinomialFixedP.cxx:55
MuonParameters::beta
@ beta
Definition:
MuonParamDefs.h:144
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition:
GeoPrimitivesHelpers.h:54
CLHEP::RandBinomialFixedP::name
std::string name() const
Definition:
RandBinomialFixedP.cxx:14
fitman.k
k
Definition:
fitman.py:528
Generated on Thu Nov 7 2024 21:24:23 for ATLAS Offline Software by
1.8.18