Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // Hadrontherapy advanced example for Geant4 << 23 // $Id: HadrontherapyRunAction.cc,v 1.0 27 // See more at: https://twiki.cern.ch/twiki/bi << 24 // -------------------------------------------------------------- 28 << 25 // GEANT 4 - Hadrontherapy example >> 26 // -------------------------------------------------------------- >> 27 // Code developed by: >> 28 // >> 29 // G.A.P. Cirrone, G. Russo >> 30 // Laboratori Nazionali del Sud - INFN, Catania, Italy >> 31 // >> 32 // -------------------------------------------------------------- 29 #include "HadrontherapyRunAction.hh" 33 #include "HadrontherapyRunAction.hh" 30 #include "HadrontherapyEventAction.hh" << 31 #include "G4AnalysisManager.hh" << 32 #include "G4Run.hh" 34 #include "G4Run.hh" 33 #include "G4RunManager.hh" 35 #include "G4RunManager.hh" 34 #include "G4UImanager.hh" 36 #include "G4UImanager.hh" >> 37 #include "G4VVisManager.hh" 35 #include "G4ios.hh" 38 #include "G4ios.hh" 36 #include "HadrontherapyDetectorConstruction.hh << 39 #include <iomanip.h> 37 #include "G4SDManager.hh" << 40 #include "Randomize.hh" 38 #include "G4Timer.hh" << 39 #include "HadrontherapyRunAction.hh" << 40 #include "HadrontherapyMatrix.hh" << 41 #include "HadrontherapyRBE.hh" << 42 #include "G4UnitsTable.hh" << 43 #include "G4SystemOfUnits.hh" << 44 41 45 #include <G4AccumulableManager.hh> << 42 #ifdef G4ANALYSIS_USE >> 43 #include "HadrontherapyAnalysisManager.hh" >> 44 #endif 46 45 47 ////////////////////////////////////////////// << 46 // --------------------------------------------------------------- 48 HadrontherapyRunAction::HadrontherapyRunAction 47 HadrontherapyRunAction::HadrontherapyRunAction() >> 48 :NbOfLayer(20000) 49 { 49 { 50 G4AccumulableManager* accumulableManager = << 51 accumulableManager->Register(&fRBEAccumula << 52 << 53 } 50 } 54 51 55 ////////////////////////////////////////////// << 52 // --------------------------------------------------------------- 56 HadrontherapyRunAction::~HadrontherapyRunActio 53 HadrontherapyRunAction::~HadrontherapyRunAction() 57 { 54 { >> 55 // delete runMessenger; 58 } 56 } 59 57 60 ////////////////////////////////////////////// << 58 // --------------------------------------------------------------- 61 void HadrontherapyRunAction::BeginOfRunAction( 59 void HadrontherapyRunAction::BeginOfRunAction(const G4Run* aRun) 62 { << 60 { 63 G4AccumulableManager* accumulableManager = << 61 for (G4int i=0; i < 50000; i++) 64 accumulableManager->Reset(); << 65 << 66 G4RunManager::GetRunManager()-> SetRandomN << 67 G4cout << "Run " << aRun -> GetRunID() << << 68 << 69 HadrontherapyRBE *rbe = HadrontherapyRBE:: << 70 if (rbe->IsCalculationEnabled() && IsMaste << 71 { 62 { 72 rbe->PrintParameters(); << 63 energy[i] = 0.0; 73 } << 64 }; >> 65 >> 66 // ---------- Analysis preliminary implentation ------------------ >> 67 // for the registration of the Bragg curve file in a .xml file >> 68 >> 69 #ifdef G4ANALYSIS_USE >> 70 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); >> 71 analysis->book(); >> 72 #endif >> 73 >> 74 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; >> 75 >> 76 // save Rndm status >> 77 G4RunManager::GetRunManager()->SetRandomNumberStore(true); >> 78 HepRandom::showEngineStatus(); >> 79 } >> 80 >> 81 // --------------------------------------------------------------------- >> 82 void HadrontherapyRunAction::EndOfRunAction(const G4Run*) >> 83 { >> 84 // WRITE ASCII FILE FOR THE REGISTRATION OF THE BRAGG PEAK >> 85 // The a two column file (BraggPeak.out) is registered. >> 86 //The first column represents >> 87 // the ionization chamber position (in mm of water); the second >> 88 // is the energy deposited for each position of the chamber >> 89 >> 90 for (G4int i = 0; i < 20000; i++) { 74 91 75 electromagnetic = 0; << 92 G4double depth = 0; 76 hadronic = 0; << 93 depth = i*0.002; //the number represents the thickness of the ionization chamber (in mm ofwater) 77 } << 94 >> 95 std::ofstream pmtfile("BraggPeak.out", std::ios::app); >> 96 if(pmtfile.is_open()) >> 97 >> 98 { >> 99 pmtfile << depth << '\t' << energy[i] << '\t' << G4endl; >> 100 } >> 101 } >> 102 >> 103 >> 104 #ifdef G4ANALYSIS_USE >> 105 HadrontherapyAnalysisManager* analysis = HadrontherapyAnalysisManager::getInstance(); 78 106 79 ////////////////////////////////////////////// << 107 //histogram fill 80 void HadrontherapyRunAction::EndOfRunAction(co << 81 { << 82 auto analysisManager = G4AnalysisManager:: << 83 108 84 G4AccumulableManager* accumulableManager = << 109 analysis -> Energy_Event( slice, energy[ slice ]); 85 accumulableManager->Merge(); << 86 110 87 // Tell the RBE class what we have accumul << 111 for (slice = 0; slice < 200; slice++) 88 HadrontherapyRBE *rbe = HadrontherapyRBE:: << 112 // It is necessary to set here the Number of slice 89 if (rbe->IsCalculationEnabled() && IsMaste << 90 { 113 { 91 if (rbe->IsAccumulationEnabled()) << 114 //G4cout << "%%%%%%%" << slice << "%%%%%" << 92 { << 115 //energy[ slice ] << "%%%%%" << G4endl; 93 rbe->AddAlphaNumerator(fRBEAccumul << 116 94 rbe->AddBetaNumerator(fRBEAccumula << 117 //n-tuple fill 95 rbe->AddDenominator(fRBEAccumulabl << 118 analysis -> Energy_Dep( slice + 0.2, energy[ slice ]); 96 rbe->AddEnergyDeposit(fRBEAccumula << 97 } << 98 else << 99 { << 100 rbe->SetAlphaNumerator(fRBEAccumul << 101 rbe->SetBetaNumerator(fRBEAccumula << 102 rbe->SetDenominator(fRBEAccumulabl << 103 rbe->SetEnergyDeposit(fRBEAccumula << 104 } << 105 << 106 rbe->StoreAlphaAndBeta(); << 107 rbe->StoreRBE(); << 108 } << 109 << 110 if (analysisManager->IsOpenFile()) { << 111 analysisManager->Write(); << 112 analysisManager->CloseFile(); << 113 } 119 } >> 120 analysis -> finish(); >> 121 >> 122 #endif >> 123 >> 124 // show Rndm status >> 125 HepRandom::showEngineStatus(); 114 } 126 } 115 ////////////////////////////////////////////// << 127 116 void HadrontherapyRunAction::AddEMProcess() << 128 // ----------------------------------------------------------------------------- >> 129 void HadrontherapyRunAction::EnergyTotSlice(G4int slice, G4double energy_dep) 117 { 130 { 118 electromagnetic += 1; << 131 energy[ slice ] = energy [ slice ] + energy_dep; >> 132 >> 133 //G4cout << "energy dalla funzione EnergyTotSlice" << energy[slice] >> 134 //<< "slice" << slice << G4endl; >> 135 119 } 136 } 120 << 137 /*void HadrontherapyRunAction::EnergyTotMarkus() 121 ////////////////////////////////////////////// << 122 void HadrontherapyRunAction::AddHadronicProces << 123 { 138 { 124 hadronic += 1; << 139 >> 140 for (G4int i = 0; i < 250; i++) { >> 141 energyMarkus[i] = 0; >> 142 } >> 143 >> 144 for (i = 0; i < 191; i++) { >> 145 for (G4int j = 0; j < 10; j++) { >> 146 energyMarkus[ i ] = energy[ i+j ] + energyMarkus[ i ]; >> 147 } >> 148 } >> 149 125 } 150 } >> 151 */ >> 152 >> 153 >> 154 >> 155 >> 156 >> 157 >> 158 >> 159 >> 160 >> 161 >> 162 >> 163 126 164