REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Loading...
Searching...
No Matches
TRestGeant4PhysicsInfo.cxx
1
2#include "TRestGeant4PhysicsInfo.h"
3
4#include <iostream>
5
6using namespace std;
7
9
10std::mutex insertMutex;
11
12set<TString> TRestGeant4PhysicsInfo::GetAllParticles() const {
13 set<TString> particles = {};
14 for (const auto& [_, name] : fParticleNamesMap) {
15 particles.insert(name);
16 }
17 return particles;
18}
19
20std::set<TString> TRestGeant4PhysicsInfo::GetAllProcesses() const {
21 set<TString> processes = {};
22 for (const auto& [_, name] : fProcessNamesMap) {
23 processes.insert(name);
24 }
25 return processes;
26}
27
28std::set<TString> TRestGeant4PhysicsInfo::GetAllProcessTypes() const {
29 set<TString> types = {};
30 for (const auto& [_, type] : fProcessTypesMap) {
31 types.insert(type);
32 }
33 return types;
34}
35
36void TRestGeant4PhysicsInfo::PrintParticles() const {
37 const auto particleNames = GetAllParticles();
38 cout << "Particles:" << endl;
39 for (const auto& name : particleNames) {
40 const auto id = GetParticleID(name);
41 cout << "\t" << name << " - " << id << endl;
42 }
43}
44
45void TRestGeant4PhysicsInfo::PrintProcesses() const {
46 const auto processNames = GetAllProcesses();
47 cout << "Processes:" << endl;
48 for (const auto& name : processNames) {
49 const auto id = GetProcessID(name);
50 cout << "\t" << name << " - " << id << endl;
51 }
52}
53
54void TRestGeant4PhysicsInfo::Print() const {
55 PrintParticles();
56 PrintProcesses();
57}
58
59void TRestGeant4PhysicsInfo::InsertProcessName(Int_t id, const TString& processName,
60 const TString& processType) {
61 if (fProcessNamesMap.count(id) > 0) {
62 return;
63 }
64 std::lock_guard<std::mutex> lock(insertMutex);
65 fProcessNamesMap[id] = processName;
66 fProcessNamesReverseMap[processName] = id;
67
68 fProcessTypesMap[processName] = processType;
69}
70
71void TRestGeant4PhysicsInfo::InsertParticleName(Int_t id, const TString& particleName) {
72 if (fParticleNamesMap.count(id) > 0) {
73 return;
74 }
75 std::lock_guard<std::mutex> lock(insertMutex);
76 fParticleNamesMap[id] = particleName;
77 fParticleNamesReverseMap[particleName] = id;
78}
79
80template <typename T, typename U>
81U GetOrDefaultMapValueFromKey(const map<T, U>* pMap, const T& key) {
82 if (pMap->count(key) > 0) {
83 return pMap->at(key);
84 }
85 return {};
86}
87
88TString TRestGeant4PhysicsInfo::GetProcessName(Int_t id) const {
89 return GetOrDefaultMapValueFromKey<Int_t, TString>(&fProcessNamesMap, id);
90}
91
92Int_t TRestGeant4PhysicsInfo::GetProcessID(const TString& processName) const {
93 return GetOrDefaultMapValueFromKey<TString, Int_t>(&fProcessNamesReverseMap, processName);
94}
95
96TString TRestGeant4PhysicsInfo::GetParticleName(Int_t id) const {
97 return GetOrDefaultMapValueFromKey<Int_t, TString>(&fParticleNamesMap, id);
98}
99
100Int_t TRestGeant4PhysicsInfo::GetParticleID(const TString& processName) const {
101 return GetOrDefaultMapValueFromKey<TString, Int_t>(&fParticleNamesReverseMap, processName);
102}
103
104TString TRestGeant4PhysicsInfo::GetProcessType(const TString& processName) const {
105 return GetOrDefaultMapValueFromKey<TString, TString>(&fProcessTypesMap, processName);
106}