Geant4-11
Public Member Functions | Protected Member Functions | Protected Attributes
G4VScoreWriter Class Reference

#include <G4VScoreWriter.hh>

Public Member Functions

virtual void DumpAllQuantitiesToFile (const G4String &fileName, const G4String &option)
 
virtual void DumpQuantityToFile (const G4String &psName, const G4String &fileName, const G4String &option)
 
 G4VScoreWriter ()
 
G4double GetFactor () const
 
void SetFactor (G4double val=1.0)
 
void SetScoringMesh (G4VScoringMesh *sm)
 
void SetVerboseLevel (G4int vl)
 
virtual ~G4VScoreWriter ()
 

Protected Member Functions

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

Protected Attributes

G4double fact
 
G4int fNMeshSegments [3]
 
G4VScoringMeshfScoringMesh
 
G4int verboseLevel
 

Detailed Description

Definition at line 40 of file G4VScoreWriter.hh.

Constructor & Destructor Documentation

◆ G4VScoreWriter()

G4VScoreWriter::G4VScoreWriter ( )

Definition at line 39 of file G4VScoreWriter.cc.

40 : fScoringMesh(nullptr)
41 , verboseLevel(0)
42 , fact(1.0)
43{
45}
G4int fNMeshSegments[3]
G4VScoringMesh * fScoringMesh

References fNMeshSegments.

◆ ~G4VScoreWriter()

G4VScoreWriter::~G4VScoreWriter ( )
virtual

Definition at line 47 of file G4VScoreWriter.cc.

47{}

Member Function Documentation

◆ DumpAllQuantitiesToFile()

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

Definition at line 168 of file G4VScoreWriter.cc.

170{
171 // change the option string into lowercase to the case-insensitive.
172 G4String opt = option;
173 std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
174
175 // confirm the option
176 if(opt.size() == 0)
177 opt = "csv";
178 if(opt.find("csv") == std::string::npos &&
179 opt.find("sequence") == std::string::npos)
180 {
181 G4cerr << "ERROR : DumpToFile : Unknown option -> " << option << G4endl;
182 return;
183 }
184
185 // open the file
186 std::ofstream ofile(fileName);
187 if(!ofile)
188 {
189 G4cerr << "ERROR : DumpToFile : File open error -> " << fileName << G4endl;
190 return;
191 }
192 ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
193 if(fact != 1.0)
194 {
195 ofile << "# multiplied factor : " << fact << std::endl;
196 }
197
198 // retrieve the map
199 using MeshScoreMap = G4VScoringMesh::MeshScoreMap;
200 MeshScoreMap fSMap = fScoringMesh->GetScoreMap();
201 MeshScoreMap::const_iterator msMapItr = fSMap.begin();
202 std::map<G4int, G4StatDouble*>* score;
203 for(; msMapItr != fSMap.end(); msMapItr++)
204 {
205 G4String psname = msMapItr->first;
206
207 score = msMapItr->second->GetMap();
208 ofile << "# primitive scorer name: " << msMapItr->first << std::endl;
209
210 G4double unitValue = fScoringMesh->GetPSUnitValue(psname);
211 G4String unit = fScoringMesh->GetPSUnit(psname);
212 G4String divisionAxisNames[3];
213 fScoringMesh->GetDivisionAxisNames(divisionAxisNames);
214 // index order
215 ofile << "# i" << divisionAxisNames[0] << ", i" << divisionAxisNames[1]
216 << ", i" << divisionAxisNames[2];
217 // unit of scored value
218 ofile << ", total(value) ";
219 if(unit.size() > 0)
220 ofile << "[" << unit << "]";
221 ofile << ", total(val^2), entry" << G4endl;
222
223 // "sequence" option: write header info
224 if(opt.find("sequence") != std::string::npos)
225 {
226 ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " "
227 << fNMeshSegments[2] << G4endl;
228 }
229
230 // write quantity
231 long count = 0;
232 ofile << std::setprecision(16); // for double value with 8 bytes
233 for(int x = 0; x < fNMeshSegments[0]; x++)
234 {
235 for(int y = 0; y < fNMeshSegments[1]; y++)
236 {
237 for(int z = 0; z < fNMeshSegments[2]; z++)
238 {
239 G4int idx = GetIndex(x, y, z);
240
241 if(opt.find("csv") != std::string::npos)
242 ofile << x << "," << y << "," << z << ",";
243
244 std::map<G4int, G4StatDouble*>::iterator value = score->find(idx);
245 if(value == score->end())
246 {
247 ofile << 0. << "," << 0. << "," << 0;
248 }
249 else
250 {
251 ofile << (value->second->sum_wx()) / unitValue * fact << ","
252 << (value->second->sum_wx2()) / unitValue / unitValue * fact *
253 fact
254 << "," << value->second->n();
255 }
256
257 if(opt.find("csv") != std::string::npos)
258 {
259 ofile << G4endl;
260 }
261 else if(opt.find("sequence") != std::string::npos)
262 {
263 ofile << " ";
264 if(count++ % 5 == 4)
265 ofile << G4endl;
266 }
267
268 } // z
269 } // y
270 } // x
271 ofile << std::setprecision(6);
272
273 } // for(; msMapItr ....)
274
275 // close the file
276 ofile.close();
277}
double G4double
Definition: G4Types.hh:83
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4int GetIndex(G4int x, G4int y, G4int z) const
G4double GetPSUnitValue(const G4String &psname)
G4String GetPSUnit(const G4String &psname)
const G4String & GetWorldName() const
std::map< G4String, RunScore * > MeshScoreMap
void GetDivisionAxisNames(G4String divisionAxisNames[3])
MeshScoreMap GetScoreMap() const
std::ofstream ofile
Definition: clparse.cc:44
G4bool transform(G4String &input, const G4String &type)

References fact, fNMeshSegments, fScoringMesh, G4cerr, G4endl, G4VScoringMesh::GetDivisionAxisNames(), GetIndex(), G4VScoringMesh::GetPSUnit(), G4VScoringMesh::GetPSUnitValue(), G4VScoringMesh::GetScoreMap(), G4VScoringMesh::GetWorldName(), ofile, and G4coutFormatters::anonymous_namespace{G4coutFormatters.cc}::transform().

Referenced by G4ScoringManager::DumpAllQuantitiesToFile().

◆ DumpQuantityToFile()

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

Definition at line 55 of file G4VScoreWriter.cc.

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

References fact, fNMeshSegments, fScoringMesh, G4cerr, G4endl, G4VScoringMesh::GetDivisionAxisNames(), GetIndex(), G4VScoringMesh::GetPSUnit(), G4VScoringMesh::GetPSUnitValue(), G4VScoringMesh::GetScoreMap(), G4VScoringMesh::GetWorldName(), ofile, and G4coutFormatters::anonymous_namespace{G4coutFormatters.cc}::transform().

Referenced by G4ScoringManager::DumpQuantityToFile().

◆ GetFactor()

G4double G4VScoreWriter::GetFactor ( ) const
inline

Definition at line 60 of file G4VScoreWriter.hh.

60{ return fact; }

References fact.

Referenced by G4ScoringManager::GetFactor().

◆ GetIndex()

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

Definition at line 279 of file G4VScoreWriter.cc.

280{
281 // return x + y*fNMeshSegments[0] + z*fNMeshSegments[0]*fNMeshSegments[1];
282 return x * fNMeshSegments[1] * fNMeshSegments[2] + y * fNMeshSegments[2] + z;
283}

References fNMeshSegments.

Referenced by DumpAllQuantitiesToFile(), and DumpQuantityToFile().

◆ SetFactor()

void G4VScoreWriter::SetFactor ( G4double  val = 1.0)
inline

Definition at line 59 of file G4VScoreWriter.hh.

59{ fact = val; }

References fact.

Referenced by G4ScoringManager::SetFactor().

◆ SetScoringMesh()

void G4VScoreWriter::SetScoringMesh ( G4VScoringMesh sm)

◆ SetVerboseLevel()

void G4VScoreWriter::SetVerboseLevel ( G4int  vl)
inline

Definition at line 58 of file G4VScoreWriter.hh.

58{ verboseLevel = vl; }

References verboseLevel.

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

Field Documentation

◆ fact

G4double G4VScoreWriter::fact
protected

◆ fNMeshSegments

G4int G4VScoreWriter::fNMeshSegments[3]
protected

◆ fScoringMesh

G4VScoringMesh* G4VScoreWriter::fScoringMesh
protected

Definition at line 68 of file G4VScoreWriter.hh.

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

◆ verboseLevel

G4int G4VScoreWriter::verboseLevel
protected

Definition at line 69 of file G4VScoreWriter.hh.

Referenced by SetVerboseLevel().


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