Geant4-11
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
39
41
43{
44 if(!fSManager)
45 {
47 }
48 return fSManager;
49}
50
52{
53 return fSManager;
54}
55
57 : verboseLevel(0)
58 , fCurrentMesh(nullptr)
59{
63 fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap");
65 G4VScoreColorMap* logColorMap = new G4ScoreLogColorMap("logColorMap");
66 (*fColorMapDict)[logColorMap->GetName()] = logColorMap;
67 writer = new G4VScoreWriter();
68}
69
71{
72 if(writer)
73 {
74 delete writer;
75 }
77 delete fColorMapDict;
78 delete fQuantityMessenger;
79 delete fMessenger;
80 fSManager = nullptr;
81}
82
85
87{
88 auto sm = FindMesh(map);
89 if(!sm)
90 return;
91 if(verboseLevel > 9)
92 {
93 G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / "
94 << map->GetName() << G4endl;
95 G4cout << " is calling G4VScoringMesh::Accumulate() of "
96 << sm->GetWorldName() << G4endl;
97 }
98 sm->Accumulate(static_cast<G4THitsMap<double>*>(map));
99}
100
102{
103 auto colID = map->GetColID();
104 G4VScoringMesh* sm = nullptr;
105 auto msh = fMeshMap.find(colID);
106 if(msh == fMeshMap.end())
107 {
108 auto wName = map->GetSDname();
109 sm = FindMesh(wName);
110 fMeshMap[colID] = sm;
111 }
112 else
113 {
114 sm = (*msh).second;
115 }
116 return sm;
117}
118
120{
121 G4VScoringMesh* sm = nullptr;
122 for(auto msh : fMeshVec)
123 {
124 if(msh->GetWorldName() == wName)
125 return msh;
126 }
127 if(!sm && verboseLevel > 9)
128 {
129 G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName
130 << "> is not found. Null returned." << G4endl;
131 }
132 return nullptr;
133}
134
136{
137 G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes."
138 << G4endl;
139 for(auto msh : fMeshVec)
140 msh->List();
141}
142
144{
145 for(auto msh : fMeshVec)
146 msh->Dump();
147}
148
150 const G4String& psName,
151 const G4String& colorMapName, G4int axflg)
152{
153 G4VScoringMesh* mesh = FindMesh(meshName);
154 if(mesh)
155 {
156 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
157 if(!colorMap)
158 {
159 G4cerr << "WARNING : Score color map <" << colorMapName
160 << "> is not found. Default linear color map is used." << G4endl;
161 colorMap = fDefaultLinearColorMap;
162 }
163 mesh->DrawMesh(psName, colorMap, axflg);
164 }
165 else
166 {
167 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" << meshName
168 << "> is not found. Nothing is done." << G4endl;
169 }
170}
171
173 const G4String& psName, G4int idxPlane,
174 G4int iColumn, const G4String& colorMapName)
175{
176 G4VScoringMesh* mesh = FindMesh(meshName);
177 if(mesh)
178 {
179 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
180 if(!colorMap)
181 {
182 G4cerr << "WARNING : Score color map <" << colorMapName
183 << "> is not found. Default linear color map is used." << G4endl;
184 colorMap = fDefaultLinearColorMap;
185 }
186 mesh->DrawMesh(psName, idxPlane, iColumn, colorMap);
187 }
188 else
189 {
190 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" << meshName
191 << "> is not found. Nothing is done." << G4endl;
192 }
193}
194
196 const G4String& psName,
197 const G4String& fileName,
198 const G4String& option)
199{
200 G4VScoringMesh* mesh = FindMesh(meshName);
201 if(mesh)
202 {
203 writer->SetScoringMesh(mesh);
204 writer->DumpQuantityToFile(psName, fileName, option);
205 }
206 else
207 {
208 G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <" << meshName
209 << "> is not found. Nothing is done." << G4endl;
210 }
211}
212
214 const G4String& fileName,
215 const G4String& option)
216{
217 G4VScoringMesh* mesh = FindMesh(meshName);
218 if(mesh)
219 {
220 writer->SetScoringMesh(mesh);
221 writer->DumpAllQuantitiesToFile(fileName, option);
222 }
223 else
224 {
225 G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <"
226 << meshName << "> is not found. Nothing is done." << G4endl;
227 }
228}
229
231{
232 if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end())
233 {
234 G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- "
235 << colorMap->GetName()
236 << " has already been registered. Method ignored." << G4endl;
237 }
238 else
239 {
240 (*fColorMapDict)[colorMap->GetName()] = colorMap;
241 }
242}
243
245{
246 ColorMapDictItr mItr = fColorMapDict->find(mapName);
247 if(mItr == fColorMapDict->end())
248 {
249 return nullptr;
250 }
251 return (mItr->second);
252}
253
255{
256 G4cout << "Registered Score Color Maps "
257 "-------------------------------------------------------"
258 << G4endl;
259 ColorMapDictItr mItr = fColorMapDict->begin();
260 for(; mItr != fColorMapDict->end(); mItr++)
261 {
262 G4cout << " " << mItr->first;
263 }
264 G4cout << G4endl;
265}
266
268{
269 for(size_t i = 0; i < GetNumberOfMesh(); i++)
270 {
271 G4VScoringMesh* fMesh = GetMesh(i);
272 G4VScoringMesh* scMesh = mgr->GetMesh(i);
273 fMesh->Merge(scMesh);
274 }
275}
std::map< G4String, G4VScoreColorMap * > ColorMapDict
std::map< G4String, G4VScoreColorMap * >::iterator ColorMapDictItr
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
ColorMapDict * fColorMapDict
static G4int GetReplicaLevel()
G4VScoreColorMap * fDefaultLinearColorMap
G4VScoringMesh * GetMesh(G4int i) const
G4ScoreQuantityMessenger * fQuantityMessenger
void Accumulate(G4VHitsCollection *map)
static void SetReplicaLevel(G4int)
size_t GetNumberOfMesh() const
G4ScoringMessenger * fMessenger
G4VScoreColorMap * GetScoreColorMap(const G4String &mapName)
void DumpAllQuantitiesToFile(const G4String &meshName, const G4String &fileName, const G4String &option="")
static G4ThreadLocal G4int replicaLevel
static G4ScoringManager * GetScoringManager()
static G4ThreadLocal G4ScoringManager * fSManager
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)
G4VScoreWriter * writer
static G4ScoringManager * GetScoringManagerIfExist()
void DumpQuantityToFile(const G4String &meshName, const G4String &psName, const G4String &fileName, const G4String &option="")
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