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