Geant4 Cross Reference |
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 // 26 // 27 /// \file dicom2.cc 27 /// \file dicom2.cc 28 /// \brief Main program of the Dicom2 example 28 /// \brief Main program of the Dicom2 example 29 29 30 #include "Dicom2ActionInitialization.hh" << 31 #include "DicomIntersectVolume.hh" << 32 #include "DicomNestedParamDetectorConstruction << 33 #include "DicomPartialDetectorConstruction.hh" << 34 #include "DicomRegularDetectorConstruction.hh" << 35 #include "QBBC.hh" << 36 #include "QGSP_BIC.hh" << 37 #include "Shielding.hh" << 38 << 39 #include "G4GenericPhysicsList.hh" << 40 #include "G4RunManagerFactory.hh" << 41 #include "G4Timer.hh" << 42 #include "G4Types.hh" 30 #include "G4Types.hh" 43 #include "G4UIExecutive.hh" << 31 #include "G4RunManagerFactory.hh" 44 #include "G4UImanager.hh" 32 #include "G4UImanager.hh" 45 #include "G4VisExecutive.hh" << 33 #include "G4GenericPhysicsList.hh" 46 #include "G4tgrMessenger.hh" 34 #include "G4tgrMessenger.hh" 47 #include "Randomize.hh" << 35 #include "G4VisExecutive.hh" >> 36 #include "G4UIExecutive.hh" >> 37 #include "G4Timer.hh" 48 #include "globals.hh" 38 #include "globals.hh" >> 39 #include "Randomize.hh" >> 40 #include "Shielding.hh" >> 41 #include "QGSP_BIC.hh" >> 42 #include "QBBC.hh" >> 43 >> 44 #include "DicomRegularDetectorConstruction.hh" >> 45 #include "DicomNestedParamDetectorConstruction.hh" >> 46 #include "DicomPartialDetectorConstruction.hh" >> 47 #include "Dicom2ActionInitialization.hh" >> 48 #include "DicomIntersectVolume.hh" 49 #ifdef G4_DCMTK 49 #ifdef G4_DCMTK 50 # include "DicomFileMgr.hh" << 50 # include "DicomFileMgr.hh" 51 #else 51 #else 52 # include "DicomHandler.hh" << 52 # include "DicomHandler.hh" 53 #endif 53 #endif 54 54 >> 55 55 //....oooOO0OOooo........oooOO0OOooo........oo 56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 56 57 57 int main(int argc, char** argv) << 58 int main(int argc,char** argv) 58 { 59 { 59 // Detect interactive mode (if no arguments) << 60 // Detect interactive mode (if no arguments) and define UI session 60 // << 61 // 61 G4UIExecutive* ui = 0; << 62 G4UIExecutive* ui = 0; 62 if (argc == 1) ui = new G4UIExecutive(argc, << 63 if (argc == 1) 63 << 64 ui = new G4UIExecutive(argc, argv); 64 new G4tgrMessenger; << 65 65 char* part = std::getenv("DICOM_PARTIAL_PARA << 66 new G4tgrMessenger; 66 G4bool bPartial = (part && G4String(part) == << 67 char* part = std::getenv("DICOM_PARTIAL_PARAM"); 67 << 68 G4bool bPartial = (part && G4String(part) == "1") ? true : false; 68 CLHEP::HepRandom::setTheEngine(new CLHEP::Mi << 69 69 CLHEP::HepRandom::setTheSeed(G4long(24534575 << 70 CLHEP::HepRandom::setTheEngine(new CLHEP::MixMaxRng); 70 G4long seeds[2]; << 71 CLHEP::HepRandom::setTheSeed(G4long(24534575684783)); 71 seeds[0] = G4long(534524575674523); << 72 G4long seeds[2]; 72 seeds[1] = G4long(526345623452457); << 73 seeds[0] = G4long(534524575674523); 73 CLHEP::HepRandom::setTheSeeds(seeds); << 74 seeds[1] = G4long(526345623452457); 74 << 75 CLHEP::HepRandom::setTheSeeds(seeds); 75 // Construct the default run manager << 76 76 G4int nthreads = G4GetEnv<G4int>("DICOM_NTHR << 77 // Construct the default run manager 77 auto* runManager = G4RunManagerFactory::Crea << 78 G4int nthreads = G4GetEnv<G4int>("DICOM_NTHREADS", G4Thread::hardware_concurrency()); 78 runManager->SetNumberOfThreads(nthreads); << 79 auto* runManager = G4RunManagerFactory::CreateRunManager(); >> 80 runManager->SetNumberOfThreads(nthreads); >> 81 >> 82 G4cout << "\n\n\tDICOM2 running with " >> 83 << runManager->GetNumberOfThreads() >> 84 << " threads\n\n" << G4endl; 79 85 80 G4cout << "\n\n\tDICOM2 running with " << ru << 86 DicomDetectorConstruction* theGeometry = 0; 81 << G4endl; << 82 << 83 DicomDetectorConstruction* theGeometry = 0; << 84 87 85 #ifdef G4_DCMTK 88 #ifdef G4_DCMTK 86 DicomFileMgr* theFileMgr = 0; << 89 DicomFileMgr* theFileMgr = 0; 87 #else 90 #else 88 DicomHandler* dcmHandler = 0; << 91 DicomHandler* dcmHandler = 0; 89 #endif 92 #endif 90 93 91 if (!bPartial) { << 94 if( !bPartial ) >> 95 { 92 #ifdef G4_DCMTK 96 #ifdef G4_DCMTK 93 G4String inpfile = "Data.dat"; << 97 G4String inpfile = "Data.dat"; 94 char* env_inpfile = std::getenv("DICOM_INP << 98 char* env_inpfile = std::getenv("DICOM_INPUT_FILE"); 95 if (env_inpfile) inpfile = env_inpfile; << 99 if(env_inpfile) >> 100 inpfile = env_inpfile; 96 101 97 theFileMgr = DicomFileMgr::GetInstance(); << 102 theFileMgr = DicomFileMgr::GetInstance(); 98 theFileMgr->Convert(inpfile); << 103 theFileMgr->Convert(inpfile); 99 #else 104 #else 100 // Treatment of DICOM images before creati << 105 // Treatment of DICOM images before creating the G4runManager 101 dcmHandler = DicomHandler::Instance(); << 106 dcmHandler = DicomHandler::Instance(); 102 dcmHandler->CheckFileFormat(); << 107 dcmHandler->CheckFileFormat(); 103 #endif 108 #endif 104 109 105 // Initialisation of physics, geometry, pr << 110 // Initialisation of physics, geometry, primary particles ... 106 char* nest = std::getenv("DICOM_NESTED_PAR << 111 char* nest = std::getenv( "DICOM_NESTED_PARAM" ); 107 if (nest && G4String(nest) == "1") { << 112 if( nest && G4String(nest) == "1" ) { 108 theGeometry = new DicomNestedParamDetect << 113 theGeometry = new DicomNestedParamDetectorConstruction(); >> 114 } else { >> 115 theGeometry = new DicomRegularDetectorConstruction(); >> 116 } >> 117 } else { >> 118 theGeometry = new DicomPartialDetectorConstruction(); >> 119 } >> 120 runManager->SetUserInitialization(theGeometry); >> 121 >> 122 // std::vector<G4String>* MyConstr = new std::vector<G4String>; >> 123 // MyConstr->push_back("G4EmStandardPhysics"); >> 124 // G4VModularPhysicsList* phys = new G4GenericPhysicsList(MyConstr); >> 125 G4VModularPhysicsList* phys = new Shielding(); >> 126 phys->SetDefaultCutValue(0.5*CLHEP::mm); >> 127 runManager->SetUserInitialization(phys); >> 128 >> 129 // User action initialization >> 130 runManager->SetUserInitialization(new Dicom2ActionInitialization()); >> 131 >> 132 runManager->Initialize(); >> 133 >> 134 new DicomIntersectVolume(); >> 135 >> 136 // Initialize visualization >> 137 // >> 138 G4VisManager* visManager = new G4VisExecutive; >> 139 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. >> 140 // G4VisManager* visManager = new G4VisExecutive("Quiet"); >> 141 visManager->Initialize(); >> 142 >> 143 // Get the pointer to the User Interface manager >> 144 G4UImanager* UImanager = G4UImanager::GetUIpointer(); >> 145 >> 146 G4Timer t; >> 147 t.Start(); >> 148 >> 149 // Process macro or start UI session >> 150 // >> 151 if ( ! ui ) { >> 152 // batch mode >> 153 G4String command = "/control/execute "; >> 154 G4String fileName = argv[1]; >> 155 UImanager->ApplyCommand(command+fileName); 109 } 156 } 110 else { 157 else { 111 theGeometry = new DicomRegularDetectorCo << 158 // interactive mode >> 159 UImanager->ApplyCommand("/control/execute vis.mac"); >> 160 ui->SessionStart(); >> 161 delete ui; 112 } 162 } 113 } << 114 else { << 115 theGeometry = new DicomPartialDetectorCons << 116 } << 117 runManager->SetUserInitialization(theGeometr << 118 << 119 // std::vector<G4String>* MyConstr = new << 120 // MyConstr->push_back("G4EmStandardPhysi << 121 // G4VModularPhysicsList* phys = new G4Ge << 122 G4VModularPhysicsList* phys = new Shielding( << 123 phys->SetDefaultCutValue(0.5 * CLHEP::mm); << 124 runManager->SetUserInitialization(phys); << 125 << 126 // User action initialization << 127 runManager->SetUserInitialization(new Dicom2 << 128 << 129 runManager->Initialize(); << 130 << 131 new DicomIntersectVolume(); << 132 << 133 // Initialize visualization << 134 // << 135 G4VisManager* visManager = new G4VisExecutiv << 136 // G4VisExecutive can take a verbosity argum << 137 // G4VisManager* visManager = new G4VisExecu << 138 visManager->Initialize(); << 139 << 140 // Get the pointer to the User Interface man << 141 G4UImanager* UImanager = G4UImanager::GetUIp << 142 << 143 G4Timer t; << 144 t.Start(); << 145 << 146 // Process macro or start UI session << 147 // << 148 if (!ui) { << 149 // batch mode << 150 G4String command = "/control/execute "; << 151 G4String fileName = argv[1]; << 152 UImanager->ApplyCommand(command + fileName << 153 } << 154 else { << 155 // interactive mode << 156 UImanager->ApplyCommand("/control/execute << 157 ui->SessionStart(); << 158 delete ui; << 159 } << 160 << 161 t.Stop(); << 162 << 163 // Job termination << 164 // Free the store: user actions, physics_lis << 165 // owned and deleted by the run manager, so << 166 // in the main() program ! << 167 163 168 delete visManager; << 164 t.Stop(); 169 delete runManager; << 165 >> 166 // Job termination >> 167 // Free the store: user actions, physics_list and detector_description are >> 168 // owned and deleted by the run manager, so they should not be deleted >> 169 // in the main() program ! 170 170 171 if (!bPartial) { << 171 delete visManager; >> 172 delete runManager; >> 173 >> 174 if( !bPartial ) >> 175 { 172 #ifdef G4_DCMTK 176 #ifdef G4_DCMTK 173 delete theFileMgr; << 177 delete theFileMgr; 174 #endif 178 #endif 175 } << 179 } 176 180 177 G4cout << "\n[" << argv[0] << "] Primary exe << 181 G4cout << "\n[" << argv[0] << "] Primary execution time: " << t << "\n" >> 182 << G4endl; 178 } 183 } 179 184 180 //....oooOO0OOooo........oooOO0OOooo........oo 185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo..... 181 186