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
16#include <FairParGenericSet.h>
17#include <FairParamList.h>
18#include <Rtypes.h>
19#include <RtypesCore.h>
20#include <TArrayD.h>
21#include <TString.h>
22#include <cmath>
23#include <cstddef>
24#include <fairlogger/Logger.h>
25#include <numeric>
26
27void normalize_TArrayD(TArrayD& a)
28{
29 const auto s = a.GetSum();
30 const auto l = a.GetSize();
31 if (s > 0.)
32 {
33 for (int j = 0; j < l; j++)
34 {
35 a[j] = a[j] / s;
36 }
37 }
38}
39
41{
42 for (int i = 0; i < NEULAND_MAX_MULT; i++)
43 {
44 // to density (Normalize)
45 fHits.at(i)[0] = 0;
46 fClusters.at(i)[0] = 0;
47 fEdep.at(i)[0] = 0;
51 }
52}
53
54R3BNeulandMultiplicityBayesPar::R3BNeulandMultiplicityBayesPar(const char* name, const char* title, const char* context)
55 : FairParGenericSet(name, title, context)
56 , fHits({ 1000, 1000, 1000, 1000, 1000, 1000, 1000 })
57 , fClusters({ 1000, 1000, 1000, 1000, 1000, 1000, 1000 })
58 , fEdep({ 1000, 1000, 1000, 1000, 1000, 1000, 1000 })
59 , fIsProperlyLoaded(false)
60{
61}
62
64{
65 // Note: Deleting stuff here or in clear() causes segfaults?
66}
67
69
71{
72 if (!l)
73 {
74 return;
75 }
76
77 for (int i = 0; i < NEULAND_MAX_MULT; i++)
78 {
79 l->add(TString::Format("NeulandMultiplicityBayesParHits-%d", i), fHits.at(i));
80 l->add(TString::Format("NeulandMultiplicityBayesParClusters-%d", i), fClusters.at(i));
81 l->add(TString::Format("NeulandMultiplicityBayesParEdep-%d", i), fEdep.at(i));
82 }
83}
84
86{
87 if (!l)
88 {
89 return false;
90 }
91
92 for (int i = 0; i < NEULAND_MAX_MULT; i++)
93 {
94 l->fill(TString::Format("NeulandMultiplicityBayesParHits-%d", i), &fHits.at(i));
95 l->fill(TString::Format("NeulandMultiplicityBayesParClusters-%d", i), &fClusters.at(i));
96 l->fill(TString::Format("NeulandMultiplicityBayesParEdep-%d", i), &fEdep.at(i));
97 }
98
99 return true;
100}
101
102void R3BNeulandMultiplicityBayesPar::Fill(int n, int nHits, int nClusters, double Edep)
103{
104 fHits.at(n)[nHits]++;
105 fClusters.at(n)[nClusters]++;
106 static constexpr auto SCALE = 10;
107 fEdep.at(n)[static_cast<int>(std::floor(Edep)) / SCALE]++;
108}
109
111 int nClusters,
112 int Edep) const
113{
115 {
117 }
118
119 R3BNeulandMultiplicity::MultiplicityProbabilities mult = { 1, 0, 0, 0, 0, 0, 0 };
120 if (nHits == 0)
121 {
122 return mult;
123 }
124
125 double sum = 0;
126 for (size_t i = 0; i < mult.size(); i++)
127 {
128 mult[i] = fHits.at(i).At(nHits) * fClusters.at(i).At(nClusters) * fEdep.at(i).At(Edep / 10);
129 sum += mult[i];
130 }
131
132 // Normalize so sum prob = 1
133 for (double& i : mult)
134 {
135 i /= sum;
136 }
137 return mult;
138}
139
141{
142 if (std::accumulate(fHits.cbegin(), fHits.cend(), 0, [](int i, const TArrayD& a) { return i + a.GetSum(); }) < 0.1)
143 {
144 LOG(fatal) << "R3BNeulandMultiplicityBayesPar: Empty dataset -> Not properly loaded!";
145 }
146 return true;
147}
148
static constexpr int NEULAND_MAX_MULT
void normalize_TArrayD(TArrayD &a)
ClassImp(R3BNeulandMultiplicityBayesPar)
std::array< TArrayD, NEULAND_MAX_MULT > fHits
R3BNeulandMultiplicityBayesPar(const char *name="R3BNeulandMultiplicityBayesPar", const char *title="Neuland Multiplicity Bayes Parameters", const char *context="TestDefaultContext")
std::array< TArrayD, NEULAND_MAX_MULT > fClusters
R3BNeulandMultiplicity::MultiplicityProbabilities GetProbabilities(int nHits, int nClusters, int Edep) const
Bool_t getParams(FairParamList *) override
std::array< TArrayD, NEULAND_MAX_MULT > fEdep
void Fill(int n, int nHits, int nClusters, double Edep)
std::array< double, NEULAND_MAX_MULT > MultiplicityProbabilities