Geant4 Cross Reference |
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 #include "F01RunAction.hh" 27 28 #include "G4CoupledTransportation.hh" 29 #include "G4Electron.hh" 30 #include "G4ParticleDefinition.hh" 31 #include "G4ProcessManager.hh" 32 #include "G4Run.hh" 33 #include "G4SystemOfUnits.hh" 34 #include "G4Transportation.hh" 35 #include "globals.hh" 36 37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 38 39 void F01RunAction::BeginOfRunAction(const G4Run* aRun) 40 { 41 G4cout << "### Run " << aRun->GetRunID() << " start." << G4endl; 42 43 G4cout << " Calling F01RunAction::ChangeLooperParameters() " << G4endl; 44 ChangeLooperParameters(G4Electron::Definition()); 45 } 46 47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 48 49 void F01RunAction::ChangeLooperParameters(const G4ParticleDefinition* particleDef) 50 { 51 if (particleDef == nullptr) particleDef = G4Electron::Definition(); 52 auto transport = FindTransportation(particleDef); 53 54 // Note that all particles that share the same Transportation 55 // (or Coupled Transportation) process (with this particle) 56 // will be affected by this change 57 // -- to change these parameters by particle type, the values 58 // must instead be changed/reset in a (Start) Tracking Action. 59 60 G4cout << " ChangeLooperParameters called with particle type " << particleDef->GetParticleName() 61 << " transport process: "; 62 if (transport != nullptr) { 63 G4cout << transport->GetProcessName(); 64 } 65 else { 66 G4cout << " UNKNOWN -- it is neither G4Transportation nor G4CoupledTransportation"; 67 } 68 G4cout << G4endl; 69 70 if (transport != nullptr) { 71 if (fWarningEnergy >= 0.0) { 72 transport->SetThresholdWarningEnergy(fWarningEnergy); 73 G4cout << "-- Changed Threshold Warning Energy (for loopers) = " 74 << fWarningEnergy / CLHEP::MeV << " MeV " << G4endl; 75 } 76 if (fImportantEnergy >= 0.0) { 77 transport->SetThresholdImportantEnergy(fImportantEnergy); 78 79 G4cout << "-- Changed Threshold Important Energy (for loopers) = " 80 << fImportantEnergy / CLHEP::MeV << " MeV " << G4endl; 81 } 82 83 if (fNumberOfTrials > 0) { 84 transport->SetThresholdTrials(fNumberOfTrials); 85 86 G4cout << "-- Changed number of Trials (for loopers) = " << fNumberOfTrials << G4endl; 87 } 88 } 89 90 if (transport == nullptr) { 91 if (fWarningEnergy >= 0.0) 92 G4cerr << " Unknown transport process> Cannot change Warning Energy. " << G4endl; 93 if (fImportantEnergy >= 0.0) 94 G4cerr << " Unknown transport process> Cannot change 'Important' Energy. " << G4endl; 95 if (fNumberOfTrials > 0) 96 G4cerr << " Unknown transport process> Cannot change number of trials. " << G4endl; 97 } 98 } 99 100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 101 102 void F01RunAction::EndOfRunAction(const G4Run*) 103 { 104 if (fVerboseLevel > 1) 105 G4cout << G4endl << G4endl << " ########### Track Statistics for Transportation process(es) " 106 << " ########### " << G4endl << " ############################################## " 107 << " ####################### " << G4endl << G4endl; 108 109 auto transport = FindTransportation(G4Electron::Definition()); 110 if (transport) { 111 transport->PrintStatistics(G4cout); 112 } 113 } 114 115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 116 117 G4Transportation* F01RunAction::FindTransportation(const G4ParticleDefinition* particleDef, 118 bool reportError) 119 { 120 const auto* partPM = particleDef->GetProcessManager(); 121 122 G4VProcess* partTransport = partPM->GetProcess("Transportation"); 123 auto transport = dynamic_cast<G4Transportation*>(partTransport); 124 125 if (!transport) { 126 partTransport = partPM->GetProcess("CoupledTransportation"); 127 auto coupledTransport = dynamic_cast<G4CoupledTransportation*>(partTransport); 128 if (coupledTransport) { 129 transport = coupledTransport; 130 } 131 else { 132 partTransport = partPM->GetProcess("TransportationWithMsc"); 133 auto transportWithMsc = dynamic_cast<G4CoupledTransportation*>(partTransport); 134 if (transportWithMsc) { 135 transport = transportWithMsc; 136 } 137 } 138 } 139 140 if (reportError && !transport) { 141 G4cerr << "Unable to find Transportation process for particle type " 142 << particleDef->GetParticleName() << " ( PDG code = " << particleDef->GetPDGEncoding() 143 << " ) " << G4endl; 144 } 145 146 return transport; 147 } 148