Geant4  10.02
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
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  {
130  CLHEP::HepRandom::showEngineStatus();
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 
144 
147 
148  for (G4int i=0; i<fNbOfPixels; i++)
149  {
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  {
165  CLHEP::HepRandom::showEngineStatus();
166  CLHEP::HepRandom::saveEngineStatus("endOfRun.rndm");
167  }
168 
169  for (G4int i=0; i<fNbOfPixels; i++)
170  {
171  G4ThreeVector v;
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
CLHEP::Hep3Vector G4ThreeVector
G4double * fDose3DDose
Definition: RunAction.hh:99
G4double fDoseC
Definition: RunAction.hh:96
int G4int
Definition: G4Types.hh:78
DetectorConstruction * fDetector
Definition: RunAction.hh:63
G4int fSaveRndm
Definition: RunAction.hh:90
G4GLOB_DLL std::ostream G4cout
G4double fMassCytoplasm
Definition: RunAction.hh:97
void EndOfRunAction(const G4Run *)
Definition: RunAction.cc:260
G4double fDoseN
Definition: RunAction.hh:95
Definition: G4Run.hh:46
G4int fNumEvent
Definition: RunAction.hh:91
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
~RunAction()
Definition: RunAction.cc:52
G4ThreeVector * fMapVoxels
Definition: RunAction.hh:101
G4int fNbOfHitsGas
Definition: RunAction.hh:93
G4int GetNumEvent()
Definition: RunAction.hh:68
CellParameterisation * fMyCellParameterisation
Definition: RunAction.hh:88
G4double fMassNucleus
Definition: RunAction.hh:98
Detector construction class to demonstrate various ways of placement.
#define G4endl
Definition: G4ios.hh:61
G4int fNbOfPixels
Definition: RunAction.hh:92
double G4double
Definition: G4Types.hh:76
static CellParameterisation * Instance()