R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandMultiplicityBayesPar.cxx
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
15#include "FairLogger.h"
16#include <numeric>
17#include <string>
18
19void normalize_TArrayD(TArrayD& a)
20{
21 const auto s = a.GetSum();
22 const auto l = a.GetSize();
23 if (s > 0.)
24 {
25 for (int j = 0; j < l; j++)
26 {
27 a[j] = a[j] / s;
28 }
29 }
30}
31
33{
34 for (int i = 0; i < NEULAND_MAX_MULT; i++)
35 {
36 // to density (Normalize)
37 fHits.at(i)[0] = 0;
38 fClusters.at(i)[0] = 0;
39 fEdep.at(i)[0] = 0;
40 normalize_TArrayD(fHits.at(i));
41 normalize_TArrayD(fClusters.at(i));
42 normalize_TArrayD(fEdep.at(i));
43 }
44}
45
46R3BNeulandMultiplicityBayesPar::R3BNeulandMultiplicityBayesPar(const char* name, const char* title, const char* context)
47 : FairParGenericSet(name, title, context)
48 , fHits({ 1000, 1000, 1000, 1000, 1000, 1000, 1000 })
49 , fClusters({ 1000, 1000, 1000, 1000, 1000, 1000, 1000 })
50 , fEdep({ 1000, 1000, 1000, 1000, 1000, 1000, 1000 })
51 , fIsProperlyLoaded(false)
52{
53}
54
56{
57 // Note: Deleting stuff here or in clear() causes segfaults?
58}
59
61
63{
64 if (!l)
65 {
66 return;
67 }
68
69 for (int i = 0; i < NEULAND_MAX_MULT; i++)
70 {
71 l->add(TString::Format("NeulandMultiplicityBayesParHits-%d", i), fHits.at(i));
72 l->add(TString::Format("NeulandMultiplicityBayesParClusters-%d", i), fClusters.at(i));
73 l->add(TString::Format("NeulandMultiplicityBayesParEdep-%d", i), fEdep.at(i));
74 }
75}
76
78{
79 if (!l)
80 {
81 return false;
82 }
83
84 for (int i = 0; i < NEULAND_MAX_MULT; i++)
85 {
86 l->fill(TString::Format("NeulandMultiplicityBayesParHits-%d", i), &fHits.at(i));
87 l->fill(TString::Format("NeulandMultiplicityBayesParClusters-%d", i), &fClusters.at(i));
88 l->fill(TString::Format("NeulandMultiplicityBayesParEdep-%d", i), &fEdep.at(i));
89 }
90
91 return true;
92}
93
94void R3BNeulandMultiplicityBayesPar::Fill(int n, int nHits, int nClusters, double Edep)
95{
96 fHits.at(n)[nHits]++;
97 fClusters.at(n)[nClusters]++;
98 fEdep.at(n)[static_cast<int>(std::floor(Edep)) / 10]++;
99}
100
102 int nClusters,
103 int Edep) const
104{
105 if (!fIsProperlyLoaded)
106 {
107 fIsProperlyLoaded = CheckIfProperlyLoaded();
108 }
109
110 R3BNeulandMultiplicity::MultiplicityProbabilities mult = { 1, 0, 0, 0, 0, 0, 0 };
111 if (nHits == 0)
112 {
113 return mult;
114 }
115
116 double sum = 0;
117 for (size_t i = 0; i < mult.size(); i++)
118 {
119 mult[i] = fHits.at(i).At(nHits) * fClusters.at(i).At(nClusters) * fEdep.at(i).At(Edep / 10);
120 sum += mult[i];
121 }
122
123 // Normalize so sum prob = 1
124 for (double& i : mult)
125 {
126 i /= sum;
127 }
128 return mult;
129}
130
132{
133 if (std::accumulate(fHits.cbegin(), fHits.cend(), 0, [](int i, const TArrayD& a) { return i + a.GetSum(); }) < 0.1)
134 {
135 LOG(fatal) << "R3BNeulandMultiplicityBayesPar: Empty dataset -> Not properly loaded!";
136 }
137 return true;
138}
139
static constexpr int NEULAND_MAX_MULT
void normalize_TArrayD(TArrayD &a)
ClassImp(R3BNeulandMultiplicityBayesPar)
R3BNeulandMultiplicityBayesPar(const char *name="R3BNeulandMultiplicityBayesPar", const char *title="Neuland Multiplicity Bayes Parameters", const char *context="TestDefaultContext")
R3BNeulandMultiplicity::MultiplicityProbabilities GetProbabilities(int nHits, int nClusters, int Edep) const
Bool_t getParams(FairParamList *) override
void Fill(int n, int nHits, int nClusters, double Edep)
std::array< double, NEULAND_MAX_MULT > MultiplicityProbabilities