4 // See the class description in the header file.
6 #include "AliSingleModuleConstruction.h"
7 #include "AliSingleModuleConstructionMessenger.h"
8 #include "AliSDManager.h"
9 #include "AliSensitiveDetector.h"
10 #include "AliGlobals.h"
14 #include "TG4GeometryManager.h"
16 #include <G3SensVolVector.hh>
17 #include <G4SDManager.hh>
18 #include <G4UImanager.hh>
19 //#include <G4Element.hh>
20 #include <G4LogicalVolume.hh>
21 #include <G4LogicalVolumeStore.hh>
26 G4VPhysicalVolume* AliSingleModuleConstruction::fgWorld = 0;
28 AliSingleModuleConstruction::AliSingleModuleConstruction(
29 G4String moduleName, G4int version,
30 AliModuleType moduleType)
31 : AliModuleConstruction(moduleName),
35 fAllLVSensitive(false)
38 fSDManager = AliSDManager::Instance();
41 fMessenger = new AliSingleModuleConstructionMessenger(this, moduleName);
44 AliSingleModuleConstruction::AliSingleModuleConstruction(
45 const AliSingleModuleConstruction& right)
46 : AliModuleConstruction(right)
49 fVersion = right.fVersion;
51 fProcessConfig = right.fProcessConfig;
52 fAllLVSensitive = right.fAllLVSensitive;
53 fSDManager = right.fSDManager;
55 G4String moduleName = right.fModuleName;
57 fMessenger = new AliSingleModuleConstructionMessenger(this, moduleName);
60 AliSingleModuleConstruction::AliSingleModuleConstruction() {
64 AliSingleModuleConstruction::~AliSingleModuleConstruction() {
71 AliSingleModuleConstruction&
72 AliSingleModuleConstruction::operator=(const AliSingleModuleConstruction& right)
74 // check assignement to self
75 if (this == &right) return *this;
77 // base class assignement
78 AliModuleConstruction::operator=(right);
80 fVersion = right.fVersion;
82 fProcessConfig = right.fProcessConfig;
83 fAllLVSensitive = right.fAllLVSensitive;
84 fSDManager = right.fSDManager;
91 void AliSingleModuleConstruction::CreateSensitiveDetectors()
93 // Creates sensitive detectors.
97 CreateSensitiveDetectors1();
99 CreateSensitiveDetectors2();
101 // set static number of logical volumes already processed
102 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
103 fSDManager->SetNofLVWithSD(pLVStore->entries());
106 void AliSingleModuleConstruction::CreateSensitiveDetectors1()
108 // Creates sensitive detectors.
109 // Sensitive detectors are set to all logical volumes
112 G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
113 G4int nofLV = pLVStore->entries();
115 G4int nofLVWithSD = fSDManager->GetNofLVWithSD();
117 for (G4int i=nofLVWithSD; i<nofLV; i++) {
118 G4LogicalVolume* lv = (*pLVStore)[i];
119 fSDManager->CreateSD(lv, fAliModule);
123 void AliSingleModuleConstruction::CreateSensitiveDetectors2()
125 // Creates sensitive detectors.
126 // Sensitive detectors are set only to logical volumes
127 // in G3SensVolVector.
130 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
132 G3SensVolVector pSVVector
133 = pGeometryManager->GetG3SensVolVector();
135 G4int nofSV = pSVVector.entries();
137 for (G4int isv=0; isv<nofSV; isv++) {
138 G4LogicalVolume* lv = pSVVector[isv];
139 fSDManager->CreateSD(lv, fAliModule);
145 void AliSingleModuleConstruction::Configure()
147 // Executes the detector setup Root macro
148 // (extracted from AliRoot Config.C) and
152 // filepaths and macro names
153 G4String rootFilePath;
156 if (fType == kDetector) {
158 //$AG4_INSTALL/macro/XXX/Config.C
159 //$AG4_INSTALL/macro/XXX/Config.in
160 rootFilePath = AliFiles::DetConfig1();
161 rootFilePath.append(fModuleName);
162 rootFilePath.append(AliFiles::DetConfig2());
163 g4FilePath = rootFilePath;
165 rootFilePath.append(AliFiles::DetConfig3());
166 g4FilePath.append(AliFiles::DetConfig4());
168 // path to g3calls.dat file
169 //$AG4_INSTALL/macro/XXX/g3calls_vN.dat
170 fDataFilePath = AliFiles::DetData1();
171 fDataFilePath.append(fModuleName);
172 fDataFilePath.append(AliFiles::DetData2());
173 G4String version("v");
174 AliGlobals::AppendNumberToString(version,fVersion);
175 fDataFilePath.append(version);
176 fDataFilePath.append(AliFiles::DetData3());
178 else if (fType == kStructure) {
179 // macro file path is set to
180 //$AG4_INSTALL/macro/STRUCT/XXXConfig.C
181 //$AG4_INSTALL/macro/STRUCT/XXXConfig.in
182 rootFilePath = AliFiles::DetConfig1();
183 rootFilePath.append(AliFiles::STRUCT());
184 rootFilePath.append(AliFiles::DetConfig2());
185 rootFilePath.append(fModuleName);
186 g4FilePath = rootFilePath;
188 rootFilePath.append(AliFiles::DetConfig3());
189 g4FilePath.append(AliFiles::DetConfig4());
191 // path to g3calls.dat file
192 //$AG4_INSTALL/macro/STRUCT/g3calls_XXXvN.dat
193 fDataFilePath = AliFiles::DetData1();
194 fDataFilePath.append(AliFiles::STRUCT());
195 fDataFilePath.append(AliFiles::DetData2());
196 fDataFilePath.append(fModuleName);
197 G4String version("v");
198 AliGlobals::AppendNumberToString(version,fVersion);
199 fDataFilePath.append(version);
200 fDataFilePath.append(AliFiles::DetData3());
203 if (fProcessConfig) {
204 // load and execute aliroot macro
205 gROOT->LoadMacro(rootFilePath);
206 G4String macroName = AliFiles::DetConfigName1();
207 AliGlobals::AppendNumberToString(macroName, fVersion);
208 macroName.append(AliFiles::DetConfigName2());
209 gInterpreter->ProcessLine(macroName);
212 // add process g4 config macro
213 // execute Geant4 macro if file is specified as an argument
214 G4String command = "/control/execute ";
215 G4UImanager* pUI = G4UImanager::GetUIpointer();
216 pUI->ApplyCommand(command + g4FilePath);
218 // get AliModule created in Config.C macro
219 fAliModule = gAlice->GetModule(fModuleName);
221 G4String text = "AliSingleModuleConstruction::Configure:\n";
222 text = text + " AliModule " + fModuleName;
223 text = text + " has not been found in gAlice.";
224 AliGlobals::Exception(text);
228 void AliSingleModuleConstruction::Construct()
230 // Constructs geometry.
233 // print default element table
234 // const G4ElementTable* table = G4Element::GetElementTable();
235 // G4cout << "Default elemnt table: " << G4endl;
236 // for (G4int i=0; i<table->entries(); i++) {
237 // G4cout << *(*table)[i] << G4endl;
242 // get geometry manager
243 TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
245 // register module name in the name map
246 pGeometryManager->SetMapSecond(fAliModule->GetName());
249 // create G3 geometry from g3calls.dat
250 pGeometryManager->SetWriteGeometry(false);
251 pGeometryManager->ReadG3Geometry(fDataFilePath);
254 // set geometry output stream for this module
255 pGeometryManager->SetWriteGeometry(fWriteGeometry);
257 pGeometryManager->OpenOutFile(fDataFilePath);
259 // create geometry from AliRoot
261 // construct materials
262 fAliModule->CreateMaterials();
264 // construct G3 geometry
265 fAliModule->CreateGeometry();
267 // construct geometry for display
268 fAliModule->BuildGeometry();
271 pGeometryManager->CloseOutFile();
274 // construct G4 geometry
275 G4VPhysicalVolume* world = pGeometryManager->CreateG4Geometry();
276 if (!fgWorld) fgWorld = world;
278 // set the detector frame (envelope)
279 // (without warning output if enevelope is not defined)
282 // create sensitive detectors
283 CreateSensitiveDetectors();
285 // build sensitive detectors table
288 // reset TG4GeometryManager
289 pGeometryManager->ClearG3Tables();
291 // print current total number of logical volumes
292 G4cout << "Current total number of sensitive volumes: "
293 << pGeometryManager->NofVolumes() << G4endl;
295 #ifdef ALICE_VISUALIZE
297 // set visualization attributes
298 // if detector envelope is defined
299 SetDetVisibility(true);
300 SetDetColour("Yellow");