4 // See the class description in the header file.
6 #include "AliSingleModuleConstruction.h"
7 #include "AliSingleModuleConstructionMessenger.h"
8 #include "AliSDManager.h"
9 #include "AliGlobals.h"
12 #include "AliModule.h"
14 #include "TG4GeometryManager.h"
16 #include <G3SensVolVector.hh>
17 #include <G4UImanager.hh>
18 //#include <G4Element.hh>
19 #include <G4LogicalVolume.hh>
20 #include <G4LogicalVolumeStore.hh>
25 G4VPhysicalVolume* AliSingleModuleConstruction::fgWorld = 0;
27 AliSingleModuleConstruction::AliSingleModuleConstruction(
28 G4String moduleName, G4int version,
29 AliModuleType moduleType)
30 : AliModuleConstruction(moduleName),
34 fAllLVSensitive(false)
37 fSDManager = AliSDManager::Instance();
40 fMessenger = new AliSingleModuleConstructionMessenger(this, moduleName);
43 AliSingleModuleConstruction::AliSingleModuleConstruction(
44 const AliSingleModuleConstruction& right)
45 : AliModuleConstruction(right)
48 fVersion = right.fVersion;
50 fProcessConfig = right.fProcessConfig;
51 fAllLVSensitive = right.fAllLVSensitive;
52 fSDManager = right.fSDManager;
54 G4String moduleName = right.fModuleName;
56 fMessenger = new AliSingleModuleConstructionMessenger(this, moduleName);
59 AliSingleModuleConstruction::AliSingleModuleConstruction() {
63 AliSingleModuleConstruction::~AliSingleModuleConstruction() {
70 AliSingleModuleConstruction&
71 AliSingleModuleConstruction::operator=(const AliSingleModuleConstruction& right)
73 // check assignement to self
74 if (this == &right) return *this;
76 // base class assignement
77 AliModuleConstruction::operator=(right);
79 fVersion = right.fVersion;
81 fProcessConfig = right.fProcessConfig;
82 fAllLVSensitive = right.fAllLVSensitive;
83 fSDManager = right.fSDManager;
90 void AliSingleModuleConstruction::CreateSensitiveDetectors()
92 // Creates sensitive detectors.
96 CreateSensitiveDetectors1();
98 CreateSensitiveDetectors2();
100 // set static number of logical volumes already processed
101 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
102 fSDManager->SetNofLVWithSD(pLVStore->entries());
105 void AliSingleModuleConstruction::CreateSensitiveDetectors1()
107 // Creates sensitive detectors.
108 // Sensitive detectors are set to all logical volumes
111 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
112 G4int nofLV = pLVStore->entries();
114 G4int nofLVWithSD = fSDManager->GetNofLVWithSD();
116 for (G4int i=nofLVWithSD; i<nofLV; i++) {
117 G4LogicalVolume* lv = (*pLVStore)[i];
118 fSDManager->CreateSD(lv, fAliModule);
122 void AliSingleModuleConstruction::CreateSensitiveDetectors2()
124 // Creates sensitive detectors.
125 // Sensitive detectors are set only to logical volumes
126 // in G3SensVolVector.
129 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
131 G3SensVolVector pSVVector
132 = pGeometryManager->GetG3SensVolVector();
134 G4int nofSV = pSVVector.entries();
136 for (G4int isv=0; isv<nofSV; isv++) {
137 G4LogicalVolume* lv = pSVVector[isv];
138 fSDManager->CreateSD(lv, fAliModule);
144 void AliSingleModuleConstruction::Configure(const AliFiles& files)
146 // Executes the detector setup Root macro
147 // (extracted from AliRoot Config.C) and
151 // filepaths and macro names
152 G4bool isStructure = (fType == kStructure);
153 G4String rootFilePath
154 = files.GetRootMacroPath(fModuleName, isStructure);
156 = files.GetG4MacroPath(fModuleName, isStructure);
158 = files.GetG3CallsDatPath(fModuleName, fVersion, isStructure);
160 // load and execute aliroot config macro
161 if (fProcessConfig) {
162 gROOT->LoadMacro(rootFilePath);
163 G4String macroName = files.GetDefaultMacroName();
164 macroName = macroName + "(";
165 AliGlobals::AppendNumberToString(macroName, fVersion);
166 macroName = macroName + ")";
167 gInterpreter->ProcessLine(macroName);
170 // process g4 config macro
171 G4String command = "/control/execute ";
172 G4UImanager* pUI = G4UImanager::GetUIpointer();
173 pUI->ApplyCommand(command + g4FilePath);
175 // get AliModule created in Config.C macro
176 fAliModule = gAlice->GetModule(fModuleName);
178 G4String text = "AliSingleModuleConstruction::Configure:\n";
179 text = text + " AliModule " + fModuleName;
180 text = text + " has not been found in gAlice.";
181 AliGlobals::Exception(text);
185 void AliSingleModuleConstruction::Construct()
187 // Constructs geometry.
190 // print default element table
191 // const G4ElementTable* table = G4Element::GetElementTable();
192 // G4cout << "Default elemnt table: " << G4endl;
193 // for (G4int i=0; i<table->entries(); i++) {
194 // G4cout << *(*table)[i] << G4endl;
199 // get geometry manager
200 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
202 // register module name in the name map
203 pGeometryManager->SetMapSecond(fAliModule->GetName());
206 // create G3 geometry from g3calls.dat
207 pGeometryManager->SetWriteGeometry(false);
208 pGeometryManager->ReadG3Geometry(fDataFilePath);
211 // set geometry output stream for this module
212 pGeometryManager->SetWriteGeometry(fWriteGeometry);
214 pGeometryManager->OpenOutFile(fDataFilePath);
216 // create geometry from AliRoot
218 // construct materials
219 fAliModule->CreateMaterials();
221 // construct G3 geometry
222 fAliModule->CreateGeometry();
225 pGeometryManager->CloseOutFile();
228 // construct G4 geometry
229 G4VPhysicalVolume* world = pGeometryManager->CreateG4Geometry();
230 if (!fgWorld) fgWorld = world;
232 // set the detector frame (envelope)
233 // (without warning output if enevelope is not defined)
236 // create sensitive detectors
237 CreateSensitiveDetectors();
239 // build sensitive detectors table
242 // construct geometry for display
243 fAliModule->BuildGeometry();
245 // reset TG4GeometryManager
246 pGeometryManager->ClearG3Tables();
248 // print current total number of logical volumes
249 G4cout << "Current total number of sensitive volumes: "
250 << pGeometryManager->NofVolumes() << G4endl;
252 #ifdef ALICE_VISUALIZE
254 // set visualization attributes
255 // if detector envelope is defined
256 SetDetVisibility(true);
257 SetDetColour("Yellow");