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