File indexing completed on 2026-04-17 07:51:43
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "RunAction.hh"
0030 #include "G4Run.hh"
0031 #include "TrackingAction.hh"
0032 #include "G4ParticleDefinition.hh"
0033 #include "G4RunManager.hh"
0034 #include "G4AnalysisManager.hh"
0035 #include "G4Threading.hh"
0036 #include "PrimaryGeneratorAction.hh"
0037 #include "MicroElecRun.hh"
0038 #include "G4UnitsTable.hh"
0039 #include "g4csv_defs.hh"
0040 #include "G4SystemOfUnits.hh"
0041
0042 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container);
0043
0044
0045
0046 RunAction::RunAction()
0047 {
0048 fFileName = "microelectronics";
0049 SEYfileName = "SEY";
0050 SEYntupleName = "SEYntuple";
0051 fpTrackingAction = 0;
0052 fInitialized = 0;
0053 NbOfIncidentPart = 0;
0054 EnergyOfIncidentPart = 999;
0055 fDebug = false;
0056 }
0057
0058
0059
0060 RunAction::~RunAction()
0061 {}
0062
0063
0064 G4Run* RunAction::GenerateRun()
0065 {
0066 fRun = new MicroElecRun();
0067 return fRun;
0068 }
0069
0070
0071
0072
0073 void RunAction::BeginOfRunAction(const G4Run* run)
0074 {
0075
0076
0077
0078
0079
0080 if (isMaster) {
0081
0082
0083
0084 BeginMaster(run);
0085 }
0086 else
0087 BeginWorker(run);
0088 }
0089
0090
0091
0092 void RunAction::EndOfRunAction(const G4Run* run)
0093 {
0094
0095 if (isMaster) {
0096 EndMaster(run);
0097 G4cout << "End of run action : " << EnergyOfIncidentPart << G4endl;
0098 }
0099 else {
0100 PrimaryGeneratorAction* PGA = (PrimaryGeneratorAction*)G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction();
0101 EnergyOfIncidentPart = PGA->GetParticleGPS()->GetCurrentSource()->GetEneDist()->GetMonoEnergy();
0102 EndWorker(run);
0103 }
0104
0105 }
0106
0107
0108
0109
0110 void RunAction::BeginMaster(const G4Run* run)
0111 {
0112 bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType() == G4RunManager::sequentialRM);
0113
0114 if(fDebug)
0115 {
0116 G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
0117 if(!sequential)
0118 G4cout << "°°°°°°°°°°°°°°°° RunAction::BeginMaster" << G4endl;
0119 PrintRunInfo(run);
0120 G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
0121 }
0122
0123 if(sequential)
0124 {
0125 if(!fInitialized)
0126 InitializeWorker(run);
0127
0128
0129
0130 }
0131
0132 else {
0133 if (run->GetRunID() == 0) { CreateSEYHistogram(); }
0134 }
0135 }
0136
0137
0138
0139 void RunAction::BeginWorker(const G4Run* run)
0140 {
0141 if(fDebug)
0142 {
0143 G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
0144 G4cout << "°°°°°°°°°°°°°°°° RunAction::BeginWorker" << G4endl;
0145 PrintRunInfo(run);
0146 G4cout << "°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°" << G4endl;
0147 }
0148 if(!fInitialized)
0149 InitializeWorker(run);
0150
0151
0152 }
0153
0154
0155
0156 void RunAction::EndMaster(const G4Run* run)
0157 {
0158 bool sequential = (G4RunManager::GetRunManager()->GetRunManagerType()
0159 == G4RunManager::sequentialRM);
0160 if (sequential) {
0161 EndWorker(run);
0162 }
0163 else {
0164
0165
0166
0167 if (run->GetRunID() == 0) {
0168 NbOfIncidentPart = run->GetNumberOfEvent();
0169 }
0170
0171
0172 MicroElecRun* localRun = (MicroElecRun*)(run);
0173
0174 EnergyOfIncidentPart = localRun->GetElecEneIncPart();
0175 G4double compteurTot = localRun->GetElecTotaScorer();
0176 G4double compteurPrimaire = localRun->GetElecPrimScorer();
0177 G4double compteurSec = localRun->GetElecSecoScorer();
0178 G4double compteurSup50 = localRun->GetElecSup50Scorer();
0179
0180 G4cout << "ooo End Master ooo, Run : " << run->GetRunID() << " | Energy = " << EnergyOfIncidentPart / eV <<
0181 " eV | Number of inci Part. = " << NbOfIncidentPart << " | Tot = " << compteurTot <<
0182 " | Primaires = " << compteurPrimaire << " | Sec = " << compteurSec << G4endl <<
0183 " | Taux d'emission = " << compteurTot/ NbOfIncidentPart << G4endl;
0184
0185 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0186 analysisManager->FillNtupleDColumn(0, EnergyOfIncidentPart/eV);
0187 analysisManager->FillNtupleDColumn(1, compteurTot/ NbOfIncidentPart);
0188 analysisManager->FillNtupleDColumn(2, compteurSec/ NbOfIncidentPart);
0189 analysisManager->FillNtupleDColumn(3, compteurPrimaire/ NbOfIncidentPart);
0190 analysisManager->FillNtupleDColumn(4, compteurSup50/ NbOfIncidentPart);
0191 analysisManager->AddNtupleRow();
0192 }
0193
0194 }
0195
0196
0197
0198 void RunAction::EndWorker(const G4Run* run)
0199 {
0200 if(fDebug)
0201 {
0202 PrintRunInfo(run);
0203 }
0204
0205
0206 G4int nofEvents = run->GetNumberOfEvent();
0207 if ( nofEvents == 0 )
0208 {
0209 if(fDebug)
0210 {
0211 G4cout << "°°°°°°°°°°°°°°°° NO EVENTS TREATED IN THIS RUN ==> LEAVING RunAction::EndOfRunAction "<< G4endl;
0212 }
0213 return;
0214 }
0215
0216
0217
0218
0219
0220
0221 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0222 analysisManager->Clear();
0223
0224
0225
0226
0227 std::map<const G4ParticleDefinition*, int>&
0228 particlesCreatedInWorld = fpTrackingAction->GetNParticlesCreatedInWorld();
0229 std::map<const G4ParticleDefinition*, int>&
0230 particlesCreatedInTarget = fpTrackingAction->GetNParticlesCreatedInTarget();
0231
0232 G4cout << "__________ooo End Worker ooo begin_____________" << G4endl;
0233 G4cout << " Number and type of particles created outside region \"Target\" :";
0234 PrintNParticles(particlesCreatedInWorld);
0235 G4cout << "ooo End Worker ooo, Number and type of particles created in region \"Target\" :";
0236 PrintNParticles(particlesCreatedInTarget);
0237 G4cout << "__________ooo End Worker ooo end_____________" << G4endl;
0238
0239
0240 }
0241
0242
0243
0244 void RunAction::InitializeWorker(const G4Run*)
0245 {
0246 if (fpTrackingAction == 0)
0247 {
0248 fpTrackingAction = (TrackingAction*) G4RunManager::GetRunManager()->GetUserTrackingAction();
0249
0250 if(fpTrackingAction == 0 && isMaster == false)
0251 {
0252 G4ExceptionDescription exDescrption ;
0253 exDescrption << "fpTrackingAction is a null pointer. Has it been correctly initialized ?";
0254 G4Exception("RunAction::BeginOfRunAction","RunAction001",FatalException, exDescrption);
0255 }
0256 }
0257
0258 fInitialized = true;
0259 }
0260
0261
0262
0263
0264
0265
0266 void RunAction::SetSEYFileName(G4String& name)
0267 {
0268 SEYfileName = name;
0269 }
0270
0271
0272
0273 void RunAction::CreateSEYHistogram()
0274 {
0275
0276
0277
0278
0279
0280
0281 G4cout << "##### Create analysis manager " << " " << this << G4endl;
0282 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0283 analysisManager->SetDefaultFileType("csv");
0284
0285 G4cout << "Using " << analysisManager->GetType() << " analysis manager" << G4endl;
0286
0287
0288
0289
0290
0291 analysisManager->SetVerboseLevel(1);
0292
0293
0294
0295 analysisManager->OpenFile(SEYfileName);
0296
0297
0298 analysisManager->CreateNtuple("data", "Sec. Ele. Emission");
0299 analysisManager->CreateNtupleDColumn("Initial energy (eV)");
0300 analysisManager->CreateNtupleDColumn("TEEY");
0301 analysisManager->CreateNtupleDColumn("SEEY");
0302 analysisManager->CreateNtupleDColumn("BEEY");
0303 analysisManager->CreateNtupleDColumn("EEY>50eV");
0304 analysisManager->FinishNtuple();
0305
0306
0307 }
0308
0309
0310
0311 void RunAction::WriteSEYHistogram()
0312 {
0313
0314
0315 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0316
0317
0318
0319 analysisManager->Write();
0320 analysisManager->CloseFile();
0321 }
0322
0323
0324
0325
0326
0327
0328 void RunAction::PrintRunInfo(const G4Run* run)
0329 {
0330 G4cout << "°°°°°°°°°°°°°°°° Run is = " << run->GetRunID() << G4endl;
0331 G4cout << "°°°°°°°°°°°°°°°° Run type is = " << G4RunManager::GetRunManager()->GetRunManagerType() << G4endl;
0332 G4cout << "°°°°°°°°°°°°°°°° Event processed = " << run->GetNumberOfEventToBeProcessed() << G4endl;
0333 G4cout << "°°°°°°°°°°°°°°°° N° Event = " << run->GetNumberOfEvent() << G4endl;
0334 }
0335
0336
0337 void PrintNParticles(std::map<const G4ParticleDefinition*, int>& container)
0338 {
0339 std::map<const G4ParticleDefinition*, int>::iterator it;
0340 for(it = container.begin() ;
0341 it != container.end(); it ++)
0342 {
0343 G4cout << "N " << it->first->GetParticleName() << " : " << it->second << G4endl;
0344 }
0345 }
0346
0347