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()))
52 //_____________________________________________________________________________
53 AliModule* AliSDConstruction::FindAliModule(G4LogicalVolume* lv) const
55 // Finds the module containing specified logical volume.
59 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
62 G4String g3Name = geometryServices->G4ToG3VolumeName(lv->GetName());
64 // get module name from the map
65 G4String moduleName = geometryServices->GetMapSecond(g3Name);
67 // find module from gAlice
68 AliModule* module = gAlice->GetModule(moduleName);
70 G4String text = "AliSDConstruction::FindAliModule:\n";
71 text = text + " AliModule " + moduleName;
72 text = text + " (mapped from logical volume " + lv->GetName() + ")\n";
73 text = text + " has not been found in gAlice.";
74 AliGlobals::Exception(text);
80 //_____________________________________________________________________________
81 void AliSDConstruction::CreateSD(G4LogicalVolume* lv, AliModule* module) const
83 // Creates/retrieves a sensitive detector for the logical volume.
86 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
87 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
89 G4String lvName = lv->GetName();
90 G4String moduleName = module->GetName();
91 G4String sdName = "/Alice/" + moduleName + "/" + lvName;
93 // cut copy number from sdName
94 sdName = geometryServices->G4ToG3VolumeName(sdName);
96 // create/retrieve the sensitive detector
97 G4VSensitiveDetector* sd = 0;
98 sd = pSDManager->FindSensitiveDetector(sdName);
100 AliSensitiveDetector* asd
101 = new AliSensitiveDetector(sdName, module);
102 pSDManager->AddNewDetector(asd);
104 if (VerboseLevel() > 0) {
105 G4cout << "Sensitive detector " << sdName << "("
106 << asd->GetID() << ") has been created." << G4endl;
111 lv->SetSensitiveDetector(sd);
114 //_____________________________________________________________________________
115 void AliSDConstruction::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const
117 // Replaces the existing sensitive detector of the logical volume
118 // with the lego sensitive detector.
121 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
122 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
124 G4String lvName = lv->GetName();
125 G4String sdName = "/Alice/lego/" + lvName;
127 // cut copy number from sdName
128 sdName = geometryServices->G4ToG3VolumeName(sdName);
130 // retrieve the standard sensitive detector
131 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
133 // create/retrieve the lego sensitive detector
134 G4VSensitiveDetector* legoVSD = 0;
135 legoVSD = pSDManager->FindSensitiveDetector(sdName);
138 AliLegoSensitiveDetector* legoSD
139 = new AliLegoSensitiveDetector(sdName, lego, sd);
140 pSDManager->AddNewDetector(legoSD);
142 if (VerboseLevel() > 0) {
143 G4cout << "Lego sensitive detector " << sdName
144 << ") has been created." << G4endl;
149 lv->SetSensitiveDetector(legoVSD);
152 //_____________________________________________________________________________
153 void AliSDConstruction::UnsetLegoSD(G4LogicalVolume* lv) const
155 // Replace the lego sensitive detector of the logical volume
156 // with the standard sensitive detector.
159 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
161 // get the lego sensitive detector
162 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
163 AliLegoSensitiveDetector* legoSD = 0;
166 legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd);
168 G4String text = "AliSDConstruction::UnsetLego: \n";
169 text = text + " Wrong sensitive detector type.";
170 AliGlobals::Exception(text);
174 // get the standard sensitive detector
175 G4VSensitiveDetector* standardSD = legoSD->GetStandardSD();
177 // set the standard sensitive detector
178 lv->SetSensitiveDetector(standardSD);
184 //_____________________________________________________________________________
185 void AliSDConstruction::Construct()
187 // Creates sensitive detectors and initialize AliModules.
188 // Sensitive detectors are set to all logical volumes
191 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
192 G4int nofLV = lvStore->size();
194 for (G4int i=0; i<nofLV; i++) {
195 G4LogicalVolume* lv = (*lvStore)[i];
196 AliModule* module = FindAliModule(lv);
197 CreateSD(lv, module);
204 //#include "TG4GeometryManager.h"
205 //#include <G3SensVolVector.hh>
207 void AliSDConstruction::CreateSensitiveDetectors2()
209 // Creates sensitive detectors.
210 // Sensitive detectors are set only to logical volumes
211 // in G3SensVolVector.
214 G3SensVolVector svVector
215 = TG4GeometryManager::Instance()->GetG3SensVolVector();
217 G4int nofSV = svVector.entries();
219 for (G4int isv=0; isv<nofSV; isv++) {
220 G4LogicalVolume* lv = svVector[isv];
221 AliModule* module = FindAliModule(lv);
222 CreateSD(lv, module);
227 //_____________________________________________________________________________
228 void AliSDConstruction::SetLego(AliLego* lego) const
230 // Replaces the existing sensitive detectors
231 // with lego sensitive detectors.
235 G4String text = "AliSDConstruction::SetLego: \n";
236 text = text + " No AliLego is defined.";
237 AliGlobals::Warning(text);
241 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
242 G4int nofLV = lvStore->size();
244 for (G4int i=0; i<nofLV; i++) {
245 G4LogicalVolume* lv = (*lvStore)[i];
246 CreateLegoSD(lv, lego);
250 //_____________________________________________________________________________
251 void AliSDConstruction::UnsetLego() const
253 // Replace the lego sensitive detectors
254 // back with standard sensitive detectors.
257 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
258 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
259 G4int nofLV = lvStore->size();
261 // set back standard sensitive detectors
262 for (G4int i=0; i<nofLV; i++) {
263 G4LogicalVolume* lv = (*lvStore)[i];
267 // The lego sensitive detectors are not deleted here
268 // as there is no way how to unregister them