Belle II Software development
PulseHeightGenerator.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <top/modules/TOPDigitizer/PulseHeightGenerator.h>
10#include <framework/logging/Logger.h>
11
12#include <TRandom.h>
13
14#include <iostream>
15
16using namespace std;
17
18namespace Belle2 {
23 namespace TOP {
24
25 PulseHeightGenerator::PulseHeightGenerator(double x0, double p1, double p2,
26 double xmax):
27 m_x0(x0), m_p1(p1), m_p2(p2), m_xmax(xmax)
28 {
29 if (x0 <= 0)
30 B2FATAL("TOP::PulseHeightGenerator: parameter x0 must be positive");
31 if (p1 < 0)
32 B2FATAL("TOP::PulseHeightGenerator: parameter p1 must be non-negative");
33 if (p2 <= 0)
34 B2FATAL("TOP::PulseHeightGenerator: parameter p2 must be positive");
35
36 double xPeak = pow((p1 / p2), 1 / p2) * x0;
37 if (m_xmax < xPeak) xPeak = m_xmax;
38 m_vPeak = getValue(xPeak);
39
40 }
41
42
44 {
45 if (m_xmax <= 0) return 0;
46 while (true) {
47 double x = gRandom->Uniform(m_xmax);
48 if (gRandom->Uniform(m_vPeak) < getValue(x)) return x;
49 }
50 }
51
52 } // TOP
54} // Belle2
double getValue(double x) const
Returns distribution value at x.
PulseHeightGenerator()
Default constructor.
double m_xmax
upper bound of range [ADC counts]
double generate() const
Returns generated pulse height.
Abstract base class for different kinds of events.
STL namespace.