Belle II Software  release-05-01-25
TOPNominalTTS.cc
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 *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <top/dbobjects/TOPNominalTTS.h>
12 #include <framework/logging/Logger.h>
13 #include <iostream>
14 #include <TRandom.h>
15 
16 using namespace std;
17 
18 namespace Belle2 {
24  void TOPNominalTTS::appendGaussian(double norm, double mean, double sigma)
25  {
26  if (norm <= 0) {
27  B2ERROR("TOPNominalTTS::appendGaussian: normalization is non-positive number");
28  return;
29  }
30  Gauss gauss;
31  gauss.fraction = norm;
32  gauss.position = mean;
33  gauss.sigma = sigma;
34  m_tts.push_back(gauss);
35  m_normalized = false;
36  }
37 
38  double TOPNominalTTS::normalize()
39  {
40  float sum = 0;
41  for (const auto& tts : m_tts) sum += tts.fraction;
42  if (sum == 0) return 0;
43  for (auto& tts : m_tts) tts.fraction /= sum;
44  m_normalized = true;
45  return sum;
46  }
47 
48  double TOPNominalTTS::generateTTS() const
49  {
50  double prob = gRandom->Rndm();
51  double s = 0;
52  for (const auto& tts : m_tts) {
53  s = s + tts.fraction;
54  if (prob < s) {
55  return gRandom->Gaus(tts.position, tts.sigma);
56  }
57  }
58  return 0;
59  }
60 
61 
62  bool TOPNominalTTS::isConsistent() const
63  {
64  if (m_tts.empty()) return false;
65  if (!m_normalized) return false;
66  return true;
67  }
68 
69 
70  void TOPNominalTTS::print(const std::string& title) const
71  {
72  TOPGeoBase::printUnderlined(title);
73  if (m_tts.empty()) {
74  cout << " -> vector is empty!" << endl;
75  return;
76  }
77  cout << " PMT type: " << m_type << endl;
78 
79  int i = 0;
80  for (const auto& tts : m_tts) {
81  i++;
82  cout << " Gaussian " << i << ": ";
83  cout << tts.fraction << ", ";
84  cout << tts.position << " ns, ";
85  cout << tts.sigma << " ns" << endl;
86  }
87  if (!m_normalized) cout << " warning: fractions not normalized" << endl;
88  }
89 
91 } // end Belle2 namespace
Belle2::TOPNominalTTS::Gauss::fraction
float fraction
area normalization
Definition: TOPNominalTTS.h:40
Belle2::TOPNominalTTS::Gauss
Gaussian distribution parameters.
Definition: TOPNominalTTS.h:39
Belle2::TOPNominalTTS::Gauss::position
float position
peak position [ns]
Definition: TOPNominalTTS.h:41
Belle2::TOPNominalTTS::Gauss::sigma
float sigma
peak width [ns]
Definition: TOPNominalTTS.h:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19