4 // Author: I. Hrivnacova
6 // Class AliModulesComposition
7 // ---------------------------
8 // See the class description in the header file.
10 #include "AliModulesComposition.h"
11 #include "AliModuleConstruction.h"
12 #include "AliGlobals.h"
14 #include "AliModule.h"
16 #include "TG4GeometryManager.h"
17 #include "TG4MagneticField.h"
18 #include "TG4UniformMagneticField.h"
20 #include <G4Material.hh>
22 //_____________________________________________________________________________
23 AliModulesComposition::AliModulesComposition()
24 : AliVerbose("modulesComposition"),
26 fMagneticFieldType(kMCApplicationField),
29 fWriteGeometry(false) {
33 //_____________________________________________________________________________
34 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
35 : AliVerbose("modulesComposition"),
39 AliGlobals::Exception("AliModulesComposition is protected from copying.");
42 //_____________________________________________________________________________
43 AliModulesComposition::~AliModulesComposition() {
45 delete fMagneticField;
50 //_____________________________________________________________________________
51 AliModulesComposition&
52 AliModulesComposition::operator=(const AliModulesComposition& right)
54 // check assignement to self
55 if (this == &right) return *this;
57 AliGlobals::Exception("AliModulesComposition is protected from assigning.");
66 //_____________________________________________________________________________
67 void AliModulesComposition::CreateMagneticField()
69 // Creates standard magnetic field (defined by TVirtualMCApplication).
72 switch (fMagneticFieldType) {
74 case kMCApplicationField:
75 fMagneticField = new TG4MagneticField();
76 G4cout << "kMCApplicationField" << G4endl;
80 fMagneticField = new TG4UniformMagneticField();
81 G4cout << "kUniformField" << G4endl;
85 G4cout << "kNoField" << G4endl;
90 //_____________________________________________________________________________
91 void AliModulesComposition::Configure()
93 // Executes the detectors setup Root macros
94 // (extracted from AliRoot Config.C) and
99 G4int nofModules = fModuleConstructionVector.size();
101 if (nofModules == 0) {
103 "AliModulesComposition::Configure: No modules are defined.");
107 for (G4int i=0; i<nofModules; i++)
108 fModuleConstructionVector[i]->Configure();
112 //_____________________________________________________________________________
113 void AliModulesComposition::CreateG4Geometry()
115 // Constructs geometry.
116 // G3 tables are process for all modules alltogether.
120 G4int nofModules = fModuleConstructionVector.size();
122 if (nofModules == 0) {
124 "AliModulesComposition::CreateG4Geometry: No modules are defined.");
128 // get geometry manager
129 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
132 for (i=0; i<nofModules; i++) {
134 // fModuleConstructionVector[i]->Configure(files);
136 // register module name in the name map
137 AliModule* module = fModuleConstructionVector[i]->GetAliModule();
138 pGeometryManager->SetMapSecond(module->GetName());
140 G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry();
141 G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry();
142 G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath();
145 // TG4GeometryManager uses g3tog4 methods for reading
146 // g3calls.dat files - as these methods do not fill name map
147 // they cannot be used for constructing more modules
150 // pGeometryManager->SetWriteGeometry(false);
151 // pGeometryManager->ReadG3Geometry(dataFilePath);
153 G4String text = "AliModulesComposition::Construct - Limitation:\n";
154 text = text + " Reading g3calls.dat is not implemented.";
155 AliGlobals::Exception(text);
158 // set geometry output stream for this module
159 pGeometryManager->SetWriteGeometry(writeGeometry);
161 pGeometryManager->OpenOutFile(dataFilePath);
163 // create geometry from AliRoot
165 // construct materials
166 module->CreateMaterials();
168 // construct G3 geometry
169 module->CreateGeometry();
172 pGeometryManager->CloseOutFile();
176 // construct G4 geometry
177 pGeometryManager->CreateG4Geometry();
180 // pGeometryManager->PrintNameMap();
183 // moved to AliSDConstruction
184 // to be performed after Init (required for MUON)
186 for (i=0; i<nofModules; i++) {
188 // construct geometry for display
189 fModuleConstructionVector[i]->GetAliModule()->BuildGeometry();
193 // reset TG4GeometryManager
194 pGeometryManager->ClearG3Tables();
197 //_____________________________________________________________________________
198 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
200 // Sets readGeometry control to all modules.
203 for (G4int i=0; i<G4int(fModuleConstructionVector.size()); i++)
204 fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
207 //_____________________________________________________________________________
208 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
210 // Sets writeGeometry control to all modules.
213 for (G4int i=0; i<G4int(fModuleConstructionVector.size()); i++)
214 fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
221 //_____________________________________________________________________________
222 void AliModulesComposition::AddModule(const G4String& name,
224 AliModuleType moduleType)
226 // Adds module to the module construction vector.
229 AliModuleConstruction* moduleConstruction
230 = new AliModuleConstruction(name, version, moduleType);
232 fModuleConstructionVector.push_back(moduleConstruction);
235 //_____________________________________________________________________________
236 void AliModulesComposition::ConstructModules()
238 // Construct geometry of all modules (both standalone and dependent.)
241 // create magnetic field
242 CreateMagneticField();
244 // set common options
245 SetReadGeometryToModules(fReadGeometry);
246 SetWriteGeometryToModules(fWriteGeometry);
251 // construct dependent modules
255 //_____________________________________________________________________________
256 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
258 // Sets processConfig control to all modules.
261 for (G4int i=0; i<G4int(fModuleConstructionVector.size()); i++)
262 fModuleConstructionVector[i]->SetProcessConfig(processConfig);
269 //_____________________________________________________________________________
270 void AliModulesComposition::PrintMaterials() const
272 // Prints all materials.
275 const G4MaterialTable* matTable = G4Material::GetMaterialTable();
280 //_____________________________________________________________________________
281 void AliModulesComposition::SetFieldType(TG4MagneticFieldType fieldType)
283 // Selects from available magnetic field types:
284 // field defined by TVirtualMCApplication, uniform magnetic field
285 // or no magnetic field.
286 // Applicable only when no field has been yet created (PreInit).
289 if (fMagneticField) {
290 G4String text = "AliModulesComposition::SetFieldType :\n";
291 text = text + " The magnetic field already exists.";
292 text = text + " Selection was ignored.";
293 AliGlobals::Warning(text);
296 fMagneticFieldType = fieldType;
299 //_____________________________________________________________________________
300 void AliModulesComposition::SetUniformFieldValue(G4double fieldValue)
302 // Sets uniform magnetic field to specified value.
305 if (!fMagneticField) {
306 G4String text = "AliModulesComposition::SetUniformMagField: \n";
307 text = text + " Magnetic field is not defined.";
308 AliGlobals::Exception(text);
312 TG4UniformMagneticField* uniformField
313 =dynamic_cast<TG4UniformMagneticField*>(fMagneticField);
316 G4String text = "AliModulesComposition::SetUniformMagField: \n";
317 text = text + " Defined magnetic field is not uniform.";
318 AliGlobals::Exception(text);
322 uniformField->SetFieldValue(fieldValue);