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