]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliSingleModuleConstruction.cxx
Ali/Lego/SensitiveDetector, AliSingle/MoreModulesConstruction update, AliSDManager...
[u/mrichter/AliRoot.git] / AliGeant4 / AliSingleModuleConstruction.cxx
CommitLineData
676fb573 1// $Id$
2// Category: geometry
3//
4// See the class description in the header file.
5
6#include "AliSingleModuleConstruction.h"
676fb573 7#include "AliGlobals.h"
8#include "AliFiles.h"
9#include "AliRun.h"
c97337f9 10#include "AliModule.h"
676fb573 11
12#include "TG4GeometryManager.h"
13
676fb573 14#include <G4UImanager.hh>
15//#include <G4Element.hh>
676fb573 16
17#include <TROOT.h>
18#include <TCint.h>
19
20G4VPhysicalVolume* AliSingleModuleConstruction::fgWorld = 0;
21
40c61242 22//_____________________________________________________________________________
676fb573 23AliSingleModuleConstruction::AliSingleModuleConstruction(
24 G4String moduleName, G4int version,
25 AliModuleType moduleType)
26 : AliModuleConstruction(moduleName),
27 fVersion(version),
28 fType(moduleType),
40c61242 29 fProcessConfig(true)
676fb573 30{
31//
676fb573 32}
33
40c61242 34//_____________________________________________________________________________
676fb573 35AliSingleModuleConstruction::AliSingleModuleConstruction(
36 const AliSingleModuleConstruction& right)
37 : AliModuleConstruction(right)
38{
39//
58c0119e 40 // copy stuff
41 *this = right;
676fb573 42}
43
40c61242 44//_____________________________________________________________________________
676fb573 45AliSingleModuleConstruction::AliSingleModuleConstruction() {
46//
47}
48
40c61242 49//_____________________________________________________________________________
676fb573 50AliSingleModuleConstruction::~AliSingleModuleConstruction() {
51//
676fb573 52}
53
54// operators
55
40c61242 56//_____________________________________________________________________________
676fb573 57AliSingleModuleConstruction&
58AliSingleModuleConstruction::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;
58c0119e 69
676fb573 70 return *this;
71}
72
676fb573 73// public methods
74
40c61242 75//_____________________________________________________________________________
869f65a5 76void AliSingleModuleConstruction::Configure(const AliFiles& files)
676fb573 77{
78// Executes the detector setup Root macro
79// (extracted from AliRoot Config.C) and
80// G4 macro.
81// ---
40c61242 82
676fb573 83 // filepaths and macro names
869f65a5 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);
676fb573 91
869f65a5 92 // load and execute aliroot config macro
676fb573 93 if (fProcessConfig) {
676fb573 94 gROOT->LoadMacro(rootFilePath);
869f65a5 95 G4String macroName = files.GetDefaultMacroName();
58c0119e 96 //macroName = macroName + "_" + fModuleName;
869f65a5 97 macroName = macroName + "(";
676fb573 98 AliGlobals::AppendNumberToString(macroName, fVersion);
869f65a5 99 macroName = macroName + ")";
676fb573 100 gInterpreter->ProcessLine(macroName);
101 }
102
869f65a5 103 // process g4 config macro
676fb573 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
40c61242 118//_____________________________________________________________________________
676fb573 119void AliSingleModuleConstruction::Construct()
120{
121// Constructs geometry.
122// ---
123
124 // print default element table
125 // const G4ElementTable* table = G4Element::GetElementTable();
5f1d09c5 126 // G4cout << "Default elemnt table: " << G4endl;
676fb573 127 // for (G4int i=0; i<table->entries(); i++) {
5f1d09c5 128 // G4cout << *(*table)[i] << G4endl;
676fb573 129 // }
130
04ed0a2e 131 // Configure();
676fb573 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();
1bf18a99 157
158 if (fWriteGeometry)
159 pGeometryManager->CloseOutFile();
676fb573 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
e88c18bd 170 // construct geometry for display
171 fAliModule->BuildGeometry();
172
676fb573 173 // reset TG4GeometryManager
174 pGeometryManager->ClearG3Tables();
676fb573 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}