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