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