Geant4  10.03.p01
 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 // $Id: G4ScoringManager.cc 94772 2015-12-09 09:46:45Z gcosmo $
28 //
29 
30 #include "G4ScoringManager.hh"
31 #include "G4ScoringMessenger.hh"
33 #include "G4VScoringMesh.hh"
34 #include "G4THitsMap.hh"
35 #include "G4VScoreColorMap.hh"
37 #include "G4ScoreLogColorMap.hh"
38 
39 G4ThreadLocal G4ScoringManager* G4ScoringManager::fSManager = nullptr;
40 
41 G4ThreadLocal G4int G4ScoringManager::replicaLevel = 3;
42 
44 {
45  if(!fSManager)
46  {
47  fSManager = new G4ScoringManager;
48  }
49  return fSManager;
50 }
51 
53 { return fSManager; }
54 
56  : verboseLevel(0),fCurrentMesh(nullptr)
57 {
58  fMessenger = new G4ScoringMessenger(this);
59  fQuantityMessenger = new G4ScoreQuantityMessenger(this);
60  fColorMapDict = new ColorMapDict();
61  fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap");
62  (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap;
63  G4VScoreColorMap * logColorMap = new G4ScoreLogColorMap("logColorMap");
64  (*fColorMapDict)[logColorMap->GetName()] = logColorMap;
65  writer = new G4VScoreWriter();
66 }
67 
69 {
70  if (writer) { delete writer; }
71  delete fDefaultLinearColorMap;
72  delete fColorMapDict;
73  delete fQuantityMessenger;
74  delete fMessenger;
75  fSManager = nullptr;
76 }
77 
79 { replicaLevel = lvl; }
81 { return replicaLevel; }
82 
84 {
85  auto sm = FindMesh(map);
86  if(!sm) return;
87  if(verboseLevel>9)
88  { G4cout << "G4ScoringManager::Accumulate() for " << map->GetSDname() << " / " << map->GetName() << G4endl;
89  G4cout << " is calling G4VScoringMesh::Accumulate() of " << sm->GetWorldName() << G4endl; }
90  sm->Accumulate(static_cast<G4THitsMap<double>*>(map));
91 }
92 
94 {
95  auto colID = map->GetColID();
96  G4VScoringMesh* sm = nullptr;
97  auto msh = fMeshMap.find(colID);
98  if(msh==fMeshMap.end())
99  {
100  auto wName = map->GetSDname();
101  sm = FindMesh(wName);
102  fMeshMap[colID] = sm;
103  }
104  else
105  { sm = (*msh).second; }
106  return sm;
107 }
108 
110 {
111  G4VScoringMesh* sm = nullptr;
112  for(auto msh : fMeshVec)
113  { if(msh->GetWorldName()==wName) return msh; }
114  if(!sm && verboseLevel>9)
115  { G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName << "> is not found. Null returned." << G4endl; }
116  return nullptr;
117 }
118 
120 {
121  G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes." << G4endl;
122  for(auto msh : fMeshVec) msh->List();
123 }
124 
126 {
127  for(auto msh : fMeshVec) msh->Dump();
128 }
129 
131  const G4String& psName,
132  const G4String& colorMapName, G4int axflg)
133 {
134  G4VScoringMesh* mesh = FindMesh(meshName);
135  if(mesh)
136  {
137  G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
138  if(!colorMap)
139  {
140  G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
141  colorMap = fDefaultLinearColorMap;
142  }
143  mesh->DrawMesh(psName,colorMap,axflg);
144  } else {
145  G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
146  << meshName << "> is not found. Nothing is done." << G4endl;
147  }
148 }
149 
151  const G4String& psName,
152  G4int idxPlane, G4int iColumn,
153  const G4String& colorMapName)
154 {
155  G4VScoringMesh* mesh = FindMesh(meshName);
156  if(mesh)
157  {
158  G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName);
159  if(!colorMap)
160  {
161  G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl;
162  colorMap = fDefaultLinearColorMap;
163  }
164  mesh->DrawMesh(psName,idxPlane,iColumn,colorMap);
165  } else {
166  G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <"
167  << meshName << "> is not found. Nothing is done." << G4endl;
168  }
169 }
170 
172  const G4String& psName,
173  const G4String& fileName,
174  const G4String& option)
175 {
176  G4VScoringMesh* mesh = FindMesh(meshName);
177  if(mesh) {
178  writer->SetScoringMesh(mesh);
179  writer->DumpQuantityToFile(psName, fileName, option);
180  } else {
181  G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <"
182  << meshName << "> is not found. Nothing is done." << G4endl;
183  }
184 }
185 
187  const G4String& fileName,
188  const G4String& option)
189 {
190  G4VScoringMesh* mesh = FindMesh(meshName);
191  if(mesh) {
192  writer->SetScoringMesh(mesh);
193  writer->DumpAllQuantitiesToFile(fileName, option);
194  } else {
195  G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <"
196  << meshName << "> is not found. Nothing is done." << G4endl;
197  }
198 }
199 
201 {
202  if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end())
203  {
204  G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- "
205  << colorMap->GetName() << " has already been registered. Method ignored." << G4endl;
206  }
207  else
208  {
209  (*fColorMapDict)[colorMap->GetName()] = colorMap;
210  }
211 }
212 
214 {
215  ColorMapDictItr mItr = fColorMapDict->find(mapName);
216  if(mItr == fColorMapDict->end()) { return nullptr; }
217  return (mItr->second);
218 }
219 
221 {
222  G4cout << "Registered Score Color Maps -------------------------------------------------------" << G4endl;
223  ColorMapDictItr mItr = fColorMapDict->begin();
224  for(;mItr!=fColorMapDict->end();mItr++)
225  { G4cout << " " << mItr->first; }
226  G4cout << G4endl;
227 }
228 
230 {
231  for(size_t i = 0; i< GetNumberOfMesh() ; i++)
232  {
233  G4VScoringMesh* fMesh = GetMesh(i);
234  G4VScoringMesh* scMesh = mgr->GetMesh(i);
235  fMesh->Merge(scMesh);
236  }
237 }
238 
239 
static void SetReplicaLevel(G4int)
void DrawMesh(const G4String &psName, G4VScoreColorMap *colorMap, G4int axflg=111)
void RegisterScoreColorMap(G4VScoreColorMap *colorMap)
void Merge(const G4VScoringMesh *scMesh)
void Dump() const
void List() const
G4VScoringMesh * FindMesh(G4VHitsCollection *map)
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
void DumpAllQuantitiesToFile(const G4String &meshName, const G4String &fileName, const G4String &option="")
G4String GetName() const
virtual void DumpAllQuantitiesToFile(const G4String &fileName, const G4String &option)
G4GLOB_DLL std::ostream G4cout
static G4ScoringManager * GetScoringManagerIfExist()
static G4int GetReplicaLevel()
G4int GetColID() const
std::map< G4String, G4VScoreColorMap * > ColorMapDict
void Accumulate(G4VHitsCollection *map)
G4VScoreColorMap * GetScoreColorMap(const G4String &mapName)
void Merge(const G4ScoringManager *scMan)
void DrawMesh(const G4String &meshName, const G4String &psName, const G4String &colorMapName, G4int axflg=111)
void SetScoringMesh(G4VScoringMesh *sm)
void DumpQuantityToFile(const G4String &meshName, const G4String &psName, const G4String &fileName, const G4String &option="")
#define G4endl
Definition: G4ios.hh:61
static G4ScoringManager * GetScoringManager()
size_t GetNumberOfMesh() const
std::map< G4String, G4VScoreColorMap * >::iterator ColorMapDictItr
G4VScoringMesh * GetMesh(G4int i) const
G4GLOB_DLL std::ostream G4cerr
G4String & GetSDname()
virtual void DumpQuantityToFile(const G4String &psName, const G4String &fileName, const G4String &option)