R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BNeulandNeutronsRValue.cxx
Go to the documentation of this file.
2#include "R3BException.h"
3#include "R3BNeulandCluster.h"
5#include <FairRootManager.h>
6#include <FairTask.h>
7#include <IsElastic.h>
8#include <Rtypes.h>
9#include <RtypesCore.h>
10#include <algorithm>
11#include <cstddef>
12#include <cstdlib>
13#include <map>
14#include <string_view>
15#include <vector>
16
18 std::string_view inputMult,
19 std::string_view inputCluster,
20 std::string_view output)
21 : FairTask("R3BNeulandNeutronsRValue")
22 , fEkinRefMeV(EkinRefMeV)
23 , fInputMultName(inputMult)
24 , fMultiplicity(nullptr)
25 , fClusters(inputCluster)
26 , fNeutrons(output)
27{
28}
29
31{
32 auto* ioman = FairRootManager::Instance();
33 if (ioman == nullptr)
34 {
35 throw R3B::runtime_error("TCAInputConnector: No FairRootManager");
36 }
37 fMultiplicity = ioman->InitObjectAs<const R3BNeulandMultiplicity*>(fInputMultName.c_str());
38
39 fClusters.init();
40 fNeutrons.init();
41 return kSUCCESS;
42}
43
44void R3BNeulandNeutronsRValue::Exec(Option_t* /*option*/)
45{
46 fNeutrons.clear();
47 cluster_buffer_.clear();
48
50
51 // Recreate R3BNeutronTracker2D Advanced Method
52 // FilterClustersByElasticScattering(clusters); // Check all pairs of clusters. Remove clusters from elastic
53 // scattering FilterClustersByEnergyDeposit(clusters); FilterClustersByKineticEnergy(clusters);
56
57 const auto mult = fMultiplicity->GetMultiplicity();
58 for (size_t index = 0; index < cluster_buffer_.size() && index < mult; index++)
59 {
60 fNeutrons.get().emplace_back(cluster_buffer_.at(index));
61 }
62}
63
64void R3BNeulandNeutronsRValue::SortClustersByRValue(std::vector<R3BNeulandCluster>& clusters) const
65{
66 std::sort(clusters.begin(),
67 clusters.end(),
68 [this](const R3BNeulandCluster& one, const R3BNeulandCluster& other)
69 { return one.GetRECluster(fEkinRefMeV) < other.GetRECluster(fEkinRefMeV); });
70}
71
72void R3BNeulandNeutronsRValue::PrioritizeTimeWiseFirstCluster(std::vector<R3BNeulandCluster>& clusters)
73{
74 auto timewiseFirstCluster = std::min_element(clusters.begin(),
75 clusters.end(),
76 [](const R3BNeulandCluster& one, const R3BNeulandCluster& other)
77 { return one.GetT() < other.GetT(); });
78 // Put first cluster in front
79 std::rotate(clusters.begin(), timewiseFirstCluster, timewiseFirstCluster + 1);
80}
81
82void R3BNeulandNeutronsRValue::FilterClustersByEnergyDeposit(std::vector<R3BNeulandCluster>& clusters)
83{
84 static constexpr auto threshold = 2.5;
85 clusters.erase(std::remove_if(clusters.begin(),
86 clusters.end(),
87 [&](const R3BNeulandCluster& cluster) { return cluster.GetE() < threshold; }),
88 clusters.end());
89}
90
91void R3BNeulandNeutronsRValue::FilterClustersByKineticEnergy(std::vector<R3BNeulandCluster>& clusters) const
92{
93 static constexpr auto threshold = 0.05;
94 clusters.erase(std::remove_if(clusters.begin(),
95 clusters.end(),
96 [this](const R3BNeulandCluster& cluster)
97 { return std::abs(cluster.GetEToF() - fEkinRefMeV) / fEkinRefMeV > threshold; }),
98 clusters.end());
99}
100
101void R3BNeulandNeutronsRValue::FilterClustersByElasticScattering(std::vector<R3BNeulandCluster>& clusters)
102{
103 std::map<const R3BNeulandCluster*, bool> marked;
104
105 for (const auto& cluster : clusters)
106 {
107 marked[&cluster] = false;
108 }
109
110 for (const auto& one_cluster : clusters)
111 {
112 for (const auto& other_cluster : clusters)
113 {
114 if (&one_cluster != &other_cluster && one_cluster.GetT() < other_cluster.GetT() &&
115 Neuland::IsElastic(&one_cluster, &other_cluster))
116 {
117 marked[&other_cluster] = true;
118 }
119 }
120 }
121
122 clusters.erase(
123 std::remove_if(
124 clusters.begin(), clusters.end(), [&](const R3BNeulandCluster& cluster) { return marked.at(&cluster); }),
125 clusters.end());
126}
127
ClassImp(R3B::Neuland::Cal2HitPar)
static void FilterClustersByEnergyDeposit(std::vector< R3BNeulandCluster > &)
void Exec(Option_t *) override
void SortClustersByRValue(std::vector< R3BNeulandCluster > &) const
auto Init() -> InitStatus override
static void PrioritizeTimeWiseFirstCluster(std::vector< R3BNeulandCluster > &)
R3B::InputVectorConnector< R3BNeulandCluster > fClusters
static void FilterClustersByElasticScattering(std::vector< R3BNeulandCluster > &)
R3BNeulandNeutronsRValue(double EkinRefMeV, std::string_view inputMult="NeulandMultiplicity", std::string_view inputCluster="NeulandClusters", std::string_view output="NeulandNeutrons")
std::vector< R3BNeulandCluster > cluster_buffer_
const R3BNeulandMultiplicity * fMultiplicity
R3B::OutputVectorConnector< R3BNeulandNeutron > fNeutrons
void FilterClustersByKineticEnergy(std::vector< R3BNeulandCluster > &) const
bool IsElastic(const R3BNeulandCluster *, const R3BNeulandCluster *)
Definition IsElastic.cxx:19