]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliSingleModuleConstruction.cxx
Initial version
[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"
7#include "AliSingleModuleConstructionMessenger.h"
8#include "AliSDManager.h"
676fb573 9#include "AliGlobals.h"
10#include "AliFiles.h"
11#include "AliRun.h"
c97337f9 12#include "AliModule.h"
676fb573 13
14#include "TG4GeometryManager.h"
15
16#include <G3SensVolVector.hh>
676fb573 17#include <G4UImanager.hh>
18//#include <G4Element.hh>
19#include <G4LogicalVolume.hh>
20#include <G4LogicalVolumeStore.hh>
21
22#include <TROOT.h>
23#include <TCint.h>
24
25G4VPhysicalVolume* AliSingleModuleConstruction::fgWorld = 0;
26
27AliSingleModuleConstruction::AliSingleModuleConstruction(
28 G4String moduleName, G4int version,
29 AliModuleType moduleType)
30 : AliModuleConstruction(moduleName),
31 fVersion(version),
32 fType(moduleType),
33 fProcessConfig(true),
34 fAllLVSensitive(false)
35{
36//
37 fSDManager = AliSDManager::Instance();
38
39 moduleName.toLower();
40 fMessenger = new AliSingleModuleConstructionMessenger(this, moduleName);
41}
42
43AliSingleModuleConstruction::AliSingleModuleConstruction(
44 const AliSingleModuleConstruction& right)
45 : AliModuleConstruction(right)
46{
47//
48 fVersion = right.fVersion;
49 fType = right.fType;
50 fProcessConfig = right.fProcessConfig;
51 fAllLVSensitive = right.fAllLVSensitive;
52 fSDManager = right.fSDManager;
53
54 G4String moduleName = right.fModuleName;
55 moduleName.toLower();
56 fMessenger = new AliSingleModuleConstructionMessenger(this, moduleName);
57}
58
59AliSingleModuleConstruction::AliSingleModuleConstruction() {
60//
61}
62
63AliSingleModuleConstruction::~AliSingleModuleConstruction() {
64//
65 delete fMessenger;
66}
67
68// operators
69
70AliSingleModuleConstruction&
71AliSingleModuleConstruction::operator=(const AliSingleModuleConstruction& right)
72{
73 // check assignement to self
74 if (this == &right) return *this;
75
76 // base class assignement
77 AliModuleConstruction::operator=(right);
78
79 fVersion = right.fVersion;
80 fType = right.fType;
81 fProcessConfig = right.fProcessConfig;
82 fAllLVSensitive = right.fAllLVSensitive;
83 fSDManager = right.fSDManager;
84
85 return *this;
86}
87
88// private methods
89
90void AliSingleModuleConstruction::CreateSensitiveDetectors()
91{
92// Creates sensitive detectors.
93// ---
94
95 if (fAllLVSensitive)
96 CreateSensitiveDetectors1();
97 else
98 CreateSensitiveDetectors2();
99
100 // set static number of logical volumes already processed
101 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
102 fSDManager->SetNofLVWithSD(pLVStore->entries());
103}
104
105void AliSingleModuleConstruction::CreateSensitiveDetectors1()
106{
107// Creates sensitive detectors.
108// Sensitive detectors are set to all logical volumes
109// ---
110
111 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
112 G4int nofLV = pLVStore->entries();
113
114 G4int nofLVWithSD = fSDManager->GetNofLVWithSD();
115
116 for (G4int i=nofLVWithSD; i<nofLV; i++) {
117 G4LogicalVolume* lv = (*pLVStore)[i];
118 fSDManager->CreateSD(lv, fAliModule);
119 }
120}
121
122void AliSingleModuleConstruction::CreateSensitiveDetectors2()
123{
124// Creates sensitive detectors.
125// Sensitive detectors are set only to logical volumes
126// in G3SensVolVector.
127// ---
128
129 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
130
131 G3SensVolVector pSVVector
132 = pGeometryManager->GetG3SensVolVector();
133
134 G4int nofSV = pSVVector.entries();
135 if (nofSV>0)
136 for (G4int isv=0; isv<nofSV; isv++) {
137 G4LogicalVolume* lv = pSVVector[isv];
138 fSDManager->CreateSD(lv, fAliModule);
139 }
140}
141
142// public methods
143
869f65a5 144void AliSingleModuleConstruction::Configure(const AliFiles& files)
676fb573 145{
146// Executes the detector setup Root macro
147// (extracted from AliRoot Config.C) and
148// G4 macro.
149// ---
150
151 // filepaths and macro names
869f65a5 152 G4bool isStructure = (fType == kStructure);
153 G4String rootFilePath
154 = files.GetRootMacroPath(fModuleName, isStructure);
155 G4String g4FilePath
156 = files.GetG4MacroPath(fModuleName, isStructure);
157 fDataFilePath
158 = files.GetG3CallsDatPath(fModuleName, fVersion, isStructure);
676fb573 159
869f65a5 160 // load and execute aliroot config macro
676fb573 161 if (fProcessConfig) {
676fb573 162 gROOT->LoadMacro(rootFilePath);
869f65a5 163 G4String macroName = files.GetDefaultMacroName();
164 macroName = macroName + "(";
676fb573 165 AliGlobals::AppendNumberToString(macroName, fVersion);
869f65a5 166 macroName = macroName + ")";
676fb573 167 gInterpreter->ProcessLine(macroName);
168 }
169
869f65a5 170 // process g4 config macro
676fb573 171 G4String command = "/control/execute ";
172 G4UImanager* pUI = G4UImanager::GetUIpointer();
173 pUI->ApplyCommand(command + g4FilePath);
174
175 // get AliModule created in Config.C macro
176 fAliModule = gAlice->GetModule(fModuleName);
177 if (!fAliModule) {
178 G4String text = "AliSingleModuleConstruction::Configure:\n";
179 text = text + " AliModule " + fModuleName;
180 text = text + " has not been found in gAlice.";
181 AliGlobals::Exception(text);
182 }
183}
184
185void AliSingleModuleConstruction::Construct()
186{
187// Constructs geometry.
188// ---
189
190 // print default element table
191 // const G4ElementTable* table = G4Element::GetElementTable();
5f1d09c5 192 // G4cout << "Default elemnt table: " << G4endl;
676fb573 193 // for (G4int i=0; i<table->entries(); i++) {
5f1d09c5 194 // G4cout << *(*table)[i] << G4endl;
676fb573 195 // }
196
04ed0a2e 197 // Configure();
676fb573 198
199 // get geometry manager
200 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
201
202 // register module name in the name map
203 pGeometryManager->SetMapSecond(fAliModule->GetName());
204
205 if (fReadGeometry) {
206 // create G3 geometry from g3calls.dat
207 pGeometryManager->SetWriteGeometry(false);
208 pGeometryManager->ReadG3Geometry(fDataFilePath);
209 }
210 else {
211 // set geometry output stream for this module
212 pGeometryManager->SetWriteGeometry(fWriteGeometry);
213 if (fWriteGeometry)
214 pGeometryManager->OpenOutFile(fDataFilePath);
215
216 // create geometry from AliRoot
217
218 // construct materials
219 fAliModule->CreateMaterials();
220
221 // construct G3 geometry
222 fAliModule->CreateGeometry();
1bf18a99 223
224 if (fWriteGeometry)
225 pGeometryManager->CloseOutFile();
676fb573 226 }
227
228 // construct G4 geometry
229 G4VPhysicalVolume* world = pGeometryManager->CreateG4Geometry();
230 if (!fgWorld) fgWorld = world;
231
232 // set the detector frame (envelope)
233 // (without warning output if enevelope is not defined)
234 SetDetFrame(false);
235
236 // create sensitive detectors
237 CreateSensitiveDetectors();
238
239 // build sensitive detectors table
240 fAliModule->Init();
241
e88c18bd 242 // construct geometry for display
243 fAliModule->BuildGeometry();
244
676fb573 245 // reset TG4GeometryManager
246 pGeometryManager->ClearG3Tables();
247
248 // print current total number of logical volumes
249 G4cout << "Current total number of sensitive volumes: "
5f1d09c5 250 << pGeometryManager->NofVolumes() << G4endl;
676fb573 251
252#ifdef ALICE_VISUALIZE
253 if (GetDetFrame()) {
254 // set visualization attributes
255 // if detector envelope is defined
256 SetDetVisibility(true);
257 SetDetColour("Yellow");
258 }
259#endif
260}