]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliModulesComposition.cxx
Incorporated latest changes in AliLevel3 class.
[u/mrichter/AliRoot.git] / AliGeant4 / AliModulesComposition.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliModulesComposition
7 // ---------------------------
8 // See the class description in the header file.
9
10 #include "AliModulesComposition.h"
11 #include "AliModuleConstruction.h"
12 #include "AliMagneticField.h"
13 #include "AliGlobals.h"
14 #include "AliFiles.h"
15 #include "AliModule.h"
16
17 #include "TG4GeometryManager.h"
18
19 #include <G4Material.hh>
20
21 //_____________________________________________________________________________
22 AliModulesComposition::AliModulesComposition()
23   : AliVerbose("modulesComposition"),
24     fReadGeometry(false),
25     fWriteGeometry(false),
26     fMagneticField(0),
27     fMessenger(this) {
28 //
29 }
30
31 //_____________________________________________________________________________
32 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
33   : AliVerbose("modulesComposition"),
34     fMessenger(this)
35 {
36 //
37   AliGlobals::Exception("AliModulesComposition is protected from copying.");  
38 }
39
40 //_____________________________________________________________________________
41 AliModulesComposition::~AliModulesComposition() {
42 //   
43   delete fMagneticField;
44 }
45
46 // operators
47
48 //_____________________________________________________________________________
49 AliModulesComposition& 
50 AliModulesComposition::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 //
61 // private methods
62 //
63
64 //_____________________________________________________________________________
65 void AliModulesComposition::Configure()
66
67 // Executes the detectors setup Root macros
68 // (extracted from AliRoot Config.C) and
69 // G4 macros.
70 // ---
71   
72   // number of modules
73   G4int nofModules = fModuleConstructionVector.size();
74
75   if (nofModules == 0) {
76     AliGlobals::Warning(
77       "AliModulesComposition::Configure: No modules are defined.");
78     return;  
79   }
80   
81   for (G4int i=0; i<nofModules; i++) 
82     fModuleConstructionVector[i]->Configure();
83 }      
84
85
86 //_____________________________________________________________________________
87 void AliModulesComposition::CreateG4Geometry()
88
89 // Constructs geometry.
90 // G3 tables are process for all modules alltogether.
91 // --
92
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);
109   
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     }   
148   }  
149   
150   // construct G4 geometry
151   pGeometryManager->CreateG4Geometry();
152
153   // print name map
154   // pGeometryManager->PrintNameMap();
155
156 /*
157   // moved to AliSDConstruction
158   // to be performed after Init  (required for MUON)
159   
160   for (i=0; i<nofModules; i++) {
161
162     // construct geometry for display
163     fModuleConstructionVector[i]->GetAliModule()->BuildGeometry();
164   }
165 */
166
167   // reset TG4GeometryManager 
168   pGeometryManager->ClearG3Tables();
169 }
170
171 //_____________________________________________________________________________
172 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
173 {
174 // Sets readGeometry control to all modules.
175 // ---
176
177   for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
178     fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
179 }    
180   
181 //_____________________________________________________________________________
182 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
183 {
184 // Sets writeGeometry control to all modules.
185 // ---
186
187   for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
188     fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
189 }    
190
191 //
192 // protected methods
193 //
194
195 //_____________________________________________________________________________
196 void AliModulesComposition::AddModule(const G4String& name, 
197                                       G4int version, 
198                                       AliModuleType moduleType)
199 {
200 // Adds module to the module construction vector.
201 // ---
202
203   AliModuleConstruction* moduleConstruction 
204     = new AliModuleConstruction(name, version, moduleType);
205
206   fModuleConstructionVector.push_back(moduleConstruction);
207 }  
208                                   
209 //_____________________________________________________________________________
210 void AliModulesComposition::ConstructModules()
211 {
212 // Construct geometry of all modules (both standalone and dependent.)
213 // ---
214
215   // set common options
216   SetReadGeometryToModules(fReadGeometry);
217   SetWriteGeometryToModules(fWriteGeometry);
218   
219   // configure modules
220   Configure();
221
222   // construct dependent modules
223   CreateG4Geometry();
224 }  
225
226 //_____________________________________________________________________________
227 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
228 {
229 // Sets processConfig control to all modules.
230 // ---
231
232   for (G4int i=0; i<fModuleConstructionVector.size(); i++) 
233     fModuleConstructionVector[i]->SetProcessConfig(processConfig);
234 }    
235
236 //
237 // public methods
238 //
239
240 //_____________________________________________________________________________
241 void AliModulesComposition::PrintMaterials() const
242 {
243 // Prints all materials.
244 // ---
245
246   const G4MaterialTable* matTable = G4Material::GetMaterialTable();
247   G4cout << *matTable;
248 }
249
250 //_____________________________________________________________________________
251 void AliModulesComposition::SetMagField(G4double fieldValue)
252 {
253 // Sets uniform magnetic field to specified value.
254 // ---
255
256   // create fields if it does not exist
257   if (!fMagneticField) fMagneticField = new AliMagneticField();
258   
259   // set value
260   fMagneticField->SetFieldValue(fieldValue);
261 }
262