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