| 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 | //
|
|---|
| 26 | //
|
|---|
| 27 |
|
|---|
| 28 | #include "RE03UserScoreWriter.hh"
|
|---|
| 29 |
|
|---|
| 30 | #include "G4MultiFunctionalDetector.hh"
|
|---|
| 31 | #include "G4SDParticleFilter.hh"
|
|---|
| 32 | #include "G4VPrimitiveScorer.hh"
|
|---|
| 33 | #include "G4VScoringMesh.hh"
|
|---|
| 34 |
|
|---|
| 35 | #include <map>
|
|---|
| 36 | #include <fstream>
|
|---|
| 37 |
|
|---|
| 38 | RE03UserScoreWriter::RE03UserScoreWriter()
|
|---|
| 39 | : G4VScoreWriter() {
|
|---|
| 40 | ;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | RE03UserScoreWriter::~RE03UserScoreWriter() {
|
|---|
| 44 | ;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | void RE03UserScoreWriter::DumpQuantityToFile(G4String & psName, G4String & fileName, G4String & option) {
|
|---|
| 48 |
|
|---|
| 49 | //
|
|---|
| 50 | if(verboseLevel > 0) {
|
|---|
| 51 | G4cout << "User-defined DumpQuantityToFile() method is invoked."
|
|---|
| 52 | << G4endl;
|
|---|
| 53 | G4cout << " -- to obtain a projection of the quantity <"
|
|---|
| 54 | << psName
|
|---|
| 55 | << "> onto the x-y plane --" << G4endl;
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | // change the option string into lowercase to the case-insensitive.
|
|---|
| 59 | G4String opt = option;
|
|---|
| 60 | std::transform(opt.begin(), opt.end(), opt.begin(), (int (*)(int))(tolower));
|
|---|
| 61 |
|
|---|
| 62 | // confirm the option
|
|---|
| 63 | if(opt.size() == 0) opt = "csv";
|
|---|
| 64 |
|
|---|
| 65 | // open the file
|
|---|
| 66 | std::ofstream ofile(fileName);
|
|---|
| 67 | if(!ofile) {
|
|---|
| 68 | G4cerr << "ERROR : DumpToFile : File open error -> "
|
|---|
| 69 | << fileName << G4endl;
|
|---|
| 70 | return;
|
|---|
| 71 | }
|
|---|
| 72 | ofile << "# mesh name: " << fScoringMesh->GetWorldName() << G4endl;
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | // retrieve the map
|
|---|
| 76 | MeshScoreMap fSMap = fScoringMesh->GetScoreMap();
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 | MeshScoreMap::const_iterator msMapItr = fSMap.find(psName);
|
|---|
| 80 | if(msMapItr == fSMap.end()) {
|
|---|
| 81 | G4cerr << "ERROR : DumpToFile : Unknown quantity, \""
|
|---|
| 82 | << psName << "\"." << G4endl;
|
|---|
| 83 | return;
|
|---|
| 84 | }
|
|---|
| 85 | std::map<G4int, G4double*> * score = msMapItr->second->GetMap();
|
|---|
| 86 | ofile << "# primitive scorer name: " << msMapItr->first << G4endl;
|
|---|
| 87 |
|
|---|
| 88 | // write header info
|
|---|
| 89 | ofile << "# xy projection" << G4endl;
|
|---|
| 90 | ofile << fNMeshSegments[0] << " " << fNMeshSegments[1] << " " << G4endl;
|
|---|
| 91 |
|
|---|
| 92 | // declare xy array
|
|---|
| 93 | std::vector<double> projy;
|
|---|
| 94 | for(int y = 0; y < fNMeshSegments[1]; y++) projy.push_back(0.);
|
|---|
| 95 | std::vector<std::vector<double> > projxy;
|
|---|
| 96 | for(int x = 0; x < fNMeshSegments[0]; x++) projxy.push_back(projy);
|
|---|
| 97 | // accumulate
|
|---|
| 98 | ofile << std::setprecision(16); // for double value with 8 bytes
|
|---|
| 99 | for(int x = 0; x < fNMeshSegments[0]; x++) {
|
|---|
| 100 | for(int y = 0; y < fNMeshSegments[1]; y++) {
|
|---|
| 101 | for(int z = 0; z < fNMeshSegments[2]; z++) {
|
|---|
| 102 |
|
|---|
| 103 | G4int idx = GetIndex(x, y, z);
|
|---|
| 104 |
|
|---|
| 105 | std::map<G4int, G4double*>::iterator value = score->find(idx);
|
|---|
| 106 | if(value != score->end()) projxy[x][y] += *(value->second);
|
|---|
| 107 |
|
|---|
| 108 | } // z
|
|---|
| 109 | } // y
|
|---|
| 110 | } // x
|
|---|
| 111 |
|
|---|
| 112 | // write quantity
|
|---|
| 113 | ofile << std::setprecision(16); // for double value with 8 bytes
|
|---|
| 114 | for(int x = 0; x < fNMeshSegments[0]; x++) {
|
|---|
| 115 | for(int y = 0; y < fNMeshSegments[1]; y++) {
|
|---|
| 116 |
|
|---|
| 117 | ofile << x << "," << y << ",";
|
|---|
| 118 | ofile << projxy[x][y] << G4endl;
|
|---|
| 119 |
|
|---|
| 120 | } // y
|
|---|
| 121 | } // x
|
|---|
| 122 | ofile << std::setprecision(6);
|
|---|
| 123 |
|
|---|
| 124 | // close the file
|
|---|
| 125 | ofile.close();
|
|---|
| 126 |
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|