Geant4  10.02.p02
G04DetectorConstruction.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 // $Id: G04DetectorConstruction.cc 87359 2014-12-01 16:04:27Z gcosmo $
27 //
30 
32 #include "G04SensitiveDetector.hh"
33 #include "G4SDManager.hh"
34 #include "G4GDMLParser.hh"
35 
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
37 
40  fParser(parser)
41 {}
42 
43 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
44 
46 {
47  return fParser.GetWorldVolume();
48 }
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51 
53 {
54  //------------------------------------------------
55  // Sensitive detectors
56  //------------------------------------------------
57 
59 
60  G4String trackerChamberSDname = "Tracker";
61  G04SensitiveDetector* aTrackerSD =
62  new G04SensitiveDetector(trackerChamberSDname);
63  SDman->AddNewDetector( aTrackerSD );
64 
66  //
67  // Example how to retrieve Auxiliary Information for sensitive detector
68  //
69  const G4GDMLAuxMapType* auxmap = fParser.GetAuxMap();
70  G4cout << "Found " << auxmap->size()
71  << " volume(s) with auxiliary information."
72  << G4endl << G4endl;
73  for(G4GDMLAuxMapType::const_iterator iter=auxmap->begin();
74  iter!=auxmap->end(); iter++)
75  {
76  G4cout << "Volume " << ((*iter).first)->GetName()
77  << " has the following list of auxiliary information: "
78  << G4endl << G4endl;
79  for (G4GDMLAuxListType::const_iterator vit=(*iter).second.begin();
80  vit!=(*iter).second.end(); vit++)
81  {
82  G4cout << "--> Type: " << (*vit).type
83  << " Value: " << (*vit).value << G4endl;
84  }
85  }
86  G4cout << G4endl;
87 
88  // The same as above, but now we are looking for
89  // sensitive detectors setting them for the volumes
90 
91  for(G4GDMLAuxMapType::const_iterator iter=auxmap->begin();
92  iter!=auxmap->end(); iter++)
93  {
94  G4cout << "Volume " << ((*iter).first)->GetName()
95  << " has the following list of auxiliary information: "
96  << G4endl << G4endl;
97  for (G4GDMLAuxListType::const_iterator vit=(*iter).second.begin();
98  vit!=(*iter).second.end();vit++)
99  {
100  if ((*vit).type=="SensDet")
101  {
102  G4cout << "Attaching sensitive detector " << (*vit).value
103  << " to volume " << ((*iter).first)->GetName()
104  << G4endl << G4endl;
105 
106  G4VSensitiveDetector* mydet =
107  SDman->FindSensitiveDetector((*vit).value);
108  if(mydet)
109  {
110  G4LogicalVolume* myvol = (*iter).first;
111  myvol->SetSensitiveDetector(mydet);
112  }
113  else
114  {
115  G4cout << (*vit).value << " detector not found" << G4endl;
116  }
117  }
118  }
119  }
120 }
121 
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
Definition of the G04DetectorConstruction class.
G4GLOB_DLL std::ostream G4cout
Definition of the G04SensitiveDetector class.
G4VSensitiveDetector * FindSensitiveDetector(G4String dName, G4bool warning=true)
Definition: G4SDManager.cc:128
CommandLineParser * parser(0)
void AddNewDetector(G4VSensitiveDetector *aSD)
Definition: G4SDManager.cc:71
const G4GDMLAuxMapType * GetAuxMap() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
virtual G4VPhysicalVolume * Construct()
#define G4endl
Definition: G4ios.hh:61
G04DetectorConstruction(const G4GDMLParser &parser)
std::map< G4LogicalVolume *, G4GDMLAuxListType > G4GDMLAuxMapType
void SetSensitiveDetector(G4VSensitiveDetector *pSDetector)
Sensitive detector to be attached to the GDML geometry.