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3 ] [ 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 ]

Diff markup

Differences between /examples/extended/geometry/vecGeomNavigation/exampleVecGeomNav.cc (Version 11.3.0) and /examples/extended/geometry/vecGeomNavigation/exampleVecGeomNav.cc (Version 11.0.p4)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //  Author: J. Apostolakis, S. Wenzel,  2018-2     26 //  Author: J. Apostolakis, S. Wenzel,  2018-2021
 27 //                                                 27 //
 28 //  Started from FullCMS Geant4 application by     28 //  Started from FullCMS Geant4 application by Mihaly Novak  (2017)
 29 //--------------------------------------------     29 //---------------------------------------------------------------------
 30                                                    30 
 31 #include "FTFP_BERT.hh"                        <<  31 #include <iostream>
 32 #include "VG01ActionInitialization.hh"         <<  32 #include <iomanip>
 33 #include "VG01DetectorConstruction.hh"         << 
 34 #include "VG01SteppingVerboseWithDir.hh"       << 
 35                                                    33 
 36 #include "G4RunManager.hh"                         34 #include "G4RunManager.hh"
 37 #include "G4RunManagerFactory.hh"                  35 #include "G4RunManagerFactory.hh"
 38 #include "G4StepLimiterPhysics.hh"             <<  36 
 39 #include "G4UImanager.hh"                          37 #include "G4UImanager.hh"
 40 #include "G4UIsession.hh"                          38 #include "G4UIsession.hh"
 41 #include "G4UIterminal.hh"                         39 #include "G4UIterminal.hh"
                                                   >>  40 
 42 #include "G4VModularPhysicsList.hh"                41 #include "G4VModularPhysicsList.hh"
                                                   >>  42 #include "FTFP_BERT.hh"
                                                   >>  43 #include "G4StepLimiterPhysics.hh"
                                                   >>  44 
 43 #include "Randomize.hh"                            45 #include "Randomize.hh"
 44                                                    46 
 45 #include <iomanip>                             <<  47 #include "VG01DetectorConstruction.hh"
 46 #include <iostream>                            <<  48 #include "VG01ActionInitialization.hh"
                                                   >>  49 #include "VG01SteppingVerboseWithDir.hh"
 47                                                    50 
 48 // For interactivity                               51 // For interactivity
 49 #include "G4UIExecutive.hh"                        52 #include "G4UIExecutive.hh"
 50 #include "G4VisExecutive.hh"                       53 #include "G4VisExecutive.hh"
 51                                                    54 
 52 static G4bool parUseVecGeom = true;            <<  55 static G4bool       parUseVecGeom = true;
 53 static G4bool parCompareG4 = false;            <<  56 static G4bool       parCompareG4  = false;
 54 static G4bool parInteractive = false;          <<  57 static G4bool       parInteractive = false;
 55 static std::string parMacroFileName = "";      <<  58 static std::string  parMacroFileName = "";
 56 static std::string parGDMLFile = "TestNTST.gdm <<  59 static std::string  parGDMLFile = "TestNTST.gdml";
 57                                                    60 
 58 void GetInputArguments(int argc, char** argv);     61 void GetInputArguments(int argc, char** argv);
 59 void PrintUsage();                                 62 void PrintUsage();
 60                                                    63 
 61 int main(int argc, char** argv)                <<  64 int main(int argc, char** argv) {
 62 {                                              << 
 63   //                                               65   //
 64   // get input arguments                           66   // get input arguments
 65   GetInputArguments(argc, argv);                   67   GetInputArguments(argc, argv);
 66   G4cout << " ========== Running exampleVecGeo <<  68   G4cout<< " ========== Running exampleVecGeomNav ================ " << G4endl
 67          << "   GDML geometry file          =  <<  69         << "   GDML geometry file          =  " << parGDMLFile       << G4endl
 68          << "   Geant4 macro                =  <<  70         << "   Geant4 macro                =  " << parMacroFileName  << G4endl
 69          << "   Use VecGeom (VG) navigation =  <<  71         << "   Use VecGeom (VG) navigation =  " << parUseVecGeom     << G4endl
 70          << "   Compare G4 vs VG navigation =  <<  72         << "   Compare G4 vs VG navigation =  " << parCompareG4      << G4endl
 71          << " ================================ <<  73         << " ===================================================== " << G4endl;
 72                                                    74 
 73   // Use custom stepping verbosity                 75   // Use custom stepping verbosity
 74   G4VSteppingVerbose::SetInstance(new VG01Step <<  76   G4VSteppingVerbose::SetInstance( new VG01SteppingVerboseWithDir() );       
 75                                                    77 
 76   // Construct the run manager                     78   // Construct the run manager
 77   //                                               79   //
 78   G4RunManager* runManager = G4RunManagerFacto <<  80   G4RunManager* runManager 
                                                   >>  81       = G4RunManagerFactory::CreateRunManager( G4RunManagerType::Serial);
 79   //  or G4RunManagerType::Default to get Task     82   //  or G4RunManagerType::Default to get Task or Multithreading
 80                                                    83 
 81   // set mandatory initialization classes          84   // set mandatory initialization classes
 82   //                                               85   //
 83   // 1. Detector construction                      86   // 1. Detector construction
 84   //                                               87   //
 85   VG01DetectorConstruction* detector = new VG0     88   VG01DetectorConstruction* detector = new VG01DetectorConstruction;
 86   detector->SetGDMLFileName(parGDMLFile);          89   detector->SetGDMLFileName(parGDMLFile);
 87   detector->SetUseVecGeom(parUseVecGeom);          90   detector->SetUseVecGeom(parUseVecGeom);
 88   runManager->SetUserInitialization(detector);     91   runManager->SetUserInitialization(detector);
 89                                                    92 
 90   // 2. Physics list                               93   // 2. Physics list
 91   //                                               94   //
 92   G4VModularPhysicsList* physicsList = new FTF     95   G4VModularPhysicsList* physicsList = new FTFP_BERT;
 93   physicsList->RegisterPhysics(new G4StepLimit     96   physicsList->RegisterPhysics(new G4StepLimiterPhysics());
 94   runManager->SetUserInitialization(physicsLis     97   runManager->SetUserInitialization(physicsList);
 95                                                    98 
 96   // 3. User action                                99   // 3. User action
 97   //                                           << 100   //  
 98   runManager->SetUserInitialization(new VG01Ac    101   runManager->SetUserInitialization(new VG01ActionInitialization());
 99                                                   102 
100   // 4. Run the simulation in batch mode, exce    103   // 4. Run the simulation in batch mode, except if macroFile == "-"
101   //                                           << 104   //  
102   G4UImanager* UImgr = G4UImanager::GetUIpoint    105   G4UImanager* UImgr = G4UImanager::GetUIpointer();
103   G4String command = "/control/execute ";         106   G4String command = "/control/execute ";
104   if (parMacroFileName != "-") UImgr->ApplyCom << 107   if( parMacroFileName != "-")
                                                   >> 108      UImgr->ApplyCommand(command+parMacroFileName);
105                                                   109 
106   // 5. Run the simulation in Interactive mode    110   // 5. Run the simulation in Interactive mode if requested ( flag: -i )
107   //                                              111   //
108   if (parInteractive) {                        << 112   if( parInteractive )
109     G4UIExecutive* uiExec = 0;                 << 113   {
110     uiExec = new G4UIExecutive(argc, argv);    << 114      G4UIExecutive* uiExec = 0;
111                                                << 115      uiExec = new G4UIExecutive(argc, argv);
112     // Initialize visualization                << 116 
113     //                                         << 117      // Initialize visualization
114     G4VisManager* visManager = new G4VisExecut << 118      //
115     // G4VisExecutive can take a verbosity arg << 119      G4VisManager* visManager = new G4VisExecutive;
116     // G4VisManager* visManager = new G4VisExe << 120      // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
117     visManager->Initialize();                  << 121      // G4VisManager* visManager = new G4VisExecutive("Quiet");
118                                                << 122      visManager->Initialize();
119     // UImgr->ApplyCommand("/control/execute i << 123 
120                                                << 124      // UImgr->ApplyCommand("/control/execute init_vis.mac");
121     // interactive mode                        << 125 
122     uiExec->SessionStart();                    << 126      // interactive mode
123                                                << 127      uiExec->SessionStart();
124     // Cleanup                                 << 128 
125     delete uiExec;                             << 129      // Cleanup
126     delete visManager;                         << 130      delete uiExec;
127   }                                            << 131      delete visManager;
128   else {                                       << 132   } 
                                                   >> 133   else 
                                                   >> 134   {
                                                   >> 135 
129     // Print out the final random number - for    136     // Print out the final random number - for batch only runs
130     G4cout << G4endl                              137     G4cout << G4endl
131            << " ==============================    138            << " ================================================================= " << G4endl
132            << " Final random number = " << G4U    139            << " Final random number = " << G4UniformRand() << G4endl
133            << " ==============================    140            << " ================================================================= " << G4endl
134            << G4endl;                             141            << G4endl;
135   }                                               142   }
136   //                                              143   //
137                                                   144 
138   // Delete the RunManager                        145   // Delete the RunManager
139   delete runManager;                              146   delete runManager;
140   return 0;                                       147   return 0;
141 }                                                 148 }
142                                                   149 
143 void horizontal_line(char c)                      150 void horizontal_line(char c)
144 {                                                 151 {
145   std::cout << "\n " << std::setw(100) << std: << 152   std::cout <<"\n " << std::setw(100) << std::setfill(c) 
                                                   >> 153             << "" << std::setfill(' ') << std::endl;
146 }                                                 154 }
147                                                   155 
148 void PrintUsage()                              << 156 void PrintUsage() {
149 {                                              << 
150   horizontal_line('=');                           157   horizontal_line('=');
151   std::cout << "  Geant4 application to demons    158   std::cout << "  Geant4 application to demonstrate interface to VecGeom Navigation.    \n"
152             << std::endl                          159             << std::endl
153             << "  Two modes: \n\n"                160             << "  Two modes: \n\n"
154             << "   * 1 parameter this is treat    161             << "   * 1 parameter this is treated as Geant4 macro file \n"
155             << " \n"                              162             << " \n"
156             << "   * Multiple Parameters: \n"     163             << "   * Multiple Parameters: \n"
157             << "      at least one of the foll    164             << "      at least one of the following: \n"
158             << "       -m :   the standard Gea    165             << "       -m :   the standard Geant4 macro file \n"
159             << "       -i :   interactive (aft    166             << "       -i :   interactive (after batch, if any) \n"
160             << "      optionally one of the fo    167             << "      optionally one of the following: \n"
161             << "       -v :   flag  ==> run us    168             << "       -v :   flag  ==> run using VecGeom navigation (default). \n"
162             << "       -o :   flag  ==> run us    169             << "       -o :   flag  ==> run using Geant4  navigation. \n"
163             << "       -c :   flag  ==> compar << 170             << "       -c :   flag  ==> compare VecGeom and Geant4 navigation"             
164             << " (and report differences.) \n"    171             << " (and report differences.) \n"
165             << "      and other(s): \n"           172             << "      and other(s): \n"
166             << "       -g :   GDML file with g    173             << "       -g :   GDML file with geometry \n"
167             << "\n"                               174             << "\n"
168             << std::endl;                         175             << std::endl;
169   horizontal_line('=');                           176   horizontal_line('=');
170 }                                                 177 }
171                                                   178 
172 void GetInputArguments(int argc, char** argv)  << 179 void GetInputArguments(int argc, char** argv) {
173 {                                              << 
174   // process arguments                            180   // process arguments
175   if (argc == 1) {                                181   if (argc == 1) {
176     PrintUsage();                                 182     PrintUsage();
177     exit(0);                                      183     exit(0);
178   }                                               184   }
179   if (argc == 2) {                                185   if (argc == 2) {
180     parMacroFileName = argv[1];                << 186      parMacroFileName = argv[1];
181     G4cout << " argc = 2  -- Filename = " << p << 187      G4cout << " argc = 2  -- Filename = " << parMacroFileName << G4endl;
182     return;                                    << 188      return;
183   }                                               189   }
184                                                   190 
185   // Adapted from examples/basic/B4/exampleB4a    191   // Adapted from examples/basic/B4/exampleB4a.cc
186   for (G4int i = 1; i < argc; ++i) {           << 192   for ( G4int i=1; i<argc; ++i ) {
187     if (G4String(argv[i]) == "-m") {           << 193     if  ( G4String(argv[i]) == "-m" ) {
188       if (++i < argc) {                        << 194       if( ++i < argc ) {
189         parMacroFileName = argv[i];               195         parMacroFileName = argv[i];
190         G4cout << " arg-parsing:  Macro file n    196         G4cout << " arg-parsing:  Macro file name= " << parMacroFileName << G4endl;
191       }                                           197       }
192       else {                                   << 198       else{
193         G4cerr << " Parse Error: '-m' cannot b << 199          G4cerr << " Parse Error: '-m' cannot be last argument.  Use it : -m <filename>" << G4endl;
194         PrintUsage();                          << 200          PrintUsage();
195         exit(1);                               << 201          exit(1);
196       }                                           202       }
197     }                                             203     }
198     else if (G4String(argv[i]) == "-g") {      << 204     else if ( G4String(argv[i]) == "-g" ) {
199       if (++i < argc) {                        << 205       if( ++i < argc ) { parGDMLFile      = argv[i];
200         parGDMLFile = argv[i];                 << 206          G4cout << " arg-parsing:  GDML file name= " << parGDMLFile << G4endl;
201         G4cout << " arg-parsing:  GDML file na << 
202       }                                           207       }
203       else {                                   << 208       else{
204         G4cerr << " Parse Error: '-m' cannot b << 209          G4cerr << " Parse Error: '-m' cannot be last argument.  Use it : -m <filename>" << G4endl;
205         PrintUsage();                          << 210          PrintUsage();
206         exit(1);                               << 211          exit(1);
207       }                                           212       }
208     }                                             213     }
209     else if (G4String(argv[i]) == "-v") {      << 214     else if ( G4String(argv[i]) == "-v" ) { parUseVecGeom = true; }
210       parUseVecGeom = true;                    << 215     else if ( G4String(argv[i]) == "-o" ) { parUseVecGeom = false; }
211     }                                          << 216     else if ( G4String(argv[i]) == "-c" ) { parCompareG4 = true;  parUseVecGeom= true; }
212     else if (G4String(argv[i]) == "-o") {      << 
213       parUseVecGeom = false;                   << 
214     }                                          << 
215     else if (G4String(argv[i]) == "-c") {      << 
216       parCompareG4 = true;                     << 
217       parUseVecGeom = true;                    << 
218     }                                          << 
219     else {                                        217     else {
220       G4cerr << "  Unknown argument : " << arg    218       G4cerr << "  Unknown argument : " << argv[i] << G4endl;
221       PrintUsage();                               219       PrintUsage();
222       exit(1);                                    220       exit(1);
223     }                                             221     }
224   }                                               222   }
225                                                   223 
226   // check if mandatory Geant4 macro file was     224   // check if mandatory Geant4 macro file was provided
227   if (parMacroFileName == "" && !parInteractiv << 225   if (parMacroFileName=="" && !parInteractive ) {
228     G4cerr << "  *** ERROR : either interactiv << 226      G4cout << "  *** ERROR : either interactive mode or a Geant4 macro file is required. " << G4endl;
229            << G4endl;                          << 227      PrintUsage();
230     PrintUsage();                              << 228      exit(-1);
231     exit(-1);                                  << 
232   }                                               229   }
233 }                                                 230 }
234                                                   231