Geant4.10
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Functions
gdml_det.cc File Reference

Main program of the persistency/gdml/G04 example. More...

#include <vector>
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4LogicalVolumeStore.hh"
#include "G4TransportationManager.hh"
#include "G4SDManager.hh"
#include "G04PrimaryGeneratorAction.hh"
#include "G04DetectorConstruction.hh"
#include "G04PhysicsList.hh"
#include "G04SensitiveDetector.hh"
#include "G4GDMLParser.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Main program of the persistency/gdml/G04 example.

Definition in file gdml_det.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 62 of file gdml_det.cc.

References G4SDManager::AddNewDetector(), G4UImanager::ApplyCommand(), G4SDManager::FindSensitiveDetector(), G4cout, G4endl, G4GDMLParser::GetAuxMap(), G4SDManager::GetSDMpointer(), G4UImanager::GetUIpointer(), G4GDMLParser::GetWorldVolume(), G4RunManager::Initialize(), G4VisManager::Initialize(), G4GDMLParser::Read(), G4UIExecutive::SessionStart(), G4LogicalVolume::SetSensitiveDetector(), G4RunManager::SetUserAction(), and G4RunManager::SetUserInitialization().

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 
101  ///////////////////////////////////////////////////////////////////////
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  //
158  ////////////////////////////////////////////////////////////////////////
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
Detector construction for laoding GDML geometry.
Physics list for the GDML senstive detector example.
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
Primary generator action for GDML sensitive detector example.
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)