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