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] [ 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/advanced/microelectronics/src/RunAction.cc (Version 11.3.0) and /examples/advanced/microelectronics/src/RunAction.cc (Version 10.0)


  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 // -------------------------------------------     26 // -------------------------------------------------------------------
                                                   >>  27 // $Id: RunAction.cc,v 1.1 2012-09-21 mraine Exp $
 27 // -------------------------------------------     28 // -------------------------------------------------------------------
 28                                                    29 
 29 #include "RunAction.hh"                            30 #include "RunAction.hh"
 30 #include "G4Run.hh"                                31 #include "G4Run.hh"
 31 #include "TrackingAction.hh"                       32 #include "TrackingAction.hh"
 32 #include "G4ParticleDefinition.hh"                 33 #include "G4ParticleDefinition.hh"
 33 #include "G4RunManager.hh"                         34 #include "G4RunManager.hh"
 34 #include "G4AnalysisManager.hh"                <<  35 #include "Analysis.hh"
 35 #include "G4Threading.hh"                          36 #include "G4Threading.hh"
 36                                                    37 
 37 void PrintNParticles(std::map<const G4Particle     38 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container);
 38                                                    39 
 39 //....oooOO0OOooo........oooOO0OOooo........oo     40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 40                                                    41 
 41 RunAction::RunAction()                             42 RunAction::RunAction()
 42 {                                                  43 {
 43  fFileName = "microelectronics";               <<  44   fpTrackingAction = 0;
 44  fpTrackingAction = 0;                         <<  45   fInitialized = 0;
 45  fInitialized = 0;                             <<  46   fDebug = false;
 46  fDebug = false;                               << 
 47 }                                                  47 }
 48                                                    48 
 49 //....oooOO0OOooo........oooOO0OOooo........oo     49 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 50                                                    50 
 51 RunAction::~RunAction()                            51 RunAction::~RunAction()
 52 {}                                                 52 {}
 53                                                    53 
 54 //....oooOO0OOooo........oooOO0OOooo........oo     54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 55                                                    55 
 56 void RunAction::BeginOfRunAction(const G4Run*      56 void RunAction::BeginOfRunAction(const G4Run* run)
 57 {                                                  57 {  
 58   // In this example, we considered that the s     58   // In this example, we considered that the same class was
 59   // used for both master and worker threads.      59   // used for both master and worker threads.
 60   // However, in case the run action is long,      60   // However, in case the run action is long,
 61   // for better code review, this practice is      61   // for better code review, this practice is not recommanded.
 62   //                                               62   //
 63                                                    63   
 64   if(isMaster) // WARNING : in sequential mode     64   if(isMaster) // WARNING : in sequential mode, isMaster == true    
 65     BeginMaster(run);                              65     BeginMaster(run);    
 66   else                                             66   else 
 67     BeginWorker(run);                              67     BeginWorker(run);
 68 }                                                  68 }
 69                                                    69 
 70 //....oooOO0OOooo........oooOO0OOooo........oo     70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 71                                                    71 
 72 void RunAction::EndOfRunAction(const G4Run* ru     72 void RunAction::EndOfRunAction(const G4Run* run)
 73 {                                                  73 {
 74   if(isMaster)                                     74   if(isMaster)   
 75     EndMaster(run);                                75     EndMaster(run);
 76   else                                             76   else  
 77     EndWorker(run);                                77     EndWorker(run);
 78 }                                                  78 }
 79                                                    79 
 80                                                    80 
 81 //....oooOO0OOooo........oooOO0OOooo........oo     81 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
 82                                                    82 
 83 void RunAction::BeginMaster(const G4Run* run)      83 void RunAction::BeginMaster(const G4Run* run)
 84 {                                                  84 {
 85   bool sequential = (G4RunManager::GetRunManag     85   bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM);
 86                                                    86   
 87   if(fDebug)                                       87   if(fDebug)
 88     {                                              88     {
 89       G4cout << "°°°°°°°°°°°°°°     89       G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
 90       if(!sequential)                              90       if(!sequential)
 91   G4cout << "°°°°°°°°°°°°°°°°      91   G4cout << "°°°°°°°°°°°°°°°° RunAction::BeginMaster" << G4endl;
 92       PrintRunInfo(run);                           92       PrintRunInfo(run);
 93       G4cout << "°°°°°°°°°°°°°°     93       G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
 94     }                                              94     }
 95                                                    95   
 96   if(sequential)                                   96   if(sequential)
 97     {                                              97     {
 98       if(!fInitialized)                            98       if(!fInitialized) 
 99   InitializeWorker(run);                           99   InitializeWorker(run);
100       // Note: fpTrackingAction could be used     100       // Note: fpTrackingAction could be used as a flag for initialization instead      
101                                                   101 
102       CreateHistogram();                          102       CreateHistogram();
103     }                                             103     }
104 }                                                 104 }
105                                                   105 
106 //....oooOO0OOooo........oooOO0OOooo........oo    106 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
107                                                   107 
108 void RunAction::BeginWorker(const G4Run* run)     108 void RunAction::BeginWorker(const G4Run* run)
109 {                                                 109 {
110   if(fDebug)                                      110   if(fDebug)
111     {                                             111     {
112       G4cout << "°°°°°°°°°°°°°°    112       G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
113       G4cout << "°°°°°°°°°°°°°°    113       G4cout << "°°°°°°°°°°°°°°°° RunAction::BeginWorker" << G4endl;
114       PrintRunInfo(run);                          114       PrintRunInfo(run);
115       G4cout << "°°°°°°°°°°°°°°    115       G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
116     }                                             116     }
117   if(!fInitialized)                               117   if(!fInitialized) 
118     InitializeWorker(run);                        118     InitializeWorker(run);
119                                                   119   
120   CreateHistogram();                              120   CreateHistogram();
121 }                                                 121 }
122                                                   122 
123 //....oooOO0OOooo........oooOO0OOooo........oo    123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
124                                                   124 
125 void RunAction::EndMaster(const G4Run* run)       125 void RunAction::EndMaster(const G4Run* run)
126 {                                                 126 {
127   bool sequential = (G4RunManager::GetRunManag    127   bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() 
128          == G4RunManager::sequentialRM);          128          == G4RunManager::sequentialRM);
129   if(sequential)                                  129   if(sequential)    
130     EndWorker(run);                               130     EndWorker(run);    
131 }                                                 131 }
132                                                   132 
133 //....oooOO0OOooo........oooOO0OOooo........oo    133 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
134                                                   134 
135 void RunAction::EndWorker(const G4Run* run)       135 void RunAction::EndWorker(const G4Run* run)
136 {                                                 136 {
137   if(fDebug)                                      137   if(fDebug)
138     {                                             138     {
139       PrintRunInfo(run);                          139       PrintRunInfo(run);
140     }                                             140     }
141                                                   141   
142   G4int nofEvents = run->GetNumberOfEvent();      142   G4int nofEvents = run->GetNumberOfEvent();
143   if ( nofEvents == 0 )                           143   if ( nofEvents == 0 )
144     {                                             144     {
145       if(fDebug)                                  145       if(fDebug)
146   {                                               146   {
147     G4cout << "°°°°°°°°°°°°°°°    147     G4cout << "°°°°°°°°°°°°°°°° NO EVENTS TREATED IN THIS RUN ==> LEAVING RunAction::EndOfRunAction "<< G4endl;
148   }                                               148   }
149       return;                                     149       return;
150     }                                             150     }
151                                                   151   
152   ///////////////                                 152   ///////////////
153   // Write Histo                                  153   // Write Histo
154   //                                              154   //
155   WriteHistogram();                               155   WriteHistogram();
156                                                << 156   
157   ///////////////                                 157   ///////////////
158   // Complete cleanup                             158   // Complete cleanup
159   //                                              159   //
160   G4AnalysisManager* analysisManager = G4Analy << 160   delete G4AnalysisManager::Instance();
161   analysisManager->Clear();                    << 161   
162                                                << 
163   ///////////////                                 162   ///////////////
164   // Printouts                                    163   // Printouts
165   //                                              164   //
166   std::map<const G4ParticleDefinition*, int>&     165   std::map<const G4ParticleDefinition*, int>&
167     particlesCreatedInWorld = fpTrackingAction    166     particlesCreatedInWorld = fpTrackingAction->GetNParticlesCreatedInWorld();
168                                                   167   
169   G4cout << "Number and type of particles crea    168   G4cout << "Number and type of particles created outside region \"Target\" :" << G4endl;
170                                                   169   
171   PrintNParticles(particlesCreatedInWorld);       170   PrintNParticles(particlesCreatedInWorld);
172                                                   171   
173   G4cout << "_______________________" << G4end    172   G4cout << "_______________________" << G4endl;
174                                                   173   
175   std::map<const G4ParticleDefinition*, int>&     174   std::map<const G4ParticleDefinition*, int>&
176     particlesCreatedInTarget = fpTrackingActio    175     particlesCreatedInTarget = fpTrackingAction->GetNParticlesCreatedInTarget();
177                                                   176   
178   G4cout << "Number and type of particles crea    177   G4cout << "Number and type of particles created in region \"Target\" :" << G4endl;
179                                                   178   
180   PrintNParticles(particlesCreatedInTarget);      179   PrintNParticles(particlesCreatedInTarget);
181                                                   180   
182 }                                                 181 }
183                                                   182 
184 //....oooOO0OOooo........oooOO0OOooo........oo    183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
185                                                   184 
186 void RunAction::InitializeWorker(const G4Run*)    185 void RunAction::InitializeWorker(const G4Run*)
187 {                                                 186 {
188   if (fpTrackingAction == 0)                      187   if (fpTrackingAction == 0)
189   {                                               188   {
190     fpTrackingAction = (TrackingAction*) G4Run    189     fpTrackingAction = (TrackingAction*) G4RunManager::GetRunManager()->GetUserTrackingAction();
191                                                   190 
192     if(fpTrackingAction == 0 && isMaster == fa    191     if(fpTrackingAction == 0 && isMaster == false)
193     {                                             192     {
194       G4ExceptionDescription exDescrption ;       193       G4ExceptionDescription exDescrption ;
195       exDescrption << "fpTrackingAction is a n    194       exDescrption << "fpTrackingAction is a null pointer. Has it been correctly initialized ?";
196       G4Exception("RunAction::BeginOfRunAction    195       G4Exception("RunAction::BeginOfRunAction","RunAction001",FatalException, exDescrption);
197     }                                             196     }
198   }                                               197   }
199                                                   198 
200   fInitialized = true;                            199   fInitialized = true;
201 }                                                 200 }
202                                                   201 
203 //....oooOO0OOooo........oooOO0OOooo........oo    202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
204                                                   203 
205 void RunAction::CreateHistogram()                 204 void RunAction::CreateHistogram()
206 {                                                 205 {
207   // Book histograms, ntuple                      206   // Book histograms, ntuple
208                                                   207 
209   // Create analysis manager                      208   // Create analysis manager
210   // The choice of analysis technology is done    209   // The choice of analysis technology is done via selection of a namespace
211   // in Analysis.hh                               210   // in Analysis.hh
212                                                   211 
213   G4cout << "##### Create analysis manager " <    212   G4cout << "##### Create analysis manager " << "  " << this << G4endl;
214   G4AnalysisManager* analysisManager = G4Analy    213   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
215   analysisManager->SetDefaultFileType("root"); << 
216                                                   214 
217   G4cout << "Using " << analysisManager->GetTy    215   G4cout << "Using " << analysisManager->GetType() << " analysis manager" << G4endl;
218                                                   216 
219   // Create directories                           217   // Create directories
220                                                   218 
221   //analysisManager->SetHistoDirectoryName("hi    219   //analysisManager->SetHistoDirectoryName("histograms");
222   //analysisManager->SetNtupleDirectoryName("n    220   //analysisManager->SetNtupleDirectoryName("ntuple");
223   analysisManager->SetVerboseLevel(1);            221   analysisManager->SetVerboseLevel(1);
224                                                   222 
225   // Open an output file                          223   // Open an output file
226                                                << 224 
227   analysisManager->OpenFile(fFileName);        << 225   G4String fileName = "microelectronics";
                                                   >> 226   analysisManager->OpenFile(fileName);
228                                                   227 
229   // Creating ntuple                              228   // Creating ntuple
230                                                   229 
231   analysisManager->CreateNtuple("microelectron    230   analysisManager->CreateNtuple("microelectronics", "physics");
232   analysisManager->CreateNtupleDColumn("flagPa    231   analysisManager->CreateNtupleDColumn("flagParticle");
233   analysisManager->CreateNtupleDColumn("flagPr    232   analysisManager->CreateNtupleDColumn("flagProcess");
234   analysisManager->CreateNtupleDColumn("x");      233   analysisManager->CreateNtupleDColumn("x");
235   analysisManager->CreateNtupleDColumn("y");      234   analysisManager->CreateNtupleDColumn("y");
236   analysisManager->CreateNtupleDColumn("z");      235   analysisManager->CreateNtupleDColumn("z");
237   analysisManager->CreateNtupleDColumn("totalE    236   analysisManager->CreateNtupleDColumn("totalEnergyDeposit");
238   analysisManager->CreateNtupleDColumn("stepLe    237   analysisManager->CreateNtupleDColumn("stepLength");
239   analysisManager->CreateNtupleDColumn("kineti    238   analysisManager->CreateNtupleDColumn("kineticEnergyDifference");
240   analysisManager->FinishNtuple();                239   analysisManager->FinishNtuple();
241 }                                                 240 }
242                                                   241 
243 //....oooOO0OOooo........oooOO0OOooo........oo    242 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
244                                                   243 
245 void RunAction::WriteHistogram()                  244 void RunAction::WriteHistogram()
246 {                                                 245 {
247   // print histogram statistics                   246   // print histogram statistics
248   //                                              247   //
249   G4AnalysisManager* analysisManager = G4Analy    248   G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
250                                                   249 
251   // save histograms                              250   // save histograms
252   //                                              251   //
253   analysisManager->Write();                       252   analysisManager->Write();
254   analysisManager->CloseFile();                   253   analysisManager->CloseFile();
255 }                                                 254 }
256                                                   255 
257 //....oooOO0OOooo........oooOO0OOooo........oo    256 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
258                                                   257 
259 void RunAction::PrintRunInfo(const G4Run* run)    258 void RunAction::PrintRunInfo(const G4Run* run)
260 {                                                 259 {
261   G4cout << "°°°°°°°°°°°°°°°°     260   G4cout << "°°°°°°°°°°°°°°°° Run is = " << run->GetRunID() << G4endl;
262   G4cout << "°°°°°°°°°°°°°°°°     261   G4cout << "°°°°°°°°°°°°°°°° Run type is = " << G4RunManager::GetRunManager()->GetRunManagerType() << G4endl;
263   G4cout << "°°°°°°°°°°°°°°°°     262   G4cout << "°°°°°°°°°°°°°°°° Event processed = " << run->GetNumberOfEventToBeProcessed() << G4endl;
264   G4cout << "°°°°°°°°°°°°°°°°     263   G4cout << "°°°°°°°°°°°°°°°° N° Event = " << run->GetNumberOfEvent() << G4endl;
265 }                                                 264 }
266                                                   265 
267 //....oooOO0OOooo........oooOO0OOooo........oo    266 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
268 void PrintNParticles(std::map<const G4Particle    267 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container)
269 {                                                 268 {
270     std::map<const G4ParticleDefinition*, int>    269     std::map<const G4ParticleDefinition*, int>::iterator it;
271     for(it = container.begin() ;                  270     for(it = container.begin() ;
272         it != container.end(); it ++)             271         it != container.end(); it ++)
273     {                                             272     {
274         G4cout << "N " << it->first->GetPartic    273         G4cout << "N " << it->first->GetParticleName() << " : " << it->second << G4endl;
275     }                                             274     }
276 }                                                 275 }
277                                                   276  
278 //....oooOO0OOooo........oooOO0OOooo........oo    277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
279                                                   278