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 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 ///  \file HadronicNucleusXS.cc
 27 ///  \brief Main program,
 28 ///         hadronic/FlukaCern/ProcessLevel/CrossSection example.
 29 //
 30 //  Author: G.Hugo, 06 January 2023
 31 //
 32 // -------------------------------------------------------------
 33 //
 34 //      GEANT4 HadronNucleusXS
 35 //
 36 ///  This application allows the study of G4 cross-sections,
 37 ///  and in addition, of the FLUKA hadron-nucleus inelastic cross sections.
 38 ///
 39 ///  The user can printout any particle-material XS.
 40 ///  The XS are exactly the ones defined in any default G4 PhysicsList chosen by the user,
 41 ///  or from FLUKA (hadron-nucleus inelastic case).
 42 ///
 43 ///  In the input file, the user can set:
 44 ///  - projectile.
 45 ///  - target material (element, compound or even mixture).
 46 ///  - plotting options.
 47 ///
 48 ///  All plots (created via the G4 analysis manager) can be dumped
 49 ///  to any of the usually supported formats (e.g. ROOT format),
 50 ///  but also in a Flair-compatible format.
 51 ///
 52 ///  NB 1: Unlike the FlukaCern/ProcessLevel/FinalState example,
 53 ///  the choice here is to directly use physics lists
 54 ///  (hence under the hood, the processes they define),
 55 ///  instead of 'hardcoding' processes of interest.
 56 ///  This allows to directly study ALL XS, with no possible discrepancy
 57 ///  with respect to what is defined inside the physics lists.
 58 ///
 59 ///  NB 2: Note that here, the application is completely independent
 60 ///  from the event loop, gun, detector etc:
 61 ///  the XS printout happend outside of the event loop anyway.
 62 ///  Hence, the fakeRun mode is used (setting number of events to 0).
 63 ///  This implies that no ActionInitialization is needed
 64 ///  (nor would be used anyway, if ever constructed),
 65 ///  and that the detector is a dummy, empty one.
 66 
 67 ///  Use: build/HadronNucleusXS all_XS.in FTFP_BERT_HP
 68 ///       build/HadronNucleusXS all_XS.in G4_HP_CFLUKAHI
 69 //
 70 // -------------------------------------------------------------
 71 //
 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 74 
 75 #include "DetectorConstruction.hh"
 76 
 77 #include "G4PhysListFactory.hh"
 78 #include "G4RunManager.hh"
 79 #include "G4RunManagerFactory.hh"
 80 #include "G4VModularPhysicsList.hh"
 81 
 82 #ifdef G4_USE_FLUKA
 83 #  include "FLUKAParticleTable.hh"
 84 
 85 #  include "G4_HP_CernFLUKAHadronInelastic_PhysicsList.hh"
 86 #endif
 87 
 88 #include "XSHistoManager.hh"
 89 
 90 #include "G4Exception.hh"
 91 #include "G4UImanager.hh"
 92 
 93 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 94 
 95 G4int main(G4int argc, char** argv)
 96 {
 97   // Check number of arguments
 98   if (argc != 3) {
 99     G4Exception("HadronNucleusXS (main)", "Wrong number of input arguments.", FatalException,
100                 "Example use: build/HadronNucleusXS all_XS.in FTFP_BERT_HP");
101   }
102 
103   // Construct a serial RUN MANAGER.
104   std::unique_ptr<G4RunManager> runManager(
105     G4RunManagerFactory::CreateRunManager(G4RunManagerType::SerialOnly));
106 
107   // Empty DETECTOR (compulsory).
108   const auto dummyDetector = new DetectorConstruction();
109   // The detector is owned by G4RunManager.
110   runManager->SetUserInitialization(dummyDetector);
111 
112   // Get PHYSICS LIST from command line argument.
113   // Default: G4_HP_CFLUKAHI.
114   const G4String physicsListName = (argc >= 3 ? argv[2] : "G4_HP_CFLUKAHI");
115   const G4bool isFLUKAPhysicsList = (physicsListName == "G4_HP_CFLUKAHI");
116 
117   G4VModularPhysicsList* physicsList = nullptr;
118 
119   // Create physics list with hadron inelastic processes from FLUKA.
120   if (isFLUKAPhysicsList) {
121 #ifdef G4_USE_FLUKA
122     physicsList = new G4_HP_CernFLUKAHadronInelastic_PhysicsList();
123 #else
124     G4Exception("HadronNucleusXS.cc", "Wrong compilation mode.", FatalException,
125                 "Requested G4_HP_CernFLUKAHadronInelastic physics list.\n"
126                 "This requires COMPILATION in FLUKA mode.\n"
127                 "Please fully recompile the example with G4_USE_FLUKA=yes.\n"
128                 "For example:\n"
129                 "source geant4/examples/extended/hadronic/FlukaCern/FlukaInterface/"
130                 "env_FLUKA_G4_interface.sh\n"
131                 "cd geant4/examples/extended/hadronic/FlukaCern/ProcessLevel/CrossSection/\n"
132                 "mkdir build\n"
133                 "cd build\n"
134                 "cmake -DGeant4_DIR=your_path_to_geant4 -DG4_USE_FLUKA=1 .. \n"
135                 "make -j8 G4_USE_FLUKA=1\n"
136                 "NB: First time use of FLUKA interface:\n"
137                 "Do not forget to first compile the FLUKA interface itself.\n"
138                 "For example: cd geant4/examples/extended/hadronic/FlukaCern/FlukaInterface/ "
139                 "&& make interface && make env\n"
140                 "FlukaInterface/env_FLUKA_G4_interface.sh then needs to be sourced\n"
141                 "in whichever terminal you want to use the FLUKA interface.\n");
142 #endif
143   }
144   // Create G4 physics list from available catalog.
145   else {
146     auto factory = G4PhysListFactory();
147     physicsList = factory.GetReferencePhysList(physicsListName);
148   }
149 
150   // The physics list is owned by G4RunManager.
151   runManager->SetUserInitialization(physicsList);
152 
153 #ifdef G4_USE_FLUKA
154   if (isFLUKAPhysicsList) {
155     // Initialize FLUKA <-> G4 particles conversions tables.
156     fluka_particle_table::initialize();
157   }
158 #endif
159 
160   // Create HISTO MANAGER (and its messenger).
161   auto histoManager = XSHistoManager();
162 
163   // User interface manager (owned by G4RunManagerKernel).
164   const auto uiManager = G4UImanager::GetUIpointer();
165   // BATCH MODE.
166   const G4String command = "/control/execute ";
167   const G4String fileName = argv[1];
168   uiManager->ApplyCommand(command + fileName);
169 
170   // CREATE HISTOGRAMS AND FILL THEM (independent from event loop!).
171   histoManager.Book();
172   histoManager.EndOfRun();
173 }
174 
175 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
176