]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliMoreModulesConstruction.h" | |
7 | #include "AliSingleModuleConstruction.h" | |
8 | #include "AliSDManager.h" | |
676fb573 | 9 | #include "AliModule.h" |
676fb573 | 10 | #include "AliGlobals.h" |
11 | ||
12 | #include "TG4GeometryManager.h" | |
13 | ||
14 | #include <G4SDManager.hh> | |
15 | #include <G4LogicalVolume.hh> | |
16 | #include <G4LogicalVolumeStore.hh> | |
17 | ||
676fb573 | 18 | AliMoreModulesConstruction::AliMoreModulesConstruction() { |
19 | // | |
20 | fSDManager = AliSDManager::Instance(); | |
21 | } | |
22 | ||
23 | AliMoreModulesConstruction::AliMoreModulesConstruction( | |
24 | const AliMoreModulesConstruction& right) | |
25 | { | |
26 | // delete current module constructions | |
27 | fModuleConstructionVector.erase( | |
28 | fModuleConstructionVector.begin(), fModuleConstructionVector.end()); | |
29 | ||
30 | // create new module constructions | |
31 | G4int nofModules = right.fModuleConstructionVector.size(); | |
32 | for (G4int i=0; i<nofModules; i++) { | |
33 | G4String name = right.fModuleConstructionVector[i]->GetDetName(); | |
34 | G4int version = right.fModuleConstructionVector[i]->GetVersion(); | |
35 | AliModuleType type = right.fModuleConstructionVector[i]->GetType(); | |
36 | AddModule(name, version, type); | |
37 | } | |
38 | ||
39 | fSDManager = right.fSDManager; | |
40 | } | |
41 | ||
42 | ||
43 | AliMoreModulesConstruction::~AliMoreModulesConstruction() | |
44 | { | |
45 | // delete module constructions | |
46 | fModuleConstructionVector.erase( | |
47 | fModuleConstructionVector.begin(), fModuleConstructionVector.end()); | |
48 | } | |
49 | ||
50 | // operators | |
51 | ||
52 | AliMoreModulesConstruction& | |
53 | AliMoreModulesConstruction::operator=(const AliMoreModulesConstruction& right) | |
54 | { | |
55 | // check assignement to self | |
56 | if (this == &right) return *this; | |
57 | ||
58 | // delete current module constructions | |
59 | fModuleConstructionVector.erase( | |
60 | fModuleConstructionVector.begin(), fModuleConstructionVector.end()); | |
61 | ||
62 | // create new module constructions | |
63 | G4int nofModules = right.fModuleConstructionVector.size(); | |
64 | for (G4int i=0; i<nofModules; i++) { | |
65 | G4String name = right.fModuleConstructionVector[i]->GetDetName(); | |
66 | G4int version = right.fModuleConstructionVector[i]->GetVersion(); | |
67 | AliModuleType type = right.fModuleConstructionVector[i]->GetType(); | |
68 | AddModule(name, version, type); | |
69 | } | |
70 | ||
71 | fSDManager = right.fSDManager; | |
72 | ||
73 | return *this; | |
74 | } | |
75 | ||
76 | // private methods | |
77 | ||
78 | void AliMoreModulesConstruction::CreateSensitiveDetectors( | |
79 | G4bool allLVSensitive) | |
80 | { | |
81 | // Creates sensitive detectors. | |
82 | // --- | |
83 | ||
84 | if (allLVSensitive) | |
85 | CreateSensitiveDetectors1(); | |
86 | else | |
87 | CreateSensitiveDetectors2(); | |
88 | ||
89 | // set static number of logical volumes already processed | |
90 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
91 | fSDManager->SetNofLVWithSD(pLVStore->entries()); | |
92 | } | |
93 | ||
94 | void AliMoreModulesConstruction::CreateSensitiveDetectors1() | |
95 | { | |
96 | // Creates sensitive detectors. | |
97 | // Sensitive detectors are set to all logical volumes | |
98 | // --- | |
99 | ||
100 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
101 | G4int nofLV = pLVStore->entries(); | |
102 | ||
103 | G4int nofLVWithSD = fSDManager->GetNofLVWithSD(); | |
104 | for (G4int i=nofLVWithSD; i<nofLV; i++) { | |
105 | G4LogicalVolume* lv = (*pLVStore)[i]; | |
106 | AliModule* module = fSDManager->FindAliModule(lv); | |
107 | fSDManager->CreateSD(lv, module); | |
108 | } | |
109 | } | |
110 | ||
111 | void AliMoreModulesConstruction::CreateSensitiveDetectors2() | |
112 | { | |
113 | // Creates sensitive detectors. | |
114 | // Sensitive detectors are set only to logical volumes | |
115 | // in G3SensVolVector. | |
116 | // --- | |
117 | ||
118 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
119 | ||
120 | G3SensVolVector pSVVector | |
121 | = pGeometryManager->GetG3SensVolVector(); | |
122 | ||
123 | G4int nofSV = pSVVector.entries(); | |
124 | if (nofSV>0) | |
125 | for (G4int isv=0; isv<nofSV; isv++) { | |
126 | G4LogicalVolume* lv = pSVVector[isv]; | |
127 | AliModule* module = fSDManager->FindAliModule(lv); | |
128 | fSDManager->CreateSD(lv, module); | |
129 | } | |
130 | } | |
131 | ||
132 | // public methods | |
133 | ||
134 | void AliMoreModulesConstruction::AddModule(G4String moduleName, G4int version, | |
135 | AliModuleType moduleType) | |
136 | { | |
137 | // Adds module specified by name, version and type. | |
138 | // --- | |
139 | ||
140 | // create module construction | |
141 | AliSingleModuleConstruction* moduleConstruction | |
142 | = new AliSingleModuleConstruction(moduleName, version, moduleType); | |
143 | ||
144 | // add module, module construction to vectors | |
145 | fModuleConstructionVector.push_back(moduleConstruction); | |
146 | } | |
147 | ||
62022fa8 | 148 | void AliMoreModulesConstruction::Configure() |
149 | { | |
150 | // Executes the detectors setup Root macros | |
151 | // (extracted from AliRoot Config.C) and | |
152 | // G4 macros. | |
153 | // --- | |
154 | ||
155 | // number of modules | |
156 | G4int nofModules = fModuleConstructionVector.size(); | |
157 | ||
158 | if (nofModules == 0) { | |
159 | AliGlobals::Warning( | |
160 | "AliMoreModulesConstruction::Construct(): No modules are defined."); | |
161 | } | |
162 | else | |
163 | for (G4int i=0; i<nofModules; i++) | |
164 | fModuleConstructionVector[i]->Configure(); | |
165 | } | |
166 | ||
676fb573 | 167 | void AliMoreModulesConstruction::Construct() |
168 | { | |
169 | // Constructs geometry. | |
170 | // G3 tables are process for all modules alltogether. | |
171 | // -- | |
172 | ||
173 | // number of modules | |
174 | G4int nofModules = fModuleConstructionVector.size(); | |
175 | ||
176 | if (nofModules == 0) { | |
177 | AliGlobals::Warning( | |
178 | "AliMoreModulesConstruction::Construct(): No modules are defined."); | |
179 | } | |
180 | else { | |
181 | // get geometry manager | |
182 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
183 | ||
184 | G4bool allLVSensitive = false; | |
185 | G4int i; | |
186 | for (i=0; i<nofModules; i++) { | |
187 | ||
62022fa8 | 188 | // fModuleConstructionVector[i]->Configure(); |
676fb573 | 189 | |
190 | // register module name in the name map | |
191 | AliModule* module = fModuleConstructionVector[i]->GetAliModule(); | |
192 | pGeometryManager->SetMapSecond(module->GetName()); | |
193 | ||
194 | G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry(); | |
195 | G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry(); | |
196 | G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath(); | |
197 | ||
198 | if (readGeometry) { | |
871f5582 | 199 | // TG4GeometryManager uses g3tog4 methods for reading |
200 | // g3calls.dat files - as these methods do not fill name map | |
201 | // they cannot be used for constructing more modules | |
202 | // together | |
203 | // | |
204 | // pGeometryManager->SetWriteGeometry(false); | |
205 | // pGeometryManager->ReadG3Geometry(dataFilePath); | |
206 | ||
207 | G4String text = "AliMoreModulesConstruction::Construct - Limitation:\n"; | |
208 | text = text + " Reading g3calls.dat is not implemented."; | |
209 | AliGlobals::Exception(text); | |
676fb573 | 210 | } |
211 | else { | |
212 | // set geometry output stream for this module | |
213 | pGeometryManager->SetWriteGeometry(writeGeometry); | |
214 | if (writeGeometry) | |
215 | pGeometryManager->OpenOutFile(dataFilePath); | |
216 | ||
217 | // create geometry from AliRoot | |
218 | ||
219 | // construct materials | |
220 | module->CreateMaterials(); | |
221 | ||
222 | // construct G3 geometry | |
223 | module->CreateGeometry(); | |
62022fa8 | 224 | |
871f5582 | 225 | if (writeGeometry) |
226 | pGeometryManager->CloseOutFile(); | |
676fb573 | 227 | } |
228 | ||
229 | // all logical volumes will be made sensitive if any | |
230 | // module requires this | |
231 | if (fModuleConstructionVector[i]->GetAllLVSensitive()) | |
232 | allLVSensitive = true; | |
233 | } | |
234 | ||
235 | // construct G4 geometry | |
236 | pGeometryManager->CreateG4Geometry(); | |
237 | ||
238 | // print name map | |
239 | // pGeometryManager->PrintNameMap(); | |
240 | ||
241 | // create sensitive detectors | |
242 | CreateSensitiveDetectors(allLVSensitive); | |
676fb573 | 243 | |
244 | for (i=0; i<nofModules; i++) { | |
245 | // set the detector frame (envelope) | |
246 | // (without warning output if enevelope is not defined) | |
247 | fModuleConstructionVector[i]->SetDetFrame(false); | |
248 | ||
249 | // build sensitive detectors table | |
250 | fModuleConstructionVector[i]->GetAliModule()->Init(); | |
e88c18bd | 251 | |
252 | // construct geometry for display | |
253 | fModuleConstructionVector[i]->GetAliModule()->BuildGeometry(); | |
676fb573 | 254 | } |
255 | ||
256 | // reset TG4GeometryManager | |
257 | pGeometryManager->ClearG3Tables(); | |
258 | ||
259 | // print current total number of logical volumes | |
260 | G4cout << "Current total number of sensitive volumes: " | |
5f1d09c5 | 261 | << pGeometryManager->NofVolumes() << G4endl; |
676fb573 | 262 | |
263 | #ifdef ALICE_VISUALIZE | |
264 | // set visualization attributes | |
265 | for (i=0; i<nofModules; i++) { | |
266 | if (fModuleConstructionVector[i]->GetDetFrame()) { | |
267 | fModuleConstructionVector[i]->SetDetVisibility(true); | |
268 | fModuleConstructionVector[i]->SetDetColour("Yellow"); | |
269 | } | |
270 | } | |
271 | #endif | |
272 | } | |
273 | } |