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