source: trunk/source/digits_hits/utils/src/G4ScoringManager.cc@ 817

Last change on this file since 817 was 814, checked in by garnier, 17 years ago

import all except CVS

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