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