Geant4  10.01.p02
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 82285 2014-06-13 14:56:02Z 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 "FTFP_BERT.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 
77  parser.Read(argv[1]);
78 
79 
80  G4RunManager* runManager = new G4RunManager;
81 
83  parser.GetWorldVolume()));
84  runManager->SetUserInitialization(new FTFP_BERT);
86 
87  runManager->Initialize();
88 
90 
91  //------------------------------------------------
92  // Sensitive detectors
93  //------------------------------------------------
94 
96 
97  G4String trackerChamberSDname = "Tracker";
98  G04SensitiveDetector* aTrackerSD =
99  new G04SensitiveDetector(trackerChamberSDname);
100  SDman->AddNewDetector( aTrackerSD );
101 
103  //
104  // Example how to retrieve Auxiliary Information for sensitive detector
105  //
106  const G4GDMLAuxMapType* auxmap = parser.GetAuxMap();
107  G4cout << "Found " << auxmap->size()
108  << " volume(s) with auxiliary information."
109  << G4endl << G4endl;
110  for(G4GDMLAuxMapType::const_iterator iter=auxmap->begin();
111  iter!=auxmap->end(); iter++)
112  {
113  G4cout << "Volume " << ((*iter).first)->GetName()
114  << " has the following list of auxiliary information: "
115  << G4endl << G4endl;
116  for (G4GDMLAuxListType::const_iterator vit=(*iter).second.begin();
117  vit!=(*iter).second.end(); vit++)
118  {
119  G4cout << "--> Type: " << (*vit).type
120  << " Value: " << (*vit).value << G4endl;
121  }
122  }
123  G4cout << G4endl;
124 
125  // The same as above, but now we are looking for
126  // sensitive detectors setting them for the volumes
127 
128  for(G4GDMLAuxMapType::const_iterator iter=auxmap->begin();
129  iter!=auxmap->end(); iter++)
130  {
131  G4cout << "Volume " << ((*iter).first)->GetName()
132  << " has the following list of auxiliary information: "
133  << G4endl << G4endl;
134  for (G4GDMLAuxListType::const_iterator vit=(*iter).second.begin();
135  vit!=(*iter).second.end();vit++)
136  {
137  if ((*vit).type=="SensDet")
138  {
139  G4cout << "Attaching sensitive detector " << (*vit).value
140  << " to volume " << ((*iter).first)->GetName()
141  << G4endl << G4endl;
142 
143  G4VSensitiveDetector* mydet =
144  SDman->FindSensitiveDetector((*vit).value);
145  if(mydet)
146  {
147  G4LogicalVolume* myvol = (*iter).first;
148  myvol->SetSensitiveDetector(mydet);
149  }
150  else
151  {
152  G4cout << (*vit).value << " detector not found" << G4endl;
153  }
154  }
155  }
156  }
157  //
158  // End of Auxiliary Information block
159  //
161 
162 #ifdef G4VIS_USE
163  G4VisManager* visManager = new G4VisExecutive;
164  visManager->Initialize();
165 #endif
166 
167  if (argc==3) // batch mode
168  {
169  G4String command = "/control/execute ";
170  G4String fileName = argv[2];
171  UImanager->ApplyCommand(command+fileName);
172  }
173  else // interactive mode
174  {
175 #ifdef G4UI_USE
176  G4UIExecutive* ui = new G4UIExecutive(argc, argv);
177 #ifdef G4VIS_USE
178  UImanager->ApplyCommand("/control/execute vis.mac");
179 #endif
180  ui->SessionStart();
181  delete ui;
182 #endif
183  }
184 
185 #ifdef G4VIS_USE
186  delete visManager;
187 #endif
188  delete runManager;
189 
190  return 0;
191 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
Definition of the G04DetectorConstruction class.
Detector construction for laoding GDML geometry.
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
CommandLineParser * parser(0)
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)
int main(int argc, char **argv)
Definition: gdml_det.cc:62
Sensitive detector to be attached to the GDML geometry.
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
virtual void SetUserAction(G4UserRunAction *userAction)