]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TGeant4/TG4SDServices.cxx
Avoid errors in the VirtuaMC version of AliRoot
[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"
8d3676ae 7#include "TG4VSensitiveDetector.h"
9f5eaf0b 8#include "TG4GeometryServices.h"
8d3676ae 9#include "TG4Globals.h"
10
11#include <G4VSensitiveDetector.hh>
12#include <G4LogicalVolumeStore.hh>
13#include <G4LogicalVolume.hh>
14#include <G4Material.hh>
002da39b 15#include <g4std/iomanip>
8d3676ae 16
17TG4SDServices* TG4SDServices::fgInstance = 0;
18
19//_____________________________________________________________________________
20TG4SDServices::TG4SDServices(){
21//
22 if (fgInstance) {
23 TG4Globals::Exception(
24 "TG4SDServices: attempt to create two instances of singleton.");
25
26 fgInstance = this;
27 }
28}
29
9f5eaf0b 30//_____________________________________________________________________________
31TG4SDServices::TG4SDServices(const TG4SDServices& right) {
32//
33 TG4Globals::Exception(
34 "Attempt to copy TG4SDServices singleton.");
35}
36
37
8d3676ae 38//_____________________________________________________________________________
39TG4SDServices::~TG4SDServices(){
40//
41}
42
9f5eaf0b 43// operators
44
45//_____________________________________________________________________________
46TG4SDServices& TG4SDServices::operator=(const TG4SDServices& right)
47{
48 // check assignement to self
49 if (this == &right) return *this;
50
51 TG4Globals::Exception(
52 "Attempt to assign TG4SDServices singleton.");
53
54 return *this;
55}
56
57
8d3676ae 58// public methods
59
9f5eaf0b 60//_____________________________________________________________________________
61void TG4SDServices::PrintStatistics(G4bool open, G4bool close) const
62{
63// Print G4 SD statistics
64// ---
65
66 if (open) TG4Globals::PrintStars(true);
67
002da39b 68 G4cout << " " << G4std::setw(5) << NofSensitiveDetectors()
9f5eaf0b 69 << " sensitive detectors" << G4endl;
70
71 if (close) TG4Globals::PrintStars(false);
72}
73
8d3676ae 74//_____________________________________________________________________________
75G4int TG4SDServices::GetVolumeID(const G4String& volName) const
76{
77// Returns the sensitive detector identifier.
78// !! Gives exception in case logical volume is not associated with
79// a sensitive detector.
80// ---
81
8d3676ae 82 G4String g4VolName
83 = TG4GeometryServices::Instance()->CutName(volName);
84
85 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
86
87 for (G4int i=0; i<pLVStore->size(); i++) {
88 G4LogicalVolume* lv = (*pLVStore)[i];
89 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
90
9f5eaf0b 91 if (sd && sd->GetName() == g4VolName)
92 return GetSensitiveDetector(sd)->GetID();
8d3676ae 93 }
94
9f5eaf0b 95 G4String text = "TG4SDServices::GetVolumeID: Sensitive detector ";
8d3676ae 96 text = text + g4VolName;
97 text = text + " is not defined.\n";
98 TG4Globals::Warning(text);
99 return 0;
100}
101
102
103//_____________________________________________________________________________
104G4int TG4SDServices::GetVolumeID(G4LogicalVolume* logicalVolume) const
105{
106// Returns the sensitive detector ID of the specified
107// logical volume.
108// ---
109
8d3676ae 110 G4VSensitiveDetector* sd
111 = logicalVolume->GetSensitiveDetector();
9f5eaf0b 112
113 if (sd) return GetSensitiveDetector(sd)->GetID();
114
115 G4String text = "TG4SDServices::GetVolumeID: \n";
116 text = text + " Volume " + logicalVolume->GetName();
117 text = text + " has not a sensitive detector.";
118 //TG4Globals::Exception(text);
119 TG4Globals::Warning(text);
120 return 0;
8d3676ae 121}
122
123
124//_____________________________________________________________________________
125G4String TG4SDServices::GetVolumeName(G4int volumeId) const
126{
127// Returns the name of the sensitive detector with the given identifier.
128// Gives a warning in case logical volume is not associated with
129// a sensitive detector.
130// ---
131
132 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
133
134 for (G4int i=0; i<pLVStore->size(); i++) {
135 G4LogicalVolume* lv = (*pLVStore)[i];
136 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
137
9f5eaf0b 138 if (sd && GetSensitiveDetector(sd)->GetID() == volumeId)
139 return sd->GetName();
8d3676ae 140 }
141
142 G4String text = "TG4SDServices::VolName:\n";
143 text = text + " Sensitive detector with given id is not defined. \n";
144 TG4Globals::Warning(text);
145 return "";
146}
147
148
149//_____________________________________________________________________________
150G4LogicalVolume* TG4SDServices::GetLogicalVolume(G4int volumeId) const
151{
152// Finds the first logical volume with specified volumeId
153// (sensitive detector ID) in G4LogicalVolumeStore.
154// ---
155
156 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
157
158 for (G4int i=0; i<pLVStore->size(); i++) {
159 G4LogicalVolume* lv = (*pLVStore)[i];
160 if (GetVolumeID(lv) == volumeId) return lv;
161 }
162
163 G4String text = "TG4SDServices::GetLogicalVolume: \n";
164 text = text + " Logical volume with given ID does not exist.";
165 return 0;
166}
167
168
169//_____________________________________________________________________________
170Int_t TG4SDServices::GetMediumId(G4int volumeId) const
171{
172// Return the material number for a given volume id
173// ---
174
9f5eaf0b 175 return TG4GeometryServices::Instance()
176 ->GetMediumId(GetLogicalVolume(volumeId));
8d3676ae 177}
178
179
180//_____________________________________________________________________________
181Int_t TG4SDServices::NofSensitiveDetectors() const
182{
183// Returns the total number of sensitive detectors.
184// ---
185
186 return TG4VSensitiveDetector::GetTotalNofSensitiveDetectors();
187}
188
9f5eaf0b 189//_____________________________________________________________________________
190TG4VSensitiveDetector* TG4SDServices::GetSensitiveDetector(
191 G4VSensitiveDetector* sd) const
192{
193// Checks and converts type of the sensitive detector.
194// ---
195
196 if (!sd) return 0;
197
198 TG4VSensitiveDetector* tsd = dynamic_cast<TG4VSensitiveDetector*>(sd);
199
200 if (!tsd) {
fd6c4ba0 201 TG4Globals::Exception(
9f5eaf0b 202 "TG4SDServices::GetSensitiveDetector: Wrong sensitive detector type.");
203 return 0;
204 }
205 else
206 return tsd;
207}
8d3676ae 208
209