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