Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 /* 28 // Code developed by: 29 // S.Guatelli, susanna@uow.edu.au 30 // 31 Original code from geant4/examples/extended/ru 32 */ 33 34 #include "BrachyUserScoreWriter.hh" 35 #include "G4AnalysisManager.hh" 36 #include "G4MultiFunctionalDetector.hh" 37 #include "G4SDParticleFilter.hh" 38 #include "G4VPrimitiveScorer.hh" 39 #include "G4VScoringMesh.hh" 40 #include "G4SystemOfUnits.hh" 41 #include <map> 42 #include <fstream> 43 // The default output is 44 // voxelX, voxelY, voxelZ, edep 45 // The BrachyUserScoreWriter allows to change 46 // in the specific case: 47 // xx (mm) yy(mm) zz(mm) edep(keV) 48 // The same information is stored in a ntuple, 49 // brachytherapy.root file 50 51 BrachyUserScoreWriter::BrachyUserScoreWriter() 52 G4VScoreWriter() 53 { 54 } 55 56 BrachyUserScoreWriter::~BrachyUserScoreWriter( 57 {;} 58 59 void BrachyUserScoreWriter::DumpQuantityToFile 60 61 62 { 63 using MeshScoreMap = G4VScoringMesh::MeshScore 64 65 if(verboseLevel > 0) 66 {G4cout << "BrachyUserScorer-defined DumpQua 67 << G4endl; 68 } 69 70 // change the option string into lowercase to 71 G4String opt = option; 72 std::transform(opt.begin(), opt.end(), opt.beg 73 74 // confirm the option 75 if(opt.size() == 0) opt = "csv"; 76 77 // open the file 78 std::ofstream ofile(fileName); 79 80 if(!ofile) 81 { 82 G4cerr << "ERROR : DumpToFile : File open e 83 return; 84 } 85 ofile << "# mesh name: " << fScoringMesh->Ge 86 87 // retrieve the map 88 MeshScoreMap fSMap = fScoringMesh -> GetScoreM 89 90 auto msMapItr = fSMap.find(psName); 91 92 if(msMapItr == fSMap.end()) 93 { 94 G4cerr << "ERROR : DumpToFile : Unknown qua 95 << "\"." << G4endl; 96 return; 97 } 98 99 auto score = msMapItr-> second-> GetMap(); 100 101 ofile << "# primitive scorer name: " << msMapI 102 // 103 // Write quantity in the ASCII output file and 104 // 105 ofile << std::setprecision(16); // for double 106 107 auto analysisManager = G4AnalysisManager::Inst 108 109 G4bool fileOpen = analysisManager -> OpenFile( 110 if (! fileOpen) { 111 G4cerr << "\n---> The ROOT output file has 112 << analysisManager->GetFileName() < 113 } 114 115 G4cout << "Using " << analysisManager -> GetTy 116 analysisManager -> SetVerboseLevel(1); 117 analysisManager -> SetActivation(true); 118 119 // Create histograms 120 G4int histo2= analysisManager-> CreateH2("h20" 121 122 // Histo 0 with the energy spectrum will not b 123 // in brachytherapy.root 124 analysisManager->SetH1Activation(0, false); 125 analysisManager->SetH2Activation(histo2, true) 126 127 for(int x = 0; x < fNMeshSegments[0]; x++) { 128 for(int y = 0; y < fNMeshSegments[1]; y++) 129 for(int z = 0; z < fNMeshSegments[2]; z++ 130 G4int numberOfVoxel_x = fNMeshSegments 131 G4int numberOfVoxel_y = fNMeshSegments 132 G4int numberOfVoxel_z =fNMeshSegments[ 133 // If the voxel width is changed in th 134 // the voxel width variable must be up 135 G4double voxelWidth = 0.25 *CLHEP::mm; 136 // 137 G4double xx = ( - numberOfVoxel_x + 1+ 138 G4double yy = ( - numberOfVoxel_y + 1+ 139 G4double zz = ( - numberOfVoxel_z + 1+ 140 G4int idx = GetIndex(x, y, z); 141 std::map<G4int, G4StatDouble*>::iterat 142 143 if (value != score -> end()) 144 { 145 // Print in the ASCII output file the 146 147 ofile << xx << " " << yy << " " << 148 <<(value->second->sum_wx())/keV 149 150 // Save the same information in the RO 151 152 if(zz> -0.125 *CLHEP::mm && zz < 0.125/mm) 153 analysisManager->FillH2(histo2, xx, y 154 }}}} 155 156 ofile << std::setprecision(6); 157 158 // Close the output ASCII file 159 ofile.close(); 160 161 // Close the output ROOT file 162 analysisManager -> Write(); 163 analysisManager -> CloseFile(); 164 } 165