ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HadrontherapyRunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HadrontherapyRunAction.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 //
26 // Hadrontherapy advanced example for Geant4
27 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
28 
31 #include "HadrontherapyAnalysis.hh"
32 #include "G4Run.hh"
33 #include "G4RunManager.hh"
34 #include "G4UImanager.hh"
35 #include "G4ios.hh"
37 #include "G4SDManager.hh"
38 #include "G4Timer.hh"
40 #include "HadrontherapyMatrix.hh"
41 #include "HadrontherapyRBE.hh"
42 #include "G4UnitsTable.hh"
43 #include "G4SystemOfUnits.hh"
44 
45 #include <G4AccumulableManager.hh>
46 
49 {
51  accumulableManager->RegisterAccumulable(&fRBEAccumulable);
52 
53  // Create analysis manager
54  // The choice of analysis technology is done via selectin of a namespace
55  // in Analysis.hh
56  auto analysisManager =G4AnalysisManager::Instance();
57  G4cout << "Using " << analysisManager -> GetType() << G4endl;
58 
59  analysisManager->SetVerboseLevel(1);
60  analysisManager->SetFirstHistoId(1);
61 
62  // Comment out the following line to generate an N-tuple
63  analysisManager-> SetFirstNtupleId(2);
64 
65  // Creating the histograms of primary kinetic
66  // energy (Ekin) and of the energy deposited (Edep)
67  // in the first voxel/slice of the water phantom
68  analysisManager -> CreateH1("Ekin","Ekin the voxel", 400,20*MeV, 60*MeV);
69  analysisManager -> CreateH1("Edep","Edep the voxel", 200, -10, 10*MeV);
70 
71  // Example of how to create an Ntuple (comment-out, if needed)
72  //analysisManager->CreateNtuple("NYUPLA", "Edep and TrackL");
73  //analysisManager->CreateNtupleDColumn("Ekin");
74 
75 }
76 
79 {
81 }
82 
85 {
86 
87  // Get analysis manager
88  auto analysisManager = G4AnalysisManager::Instance();
89 
90  // Open an output file
91  //
92  G4String fileName = "Hadrontherapy";
93  analysisManager->OpenFile(fileName);
94 
96  accumulableManager->Reset();
97 
98  G4RunManager::GetRunManager()-> SetRandomNumberStore(true);
99  G4cout << "Run " << aRun -> GetRunID() << " starts ..." << G4endl;
100 
102  if (rbe->IsCalculationEnabled() && IsMaster() && rbe->GetVerboseLevel() > 0)
103  {
104  rbe->PrintParameters();
105  }
106 
107  electromagnetic = 0;
108  hadronic = 0;
109 }
110 
113 {
114  auto analysisManager = G4AnalysisManager::Instance();
115 
116  //G4cout << " Summary of Run " << aRun -> GetRunID() <<" :"<< G4endl;
117  //G4cout << "Number of electromagnetic processes of primary particles in the phantom:"
118  // << electromagnetic << G4endl;
119  //G4cout << "Number of hadronic processes of primary particles in the phantom:"
120  // << hadronic << G4endl;
122  accumulableManager->Merge();
123 
124  // Tell the RBE class what we have accumulated...
126  if (rbe->IsCalculationEnabled() && IsMaster())
127  {
128  if (rbe->IsAccumulationEnabled())
129  {
134  }
135  else
136  {
141  }
142 
143  rbe->StoreAlphaAndBeta();
144  rbe->StoreRBE();
145  }
146 
147  analysisManager->Write();
148  analysisManager->CloseFile();
149 
150 }
153 {
154  electromagnetic += 1;
155 }
156 
159 {
160  hadronic += 1;
161 }