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 // 27 /// \file field/field01/field01.cc 28 /// \brief Main program of the field/field01 example 29 // 30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 33 #include "F01ActionInitialization.hh" 34 #include "F01DetectorConstruction.hh" 35 #include "F01RunAction.hh" 36 #include "F01SteppingVerbose.hh" 37 38 #include "G4RunManagerFactory.hh" 39 #include "G4Types.hh" 40 #include "G4UImanager.hh" 41 42 #include "FTFP_BERT.hh" 43 44 #include "G4EmParameters.hh" 45 #include "G4HadronicParameters.hh" 46 #include "G4PhysicsListHelper.hh" 47 #include "G4StepLimiterPhysics.hh" 48 #include "G4UIExecutive.hh" 49 #include "G4VisExecutive.hh" 50 #include "Randomize.hh" 51 52 // For Printing statistic from Transporation process(es) 53 #include "G4CoupledTransportation.hh" 54 #include "G4Electron.hh" 55 #include "G4Transportation.hh" 56 #include "G4TransportationParameters.hh" 57 58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 60 int main(int argc, char** argv) 61 { 62 // Instantiate G4UIExecutive if there are no arguments (interactive mode) 63 // 64 G4UIExecutive* ui = nullptr; 65 if (argc == 1) { 66 ui = new G4UIExecutive(argc, argv); 67 } 68 69 // Setting the application-specific SteppingVerbose 70 // 71 auto verbosity = new F01SteppingVerbose; 72 73 // Construct the default run manager 74 auto runManager = G4RunManagerFactory::CreateRunManager(); 75 76 // G4TransportationWithMscType: fDisabled, fEnabled, fMultipleSteps 77 // G4EmParameters::Instance()->SetTransportationWithMsc(G4TransportationWithMscType::fEnabled); 78 79 // Set mandatory initialization classes 80 // 81 // Detector construction 82 auto detector = new F01DetectorConstruction(); 83 // detector->SetUseFSALstepper(); // Uncomment to use FSAL steppers 84 85 runManager->SetUserInitialization(detector); 86 87 // Configure the use of low thresholds for looping particles 88 // ( appropriate for typical applications using low-energy physics. ) 89 // auto plHelper = G4PhysicsListHelper::GetPhysicsListHelper(); 90 // plHelper->UseLowLooperThresholds(); 91 // plHelper->UseHighLooperThresholds(); 92 // Request a set of pre-selected values of the parameters for looping 93 // particles: 94 // - High for collider HEP applications, 95 // - Low for 'low-E' applications, medical, .. 96 // Note: If helper is used select low or high thresholds , it will overwrite 97 // values from TransportationParameters! 98 99 // They are currently applied in the following order: 100 // 1. Transportation Parameters - fine grained control in Transportation construction 101 // 2. Physics List Helper - impose a fixed set of new values in Transport classes 102 // 3. Run Action (F01RunAction) - revise values at Start of Run 103 // 4. Tracking Action - could revise value at start of each track (not shown) 104 // Note that this also could customise by particle type, e.g. giving different values 105 // to mu-/mu+ , e-/e+ vs others) 106 // If multiple are present, later methods overwrite previous ones in this list. 107 108 // Physics list 109 G4VModularPhysicsList* physicsList = new FTFP_BERT; 110 physicsList->RegisterPhysics(new G4StepLimiterPhysics()); 111 runManager->SetUserInitialization(physicsList); 112 113 // User action initialization 114 runManager->SetUserInitialization(new F01ActionInitialization(detector)); 115 116 G4double warningE = 10.0 * CLHEP::keV; 117 G4double importantE = 0.1 * CLHEP::MeV; 118 G4int numTrials = 30; 119 120 G4bool useTransportParams = true; // Use the new way - Nov 2022 121 122 if (useTransportParams) { 123 auto transportParams = G4TransportationParameters::Instance(); 124 transportParams->SetWarningEnergy(warningE); 125 transportParams->SetImportantEnergy(importantE); 126 transportParams->SetNumberOfTrials(numTrials); 127 G4cout << "field01: Using G4TransportationParameters to set looper parameters." << G4endl; 128 } 129 else { 130 // Fine grained control of thresholds for looping particles 131 auto runAction = new F01RunAction(); 132 runAction->SetWarningEnergy(warningE); 133 // Looping particles with E < 10 keV will be killed after 1 step 134 // with warning. 135 // Looping particles with E > 10 keV will generate a warning. 136 runAction->SetImportantEnergy(importantE); 137 runAction->SetNumberOfTrials(numTrials); 138 // Looping particles with E > 0.1 MeV will survive for up to 139 // 30 'tracking' steps, and only be killed if they still loop. 140 141 G4cout << "field01: Using F01RunAction to set looper parameters." << G4endl; 142 runManager->SetUserAction(runAction); 143 } 144 145 // Note: this mechanism overwrites the thresholds established by 146 // the call to UseLowLooperThresholds() above. 147 148 // Suppress large verbosity from EM & hadronic processes 149 G4EmParameters::Instance()->SetVerbose(0); 150 G4HadronicParameters::Instance()->SetVerboseLevel(0); 151 152 // Initialize G4 kernel 153 // 154 runManager->Initialize(); 155 156 // Initialize visualization 157 // 158 // G4VisExecutive can take a verbosity argument - see /vis/verbose 159 G4VisManager* visManager = new G4VisExecutive("Quiet"); 160 visManager->Initialize(); 161 162 // Get the pointer to the User Interface manager 163 // 164 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 165 166 if (!ui) // batch mode 167 { 168 G4String command = "/control/execute "; 169 G4String fileName = argv[1]; 170 UImanager->ApplyCommand(command + fileName); 171 } 172 else { // interactive mode : define UI session 173 UImanager->ApplyCommand("/control/execute init_vis.mac"); 174 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac"); 175 ui->SessionStart(); 176 delete ui; 177 } 178 179 // Statistics of tracks killed by G4Transportation are currently 180 // printed in the RunAction's EndOfEvent action. 181 // ( Eventually a summary could be provided here instead or as well. ) 182 183 delete verbosity; 184 delete visManager; 185 delete runManager; 186 187 return 0; 188 } 189 190 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 191