Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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)
45 {
46 fSManager = new G4ScoringManager;
47 }
48 return fSManager;
49}
50
52{ return fSManager; }
53
55 : verboseLevel(0),fCurrentMesh(nullptr)
56{
57 fMessenger = new G4ScoringMessenger(this);
58 fQuantityMessenger = new G4ScoreQuantityMessenger(this);
59 fColorMapDict = new ColorMapDict();
60 fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap");
61 (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap;
62 G4VScoreColorMap * logColorMap = new G4ScoreLogColorMap("logColorMap");
63 (*fColorMapDict)[logColorMap->GetName()] = logColorMap;
64 writer = new G4VScoreWriter();
65}
66
68{
69 if (writer) { delete writer; }
70 delete fDefaultLinearColorMap;
71 delete fColorMapDict;
72 delete fQuantityMessenger;
73 delete fMessenger;
74 fSManager = nullptr;
75}
76
78{ replicaLevel = lvl; }
80{ return replicaLevel; }
81
83{
84 auto sm = FindMesh(map);
85 if(!sm) return;
86 if(verboseLevel>9)
87 { G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / " << map->GetName() << G4endl;
88 G4cout << " is calling G4VScoringMesh::Accumulate() of " << sm->GetWorldName() << G4endl; }
89 sm->Accumulate(static_cast<G4THitsMap<double>*>(map));
90}
91
93{
94 auto colID = map->GetColID();
95 G4VScoringMesh* sm = nullptr;
96 auto msh = fMeshMap.find(colID);
97 if(msh==fMeshMap.end())
98 {
99 auto wName = map->GetSDname();
100 sm = FindMesh(wName);
101 fMeshMap[colID] = sm;
102 }
103 else
104 { sm = (*msh).second; }
105 return sm;
106}
107
109{
110 G4VScoringMesh* sm = nullptr;
111 for(auto msh : fMeshVec)
112 { if(msh->GetWorldName()==wName) return msh; }
113 if(!sm && verboseLevel>9)
114 { G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName << "> is not found. Null returned." << G4endl; }
115 return nullptr;
116}
117
119{
120 G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes." << G4endl;
121 for(auto msh : fMeshVec) msh->List();
122}
123
125{
126 for(auto msh : fMeshVec) msh->Dump();
127}
128
130 const G4String& psName,
131 const G4String& colorMapName, G4int axflg)
132{
133 G4VScoringMesh* mesh = FindMesh(meshName);
134 if(mesh)
135 {
136 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
137 if(!colorMap)
138 {
139 G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
140 colorMap = fDefaultLinearColorMap;
141 }
142 mesh->DrawMesh(psName,colorMap,axflg);
143 } else {
144 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
145 << meshName << "> is not found. Nothing is done." << G4endl;
146 }
147}
148
150 const G4String& psName,
151 G4int idxPlane, G4int iColumn,
152 const G4String& colorMapName)
153{
154 G4VScoringMesh* mesh = FindMesh(meshName);
155 if(mesh)
156 {
157 G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
158 if(!colorMap)
159 {
160 G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
161 colorMap = fDefaultLinearColorMap;
162 }
163 mesh->DrawMesh(psName,idxPlane,iColumn,colorMap);
164 } else {
165 G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
166 << meshName << "> is not found. Nothing is done." << G4endl;
167 }
168}
169
171 const G4String& psName,
172 const G4String& fileName,
173 const G4String& option)
174{
175 G4VScoringMesh* mesh = FindMesh(meshName);
176 if(mesh) {
177 writer->SetScoringMesh(mesh);
178 writer->DumpQuantityToFile(psName, fileName, option);
179 } else {
180 G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <"
181 << meshName << "> is not found. Nothing is done." << G4endl;
182 }
183}
184
186 const G4String& fileName,
187 const G4String& option)
188{
189 G4VScoringMesh* mesh = FindMesh(meshName);
190 if(mesh) {
191 writer->SetScoringMesh(mesh);
192 writer->DumpAllQuantitiesToFile(fileName, option);
193 } else {
194 G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <"
195 << meshName << "> is not found. Nothing is done." << G4endl;
196 }
197}
198
200{
201 if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end())
202 {
203 G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- "
204 << colorMap->GetName() << " has already been registered. Method ignored." << G4endl;
205 }
206 else
207 {
208 (*fColorMapDict)[colorMap->GetName()] = colorMap;
209 }
210}
211
213{
214 ColorMapDictItr mItr = fColorMapDict->find(mapName);
215 if(mItr == fColorMapDict->end()) { return nullptr; }
216 return (mItr->second);
217}
218
220{
221 G4cout << "Registered Score Color Maps -------------------------------------------------------" << G4endl;
222 ColorMapDictItr mItr = fColorMapDict->begin();
223 for(;mItr!=fColorMapDict->end();mItr++)
224 { G4cout << " " << mItr->first; }
225 G4cout << G4endl;
226}
227
229{
230 for(size_t i = 0; i< GetNumberOfMesh() ; i++)
231 {
232 G4VScoringMesh* fMesh = GetMesh(i);
233 G4VScoringMesh* scMesh = mgr->GetMesh(i);
234 fMesh->Merge(scMesh);
235 }
236}
237
238
std::map< G4String, G4VScoreColorMap * >::iterator ColorMapDictItr
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