Belle II Software development
EvtLinSample Struct Reference

Description: The simple helper class to generate arbitrary distribution based on a linear piece-wise approximation of it. More...

Public Member Functions

 EvtLinSample ()
 The default constructor.
 
 EvtLinSample (const std::vector< EvtPointf > &_v)
 The primary constructor with an actual shape to generate.
 
void init (const std::vector< EvtPointf > &_v)
 The method to initialize data.
 
std::pair< double, double > operator() (double) const
 The operator to return <x,weight> depend on argument in [0,1] range which represent fraction of the total distribution integral.
 

Public Attributes

std::vector< EvtPointfm_v
 shape data
 
std::vector< double > m_I
 cumulative integral data
 

Detailed Description

Description: The simple helper class to generate arbitrary distribution based on a linear piece-wise approximation of it.

Definition at line 68 of file EvtbTosllNPR.cc.

Constructor & Destructor Documentation

◆ EvtLinSample() [1/2]

EvtLinSample ( )
inline

The default constructor.

Definition at line 72 of file EvtbTosllNPR.cc.

72{}

◆ EvtLinSample() [2/2]

EvtLinSample ( const std::vector< EvtPointf > & _v)
inlineexplicit

The primary constructor with an actual shape to generate.

Definition at line 77 of file EvtbTosllNPR.cc.

77{ init(_v); }
void init(const std::vector< EvtPointf > &_v)
The method to initialize data.

Member Function Documentation

◆ init()

void init ( const std::vector< EvtPointf > & _v)

The method to initialize data.

The method to initialize a cumulative integral of the piece-wise approximation provided as input _v.

Definition at line 187 of file EvtbTosllNPR.cc.

188{
189 m_v = _v;
190 m_I.push_back(0);
191 for (unsigned i = 0; i < m_v.size() - 1; i++)
192 m_I.push_back((m_v[i + 1].y + m_v[i + 0].y) * (m_v[i + 1].x - m_v[i + 0].x) + m_I.back());
193 double norm = 1 / m_I.back();
194 for (unsigned i = 0; i < m_v.size(); i++)
195 m_I[i] *= norm;
196}
std::vector< double > m_I
cumulative integral data
std::vector< EvtPointf > m_v
shape data

◆ operator()()

std::pair< double, double > operator() ( double r) const

The operator to return <x,weight> depend on argument in [0,1] range which represent fraction of the total distribution integral.

Sample from the cumulative integral and return q^2 and the associated weight.

Definition at line 202 of file EvtbTosllNPR.cc.

203{
204 int j = upper_bound(m_I.begin(), m_I.end(), r) - m_I.begin();
205 double dI = m_I[j] - m_I[j - 1];
206 r = (r - m_I[j - 1]) / dI;
207 double f0 = m_v[j - 1].y, f1 = m_v[j].y, x0 = m_v[j - 1].x, x1 = m_v[j].x,
208 df = f1 - f0, dx = x1 - x0, z;
209 if (fabs(df) > f0 * 1e-3) {
210 z = (f1 * x0 - x1 * f0 + dx * sqrt(df * (f0 + f1) * r + f0 * f0)) / df;
211 } else {
212 if (f0 > f1) {
213 z = x0 + (r * dx) * (f1 - r * df) / f0;
214 } else {
215 z = x1 - (r * dx) * (f0 + r * df) / f1;
216 }
217 }
218 return std::make_pair(z, f0 + (df / dx) * (z - x0));
219}
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28

Member Data Documentation

◆ m_I

std::vector<double> m_I

cumulative integral data

Definition at line 94 of file EvtbTosllNPR.cc.

◆ m_v

std::vector<EvtPointf> m_v

shape data

Definition at line 91 of file EvtbTosllNPR.cc.


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