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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/microdosimetry/src/RunAction.cc (Version 11.3.0) and /examples/extended/medical/dna/microdosimetry/src/RunAction.cc (Version 10.3)


  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. 45, (2018) e722-e739             << 
 30 // Phys. Med. 31 (2015) 861-874                << 
 31 // Med. Phys. 37 (2010) 4692-4708                  29 // Med. Phys. 37 (2010) 4692-4708
 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010) << 
 33 // The Geant4-DNA web site is available at htt     30 // The Geant4-DNA web site is available at http://geant4-dna.org
 34 //                                                 31 //
 35 //                                             <<  32 // $ID$
 36 /// \file RunAction.cc                             33 /// \file RunAction.cc
 37 /// \brief Implementation of the RunAction cla     34 /// \brief Implementation of the RunAction class
 38                                                    35 
 39 #include "RunAction.hh"                            36 #include "RunAction.hh"
 40                                                << 
 41 #include "G4AnalysisManager.hh"                << 
 42 #include "G4Run.hh"                                37 #include "G4Run.hh"
                                                   >>  38 #include "TrackingAction.hh"
                                                   >>  39 #include "G4ParticleDefinition.hh"
                                                   >>  40 #include "G4RunManager.hh"
                                                   >>  41 #include "Analysis.hh"
                                                   >>  42 #include "G4Threading.hh"
                                                   >>  43 #include "CommandLineParser.hh"
                                                   >>  44 
                                                   >>  45 using namespace G4DNAPARSER;
                                                   >>  46 
                                                   >>  47 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container);
                                                   >>  48 
                                                   >>  49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  50 
                                                   >>  51 RunAction::RunAction() : G4UserRunAction(),
                                                   >>  52       fpTrackingAction(0), fInitialized(0), fDebug(false)
                                                   >>  53 {}
                                                   >>  54 
                                                   >>  55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  56 
                                                   >>  57 RunAction::~RunAction()
                                                   >>  58 {}
 43                                                    59 
 44 //....oooOO0OOooo........oooOO0OOooo........oo     60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 45                                                    61 
 46 RunAction::RunAction() : G4UserRunAction()     <<  62 void RunAction::BeginOfRunAction(const G4Run* run)
 47 {                                                  63 {
                                                   >>  64   // In this example, we considered that the same class was
                                                   >>  65   // used for both master and worker threads.
                                                   >>  66   // However, in case the run action is long,
                                                   >>  67   // for better code review, this practice is not recommanded.
                                                   >>  68   //
                                                   >>  69   // Please note, in the example provided with the Geant4 X beta version,
                                                   >>  70   // this RunAction class were not used by the master thread.
                                                   >>  71 
                                                   >>  72   bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == 
                                                   >>  73                      G4RunManager::sequentialRM);
                                                   >>  74 
                                                   >>  75   if(isMaster && sequential == false )
                                                   >>  76   // WARNING : in sequential mode, isMaster == true
                                                   >>  77   {
                                                   >>  78     BeginMaster(run);
                                                   >>  79   }
                                                   >>  80   else BeginWorker(run);
                                                   >>  81 }
                                                   >>  82 
                                                   >>  83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >>  84 
                                                   >>  85 void RunAction::EndOfRunAction(const G4Run* run)
                                                   >>  86 {
                                                   >>  87 
                                                   >>  88   bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == 
                                                   >>  89                      G4RunManager::sequentialRM);
                                                   >>  90 
                                                   >>  91   if(isMaster && sequential == false)
                                                   >>  92   {
                                                   >>  93     EndMaster(run);
                                                   >>  94   }
                                                   >>  95   else
                                                   >>  96   {
                                                   >>  97     EndWorker(run);
                                                   >>  98   }
                                                   >>  99 }
                                                   >> 100 
                                                   >> 101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 102 
                                                   >> 103 void RunAction::BeginMaster(const G4Run* run)
                                                   >> 104 {
                                                   >> 105   if(fDebug)
                                                   >> 106   {
                                                   >> 107     bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == 
                                                   >> 108                        G4RunManager::sequentialRM);
                                                   >> 109     G4cout << "===================================" << G4endl;
                                                   >> 110     if(!sequential)
                                                   >> 111       G4cout << "================ RunAction::BeginMaster" << G4endl;
                                                   >> 112     PrintRunInfo(run);
                                                   >> 113     G4cout << "===================================" << G4endl;
                                                   >> 114   }
                                                   >> 115 }
                                                   >> 116 
                                                   >> 117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 118 
                                                   >> 119 void RunAction::BeginWorker(const G4Run* run)
                                                   >> 120 {
                                                   >> 121   if (fDebug)
                                                   >> 122   {
                                                   >> 123     G4cout << "===================================" << G4endl;
                                                   >> 124     G4cout << "================ RunAction::BeginWorker" << G4endl;
                                                   >> 125     PrintRunInfo(run);
                                                   >> 126     G4cout << "===================================" << G4endl;
                                                   >> 127   }
                                                   >> 128   if(fInitialized == false) InitializeWorker(run);
                                                   >> 129 
                                                   >> 130   CreateHistogram();
                                                   >> 131 }
                                                   >> 132 
                                                   >> 133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 134 
                                                   >> 135 void RunAction::EndMaster(const G4Run*)
                                                   >> 136 {
                                                   >> 137 }
                                                   >> 138 
                                                   >> 139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 140 
                                                   >> 141 void RunAction::EndWorker(const G4Run* run)
                                                   >> 142 {
                                                   >> 143   if(fDebug)
                                                   >> 144   {
                                                   >> 145     G4cout << "===================================" << G4endl;
                                                   >> 146     G4cout << "================ RunAction::EndWorker" << G4endl;
                                                   >> 147     PrintRunInfo(run);
                                                   >> 148     G4cout << "===================================" << G4endl;
                                                   >> 149   }
                                                   >> 150 
                                                   >> 151   G4int nofEvents = run->GetNumberOfEvent();
                                                   >> 152   if ( nofEvents == 0 )
                                                   >> 153   {
                                                   >> 154     if(fDebug)
                                                   >> 155     {
                                                   >> 156       G4cout << "================ NO EVENTS TREATED IN THIS RUN ==> Exit"
                                                   >> 157              << G4endl;
                                                   >> 158     }
                                                   >> 159     return;
                                                   >> 160   }
                                                   >> 161 
                                                   >> 162   ///////////////
                                                   >> 163   // Write Histo
                                                   >> 164   //
                                                   >> 165   WriteHistogram();
                                                   >> 166 
                                                   >> 167   ///////////////
                                                   >> 168   // Complete cleanup
                                                   >> 169   //
                                                   >> 170   delete G4AnalysisManager::Instance();
                                                   >> 171 
                                                   >> 172   ///////////////
                                                   >> 173   // Printouts
                                                   >> 174   //
                                                   >> 175   std::map<const G4ParticleDefinition*, int>&
                                                   >> 176   particlesCreatedInWorld = fpTrackingAction->GetNParticlesCreatedInWorld();
                                                   >> 177 
                                                   >> 178   G4cout << "Number and type of particles created outside region \"Target\" :"
                                                   >> 179          << G4endl;
                                                   >> 180 
                                                   >> 181   PrintNParticles(particlesCreatedInWorld);
                                                   >> 182 
                                                   >> 183   G4cout << "_______________________" << G4endl;
                                                   >> 184 
                                                   >> 185   std::map<const G4ParticleDefinition*, int>&
                                                   >> 186   particlesCreatedInTarget = fpTrackingAction->GetNParticlesCreatedInTarget();
                                                   >> 187 
                                                   >> 188   G4cout << "Number and type of particles created in region \"Target\" :"
                                                   >> 189          << G4endl;
                                                   >> 190 
                                                   >> 191   PrintNParticles(particlesCreatedInTarget);
                                                   >> 192 }
                                                   >> 193 
                                                   >> 194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 195 
                                                   >> 196 void RunAction::InitializeWorker(const G4Run*)
                                                   >> 197 {
                                                   >> 198   RunInitManager::Instance()->Initialize();
                                                   >> 199 
                                                   >> 200   if (fpTrackingAction == 0)
                                                   >> 201   {
                                                   >> 202     fpTrackingAction = (TrackingAction*) G4RunManager::GetRunManager()->
                                                   >> 203         GetUserTrackingAction();
                                                   >> 204 
                                                   >> 205     if(fpTrackingAction == 0 && isMaster == false)
                                                   >> 206     {
                                                   >> 207       G4ExceptionDescription exDescrption ;
                                                   >> 208       exDescrption << "fpTrackingAction is a null pointer. "
                                                   >> 209           "Has it been correctly initialized ?";
                                                   >> 210       G4Exception("RunAction::BeginOfRunAction",
                                                   >> 211           "RunAction001",FatalException, exDescrption);
                                                   >> 212     }
                                                   >> 213   }
                                                   >> 214 
                                                   >> 215   fInitialized = true;
                                                   >> 216 }
                                                   >> 217 
                                                   >> 218 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
                                                   >> 219 
                                                   >> 220 void RunAction::CreateHistogram()
                                                   >> 221 {
                                                   >> 222   // Book histograms, ntuple
                                                   >> 223 
 48   // Create analysis manager                      224   // Create analysis manager
                                                   >> 225   // The choice of analysis technology is done via selection of a namespace
                                                   >> 226   // in Analysis.hh
                                                   >> 227 
                                                   >> 228   CommandLineParser* parser = CommandLineParser::GetParser();
                                                   >> 229   Command* command(0);
                                                   >> 230   if((command = parser->GetCommandIfActive("-out"))==0) return;
 49                                                   231 
 50   G4cout << "##### Create analysis manager "   << 232   G4cout << "##### Create analysis manager " << "  " << this << G4endl;
 51          << "  " << this << G4endl;            << 233   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
 52   auto analysisManager = G4AnalysisManager::In << 234 //  if(!analysisManager->IsActive()) {return; }
 53                                                   235 
 54   analysisManager->SetDefaultFileType("root"); << 236   G4cout << "Using " << analysisManager->GetType() <<
 55   analysisManager->SetNtupleMerging(true);     << 237       " analysis manager" << G4endl;
 56                                                   238 
 57   G4cout << "Using " << analysisManager->GetTy << 239   // Create directories
 58                                                   240 
                                                   >> 241   //analysisManager->SetHistoDirectoryName("histograms");
                                                   >> 242   //analysisManager->SetNtupleDirectoryName("ntuple");
 59   analysisManager->SetVerboseLevel(1);            243   analysisManager->SetVerboseLevel(1);
 60                                                   244 
 61   // Create ntuple                             << 245   // Open an output file
                                                   >> 246   G4String fileName;
                                                   >> 247   if(command->GetOption().empty() == false)
                                                   >> 248   {
                                                   >> 249     fileName = command->GetOption();
                                                   >> 250   }
                                                   >> 251   else
                                                   >> 252   {
                                                   >> 253    fileName = "microdosimetry";
                                                   >> 254   }
                                                   >> 255   analysisManager->OpenFile(fileName);
                                                   >> 256 
                                                   >> 257   // Creating ntuple
 62                                                   258 
 63   analysisManager->CreateNtuple("dna", "dnaphy << 259   analysisManager->CreateNtuple("microdosimetry", "physics");
 64   analysisManager->CreateNtupleDColumn("flagPa    260   analysisManager->CreateNtupleDColumn("flagParticle");
 65   analysisManager->CreateNtupleDColumn("flagPr    261   analysisManager->CreateNtupleDColumn("flagProcess");
 66   analysisManager->CreateNtupleDColumn("x");      262   analysisManager->CreateNtupleDColumn("x");
 67   analysisManager->CreateNtupleDColumn("y");      263   analysisManager->CreateNtupleDColumn("y");
 68   analysisManager->CreateNtupleDColumn("z");      264   analysisManager->CreateNtupleDColumn("z");
 69   analysisManager->CreateNtupleDColumn("totalE    265   analysisManager->CreateNtupleDColumn("totalEnergyDeposit");
 70   analysisManager->CreateNtupleDColumn("stepLe    266   analysisManager->CreateNtupleDColumn("stepLength");
 71   analysisManager->CreateNtupleDColumn("kineti    267   analysisManager->CreateNtupleDColumn("kineticEnergyDifference");
 72   analysisManager->CreateNtupleDColumn("kineti << 
 73   analysisManager->CreateNtupleDColumn("cosThe << 
 74   analysisManager->CreateNtupleIColumn("eventI << 
 75   analysisManager->CreateNtupleIColumn("trackI << 
 76   analysisManager->CreateNtupleIColumn("parent << 
 77   analysisManager->CreateNtupleIColumn("stepID << 
 78   analysisManager->FinishNtuple();                268   analysisManager->FinishNtuple();
 79 }                                                 269 }
 80                                                   270 
 81 //....oooOO0OOooo........oooOO0OOooo........oo    271 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 82                                                   272 
 83 RunAction::~RunAction() {}                     << 273 void RunAction::WriteHistogram()
 84                                                << 
 85 //....oooOO0OOooo........oooOO0OOooo........oo << 
 86                                                << 
 87 void RunAction::BeginOfRunAction(const G4Run*) << 
 88 {                                                 274 {
 89   auto analysisManager = G4AnalysisManager::In << 275   CommandLineParser* parser = CommandLineParser::GetParser();
                                                   >> 276   Command* commandLine(0);
                                                   >> 277   if((commandLine = parser->GetCommandIfActive("-out"))==0) return;
                                                   >> 278 
                                                   >> 279   // print histogram statistics
                                                   >> 280   //
                                                   >> 281   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
                                                   >> 282   // if(!analysisManager->IsActive()) {return; }
 90                                                   283 
 91   // Open an output file                       << 284   // save histograms
 92   G4String fileName = "dna";                   << 285   //
 93   analysisManager->OpenFile(fileName);         << 286   analysisManager->Write();
                                                   >> 287   analysisManager->CloseFile();
                                                   >> 288 
                                                   >> 289   if(fDebug)
                                                   >> 290   {
                                                   >> 291     G4cout << "================ ROOT FILES HAVE BEEN WRITTEN"
                                                   >> 292            << G4endl;
                                                   >> 293   }
 94 }                                                 294 }
 95                                                   295 
 96 //....oooOO0OOooo........oooOO0OOooo........oo    296 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 97                                                   297 
 98 void RunAction::EndOfRunAction(const G4Run* aR << 298 void RunAction::PrintRunInfo(const G4Run* run)
 99 {                                                 299 {
100   G4int nofEvents = aRun->GetNumberOfEvent();  << 300   G4cout << "================ Run is = "
101   if (nofEvents == 0) return;                  << 301          << run->GetRunID() << G4endl;
                                                   >> 302   G4cout << "================ Run type is = "
                                                   >> 303          << G4RunManager::GetRunManager()->GetRunManagerType() << G4endl;
                                                   >> 304   G4cout << "================ Event processed = "
                                                   >> 305          << run->GetNumberOfEventToBeProcessed() << G4endl;
                                                   >> 306   G4cout << "================ Nevent = "
                                                   >> 307          << run->GetNumberOfEvent() << G4endl;
                                                   >> 308 }
102                                                   309 
103   // Print histogram statistics                << 310 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
104   auto analysisManager = G4AnalysisManager::In << 
105                                                   311 
106   // Save histograms                           << 312 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container)
107   analysisManager->Write();                    << 313 {
108   analysisManager->CloseFile();                << 314   std::map<const G4ParticleDefinition*, int>::iterator it;
                                                   >> 315   for(it = container.begin() ;
                                                   >> 316       it != container.end(); it ++)
                                                   >> 317   {
                                                   >> 318     G4cout << "N " << it->first->GetParticleName() << " : "
                                                   >> 319         << it->second << G4endl;
                                                   >> 320   }
109 }                                                 321 }
                                                   >> 322 
                                                   >> 323 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
110                                                   324