Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /geant4/examples/advanced/hadrontherapy/hadrontherapy.cc was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 AUTHORS
0031 //                                  ====================
0032 //         G.A.P. Cirrone(a)*, L. Pandola(a), G. Petringa(a), S.Fattori(a), A.Sciuto(a)
0033 //              *Corresponding author, email to pablo.cirrone@lns.infn.it
0034 //
0035 //
0036 //                 ==========>   PAST CONTRIBUTORS  <==========
0037 //
0038 //                    R.Calcagno(a), G.Danielsen (b), F.Di Rosa(a),
0039 //                    S.Guatelli(c), A.Heikkinen(b), P.Kaitaniemi(b),
0040 //                    A.Lechner(d), S.E.Mazzaglia(a), Z. Mei(h), G.Milluzzo(a),
0041 //                    M.G.Pia(e), F.Romano(a), G.Russo(a,g),
0042 //                    M.Russo(a), A.Tramontana (a), A.Varisano(a)
0043 //
0044 //              (a) Laboratori Nazionali del Sud of INFN, Catania, Italy
0045 //              (b) Helsinki Institute of Physics, Helsinki, Finland
0046 //              (c) University of Wallongong, Australia
0047 //              (d) CERN, Geneve, Switzwerland
0048 //              (e) INFN Section of Genova, Genova, Italy
0049 //              (f) Physics and Astronomy Department, Univ. of Catania, Catania, Italy
0050 //              (g) CNR-IBFM, Italy
0051 //              (h) Institute of Applied Electromagnetic Engineering(IAEE)
0052 //                  Huazhong University of Science and Technology(HUST), Wuhan, China
0053 //
0054 //
0055 //                                          WEB
0056 //                                      ===========
0057 //       https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
0058 //
0059 // ----------------------------------------------------------------------------
0060 
0061 #include "G4RunManager.hh"
0062 #include "G4UImanager.hh"
0063 #include "G4PhysListFactory.hh"
0064 #include "G4VModularPhysicsList.hh"
0065 #include "HadrontherapyEventAction.hh"
0066 #include "HadrontherapyPhysicsList.hh"
0067 #include "HadrontherapyDetectorSD.hh"
0068 #include "HadrontherapyPrimaryGeneratorAction.hh"
0069 #include "HadrontherapyRunAction.hh"
0070 #include "HadrontherapyMatrix.hh"
0071 #include "Randomize.hh"
0072 
0073 #include "G4UImessenger.hh"
0074 #include "globals.hh"
0075 #include "HadrontherapySteppingAction.hh"
0076 #include "HadrontherapyGeometryController.hh"
0077 #include "HadrontherapyGeometryMessenger.hh"
0078 #include "HadrontherapyInteractionParameters.hh"
0079 #include "HadrontherapyLet.hh"
0080 
0081 #include "G4ScoringManager.hh"
0082 #include "G4ParallelWorldPhysics.hh"
0083 #include <time.h>
0084 #include "G4Timer.hh"
0085 #include "G4RunManagerFactory.hh"
0086 #include "HadrontherapyActionInitialization.hh"
0087 
0088 #include "G4VisExecutive.hh"
0089 #include "G4UIExecutive.hh"
0090 
0091 #include "QBBC.hh"
0092 
0093 //////////////////////////////////////////////////////////////////////////////////////////////
0094 int main(int argc ,char ** argv)
0095 {
0096     // Detect interactive mode (if no arguments) and define UI session
0097     //
0098     G4UIExecutive* ui = nullptr;
0099     if ( argc == 1 ) { ui = new G4UIExecutive(argc, argv); }
0100 
0101     //Instantiate the G4Timer object, to monitor the CPU time spent for
0102     //the entire execution
0103     G4Timer* theTimer = new G4Timer();
0104     //Start the benchmark
0105     theTimer->Start();
0106     
0107     // Set the Random engine
0108     // The following guarantees random generation also for different runs
0109     // in multithread
0110     CLHEP::RanluxEngine defaultEngine( 1234567, 4 );
0111     G4Random::setTheEngine( &defaultEngine );
0112     G4int seed = (G4int) time( NULL );
0113     G4Random::setTheSeed( seed );
0114     
0115     // Construct the default run manager
0116     //
0117     auto* runManager = G4RunManagerFactory::CreateRunManager(G4RunManagerType::Default);
0118     
0119     // Define the number of threads for the simulation runs
0120     G4int nThreads = 4;
0121     runManager->SetNumberOfThreads(nThreads);
0122 
0123     // Geometry controller is responsible for instantiating the geometries.
0124     //
0125     HadrontherapyGeometryController *geometryController = new HadrontherapyGeometryController();
0126     
0127     // Connect the geometry controller to the G4 user interface
0128     //
0129     HadrontherapyGeometryMessenger *geometryMessenger = new HadrontherapyGeometryMessenger(geometryController);
0130     
0131     G4ScoringManager *scoringManager = G4ScoringManager::GetScoringManager();
0132     scoringManager->SetVerboseLevel(1);
0133     
0134     // Initialize the default Hadrontherapy geometry
0135     geometryController->SetGeometry("default");
0136     
0137     // Initialize the physics
0138     G4PhysListFactory factory;
0139     G4VModularPhysicsList* physicsList = 0;
0140     physicsList = new HadrontherapyPhysicsList();
0141     
0142     if (physicsList)
0143     {
0144         G4cout << "Going to register G4ParallelWorldPhysics" << G4endl;
0145         physicsList -> RegisterPhysics(new G4ParallelWorldPhysics("DetectorROGeometry"));
0146     }
0147     
0148     // Initialisations of physics
0149     runManager->SetUserInitialization(physicsList);
0150     
0151     // Initialisation of the Actions
0152     runManager->SetUserInitialization(new HadrontherapyActionInitialization);
0153     
0154     // Initialize command based scoring
0155     G4ScoringManager::GetScoringManager();
0156     
0157     // Interaction data: stopping powers
0158     //
0159     HadrontherapyInteractionParameters* pInteraction = new HadrontherapyInteractionParameters(true);
0160     
0161     // Initialize analysis
0162     //
0163     HadrontherapyAnalysis* analysis = HadrontherapyAnalysis::GetInstance();
0164     
0165 
0166     // Initialise the Visualisation
0167     //
0168     auto visManager = new G4VisExecutive(argc, argv);
0169     visManager -> Initialize();
0170     
0171     //** Get the pointer to the User Interface manager
0172     //
0173     auto UImanager = G4UImanager::GetUIpointer();
0174     
0175     if ( !ui ) {
0176         // batch mode
0177         G4String command = "/control/execute ";
0178         G4String fileName = argv[1];
0179         UImanager->ApplyCommand(command+fileName);
0180     }
0181     
0182     else {
0183         UImanager -> ApplyCommand("/control/macroPath macro");
0184         UImanager -> ApplyCommand("/control/execute macro/defaultMacro.mac");
0185         ui -> SessionStart();
0186         delete ui;
0187     }
0188     delete visManager;
0189  
0190     //Stop the benchmark here
0191     theTimer->Stop();
0192     
0193     G4cout << "The simulation took: " << theTimer->GetRealElapsed() << " s to run (real time)"
0194     << G4endl;
0195     
0196     // Job termination
0197     // Free the store: user actions, physics_list and detector_description are
0198     // owned and deleted by the run manager, so they should not be deleted
0199     // in the main() program !
0200     
0201     
0202         if ( HadrontherapyMatrix * pMatrix = HadrontherapyMatrix::GetInstance() )
0203     {
0204         // pMatrix -> TotalEnergyDeposit();
0205         pMatrix -> StoreDoseFluenceAscii();
0206         
0207     }
0208     
0209     if (HadrontherapyLet *let = HadrontherapyLet::GetInstance())
0210         if(let -> doCalculation)
0211         {
0212             let -> LetOutput();     // Calculate let
0213             let -> StoreLetAscii(); // Store it
0214         }
0215     
0216     delete geometryMessenger;
0217     delete geometryController;
0218     delete pInteraction;
0219     delete runManager;
0220     delete analysis;
0221     return 0;
0222     
0223 }