Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions
RE03UserScoreWriter Class Reference

#include <RE03UserScoreWriter.hh>

Inheritance diagram for RE03UserScoreWriter:
G4VScoreWriter

Public Member Functions

 RE03UserScoreWriter ()
 
virtual ~RE03UserScoreWriter ()
 
virtual void DumpQuantityToFile (const G4String &psName, const G4String &fileName, const G4String &option)
 
- Public Member Functions inherited from G4VScoreWriter
 G4VScoreWriter ()
 
virtual ~G4VScoreWriter ()
 
virtual void DumpAllQuantitiesToFile (const G4String &fileName, const G4String &option)
 
void SetScoringMesh (G4VScoringMesh *sm)
 
void SetVerboseLevel (G4int vl)
 

Additional Inherited Members

- Protected Member Functions inherited from G4VScoreWriter
G4int GetIndex (G4int x, G4int y, G4int z) const
 
- Protected Attributes inherited from G4VScoreWriter
G4int fNMeshSegments [3]
 
G4VScoringMeshfScoringMesh
 
G4int verboseLevel
 

Detailed Description

Definition at line 43 of file RE03UserScoreWriter.hh.

Constructor & Destructor Documentation

RE03UserScoreWriter::RE03UserScoreWriter ( )

Definition at line 43 of file RE03UserScoreWriter.cc.

44  : G4VScoreWriter()
45 {;}
RE03UserScoreWriter::~RE03UserScoreWriter ( )
virtual

Definition at line 48 of file RE03UserScoreWriter.cc.

49 {;}

Member Function Documentation

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

Reimplemented from G4VScoreWriter.

Definition at line 52 of file RE03UserScoreWriter.cc.

References G4VScoreWriter::fNMeshSegments, G4VScoreWriter::fScoringMesh, G4cerr, G4cout, G4endl, G4VScoreWriter::GetIndex(), G4VScoringMesh::GetScoreMap(), G4VScoringMesh::GetWorldName(), int(), ofile, G4VScoreWriter::verboseLevel, test::x, and z.

54  {
55 
56  //
57  if(verboseLevel > 0) {
58  G4cout << "User-defined DumpQuantityToFile() method is invoked."
59  << G4endl;
60  G4cout << " -- to obtain a projection of the quantity <"
61  << psName
62  << "> onto the x-y plane --" << G4endl;
63  }
64 
65  // change the option string into lowercase to the case-insensitive.
66  G4String opt = option;
67  std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
68 
69  // confirm the option
70  if(opt.size() == 0) opt = "csv";
71 
72  // open the file
73  std::ofstream ofile(fileName);
74  if(!ofile) {
75  G4cerr << "ERROR : DumpToFile : File open error -> "
76  << fileName << G4endl;
77  return;
78  }
79  ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
80 
81 
82  // retrieve the map
84 
85  MeshScoreMap::const_iterator msMapItr = scMap.find(psName);
86  if(msMapItr == scMap.end()) {
87  G4cerr << "ERROR : DumpToFile : Unknown quantity, \""
88  << psName << "\"." << G4endl;
89  return;
90  }
91  std::map<G4int, G4double*> * score = msMapItr->second->GetMap();
92  ofile << "# primitive scorer name: " << msMapItr->first << G4endl;
93 
94  // write header info
95  ofile << "# xy projection" << G4endl;
96  ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << G4endl;
97 
98  // declare xy array
99  std::vector<double> projy;
100  for(int y = 0; y < fNMeshSegments[1]; y++) projy.push_back(0.);
101  std::vector<std::vector<double> > projxy;
102  for(int x = 0; x < fNMeshSegments[0]; x++) projxy.push_back(projy);
103  // accumulate
104  ofile << std::setprecision(16); // for double value with 8 bytes
105  for(int x = 0; x < fNMeshSegments[0]; x++) {
106  for(int y = 0; y < fNMeshSegments[1]; y++) {
107  for(int z = 0; z < fNMeshSegments[2]; z++) {
108 
109  G4int idx = GetIndex(x, y, z);
110 
111  std::map<G4int, G4double*>::iterator value = score->find(idx);
112  if(value != score->end()) projxy[x][y] += *(value->second);
113 
114  } // z
115  } // y
116  } // x
117 
118  // write quantity
119  ofile << std::setprecision(16); // for double value with 8 bytes
120  for(int x = 0; x < fNMeshSegments[0]; x++) {
121  for(int y = 0; y < fNMeshSegments[1]; y++) {
122 
123  ofile << x << "," << y << ",";
124  ofile << projxy[x][y] << G4endl;
125 
126  } // y
127  } // x
128  ofile << std::setprecision(6);
129 
130  // close the file
131  ofile.close();
132 
133 }
const G4String & GetWorldName() const
std::map< G4String, G4THitsMap< G4double > * > MeshScoreMap
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4double z
Definition: TRTMaterials.hh:39
int G4int
Definition: G4Types.hh:78
G4VScoringMesh * fScoringMesh
G4int fNMeshSegments[3]
G4GLOB_DLL std::ostream G4cout
G4int GetIndex(G4int x, G4int y, G4int z) const
std::ofstream ofile
Definition: clparse.cc:45
MeshScoreMap GetScoreMap() const
const XML_Char int const XML_Char * value
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr

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