Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:46

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 /// \file dicom2.cc
0028 /// \brief Main program of the Dicom2 example
0029 
0030 #include "Dicom2ActionInitialization.hh"
0031 #include "DicomIntersectVolume.hh"
0032 #include "DicomNestedParamDetectorConstruction.hh"
0033 #include "DicomPartialDetectorConstruction.hh"
0034 #include "DicomRegularDetectorConstruction.hh"
0035 #include "QBBC.hh"
0036 #include "QGSP_BIC.hh"
0037 #include "Shielding.hh"
0038 
0039 #include "G4GenericPhysicsList.hh"
0040 #include "G4RunManagerFactory.hh"
0041 #include "G4Timer.hh"
0042 #include "G4Types.hh"
0043 #include "G4UIExecutive.hh"
0044 #include "G4UImanager.hh"
0045 #include "G4VisExecutive.hh"
0046 #include "G4tgrMessenger.hh"
0047 #include "Randomize.hh"
0048 #include "globals.hh"
0049 #ifdef G4_DCMTK
0050 #  include "DicomFileMgr.hh"
0051 #else
0052 #  include "DicomHandler.hh"
0053 #endif
0054 
0055 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 int main(int argc, char** argv)
0058 {
0059   // Detect interactive mode (if no arguments) and define UI session
0060   //
0061   G4UIExecutive* ui = 0;
0062   if (argc == 1) ui = new G4UIExecutive(argc, argv);
0063 
0064   new G4tgrMessenger;
0065   char* part = std::getenv("DICOM_PARTIAL_PARAM");
0066   G4bool bPartial = (part && G4String(part) == "1") ? true : false;
0067 
0068   CLHEP::HepRandom::setTheEngine(new CLHEP::MixMaxRng);
0069   CLHEP::HepRandom::setTheSeed(G4long(24534575684783));
0070   G4long seeds[2];
0071   seeds[0] = G4long(534524575674523);
0072   seeds[1] = G4long(526345623452457);
0073   CLHEP::HepRandom::setTheSeeds(seeds);
0074 
0075   // Construct the default run manager
0076   G4int nthreads = G4GetEnv<G4int>("DICOM_NTHREADS", G4Thread::hardware_concurrency());
0077   auto* runManager = G4RunManagerFactory::CreateRunManager();
0078   runManager->SetNumberOfThreads(nthreads);
0079 
0080   G4cout << "\n\n\tDICOM2 running with " << runManager->GetNumberOfThreads() << " threads\n\n"
0081          << G4endl;
0082 
0083   DicomDetectorConstruction* theGeometry = 0;
0084 
0085 #ifdef G4_DCMTK
0086   DicomFileMgr* theFileMgr = 0;
0087 #else
0088   DicomHandler* dcmHandler = 0;
0089 #endif
0090 
0091   if (!bPartial) {
0092 #ifdef G4_DCMTK
0093     G4String inpfile = "Data.dat";
0094     char* env_inpfile = std::getenv("DICOM_INPUT_FILE");
0095     if (env_inpfile) inpfile = env_inpfile;
0096 
0097     theFileMgr = DicomFileMgr::GetInstance();
0098     theFileMgr->Convert(inpfile);
0099 #else
0100     // Treatment of DICOM images before creating the G4runManager
0101     dcmHandler = DicomHandler::Instance();
0102     dcmHandler->CheckFileFormat();
0103 #endif
0104 
0105     // Initialisation of physics, geometry, primary particles ...
0106     char* nest = std::getenv("DICOM_NESTED_PARAM");
0107     if (nest && G4String(nest) == "1") {
0108       theGeometry = new DicomNestedParamDetectorConstruction();
0109     }
0110     else {
0111       theGeometry = new DicomRegularDetectorConstruction();
0112     }
0113   }
0114   else {
0115     theGeometry = new DicomPartialDetectorConstruction();
0116   }
0117   runManager->SetUserInitialization(theGeometry);
0118 
0119   //    std::vector<G4String>* MyConstr = new std::vector<G4String>;
0120   //    MyConstr->push_back("G4EmStandardPhysics");
0121   //    G4VModularPhysicsList* phys = new G4GenericPhysicsList(MyConstr);
0122   G4VModularPhysicsList* phys = new Shielding();
0123   phys->SetDefaultCutValue(0.5 * CLHEP::mm);
0124   runManager->SetUserInitialization(phys);
0125 
0126   // User action initialization
0127   runManager->SetUserInitialization(new Dicom2ActionInitialization());
0128 
0129   runManager->Initialize();
0130 
0131   new DicomIntersectVolume();
0132 
0133   // Initialize visualization
0134   //
0135   G4VisManager* visManager = new G4VisExecutive;
0136   // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
0137   // G4VisManager* visManager = new G4VisExecutive("Quiet");
0138   visManager->Initialize();
0139 
0140   // Get the pointer to the User Interface manager
0141   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0142 
0143   G4Timer t;
0144   t.Start();
0145 
0146   // Process macro or start UI session
0147   //
0148   if (!ui) {
0149     // batch mode
0150     G4String command = "/control/execute ";
0151     G4String fileName = argv[1];
0152     UImanager->ApplyCommand(command + fileName);
0153   }
0154   else {
0155     // interactive mode
0156     UImanager->ApplyCommand("/control/execute vis.mac");
0157     ui->SessionStart();
0158     delete ui;
0159   }
0160 
0161   t.Stop();
0162 
0163   // Job termination
0164   // Free the store: user actions, physics_list and detector_description are
0165   // owned and deleted by the run manager, so they should not be deleted
0166   // in the main() program !
0167 
0168   delete visManager;
0169   delete runManager;
0170 
0171   if (!bPartial) {
0172 #ifdef G4_DCMTK
0173     delete theFileMgr;
0174 #endif
0175   }
0176 
0177   G4cout << "\n[" << argv[0] << "] Primary execution time: " << t << "\n" << G4endl;
0178 }
0179 
0180 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....