]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliSingleModuleConstruction.cxx
Updated class description: added class title, author;
[u/mrichter/AliRoot.git] / AliGeant4 / AliSingleModuleConstruction.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // See the class description in the header file.
5
6 #include "AliSingleModuleConstruction.h"
7 #include "AliGlobals.h"
8 #include "AliFiles.h"
9 #include "AliRun.h"
10 #include "AliModule.h"
11
12 #include "TG4GeometryManager.h"
13
14 #include <G4UImanager.hh>
15 //#include <G4Element.hh>
16
17 #include <TROOT.h> 
18 #include <TCint.h> 
19
20 G4VPhysicalVolume* AliSingleModuleConstruction::fgWorld = 0;
21
22 //_____________________________________________________________________________
23 AliSingleModuleConstruction::AliSingleModuleConstruction(
24                                 G4String moduleName, G4int version,
25                                 AliModuleType moduleType)
26   : AliModuleConstruction(moduleName),
27     fVersion(version),
28     fType(moduleType),
29     fProcessConfig(true)
30 {
31 //
32 }
33
34 //_____________________________________________________________________________
35 AliSingleModuleConstruction::AliSingleModuleConstruction(
36                                 const AliSingleModuleConstruction& right)
37   : AliModuleConstruction(right)                                
38 {
39 //
40   // copy stuff
41   *this = right;
42 }
43
44 //_____________________________________________________________________________
45 AliSingleModuleConstruction::AliSingleModuleConstruction() {
46 //
47 }
48
49 //_____________________________________________________________________________
50 AliSingleModuleConstruction::~AliSingleModuleConstruction() {
51 //
52 }
53
54 // operators
55
56 //_____________________________________________________________________________
57 AliSingleModuleConstruction& 
58 AliSingleModuleConstruction::operator=(const AliSingleModuleConstruction& right)
59 {    
60   // check assignement to self
61   if (this == &right) return *this;
62   
63   // base class assignement
64   AliModuleConstruction::operator=(right);
65   
66   fVersion = right.fVersion;
67   fType = right.fType;
68   fProcessConfig = right.fProcessConfig;
69  
70   return *this;
71 }
72
73 // public methods 
74
75 //_____________________________________________________________________________
76 void AliSingleModuleConstruction::Configure(const AliFiles& files)
77
78 // Executes the detector setup Root macro
79 // (extracted from AliRoot Config.C) and
80 // G4 macro.
81 // ---
82
83   // filepaths and macro names 
84   G4bool isStructure = (fType == kStructure);
85   G4String rootFilePath 
86     = files.GetRootMacroPath(fModuleName, isStructure);
87   G4String g4FilePath
88     = files.GetG4MacroPath(fModuleName, isStructure);
89   fDataFilePath 
90     = files.GetG3CallsDatPath(fModuleName, fVersion, isStructure); 
91   
92   // load and execute aliroot config macro
93   if (fProcessConfig) {
94     gROOT->LoadMacro(rootFilePath);
95     G4String macroName = files.GetDefaultMacroName();
96     //macroName = macroName + "_" + fModuleName;
97     macroName = macroName + "(";
98     AliGlobals::AppendNumberToString(macroName, fVersion);
99     macroName = macroName + ")";
100     gInterpreter->ProcessLine(macroName);
101   } 
102   
103   // process g4 config macro
104   G4String command = "/control/execute ";
105   G4UImanager* pUI = G4UImanager::GetUIpointer();  
106   pUI->ApplyCommand(command + g4FilePath);
107   
108   // get AliModule created in Config.C macro
109   fAliModule = gAlice->GetModule(fModuleName);
110   if (!fAliModule) {
111     G4String text = "AliSingleModuleConstruction::Configure:\n";
112     text = text + "    AliModule " + fModuleName;
113     text = text + " has not been found in gAlice.";
114     AliGlobals::Exception(text);
115   }  
116 }
117
118 //_____________________________________________________________________________
119 void AliSingleModuleConstruction::Construct()
120
121 // Constructs geometry.
122 // ---
123
124   // print default element table
125   // const G4ElementTable* table = G4Element::GetElementTable();
126   // G4cout << "Default elemnt table: " << G4endl;
127   // for (G4int i=0; i<table->entries(); i++) {
128   //   G4cout << *(*table)[i] << G4endl;
129   // }  
130
131   // Configure();
132
133   // get geometry manager
134   TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
135
136   // register module name in the name map
137   pGeometryManager->SetMapSecond(fAliModule->GetName());        
138
139   if (fReadGeometry) {
140     // create G3 geometry from g3calls.dat
141     pGeometryManager->SetWriteGeometry(false);
142     pGeometryManager->ReadG3Geometry(fDataFilePath);
143   }
144   else {
145     // set geometry output stream for this module
146     pGeometryManager->SetWriteGeometry(fWriteGeometry);
147     if (fWriteGeometry) 
148       pGeometryManager->OpenOutFile(fDataFilePath);
149
150     // create geometry from AliRoot
151
152     // construct materials
153     fAliModule->CreateMaterials();
154
155     // construct G3 geometry
156     fAliModule->CreateGeometry();
157         
158     if (fWriteGeometry) 
159       pGeometryManager->CloseOutFile();
160   }  
161   
162   // construct G4 geometry
163   G4VPhysicalVolume* world = pGeometryManager->CreateG4Geometry();
164   if (!fgWorld) fgWorld = world; 
165   
166   // set the detector frame (envelope)
167   // (without warning output if enevelope is not defined)
168   SetDetFrame(false);
169
170   // construct geometry for display
171   fAliModule->BuildGeometry();
172
173   // reset TG4GeometryManager 
174   pGeometryManager->ClearG3Tables();
175
176 #ifdef ALICE_VISUALIZE
177   if (GetDetFrame()) {
178     // set visualization attributes
179     // if detector envelope is defined
180     SetDetVisibility(true);
181     SetDetColour("Yellow");
182   }  
183 #endif
184 }