R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandMultiplicityBayes.cxx
Go to the documentation of this file.
2#include "FairRootManager.h"
3#include "FairRtdbRun.h"
4#include "FairRuntimeDb.h"
5#include <numeric>
6
7R3BNeulandMultiplicityBayes::R3BNeulandMultiplicityBayes(std::string_view input, std::string_view output)
8 : FairTask("R3BNeulandMultiplicityBayes")
9 , fClusters(input)
10 , fMultiplicity{ std::make_unique<R3BNeulandMultiplicity>() }
11 , multiplicity_par_ptr{ fMultiplicity.get() }
12 , fOutputName(output)
13{
14}
15
17{
18 // Input
19 fClusters.init();
20
21 // Output
22 auto* ioman = FairRootManager::Instance();
23 if (ioman == nullptr)
24 {
25 LOG(fatal) << "R3BNeulandMultiplicityBayes:Init: No FairRootManager";
26 return kFATAL;
27 }
28 ioman->RegisterAny(fOutputName.c_str(), multiplicity_par_ptr, true);
29
30 return kSUCCESS;
31}
32
34{
35 auto* rtdb = FairRuntimeDb::instance();
36 if (rtdb == nullptr)
37 {
38 LOG(fatal) << "R3BNeulandMultiplicityBayes::SetParContainers: No FairRuntimeDb!";
39 return;
40 }
41
42 fPar = dynamic_cast<R3BNeulandMultiplicityBayesPar*>(rtdb->getContainer("R3BNeulandMultiplicityBayesPar"));
43 if (fPar == nullptr)
44 {
45 LOG(fatal) << "R3BNeulandMultiplicityBayes::SetParContainers: No NeulandMultiplicityBayesPar!";
46 return;
47 }
48
49 // FIXME: FairRuntimeDB needs to be forced to load the Data from the second file with Run Id 1
50 rtdb->initContainers(rtdb->getCurrentRun()->getRunId(), 1);
51}
52
54{
55 const auto& clusters = fClusters.get();
56 const auto nClusters = clusters.size();
57
58 if (nClusters == 0)
59 {
60 fMultiplicity->m.fill(0.);
61 fMultiplicity->m[0] = 1.;
62 return;
63 }
64
65 const auto nHits =
66 std::accumulate(clusters.cbegin(),
67 clusters.cend(),
68 0,
69 [](auto size, const R3BNeulandCluster& cluster) { return size + cluster.GetSize(); });
70 const auto Edep =
71 std::accumulate(clusters.cbegin(),
72 clusters.cend(),
73 0.,
74 [](double energy, const R3BNeulandCluster& cluster) { return energy + cluster.GetE(); });
75
76 fMultiplicity->m = fPar->GetProbabilities(nHits, static_cast<int>(nClusters), static_cast<int>(std::ceil(Edep)));
77}
78
ClassImp(R3B::Neuland::Cal2HitPar)
R3BNeulandMultiplicityBayes(std::string_view input="NeulandClusters", std::string_view output="NeulandMultiplicity")
auto Init() -> InitStatus override