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