Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
RE03UserScoreWriter.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
28 //
29 // $Id: RE03UserScoreWriter.cc 99162 2016-09-07 08:14:24Z gcosmo $
30 //
31 
32 #include "RE03UserScoreWriter.hh"
33 
35 #include "G4SDParticleFilter.hh"
36 #include "G4VPrimitiveScorer.hh"
37 #include "G4VScoringMesh.hh"
38 
39 #include <map>
40 #include <fstream>
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44  : G4VScoreWriter()
45 {;}
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 {;}
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53  const G4String & fileName,
54  const G4String & option) {
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, G4StatDouble*> * 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, G4StatDouble*>::iterator value = score->find(idx);
112  if(value != score->end()) projxy[x][y] += value->second->sum_wx();
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 }
134 
Float_t x
Definition: compare.C:6
MeshScoreMap GetScoreMap() const
G4int GetIndex(G4int x, G4int y, G4int z) const
G4VScoringMesh * fScoringMesh
const G4String & GetWorldName() const
G4int fNMeshSegments[3]
#define G4endl
Definition: G4ios.hh:61
Float_t y
Definition: compare.C:6
Double_t z
virtual void DumpQuantityToFile(const G4String &psName, const G4String &fileName, const G4String &option)
const XML_Char int const XML_Char * value
Definition: expat.h:331
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
G4GLOB_DLL std::ostream G4cerr
int G4int
Definition: G4Types.hh:78
std::ofstream ofile
Definition: clparse.cc:45
G4GLOB_DLL std::ostream G4cout
Definition of the RE03UserScoreWriter class.
std::map< G4String, RunScore * > MeshScoreMap