ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RunAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RunAction.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 // 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 // and papers
31 // M. Batmunkh et al. J Radiat Res Appl Sci 8 (2015) 498-507
32 // O. Belov et al. Physica Medica 32 (2016) 1510-1520
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // -------------------------------------------------------------------
36 // November 2016
37 // -------------------------------------------------------------------
38 //
41 
42 #include "RunAction.hh"
43 #include "G4Run.hh"
44 #include "TrackingAction.hh"
45 #include "G4ParticleDefinition.hh"
46 #include "G4RunManager.hh"
47 #include "Analysis.hh"
48 #include "G4Threading.hh"
49 #include "CommandLineParser.hh"
50 //#include "NeuronLoadDataFile.hh"
51 #include "Run.hh"
52 #include "Randomize.hh"
53 #include <iomanip>
54 #include "G4UnitsTable.hh"
55 #include "G4SystemOfUnits.hh"
56 #include "G4UImanager.hh"
57 #include "DetectorConstruction.hh"
58 #include "PrimaryGeneratorAction.hh"
59 #include "G4RunManager.hh"
60 #include "G4UImanager.hh"
61 
62 using namespace G4DNAPARSER;
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 
67 : G4UserRunAction(), //fpTrackingAction(0), fInitialized(0),
68  fDebug(false),
69 fDetector(det),fPrimary(prim),fRun(0)
70 {
71  //CreateHistogram();
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  //delete G4AnalysisManager::Instance();
79 }
80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81 
83 {
84  fRun = new Run(fDetector);
85  return fRun;
86 }
87 
88 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
89 
90 void RunAction::BeginOfRunAction(const G4Run* /*run*/)
91 {
92 
94 
95  // keep run condition
96  if ( fPrimary ) {
100  fRun->SetPrimary(particle, energy);
101  }
102 
103 /*
104  G4cout << "##### Create analysis manager " << " " << this << G4endl;
105  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
106  analysisManager->SetFirstHistoId(1);
107 // if(!analysisManager->IsActive()) {return; }
108 
109  G4cout << "Using " << analysisManager->GetType() <<
110  " analysis manager" << G4endl;
111  // Open an output file
112  analysisManager->OpenFile("neuronG4");
113  G4cout << "\n----> Histogram file is opened in neuronG4" <<
114  "." << analysisManager->GetFileType() << G4endl;
115 // -----------------------------------------------------
116  //Declare ntuples
117  //
118  // Create 1st ntuple (id = 1)
119  //
120  analysisManager->CreateNtuple("ntuple0", "Soma3D");
121  analysisManager->CreateNtupleDColumn("ind");
122  analysisManager->CreateNtupleDColumn("dist");
123  analysisManager->CreateNtupleDColumn("edep");
124  analysisManager->CreateNtupleDColumn("dose");
125  analysisManager->FinishNtuple();
126  //G4cout << "Ntuple-1 created" << G4endl;
127 
128  // Create 2nd ntuple (id = 2)
129  //
130  analysisManager->CreateNtuple("ntuple1", "Dend3D");
131  analysisManager->CreateNtupleDColumn("indD");
132  analysisManager->CreateNtupleDColumn("distD");
133  analysisManager->CreateNtupleDColumn("edepD");
134  analysisManager->CreateNtupleDColumn("doseD");
135  analysisManager->FinishNtuple();
136  //G4cout << "Ntuple-2 created" << G4endl;
137 
138  // Create 3rd ntuple (id = 3)
139  //
140  analysisManager->CreateNtuple("ntuple2", "Axon3D");
141  analysisManager->CreateNtupleDColumn("indA");
142  analysisManager->CreateNtupleDColumn("distA");
143  analysisManager->CreateNtupleDColumn("edepA");
144  analysisManager->CreateNtupleDColumn("doseA");
145  analysisManager->FinishNtuple();
146  //G4cout << "Ntuple-3 created" << G4endl;
147 
148  // Create 4rd ntuple (id = 4)
149  //
150  analysisManager->CreateNtuple("ntuple3", "Outputs per event");
151  analysisManager->CreateNtupleDColumn("EdepAll");
152  analysisManager->CreateNtupleDColumn("EdepMed");
153  analysisManager->CreateNtupleDColumn("EdepSlice");
154  analysisManager->CreateNtupleDColumn("EdepNeuron");
155  analysisManager->FinishNtuple();
156  //G4cout << "Ntuple-4 created" << G4endl;
157  // ............................
158  G4cout << "All Ntuples have been created " << G4endl;
159 */
160 }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
163 
164 void RunAction::EndOfRunAction(const G4Run* /*run*/)
165 {
166 
167  if (isMaster) fRun->EndOfRun();
168 
169 // save histogramms
170 /* G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
171  //save histograms
172  analysisManager->Write();
173  analysisManager->CloseFile();
174  // Complete clean-up
175  delete G4AnalysisManager::Instance();
176 */
177 
178 }
179 
180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
181 
183 {
184  // Book histograms, ntuple
185 
186  // Create analysis manager
187  // The choice of analysis technology is done via selection of a namespace
188  // in Analysis.hh
189 
190  CommandLineParser* parser = CommandLineParser::GetParser();
191  Command* command(0);
192  if((command = parser->GetCommandIfActive("-out"))==0) return;
193 //
194 // Declare ntuples
195 }
196 
197 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
198 
200 {
201  CommandLineParser* parser = CommandLineParser::GetParser();
202  Command* commandLine(0);
203  if((commandLine = parser->GetCommandIfActive("-out"))==0) return;
204 
205  // print histogram statistics
206  //
207  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
208  // if(!analysisManager->IsActive()) {return; }
209 
210  // save histograms
211  //
212  analysisManager->Write();
213  analysisManager->CloseFile();
214 
215  if(fDebug)
216  {
217  G4cout << "================ ROOT FILES HAVE BEEN WRITTEN"
218  << G4endl;
219  }
220 }
221 
222 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
223 
224 void RunAction::PrintRunInfo(const G4Run* run)
225 {
226  G4cout << "================ Run is = "
227  << run->GetRunID() << G4endl;
228  G4cout << "================ Run type is = "
230  G4cout << "================ Event processed = "
232  G4cout << "================ Nevent = "
233  << run->GetNumberOfEvent() << G4endl;
234 }
235 
236 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......