Belle II Software development
TOPPmtTTSPar.h
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#pragma once
10
11#include <TObject.h>
12#include <framework/logging/Logger.h>
13#include <vector>
14
15#include <TRandom.h>
16
17namespace Belle2 {
26 class TOPPmtTTSPar : public TObject {
27
28 public:
32 struct Gaussian {
33 float fraction = 0;
34 float mean = 0;
35 float sigma = 0;
36 };
37
41 enum {c_NumPmtPixels = 16};
42
47 {}
48
53 explicit TOPPmtTTSPar(const std::string& serialNumber):
54 m_serialNumber(serialNumber)
55 {}
56
57
63 void appendGaussian(unsigned pmtPixel, const Gaussian& gaus)
64 {
65 pmtPixel--;
66 if (pmtPixel >= c_NumPmtPixels) {
67 B2ERROR("TOPPmtTTSPar::appendGaussian: invalid PMT pixel "
68 << LogVar("PMT pixel", pmtPixel + 1));
69 return;
70 }
71 m_gaussians[pmtPixel].push_back(gaus);
72 }
73
74
82 void appendGaussian(unsigned pmtPixel, double fraction, double mean, double sigma)
83 {
84 Gaussian gaus;
85 gaus.fraction = fraction;
86 gaus.mean = mean;
87 gaus.sigma = sigma;
88 appendGaussian(pmtPixel, gaus);
89 }
90
95 int getNumOfPixels() const {return c_NumPmtPixels;}
96
101 const std::string& getSerialNumber() const {return m_serialNumber;}
102
103
109 const std::vector<Gaussian>& getGaussians(unsigned pmtPixel) const
110 {
111 pmtPixel--;
112 if (pmtPixel >= c_NumPmtPixels) {
113 B2ERROR("TOPPmtTTSPar::getGaussians: invalid PMT pixel. "
114 "Returning data for pixel 1."
115 << LogVar("PMT pixel", pmtPixel + 1));
116 pmtPixel = 0;
117 }
118 return m_gaussians[pmtPixel];
119 }
120
121
127 double getRandomTime(unsigned pmtPixel) const
128 {
129 pmtPixel--;
130 if (pmtPixel >= c_NumPmtPixels) return 0;
131
132 double prob = gRandom->Rndm();
133 double s = 0;
134 for (const auto& gaus : m_gaussians[pmtPixel]) {
135 s = s + gaus.fraction;
136 if (prob < s) {
137 return gRandom->Gaus(gaus.mean, gaus.sigma);
138 }
139 }
140 return 0; // this should not happen, if fractions are properly normalized
141 }
142
143
148 {
149 double sum = 0;
150 for (int ich = 0 ; ich < c_NumPmtPixels ; ich++) {
151 for (const auto& gaus : m_gaussians[ich]) {
152 sum = sum + gaus.fraction;
153 }
154 if (sum == 0) return;
155 for (auto& gaus : m_gaussians[ich]) {
156 gaus.fraction = gaus.fraction / sum;
157 }
158 }
159 return;
160 }
161
162
163
164 private:
165
166 std::string m_serialNumber;
167 std::vector<Gaussian> m_gaussians[c_NumPmtPixels];
171 };
172
174} // end namespace Belle2
175
176
Parameterized TTS for each PMT pixel.
Definition: TOPPmtTTSPar.h:26
std::vector< Gaussian > m_gaussians[c_NumPmtPixels]
TTS distribution composed of Gaussians.
Definition: TOPPmtTTSPar.h:167
TOPPmtTTSPar()
Default constructor.
Definition: TOPPmtTTSPar.h:46
int getNumOfPixels() const
Returns number of PMT pixels.
Definition: TOPPmtTTSPar.h:95
std::string m_serialNumber
serial number, e.g.
Definition: TOPPmtTTSPar.h:166
TOPPmtTTSPar(const std::string &serialNumber)
Full constructor.
Definition: TOPPmtTTSPar.h:53
void normalizeFractions()
Normalizes the gaussian fractions to unity.
Definition: TOPPmtTTSPar.h:147
void appendGaussian(unsigned pmtPixel, double fraction, double mean, double sigma)
Append gaussian using its parameters (frac, mean, sigma)
Definition: TOPPmtTTSPar.h:82
double getRandomTime(unsigned pmtPixel) const
Returns a random number, generated according to the distribution.
Definition: TOPPmtTTSPar.h:127
void appendGaussian(unsigned pmtPixel, const Gaussian &gaus)
Append struct gauss.
Definition: TOPPmtTTSPar.h:63
ClassDef(TOPPmtTTSPar, 2)
ClassDef.
const std::vector< Gaussian > & getGaussians(unsigned pmtPixel) const
Returns vector of gaussians.
Definition: TOPPmtTTSPar.h:109
const std::string & getSerialNumber() const
Returns PMT serial number.
Definition: TOPPmtTTSPar.h:101
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.
Gaussian distribution parameters.
Definition: TOPPmtTTSPar.h:32
float fraction
area normalization
Definition: TOPPmtTTSPar.h:33
float mean
peak position [ns]
Definition: TOPPmtTTSPar.h:34
float sigma
peak width [ns]
Definition: TOPPmtTTSPar.h:35