Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VScoreWriter Class Reference

#include <G4VScoreWriter.hh>

Collaboration diagram for G4VScoreWriter:

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 ( )

Definition at line 40 of file G4VScoreWriter.cc.

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

Definition at line 45 of file G4VScoreWriter.cc.

45  {
46 }

Member Function Documentation

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

Definition at line 152 of file G4VScoreWriter.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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, G4StatDouble*> * 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 << ", total(value) ";
106  if(unit.size() > 0) ofile << "[" << unit << "]";
107  ofile << ", total(val^2), entry" << 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, G4StatDouble*>::iterator value = score->find(idx);
127  if(value == score->end()) {
128  ofile << 0. << "," << 0. << "," << 0;
129  } else {
130  ofile << (value->second->sum_wx())/unitValue << ","
131  << (value->second->sum_wx2())/unitValue/unitValue << ","
132  << value->second->n();
133  }
134 
135  if(opt.find("csv") != std::string::npos) {
136  ofile << G4endl;
137  } else if(opt.find("sequence") != std::string::npos) {
138  ofile << " ";
139  if(count++%5 == 4) ofile << G4endl;
140  }
141 
142  } // z
143  } // y
144  } // x
145  ofile << std::setprecision(6);
146 
147  // close the file
148  ofile.close();
149 
150 }
const G4String & GetWorldName() const
G4double GetPSUnitValue(const G4String &psname)
G4String GetPSUnit(const G4String &psname)
int G4int
Definition: G4Types.hh:78
G4VScoringMesh * fScoringMesh
G4int fNMeshSegments[3]
const XML_Char int const XML_Char * value
Definition: expat.h:331
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4int GetIndex(G4int x, G4int y, G4int z) const
std::ofstream ofile
Definition: clparse.cc:45
void GetDivisionAxisNames(G4String divisionAxisNames[3])
MeshScoreMap GetScoreMap() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
std::map< G4String, RunScore * > MeshScoreMap
G4GLOB_DLL std::ostream G4cerr

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 247 of file G4VScoreWriter.cc.

247  {
248  //return x + y*fNMeshSegments[0] + z*fNMeshSegments[0]*fNMeshSegments[1];
249  return x*fNMeshSegments[1]*fNMeshSegments[2] +y*fNMeshSegments[2]+z;
250 }
G4int fNMeshSegments[3]

Here is the caller graph for this function:

void G4VScoreWriter::SetScoringMesh ( G4VScoringMesh sm)

Definition at line 48 of file G4VScoreWriter.cc.

48  {
49  fScoringMesh = sm;
51 }
void GetNumberOfSegments(G4int nSegment[3])
G4VScoringMesh * fScoringMesh
G4int fNMeshSegments[3]

Here is the call graph for this function:

Here is the caller graph for this function:

void G4VScoreWriter::SetVerboseLevel ( G4int  vl)
inline

Definition at line 59 of file G4VScoreWriter.hh.

59  {
60  verboseLevel = vl;
61  }

Here is the caller graph for this function:

Member Data Documentation

G4int G4VScoreWriter::fNMeshSegments[3]
protected

Definition at line 68 of file G4VScoreWriter.hh.

G4VScoringMesh* G4VScoreWriter::fScoringMesh
protected

Definition at line 69 of file G4VScoreWriter.hh.

G4int G4VScoreWriter::verboseLevel
protected

Definition at line 70 of file G4VScoreWriter.hh.


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