Geant4_10
gdml_det.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 //
28 //
29 //
30 // $Id: gdml_det.cc 68025 2013-03-13 13:43:46Z gcosmo $
31 //
32 //
33 // --------------------------------------------------------------
34 // GEANT 4 - gdml_det
35 //
36 // --------------------------------------------------------------
37 
38 #include <vector>
39 
40 #include "G4RunManager.hh"
41 #include "G4UImanager.hh"
42 
43 #include "G4LogicalVolumeStore.hh"
45 #include "G4SDManager.hh"
46 
49 #include "G04PhysicsList.hh"
50 #include "G04SensitiveDetector.hh"
51 
52 #ifdef G4VIS_USE
53 #include "G4VisExecutive.hh"
54 #endif
55 
56 #ifdef G4UI_USE
57 #include "G4UIExecutive.hh"
58 #endif
59 
60 #include "G4GDMLParser.hh"
61 
62 int main(int argc,char **argv)
63 {
64  G4cout << G4endl;
65  G4cout << "Usage: gdml_det <intput_gdml_file:mandatory>"
66  << G4endl;
67  G4cout << G4endl;
68 
69  if (argc<2)
70  {
71  G4cout << "Error! Mandatory input file is not specified!" << G4endl;
72  G4cout << G4endl;
73  return -1;
74  }
75 
76  G4GDMLParser parser;
77  parser.Read(argv[1]);
78 
79 
80  G4RunManager* runManager = new G4RunManager;
81 
83  parser.GetWorldVolume()));
84  runManager->SetUserInitialization(new G04PhysicsList);
86 
87  runManager->Initialize();
88 
90 
91  //------------------------------------------------
92  // Sensitive detectors
93  //------------------------------------------------
94 
96 
97  G4String trackerChamberSDname = "Tracker";
98  G04SensitiveDetector* aTrackerSD = new G04SensitiveDetector(trackerChamberSDname);
99  SDman->AddNewDetector( aTrackerSD );
100 
102  //
103  // Example how to retrieve Auxiliary Information for sensitive detector
104  //
105  const G4GDMLAuxMapType* auxmap = parser.GetAuxMap();
106  std::cout << "Found " << auxmap->size()
107  << " volume(s) with auxiliary information."
108  << G4endl << G4endl;
109  for(G4GDMLAuxMapType::const_iterator iter=auxmap->begin();
110  iter!=auxmap->end(); iter++)
111  {
112  G4cout << "Volume " << ((*iter).first)->GetName()
113  << " has the following list of auxiliary information: "
114  << G4endl << G4endl;
115  for (G4GDMLAuxListType::const_iterator vit=(*iter).second.begin();
116  vit!=(*iter).second.end(); vit++)
117  {
118  std::cout << "--> Type: " << (*vit).type
119  << " Value: " << (*vit).value << std::endl;
120  }
121  }
122  G4cout << G4endl;
123 
124  // The same as above, but now we are looking for
125  // sensitive detectors setting them for the volumes
126 
127  for(G4GDMLAuxMapType::const_iterator iter=auxmap->begin();
128  iter!=auxmap->end(); iter++)
129  {
130  G4cout << "Volume " << ((*iter).first)->GetName()
131  << " has the following list of auxiliary information: "
132  << G4endl << G4endl;
133  for (G4GDMLAuxListType::const_iterator vit=(*iter).second.begin();
134  vit!=(*iter).second.end();vit++)
135  {
136  if ((*vit).type=="SensDet")
137  {
138  G4cout << "Attaching sensitive detector " << (*vit).value
139  << " to volume " << ((*iter).first)->GetName()
140  << G4endl << G4endl;
141 
142  G4VSensitiveDetector* mydet = SDman->FindSensitiveDetector((*vit).value);
143  if(mydet)
144  {
145  G4LogicalVolume* myvol = (*iter).first;
146  myvol->SetSensitiveDetector(mydet);
147  }
148  else
149  {
150  G4cout << (*vit).value << " detector not found" << G4endl;
151  }
152  }
153  }
154  }
155  //
156  // End of Auxiliary Information block
157  //
159 
160 #ifdef G4VIS_USE
161  G4VisManager* visManager = new G4VisExecutive;
162  visManager->Initialize();
163 #endif
164 
165  if (argc==3) // batch mode
166  {
167  G4String command = "/control/execute ";
168  G4String fileName = argv[2];
169  UImanager->ApplyCommand(command+fileName);
170  }
171  else // interactive mode
172  {
173 #ifdef G4UI_USE
174  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
175 #ifdef G4VIS_USE
176  UImanager->ApplyCommand("/control/execute vis.mac");
177 #endif
178  ui->SessionStart();
179  delete ui;
180 #endif
181  }
182 
183 #ifdef G4VIS_USE
184  delete visManager;
185 #endif
186  delete runManager;
187 
188  return 0;
189 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
Definition of the G04DetectorConstruction class.
Detector construction for laoding GDML geometry.
Physics list for the GDML senstive detector example.
int main(int argc, char **argv)
Definition: genwindef.cpp:30
Definition of the G04PhysicsList class.
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
Definition of the G04SensitiveDetector class.
Primary generator action for GDML sensitive detector example.
Definition of the G04PrimaryGeneratorAction class.
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:124
void Initialize()
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:67
const G4GDMLAuxMapType * GetAuxMap() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
void Read(const G4String &filename, G4bool Validate=true)
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
std::map< G4LogicalVolume *, G4GDMLAuxListType > G4GDMLAuxMapType
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)
Sensitive detector to be attached to the GDML geometry.
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
virtual void SetUserAction(G4UserRunAction *userAction)