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