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,v 1.31 2008/03/25 02:18:38 akimura Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-03 $ |
---|
29 | // |
---|
30 | |
---|
31 | #include "G4ScoringManager.hh" |
---|
32 | #include "G4ScoringMessenger.hh" |
---|
33 | #include "G4ScoreQuantityMessenger.hh" |
---|
34 | #include "G4VScoringMesh.hh" |
---|
35 | #include "G4THitsMap.hh" |
---|
36 | #include "G4VScoreColorMap.hh" |
---|
37 | #include "G4DefaultLinearColorMap.hh" |
---|
38 | #include "G4ScoreLogColorMap.hh" |
---|
39 | |
---|
40 | G4ScoringManager* G4ScoringManager::fSManager = 0; |
---|
41 | |
---|
42 | G4int G4ScoringManager::replicaLevel = 2; |
---|
43 | |
---|
44 | G4ScoringManager* G4ScoringManager::GetScoringManager() |
---|
45 | { |
---|
46 | if(!fSManager) |
---|
47 | { |
---|
48 | fSManager = new G4ScoringManager; |
---|
49 | } |
---|
50 | return fSManager; |
---|
51 | } |
---|
52 | |
---|
53 | G4ScoringManager* G4ScoringManager::GetScoringManagerIfExist() |
---|
54 | { return fSManager; } |
---|
55 | |
---|
56 | G4ScoringManager::G4ScoringManager() |
---|
57 | :verboseLevel(0),fCurrentMesh(0) |
---|
58 | { |
---|
59 | fMessenger = new G4ScoringMessenger(this); |
---|
60 | fQuantityMessenger = new G4ScoreQuantityMessenger(this); |
---|
61 | fColorMapDict = new ColorMapDict(); |
---|
62 | fDefaultLinearColorMap = new G4DefaultLinearColorMap("defaultLinearColorMap"); |
---|
63 | (*fColorMapDict)[fDefaultLinearColorMap->GetName()] = fDefaultLinearColorMap; |
---|
64 | G4VScoreColorMap * logColorMap = new G4ScoreLogColorMap("logColorMap"); |
---|
65 | (*fColorMapDict)[logColorMap->GetName()] = logColorMap; |
---|
66 | writer = new G4VScoreWriter(); |
---|
67 | } |
---|
68 | |
---|
69 | G4ScoringManager::~G4ScoringManager() |
---|
70 | { |
---|
71 | delete fMessenger; |
---|
72 | fSManager = 0; |
---|
73 | if(writer) delete writer; |
---|
74 | } |
---|
75 | |
---|
76 | void G4ScoringManager::SetReplicaLevel(G4int lvl) |
---|
77 | { replicaLevel = lvl; } |
---|
78 | G4int G4ScoringManager::GetReplicaLevel() |
---|
79 | { return replicaLevel; } |
---|
80 | |
---|
81 | void G4ScoringManager::Accumulate(G4VHitsCollection* map) |
---|
82 | { |
---|
83 | G4String wName = map->GetSDname(); |
---|
84 | G4VScoringMesh* sm = FindMesh(wName); |
---|
85 | if(sm == NULL) 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 | |
---|
92 | G4VScoringMesh* G4ScoringManager::FindMesh(G4String wName) |
---|
93 | { |
---|
94 | G4VScoringMesh* sm = 0; |
---|
95 | for(MeshVecItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) { |
---|
96 | G4String smName = (*itr)->GetWorldName(); |
---|
97 | if(wName == smName) { |
---|
98 | sm = *itr; |
---|
99 | break; |
---|
100 | } |
---|
101 | } |
---|
102 | if(!sm && verboseLevel>9) |
---|
103 | { G4cout << "WARNING : G4ScoringManager::FindMesh() --- <" << wName << "> is not found. Null returned." << G4endl; } |
---|
104 | |
---|
105 | return sm; |
---|
106 | } |
---|
107 | |
---|
108 | void G4ScoringManager::List() const |
---|
109 | { |
---|
110 | G4cout << "G4ScoringManager has " << GetNumberOfMesh() << " scoring meshes." << G4endl; |
---|
111 | for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) { |
---|
112 | (*itr)->List(); |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | void G4ScoringManager::Dump() const |
---|
117 | { |
---|
118 | for(MeshVecConstItr itr = fMeshVec.begin(); itr != fMeshVec.end(); itr++) { |
---|
119 | (*itr)->Dump(); |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | void G4ScoringManager::DrawMesh(G4String meshName,G4String psName,G4String colorMapName,G4int axflg) |
---|
124 | { |
---|
125 | G4VScoringMesh* mesh = FindMesh(meshName); |
---|
126 | if(mesh) |
---|
127 | { |
---|
128 | G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName); |
---|
129 | if(!colorMap) |
---|
130 | { |
---|
131 | G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl; |
---|
132 | colorMap = fDefaultLinearColorMap; |
---|
133 | } |
---|
134 | mesh->DrawMesh(psName,colorMap,axflg); |
---|
135 | } else { |
---|
136 | G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" |
---|
137 | << meshName << "> is not found. Nothing is done." << G4endl; |
---|
138 | } |
---|
139 | } |
---|
140 | |
---|
141 | void G4ScoringManager::DrawMesh(G4String meshName,G4String psName,G4int idxPlane,G4int iColumn,G4String colorMapName) |
---|
142 | { |
---|
143 | G4VScoringMesh* mesh = FindMesh(meshName); |
---|
144 | if(mesh) |
---|
145 | { |
---|
146 | G4VScoreColorMap* colorMap = GetScoreColorMap(colorMapName); |
---|
147 | if(!colorMap) |
---|
148 | { |
---|
149 | G4cerr << "WARNING : Score color map <" << colorMapName << "> is not found. Default linear color map is used." << G4endl; |
---|
150 | colorMap = fDefaultLinearColorMap; |
---|
151 | } |
---|
152 | mesh->DrawMesh(psName,idxPlane,iColumn,colorMap); |
---|
153 | } else { |
---|
154 | G4cerr << "ERROR : G4ScoringManager::DrawMesh() --- <" |
---|
155 | << meshName << "> is not found. Nothing is done." << G4endl; |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | void G4ScoringManager::DumpQuantityToFile(G4String meshName,G4String psName,G4String fileName, G4String option) |
---|
160 | { |
---|
161 | G4VScoringMesh* mesh = FindMesh(meshName); |
---|
162 | if(mesh) { |
---|
163 | writer->SetScoringMesh(mesh); |
---|
164 | writer->DumpQuantityToFile(psName, fileName, option); |
---|
165 | } else { |
---|
166 | G4cerr << "ERROR : G4ScoringManager::DrawQuantityToFile() --- <" |
---|
167 | << meshName << "> is not found. Nothing is done." << G4endl; |
---|
168 | } |
---|
169 | } |
---|
170 | |
---|
171 | void G4ScoringManager::DumpAllQuantitiesToFile(G4String meshName,G4String fileName, G4String option) |
---|
172 | { |
---|
173 | G4VScoringMesh* mesh = FindMesh(meshName); |
---|
174 | if(mesh) { |
---|
175 | writer->SetScoringMesh(mesh); |
---|
176 | writer->DumpAllQuantitiesToFile(fileName, option); |
---|
177 | } else { |
---|
178 | G4cerr << "ERROR : G4ScoringManager::DrawAllQuantitiesToFile() --- <" |
---|
179 | << meshName << "> is not found. Nothing is done." << G4endl; |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | void G4ScoringManager::RegisterScoreColorMap(G4VScoreColorMap* colorMap) |
---|
184 | { |
---|
185 | if(fColorMapDict->find(colorMap->GetName()) != fColorMapDict->end()) |
---|
186 | { |
---|
187 | G4cerr << "ERROR : G4ScoringManager::RegisterScoreColorMap -- " |
---|
188 | << colorMap->GetName() << " has already been registered. Method ignored." << G4endl; |
---|
189 | } |
---|
190 | else |
---|
191 | { |
---|
192 | (*fColorMapDict)[colorMap->GetName()] = colorMap; |
---|
193 | } |
---|
194 | } |
---|
195 | |
---|
196 | G4VScoreColorMap* G4ScoringManager::GetScoreColorMap(G4String mapName) |
---|
197 | { |
---|
198 | ColorMapDictItr mItr = fColorMapDict->find(mapName); |
---|
199 | if(mItr == fColorMapDict->end()) { return 0; } |
---|
200 | return (mItr->second); |
---|
201 | } |
---|
202 | |
---|
203 | void G4ScoringManager::ListScoreColorMaps() |
---|
204 | { |
---|
205 | G4cout << "Registered Score Color Maps -------------------------------------------------------" << G4endl; |
---|
206 | ColorMapDictItr mItr = fColorMapDict->begin(); |
---|
207 | for(;mItr!=fColorMapDict->end();mItr++) |
---|
208 | { G4cout << " " << mItr->first; } |
---|
209 | G4cout << G4endl; |
---|
210 | } |
---|
211 | |
---|
212 | |
---|