]> git.uio.no Git - u/mrichter/AliRoot.git/blame - AliGeant4/AliDetConstruction.cxx
Updated VZERO source
[u/mrichter/AliRoot.git] / AliGeant4 / AliDetConstruction.cxx
CommitLineData
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 24AliDetConstruction::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));
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
1d18f4de 51 // update messenger
52 fDetSwitchVector.UpdateMessenger();
53
80ed9a99 54 // instantiate LVtree browser
55 AliLVTree::Instance();
676fb573 56}
57
78ca1e9c 58//_____________________________________________________________________________
676fb573 59AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
60 : AliModulesComposition(right)
61{
62 // AliModuleComposition is protected from copying
63}
64
78ca1e9c 65//_____________________________________________________________________________
80ed9a99 66AliDetConstruction::~AliDetConstruction()
67{
68 // delete LVtree browser
69 delete AliLVTree::Instance();
676fb573 70}
71
72// operators
73
78ca1e9c 74//_____________________________________________________________________________
676fb573 75AliDetConstruction&
76AliDetConstruction::operator=(const AliDetConstruction& right)
77{
78 // check assignement to self
79 if (this == &right) return *this;
80
81 // base class assignement
82 // AliModuleComposition is protected from assigning
83 AliModulesComposition::operator=(right);
84
85 return *this;
86}
87
88// private methods
89
78ca1e9c 90//_____________________________________________________________________________
676fb573 91void AliDetConstruction::BuildDetectors()
92{
93// Create module constructions for AliModules
94// that have been created and registered by gAlice
95// ---
96
97 TObjArray* pDetectors = gAlice->Detectors();
98 TIter next(pDetectors);
99
100 // the first AliModule is expected to be the top volume
101 AliModule *module = (AliModule*)next();
102 if (G4String(module->GetName()) != "BODY") {
103 G4String text = "AliDetConstruction::BuildDetectors():\n";
104 text = text + " Instead of BODY - the first module ";
105 text = text + module->GetName() + " has been found.";
106 AliGlobals::Exception(text);
107 }
80ed9a99 108 AddModule("BODY", 0, kStructure);
676fb573 109
110 G4bool first = true;
111 while ((module = (AliModule*)next())) {
80ed9a99 112
676fb573 113 // register moduleConstruction in fDetSwitchVector
80ed9a99 114 // in order to keep availability of /aliDet/list command
676fb573 115 G4String modName = module->GetName();
116 G4int modVersion = module->IsVersion();
117 if (first)
118 // skip registering of the top volume
119 first = false;
120 else
80ed9a99 121 fDetSwitchVector.SwitchDetOn(modName, modVersion);
676fb573 122
123 // all modules will be processed alltogether
52ff5c7d 124 AddModule(modName, modVersion, fDetSwitchVector.GetDetSwitch(modName)->GetType());
676fb573 125
e980662a 126 if (VerboseLevel() > 0) {
127 G4cout << "Created module construction for "
128 << modName << "v" << modVersion << "." << G4endl;
129 }
676fb573 130 }
131
132 // do not process Config.C
133 // (it was processed when creating modules by gAlice)
134 SetProcessConfigToModules(false);
135}
136
78ca1e9c 137//_____________________________________________________________________________
676fb573 138void AliDetConstruction::CreateDetectors()
139{
140// Creates AliModules and their module constructions
141// according to the fDetSwitchVector
142// ---
143
144 // add top volume (AliBODY) construction first
80ed9a99 145 AddModule("BODY", 0, kStructure);
676fb573 146
147 // add modules constructions
80ed9a99 148 for (G4int i=0; i<fDetSwitchVector.GetSize(); i++)
676fb573 149 {
80ed9a99 150 AliDetSwitch* detSwitch = fDetSwitchVector.GetDetSwitch(i);
151 G4String detName = detSwitch->GetDetName();
152 G4int version = detSwitch->GetSwitchedVersion();
153 AliModuleType type = detSwitch->GetType();
676fb573 154
155 if (version > -1)
80ed9a99 156 AddModule(detName, version, type);
676fb573 157 }
158}
159
d08272d4 160//_____________________________________________________________________________
161void AliDetConstruction::CheckDependence(const G4String& master,
162 const G4String& slave)
163{
164// Checks modules dependence.
165// If master is switch on and slave off, the default version
166// of slave is switched on and a warning is issued.
167// ---
168
169 AliDetSwitch* masterSwitch = fDetSwitchVector.GetDetSwitch(master);
170 AliDetSwitch* slaveSwitch = fDetSwitchVector.GetDetSwitch(slave);
171
172 if ( masterSwitch->GetSwitchedVersion() > -1 &&
173 slaveSwitch->GetSwitchedVersion() < 0 ) {
174
175 slaveSwitch->SwitchOnDefault();
176
177 // warning
178 G4String text = "AliDetConstruction::CheckDetDependence: \n";
179 text = text + " Switched " + master + " requires " + slave + ".\n";
180 text = text + " The det switch for " + slave + " has been changed.";
181 AliGlobals::Warning(text);
182 }
183}
184
78ca1e9c 185//_____________________________________________________________________________
676fb573 186void AliDetConstruction::CheckDetDependencies()
187{
188// Checks modules dependencies.
676fb573 189// ---
190
d08272d4 191 CheckDependence("MUON", "DIPO");
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 203G4VPhysicalVolume* 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//_____________________________________________________________________________
227void 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
266 xml.GenerateSection(detName, detVersion, "today", "Generated from Geant4",
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