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 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/dna/wholeNuclearDNA/src/RunAction.cc (Version 11.3.0) and /examples/extended/medical/dna/wholeNuclearDNA/src/RunAction.cc (Version 11.1.1)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // This example is provided by the Geant4-DNA      26 // This example is provided by the Geant4-DNA collaboration
 27 // Any report or published results obtained us <<  27 // Any report or published results obtained using the Geant4-DNA software 
 28 // shall cite the following Geant4-DNA collabo     28 // shall cite the following Geant4-DNA collaboration publication:
 29 // Med. Phys. 37 (2010) 4692-4708                  29 // Med. Phys. 37 (2010) 4692-4708
 30 // The Geant4-DNA web site is available at htt     30 // The Geant4-DNA web site is available at http://geant4-dna.org
 31 //                                                 31 //
 32 /// \file RunAction.cc                             32 /// \file RunAction.cc
 33 /// \brief Implementation of the RunAction cla     33 /// \brief Implementation of the RunAction class
 34                                                    34 
 35 #include "RunAction.hh"                            35 #include "RunAction.hh"
 36                                                << 
 37 #include "CommandLineParser.hh"                << 
 38                                                << 
 39 #include "G4AnalysisManager.hh"                << 
 40 #include "G4Run.hh"                                36 #include "G4Run.hh"
 41 #include "G4RunManager.hh"                         37 #include "G4RunManager.hh"
                                                   >>  38 #include "G4AnalysisManager.hh"
 42 #include "G4Threading.hh"                          39 #include "G4Threading.hh"
                                                   >>  40 #include "CommandLineParser.hh"
 43                                                    41 
 44 using namespace G4DNAPARSER;                       42 using namespace G4DNAPARSER;
 45                                                    43 
 46 void PrintNParticles(std::map<const G4Particle     44 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container);
 47                                                    45 
 48 //....oooOO0OOooo........oooOO0OOooo........oo     46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 49                                                    47 
 50 RunAction::RunAction() : G4UserRunAction(), fI <<  48 RunAction::RunAction() : G4UserRunAction(),
                                                   >>  49       fInitialized(0), fDebug(false)
                                                   >>  50 {}
 51                                                    51 
 52 //....oooOO0OOooo........oooOO0OOooo........oo     52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 53                                                    53 
 54 RunAction::~RunAction() {}                     <<  54 RunAction::~RunAction()
                                                   >>  55 {}
 55                                                    56 
 56 //....oooOO0OOooo........oooOO0OOooo........oo     57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 57                                                    58 
 58 void RunAction::BeginOfRunAction(const G4Run*      59 void RunAction::BeginOfRunAction(const G4Run* run)
 59 {                                                  60 {
 60   // In this example, we considered that the s     61   // In this example, we considered that the same class was
 61   // used for both master and worker threads.      62   // used for both master and worker threads.
 62   // However, in case the run action is long,      63   // However, in case the run action is long,
 63   // for better code review, this practice is      64   // for better code review, this practice is not recommanded.
 64   //                                               65   //
 65   // Please note, in the example provided with     66   // Please note, in the example provided with the Geant4 X beta version,
 66   // this RunAction class were not used by the     67   // this RunAction class were not used by the master thread.
 67                                                    68 
 68   bool sequential =                            << 
 69     (G4RunManager::GetRunManager()->GetRunMana << 
 70                                                    69 
 71   if (isMaster && sequential == false)         <<  70   bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == 
                                                   >>  71                      G4RunManager::sequentialRM);
                                                   >>  72 
                                                   >>  73   if(isMaster && sequential == false )
 72   // WARNING : in sequential mode, isMaster ==     74   // WARNING : in sequential mode, isMaster == true
 73   {                                                75   {
 74     BeginMaster(run);                              76     BeginMaster(run);
 75   }                                                77   }
 76   else                                         <<  78   else BeginWorker(run);
 77     BeginWorker(run);                          << 
 78 }                                                  79 }
 79                                                    80 
 80 //....oooOO0OOooo........oooOO0OOooo........oo     81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81                                                    82 
 82 void RunAction::EndOfRunAction(const G4Run* ru     83 void RunAction::EndOfRunAction(const G4Run* run)
 83 {                                                  84 {
 84   bool sequential =                            << 
 85     (G4RunManager::GetRunManager()->GetRunMana << 
 86                                                    85 
 87   if (isMaster && sequential == false) {       <<  86   bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == 
                                                   >>  87                      G4RunManager::sequentialRM);
                                                   >>  88 
                                                   >>  89   if(isMaster && sequential == false)
                                                   >>  90   {
 88     EndMaster(run);                                91     EndMaster(run);
 89   }                                                92   }
 90   else {                                       <<  93   else
                                                   >>  94   {
 91     EndWorker(run);                                95     EndWorker(run);
 92   }                                                96   }
 93 }                                                  97 }
 94                                                    98 
 95 //....oooOO0OOooo........oooOO0OOooo........oo     99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 96                                                   100 
 97 void RunAction::BeginMaster(const G4Run* run)     101 void RunAction::BeginMaster(const G4Run* run)
 98 {                                                 102 {
 99   if (fDebug) {                                << 103   if(fDebug)
100     bool sequential =                          << 104   {
101       (G4RunManager::GetRunManager()->GetRunMa << 105     bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == 
                                                   >> 106                        G4RunManager::sequentialRM);
102     G4cout << "===============================    107     G4cout << "===================================" << G4endl;
103     if (!sequential) G4cout << "============== << 108     if(!sequential)
                                                   >> 109       G4cout << "================ RunAction::BeginMaster" << G4endl;
104     PrintRunInfo(run);                            110     PrintRunInfo(run);
105     G4cout << "===============================    111     G4cout << "===================================" << G4endl;
106   }                                               112   }
107 }                                                 113 }
108                                                   114 
109 //....oooOO0OOooo........oooOO0OOooo........oo    115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110                                                   116 
111 void RunAction::BeginWorker(const G4Run* run)     117 void RunAction::BeginWorker(const G4Run* run)
112 {                                                 118 {
113   if (fDebug) {                                << 119   if (fDebug)
                                                   >> 120   {
114     G4cout << "===============================    121     G4cout << "===================================" << G4endl;
115     G4cout << "================ RunAction::Beg    122     G4cout << "================ RunAction::BeginWorker" << G4endl;
116     PrintRunInfo(run);                            123     PrintRunInfo(run);
117     G4cout << "===============================    124     G4cout << "===================================" << G4endl;
118   }                                               125   }
119   if (fInitialized == false) InitializeWorker( << 126   if(fInitialized == false) InitializeWorker(run);
120                                                   127 
121   CreateNtuple();                                 128   CreateNtuple();
122 }                                                 129 }
123                                                   130 
124 //....oooOO0OOooo........oooOO0OOooo........oo    131 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125                                                   132 
126 void RunAction::EndMaster(const G4Run*) {}     << 133 void RunAction::EndMaster(const G4Run*)
                                                   >> 134 {
                                                   >> 135 }
127                                                   136 
128 //....oooOO0OOooo........oooOO0OOooo........oo    137 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
129                                                   138 
130 void RunAction::EndWorker(const G4Run* run)       139 void RunAction::EndWorker(const G4Run* run)
131 {                                                 140 {
132   if (fDebug) {                                << 141   if(fDebug)
                                                   >> 142   {
133     PrintRunInfo(run);                            143     PrintRunInfo(run);
134   }                                               144   }
135                                                   145 
136   G4int nofEvents = run->GetNumberOfEvent();      146   G4int nofEvents = run->GetNumberOfEvent();
137   if (nofEvents == 0) {                        << 147   if ( nofEvents == 0 )
138     if (fDebug) {                              << 148   {
139       G4cout << "================ NO EVENTS TR << 149     if(fDebug)
                                                   >> 150     {
                                                   >> 151       G4cout << "================ NO EVENTS TREATED IN THIS RUN ==> Exit"
                                                   >> 152              << G4endl;
140     }                                             153     }
141     return;                                       154     return;
142   }                                               155   }
143                                                   156 
144   ///////////////                                 157   ///////////////
145   // Write Ntuple                                 158   // Write Ntuple
146   //                                              159   //
147   WriteNtuple();                                  160   WriteNtuple();
148 }                                                 161 }
149                                                   162 
150 //....oooOO0OOooo........oooOO0OOooo........oo    163 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
151                                                   164 
152 void RunAction::InitializeWorker(const G4Run*)    165 void RunAction::InitializeWorker(const G4Run*)
153 {                                                 166 {
154   // Initialize worker here                       167   // Initialize worker here
155   // example: you want to retrieve pointers to    168   // example: you want to retrieve pointers to other user actions
156   fInitialized = true;                            169   fInitialized = true;
157 }                                                 170 }
158                                                   171 
159 //....oooOO0OOooo........oooOO0OOooo........oo    172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
160                                                   173 
161 void RunAction::CreateNtuple()                    174 void RunAction::CreateNtuple()
162 {                                                 175 {
163   // Book histograms, ntuple                      176   // Book histograms, ntuple
164                                                   177 
165   // Create analysis manager                      178   // Create analysis manager
166                                                   179 
167   CommandLineParser* parser = CommandLineParse    180   CommandLineParser* parser = CommandLineParser::GetParser();
168   Command* command(0);                            181   Command* command(0);
169   if ((command = parser->GetCommandIfActive("- << 182   if((command = parser->GetCommandIfActive("-out"))==0) return;
170                                                   183 
171   G4cout << "##### Create analysis manager "   << 184   G4cout << "##### Create analysis manager " << "  " << this << G4endl;
172          << "  " << this << G4endl;            << 
173   G4AnalysisManager* analysisManager = G4Analy    185   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
174   analysisManager->SetDefaultFileType("root");    186   analysisManager->SetDefaultFileType("root");
175   //  if(!analysisManager->IsActive()) {return << 187 //  if(!analysisManager->IsActive()) {return; }
176                                                   188 
177   G4cout << "Using " << analysisManager->GetTy << 189   G4cout << "Using " << analysisManager->GetType() <<
                                                   >> 190       " analysis manager" << G4endl;
178                                                   191 
179   // Create directories                           192   // Create directories
180                                                   193 
181   // analysisManager->SetHistoDirectoryName("h << 194   //analysisManager->SetHistoDirectoryName("histograms");
182   // analysisManager->SetNtupleDirectoryName(" << 195   //analysisManager->SetNtupleDirectoryName("ntuple");
183   analysisManager->SetVerboseLevel(1);            196   analysisManager->SetVerboseLevel(1);
184                                                   197 
185   // Open an output file                          198   // Open an output file
186   G4String fileName;                              199   G4String fileName;
187   if (command->GetOption().empty() == false) { << 200   if(command->GetOption().empty() == false)
                                                   >> 201   {
188     fileName = command->GetOption();              202     fileName = command->GetOption();
189   }                                               203   }
190   else {                                       << 204   else
191     fileName = "wholeNuclearDNA";              << 205   {
192     //   fileName = command->GetDefaultOption( << 206    fileName = "wholeNuclearDNA";
                                                   >> 207 //   fileName = command->GetDefaultOption(); // should work as well
193   }                                               208   }
194   analysisManager->OpenFile(fileName);            209   analysisManager->OpenFile(fileName);
195                                                   210 
196   // Creating ntuple                              211   // Creating ntuple
197   analysisManager->CreateNtuple("ntuple", "geo    212   analysisManager->CreateNtuple("ntuple", "geom_dna");
198   analysisManager->CreateNtupleDColumn("flagPa    213   analysisManager->CreateNtupleDColumn("flagParticle");
199   analysisManager->CreateNtupleDColumn("flagPr    214   analysisManager->CreateNtupleDColumn("flagProcess");
200   analysisManager->CreateNtupleDColumn("flagVo    215   analysisManager->CreateNtupleDColumn("flagVolume");
201   analysisManager->CreateNtupleDColumn("x");      216   analysisManager->CreateNtupleDColumn("x");
202   analysisManager->CreateNtupleDColumn("y");      217   analysisManager->CreateNtupleDColumn("y");
203   analysisManager->CreateNtupleDColumn("z");      218   analysisManager->CreateNtupleDColumn("z");
204   analysisManager->CreateNtupleDColumn("edep")    219   analysisManager->CreateNtupleDColumn("edep");
205   analysisManager->CreateNtupleDColumn("stepLe    220   analysisManager->CreateNtupleDColumn("stepLength");
206                                                   221 
207   analysisManager->FinishNtuple();                222   analysisManager->FinishNtuple();
                                                   >> 223 
208 }                                                 224 }
209                                                   225 
210 //....oooOO0OOooo........oooOO0OOooo........oo    226 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211                                                   227 
212 void RunAction::WriteNtuple()                     228 void RunAction::WriteNtuple()
213 {                                                 229 {
214   CommandLineParser* parser = CommandLineParse    230   CommandLineParser* parser = CommandLineParser::GetParser();
215   Command* commandLine(0);                        231   Command* commandLine(0);
216   if ((commandLine = parser->GetCommandIfActiv << 232   if((commandLine = parser->GetCommandIfActive("-out"))==0) return;
217                                                   233 
218   // print histogram statistics                   234   // print histogram statistics
219   //                                              235   //
220   G4AnalysisManager* analysisManager = G4Analy    236   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
221   //  if(!analysisManager->IsActive()) {return << 237 //  if(!analysisManager->IsActive()) {return; }
222                                                   238 
223   // save histograms                              239   // save histograms
224   //                                              240   //
225   analysisManager->Write();                       241   analysisManager->Write();
226   analysisManager->CloseFile();                   242   analysisManager->CloseFile();
227   analysisManager->Clear();                       243   analysisManager->Clear();
228 }                                                 244 }
229                                                   245 
230 //....oooOO0OOooo........oooOO0OOooo........oo    246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
231                                                   247 
232 void RunAction::PrintRunInfo(const G4Run* run)    248 void RunAction::PrintRunInfo(const G4Run* run)
233 {                                                 249 {
234   G4cout << "================ Run is = " << ru << 250   G4cout << "================ Run is = "
235   G4cout << "================ Run type is = "  << 251          << run->GetRunID() << G4endl;
236          << G4endl;                            << 252   G4cout << "================ Run type is = "
237   G4cout << "================ Event processed  << 253          << G4RunManager::GetRunManager()->GetRunManagerType() << G4endl;
238   G4cout << "================ Nevent = " << ru << 254   G4cout << "================ Event processed = "
                                                   >> 255          << run->GetNumberOfEventToBeProcessed() << G4endl;
                                                   >> 256   G4cout << "================ Nevent = "
                                                   >> 257          << run->GetNumberOfEvent() << G4endl;
239 }                                                 258 }
240 //....oooOO0OOooo........oooOO0OOooo........oo    259 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
241                                                   260