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