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