Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4ScoringManager.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28
29#include "G4ScoringManager.hh"
30#include "G4ScoringMessenger.hh"
32#include "G4VScoringMesh.hh"
33#include "G4THitsMap.hh"
34#include "G4VScoreColorMap.hh"
36#include "G4ScoreLogColorMap.hh"
37
38G4ThreadLocal G4ScoringManager* G4ScoringManager::fSManager = nullptr;
39
40G4ThreadLocal G4int G4ScoringManager::replicaLevel = 3;
41
43{
44 if(fSManager == nullptr)
45 {
46 fSManager = new G4ScoringManager;
47 }
48 return fSManager;
49}
50
52{
53 return fSManager;
54}
55
57 : verboseLevel(0)
58 , fCurrentMesh(nullptr)
59{
60 fMessenger = new G4ScoringMessenger(this);
61 fQuantityMessenger = new G4ScoreQuantityMessenger(this);
62 fColorMapDict = new ColorMapDict();
63 fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap");
64 (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap;
65 G4VScoreColorMap* logColorMap = new G4ScoreLogColorMap("logColorMap");
66 (*fColorMapDict)[logColorMap->GetName()] = logColorMap;
67 writer = new G4VScoreWriter();
68}
69
71{
72 delete writer;
73 delete fDefaultLinearColorMap;
74 delete fColorMapDict;
75 delete fQuantityMessenger;
76 delete fMessenger;
77 fSManager = nullptr;
78}
79
80void G4ScoringManager::SetReplicaLevel(G4int lvl) { replicaLevel = lvl; }
81G4int G4ScoringManager::GetReplicaLevel() { return replicaLevel; }
82
84{
85 auto sm = FindMesh(map);
86 if(sm == nullptr)
87 return;
88 if(verboseLevel > 9)
89 {
90 G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / "
91 << map->GetName() << G4endl;
92 G4cout << " is calling G4VScoringMesh::Accumulate() of "
93 << sm->GetWorldName() << G4endl;
94 }
95 sm->Accumulate(static_cast<G4THitsMap<double>*>(map));
96}
97
99{
100 auto colID = map->GetColID();
101 G4VScoringMesh* sm = nullptr;
102 auto msh = fMeshMap.find(colID);
103 if(msh == fMeshMap.end())
104 {
105 auto wName = map->GetSDname();
106 sm = FindMesh(wName);
107 fMeshMap[colID] = sm;
108 }
109 else
110 {
111 sm = (*msh).second;
112 }
113 return sm;
114}
115
117{
118 G4VScoringMesh* sm = nullptr;
119 for(auto msh : fMeshVec)
120 {
121 if(msh->GetWorldName() == wName)
122 return msh;
123 }
124 if((sm == nullptr) && verboseLevel > 9)
125 {
126 G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName
127 << "> is not found. Null returned." << G4endl;
128 }
129 return nullptr;
130}
131
133{
134 G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes."
135 << G4endl;
136 for(auto msh : fMeshVec)
137 msh->List();
138}
139
141{
142 for(auto msh : fMeshVec)
143 msh->Dump();
144}
145
147 const G4String& psName,
148 const G4String& colorMapName, G4int axflg)
149{
150 G4VScoringMesh* mesh = FindMesh(meshName);
151 if(mesh != nullptr)
152 {
153 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
154 if(colorMap == nullptr)
155 {
156 G4cerr << "WARNING : Score color map <" << colorMapName
157 << "> is not found. Default linear color map is used." << G4endl;
158 colorMap = fDefaultLinearColorMap;
159 }
160 mesh->DrawMesh(psName, colorMap, axflg);
161 }
162 else
163 {
164 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" << meshName
165 << "> is not found. Nothing is done." << G4endl;
166 }
167}
168
170 const G4String& psName, G4int idxPlane,
171 G4int iColumn, const G4String& colorMapName)
172{
173 G4VScoringMesh* mesh = FindMesh(meshName);
174 if(mesh != nullptr)
175 {
176 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
177 if(colorMap == nullptr)
178 {
179 G4cerr << "WARNING : Score color map <" << colorMapName
180 << "> is not found. Default linear color map is used." << G4endl;
181 colorMap = fDefaultLinearColorMap;
182 }
183 mesh->DrawMesh(psName, idxPlane, iColumn, colorMap);
184 }
185 else
186 {
187 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" << meshName
188 << "> is not found. Nothing is done." << G4endl;
189 }
190}
191
193 const G4String& psName,
194 const G4String& fileName,
195 const G4String& option)
196{
197 G4VScoringMesh* mesh = FindMesh(meshName);
198 if(mesh != nullptr)
199 {
200 writer->SetScoringMesh(mesh);
201 writer->DumpQuantityToFile(psName, fileName, option);
202 }
203 else
204 {
205 G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <" << meshName
206 << "> is not found. Nothing is done." << G4endl;
207 }
208}
209
211 const G4String& fileName,
212 const G4String& option)
213{
214 G4VScoringMesh* mesh = FindMesh(meshName);
215 if(mesh != nullptr)
216 {
217 writer->SetScoringMesh(mesh);
218 writer->DumpAllQuantitiesToFile(fileName, option);
219 }
220 else
221 {
222 G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <"
223 << meshName << "> is not found. Nothing is done." << G4endl;
224 }
225}
226
228{
229 if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->cend())
230 {
231 G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- "
232 << colorMap->GetName()
233 << " has already been registered. Method ignored." << G4endl;
234 }
235 else
236 {
237 (*fColorMapDict)[colorMap->GetName()] = colorMap;
238 }
239}
240
242{
243 auto mItr = fColorMapDict->find(mapName);
244 if(mItr == fColorMapDict->cend())
245 {
246 return nullptr;
247 }
248 return (mItr->second);
249}
250
252{
253 G4cout << "Registered Score Color Maps "
254 "-------------------------------------------------------"
255 << G4endl;
256 auto mItr = fColorMapDict->cbegin();
257 for(; mItr != fColorMapDict->cend(); ++mItr)
258 {
259 G4cout << " " << mItr->first;
260 }
261 G4cout << G4endl;
262}
263
265{
266 for(G4int i = 0; i < (G4int)GetNumberOfMesh(); ++i)
267 {
268 G4VScoringMesh* fMesh = GetMesh(i);
269 G4VScoringMesh* scMesh = mgr->GetMesh(i);
270 fMesh->Merge(scMesh);
271 }
272}
std::map< G4String, G4VScoreColorMap * > ColorMapDict
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
static G4int GetReplicaLevel()
G4VScoringMesh * GetMesh(G4int i) const
void Accumulate(G4VHitsCollection *map)
static void SetReplicaLevel(G4int)
size_t GetNumberOfMesh() const
G4VScoreColorMap * GetScoreColorMap(const G4String &mapName)
void DumpAllQuantitiesToFile(const G4String &meshName, const G4String &fileName, const G4String &option="")
static G4ScoringManager * GetScoringManager()
G4VScoringMesh * FindMesh(G4VHitsCollection *map)
void RegisterScoreColorMap(G4VScoreColorMap *colorMap)
void DrawMesh(const G4String &meshName, const G4String &psName, const G4String &colorMapName, G4int axflg=111)
void Merge(const G4ScoringManager *scMan)
static G4ScoringManager * GetScoringManagerIfExist()
void DumpQuantityToFile(const G4String &meshName, const G4String &psName, const G4String &fileName, const G4String &option="")
const G4String & GetSDname() const
G4int GetColID() const
const G4String & GetName() const
G4String GetName() const
virtual void DumpQuantityToFile(const G4String &psName, const G4String &fileName, const G4String &option)
virtual void DumpAllQuantitiesToFile(const G4String &fileName, const G4String &option)
void SetScoringMesh(G4VScoringMesh *sm)
void DrawMesh(const G4String &psName, G4VScoreColorMap *colorMap, G4int axflg=111)
void Merge(const G4VScoringMesh *scMesh)
#define G4ThreadLocal
Definition: tls.hh:77