]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliMoreModulesConstruction.cxx
Rewriting and cleaning up
[u/mrichter/AliRoot.git] / AliGeant4 / AliMoreModulesConstruction.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliMoreModulesConstruction
7 // --------------------------------
8 // See the class description in the header file.
9
10 #include "AliMoreModulesConstruction.h"
11 #include "AliSingleModuleConstruction.h"
12 #include "AliModule.h"
13 #include "AliGlobals.h"
14 #include "AliFiles.h"
15
16 #include "TG4GeometryManager.h"
17
18 #include <G4LogicalVolume.hh>
19 #include <G4LogicalVolumeStore.hh>
20
21 //_____________________________________________________________________________
22 AliMoreModulesConstruction::AliMoreModulesConstruction() {
23 //
24 }
25
26 //_____________________________________________________________________________
27 AliMoreModulesConstruction::AliMoreModulesConstruction(
28                                const AliMoreModulesConstruction& right)
29 {
30   // copy stuff
31   *this = right;
32 }  
33                                
34
35 //_____________________________________________________________________________
36 AliMoreModulesConstruction::~AliMoreModulesConstruction()
37 {
38   // delete module constructions
39   fModuleConstructionVector.erase(
40     fModuleConstructionVector.begin(), fModuleConstructionVector.end());
41 }
42
43 // operators
44
45 //_____________________________________________________________________________
46 AliMoreModulesConstruction& 
47 AliMoreModulesConstruction::operator=(const AliMoreModulesConstruction& right)
48 {
49   // check assignement to self
50   if (this == &right) return *this;
51
52   // delete current module constructions
53   fModuleConstructionVector.erase(
54     fModuleConstructionVector.begin(), fModuleConstructionVector.end());
55     
56   // create new module constructions   
57   G4int nofModules = right.fModuleConstructionVector.size();
58   for (G4int i=0; i<nofModules; i++) {
59     G4String name = right.fModuleConstructionVector[i]->GetDetName();
60     G4int version = right.fModuleConstructionVector[i]->GetVersion();
61     AliModuleType type = right.fModuleConstructionVector[i]->GetType();
62     AddModule(name, version, type);
63   }  
64
65   return *this;  
66 }    
67           
68 // public methods
69
70 //_____________________________________________________________________________
71 void AliMoreModulesConstruction::AddModule(G4String moduleName, G4int version,
72                                            AliModuleType moduleType)
73 {                                          
74 // Adds module specified by name, version and type.
75 // ---
76
77   // create module construction
78   AliSingleModuleConstruction* moduleConstruction 
79     = new AliSingleModuleConstruction(moduleName, version, moduleType);
80
81   // add module, module construction to vectors
82   fModuleConstructionVector.push_back(moduleConstruction);
83 }  
84                                            
85 //_____________________________________________________________________________
86 void AliMoreModulesConstruction::Configure(const AliFiles& files)
87
88 // Executes the detectors setup Root macros
89 // (extracted from AliRoot Config.C) and
90 // G4 macros.
91 // ---
92   
93   // number of modules
94   G4int nofModules = fModuleConstructionVector.size();
95
96   if (nofModules == 0) {
97     AliGlobals::Warning(
98       "AliMoreModulesConstruction::Construct(): No modules are defined.");
99   }
100   else 
101     for (G4int i=0; i<nofModules; i++) 
102       fModuleConstructionVector[i]->Configure(files);
103 }      
104
105 //_____________________________________________________________________________
106 void AliMoreModulesConstruction::Construct()
107
108 // Constructs geometry.
109 // G3 tables are process for all modules alltogether.
110 // --
111
112   // number of modules
113   G4int nofModules = fModuleConstructionVector.size();
114
115   if (nofModules == 0) {
116     AliGlobals::Warning(
117       "AliMoreModulesConstruction::Construct(): No modules are defined.");
118   }
119   else {      
120     // get geometry manager
121     TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
122
123     G4int i;
124     for (i=0; i<nofModules; i++) {
125
126       // fModuleConstructionVector[i]->Configure(files);
127     
128       // register module name in the name map
129       AliModule* module = fModuleConstructionVector[i]->GetAliModule();
130       pGeometryManager->SetMapSecond(module->GetName());        
131
132       G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry();
133       G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry();
134       G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath();
135
136       if (readGeometry) {
137         // TG4GeometryManager uses g3tog4 methods for reading
138         // g3calls.dat files - as these methods do not fill name map
139         // they cannot be used for constructing more modules
140         // together
141         //
142         // pGeometryManager->SetWriteGeometry(false);
143         // pGeometryManager->ReadG3Geometry(dataFilePath);
144         
145         G4String text = "AliMoreModulesConstruction::Construct - Limitation:\n";
146         text = text + "    Reading g3calls.dat is not implemented.";
147         AliGlobals::Exception(text);
148       }
149       else {                
150         // set geometry output stream for this module
151         pGeometryManager->SetWriteGeometry(writeGeometry);
152         if (writeGeometry) 
153           pGeometryManager->OpenOutFile(dataFilePath);
154         
155         // create geometry from AliRoot
156       
157         // construct materials
158         module->CreateMaterials();   
159
160         // construct G3 geometry
161         module->CreateGeometry();
162         
163         if (writeGeometry) 
164           pGeometryManager->CloseOutFile();
165       } 
166     }  
167   
168     // construct G4 geometry
169     pGeometryManager->CreateG4Geometry();
170
171     // print name map
172     // pGeometryManager->PrintNameMap();
173
174     for (i=0; i<nofModules; i++) {
175       // set the detector frame (envelope)
176       // (without warning output if enevelope is not defined)
177       fModuleConstructionVector[i]->SetDetFrame(false);
178
179       // construct geometry for display
180       fModuleConstructionVector[i]->GetAliModule()->BuildGeometry();
181     }
182
183     // reset TG4GeometryManager 
184     pGeometryManager->ClearG3Tables();
185
186 #ifdef ALICE_VISUALIZE
187     // set visualization attributes
188     for (i=0; i<nofModules; i++) {
189       if (fModuleConstructionVector[i]->GetDetFrame()) {
190         fModuleConstructionVector[i]->SetDetVisibility(true);
191         fModuleConstructionVector[i]->SetDetColour("Yellow");
192       }
193     }  
194 #endif
195   }
196 }