]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliModulesComposition.cxx
Smaller changes
[u/mrichter/AliRoot.git] / AliGeant4 / AliModulesComposition.cxx
CommitLineData
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"
80ed9a99 11#include "AliModuleConstruction.h"
676fb573 12#include "AliMagneticField.h"
13#include "AliGlobals.h"
55ebdd9f 14#include "AliFiles.h"
80ed9a99 15#include "AliModule.h"
676fb573 16
93debb41 17#include "TG4GeometryManager.h"
7b34522f 18
7b34522f 19#include <G4Material.hh>
676fb573 20
93debb41 21//_____________________________________________________________________________
676fb573 22AliModulesComposition::AliModulesComposition()
e980662a 23 : AliVerbose("modulesComposition"),
24 fReadGeometry(false),
9b0f6db2 25 fWriteGeometry(false),
ad42298e 26 fMagneticField(0),
80ed9a99 27 fMessenger(this) {
676fb573 28//
676fb573 29}
30
93debb41 31//_____________________________________________________________________________
676fb573 32AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
e980662a 33 : AliVerbose("modulesComposition"),
34 fMessenger(this)
676fb573 35{
36//
37 AliGlobals::Exception("AliModulesComposition is protected from copying.");
38}
39
93debb41 40//_____________________________________________________________________________
676fb573 41AliModulesComposition::~AliModulesComposition() {
42//
676fb573 43 delete fMagneticField;
676fb573 44}
45
46// operators
47
93debb41 48//_____________________________________________________________________________
676fb573 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
80ed9a99 60//
61// private methods
62//
676fb573 63
93debb41 64//_____________________________________________________________________________
80ed9a99 65void AliModulesComposition::Configure()
66{
67// Executes the detectors setup Root macros
68// (extracted from AliRoot Config.C) and
69// G4 macros.
676fb573 70// ---
80ed9a99 71
72 // number of modules
73 G4int nofModules = fModuleConstructionVector.size();
676fb573 74
80ed9a99 75 if (nofModules == 0) {
76 AliGlobals::Warning(
77 "AliModulesComposition::Configure: No modules are defined.");
78 return;
79 }
676fb573 80
80ed9a99 81 for (G4int i=0; i<nofModules; i++)
82 fModuleConstructionVector[i]->Configure();
83}
676fb573 84
676fb573 85
93debb41 86//_____________________________________________________________________________
80ed9a99 87void AliModulesComposition::CreateG4Geometry()
88{
89// Constructs geometry.
90// G3 tables are process for all modules alltogether.
91// --
676fb573 92
80ed9a99 93 // number of modules
94 G4int nofModules = fModuleConstructionVector.size();
95
96 if (nofModules == 0) {
97 AliGlobals::Warning(
98 "AliModulesComposition::CreateG4Geometry: No modules are defined.");
99 return;
100 }
101
102 // get geometry manager
103 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
104
105 G4int i;
106 for (i=0; i<nofModules; i++) {
107
108 // fModuleConstructionVector[i]->Configure(files);
676fb573 109
80ed9a99 110 // register module name in the name map
111 AliModule* module = fModuleConstructionVector[i]->GetAliModule();
112 pGeometryManager->SetMapSecond(module->GetName());
113
114 G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry();
115 G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry();
116 G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath();
117
118 if (readGeometry) {
119 // TG4GeometryManager uses g3tog4 methods for reading
120 // g3calls.dat files - as these methods do not fill name map
121 // they cannot be used for constructing more modules
122 // together
123 //
124 // pGeometryManager->SetWriteGeometry(false);
125 // pGeometryManager->ReadG3Geometry(dataFilePath);
126
127 G4String text = "AliModulesComposition::Construct - Limitation:\n";
128 text = text + " Reading g3calls.dat is not implemented.";
129 AliGlobals::Exception(text);
130 }
131 else {
132 // set geometry output stream for this module
133 pGeometryManager->SetWriteGeometry(writeGeometry);
134 if (writeGeometry)
135 pGeometryManager->OpenOutFile(dataFilePath);
136
137 // create geometry from AliRoot
138
139 // construct materials
140 module->CreateMaterials();
141
142 // construct G3 geometry
143 module->CreateGeometry();
144
145 if (writeGeometry)
146 pGeometryManager->CloseOutFile();
147 }
676fb573 148 }
80ed9a99 149
150 // construct G4 geometry
151 pGeometryManager->CreateG4Geometry();
676fb573 152
80ed9a99 153 // print name map
154 // pGeometryManager->PrintNameMap();
7fe075c8 155
99cb3453 156/*
157 // moved to AliSDConstruction
158 // to be performed after Init (required for MUON)
159
80ed9a99 160 for (i=0; i<nofModules; i++) {
ad42298e 161
80ed9a99 162 // construct geometry for display
163 fModuleConstructionVector[i]->GetAliModule()->BuildGeometry();
164 }
99cb3453 165*/
80ed9a99 166
167 // reset TG4GeometryManager
168 pGeometryManager->ClearG3Tables();
169}
7fe075c8 170
93debb41 171//_____________________________________________________________________________
676fb573 172void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
173{
174// Sets readGeometry control to all modules.
175// ---
176
80ed9a99 177 for (G4int i=0; i<fModuleConstructionVector.size(); i++)
178 fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
676fb573 179}
180
93debb41 181//_____________________________________________________________________________
676fb573 182void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
183{
184// Sets writeGeometry control to all modules.
185// ---
186
80ed9a99 187 for (G4int i=0; i<fModuleConstructionVector.size(); i++)
188 fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
676fb573 189}
190
80ed9a99 191//
192// protected methods
193//
676fb573 194
93debb41 195//_____________________________________________________________________________
80ed9a99 196void AliModulesComposition::AddModule(const G4String& name,
197 G4int version,
198 AliModuleType moduleType)
199{
200// Adds module to the module construction vector.
676fb573 201// ---
202
80ed9a99 203 AliModuleConstruction* moduleConstruction
204 = new AliModuleConstruction(name, version, moduleType);
676fb573 205
80ed9a99 206 fModuleConstructionVector.push_back(moduleConstruction);
207}
208
93debb41 209//_____________________________________________________________________________
80ed9a99 210void AliModulesComposition::ConstructModules()
211{
212// Construct geometry of all modules (both standalone and dependent.)
676fb573 213// ---
214
80ed9a99 215 // set common options
216 SetReadGeometryToModules(fReadGeometry);
217 SetWriteGeometryToModules(fWriteGeometry);
218
219 // configure modules
220 Configure();
676fb573 221
80ed9a99 222 // construct dependent modules
223 CreateG4Geometry();
224}
676fb573 225
93debb41 226//_____________________________________________________________________________
80ed9a99 227void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
228{
229// Sets processConfig control to all modules.
676fb573 230// ---
231
80ed9a99 232 for (G4int i=0; i<fModuleConstructionVector.size(); i++)
233 fModuleConstructionVector[i]->SetProcessConfig(processConfig);
234}
676fb573 235
80ed9a99 236//
237// public methods
238//
676fb573 239
93debb41 240//_____________________________________________________________________________
7b34522f 241void AliModulesComposition::PrintMaterials() const
242{
243// Prints all materials.
244// ---
245
246 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
247 G4cout << *matTable;
248}
249
93debb41 250//_____________________________________________________________________________
676fb573 251void AliModulesComposition::SetMagField(G4double fieldValue)
252{
253// Sets uniform magnetic field to specified value.
254// ---
9b0f6db2 255
256 // create fields if it does not exist
257 if (!fMagneticField) fMagneticField = new AliMagneticField();
258
259 // set value
260 fMagneticField->SetFieldValue(fieldValue);
676fb573 261}
262