Belle II Software development
TOPNominalTTS.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/dbobjects/TOPNominalTTS.h>
10#include <framework/logging/Logger.h>
11#include <iostream>
12#include <TRandom.h>
13
14using namespace std;
15
16namespace Belle2 {
22 void TOPNominalTTS::appendGaussian(double norm, double mean, double sigma)
23 {
24 if (norm <= 0) {
25 B2ERROR("TOPNominalTTS::appendGaussian: normalization is non-positive number");
26 return;
27 }
28 Gauss gauss;
29 gauss.fraction = norm;
30 gauss.position = mean;
31 gauss.sigma = sigma;
32 m_tts.push_back(gauss);
33 m_normalized = false;
34 }
35
37 {
38 float sum = 0;
39 for (const auto& tts : m_tts) sum += tts.fraction;
40 if (sum == 0) return 0;
41 for (auto& tts : m_tts) tts.fraction /= sum;
42 m_normalized = true;
43 return sum;
44 }
45
47 {
48 double prob = gRandom->Rndm();
49 double s = 0;
50 for (const auto& tts : m_tts) {
51 s = s + tts.fraction;
52 if (prob < s) {
53 return gRandom->Gaus(tts.position, tts.sigma);
54 }
55 }
56 return 0;
57 }
58
59
61 {
62 if (m_tts.empty()) return false;
63 if (!m_normalized) return false;
64 return true;
65 }
66
67
68 void TOPNominalTTS::print(const std::string& title) const
69 {
71 if (m_tts.empty()) {
72 cout << " -> vector is empty!" << endl;
73 return;
74 }
75 cout << " PMT type: " << m_type << endl;
76
77 int i = 0;
78 for (const auto& tts : m_tts) {
79 i++;
80 cout << " Gaussian " << i << ": ";
81 cout << tts.fraction << ", ";
82 cout << tts.position << " ns, ";
83 cout << tts.sigma << " ns" << endl;
84 }
85 if (!m_normalized) cout << " warning: fractions not normalized" << endl;
86 }
87
89} // end Belle2 namespace
bool m_normalized
normalization flag
unsigned m_type
PMT type (see TOPPmtObsoleteData::EType)
std::vector< Gauss > m_tts
TTS distribution composed of a sum of Gaussians.
double normalize()
Normalize the distribution (fractions)
bool isConsistent() const override
Check for consistency of data members.
void printUnderlined(const std::string &title) const
Print the content of the class.
Definition: TOPGeoBase.cc:35
void appendGaussian(double norm, double mean, double sigma)
Append Gaussian.
void print(const std::string &title="Nominal TTS distribution") const override
Print the content of the class.
double generateTTS() const
Generate time according to TTS distribution.
Abstract base class for different kinds of events.
STL namespace.
Gaussian distribution parameters.
Definition: TOPNominalTTS.h:29
float fraction
area normalization
Definition: TOPNominalTTS.h:30
float position
peak position [ns]
Definition: TOPNominalTTS.h:31
float sigma
peak width [ns]
Definition: TOPNominalTTS.h:32