2 // Category: digits+hits
4 // Author: I. Hrivnacova
6 // Class AliAliSDConstruction
7 // --------------------------
8 // See the class description in the header file.
10 #include "AliSDConstruction.h"
11 #include "AliSensitiveDetector.h"
12 #include "AliLegoSensitiveDetector.h"
13 #include "AliGlobals.h"
15 #include "AliModule.h"
17 #include "TG4GeometryServices.h"
19 #include <G4SDManager.hh>
20 #include <G4LogicalVolume.hh>
21 #include <G4LogicalVolumeStore.hh>
23 #include <TObjArray.h>
25 //_____________________________________________________________________________
26 AliSDConstruction::AliSDConstruction()
27 : TG4VSDConstruction(),
28 AliVerbose("SDConstruction") {
32 //_____________________________________________________________________________
33 AliSDConstruction::~AliSDConstruction() {
39 //_____________________________________________________________________________
40 void AliSDConstruction::InitializeModules()
42 // Initializes AliModules.
45 TObjArray* modules = gAlice->Modules();
48 while((module = (AliModule*)next())) {
50 module->BuildGeometry();
54 //_____________________________________________________________________________
55 AliModule* AliSDConstruction::FindAliModule(G4LogicalVolume* lv) const
57 // Finds the module containing specified logical volume.
61 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
64 G4String g3Name = geometryServices->G4ToG3VolumeName(lv->GetName());
66 // get module name from the map
67 G4String moduleName = geometryServices->GetMapSecond(g3Name);
69 // find module from gAlice
70 AliModule* module = gAlice->GetModule(moduleName);
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);
82 //_____________________________________________________________________________
83 void AliSDConstruction::CreateSD(G4LogicalVolume* lv, AliModule* module) const
85 // Creates/retrieves a sensitive detector for the logical volume.
88 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
89 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
91 G4String lvName = lv->GetName();
92 G4String moduleName = module->GetName();
93 G4String sdName = "/Alice/" + moduleName + "/" + lvName;
95 // cut copy number from sdName
96 sdName = geometryServices->G4ToG3VolumeName(sdName);
98 // create/retrieve the sensitive detector
99 G4VSensitiveDetector* sd = 0;
100 sd = pSDManager->FindSensitiveDetector(sdName);
102 AliSensitiveDetector* asd
103 = new AliSensitiveDetector(sdName, module);
104 pSDManager->AddNewDetector(asd);
106 if (VerboseLevel() > 0) {
107 G4cout << "Sensitive detector " << sdName << "("
108 << asd->GetID() << ") has been created." << G4endl;
113 lv->SetSensitiveDetector(sd);
116 //_____________________________________________________________________________
117 void AliSDConstruction::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const
119 // Replaces the existing sensitive detector of the logical volume
120 // with the lego sensitive detector.
123 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
124 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
126 G4String lvName = lv->GetName();
127 G4String sdName = "/Alice/lego/" + lvName;
129 // cut copy number from sdName
130 sdName = geometryServices->G4ToG3VolumeName(sdName);
132 // retrieve the standard sensitive detector
133 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
135 // create/retrieve the lego sensitive detector
136 G4VSensitiveDetector* legoVSD = 0;
137 legoVSD = pSDManager->FindSensitiveDetector(sdName);
140 AliLegoSensitiveDetector* legoSD
141 = new AliLegoSensitiveDetector(sdName, lego, sd);
142 pSDManager->AddNewDetector(legoSD);
144 if (VerboseLevel() > 0) {
145 G4cout << "Lego sensitive detector " << sdName
146 << ") has been created." << G4endl;
151 lv->SetSensitiveDetector(legoVSD);
154 //_____________________________________________________________________________
155 void AliSDConstruction::UnsetLegoSD(G4LogicalVolume* lv) const
157 // Replace the lego sensitive detector of the logical volume
158 // with the standard sensitive detector.
161 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
163 // get the lego sensitive detector
164 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
165 AliLegoSensitiveDetector* legoSD = 0;
168 legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd);
170 G4String text = "AliSDConstruction::UnsetLego: \n";
171 text = text + " Wrong sensitive detector type.";
172 AliGlobals::Exception(text);
176 // get the standard sensitive detector
177 G4VSensitiveDetector* standardSD = legoSD->GetStandardSD();
179 // set the standard sensitive detector
180 lv->SetSensitiveDetector(standardSD);
186 //_____________________________________________________________________________
187 void AliSDConstruction::Construct()
189 // Creates sensitive detectors and initialize AliModules.
190 // Sensitive detectors are set to all logical volumes
193 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
194 G4int nofLV = lvStore->size();
196 for (G4int i=0; i<nofLV; i++) {
197 G4LogicalVolume* lv = (*lvStore)[i];
198 AliModule* module = FindAliModule(lv);
199 CreateSD(lv, module);
206 //#include "TG4GeometryManager.h"
207 //#include <G3SensVolVector.hh>
209 void AliSDConstruction::CreateSensitiveDetectors2()
211 // Creates sensitive detectors.
212 // Sensitive detectors are set only to logical volumes
213 // in G3SensVolVector.
216 G3SensVolVector svVector
217 = TG4GeometryManager::Instance()->GetG3SensVolVector();
219 G4int nofSV = svVector.entries();
221 for (G4int isv=0; isv<nofSV; isv++) {
222 G4LogicalVolume* lv = svVector[isv];
223 AliModule* module = FindAliModule(lv);
224 CreateSD(lv, module);
229 //_____________________________________________________________________________
230 void AliSDConstruction::SetLego(AliLego* lego) const
232 // Replaces the existing sensitive detectors
233 // with lego sensitive detectors.
237 G4String text = "AliSDConstruction::SetLego: \n";
238 text = text + " No AliLego is defined.";
239 AliGlobals::Warning(text);
243 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
244 G4int nofLV = lvStore->size();
246 for (G4int i=0; i<nofLV; i++) {
247 G4LogicalVolume* lv = (*lvStore)[i];
248 CreateLegoSD(lv, lego);
252 //_____________________________________________________________________________
253 void AliSDConstruction::UnsetLego() const
255 // Replace the lego sensitive detectors
256 // back with standard sensitive detectors.
259 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
260 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
261 G4int nofLV = lvStore->size();
263 // set back standard sensitive detectors
264 for (G4int i=0; i<nofLV; i++) {
265 G4LogicalVolume* lv = (*lvStore)[i];
269 // The lego sensitive detectors are not deleted here
270 // as there is no way how to unregister them