]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliSDConstruction.cxx
-lTHBTprocessor -lhbtprocessor added to LIBS
[u/mrichter/AliRoot.git] / AliGeant4 / AliSDConstruction.cxx
CommitLineData
c926eee0 1// $Id$
2// Category: digits+hits
3//
a6412d9b 4// Author: I. Hrivnacova
5//
6// Class AliAliSDConstruction
7// --------------------------
c926eee0 8// See the class description in the header file.
9
10#include "AliSDConstruction.h"
11#include "AliSensitiveDetector.h"
12#include "AliLegoSensitiveDetector.h"
13#include "AliGlobals.h"
14#include "AliRun.h"
15#include "AliModule.h"
16
17#include "TG4GeometryServices.h"
18
19#include <G4SDManager.hh>
20#include <G4LogicalVolume.hh>
21#include <G4LogicalVolumeStore.hh>
22
23#include <TObjArray.h>
24
a6412d9b 25//_____________________________________________________________________________
c926eee0 26AliSDConstruction::AliSDConstruction()
27 : TG4VSDConstruction() {
28//
29}
30
a6412d9b 31//_____________________________________________________________________________
c926eee0 32AliSDConstruction::~AliSDConstruction() {
33//
34}
35
36// private methods
37
a6412d9b 38//_____________________________________________________________________________
c926eee0 39void AliSDConstruction::InitializeModules()
40{
41// Initializes AliModules.
42// ---
43
44 TObjArray* modules = gAlice->Modules();
45 TIter next(modules);
46 AliModule* module;
47 while((module = (AliModule*)next()))
48 module->Init();
49}
50
a6412d9b 51//_____________________________________________________________________________
c926eee0 52AliModule* AliSDConstruction::FindAliModule(G4LogicalVolume* lv) const
53{
54// Finds the module containing specified logical volume.
55// ---
56
57 // geometry manager
58 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
59
60 // get g3 volume name
a6412d9b 61 G4String g3Name = geometryServices->G4ToG3VolumeName(lv->GetName());
c926eee0 62
63 // get module name from the map
64 G4String moduleName = geometryServices->GetMapSecond(g3Name);
65
66 // find module from gAlice
67 AliModule* module = gAlice->GetModule(moduleName);
68 if (!module) {
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);
74 }
75
76 return module;
77}
78
a6412d9b 79//_____________________________________________________________________________
c926eee0 80void AliSDConstruction::CreateSD(G4LogicalVolume* lv, AliModule* module) const
81{
82// Creates/retrieves a sensitive detector for the logical volume.
83// ---
84
85 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
86 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
87
a6412d9b 88 G4String lvName = lv->GetName();
c926eee0 89 G4String moduleName = module->GetName();
90 G4String sdName = "/Alice/" + moduleName + "/" + lvName;
91
92 // cut copy number from sdName
a6412d9b 93 sdName = geometryServices->G4ToG3VolumeName(sdName);
c926eee0 94
95 // create/retrieve the sensitive detector
96 G4VSensitiveDetector* sd = 0;
97 sd = pSDManager->FindSensitiveDetector(sdName);
98 if (!sd) {
99 AliSensitiveDetector* asd
100 = new AliSensitiveDetector(sdName, module);
101 pSDManager->AddNewDetector(asd);
102 // add verbose
103 G4cout << "Sensitive detector " << sdName << "("
104 << asd->GetID() << ") has been created." << G4endl;
105 sd = asd;
106 }
107 lv->SetSensitiveDetector(sd);
108}
109
a6412d9b 110//_____________________________________________________________________________
c926eee0 111void AliSDConstruction::CreateLegoSD(G4LogicalVolume* lv, AliLego* lego) const
112{
113// Replaces the existing sensitive detector of the logical volume
114// with the lego sensitive detector.
115// ---
116
117 TG4GeometryServices* geometryServices = TG4GeometryServices::Instance();
118 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
119
120 G4String lvName = lv->GetName();
121 G4String sdName = "/Alice/lego/" + lvName;
122
123 // cut copy number from sdName
a6412d9b 124 sdName = geometryServices->G4ToG3VolumeName(sdName);
c926eee0 125
126 // retrieve the standard sensitive detector
127 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
128
129 // create/retrieve the lego sensitive detector
130 G4VSensitiveDetector* legoVSD = 0;
131 legoVSD = pSDManager->FindSensitiveDetector(sdName);
132
133 if (!legoVSD) {
134 AliLegoSensitiveDetector* legoSD
135 = new AliLegoSensitiveDetector(sdName, lego, sd);
136 pSDManager->AddNewDetector(legoSD);
137 // add verbose
138 G4cout << "Lego sensitive detector " << sdName
139 << ") has been created." << G4endl;
140 legoVSD = legoSD;
141 }
142 lv->SetSensitiveDetector(legoVSD);
143}
144
a6412d9b 145//_____________________________________________________________________________
c926eee0 146void AliSDConstruction::UnsetLegoSD(G4LogicalVolume* lv) const
147{
148// Replace the lego sensitive detector of the logical volume
149// with the standard sensitive detector.
150// ---
151
152 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
153
154 // get the lego sensitive detector
155 G4VSensitiveDetector* sd = lv->GetSensitiveDetector();
156 AliLegoSensitiveDetector* legoSD = 0;
157 if (sd) {
158 // check type
159 legoSD = dynamic_cast<AliLegoSensitiveDetector*>(sd);
160 if (!legoSD) {
161 G4String text = "AliSDConstruction::UnsetLego: \n";
162 text = text + " Wrong sensitive detector type.";
163 AliGlobals::Exception(text);
164 }
165 }
166
167 // get the standard sensitive detector
168 G4VSensitiveDetector* standardSD = legoSD->GetStandardSD();
169
170 // set the standard sensitive detector
171 lv->SetSensitiveDetector(standardSD);
172}
173
174
175// public methods
176
a6412d9b 177//_____________________________________________________________________________
c926eee0 178void AliSDConstruction::Construct()
179{
180// Creates sensitive detectors and initialize AliModules.
181// Sensitive detectors are set to all logical volumes
182// ---
183
184 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
185 G4int nofLV = lvStore->size();
186
187 for (G4int i=0; i<nofLV; i++) {
188 G4LogicalVolume* lv = (*lvStore)[i];
189 AliModule* module = FindAliModule(lv);
190 CreateSD(lv, module);
191 }
192
193 InitializeModules();
194}
195
196/*
197//#include "TG4GeometryManager.h"
198//#include <G3SensVolVector.hh>
199
200void AliSDConstruction::CreateSensitiveDetectors2()
201{
202// Creates sensitive detectors.
203// Sensitive detectors are set only to logical volumes
204// in G3SensVolVector.
205// ---
206
207 G3SensVolVector svVector
208 = TG4GeometryManager::Instance()->GetG3SensVolVector();
209
210 G4int nofSV = svVector.entries();
211 if (nofSV>0)
212 for (G4int isv=0; isv<nofSV; isv++) {
213 G4LogicalVolume* lv = svVector[isv];
214 AliModule* module = FindAliModule(lv);
215 CreateSD(lv, module);
216 }
217}
218*/
219
a6412d9b 220//_____________________________________________________________________________
c926eee0 221void AliSDConstruction::SetLego(AliLego* lego) const
222{
223// Replaces the existing sensitive detectors
224// with lego sensitive detectors.
225// ---
226
227 if (!lego) {
228 G4String text = "AliSDConstruction::SetLego: \n";
229 text = text + " No AliLego is defined.";
230 AliGlobals::Warning(text);
231 return;
232 }
233
234 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
235 G4int nofLV = lvStore->size();
236
237 for (G4int i=0; i<nofLV; i++) {
238 G4LogicalVolume* lv = (*lvStore)[i];
239 CreateLegoSD(lv, lego);
240 }
241}
242
a6412d9b 243//_____________________________________________________________________________
c926eee0 244void AliSDConstruction::UnsetLego() const
245{
246// Replace the lego sensitive detectors
247// back with standard sensitive detectors.
248// ---
249
250 G4SDManager* pSDManager = G4SDManager::GetSDMpointer();
251 G4LogicalVolumeStore* lvStore = G4LogicalVolumeStore::GetInstance();
252 G4int nofLV = lvStore->size();
253
254 // set back standard sensitive detectors
255 for (G4int i=0; i<nofLV; i++) {
256 G4LogicalVolume* lv = (*lvStore)[i];
257 UnsetLegoSD(lv);
258 }
259
260 // The lego sensitive detectors are not deleted here
261 // as there is no way how to unregister them
262 // from G4SDManager
263}