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() {
31 //_____________________________________________________________________________
32 AliSDConstruction::~AliSDConstruction() {
38 //_____________________________________________________________________________
39 void AliSDConstruction::InitializeModules()
41 // Initializes AliModules.
44 TObjArray* modules = gAlice->Modules();
47 while((module = (AliModule*)next()))
51 //_____________________________________________________________________________
52 AliModule* AliSDConstruction::FindAliModule(G4LogicalVolume* lv) const
54 // Finds the module containing specified logical volume.
58 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
61 G4String g3Name = geometryServices->G4ToG3VolumeName(lv->GetName());
63 // get module name from the map
64 G4String moduleName = geometryServices->GetMapSecond(g3Name);
66 // find module from gAlice
67 AliModule* module = gAlice->GetModule(moduleName);
69 G4String text = "AliSDConstruction::FindAliModule:\n";
70 text = text + " AliModule " + moduleName;
71 text = text + " (mapped from logical volume " + lv->GetName() + ")\n";
72 text = text + " has not been found in gAlice.";
73 AliGlobals::Exception(text);
79 //_____________________________________________________________________________
80 void AliSDConstruction::CreateSD(G4LogicalVolume* lv, AliModule* module) const
82 // Creates/retrieves a sensitive detector for the logical volume.
85 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
86 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
88 G4String lvName = lv->GetName();
89 G4String moduleName = module->GetName();
90 G4String sdName = "/Alice/" + moduleName + "/" + lvName;
92 // cut copy number from sdName
93 sdName = geometryServices->G4ToG3VolumeName(sdName);
95 // create/retrieve the sensitive detector
96 G4VSensitiveDetector* sd = 0;
97 sd = pSDManager->FindSensitiveDetector(sdName);
99 AliSensitiveDetector* asd
100 = new AliSensitiveDetector(sdName, module);
101 pSDManager->AddNewDetector(asd);
103 G4cout << "Sensitive detector " << sdName << "("
104 << asd->GetID() << ") has been created." << G4endl;
107 lv->SetSensitiveDetector(sd);
110 //_____________________________________________________________________________
111 void AliSDConstruction::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const
113 // Replaces the existing sensitive detector of the logical volume
114 // with the lego sensitive detector.
117 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
118 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
120 G4String lvName = lv->GetName();
121 G4String sdName = "/Alice/lego/" + lvName;
123 // cut copy number from sdName
124 sdName = geometryServices->G4ToG3VolumeName(sdName);
126 // retrieve the standard sensitive detector
127 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
129 // create/retrieve the lego sensitive detector
130 G4VSensitiveDetector* legoVSD = 0;
131 legoVSD = pSDManager->FindSensitiveDetector(sdName);
134 AliLegoSensitiveDetector* legoSD
135 = new AliLegoSensitiveDetector(sdName, lego, sd);
136 pSDManager->AddNewDetector(legoSD);
138 G4cout << "Lego sensitive detector " << sdName
139 << ") has been created." << G4endl;
142 lv->SetSensitiveDetector(legoVSD);
145 //_____________________________________________________________________________
146 void AliSDConstruction::UnsetLegoSD(G4LogicalVolume* lv) const
148 // Replace the lego sensitive detector of the logical volume
149 // with the standard sensitive detector.
152 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
154 // get the lego sensitive detector
155 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
156 AliLegoSensitiveDetector* legoSD = 0;
159 legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd);
161 G4String text = "AliSDConstruction::UnsetLego: \n";
162 text = text + " Wrong sensitive detector type.";
163 AliGlobals::Exception(text);
167 // get the standard sensitive detector
168 G4VSensitiveDetector* standardSD = legoSD->GetStandardSD();
170 // set the standard sensitive detector
171 lv->SetSensitiveDetector(standardSD);
177 //_____________________________________________________________________________
178 void AliSDConstruction::Construct()
180 // Creates sensitive detectors and initialize AliModules.
181 // Sensitive detectors are set to all logical volumes
184 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
185 G4int nofLV = lvStore->size();
187 for (G4int i=0; i<nofLV; i++) {
188 G4LogicalVolume* lv = (*lvStore)[i];
189 AliModule* module = FindAliModule(lv);
190 CreateSD(lv, module);
197 //#include "TG4GeometryManager.h"
198 //#include <G3SensVolVector.hh>
200 void AliSDConstruction::CreateSensitiveDetectors2()
202 // Creates sensitive detectors.
203 // Sensitive detectors are set only to logical volumes
204 // in G3SensVolVector.
207 G3SensVolVector svVector
208 = TG4GeometryManager::Instance()->GetG3SensVolVector();
210 G4int nofSV = svVector.entries();
212 for (G4int isv=0; isv<nofSV; isv++) {
213 G4LogicalVolume* lv = svVector[isv];
214 AliModule* module = FindAliModule(lv);
215 CreateSD(lv, module);
220 //_____________________________________________________________________________
221 void AliSDConstruction::SetLego(AliLego* lego) const
223 // Replaces the existing sensitive detectors
224 // with lego sensitive detectors.
228 G4String text = "AliSDConstruction::SetLego: \n";
229 text = text + " No AliLego is defined.";
230 AliGlobals::Warning(text);
234 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
235 G4int nofLV = lvStore->size();
237 for (G4int i=0; i<nofLV; i++) {
238 G4LogicalVolume* lv = (*lvStore)[i];
239 CreateLegoSD(lv, lego);
243 //_____________________________________________________________________________
244 void AliSDConstruction::UnsetLego() const
246 // Replace the lego sensitive detectors
247 // back with standard sensitive detectors.
250 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
251 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
252 G4int nofLV = lvStore->size();
254 // set back standard sensitive detectors
255 for (G4int i=0; i<nofLV; i++) {
256 G4LogicalVolume* lv = (*lvStore)[i];
260 // The lego sensitive detectors are not deleted here
261 // as there is no way how to unregister them