Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  // Read phantom - Singleton
62  fMyCellParameterisation = CellParameterisation::Instance();
63 
64  // Histograms
65  // Get/create analysis manager
66  G4cout << "##### Create analysis manager " << " " << this << G4endl;
67 
68  G4AnalysisManager* man = G4AnalysisManager::Instance();
69 
70  G4cout << "Using " << man->GetType() << " analysis manager" << G4endl;
71 
72  // Open an output file
73  man->OpenFile("microbeam");
74  man->SetFirstNtupleId(1);
75 
76  //Declare ntuples
77  //
78  // Create 1st ntuple (id = 1)
79  //
80  man->CreateNtuple("ntuple0", "Stopping power");
81  man->CreateNtupleDColumn("e");
82  man->CreateNtupleDColumn("sp");
83  man->FinishNtuple();
84  //G4cout << "Ntuple-1 created" << G4endl;
85 
86  //
87  // Create 2nd ntuple (id = 2)
88  //
89  man->CreateNtuple("ntuple1", "Beam position");
90  man->CreateNtupleDColumn("x");
91  man->CreateNtupleDColumn("y");
92  man->FinishNtuple();
93  //G4cout << "Ntuple-2 created" << G4endl;
94 
95  //
96  // Create 3rd ntuple (id = 3)
97  //
98  man->CreateNtuple("ntuple2", "Range");
99  man->CreateNtupleDColumn("x");
100  man->CreateNtupleDColumn("y");
101  man->CreateNtupleDColumn("z");
102  man->FinishNtuple();
103  //G4cout << "Ntuple-3 created" << G4endl;
104 
105  //
106  // Create 4th ntuple (id = 4)
107  //
108  man->CreateNtuple("ntuple3", "Doses");
109  man->CreateNtupleDColumn("doseN");
110  man->CreateNtupleDColumn("doseC");
111  man->FinishNtuple();
112  //G4cout << "Ntuple-4 created" << G4endl;
113 
114  //
115  // Create 5th ntuple (id = 5)
116  //
117  man->CreateNtuple("ntuple4", "3D");
118  man->CreateNtupleDColumn("x");
119  man->CreateNtupleDColumn("y");
120  man->CreateNtupleDColumn("z");
121  man->CreateNtupleDColumn("doseV");
122  man->FinishNtuple();
123  //G4cout << "Ntuple-3 created" << G4endl;
124 
125  G4cout << "All Ntuples have been created " << G4endl;
126 
127  // save Rndm status
128  if (fSaveRndm > 0)
129  {
131  CLHEP::HepRandom::saveEngineStatus("beginOfRun.rndm");
132  }
133 
134  fNumEvent = 0;
135  fNbOfHitsGas = 0;
136 
137  // ABSORBED DOSES INITIALIZATION
138  fDoseN = 0;
139  fDoseC = 0;
140 
141  fMassCytoplasm = fDetector->GetMassCytoplasm();
142  fMassNucleus = fDetector->GetMassNucleus();
143  fNbOfPixels = fDetector->GetNbOfPixelsInPhantom();
144 
145  fMapVoxels = new G4ThreeVector[fNbOfPixels];
146  fDose3DDose = new G4double[fNbOfPixels];
147 
148  for (G4int i=0; i<fNbOfPixels; i++)
149  {
150  fMapVoxels [i]=fMyCellParameterisation->GetVoxelThreeVector(i);
151  fDose3DDose[i]=0;
152  }
153 
154 }
155 
156 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
157 
158 void RunAction::EndOfRunAction(const G4Run* /*aRun*/)
159 {
160  G4AnalysisManager* man = G4AnalysisManager::Instance();
161 
162  // save Rndm status
163  if (fSaveRndm == 1)
164  {
166  CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
167  }
168 
169  for (G4int i=0; i<fNbOfPixels; i++)
170  {
172  v = fMapVoxels[i];
173  if ( (GetNumEvent()+1) !=0)
174  {
175  //Fill ntuple #5
176  man->FillNtupleDColumn(5,0,v.x());
177  man->FillNtupleDColumn(5,1,v.y());
178  man->FillNtupleDColumn(5,2,v.z());
179  man->FillNtupleDColumn(5,3,fDose3DDose[i]/(GetNumEvent()+1));
180  man->AddNtupleRow(5);
181  }
182  }
183 
184  G4cout << "-> Total number of particles detected by the gas detector : " << GetNbOfHitsGas() << G4endl;
185  G4cout << G4endl;
186 
187  //save histograms
188  man->Write();
189  man->CloseFile();
190 
191  // Complete clean-up
192  delete G4AnalysisManager::Instance();
193 
194 }
G4int GetNbOfHitsGas()
Definition: RunAction.hh:71
G4ThreeVector GetVoxelThreeVector(G4int i)
void BeginOfRunAction(const G4Run *)
Definition: RunAction.cc:57
double x() const
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
tuple v
Definition: test.py:18
static void showEngineStatus()
Definition: Random.cc:303
~RunAction()
Definition: RunAction.cc:52
G4int GetNumEvent()
Definition: RunAction.hh:68
static void saveEngineStatus(const char filename[]="Config.conf")
Definition: Random.cc:275
double y() const
Detector construction class to define materials and geometry.
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4CsvAnalysisManager G4AnalysisManager
Definition: g4csv_defs.hh:77
static CellParameterisation * Instance()