Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:20:09

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //      ----------------------------------------------------------------------------
0027 //                              GEANT 4 - Hadrontherapy example
0028 //      ----------------------------------------------------------------------------
0029 //
0030 //                                      MAIN AUTHOR
0031 //                                  ====================
0032 //                                  G.A.P. Cirrone(a)*
0033 //
0034 //                 *Corresponding author, email to pablo.cirrone@lns.infn.it
0035 //
0036 //                                  ACTUAL CONTRIBUTORS
0037 //                                  ====================
0038 //                  G.A.P. Cirrone(a), L. Pandola(a), G. Petringa(a)
0039 //
0040 //
0041 //                      ==========>   PAST CONTRIBUTORS  <==========
0042 //
0043 //                      R. Calcagno(a), G.Danielsen (b), F.Di Rosa(a),
0044 //                      S.Guatelli(c), A.Heikkinen(b), P.Kaitaniemi(b),
0045 //                      A.Lechner(d), S.E.Mazzaglia(a), Z. Mei(h), M.G.Pia(e),
0046 //                      F.Romano(a), G.Russo(a,g), M.Russo(a), A. Tramontana (a),
0047 //                      A.Varisano(a)
0048 //
0049 //              (a) Laboratori Nazionali del Sud of INFN, Catania, Italy
0050 //              (b) Helsinki Institute of Physics, Helsinki, Finland
0051 //              (c) University of Wallongong, Australia
0052 //              (d) CERN, Geneve, Switzwerland
0053 //              (e) INFN Section of Genova, Genova, Italy
0054 //              (f) Physics and Astronomy Department, Univ. of Catania, Catania, Italy
0055 //              (g) CNR-IBFM, Italy
0056 //              (h) Institute of Applied Electromagnetic Engineering(IAEE)
0057 //                  Huazhong University of Science and Technology(HUST), Wuhan, China
0058 //
0059 //
0060 //                                          WEB
0061 //                                      ===========
0062 //       https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
0063 //
0064 // ----------------------------------------------------------------------------
0065 
0066 #include "G4RunManager.hh"
0067 #include "G4UImanager.hh"
0068 #include "G4PhysListFactory.hh"
0069 #include "G4VModularPhysicsList.hh"
0070 #include "HadrontherapyEventAction.hh"
0071 #include "HadrontherapyPhysicsList.hh"
0072 #include "HadrontherapyDetectorSD.hh"
0073 #include "HadrontherapyPrimaryGeneratorAction.hh"
0074 #include "HadrontherapyRunAction.hh"
0075 #include "HadrontherapyMatrix.hh"
0076 #include "Randomize.hh"
0077 
0078 #include "G4UImessenger.hh"
0079 #include "globals.hh"
0080 #include "HadrontherapySteppingAction.hh"
0081 #include "HadrontherapyGeometryController.hh"
0082 #include "HadrontherapyGeometryMessenger.hh"
0083 #include "HadrontherapyInteractionParameters.hh"
0084 #include "HadrontherapyLet.hh"
0085 
0086 #include "G4ScoringManager.hh"
0087 #include "G4ParallelWorldPhysics.hh"
0088 #include <time.h>
0089 #include "G4Timer.hh"
0090 #include "G4RunManagerFactory.hh"
0091 #include "HadrontherapyActionInitialization.hh"
0092 
0093 #include "G4VisExecutive.hh"
0094 #include "G4UIExecutive.hh"
0095 
0096 //////////////////////////////////////////////////////////////////////////////////////////////
0097 int main(int argc ,char ** argv)
0098 {
0099         G4UIExecutive* ui = 0;
0100     if ( argc == 1 ) {
0101         ui = new G4UIExecutive(argc, argv);
0102     }
0103     
0104     //Instantiate the G4Timer object, to monitor the CPU time spent for
0105     //the entire execution
0106     G4Timer* theTimer = new G4Timer();
0107     //Start the benchmark
0108     theTimer->Start();
0109     
0110     // Set the Random engine
0111     // The following guarantees random generation also for different runs
0112     // in multithread
0113     CLHEP::RanluxEngine defaultEngine( 1234567, 4 );
0114     G4Random::setTheEngine( &defaultEngine );
0115     G4int seed = (G4int) time( NULL );
0116     G4Random::setTheSeed( seed );
0117  
0118  auto* runManager = G4RunManagerFactory::CreateRunManager();
0119  G4int nThreads = 4;
0120  runManager->SetNumberOfThreads(nThreads); 
0121 
0122     // Geometry controller is responsible for instantiating the
0123     // geometries. All geometry specific m tasks are now in class
0124     // HadrontherapyGeometryController.
0125     HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController();
0126     
0127     // Connect the geometry controller to the G4 user interface
0128     HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
0129     
0130     G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager();
0131     scoringManager->SetVerboseLevel(1);
0132     
0133     // Initialize the default Hadrontherapy geometry
0134     geometryController->SetGeometry("default");
0135     
0136     // Initialize the physics
0137     G4PhysListFactory factory;
0138     G4VModularPhysicsList* phys = 0;
0139     G4String physName = "";
0140     
0141     // Physics List name defined via environment variable
0142     char* path = std::getenv("PHYSLIST");
0143     if (path) { physName = G4String(path); }
0144     
0145     if(physName != "" && factory.IsReferencePhysList(physName))
0146     {
0147         phys = factory.GetReferencePhysList(physName);
0148     }
0149     if (phys)
0150     {
0151         G4cout << "Going to register G4ParallelWorldPhysics" << G4endl;
0152         phys->RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry"));
0153     }
0154     else
0155     {
0156         G4cout << "Using HadrontherapyPhysicsList()" << G4endl;
0157         phys = new HadrontherapyPhysicsList();
0158     }
0159     
0160     // Initialisations of physics
0161     runManager->SetUserInitialization(phys);
0162     
0163     // Initialisation of the Actions
0164     runManager->SetUserInitialization(new HadrontherapyActionInitialization);
0165     
0166     // Initialize command based scoring
0167     G4ScoringManager::GetScoringManager();
0168     
0169     // Interaction data: stopping powers
0170     HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true);
0171     
0172     // Initialize analysis
0173     HadrontherapyAnalysis* analysis = HadrontherapyAnalysis::GetInstance();
0174     
0175 
0176     
0177 // Initialise the Visualisation
0178     G4VisManager* visManager = new G4VisExecutive;
0179     visManager -> Initialize();
0180     
0181     //** Get the pointer to the User Interface manager
0182     G4UImanager* UImanager = G4UImanager::GetUIpointer();
0183     
0184     if ( !ui ) {
0185         // batch mode
0186         G4String command = "/control/execute ";
0187         G4String fileName = argv[1];
0188         UImanager->ApplyCommand(command+fileName);
0189         
0190     }
0191     
0192     else {
0193 
0194         UImanager -> ApplyCommand("/control/execute macro/defaultMacro.mac");
0195         ui -> SessionStart();
0196         delete ui;
0197     }
0198     delete visManager;
0199  
0200     //Stop the benchmark here
0201     theTimer->Stop();
0202     
0203     G4cout << "The simulation took: " << theTimer->GetRealElapsed() << " s to run (real time)"
0204     << G4endl;
0205     
0206     // Job termination
0207     // Free the store: user actions, physics_list and detector_description are
0208     // owned and deleted by the run manager, so they should not be deleted
0209     // in the main() program !
0210     
0211     
0212         if ( HadrontherapyMatrix * pMatrix = HadrontherapyMatrix::GetInstance() )
0213     {
0214         // pMatrix -> TotalEnergyDeposit();
0215         pMatrix -> StoreDoseFluenceAscii();
0216         
0217     }
0218     
0219     if (HadrontherapyLet *let = HadrontherapyLet::GetInstance())
0220         if(let -> doCalculation)
0221         {
0222             let -> LetOutput();     // Calculate let
0223             let -> StoreLetAscii(); // Store it
0224         }
0225     
0226     delete geometryMessenger;
0227     delete geometryController;
0228     delete pInteraction;
0229     delete runManager;
0230     delete analysis;
0231     return 0;
0232     
0233 }