]>
Commit | Line | Data |
---|---|---|
676fb573 | 1 | // $Id$ |
2 | // Category: geometry | |
3 | // | |
7005154f | 4 | // Author: I. Hrivnacova |
5 | // | |
6 | // Class AliDetConstruction | |
7 | // ------------------------ | |
676fb573 | 8 | // See the class description in the header file. |
9 | ||
10 | #include "AliDetConstruction.h" | |
c97337f9 | 11 | #include "AliDetSwitch.h" |
676fb573 | 12 | #include "AliGlobals.h" |
80ed9a99 | 13 | #include "AliFiles.h" |
676fb573 | 14 | #include "AliRun.h" |
15 | #include "AliModule.h" | |
16 | ||
80ed9a99 | 17 | #include "TG4XMLGeometryGenerator.h" |
18 | #include "TG4GeometryServices.h" | |
b9d0a01d | 19 | #include "TG4LVTree.h" |
80ed9a99 | 20 | |
21 | #include <G4VPhysicalVolume.hh> | |
22 | ||
78ca1e9c | 23 | //_____________________________________________________________________________ |
676fb573 | 24 | AliDetConstruction::AliDetConstruction() |
80ed9a99 | 25 | : AliModulesComposition() |
676fb573 | 26 | { |
27 | // initialize det switch vector: | |
80ed9a99 | 28 | // moduleName nofVersions defaultVersion [type] |
29 | // det switch objects are deleted in fDetSwitchVector destructor | |
30 | ||
cb36e041 | 31 | fDetSwitchVector.Add(new AliDetSwitch("MAG", 1, 0, kStructure)); |
80ed9a99 | 32 | fDetSwitchVector.Add(new AliDetSwitch("ABSO", 1, 0, kStructure)); |
33 | fDetSwitchVector.Add(new AliDetSwitch("DIPO", 3, 2, kStructure)); | |
34 | fDetSwitchVector.Add(new AliDetSwitch("FRAME", 3, 2, kStructure)); | |
35 | fDetSwitchVector.Add(new AliDetSwitch("HALL", 1, 0, kStructure)); | |
80ed9a99 | 36 | fDetSwitchVector.Add(new AliDetSwitch("PIPE", 5, 0, kStructure)); |
b9d0a01d | 37 | fDetSwitchVector.Add(new AliDetSwitch("SHIL", 2, 2, kStructure)); |
38 | fDetSwitchVector.Add(new AliDetSwitch("CRT", 1, 0)); | |
39 | fDetSwitchVector.Add(new AliDetSwitch("EMCAL", 2, 1)); | |
80ed9a99 | 40 | fDetSwitchVector.Add(new AliDetSwitch("FMD", 2, 1)); |
41 | fDetSwitchVector.Add(new AliDetSwitch("ITS", 7, 5)); | |
42 | fDetSwitchVector.Add(new AliDetSwitch("MUON", 2, 1)); | |
80ed9a99 | 43 | fDetSwitchVector.Add(new AliDetSwitch("PHOS", 2, 1)); |
44 | fDetSwitchVector.Add(new AliDetSwitch("PMD", 3, 1)); | |
45 | fDetSwitchVector.Add(new AliDetSwitch("RICH", 3, 1)); | |
46 | fDetSwitchVector.Add(new AliDetSwitch("START", 2, 1)); | |
47 | fDetSwitchVector.Add(new AliDetSwitch("TOF", 5, 2)); | |
48 | fDetSwitchVector.Add(new AliDetSwitch("TPC", 4, 2)); | |
49 | fDetSwitchVector.Add(new AliDetSwitch("TRD", 2, 1)); | |
50 | fDetSwitchVector.Add(new AliDetSwitch("ZDC", 3, 2)); | |
51 | ||
1d18f4de | 52 | // update messenger |
53 | fDetSwitchVector.UpdateMessenger(); | |
54 | ||
80ed9a99 | 55 | // instantiate LVtree browser |
b9d0a01d | 56 | TG4LVTree::Instance(); |
676fb573 | 57 | } |
58 | ||
78ca1e9c | 59 | //_____________________________________________________________________________ |
676fb573 | 60 | AliDetConstruction::AliDetConstruction(const AliDetConstruction& right) |
61 | : AliModulesComposition(right) | |
62 | { | |
63 | // AliModuleComposition is protected from copying | |
64 | } | |
65 | ||
78ca1e9c | 66 | //_____________________________________________________________________________ |
80ed9a99 | 67 | AliDetConstruction::~AliDetConstruction() |
68 | { | |
69 | // delete LVtree browser | |
b9d0a01d | 70 | delete TG4LVTree::Instance(); |
676fb573 | 71 | } |
72 | ||
73 | // operators | |
74 | ||
78ca1e9c | 75 | //_____________________________________________________________________________ |
676fb573 | 76 | AliDetConstruction& |
77 | AliDetConstruction::operator=(const AliDetConstruction& right) | |
78 | { | |
79 | // check assignement to self | |
80 | if (this == &right) return *this; | |
81 | ||
82 | // base class assignement | |
83 | // AliModuleComposition is protected from assigning | |
84 | AliModulesComposition::operator=(right); | |
85 | ||
86 | return *this; | |
87 | } | |
88 | ||
89 | // private methods | |
90 | ||
78ca1e9c | 91 | //_____________________________________________________________________________ |
676fb573 | 92 | void AliDetConstruction::BuildDetectors() |
93 | { | |
94 | // Create module constructions for AliModules | |
95 | // that have been created and registered by gAlice | |
96 | // --- | |
97 | ||
98 | TObjArray* pDetectors = gAlice->Detectors(); | |
99 | TIter next(pDetectors); | |
100 | ||
101 | // the first AliModule is expected to be the top volume | |
102 | AliModule *module = (AliModule*)next(); | |
103 | if (G4String(module->GetName()) != "BODY") { | |
104 | G4String text = "AliDetConstruction::BuildDetectors():\n"; | |
105 | text = text + " Instead of BODY - the first module "; | |
106 | text = text + module->GetName() + " has been found."; | |
107 | AliGlobals::Exception(text); | |
108 | } | |
80ed9a99 | 109 | AddModule("BODY", 0, kStructure); |
676fb573 | 110 | |
111 | G4bool first = true; | |
112 | while ((module = (AliModule*)next())) { | |
80ed9a99 | 113 | |
676fb573 | 114 | // register moduleConstruction in fDetSwitchVector |
80ed9a99 | 115 | // in order to keep availability of /aliDet/list command |
676fb573 | 116 | G4String modName = module->GetName(); |
117 | G4int modVersion = module->IsVersion(); | |
118 | if (first) | |
119 | // skip registering of the top volume | |
120 | first = false; | |
121 | else | |
80ed9a99 | 122 | fDetSwitchVector.SwitchDetOn(modName, modVersion); |
676fb573 | 123 | |
124 | // all modules will be processed alltogether | |
52ff5c7d | 125 | AddModule(modName, modVersion, fDetSwitchVector.GetDetSwitch(modName)->GetType()); |
676fb573 | 126 | |
e980662a | 127 | if (VerboseLevel() > 0) { |
128 | G4cout << "Created module construction for " | |
129 | << modName << "v" << modVersion << "." << G4endl; | |
130 | } | |
676fb573 | 131 | } |
132 | ||
133 | // do not process Config.C | |
134 | // (it was processed when creating modules by gAlice) | |
135 | SetProcessConfigToModules(false); | |
136 | } | |
137 | ||
78ca1e9c | 138 | //_____________________________________________________________________________ |
676fb573 | 139 | void AliDetConstruction::CreateDetectors() |
140 | { | |
141 | // Creates AliModules and their module constructions | |
142 | // according to the fDetSwitchVector | |
143 | // --- | |
144 | ||
145 | // add top volume (AliBODY) construction first | |
80ed9a99 | 146 | AddModule("BODY", 0, kStructure); |
676fb573 | 147 | |
148 | // add modules constructions | |
80ed9a99 | 149 | for (G4int i=0; i<fDetSwitchVector.GetSize(); i++) |
676fb573 | 150 | { |
80ed9a99 | 151 | AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i); |
152 | G4String detName = detSwitch->GetDetName(); | |
153 | G4int version = detSwitch->GetSwitchedVersion(); | |
154 | AliModuleType type = detSwitch->GetType(); | |
676fb573 | 155 | |
156 | if (version > -1) | |
80ed9a99 | 157 | AddModule(detName, version, type); |
676fb573 | 158 | } |
159 | } | |
160 | ||
d08272d4 | 161 | //_____________________________________________________________________________ |
162 | void AliDetConstruction::CheckDependence(const G4String& master, | |
163 | const G4String& slave) | |
164 | { | |
165 | // Checks modules dependence. | |
166 | // If master is switch on and slave off, the default version | |
167 | // of slave is switched on and a warning is issued. | |
168 | // --- | |
169 | ||
170 | AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master); | |
171 | AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave); | |
172 | ||
173 | if ( masterSwitch->GetSwitchedVersion() > -1 && | |
174 | slaveSwitch->GetSwitchedVersion() < 0 ) { | |
175 | ||
176 | slaveSwitch->SwitchOnDefault(); | |
177 | ||
178 | // warning | |
179 | G4String text = "AliDetConstruction::CheckDetDependence: \n"; | |
180 | text = text + " Switched " + master + " requires " + slave + ".\n"; | |
181 | text = text + " The det switch for " + slave + " has been changed."; | |
182 | AliGlobals::Warning(text); | |
183 | } | |
184 | } | |
185 | ||
78ca1e9c | 186 | //_____________________________________________________________________________ |
676fb573 | 187 | void AliDetConstruction::CheckDetDependencies() |
188 | { | |
189 | // Checks modules dependencies. | |
676fb573 | 190 | // --- |
191 | ||
d08272d4 | 192 | CheckDependence("TOF", "FRAME"); |
193 | CheckDependence("TRD", "FRAME"); | |
194 | CheckDependence("ZDC", "PIPE"); | |
195 | CheckDependence("ZDC", "ABSO"); | |
196 | CheckDependence("ZDC", "DIPO"); | |
197 | CheckDependence("ZDC", "SHIL"); | |
676fb573 | 198 | } |
199 | ||
200 | // public methods | |
201 | ||
78ca1e9c | 202 | //_____________________________________________________________________________ |
676fb573 | 203 | G4VPhysicalVolume* AliDetConstruction::Construct() |
204 | { | |
205 | // Constructs geometry. | |
206 | // This method is called by G4RunManager in initialization. | |
207 | // --- | |
208 | ||
209 | if (gAlice->Modules()->GetLast() < 0) { | |
210 | // create geometry (including AliModules) according to | |
211 | // the fDetSwitchVector | |
212 | CheckDetDependencies(); | |
213 | CreateDetectors(); | |
214 | } | |
215 | else { | |
216 | // create geometry for AliModules | |
217 | // that have been created and registered by gAlice | |
218 | BuildDetectors(); | |
219 | } | |
220 | // construct modules geometry | |
221 | ConstructModules(); | |
222 | ||
80ed9a99 | 223 | return TG4GeometryServices::Instance()->GetWorld(); |
676fb573 | 224 | } |
225 | ||
80ed9a99 | 226 | //_____________________________________________________________________________ |
227 | void AliDetConstruction::GenerateXMLGeometry() const | |
228 | { | |
229 | // Generates XML geometry file from the top volume. | |
230 | // The file name is set according the last switched detector | |
231 | // registered in the det switch vector. | |
232 | // --- | |
233 | ||
234 | G4VPhysicalVolume* world = TG4GeometryServices::Instance()->GetWorld(); | |
235 | ||
236 | // XML filename | |
237 | // according to last switched detector | |
238 | G4String detName; | |
239 | G4String detVersion = ""; | |
240 | G4int version = -1; | |
241 | for (G4int i=fDetSwitchVector.GetSize()-1; i>=0; i--) { | |
242 | version = fDetSwitchVector.GetDetSwitch(i)->GetSwitchedVersion(); | |
243 | if (version > -1) { | |
244 | detName = fDetSwitchVector.GetDetSwitch(i)->GetDetName(); | |
245 | AliGlobals::AppendNumberToString(detVersion,version); | |
246 | break; | |
247 | } | |
248 | } | |
249 | G4String filePath | |
250 | = AliFiles::Instance()->GetXMLFilePath(detName, version); | |
251 | ||
252 | // set top volume name | |
253 | G4String topName = world->GetName() + "_comp"; | |
254 | ||
255 | // generate XML | |
256 | ||
257 | TG4XMLGeometryGenerator xml; | |
258 | xml.OpenFile(filePath); | |
259 | ||
260 | // generate materials | |
261 | // not implemented | |
262 | // xml.GenerateMaterials(version, "today", "Generated from G4", | |
263 | // "v4", world->GetLogicalVolume()); | |
264 | ||
265 | // generate volumes tree | |
b9d0a01d | 266 | xml.GenerateSection("v6", detName, detVersion, "today", "Generated from Geant4", |
80ed9a99 | 267 | topName, world->GetLogicalVolume()); |
268 | xml.CloseFile(); | |
269 | ||
e980662a | 270 | if (VerboseLevel() > 0) { |
271 | G4cout << "File " << detName << "v" << version << ".xml has been generated." | |
272 | << G4endl; | |
273 | } | |
80ed9a99 | 274 | } |
275 |