Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VScoreWriter Class Reference

#include <G4VScoreWriter.hh>

Public Member Functions

 G4VScoreWriter ()
 
virtual ~G4VScoreWriter ()
 
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 SetVerboseLevel (G4int vl)
 

Protected Member Functions

G4int GetIndex (G4int x, G4int y, G4int z) const
 

Protected Attributes

G4int fNMeshSegments [3]
 
G4VScoringMeshfScoringMesh
 
G4int verboseLevel
 

Detailed Description

Definition at line 41 of file G4VScoreWriter.hh.

Constructor & Destructor Documentation

◆ G4VScoreWriter()

G4VScoreWriter::G4VScoreWriter ( )

Definition at line 40 of file G4VScoreWriter.cc.

41 : fScoringMesh(0), verboseLevel(0) {
43}
G4int fNMeshSegments[3]
G4VScoringMesh * fScoringMesh

◆ ~G4VScoreWriter()

G4VScoreWriter::~G4VScoreWriter ( )
virtual

Definition at line 45 of file G4VScoreWriter.cc.

45 {
46}

Member Function Documentation

◆ DumpAllQuantitiesToFile()

void G4VScoreWriter::DumpAllQuantitiesToFile ( const G4String fileName,
const G4String option 
)
virtual

Definition at line 150 of file G4VScoreWriter.cc.

151 {
152
153 // change the option string into lowercase to the case-insensitive.
154 G4String opt = option;
155 std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
156
157 // confirm the option
158 if(opt.size() == 0) opt = "csv";
159 if(opt.find("csv") == std::string::npos &&
160 opt.find("sequence") == std::string::npos) {
161 G4cerr << "ERROR : DumpToFile : Unknown option -> "
162 << option << G4endl;
163 return;
164 }
165
166 // open the file
167 std::ofstream ofile(fileName);
168 if(!ofile) {
169 G4cerr << "ERROR : DumpToFile : File open error -> "
170 << fileName << G4endl;
171 return;
172 }
173 ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
174
175 // retrieve the map
177 MeshScoreMap::const_iterator msMapItr = fSMap.begin();
178 std::map<G4int, G4double*> * score;
179 for(; msMapItr != fSMap.end(); msMapItr++) {
180
181 G4String psname = msMapItr->first;
182
183 score = msMapItr->second->GetMap();
184 ofile << "# primitive scorer name: " << msMapItr->first << std::endl;
185
186 G4double unitValue = fScoringMesh->GetPSUnitValue(psname);
187 G4String unit = fScoringMesh->GetPSUnit(psname);
188 G4String divisionAxisNames[3];
189 fScoringMesh->GetDivisionAxisNames(divisionAxisNames);
190 // index order
191 ofile << "# i" << divisionAxisNames[0]
192 << ", i" << divisionAxisNames[1]
193 << ", i" << divisionAxisNames[2];
194 // unit of scored value
195 ofile << ", value ";
196 if(unit.size() > 0) ofile << "[" << unit << "]";
197 ofile << G4endl;
198
199
200 // "sequence" option: write header info
201 if(opt.find("sequence") != std::string::npos) {
202 ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << fNMeshSegments[2]
203 << G4endl;
204 }
205
206 // write quantity
207 long count = 0;
208 ofile << std::setprecision(16); // for double value with 8 bytes
209 for(int x = 0; x < fNMeshSegments[0]; x++) {
210 for(int y = 0; y < fNMeshSegments[1]; y++) {
211 for(int z = 0; z < fNMeshSegments[2]; z++) {
212 G4int idx = GetIndex(x, y, z);
213
214 if(opt.find("csv") != std::string::npos)
215 ofile << x << "," << y << "," << z << ",";
216
217 std::map<G4int, G4double*>::iterator value = score->find(idx);
218 if(value == score->end()) {
219 ofile << 0.;
220 } else {
221 ofile << *(value->second)/unitValue;
222 }
223
224 if(opt.find("csv") != std::string::npos) {
225 ofile << G4endl;
226 } else if(opt.find("sequence") != std::string::npos) {
227 ofile << " ";
228 if(count++%5 == 4) ofile << G4endl;
229 }
230
231 } // z
232 } // y
233 } // x
234 ofile << std::setprecision(6);
235
236 } // for(; msMapItr ....)
237
238 // close the file
239 ofile.close();
240
241}
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
std::map< G4String, G4THitsMap< G4double > * > MeshScoreMap
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4int first(char) const
G4int GetIndex(G4int x, G4int y, G4int z) const
G4double GetPSUnitValue(const G4String &psname)
G4String GetPSUnit(const G4String &psname)
MeshScoreMap GetScoreMap()
const G4String & GetWorldName() const
void GetDivisionAxisNames(G4String divisionAxisNames[3])
std::ofstream ofile
Definition: clparse.cc:45

Referenced by G4ScoringManager::DumpAllQuantitiesToFile().

◆ DumpQuantityToFile()

void G4VScoreWriter::DumpQuantityToFile ( const G4String psName,
const G4String fileName,
const G4String option 
)
virtual

Definition at line 53 of file G4VScoreWriter.cc.

55 {
56
57 // change the option string into lowercase to the case-insensitive.
58 G4String opt = option;
59 std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
60
61 // confirm the option
62 if(opt.size() == 0) opt = "csv";
63 if(opt.find("csv") == std::string::npos &&
64 opt.find("sequence") == std::string::npos) {
65 G4cerr << "ERROR : DumpToFile : Unknown option -> "
66 << option << G4endl;
67 return;
68 }
69
70 // open the file
71 std::ofstream ofile(fileName);
72 if(!ofile) {
73 G4cerr << "ERROR : DumpToFile : File open error -> "
74 << fileName << G4endl;
75 return;
76 }
77 ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
78
79
80 // retrieve the map
82
83
84 MeshScoreMap::const_iterator msMapItr = fSMap.find(psName);
85 if(msMapItr == fSMap.end()) {
86 G4cerr << "ERROR : DumpToFile : Unknown quantity, \""
87 << psName << "\"." << G4endl;
88 return;
89 }
90
91
92 std::map<G4int, G4double*> * score = msMapItr->second->GetMap();
93 ofile << "# primitive scorer name: " << msMapItr->first << std::endl;
94
95
96 G4double unitValue = fScoringMesh->GetPSUnitValue(psName);
97 G4String unit = fScoringMesh->GetPSUnit(psName);
98 G4String divisionAxisNames[3];
99 fScoringMesh->GetDivisionAxisNames(divisionAxisNames);
100 // index order
101 ofile << "# i" << divisionAxisNames[0]
102 << ", i" << divisionAxisNames[1]
103 << ", i" << divisionAxisNames[2];
104 // unit of scored value
105 ofile << ", value ";
106 if(unit.size() > 0) ofile << "[" << unit << "]";
107 ofile << G4endl;
108
109 // "sequence" option: write header info
110 if(opt.find("sequence") != std::string::npos) {
111 ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << fNMeshSegments[2]
112 << G4endl;
113 }
114
115 // write quantity
116 long count = 0;
117 ofile << std::setprecision(16); // for double value with 8 bytes
118 for(int x = 0; x < fNMeshSegments[0]; x++) {
119 for(int y = 0; y < fNMeshSegments[1]; y++) {
120 for(int z = 0; z < fNMeshSegments[2]; z++) {
121 G4int idx = GetIndex(x, y, z);
122
123 if(opt.find("csv") != std::string::npos)
124 ofile << x << "," << y << "," << z << ",";
125
126 std::map<G4int, G4double*>::iterator value = score->find(idx);
127 if(value == score->end()) {
128 ofile << 0.;
129 } else {
130 ofile << *(value->second)/unitValue;
131 }
132
133 if(opt.find("csv") != std::string::npos) {
134 ofile << G4endl;
135 } else if(opt.find("sequence") != std::string::npos) {
136 ofile << " ";
137 if(count++%5 == 4) ofile << G4endl;
138 }
139
140 } // z
141 } // y
142 } // x
143 ofile << std::setprecision(6);
144
145 // close the file
146 ofile.close();
147
148}

Referenced by G4ScoringManager::DumpQuantityToFile().

◆ GetIndex()

G4int G4VScoreWriter::GetIndex ( G4int  x,
G4int  y,
G4int  z 
) const
protected

Definition at line 243 of file G4VScoreWriter.cc.

243 {
244 //return x + y*fNMeshSegments[0] + z*fNMeshSegments[0]*fNMeshSegments[1];
245 return x*fNMeshSegments[1]*fNMeshSegments[2] +y*fNMeshSegments[2]+z;
246}

Referenced by DumpAllQuantitiesToFile(), and DumpQuantityToFile().

◆ SetScoringMesh()

void G4VScoreWriter::SetScoringMesh ( G4VScoringMesh sm)

◆ SetVerboseLevel()

void G4VScoreWriter::SetVerboseLevel ( G4int  vl)
inline

Definition at line 59 of file G4VScoreWriter.hh.

59 {
60 verboseLevel = vl;
61 }

Referenced by G4ScoringManager::SetScoreWriter(), and G4ScoringManager::SetVerboseLevel().

Member Data Documentation

◆ fNMeshSegments

G4int G4VScoreWriter::fNMeshSegments[3]
protected

◆ fScoringMesh

G4VScoringMesh* G4VScoreWriter::fScoringMesh
protected

Definition at line 69 of file G4VScoreWriter.hh.

Referenced by DumpAllQuantitiesToFile(), DumpQuantityToFile(), and SetScoringMesh().

◆ verboseLevel

G4int G4VScoreWriter::verboseLevel
protected

Definition at line 70 of file G4VScoreWriter.hh.

Referenced by SetVerboseLevel().


The documentation for this class was generated from the following files: