File indexing completed on 2025-02-23 09:22:44
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
0030
0031 #include "RE03UserScoreWriter.hh"
0032
0033 #include "G4MultiFunctionalDetector.hh"
0034 #include "G4SDParticleFilter.hh"
0035 #include "G4VPrimitiveScorer.hh"
0036 #include "G4VScoringMesh.hh"
0037
0038 #include <fstream>
0039 #include <map>
0040
0041
0042 RE03UserScoreWriter::RE03UserScoreWriter() : G4VScoreWriter()
0043 {
0044 ;
0045 }
0046
0047
0048 RE03UserScoreWriter::~RE03UserScoreWriter()
0049 {
0050 ;
0051 }
0052
0053
0054 void RE03UserScoreWriter::DumpQuantityToFile(const G4String& psName, const G4String& fileName,
0055 const G4String& option)
0056 {
0057 using MeshScoreMap = G4VScoringMesh::MeshScoreMap;
0058
0059 if (verboseLevel > 0) {
0060 G4cout << "User-defined DumpQuantityToFile() method is invoked." << G4endl;
0061 G4cout << " -- to obtain a projection of the quantity <" << psName << "> onto the x-y plane --"
0062 << G4endl;
0063 }
0064
0065
0066 G4String opt = option;
0067 std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
0068
0069
0070 if (opt.size() == 0) opt = "csv";
0071
0072
0073 std::ofstream ofile(fileName);
0074 if (!ofile) {
0075 G4cerr << "ERROR : DumpToFile : File open error -> " << fileName << G4endl;
0076 return;
0077 }
0078 ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
0079
0080
0081 MeshScoreMap scMap = fScoringMesh->GetScoreMap();
0082
0083 MeshScoreMap::const_iterator msMapItr = scMap.find(psName);
0084 if (msMapItr == scMap.end()) {
0085 G4cerr << "ERROR : DumpToFile : Unknown quantity, \"" << psName << "\"." << G4endl;
0086 return;
0087 }
0088 std::map<G4int, G4StatDouble*>* score = msMapItr->second->GetMap();
0089 ofile << "# primitive scorer name: " << msMapItr->first << G4endl;
0090
0091
0092 ofile << "# xy projection" << G4endl;
0093 ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << G4endl;
0094
0095
0096 std::vector<double> projy;
0097 for (int y = 0; y < fNMeshSegments[1]; y++)
0098 projy.push_back(0.);
0099 std::vector<std::vector<double>> projxy;
0100 for (int x = 0; x < fNMeshSegments[0]; x++)
0101 projxy.push_back(projy);
0102
0103 ofile << std::setprecision(16);
0104 for (int x = 0; x < fNMeshSegments[0]; x++) {
0105 for (int y = 0; y < fNMeshSegments[1]; y++) {
0106 for (int z = 0; z < fNMeshSegments[2]; z++) {
0107 G4int idx = GetIndex(x, y, z);
0108
0109 std::map<G4int, G4StatDouble*>::iterator value = score->find(idx);
0110 if (value != score->end()) projxy[x][y] += value->second->sum_wx();
0111
0112 }
0113 }
0114 }
0115
0116
0117 ofile << std::setprecision(16);
0118 for (int x = 0; x < fNMeshSegments[0]; x++) {
0119 for (int y = 0; y < fNMeshSegments[1]; y++) {
0120 ofile << x << "," << y << ",";
0121 ofile << projxy[x][y] << G4endl;
0122
0123 }
0124 }
0125 ofile << std::setprecision(6);
0126
0127
0128 ofile.close();
0129 }