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 medical/DICOM/DICOM.cc
0028 /// \brief Main program of the medical/DICOM example
0029 //
0030 // The code was written by :
0031 //        *Louis Archambault louis.archambault@phy.ulaval.ca,
0032 //      *Luc Beaulieu beaulieu@phy.ulaval.ca
0033 //      +Vincent Hubert-Tremblay at tigre.2@sympatico.ca
0034 //
0035 //
0036 // *Centre Hospitalier Universitaire de Quebec (CHUQ),
0037 // Hotel-Dieu de Quebec, departement de Radio-oncologie
0038 // 11 cote du palais. Quebec, QC, Canada, G1R 2J6
0039 // tel (418) 525-4444 #6720
0040 // fax (418) 691 5268
0041 //
0042 // + Université Laval, Québec (QC) Canada
0043 // *******************************************************
0044 #include "DicomActionInitialization.hh"
0045 #include "DicomNestedParamDetectorConstruction.hh"
0046 #include "DicomPartialDetectorConstruction.hh"
0047 #include "DicomRegularDetectorConstruction.hh"
0048 
0049 #include "G4GenericPhysicsList.hh"
0050 #include "G4RunManagerFactory.hh"
0051 #include "G4Types.hh"
0052 #include "G4UImanager.hh"
0053 #include "Randomize.hh"
0054 #include "globals.hh"
0055 
0056 #ifdef G4_DCMTK
0057 #  include "DicomFileMgr.hh"
0058 #else
0059 #  include "DicomHandler.hh"
0060 #endif
0061 
0062 #include "DicomIntersectVolume.hh"
0063 #include "QGSP_BIC.hh"
0064 #include "Shielding.hh"
0065 
0066 #include "G4UIExecutive.hh"
0067 #include "G4VisExecutive.hh"
0068 #include "G4tgrMessenger.hh"
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 int main(int argc, char** argv)
0073 {
0074   // Instantiate G4UIExecutive if interactive mode
0075   G4UIExecutive* ui = nullptr;
0076   if (argc == 1) {
0077     ui = new G4UIExecutive(argc, argv);
0078   }
0079 
0080   new G4tgrMessenger;
0081   char* part = std::getenv("DICOM_PARTIAL_PARAM");
0082   G4bool bPartial = FALSE;
0083   if (part && G4String(part) == "1") {
0084     bPartial = TRUE;
0085   }
0086 
0087   CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
0088   CLHEP::HepRandom::setTheSeed(G4long(24534575684783));
0089   G4long seeds[2];
0090   seeds[0] = G4long(534524575674523);
0091   seeds[1] = G4long(526345623452457);
0092   CLHEP::HepRandom::setTheSeeds(seeds);
0093 
0094   // Construct the default run manager
0095   char* nthread_c = std::getenv("DICOM_NTHREADS");
0096 
0097   unsigned nthreads = 4;
0098   unsigned env_threads = 0;
0099 
0100   if (nthread_c) {
0101     env_threads = unsigned(G4UIcommand::ConvertToDouble(nthread_c));
0102   }
0103   if (env_threads > 0) {
0104     nthreads = env_threads;
0105   }
0106 
0107   auto* runManager = G4RunManagerFactory::CreateRunManager();
0108   runManager->SetNumberOfThreads(nthreads);
0109 
0110   DicomDetectorConstruction* theGeometry = 0;
0111 
0112 #ifdef G4_DCMTK
0113   DicomFileMgr* theFileMgr = 0;
0114 #else
0115   DicomHandler* dcmHandler = 0;
0116 #endif
0117 
0118   if (!bPartial) {
0119 #ifdef G4_DCMTK
0120 
0121     theFileMgr = DicomFileMgr::GetInstance();
0122     theFileMgr->Convert("Data.dat");
0123 
0124 #else
0125     // Treatment of DICOM images before creating the G4runManager
0126     dcmHandler = DicomHandler::Instance();
0127     dcmHandler->CheckFileFormat();
0128 #endif
0129 
0130     // Initialisation of physics, geometry, primary particles ...
0131     char* nest = std::getenv("DICOM_NESTED_PARAM");
0132     if (nest && G4String(nest) == "1") {
0133       theGeometry = new DicomNestedParamDetectorConstruction();
0134     }
0135     else {
0136       theGeometry = new DicomRegularDetectorConstruction();
0137     }
0138   }
0139   else {
0140     theGeometry = new DicomPartialDetectorConstruction();
0141   }
0142   runManager->SetUserInitialization(theGeometry);
0143 
0144   //    std::vector<G4String>* MyConstr = new std::vector<G4String>;
0145   //    MyConstr->push_back("G4EmStandardPhysics");
0146   //    G4VModularPhysicsList* phys = new G4GenericPhysicsList(MyConstr);
0147   G4VModularPhysicsList* phys = new Shielding();
0148   runManager->SetUserInitialization(phys);
0149 
0150   // Set user action classes
0151   runManager->SetUserInitialization(new DicomActionInitialization());
0152 
0153   runManager->Initialize();
0154 
0155   new DicomIntersectVolume();
0156 
0157   // visualisation manager
0158   G4VisManager* visManager = new G4VisExecutive;
0159   visManager->Initialize();
0160 
0161   G4UImanager* UImanager = G4UImanager::GetUIpointer();
0162 
0163   if (ui) {
0164     UImanager->ApplyCommand("/control/execute vis.mac");
0165     ui->SessionStart();
0166     delete ui;
0167   }
0168   else {
0169     G4String command = "/control/execute ";
0170     G4String fileName = argv[1];
0171     UImanager->ApplyCommand(command + fileName);
0172   }
0173 
0174   delete visManager;
0175   delete runManager;
0176 
0177   if (!bPartial) {
0178 #ifdef G4_DCMTK
0179     delete theFileMgr;
0180 #endif
0181   }
0182 
0183   return 0;
0184 }