]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliModulesComposition.h" | |
7 | #include "AliModulesCompositionMessenger.h" | |
8 | #include "AliSingleModuleConstruction.h" | |
9 | #include "AliMoreModulesConstruction.h" | |
c97337f9 | 10 | #include "AliDetSwitch.h" |
676fb573 | 11 | #include "AliMagneticField.h" |
12 | #include "AliGlobals.h" | |
55ebdd9f | 13 | #include "AliFiles.h" |
676fb573 | 14 | |
6f0bd611 | 15 | #include "TG4GeometryManager.h" |
7b34522f | 16 | #include "TG4XMLGeometryGenerator.h" |
17 | ||
7b34522f | 18 | #include <G4Material.hh> |
c97337f9 | 19 | #include <G4VPhysicalVolume.hh> |
676fb573 | 20 | |
21 | AliModulesComposition::AliModulesComposition() | |
22 | : fAllLVSensitive(false), | |
6f0bd611 | 23 | fForceAllLVSensitive(true), |
676fb573 | 24 | fReadGeometry(false), |
9b0f6db2 | 25 | fWriteGeometry(false), |
26 | fMagneticField(0) | |
676fb573 | 27 | { |
28 | // | |
29 | fMoreModulesConstruction = new AliMoreModulesConstruction(); | |
676fb573 | 30 | fMessenger = new AliModulesCompositionMessenger(this); |
31 | } | |
32 | ||
33 | AliModulesComposition::AliModulesComposition(const AliModulesComposition& right) | |
34 | { | |
35 | // | |
36 | AliGlobals::Exception("AliModulesComposition is protected from copying."); | |
37 | } | |
38 | ||
39 | AliModulesComposition::~AliModulesComposition() { | |
40 | // | |
41 | delete fMoreModulesConstruction; | |
42 | delete fMagneticField; | |
43 | delete fMessenger; | |
44 | ||
45 | // destroy det switch vector | |
46 | fDetSwitchVector.clearAndDestroy(); | |
47 | ||
48 | // destroy det construction vector | |
49 | fModuleConstructionVector.clearAndDestroy(); | |
50 | } | |
51 | ||
52 | // operators | |
53 | ||
54 | AliModulesComposition& | |
55 | AliModulesComposition::operator=(const AliModulesComposition& right) | |
56 | { | |
57 | // check assignement to self | |
58 | if (this == &right) return *this; | |
59 | ||
60 | AliGlobals::Exception("AliModulesComposition is protected from assigning."); | |
61 | ||
62 | return *this; | |
63 | } | |
64 | ||
65 | // protected methods | |
66 | ||
67 | void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch) | |
68 | { | |
69 | // Adds detSwitch to the detSwitch vector. | |
70 | // --- | |
71 | ||
72 | fDetSwitchVector.insert(detSwitch); | |
73 | fMessenger->SetCandidates(); | |
74 | } | |
75 | ||
76 | void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName, | |
77 | G4int version, AliModuleType moduleType) | |
78 | { | |
79 | // Adds SingleModuleConstruction. | |
80 | // --- | |
81 | ||
82 | AliSingleModuleConstruction* moduleConstruction | |
83 | = new AliSingleModuleConstruction(moduleName, version, moduleType); | |
84 | fModuleConstructionVector.insert(moduleConstruction); | |
85 | } | |
86 | ||
87 | void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName, | |
88 | G4int version, AliModuleType moduleType) | |
89 | { | |
90 | // Adds module to MoreModulesConstruction (construction of dependent | |
91 | // modules.) | |
92 | // --- | |
93 | ||
94 | fMoreModulesConstruction->AddModule(moduleName, version, moduleType); | |
95 | } | |
96 | ||
97 | void AliModulesComposition::ConstructModules() | |
98 | { | |
99 | // Construct geometry of all modules (both standalone and dependent.) | |
100 | // --- | |
101 | ||
102 | // set common options | |
103 | SetReadGeometryToModules(fReadGeometry); | |
104 | SetWriteGeometryToModules(fWriteGeometry); | |
105 | SetAllLVSensitiveToModules(fAllLVSensitive); | |
106 | // common setAllLVSensitive is overridden by Config.in | |
107 | // macro | |
108 | ||
109 | // one module constructions | |
110 | G4int nofDets = fModuleConstructionVector.entries(); | |
7b34522f | 111 | for (G4int i=0; i<nofDets; i++) { |
55ebdd9f | 112 | fModuleConstructionVector[i]->Configure(*AliFiles::Instance()); |
7b34522f | 113 | } |
45ee196a | 114 | if (fForceAllLVSensitive) |
115 | SetAllLVSensitiveToModules(fForceAllLVSensitive); | |
116 | // override the setAllLVSensitive by Config.in macro | |
117 | // if required | |
118 | ||
676fb573 | 119 | for (G4int i=0; i<nofDets; i++) { |
120 | G4cout << "Module " << fModuleConstructionVector[i]->GetDetName() | |
ba6f5bec | 121 | << " will be constructed now." << G4endl; |
676fb573 | 122 | fModuleConstructionVector[i]->Construct(); |
123 | } | |
124 | ||
125 | // more modules construction | |
126 | G4int nofModules = fMoreModulesConstruction->GetNofModules(); | |
127 | if (nofModules>0) { | |
55ebdd9f | 128 | fMoreModulesConstruction->Configure(*AliFiles::Instance()); |
45ee196a | 129 | if (fForceAllLVSensitive) |
130 | SetAllLVSensitiveToModules(fForceAllLVSensitive); | |
131 | // override the setAllLVSensitive by Config.in macro | |
132 | // if required | |
133 | ||
ba6f5bec | 134 | G4cout << "Dependent modules will be constructed now." << G4endl; |
676fb573 | 135 | fMoreModulesConstruction->Construct(); |
136 | } | |
6f0bd611 | 137 | |
138 | // fill medium Id vector | |
139 | TG4GeometryManager::Instance()->FillMediumIdVector(); | |
140 | // this step can be done only after the sensitive | |
141 | // detectors have been created | |
676fb573 | 142 | } |
143 | ||
144 | void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry) | |
145 | { | |
146 | // Sets readGeometry control to all modules. | |
147 | // --- | |
148 | ||
149 | // single module constructions | |
150 | G4int nofDets = fModuleConstructionVector.entries(); | |
151 | G4int i; | |
152 | for (i=0; i<nofDets; i++) | |
153 | fModuleConstructionVector[i]->SetReadGeometry(readGeometry); | |
154 | ||
155 | // more modules construction | |
156 | nofDets = fMoreModulesConstruction->GetNofModules(); | |
157 | for (i=0; i<nofDets; i++) { | |
158 | AliSingleModuleConstruction* moduleConstruction | |
159 | = fMoreModulesConstruction->GetModuleConstruction(i); | |
160 | moduleConstruction->SetReadGeometry(readGeometry); | |
161 | } | |
162 | } | |
163 | ||
164 | void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry) | |
165 | { | |
166 | // Sets writeGeometry control to all modules. | |
167 | // --- | |
168 | ||
169 | // single module constructions | |
170 | G4int nofDets = fModuleConstructionVector.entries(); | |
171 | G4int i; | |
172 | for (i=0; i<nofDets; i++) | |
173 | fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry); | |
174 | ||
175 | // more modules construction | |
176 | nofDets = fMoreModulesConstruction->GetNofModules(); | |
177 | for (i=0; i<nofDets; i++) { | |
178 | AliSingleModuleConstruction* moduleConstruction | |
179 | = fMoreModulesConstruction->GetModuleConstruction(i); | |
180 | moduleConstruction->SetWriteGeometry(writeGeometry); | |
181 | } | |
182 | } | |
183 | ||
184 | void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive) | |
185 | { | |
186 | // Sets setAllSensitive control to all modules. | |
187 | // --- | |
188 | ||
189 | // single module constructions | |
190 | G4int nofDets = fModuleConstructionVector.entries(); | |
191 | G4int i; | |
ba6f5bec | 192 | for (i=0; i<nofDets; i++) |
193 | fModuleConstructionVector[i]->SetAllLVSensitive(allSensitive); | |
676fb573 | 194 | |
195 | // more modules construction | |
196 | nofDets = fMoreModulesConstruction->GetNofModules(); | |
197 | for (i=0; i<nofDets; i++) { | |
198 | AliSingleModuleConstruction* moduleConstruction | |
199 | = fMoreModulesConstruction->GetModuleConstruction(i); | |
200 | moduleConstruction->SetAllLVSensitive(allSensitive); | |
201 | } | |
202 | } | |
203 | ||
204 | void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig) | |
205 | { | |
206 | // Sets processConfig control to all modules. | |
207 | // --- | |
208 | ||
209 | // single module constructions | |
210 | G4int nofDets = fModuleConstructionVector.entries(); | |
211 | G4int i; | |
ba6f5bec | 212 | for (i=0; i<nofDets; i++) |
213 | fModuleConstructionVector[i]->SetProcessConfig(processConfig); | |
676fb573 | 214 | |
215 | // more modules construction | |
216 | nofDets = fMoreModulesConstruction->GetNofModules(); | |
217 | for (i=0; i<nofDets; i++) { | |
218 | AliSingleModuleConstruction* moduleConstruction | |
219 | = fMoreModulesConstruction->GetModuleConstruction(i); | |
220 | moduleConstruction->SetProcessConfig(processConfig); | |
221 | } | |
222 | } | |
223 | ||
224 | // public methods | |
225 | ||
226 | void AliModulesComposition::SwitchDetOn(G4String moduleNameVer) | |
227 | { | |
228 | // Switchs on module specified by name and version. | |
229 | // --- | |
230 | ||
231 | G4int nofDets = fDetSwitchVector.entries(); | |
232 | if (moduleNameVer == "ALL") { | |
55ebdd9f | 233 | for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnDefault(); |
234 | } | |
235 | else if (moduleNameVer == "PPR") { | |
236 | for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnPPR(); | |
237 | AliFiles::Instance()->SetMacroName("ConfigPPR"); | |
676fb573 | 238 | } |
239 | else if (moduleNameVer == "NONE") { | |
240 | for (G4int id=0; id<nofDets; id++) | |
241 | fDetSwitchVector[id]->SwitchOff(); | |
242 | } | |
243 | else { | |
244 | // get version number | |
245 | G4int len = moduleNameVer.length(); | |
246 | G4String moduleName = moduleNameVer(0, len-1); | |
247 | G4String version = moduleNameVer(len-1, 1); | |
248 | G4int iVersion = AliGlobals::StringToInt(version); | |
249 | ||
250 | if (iVersion < 0) { | |
251 | // in case the version number is not provided | |
252 | // the default one is set | |
253 | SwitchDetOnDefault(moduleNameVer); | |
254 | } | |
255 | else | |
256 | SwitchDetOn(moduleName, iVersion); | |
257 | } | |
258 | } | |
259 | ||
260 | void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version) | |
261 | { | |
262 | // Switchs on module specified by name and version. | |
263 | // --- | |
264 | ||
265 | G4int nofDets = fDetSwitchVector.entries(); | |
266 | for (G4int id=0; id<nofDets; id++) { | |
267 | G4String iDetName = fDetSwitchVector[id]->GetDetName(); | |
268 | if (iDetName == moduleName) { | |
269 | fDetSwitchVector[id]->SwitchOn(version); | |
270 | return; | |
271 | } | |
272 | } | |
273 | AliGlobals::Exception( | |
274 | "AliModulesComposition: Wrong detector name for " + moduleName + "."); | |
275 | } | |
276 | ||
277 | void AliModulesComposition::SwitchDetOnDefault(G4String moduleName) | |
278 | { | |
279 | // Switchs on module specified by name with default version. | |
280 | // --- | |
281 | ||
282 | G4int nofDets = fDetSwitchVector.entries(); | |
283 | for (G4int id=0; id<nofDets; id++) { | |
284 | G4String iDetName = fDetSwitchVector[id]->GetDetName(); | |
285 | if (iDetName == moduleName) { | |
286 | fDetSwitchVector[id]->SwitchOnDefault(); | |
287 | return; | |
288 | } | |
289 | } | |
290 | AliGlobals::Exception( | |
291 | "AliModulesComposition: Wrong detector name for " + moduleName + "."); | |
292 | } | |
293 | ||
55ebdd9f | 294 | void AliModulesComposition::SwitchDetOnPPR(G4String moduleName) |
295 | { | |
296 | // Switchs on module specified by name with PPR version. | |
297 | // --- | |
298 | ||
299 | G4int nofDets = fDetSwitchVector.entries(); | |
300 | for (G4int id=0; id<nofDets; id++) { | |
301 | G4String iDetName = fDetSwitchVector[id]->GetDetName(); | |
302 | if (iDetName == moduleName) { | |
303 | fDetSwitchVector[id]->SwitchOnPPR(); | |
304 | return; | |
305 | } | |
306 | } | |
307 | AliGlobals::Exception( | |
308 | "AliModulesComposition: Wrong detector name for " + moduleName + "."); | |
309 | } | |
310 | ||
676fb573 | 311 | void AliModulesComposition::SwitchDetOff(G4String moduleName) |
312 | { | |
313 | // Switchs off module specified by name. | |
314 | // --- | |
315 | ||
316 | G4int nofDets = fDetSwitchVector.entries(); | |
317 | if (moduleName == "ALL") { | |
318 | for (G4int id=0; id<nofDets; id++) | |
319 | fDetSwitchVector[id]->SwitchOff(); | |
320 | } | |
321 | else { | |
322 | for (G4int id=0; id<nofDets; id++) { | |
323 | G4String iDetName = fDetSwitchVector[id]->GetDetName(); | |
324 | if (iDetName == moduleName) { | |
325 | fDetSwitchVector[id]->SwitchOff(); | |
326 | return; | |
327 | } | |
328 | } | |
329 | } | |
330 | AliGlobals::Exception( | |
331 | "AliModulesComposition: Wrong detector name for " + moduleName + "."); | |
332 | } | |
333 | ||
334 | void AliModulesComposition::PrintSwitchedDets() const | |
335 | { | |
336 | // Lists switched detectors. | |
337 | // --- | |
338 | ||
339 | G4String svList = GetSwitchedDetsList(); | |
340 | ||
ba6f5bec | 341 | G4cout << "Switched Alice detectors: " << G4endl; |
342 | G4cout << "--------------------------" << G4endl; | |
343 | G4cout << svList << G4endl; | |
676fb573 | 344 | } |
345 | ||
346 | void AliModulesComposition::PrintAvailableDets() const | |
347 | { | |
348 | // Lists available detectors. | |
349 | // --- | |
350 | ||
351 | G4String avList = GetAvailableDetsList(); | |
352 | ||
ba6f5bec | 353 | G4cout << "Available Alice detectors: " << G4endl; |
354 | G4cout << "---------------------------" << G4endl; | |
355 | G4cout << avList << G4endl; | |
676fb573 | 356 | } |
357 | ||
7b34522f | 358 | void AliModulesComposition::PrintMaterials() const |
359 | { | |
360 | // Prints all materials. | |
361 | // --- | |
362 | ||
363 | const G4MaterialTable* matTable = G4Material::GetMaterialTable(); | |
364 | G4cout << *matTable; | |
365 | } | |
366 | ||
367 | void AliModulesComposition::GenerateXMLGeometry() const | |
368 | { | |
369 | // Generates XML geometry file from the top volume. | |
370 | // The file name is set according the last switched detector | |
371 | // registered in the det switch vector. | |
372 | // --- | |
373 | ||
374 | G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld(); | |
375 | ||
55ebdd9f | 376 | // XML filename |
377 | // according to last switched detector | |
7b34522f | 378 | G4String detName; |
55ebdd9f | 379 | G4int version; |
7b34522f | 380 | for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) { |
55ebdd9f | 381 | version = fDetSwitchVector[i]->GetSwitchedVersion(); |
382 | if (version > -1) { | |
7b34522f | 383 | detName = fDetSwitchVector[i]->GetDetName(); |
7b34522f | 384 | break; |
385 | } | |
386 | } | |
55ebdd9f | 387 | G4String filePath |
388 | = AliFiles::Instance()->GetXMLFilePath(detName, version); | |
7b34522f | 389 | |
390 | // set top volume name | |
391 | G4String topName = world->GetName() + "_comp"; | |
392 | ||
393 | // generate XML | |
394 | ||
395 | TG4XMLGeometryGenerator xml; | |
396 | xml.OpenFile(filePath); | |
397 | ||
398 | // generate materials | |
399 | // not yet implemented | |
400 | // xml.GenerateMaterials(version, "today", "Generated from G4", | |
401 | // "v4", world->GetLogicalVolume()); | |
402 | ||
403 | // generate volumes tree | |
404 | xml.GenerateSection(detName, version, "today", "Generated from Geant4", | |
405 | topName, world->GetLogicalVolume()); | |
406 | xml.CloseFile(); | |
407 | ||
408 | // set verbose | |
55ebdd9f | 409 | G4cout << "File " << detName << "v" << version << ".xml has been generated." |
7b34522f | 410 | << G4endl; |
411 | } | |
412 | ||
413 | ||
676fb573 | 414 | G4String AliModulesComposition::GetSwitchedDetsList() const |
415 | { | |
416 | // Returns list of switched detectors. | |
417 | // --- | |
418 | ||
419 | G4String svList = ""; | |
420 | ||
421 | G4int nofDets = fDetSwitchVector.entries(); | |
422 | G4int nofSwitchedDets = 0; | |
423 | for (G4int id=0; id<nofDets; id++) { | |
424 | G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion(); | |
425 | if (iVersion > -1) { | |
426 | nofSwitchedDets++; | |
427 | G4String moduleNameVer = fDetSwitchVector[id]->GetDetName(); | |
428 | AliGlobals::AppendNumberToString(moduleNameVer, iVersion); | |
429 | svList += moduleNameVer; | |
430 | svList += " "; | |
431 | } | |
432 | } | |
433 | ||
434 | if (nofSwitchedDets == nofDets) svList = "ALL: " + svList; | |
435 | if (nofSwitchedDets == 0) svList = "NONE"; | |
436 | ||
437 | return svList; | |
438 | } | |
439 | ||
440 | const G4RWTPtrOrderedVector<AliDetSwitch>& | |
441 | AliModulesComposition::GetDetSwitchVector() const | |
442 | { | |
443 | // Returns detSwitch vector. | |
444 | // --- | |
445 | ||
446 | //const AliDetSwitchVector& vector = fDetSwitchVector; | |
447 | const G4RWTPtrOrderedVector<AliDetSwitch>& vector = fDetSwitchVector; | |
448 | return vector; | |
449 | } | |
450 | ||
451 | G4String AliModulesComposition::GetAvailableDetsList() const | |
452 | { | |
453 | // Returns list of available detectors. | |
454 | // --- | |
455 | ||
456 | G4String svList = ""; | |
457 | ||
458 | G4int nofDets = fDetSwitchVector.entries(); | |
459 | for (G4int id=0; id<nofDets; id++) { | |
460 | G4int nofVersions = fDetSwitchVector[id]->GetNofVersions(); | |
461 | for (G4int iv=0; iv<nofVersions; iv++) { | |
462 | G4String moduleNameVer = fDetSwitchVector[id]->GetDetName(); | |
463 | AliGlobals::AppendNumberToString(moduleNameVer, iv); | |
464 | svList += moduleNameVer; | |
465 | svList += " "; | |
466 | } | |
467 | } | |
468 | ||
469 | return svList; | |
470 | } | |
471 | ||
472 | G4String AliModulesComposition::GetAvailableDetsListWithCommas() const | |
473 | { | |
474 | // Returns list of available detectors with commas. | |
475 | // --- | |
476 | ||
477 | G4String svList = ""; | |
478 | ||
479 | G4int nofDets = fDetSwitchVector.entries(); | |
480 | for (G4int id=0; id<nofDets; id++) { | |
481 | G4int nofVersions = fDetSwitchVector[id]->GetNofVersions(); | |
482 | for (G4int iv=0; iv<nofVersions; iv++) { | |
483 | G4String moduleNameVer = fDetSwitchVector[id]->GetDetName(); | |
484 | AliGlobals::AppendNumberToString(moduleNameVer, iv); | |
485 | svList += moduleNameVer; | |
486 | if (iv<nofVersions-1) svList += "/"; | |
487 | else if (id < nofDets-1) svList += ", "; | |
488 | } | |
489 | } | |
490 | ||
491 | return svList; | |
492 | } | |
493 | ||
494 | G4String AliModulesComposition::GetDetNamesList() const | |
495 | { | |
496 | // Returns list of detector names. | |
497 | // --- | |
498 | ||
499 | G4String svList = ""; | |
500 | ||
501 | G4int nofDets = fDetSwitchVector.entries(); | |
502 | for (G4int id=0; id<nofDets; id++) { | |
503 | svList += fDetSwitchVector[id]->GetDetName(); | |
504 | svList += " "; | |
505 | } | |
506 | ||
507 | return svList; | |
508 | } | |
509 | ||
510 | G4String AliModulesComposition::GetDetNamesListWithCommas() const | |
511 | { | |
512 | // Returns list of detector names with commas. | |
513 | // --- | |
514 | ||
515 | G4String svList = ""; | |
516 | ||
517 | G4int nofDets = fDetSwitchVector.entries(); | |
518 | for (G4int id=0; id<nofDets; id++) { | |
519 | svList += fDetSwitchVector[id]->GetDetName(); | |
520 | if (id < nofDets-1) svList += ", "; | |
521 | } | |
522 | ||
523 | return svList; | |
524 | } | |
525 | ||
526 | void AliModulesComposition::SetMagField(G4double fieldValue) | |
527 | { | |
528 | // Sets uniform magnetic field to specified value. | |
529 | // --- | |
9b0f6db2 | 530 | |
531 | // create fields if it does not exist | |
532 | if (!fMagneticField) fMagneticField = new AliMagneticField(); | |
533 | ||
534 | // set value | |
535 | fMagneticField->SetFieldValue(fieldValue); | |
676fb573 | 536 | } |
537 |