Warning, file /geant4/examples/extended/runAndEvent/RE03/src/RE03UserScoreWriter.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "RE03UserScoreWriter.hh"
0030
0031 #include "G4MultiFunctionalDetector.hh"
0032 #include "G4SDParticleFilter.hh"
0033 #include "G4VPrimitiveScorer.hh"
0034 #include "G4VScoringMesh.hh"
0035
0036 #include <fstream>
0037 #include <map>
0038
0039
0040 RE03UserScoreWriter::RE03UserScoreWriter() : G4VScoreWriter()
0041 {
0042 ;
0043 }
0044
0045
0046 RE03UserScoreWriter::~RE03UserScoreWriter()
0047 {
0048 ;
0049 }
0050
0051
0052 void RE03UserScoreWriter::DumpQuantityToFile(const G4String& psName, const G4String& fileName,
0053 const G4String& option)
0054 {
0055 using MeshScoreMap = G4VScoringMesh::MeshScoreMap;
0056
0057 if (verboseLevel > 0) {
0058 G4cout << "User-defined DumpQuantityToFile() method is invoked." << G4endl;
0059 G4cout << " -- to obtain a projection of the quantity <" << psName << "> onto the x-y plane --"
0060 << G4endl;
0061 }
0062
0063
0064 G4String opt = option;
0065 std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
0066
0067
0068 if (opt.size() == 0) opt = "csv";
0069
0070
0071 std::ofstream ofile(fileName);
0072 if (!ofile) {
0073 G4cerr << "ERROR : DumpToFile : File open error -> " << fileName << G4endl;
0074 return;
0075 }
0076 ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
0077
0078
0079 MeshScoreMap scMap = fScoringMesh->GetScoreMap();
0080
0081 MeshScoreMap::const_iterator msMapItr = scMap.find(psName);
0082 if (msMapItr == scMap.end()) {
0083 G4cerr << "ERROR : DumpToFile : Unknown quantity, \"" << psName << "\"." << G4endl;
0084 return;
0085 }
0086 std::map<G4int, G4StatDouble*>* score = msMapItr->second->GetMap();
0087 ofile << "# primitive scorer name: " << msMapItr->first << G4endl;
0088
0089
0090 ofile << "# xy projection" << G4endl;
0091 ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << G4endl;
0092
0093
0094 std::vector<double> projy;
0095 for (int y = 0; y < fNMeshSegments[1]; y++)
0096 projy.push_back(0.);
0097 std::vector<std::vector<double>> projxy;
0098 for (int x = 0; x < fNMeshSegments[0]; x++)
0099 projxy.push_back(projy);
0100
0101 ofile << std::setprecision(16);
0102 for (int x = 0; x < fNMeshSegments[0]; x++) {
0103 for (int y = 0; y < fNMeshSegments[1]; y++) {
0104 for (int z = 0; z < fNMeshSegments[2]; z++) {
0105 G4int idx = GetIndex(x, y, z);
0106
0107 std::map<G4int, G4StatDouble*>::iterator value = score->find(idx);
0108 if (value != score->end()) projxy[x][y] += value->second->sum_wx();
0109
0110 }
0111 }
0112 }
0113
0114
0115 ofile << std::setprecision(16);
0116 for (int x = 0; x < fNMeshSegments[0]; x++) {
0117 for (int y = 0; y < fNMeshSegments[1]; y++) {
0118 ofile << x << "," << y << ",";
0119 ofile << projxy[x][y] << G4endl;
0120
0121 }
0122 }
0123 ofile << std::setprecision(6);
0124
0125
0126 ofile.close();
0127 }