Geant4_10
RunAction.cc
Go to the documentation of this file.
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 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // The Geant4-DNA web site is available at http://geant4-dna.org
31 //
32 // If you use this example, please cite the following publication:
33 // Rad. Prot. Dos. 133 (2009) 2-11
34 
35 #include "G4UImanager.hh"
36 #include "Randomize.hh"
37 
38 #include "RunAction.hh"
39 #include "Analysis.hh"
40 
41 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
42 
44 :fDetector(det)
45 {
46  fSaveRndm = 0;
47 }
48 
49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
50 
52 {
53  delete[] fDose3DDose;
54  delete[] fMapVoxels;
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
58 
60 {
61 
62  // Histograms
63  // Get/create analysis manager
64  G4cout << "##### Create analysis manager " << " " << this << G4endl;
65 
66  G4AnalysisManager* man = G4AnalysisManager::Instance();
67 
68  G4cout << "Using " << man->GetType() << " analysis manager" << G4endl;
69 
70  // Open an output file
71  man->OpenFile("microbeam");
72  man->SetFirstNtupleId(1);
73 
74  //Declare ntuples
75  //
76  // Create 1st ntuple (id = 1)
77  //
78  man->CreateNtuple("ntuple0", "Stopping power");
79  man->CreateNtupleDColumn("e");
80  man->CreateNtupleDColumn("sp");
81  man->FinishNtuple();
82  //G4cout << "Ntuple-1 created" << G4endl;
83 
84  //
85  // Create 2nd ntuple (id = 2)
86  //
87  man->CreateNtuple("ntuple1", "Beam position");
88  man->CreateNtupleDColumn("x");
89  man->CreateNtupleDColumn("y");
90  man->FinishNtuple();
91  //G4cout << "Ntuple-2 created" << G4endl;
92 
93  //
94  // Create 3rd ntuple (id = 3)
95  //
96  man->CreateNtuple("ntuple2", "Range");
97  man->CreateNtupleDColumn("x");
98  man->CreateNtupleDColumn("y");
99  man->CreateNtupleDColumn("z");
100  man->FinishNtuple();
101  //G4cout << "Ntuple-3 created" << G4endl;
102 
103  //
104  // Create 4th ntuple (id = 4)
105  //
106  man->CreateNtuple("ntuple3", "Doses");
107  man->CreateNtupleDColumn("doseN");
108  man->CreateNtupleDColumn("doseC");
109  man->FinishNtuple();
110  //G4cout << "Ntuple-4 created" << G4endl;
111 
112  //
113  // Create 5th ntuple (id = 5)
114  //
115  man->CreateNtuple("ntuple4", "3D");
116  man->CreateNtupleDColumn("x");
117  man->CreateNtupleDColumn("y");
118  man->CreateNtupleDColumn("z");
119  man->CreateNtupleDColumn("doseV");
120  man->FinishNtuple();
121  //G4cout << "Ntuple-3 created" << G4endl;
122 
123  G4cout << "All Ntuples have been created " << G4endl;
124 
125  // save Rndm status
126  if (fSaveRndm > 0)
127  {
129  CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
130  }
131 
132  fNumEvent = 0;
133  fNbOfHitsGas = 0;
134 
135  // ABSORBED DOSES INITIALIZATION
136  fDoseN = 0;
137  fDoseC = 0;
138 
139  fMassCytoplasm = fDetector->GetMassCytoplasm();
140  fMassNucleus = fDetector->GetMassNucleus();
141  fNbOfPixels = fDetector->GetNbOfPixelsInPhantom();
142 
143  fMapVoxels = new G4ThreeVector[fNbOfPixels];
144  fDose3DDose = new G4float[fNbOfPixels];
145 
146  for (G4int i=0; i<fNbOfPixels; i++)
147  {
148  fMapVoxels [i]=fMyPhantomConfiguration.GetVoxelThreeVector(i);
149  fDose3DDose[i]=0;
150  G4ThreeVector v=fMapVoxels[i];
151  }
152 
153 }
154 
155 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
156 
157 void RunAction::EndOfRunAction(const G4Run* /*aRun*/)
158 {
159  G4AnalysisManager* man = G4AnalysisManager::Instance();
160 
161  // save Rndm status
162  if (fSaveRndm == 1)
163  {
165  CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
166  }
167 
168  for (G4int i=0; i<fNbOfPixels; i++)
169  {
171  v = fMapVoxels[i];
172  if ( (GetNumEvent()+1) !=0)
173  {
174  //Fill ntuple #5
175  man->FillNtupleDColumn(5,0,v.x());
176  man->FillNtupleDColumn(5,1,v.y());
177  man->FillNtupleDColumn(5,2,v.z());
178  man->FillNtupleDColumn(5,3,fDose3DDose[i]/(GetNumEvent()+1));
179  man->AddNtupleRow(5);
180  }
181  }
182 
183  G4cout << "-> Total number of particles detected by the gas detector : " << GetNbOfHitsGas() << G4endl;
184  G4cout << G4endl;
185 
186  //save histograms
187  man->Write();
188  man->CloseFile();
189 
190  // Complete clean-up
191  delete G4AnalysisManager::Instance();
192 
193 }
G4int GetNbOfHitsGas()
Definition: RunAction.hh:71
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
double x() const
float G4float
Definition: G4Types.hh:77
int G4int
Definition: G4Types.hh:78
double z() const
G4GLOB_DLL std::ostream G4cout
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
Definition: G4Run.hh:46
G4ThreeVector GetVoxelThreeVector(G4int i)
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:46
tuple v
Definition: test.py:18
static void showEngineStatus()
Definition: Random.cc:203
~RunAction()
Definition: RunAction.cc:52
G4int GetNumEvent()
Definition: RunAction.hh:68
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:175
double y() const
#define G4endl
Definition: G4ios.hh:61