Geant4 10.7.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)
 
void SetFactor (G4double val=1.0)
 
G4double GetFactor () const
 

Protected Member Functions

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

Protected Attributes

G4int fNMeshSegments [3]
 
G4VScoringMeshfScoringMesh
 
G4int verboseLevel
 
G4double fact
 

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), verboseLevel(0), fact(1.0)
41{
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 153 of file G4VScoreWriter.cc.

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

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 using MeshScoreMap = G4VScoringMesh::MeshScoreMap;
80 // retrieve the map
81 MeshScoreMap fSMap = fScoringMesh->GetScoreMap();
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, G4StatDouble*> * score = msMapItr->second->GetMap();
93 ofile << "# primitive scorer name: " << msMapItr->first << std::endl;
94 if(fact!=1.0)
95 { ofile << "# multiplied factor : " << fact << std::endl; }
96
97 G4double unitValue = fScoringMesh->GetPSUnitValue(psName);
98 G4String unit = fScoringMesh->GetPSUnit(psName);
99 G4String divisionAxisNames[3];
100 fScoringMesh->GetDivisionAxisNames(divisionAxisNames);
101 // index order
102 ofile << "# i" << divisionAxisNames[0]
103 << ", i" << divisionAxisNames[1]
104 << ", i" << divisionAxisNames[2];
105 // unit of scored value
106 ofile << ", total(value) ";
107 if(unit.size() > 0) ofile << "[" << unit << "]";
108 ofile << ", total(val^2), entry" << G4endl;
109
110 // "sequence" option: write header info
111 if(opt.find("sequence") != std::string::npos) {
112 ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << fNMeshSegments[2]
113 << G4endl;
114 }
115
116 // write quantity
117 long count = 0;
118 ofile << std::setprecision(16); // for double value with 8 bytes
119 for(int x = 0; x < fNMeshSegments[0]; x++) {
120 for(int y = 0; y < fNMeshSegments[1]; y++) {
121 for(int z = 0; z < fNMeshSegments[2]; z++) {
122 G4int idx = GetIndex(x, y, z);
123
124 if(opt.find("csv") != std::string::npos)
125 ofile << x << "," << y << "," << z << ",";
126
127 std::map<G4int, G4StatDouble*>::iterator value = score->find(idx);
128 if(value == score->end()) {
129 ofile << 0. << "," << 0. << "," << 0;
130 } else {
131 ofile << (value->second->sum_wx())/unitValue*fact << ","
132 << (value->second->sum_wx2())/unitValue/unitValue*fact*fact << ","
133 << value->second->n();
134 }
135
136 if(opt.find("csv") != std::string::npos) {
137 ofile << G4endl;
138 } else if(opt.find("sequence") != std::string::npos) {
139 ofile << " ";
140 if(count++%5 == 4) ofile << G4endl;
141 }
142
143 } // z
144 } // y
145 } // x
146 ofile << std::setprecision(6);
147
148 // close the file
149 ofile.close();
150
151}

Referenced by G4ScoringManager::DumpQuantityToFile().

◆ GetFactor()

G4double G4VScoreWriter::GetFactor ( ) const
inline

Definition at line 60 of file G4VScoreWriter.hh.

60{ return fact; }

Referenced by G4ScoringManager::GetFactor().

◆ GetIndex()

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

Definition at line 251 of file G4VScoreWriter.cc.

251 {
252 //return x + y*fNMeshSegments[0] + z*fNMeshSegments[0]*fNMeshSegments[1];
253 return x*fNMeshSegments[1]*fNMeshSegments[2] +y*fNMeshSegments[2]+z;
254}

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; }

Referenced by G4ScoringManager::SetFactor().

◆ SetScoringMesh()

void G4VScoreWriter::SetScoringMesh ( G4VScoringMesh sm)

◆ SetVerboseLevel()

void G4VScoreWriter::SetVerboseLevel ( G4int  vl)
inline

Member Data 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: