]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
4 | // See the class description in the header file. | |
5 | ||
6 | #include "AliMoreModulesConstruction.h" | |
7 | #include "AliSingleModuleConstruction.h" | |
8 | #include "AliSDManager.h" | |
676fb573 | 9 | #include "AliModule.h" |
676fb573 | 10 | #include "AliGlobals.h" |
e4868b5c | 11 | #include "AliFiles.h" |
676fb573 | 12 | |
13 | #include "TG4GeometryManager.h" | |
14 | ||
15 | #include <G4SDManager.hh> | |
16 | #include <G4LogicalVolume.hh> | |
17 | #include <G4LogicalVolumeStore.hh> | |
18 | ||
676fb573 | 19 | AliMoreModulesConstruction::AliMoreModulesConstruction() { |
20 | // | |
21 | fSDManager = AliSDManager::Instance(); | |
22 | } | |
23 | ||
24 | AliMoreModulesConstruction::AliMoreModulesConstruction( | |
25 | const AliMoreModulesConstruction& right) | |
26 | { | |
27 | // delete current module constructions | |
28 | fModuleConstructionVector.erase( | |
29 | fModuleConstructionVector.begin(), fModuleConstructionVector.end()); | |
30 | ||
31 | // create new module constructions | |
32 | G4int nofModules = right.fModuleConstructionVector.size(); | |
33 | for (G4int i=0; i<nofModules; i++) { | |
34 | G4String name = right.fModuleConstructionVector[i]->GetDetName(); | |
35 | G4int version = right.fModuleConstructionVector[i]->GetVersion(); | |
36 | AliModuleType type = right.fModuleConstructionVector[i]->GetType(); | |
37 | AddModule(name, version, type); | |
38 | } | |
39 | ||
40 | fSDManager = right.fSDManager; | |
41 | } | |
42 | ||
43 | ||
44 | AliMoreModulesConstruction::~AliMoreModulesConstruction() | |
45 | { | |
46 | // delete module constructions | |
47 | fModuleConstructionVector.erase( | |
48 | fModuleConstructionVector.begin(), fModuleConstructionVector.end()); | |
49 | } | |
50 | ||
51 | // operators | |
52 | ||
53 | AliMoreModulesConstruction& | |
54 | AliMoreModulesConstruction::operator=(const AliMoreModulesConstruction& right) | |
55 | { | |
56 | // check assignement to self | |
57 | if (this == &right) return *this; | |
58 | ||
59 | // delete current module constructions | |
60 | fModuleConstructionVector.erase( | |
61 | fModuleConstructionVector.begin(), fModuleConstructionVector.end()); | |
62 | ||
63 | // create new module constructions | |
64 | G4int nofModules = right.fModuleConstructionVector.size(); | |
65 | for (G4int i=0; i<nofModules; i++) { | |
66 | G4String name = right.fModuleConstructionVector[i]->GetDetName(); | |
67 | G4int version = right.fModuleConstructionVector[i]->GetVersion(); | |
68 | AliModuleType type = right.fModuleConstructionVector[i]->GetType(); | |
69 | AddModule(name, version, type); | |
70 | } | |
71 | ||
72 | fSDManager = right.fSDManager; | |
73 | ||
74 | return *this; | |
75 | } | |
76 | ||
77 | // private methods | |
78 | ||
79 | void AliMoreModulesConstruction::CreateSensitiveDetectors( | |
80 | G4bool allLVSensitive) | |
81 | { | |
82 | // Creates sensitive detectors. | |
83 | // --- | |
84 | ||
85 | if (allLVSensitive) | |
86 | CreateSensitiveDetectors1(); | |
87 | else | |
88 | CreateSensitiveDetectors2(); | |
89 | ||
90 | // set static number of logical volumes already processed | |
91 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
92 | fSDManager->SetNofLVWithSD(pLVStore->entries()); | |
93 | } | |
94 | ||
95 | void AliMoreModulesConstruction::CreateSensitiveDetectors1() | |
96 | { | |
97 | // Creates sensitive detectors. | |
98 | // Sensitive detectors are set to all logical volumes | |
99 | // --- | |
100 | ||
101 | G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance(); | |
102 | G4int nofLV = pLVStore->entries(); | |
103 | ||
104 | G4int nofLVWithSD = fSDManager->GetNofLVWithSD(); | |
105 | for (G4int i=nofLVWithSD; i<nofLV; i++) { | |
106 | G4LogicalVolume* lv = (*pLVStore)[i]; | |
107 | AliModule* module = fSDManager->FindAliModule(lv); | |
108 | fSDManager->CreateSD(lv, module); | |
109 | } | |
110 | } | |
111 | ||
112 | void AliMoreModulesConstruction::CreateSensitiveDetectors2() | |
113 | { | |
114 | // Creates sensitive detectors. | |
115 | // Sensitive detectors are set only to logical volumes | |
116 | // in G3SensVolVector. | |
117 | // --- | |
118 | ||
119 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
120 | ||
121 | G3SensVolVector pSVVector | |
122 | = pGeometryManager->GetG3SensVolVector(); | |
123 | ||
124 | G4int nofSV = pSVVector.entries(); | |
125 | if (nofSV>0) | |
126 | for (G4int isv=0; isv<nofSV; isv++) { | |
127 | G4LogicalVolume* lv = pSVVector[isv]; | |
128 | AliModule* module = fSDManager->FindAliModule(lv); | |
129 | fSDManager->CreateSD(lv, module); | |
130 | } | |
131 | } | |
132 | ||
133 | // public methods | |
134 | ||
135 | void AliMoreModulesConstruction::AddModule(G4String moduleName, G4int version, | |
136 | AliModuleType moduleType) | |
137 | { | |
138 | // Adds module specified by name, version and type. | |
139 | // --- | |
140 | ||
141 | // create module construction | |
142 | AliSingleModuleConstruction* moduleConstruction | |
143 | = new AliSingleModuleConstruction(moduleName, version, moduleType); | |
144 | ||
145 | // add module, module construction to vectors | |
146 | fModuleConstructionVector.push_back(moduleConstruction); | |
147 | } | |
148 | ||
e4868b5c | 149 | void AliMoreModulesConstruction::Configure(const AliFiles& files) |
62022fa8 | 150 | { |
151 | // Executes the detectors setup Root macros | |
152 | // (extracted from AliRoot Config.C) and | |
153 | // G4 macros. | |
154 | // --- | |
155 | ||
156 | // number of modules | |
157 | G4int nofModules = fModuleConstructionVector.size(); | |
158 | ||
159 | if (nofModules == 0) { | |
160 | AliGlobals::Warning( | |
161 | "AliMoreModulesConstruction::Construct(): No modules are defined."); | |
162 | } | |
163 | else | |
164 | for (G4int i=0; i<nofModules; i++) | |
e4868b5c | 165 | fModuleConstructionVector[i]->Configure(files); |
62022fa8 | 166 | } |
167 | ||
676fb573 | 168 | void AliMoreModulesConstruction::Construct() |
169 | { | |
170 | // Constructs geometry. | |
171 | // G3 tables are process for all modules alltogether. | |
172 | // -- | |
173 | ||
174 | // number of modules | |
175 | G4int nofModules = fModuleConstructionVector.size(); | |
176 | ||
177 | if (nofModules == 0) { | |
178 | AliGlobals::Warning( | |
179 | "AliMoreModulesConstruction::Construct(): No modules are defined."); | |
180 | } | |
181 | else { | |
182 | // get geometry manager | |
183 | TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance(); | |
184 | ||
185 | G4bool allLVSensitive = false; | |
186 | G4int i; | |
187 | for (i=0; i<nofModules; i++) { | |
188 | ||
e4868b5c | 189 | // fModuleConstructionVector[i]->Configure(files); |
676fb573 | 190 | |
191 | // register module name in the name map | |
192 | AliModule* module = fModuleConstructionVector[i]->GetAliModule(); | |
193 | pGeometryManager->SetMapSecond(module->GetName()); | |
194 | ||
195 | G4bool readGeometry = fModuleConstructionVector[i]->GetReadGeometry(); | |
196 | G4bool writeGeometry = fModuleConstructionVector[i]->GetWriteGeometry(); | |
197 | G4String dataFilePath = fModuleConstructionVector[i]->GetDataFilePath(); | |
198 | ||
199 | if (readGeometry) { | |
871f5582 | 200 | // TG4GeometryManager uses g3tog4 methods for reading |
201 | // g3calls.dat files - as these methods do not fill name map | |
202 | // they cannot be used for constructing more modules | |
203 | // together | |
204 | // | |
205 | // pGeometryManager->SetWriteGeometry(false); | |
206 | // pGeometryManager->ReadG3Geometry(dataFilePath); | |
207 | ||
208 | G4String text = "AliMoreModulesConstruction::Construct - Limitation:\n"; | |
209 | text = text + " Reading g3calls.dat is not implemented."; | |
210 | AliGlobals::Exception(text); | |
676fb573 | 211 | } |
212 | else { | |
213 | // set geometry output stream for this module | |
214 | pGeometryManager->SetWriteGeometry(writeGeometry); | |
215 | if (writeGeometry) | |
216 | pGeometryManager->OpenOutFile(dataFilePath); | |
217 | ||
218 | // create geometry from AliRoot | |
219 | ||
220 | // construct materials | |
221 | module->CreateMaterials(); | |
222 | ||
223 | // construct G3 geometry | |
224 | module->CreateGeometry(); | |
62022fa8 | 225 | |
871f5582 | 226 | if (writeGeometry) |
227 | pGeometryManager->CloseOutFile(); | |
676fb573 | 228 | } |
229 | ||
230 | // all logical volumes will be made sensitive if any | |
231 | // module requires this | |
232 | if (fModuleConstructionVector[i]->GetAllLVSensitive()) | |
233 | allLVSensitive = true; | |
234 | } | |
235 | ||
236 | // construct G4 geometry | |
237 | pGeometryManager->CreateG4Geometry(); | |
238 | ||
239 | // print name map | |
240 | // pGeometryManager->PrintNameMap(); | |
241 | ||
242 | // create sensitive detectors | |
243 | CreateSensitiveDetectors(allLVSensitive); | |
676fb573 | 244 | |
245 | for (i=0; i<nofModules; i++) { | |
246 | // set the detector frame (envelope) | |
247 | // (without warning output if enevelope is not defined) | |
248 | fModuleConstructionVector[i]->SetDetFrame(false); | |
249 | ||
250 | // build sensitive detectors table | |
251 | fModuleConstructionVector[i]->GetAliModule()->Init(); | |
e88c18bd | 252 | |
253 | // construct geometry for display | |
254 | fModuleConstructionVector[i]->GetAliModule()->BuildGeometry(); | |
676fb573 | 255 | } |
256 | ||
257 | // reset TG4GeometryManager | |
258 | pGeometryManager->ClearG3Tables(); | |
259 | ||
260 | // print current total number of logical volumes | |
261 | G4cout << "Current total number of sensitive volumes: " | |
5f1d09c5 | 262 | << pGeometryManager->NofVolumes() << G4endl; |
676fb573 | 263 | |
264 | #ifdef ALICE_VISUALIZE | |
265 | // set visualization attributes | |
266 | for (i=0; i<nofModules; i++) { | |
267 | if (fModuleConstructionVector[i]->GetDetFrame()) { | |
268 | fModuleConstructionVector[i]->SetDetVisibility(true); | |
269 | fModuleConstructionVector[i]->SetDetColour("Yellow"); | |
270 | } | |
271 | } | |
272 | #endif | |
273 | } | |
274 | } |