]>
Commit | Line | Data |
---|---|---|
c926eee0 | 1 | // $Id$ |
2 | // Category: digits+hits | |
3 | // | |
a6412d9b | 4 | // Author: I. Hrivnacova |
5 | // | |
6 | // Class AliAliSDConstruction | |
7 | // -------------------------- | |
c926eee0 | 8 | // See the class description in the header file. |
9 | ||
10 | #include "AliSDConstruction.h" | |
11 | #include "AliSensitiveDetector.h" | |
12 | #include "AliLegoSensitiveDetector.h" | |
13 | #include "AliGlobals.h" | |
14 | #include "AliRun.h" | |
15 | #include "AliModule.h" | |
16 | ||
17 | #include "TG4GeometryServices.h" | |
18 | ||
19 | #include <G4SDManager.hh> | |
20 | #include <G4LogicalVolume.hh> | |
21 | #include <G4LogicalVolumeStore.hh> | |
22 | ||
23 | #include <TObjArray.h> | |
24 | ||
a6412d9b | 25 | //_____________________________________________________________________________ |
c926eee0 | 26 | AliSDConstruction::AliSDConstruction() |
e980662a | 27 | : TG4VSDConstruction(), |
28 | AliVerbose("SDConstruction") { | |
c926eee0 | 29 | // |
30 | } | |
31 | ||
a6412d9b | 32 | //_____________________________________________________________________________ |
c926eee0 | 33 | AliSDConstruction::~AliSDConstruction() { |
34 | // | |
35 | } | |
36 | ||
37 | // private methods | |
38 | ||
a6412d9b | 39 | //_____________________________________________________________________________ |
c926eee0 | 40 | void AliSDConstruction::InitializeModules() |
41 | { | |
42 | // Initializes AliModules. | |
43 | // --- | |
44 | ||
45 | TObjArray* modules = gAlice->Modules(); | |
46 | TIter next(modules); | |
47 | AliModule* module; | |
19a27042 | 48 | while((module = (AliModule*)next())) { |
c926eee0 | 49 | module->Init(); |
19a27042 | 50 | module->BuildGeometry(); |
51 | } | |
c926eee0 | 52 | } |
53 | ||
a6412d9b | 54 | //_____________________________________________________________________________ |
c926eee0 | 55 | AliModule* AliSDConstruction::FindAliModule(G4LogicalVolume* lv) const |
56 | { | |
57 | // Finds the module containing specified logical volume. | |
58 | // --- | |
59 | ||
60 | // geometry manager | |
61 | TG4GeometryServices* geometryServices = TG4GeometryServices::Instance(); | |
62 | ||
63 | // get g3 volume name | |
a6412d9b | 64 | G4String g3Name = geometryServices->G4ToG3VolumeName(lv->GetName()); |
c926eee0 | 65 | |
66 | // get module name from the map | |
67 | G4String moduleName = geometryServices->GetMapSecond(g3Name); | |
68 | ||
69 | // find module from gAlice | |
70 | AliModule* module = gAlice->GetModule(moduleName); | |
71 | if (!module) { | |
72 | G4String text = "AliSDConstruction::FindAliModule:\n"; | |
73 | text = text + " AliModule " + moduleName; | |
74 | text = text + " (mapped from logical volume " + lv->GetName() + ")\n"; | |
75 | text = text + " has not been found in gAlice."; | |
76 | AliGlobals::Exception(text); | |
77 | } | |
78 | ||
79 | return module; | |
80 | } | |
81 | ||
a6412d9b | 82 | //_____________________________________________________________________________ |
c926eee0 | 83 | void AliSDConstruction::CreateSD(G4LogicalVolume* lv, AliModule* module) const |
84 | { | |
85 | // Creates/retrieves a sensitive detector for the logical volume. | |
86 | // --- | |
87 | ||
88 | TG4GeometryServices* geometryServices = TG4GeometryServices::Instance(); | |
89 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
90 | ||
a6412d9b | 91 | G4String lvName = lv->GetName(); |
c926eee0 | 92 | G4String moduleName = module->GetName(); |
93 | G4String sdName = "/Alice/" + moduleName + "/" + lvName; | |
94 | ||
95 | // cut copy number from sdName | |
a6412d9b | 96 | sdName = geometryServices->G4ToG3VolumeName(sdName); |
c926eee0 | 97 | |
98 | // create/retrieve the sensitive detector | |
99 | G4VSensitiveDetector* sd = 0; | |
100 | sd = pSDManager->FindSensitiveDetector(sdName); | |
101 | if (!sd) { | |
102 | AliSensitiveDetector* asd | |
103 | = new AliSensitiveDetector(sdName, module); | |
104 | pSDManager->AddNewDetector(asd); | |
e980662a | 105 | |
106 | if (VerboseLevel() > 0) { | |
107 | G4cout << "Sensitive detector " << sdName << "(" | |
108 | << asd->GetID() << ") has been created." << G4endl; | |
109 | } | |
110 | ||
c926eee0 | 111 | sd = asd; |
112 | } | |
113 | lv->SetSensitiveDetector(sd); | |
114 | } | |
115 | ||
a6412d9b | 116 | //_____________________________________________________________________________ |
c926eee0 | 117 | void AliSDConstruction::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const |
118 | { | |
119 | // Replaces the existing sensitive detector of the logical volume | |
120 | // with the lego sensitive detector. | |
121 | // --- | |
122 | ||
123 | TG4GeometryServices* geometryServices = TG4GeometryServices::Instance(); | |
124 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
125 | ||
126 | G4String lvName = lv->GetName(); | |
127 | G4String sdName = "/Alice/lego/" + lvName; | |
128 | ||
129 | // cut copy number from sdName | |
a6412d9b | 130 | sdName = geometryServices->G4ToG3VolumeName(sdName); |
c926eee0 | 131 | |
132 | // retrieve the standard sensitive detector | |
133 | G4VSensitiveDetector* sd = lv->GetSensitiveDetector(); | |
134 | ||
135 | // create/retrieve the lego sensitive detector | |
136 | G4VSensitiveDetector* legoVSD = 0; | |
137 | legoVSD = pSDManager->FindSensitiveDetector(sdName); | |
138 | ||
139 | if (!legoVSD) { | |
140 | AliLegoSensitiveDetector* legoSD | |
141 | = new AliLegoSensitiveDetector(sdName, lego, sd); | |
142 | pSDManager->AddNewDetector(legoSD); | |
e980662a | 143 | |
144 | if (VerboseLevel() > 0) { | |
145 | G4cout << "Lego sensitive detector " << sdName | |
146 | << ") has been created." << G4endl; | |
147 | } | |
148 | ||
c926eee0 | 149 | legoVSD = legoSD; |
150 | } | |
151 | lv->SetSensitiveDetector(legoVSD); | |
152 | } | |
153 | ||
a6412d9b | 154 | //_____________________________________________________________________________ |
c926eee0 | 155 | void AliSDConstruction::UnsetLegoSD(G4LogicalVolume* lv) const |
156 | { | |
157 | // Replace the lego sensitive detector of the logical volume | |
158 | // with the standard sensitive detector. | |
159 | // --- | |
160 | ||
161 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
162 | ||
163 | // get the lego sensitive detector | |
164 | G4VSensitiveDetector* sd = lv->GetSensitiveDetector(); | |
165 | AliLegoSensitiveDetector* legoSD = 0; | |
166 | if (sd) { | |
167 | // check type | |
168 | legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd); | |
169 | if (!legoSD) { | |
170 | G4String text = "AliSDConstruction::UnsetLego: \n"; | |
171 | text = text + " Wrong sensitive detector type."; | |
172 | AliGlobals::Exception(text); | |
173 | } | |
174 | } | |
175 | ||
176 | // get the standard sensitive detector | |
177 | G4VSensitiveDetector* standardSD = legoSD->GetStandardSD(); | |
178 | ||
179 | // set the standard sensitive detector | |
180 | lv->SetSensitiveDetector(standardSD); | |
181 | } | |
182 | ||
183 | ||
184 | // public methods | |
185 | ||
a6412d9b | 186 | //_____________________________________________________________________________ |
c926eee0 | 187 | void AliSDConstruction::Construct() |
188 | { | |
189 | // Creates sensitive detectors and initialize AliModules. | |
190 | // Sensitive detectors are set to all logical volumes | |
191 | // --- | |
192 | ||
193 | G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance(); | |
194 | G4int nofLV = lvStore->size(); | |
195 | ||
196 | for (G4int i=0; i<nofLV; i++) { | |
197 | G4LogicalVolume* lv = (*lvStore)[i]; | |
198 | AliModule* module = FindAliModule(lv); | |
199 | CreateSD(lv, module); | |
200 | } | |
201 | ||
202 | InitializeModules(); | |
203 | } | |
204 | ||
205 | /* | |
206 | //#include "TG4GeometryManager.h" | |
207 | //#include <G3SensVolVector.hh> | |
208 | ||
209 | void AliSDConstruction::CreateSensitiveDetectors2() | |
210 | { | |
211 | // Creates sensitive detectors. | |
212 | // Sensitive detectors are set only to logical volumes | |
213 | // in G3SensVolVector. | |
214 | // --- | |
215 | ||
216 | G3SensVolVector svVector | |
217 | = TG4GeometryManager::Instance()->GetG3SensVolVector(); | |
218 | ||
219 | G4int nofSV = svVector.entries(); | |
220 | if (nofSV>0) | |
221 | for (G4int isv=0; isv<nofSV; isv++) { | |
222 | G4LogicalVolume* lv = svVector[isv]; | |
223 | AliModule* module = FindAliModule(lv); | |
224 | CreateSD(lv, module); | |
225 | } | |
226 | } | |
227 | */ | |
228 | ||
a6412d9b | 229 | //_____________________________________________________________________________ |
c926eee0 | 230 | void AliSDConstruction::SetLego(AliLego* lego) const |
231 | { | |
232 | // Replaces the existing sensitive detectors | |
233 | // with lego sensitive detectors. | |
234 | // --- | |
235 | ||
236 | if (!lego) { | |
237 | G4String text = "AliSDConstruction::SetLego: \n"; | |
238 | text = text + " No AliLego is defined."; | |
239 | AliGlobals::Warning(text); | |
240 | return; | |
241 | } | |
242 | ||
243 | G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance(); | |
244 | G4int nofLV = lvStore->size(); | |
245 | ||
246 | for (G4int i=0; i<nofLV; i++) { | |
247 | G4LogicalVolume* lv = (*lvStore)[i]; | |
248 | CreateLegoSD(lv, lego); | |
249 | } | |
250 | } | |
251 | ||
a6412d9b | 252 | //_____________________________________________________________________________ |
c926eee0 | 253 | void AliSDConstruction::UnsetLego() const |
254 | { | |
255 | // Replace the lego sensitive detectors | |
256 | // back with standard sensitive detectors. | |
257 | // --- | |
258 | ||
259 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
260 | G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance(); | |
261 | G4int nofLV = lvStore->size(); | |
262 | ||
263 | // set back standard sensitive detectors | |
264 | for (G4int i=0; i<nofLV; i++) { | |
265 | G4LogicalVolume* lv = (*lvStore)[i]; | |
266 | UnsetLegoSD(lv); | |
267 | } | |
268 | ||
269 | // The lego sensitive detectors are not deleted here | |
270 | // as there is no way how to unregister them | |
271 | // from G4SDManager | |
272 | } |