]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliSDManager.h" | |
7 | //#include "AliSDMessenger.h" | |
8 | #include "AliSensitiveDetector.h" | |
9 | #include "AliLegoSensitiveDetector.h" | |
10 | #include "AliGlobals.h" | |
11 | #include "AliFiles.h" | |
12 | #include "AliRun.h" | |
183a2787 | 13 | #include "AliModule.h" |
676fb573 | 14 | |
15 | #include "TG4GeometryManager.h" | |
16 | ||
17 | #include <G3SensVolVector.hh> | |
18 | #include <G4SDManager.hh> | |
19 | #include <G4UImanager.hh> | |
20 | #include <G4LogicalVolume.hh> | |
21 | #include <G4LogicalVolumeStore.hh> | |
22 | ||
23 | AliSDManager* AliSDManager::fgInstance = 0; | |
24 | ||
25 | AliSDManager* AliSDManager::Instance() | |
26 | { | |
27 | // Returns the singleton instance. | |
28 | // Creates the instance if it does not exist. | |
29 | // --- | |
30 | ||
31 | if (!fgInstance) new AliSDManager(); | |
32 | ||
33 | return fgInstance; | |
34 | } | |
35 | ||
a56d6518 | 36 | AliSDManager::AliSDManager() |
37 | : fNofLVWithSD(0) | |
38 | { | |
676fb573 | 39 | // |
40 | //fMessenger = new AliSDMessenger(this); | |
41 | fgInstance = this; | |
42 | } | |
43 | ||
44 | AliSDManager::AliSDManager(const AliSDManager& right) { | |
45 | // | |
46 | AliGlobals::Exception( | |
47 | "Singleton AliSDManager is protected from copying."); | |
48 | } | |
49 | ||
50 | AliSDManager::~AliSDManager() | |
51 | { | |
52 | //delete fMessenger; | |
53 | } | |
54 | ||
55 | // operators | |
56 | ||
57 | AliSDManager& AliSDManager::operator=(const AliSDManager& right) | |
58 | { | |
59 | // check assignement to self | |
60 | if (this == &right) return *this; | |
61 | ||
62 | AliGlobals::Exception( | |
63 | "Singleton AliSDManager is protected from assigning."); | |
64 | ||
65 | return *this; | |
66 | } | |
67 | ||
68 | // private methods | |
69 | ||
70 | void AliSDManager::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const | |
71 | { | |
72 | // Replaces the existing sensitive detector of the logical volume | |
73 | // with the lego sensitive detector. | |
74 | // --- | |
75 | ||
76 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
77 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
78 | ||
79 | G4String lvName = lv->GetName(); | |
80 | G4String sdName = "/Alice/lego/" + lvName; | |
81 | ||
82 | // cut copy number from sdName | |
83 | pGeometryManager->G4ToG3VolumeName(sdName); | |
84 | ||
85 | // retrieve the standard sensitive detector | |
86 | G4VSensitiveDetector* sd = lv->GetSensitiveDetector(); | |
87 | ||
88 | // create/retrieve the lego sensitive detector | |
89 | G4VSensitiveDetector* legoVSD = 0; | |
90 | legoVSD = pSDManager->FindSensitiveDetector(sdName); | |
91 | ||
92 | if (!legoVSD) { | |
93 | AliLegoSensitiveDetector* legoSD | |
94 | = new AliLegoSensitiveDetector(sdName, lego, sd); | |
95 | pSDManager->AddNewDetector(legoSD); | |
96 | // add verbose | |
97 | G4cout << "Lego sensitive detector " << sdName | |
5f1d09c5 | 98 | << ") has been created." << G4endl; |
676fb573 | 99 | legoVSD = legoSD; |
100 | } | |
101 | lv->SetSensitiveDetector(legoVSD); | |
102 | } | |
103 | ||
104 | void AliSDManager::UnsetLegoSD(G4LogicalVolume* lv) const | |
105 | { | |
106 | // Replace the lego sensitive detector of the logical volume | |
107 | // with the standard sensitive detector. | |
108 | // --- | |
109 | ||
110 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
111 | ||
112 | // get the lego sensitive detector | |
113 | G4VSensitiveDetector* sd = lv->GetSensitiveDetector(); | |
114 | AliLegoSensitiveDetector* legoSD = 0; | |
115 | if (sd) { | |
116 | // check type | |
117 | legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd); | |
118 | if (!legoSD) { | |
119 | G4String text = "AliSDManager::UnsetLego: \n"; | |
120 | text = text + " Wrong sensitive detector type."; | |
121 | AliGlobals::Exception(text); | |
122 | } | |
123 | } | |
124 | ||
125 | // get the standard sensitive detector | |
126 | G4VSensitiveDetector* standardSD = legoSD->GetStandardSD(); | |
127 | ||
128 | // set the standard sensitive detector | |
129 | lv->SetSensitiveDetector(standardSD); | |
130 | } | |
131 | ||
132 | ||
133 | // public methods | |
134 | ||
135 | void AliSDManager::CreateSD(G4LogicalVolume* lv, AliModule* module) const | |
136 | { | |
137 | // Creates/retrieves a sensitive detector for the logical volume. | |
138 | // --- | |
139 | ||
140 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
141 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
142 | ||
143 | G4String lvName = lv->GetName(); | |
144 | ||
145 | G4String moduleName = module->GetName(); | |
146 | G4String sdName = "/Alice/" + moduleName + "/" + lvName; | |
147 | ||
148 | // cut copy number from sdName | |
149 | pGeometryManager->G4ToG3VolumeName(sdName); | |
150 | ||
151 | // create/retrieve the sensitive detector | |
152 | G4VSensitiveDetector* sd = 0; | |
153 | sd = pSDManager->FindSensitiveDetector(sdName); | |
154 | if (!sd) { | |
155 | AliSensitiveDetector* asd | |
156 | = new AliSensitiveDetector(sdName, module); | |
157 | pSDManager->AddNewDetector(asd); | |
158 | // add verbose | |
159 | G4cout << "Sensitive detector " << sdName << "(" | |
5f1d09c5 | 160 | << asd->GetID() << ") has been created." << G4endl; |
676fb573 | 161 | sd = asd; |
162 | } | |
163 | lv->SetSensitiveDetector(sd); | |
164 | } | |
165 | ||
166 | AliModule* AliSDManager::FindAliModule(G4LogicalVolume* lv) const | |
167 | { | |
168 | // Finds the module containing specified logical volume. | |
169 | // --- | |
170 | ||
171 | // geometry manager | |
172 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
173 | ||
174 | // get g3 volume name | |
175 | G4String g3Name = lv->GetName(); | |
176 | pGeometryManager->G4ToG3VolumeName(g3Name); | |
177 | ||
178 | // get module name from the map | |
179 | G4String moduleName = pGeometryManager->GetMapSecond(g3Name); | |
180 | ||
181 | // find module from gAlice | |
182 | AliModule* module = gAlice->GetModule(moduleName); | |
183 | if (!module) { | |
a01c9af5 | 184 | G4String text = "AliSDManager::FindAliModule:\n"; |
676fb573 | 185 | text = text + " AliModule " + moduleName; |
a01c9af5 | 186 | text = text + " (mapped from logical volume " + lv->GetName() + ")\n"; |
187 | text = text + " has not been found in gAlice."; | |
676fb573 | 188 | AliGlobals::Exception(text); |
189 | } | |
190 | ||
191 | return module; | |
192 | } | |
193 | ||
194 | void AliSDManager::SetLego(AliLego* lego) const | |
195 | { | |
196 | // Replaces the existing sensitive detectors | |
197 | // with lego sensitive detectors. | |
198 | // --- | |
199 | ||
200 | if (!lego) { | |
201 | G4String text = "AliSDManager::SetLego: \n"; | |
202 | text = text + " No AliLego is defined."; | |
203 | AliGlobals::Warning(text); | |
204 | return; | |
205 | } | |
206 | ||
207 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
208 | G4int nofLV = pLVStore->entries(); | |
209 | ||
210 | for (G4int i=0; i<nofLV; i++) { | |
211 | G4LogicalVolume* lv = (*pLVStore)[i]; | |
212 | CreateLegoSD(lv, lego); | |
213 | } | |
214 | } | |
215 | ||
216 | void AliSDManager::UnsetLego() const | |
217 | { | |
218 | // Replace the lego sensitive detectors | |
219 | // back with standard sensitive detectors. | |
220 | // --- | |
221 | ||
222 | G4SDManager* pSDManager = G4SDManager::GetSDMpointer(); | |
223 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
224 | G4int nofLV = pLVStore->entries(); | |
225 | ||
226 | // set back standard sensitive detectors | |
227 | for (G4int i=0; i<nofLV; i++) { | |
228 | G4LogicalVolume* lv = (*pLVStore)[i]; | |
229 | UnsetLegoSD(lv); | |
230 | } | |
231 | ||
232 | // The lego sensitive detectors are not deleted here | |
233 | // as there is no way how to unregister them | |
234 | // from G4SDManager | |
235 | } |