Belle II Software  release-05-01-25
TOPPmtTTSPar.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Marko Staric, Alessandro Gaz *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 
13 #include <TObject.h>
14 #include <framework/logging/Logger.h>
15 #include <vector>
16 
17 #include <TRandom.h>
18 
19 namespace Belle2 {
28  class TOPPmtTTSPar : public TObject {
29 
30  public:
34  struct Gaussian {
35  float fraction = 0;
36  float mean = 0;
37  float sigma = 0;
38  };
39 
43  enum {c_NumPmtPixels = 16};
44 
48  TOPPmtTTSPar()
49  {}
50 
55  explicit TOPPmtTTSPar(const std::string& serialNumber):
56  m_serialNumber(serialNumber)
57  {}
58 
59 
65  void appendGaussian(unsigned pmtPixel, const Gaussian& gaus)
66  {
67  pmtPixel--;
68  if (pmtPixel >= c_NumPmtPixels) {
69  B2ERROR("TOPPmtTTSPar::appendGaussian: invalid PMT pixel "
70  << LogVar("PMT pixel", pmtPixel + 1));
71  return;
72  }
73  m_gaussians[pmtPixel].push_back(gaus);
74  }
75 
76 
84  void appendGaussian(unsigned pmtPixel, double fraction, double mean, double sigma)
85  {
86  Gaussian gaus;
87  gaus.fraction = fraction;
88  gaus.mean = mean;
89  gaus.sigma = sigma;
90  appendGaussian(pmtPixel, gaus);
91  }
92 
97  int getNumOfPixels() const {return c_NumPmtPixels;}
98 
103  const std::string& getSerialNumber() const {return m_serialNumber;}
104 
105 
111  const std::vector<Gaussian>& getGaussians(unsigned pmtPixel) const
112  {
113  pmtPixel--;
114  if (pmtPixel >= c_NumPmtPixels) {
115  B2ERROR("TOPPmtTTSPar::getGaussians: invalid PMT pixel. "
116  "Returning data for pixel 1."
117  << LogVar("PMT pixel", pmtPixel + 1));
118  pmtPixel = 0;
119  }
120  return m_gaussians[pmtPixel];
121  }
122 
123 
129  double getRandomTime(unsigned pmtPixel) const
130  {
131  pmtPixel--;
132  if (pmtPixel >= c_NumPmtPixels) return 0;
133 
134  double prob = gRandom->Rndm();
135  double s = 0;
136  for (const auto& gaus : m_gaussians[pmtPixel]) {
137  s = s + gaus.fraction;
138  if (prob < s) {
139  return gRandom->Gaus(gaus.mean, gaus.sigma);
140  }
141  }
142  return 0; // this should not happen, if fractions are properly normalized
143  }
144 
145 
149  void normalizeFractions()
150  {
151  double sum = 0;
152  for (int ich = 0 ; ich < c_NumPmtPixels ; ich++) {
153  for (const auto& gaus : m_gaussians[ich]) {
154  sum = sum + gaus.fraction;
155  }
156  if (sum == 0) return;
157  for (auto& gaus : m_gaussians[ich]) {
158  gaus.fraction = gaus.fraction / sum;
159  }
160  }
161  return;
162  }
163 
164 
165 
166  private:
167 
168  std::string m_serialNumber;
169  std::vector<Gaussian> m_gaussians[c_NumPmtPixels];
171  ClassDef(TOPPmtTTSPar, 2);
173  };
174 
176 } // end namespace Belle2
177 
178 
Belle2::TOPPmtTTSPar::normalizeFractions
void normalizeFractions()
Normalizes the gaussian fractions to unity.
Definition: TOPPmtTTSPar.h:157
Belle2::TOPPmtTTSPar::getRandomTime
double getRandomTime(unsigned pmtPixel) const
Returns a random number, generated according to the distribution.
Definition: TOPPmtTTSPar.h:137
Belle2::TOPPmtTTSPar::getNumOfPixels
int getNumOfPixels() const
Returns number of PMT pixels.
Definition: TOPPmtTTSPar.h:105
Belle2::TOPPmtTTSPar::Gaussian::mean
float mean
peak position [ns]
Definition: TOPPmtTTSPar.h:44
Belle2::TOPPmtTTSPar::Gaussian::sigma
float sigma
peak width [ns]
Definition: TOPPmtTTSPar.h:45
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::TOPPmtTTSPar::TOPPmtTTSPar
TOPPmtTTSPar()
Default constructor.
Definition: TOPPmtTTSPar.h:56
LogVar
Class to store variables with their name which were sent to the logging service.
Definition: LogVariableStream.h:24
Belle2::TOPPmtTTSPar::m_serialNumber
std::string m_serialNumber
serial number, e.g.
Definition: TOPPmtTTSPar.h:176
Belle2::TOPPmtTTSPar::getSerialNumber
const std::string & getSerialNumber() const
Returns PMT serial number.
Definition: TOPPmtTTSPar.h:111
Belle2::TOPPmtTTSPar::m_gaussians
std::vector< Gaussian > m_gaussians[c_NumPmtPixels]
TTS distribution composed of Gaussians.
Definition: TOPPmtTTSPar.h:177
Belle2::TOPPmtTTSPar::getGaussians
const std::vector< Gaussian > & getGaussians(unsigned pmtPixel) const
Returns vector of gaussians.
Definition: TOPPmtTTSPar.h:119
Belle2::TOPPmtTTSPar::Gaussian::fraction
float fraction
area normalization
Definition: TOPPmtTTSPar.h:43
Belle2::TOPPmtTTSPar::ClassDef
ClassDef(TOPPmtTTSPar, 2)
ClassDef.
Belle2::TOPPmtTTSPar::appendGaussian
void appendGaussian(unsigned pmtPixel, const Gaussian &gaus)
Append struct gauss.
Definition: TOPPmtTTSPar.h:73