]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliDetConstruction.cxx
Updated class description: added class title, author;
[u/mrichter/AliRoot.git] / AliGeant4 / AliDetConstruction.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliDetConstruction
7 // ------------------------
8 // See the class description in the header file.
9
10 #include "AliDetConstruction.h"
11 #include "AliSingleModuleConstruction.h"
12 #include "AliDetSwitch.h"
13 #include "AliGlobals.h"
14 #include "AliRun.h"
15 #include "AliModule.h"
16
17 //_____________________________________________________________________________
18 AliDetConstruction::AliDetConstruction()
19   : fTopVolumeName("ALIC")
20 {
21   // initialize det switch vector: 
22   // moduleName nofVersions defaultVersion PPRVersion [type isStandalone]     
23         // det switch objects are deleted in
24         // tbe base class (AliModulesCompositions) destructor
25
26   AliDetSwitch* detSwitch;
27   detSwitch = new AliDetSwitch("ABSO",   1, 0, 0, kStructure);
28   AddDetSwitch(detSwitch); 
29   detSwitch = new AliDetSwitch("DIPO",   3, 2, 2, kStructure, false);
30   AddDetSwitch(detSwitch); 
31   detSwitch = new AliDetSwitch("FRAME",  3, 2, 2, kStructure, false);
32   AddDetSwitch(detSwitch); 
33   detSwitch = new AliDetSwitch("HALL",   1, 0, 0, kStructure);
34   AddDetSwitch(detSwitch); 
35   detSwitch = new AliDetSwitch("MAG",    1, 0, 0, kStructure);
36   AddDetSwitch(detSwitch); 
37   detSwitch = new AliDetSwitch("PIPE",   5, 0, 0, kStructure);
38   AddDetSwitch(detSwitch); 
39   detSwitch = new AliDetSwitch("SHIL",   1, 0, 0, kStructure);
40   AddDetSwitch(detSwitch); 
41   detSwitch = new AliDetSwitch("CASTOR", 2, 1, 1);
42   AddDetSwitch(detSwitch); 
43   detSwitch = new AliDetSwitch("FMD",    2, 0, 0);
44   AddDetSwitch(detSwitch); 
45   detSwitch = new AliDetSwitch("ITS",    7, 5, 5);
46   AddDetSwitch(detSwitch); 
47   detSwitch = new AliDetSwitch("MUON",   2, 1, 1);
48   AddDetSwitch(detSwitch); 
49   detSwitch = new AliDetSwitch("PHOS",   5, 1, 1);
50   AddDetSwitch(detSwitch); 
51   detSwitch = new AliDetSwitch("PMD",    3, 1, 1);
52   AddDetSwitch(detSwitch); 
53   detSwitch = new AliDetSwitch("RICH",   3, 1, 1);
54   AddDetSwitch(detSwitch); 
55   detSwitch = new AliDetSwitch("START",  2, 1, 1);
56   AddDetSwitch(detSwitch); 
57   detSwitch = new AliDetSwitch("TOF",    5, 2, 2, kDetector, false);
58   AddDetSwitch(detSwitch); 
59   detSwitch = new AliDetSwitch("TPC",    4, 2, 2);
60   AddDetSwitch(detSwitch); 
61   detSwitch = new AliDetSwitch("TRD",    2, 1, 1, kDetector, false);
62   AddDetSwitch(detSwitch); 
63   detSwitch = new AliDetSwitch("ZDC",    2, 1, 1, kDetector, false);
64   AddDetSwitch(detSwitch);  
65 }
66
67 //_____________________________________________________________________________
68 AliDetConstruction::AliDetConstruction(const AliDetConstruction& right)
69   : AliModulesComposition(right)
70 {
71   // AliModuleComposition is protected from copying
72 }  
73
74 //_____________________________________________________________________________
75 AliDetConstruction::~AliDetConstruction() {
76 //
77 }
78
79 // operators
80
81 //_____________________________________________________________________________
82 AliDetConstruction& 
83 AliDetConstruction::operator=(const AliDetConstruction& right)
84 {
85   // check assignement to self
86   if (this == &right) return *this;
87
88   // base class assignement
89   // AliModuleComposition is protected from assigning
90   AliModulesComposition::operator=(right);
91
92   return *this;  
93 }    
94           
95 // private methods
96
97 //_____________________________________________________________________________
98 void AliDetConstruction::BuildDetectors()
99 {
100 // Create module constructions for AliModules 
101 // that have been created and registered by gAlice 
102 // ---
103
104   TObjArray* pDetectors = gAlice->Detectors();
105   TIter next(pDetectors);
106
107   // the first AliModule is expected to be the top volume
108   AliModule *module = (AliModule*)next();
109   if (G4String(module->GetName()) != "BODY") {
110     G4String text = "AliDetConstruction::BuildDetectors():\n";
111     text = text + "    Instead of BODY - the first module ";
112     text = text + module->GetName() + " has been found.";
113     AliGlobals::Exception(text);
114   }  
115   AddSingleModuleConstruction("BODY", 0, kStructure);
116
117   G4bool first = true;
118   while ((module = (AliModule*)next())) {
119     // register moduleConstruction in fDetSwitchVector
120     // in order to keep availability of /AlDet/list command
121     G4String modName = module->GetName();
122     G4int modVersion = module->IsVersion();
123     if (first)
124       // skip registering of the top volume 
125       first = false;
126     else 
127       SwitchDetOn(modName, modVersion);
128  
129     // all modules will be processed alltogether
130     AddMoreModuleConstruction(modName, modVersion);
131
132     G4cout << "Created module construction for " 
133            << modName << "v" << modVersion << "." << G4endl;   
134   }
135   
136   // do not process Config.C 
137   // (it was processed when creating modules by gAlice)
138   SetProcessConfigToModules(false);     
139 }
140
141 //_____________________________________________________________________________
142 void AliDetConstruction::CreateDetectors()
143 {
144 // Creates AliModules and their module constructions 
145 // according to the fDetSwitchVector
146 // ---
147
148   // add top volume (AliBODY) construction first
149   AddSingleModuleConstruction("BODY", 0, kStructure);
150
151   // add modules constructions
152   for (G4int id=0; id<fDetSwitchVector.size(); id++)
153   {
154     G4String detName = fDetSwitchVector[id]->GetDetName();
155     G4int version = fDetSwitchVector[id]->GetSwitchedVersion();
156     G4bool isStandalone = fDetSwitchVector[id]->IsStandalone();
157     AliModuleType type = fDetSwitchVector[id]->GetType();
158     
159     if (version > -1)
160       if (isStandalone)
161         AddSingleModuleConstruction(detName, version, type);
162       else
163         AddMoreModuleConstruction(detName, version, type);
164   }    
165 }
166
167 //_____________________________________________________________________________
168 void AliDetConstruction::CheckDetDependencies()
169 {
170 // Checks modules dependencies.
171 // Dependent modules FRAME, TOF, TRD 
172 // TOF always requires FRAMEv1
173 // TRD can be built with both (??)
174 // ZDC requires DIPO
175 // ---
176
177   // get switched versions of dependent modules
178   G4int verTOF = GetDetSwitch("TOF")->GetSwitchedVersion(); 
179   G4int verTRD = GetDetSwitch("TRD")->GetSwitchedVersion(); 
180   G4int verZDC = GetDetSwitch("ZDC")->GetSwitchedVersion(); 
181   G4int verFRAME = GetDetSwitch("FRAME")->GetSwitchedVersion(); 
182   
183   // check dependencies  
184   if (verTOF > -1) {
185     // TOF requires FRAMEv1 - obsolete? 
186     if (verFRAME != 2) {
187       GetDetSwitch("FRAME")->SwitchOn(2);
188       G4String text = "AliDetConstruction::CheckDetDependencies: \n";
189       text = text + "    Switched TOF requires FRAME v1.\n"; 
190       text = text + "    The det switch for FRAME has been changed."; 
191       AliGlobals::Warning(text);
192     }  
193   }
194   if (verTRD > -1) {
195     // TRD requires FRAME
196     verFRAME = GetDetSwitch("FRAME")->GetSwitchedVersion(); 
197     if (verFRAME < 0) {
198       GetDetSwitch("FRAME")->SwitchOnDefault();
199       G4String text = "AliDetConstruction::CheckDetDependencies: \n";
200       text = text + "    Switched TRD requires FRAME.\n"; 
201       text = text + "    The det switch for FRAME has been changed."; 
202       AliGlobals::Warning(text);
203     }  
204   }  
205   if (verZDC > 0) {
206     // ZDC requires PIPE, ABSO, DIPO, SHIL 
207     G4int verPIPE = GetDetSwitch("PIPE")->GetSwitchedVersion(); 
208     G4int verABSO = GetDetSwitch("ABSO")->GetSwitchedVersion(); 
209     G4int verDIPO = GetDetSwitch("DIPO")->GetSwitchedVersion(); 
210     G4int verSHIL = GetDetSwitch("SHIL")->GetSwitchedVersion(); 
211     if ( verPIPE != 1 || verABSO !=0 || verDIPO == -1 || verSHIL == -1) {
212       G4String text = "AliDetConstruction::CheckDetDependencies: \n";
213       text = text + "    Switched ZDC requires PIPE, ABSO, DIPO and SHIL.\n"; 
214       if (verPIPE == -1) {
215         GetDetSwitch("PIPE")->SwitchOnDefault();
216         text = text + "    The det switch for PIPE has been changed.\n"; 
217       }  
218       if (verABSO == -1) {
219         GetDetSwitch("ABSO")->SwitchOnDefault();
220         text = text + "    The det switch for ABSO has been changed.\n"; 
221       }  
222       if (verDIPO == -1) {
223         GetDetSwitch("DIPO")->SwitchOnDefault();
224         text = text + "    The det switch for DIPO has been changed.\n"; 
225       }  
226       if (verSHIL == -1) {
227         GetDetSwitch("SHIL")->SwitchOnDefault();
228         text = text + "    The det switch for SHIL has been changed."; 
229       }  
230       AliGlobals::Warning(text);
231     }  
232   }    
233 }  
234
235 // public methods
236
237 //_____________________________________________________________________________
238 G4VPhysicalVolume* AliDetConstruction::Construct()
239 {
240 // Constructs geometry.
241 // This method is called by G4RunManager in initialization.
242 // ---
243
244   if (gAlice->Modules()->GetLast() < 0) {
245     // create geometry (including AliModules) according to 
246     // the fDetSwitchVector
247     CheckDetDependencies();
248     CreateDetectors();
249   }   
250   else {
251     // create geometry for AliModules 
252     // that have been created and registered by gAlice 
253     BuildDetectors();
254   }  
255   // construct modules geometry
256   ConstructModules();
257
258   return AliSingleModuleConstruction::GetWorld();      
259 }
260