]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4SDServices.cxx
Initial version
[u/mrichter/AliRoot.git] / TGeant4 / TG4SDServices.cxx
CommitLineData
8d3676ae 1// $Id$
2// Category: digits+hits
3//
4// See the class description in the header file.
5
6#include "TG4SDServices.h"
7#include "TG4GeometryServices.h"
8#include "TG4VSensitiveDetector.h"
9#include "TG4Globals.h"
10
11#include <G4VSensitiveDetector.hh>
12#include <G4LogicalVolumeStore.hh>
13#include <G4LogicalVolume.hh>
14#include <G4Material.hh>
15
16TG4SDServices* TG4SDServices::fgInstance = 0;
17
18//_____________________________________________________________________________
19TG4SDServices::TG4SDServices(){
20//
21 if (fgInstance) {
22 TG4Globals::Exception(
23 "TG4SDServices: attempt to create two instances of singleton.");
24
25 fgInstance = this;
26 }
27}
28
29//_____________________________________________________________________________
30TG4SDServices::~TG4SDServices(){
31//
32}
33
34// public methods
35
36//_____________________________________________________________________________
37G4int TG4SDServices::GetVolumeID(const G4String& volName) const
38{
39// Returns the sensitive detector identifier.
40// !! Gives exception in case logical volume is not associated with
41// a sensitive detector.
42// ---
43
44
45 G4String g4VolName
46 = TG4GeometryServices::Instance()->CutName(volName);
47
48 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
49
50 for (G4int i=0; i<pLVStore->size(); i++) {
51 G4LogicalVolume* lv = (*pLVStore)[i];
52 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
53
54 if ((sd) && (sd->GetName()==g4VolName)) {
55 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
56 if (tsd)
57 return tsd->GetID();
58 else {
59 TG4Globals::Exception(
60 "TG4SDServices::GetVolumeID: Unknown sensitive detector type");
61 return 0;
62 }
63 }
64 }
65
66 G4String text = "TG4SDServices::VolId: Sensitive detector ";
67 text = text + g4VolName;
68 text = text + " is not defined.\n";
69 TG4Globals::Warning(text);
70 return 0;
71}
72
73
74//_____________________________________________________________________________
75G4int TG4SDServices::GetVolumeID(G4LogicalVolume* logicalVolume) const
76{
77// Returns the sensitive detector ID of the specified
78// logical volume.
79// ---
80
81 // sensitive detector ID
82 G4VSensitiveDetector* sd
83 = logicalVolume->GetSensitiveDetector();
84 if (sd) {
85 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
86 if (tsd)
87 return tsd->GetID();
88 else {
89 TG4Globals::Exception(
90 "TG4SDServices::GetVolumeID: Unknown sensitive detector type");
91 return 0;
92 }
93 }
94 else {
95 G4String text = "TG4SDServices::GetVolumeID: \n";
96 text = text + " Volume " + logicalVolume->GetName();
97 text = text + " has not a sensitive detector.";
98 //TG4Globals::Exception(text);
99 TG4Globals::Warning(text);
100 return 0;
101 }
102}
103
104
105//_____________________________________________________________________________
106G4String TG4SDServices::GetVolumeName(G4int volumeId) const
107{
108// Returns the name of the sensitive detector with the given identifier.
109// Gives a warning in case logical volume is not associated with
110// a sensitive detector.
111// ---
112
113 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
114
115 for (G4int i=0; i<pLVStore->size(); i++) {
116 G4LogicalVolume* lv = (*pLVStore)[i];
117 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
118
119 if (sd) {
120 G4int sdID;
121 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
122 if (tsd)
123 sdID = tsd->GetID();
124 else {
125 TG4Globals::Exception(
126 "TG4SDServices::VolId: Unknown sensitive detector type");
127 return "";
128 }
129 if (sdID == volumeId) return sd->GetName();
130 }
131 }
132
133 G4String text = "TG4SDServices::VolName:\n";
134 text = text + " Sensitive detector with given id is not defined. \n";
135 TG4Globals::Warning(text);
136 return "";
137}
138
139
140//_____________________________________________________________________________
141G4LogicalVolume* TG4SDServices::GetLogicalVolume(G4int volumeId) const
142{
143// Finds the first logical volume with specified volumeId
144// (sensitive detector ID) in G4LogicalVolumeStore.
145// ---
146
147 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
148
149 for (G4int i=0; i<pLVStore->size(); i++) {
150 G4LogicalVolume* lv = (*pLVStore)[i];
151 if (GetVolumeID(lv) == volumeId) return lv;
152 }
153
154 G4String text = "TG4SDServices::GetLogicalVolume: \n";
155 text = text + " Logical volume with given ID does not exist.";
156 return 0;
157}
158
159
160//_____________________________________________________________________________
161Int_t TG4SDServices::GetMediumId(G4int volumeId) const
162{
163// Return the material number for a given volume id
164// ---
165
166 G4LogicalVolume* logicalVolume = GetLogicalVolume(volumeId);
167
168 G4Material* material = logicalVolume->GetMaterial();
169
170 return TG4GeometryServices::Instance()->GetMediumId(material);
171}
172
173
174//_____________________________________________________________________________
175Int_t TG4SDServices::NofSensitiveDetectors() const
176{
177// Returns the total number of sensitive detectors.
178// ---
179
180 return TG4VSensitiveDetector::GetTotalNofSensitiveDetectors();
181}
182
183
184
185