]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliModulesComposition.cxx
Modify tmaxfd in media definition
[u/mrichter/AliRoot.git] / AliGeant4 / AliModulesComposition.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // See the class description in the header file.
5
6 #include "AliModulesComposition.h"
7 #include "AliModulesCompositionMessenger.h"
8 #include "AliSingleModuleConstruction.h"
9 #include "AliMoreModulesConstruction.h"
10 #include "AliDetSwitch.h"
11 #include "AliMagneticField.h"
12 #include "AliGlobals.h"
13 #include "AliFiles.h"
14
15 #include "TG4GeometryManager.h"
16 #include "TG4XMLGeometryGenerator.h"
17
18 #include <G4Material.hh>
19 #include <G4VPhysicalVolume.hh>
20
21 AliModulesComposition::AliModulesComposition()
22   : fAllLVSensitive(false),
23     fForceAllLVSensitive(true),
24     fReadGeometry(false),
25     fWriteGeometry(false),
26     fMagneticField(0)    
27 {
28 //
29   fMoreModulesConstruction = new AliMoreModulesConstruction();
30   fMessenger = new AliModulesCompositionMessenger(this);
31 }
32
33 AliModulesComposition::AliModulesComposition(const AliModulesComposition& right)
34 {
35 //
36   AliGlobals::Exception("AliModulesComposition is protected from copying.");  
37 }
38
39 AliModulesComposition::~AliModulesComposition() {
40 //   
41   delete fMoreModulesConstruction;
42   delete fMagneticField;
43   delete fMessenger; 
44   
45   // destroy det switch vector
46   fDetSwitchVector.clearAndDestroy();  
47   
48   // destroy det construction vector
49   fModuleConstructionVector.clearAndDestroy();
50 }
51
52 // operators
53
54 AliModulesComposition& 
55 AliModulesComposition::operator=(const AliModulesComposition& right)
56 {
57   // check assignement to self
58   if (this == &right) return *this;
59   
60   AliGlobals::Exception("AliModulesComposition is protected from assigning.");  
61
62   return *this;  
63 }    
64           
65 // protected methods
66
67 void AliModulesComposition::AddDetSwitch(AliDetSwitch* detSwitch)
68 {
69 // Adds detSwitch to the detSwitch vector.
70 // ---
71
72   fDetSwitchVector.insert(detSwitch);
73   fMessenger->SetCandidates();
74 }  
75   
76 void AliModulesComposition::AddSingleModuleConstruction(G4String moduleName, 
77                                G4int version, AliModuleType moduleType)
78 {
79 // Adds SingleModuleConstruction.
80 // ---
81
82   AliSingleModuleConstruction* moduleConstruction
83     = new AliSingleModuleConstruction(moduleName, version, moduleType);
84   fModuleConstructionVector.insert(moduleConstruction);
85 }  
86                   
87 void AliModulesComposition::AddMoreModuleConstruction(G4String moduleName, 
88                                G4int version, AliModuleType moduleType)
89 {
90 // Adds module to MoreModulesConstruction (construction of dependent
91 // modules.)
92 // ---
93
94   fMoreModulesConstruction->AddModule(moduleName, version, moduleType);
95 }  
96                                   
97 void AliModulesComposition::ConstructModules()
98 {
99 // Construct geometry of all modules (both standalone and dependent.)
100 // ---
101
102   // set common options
103   SetReadGeometryToModules(fReadGeometry);
104   SetWriteGeometryToModules(fWriteGeometry);
105   SetAllLVSensitiveToModules(fAllLVSensitive);
106      // common setAllLVSensitive is overridden by Config.in
107      // macro
108   
109   // one module constructions
110   G4int nofDets = fModuleConstructionVector.entries();
111   G4int i;
112   for (i=0; i<nofDets; i++) {
113     fModuleConstructionVector[i]->Configure(*AliFiles::Instance());
114   }  
115   if (fForceAllLVSensitive)
116     SetAllLVSensitiveToModules(fForceAllLVSensitive);
117       // override the setAllLVSensitive by Config.in macro
118       // if required
119      
120   for (i=0; i<nofDets; i++) {
121     G4cout << "Module " << fModuleConstructionVector[i]->GetDetName()
122            << " will be constructed now." << G4endl;
123     fModuleConstructionVector[i]->Construct();
124   }  
125     
126   // more modules construction
127   G4int nofModules = fMoreModulesConstruction->GetNofModules();
128   if (nofModules>0) {
129     fMoreModulesConstruction->Configure(*AliFiles::Instance());
130     if (fForceAllLVSensitive)
131       SetAllLVSensitiveToModules(fForceAllLVSensitive);
132         // override the setAllLVSensitive by Config.in macro
133         // if required
134
135     G4cout << "Dependent modules will be constructed now." << G4endl;
136     fMoreModulesConstruction->Construct();
137   }  
138     
139   // fill medium Id vector
140   TG4GeometryManager::Instance()->FillMediumIdVector();
141         // this step can be done only after the sensitive
142         // detectors have been created
143 }  
144
145 void AliModulesComposition::SetReadGeometryToModules(G4bool readGeometry)
146 {
147 // Sets readGeometry control to all modules.
148 // ---
149
150   // single module constructions
151   G4int nofDets = fModuleConstructionVector.entries();
152   G4int i;
153   for (i=0; i<nofDets; i++)
154     fModuleConstructionVector[i]->SetReadGeometry(readGeometry);
155
156   // more modules construction
157   nofDets = fMoreModulesConstruction->GetNofModules();
158   for (i=0; i<nofDets; i++) { 
159     AliSingleModuleConstruction* moduleConstruction
160       = fMoreModulesConstruction->GetModuleConstruction(i);
161     moduleConstruction->SetReadGeometry(readGeometry);
162   }  
163 }    
164   
165 void AliModulesComposition::SetWriteGeometryToModules(G4bool writeGeometry)
166 {
167 // Sets writeGeometry control to all modules.
168 // ---
169
170   // single module constructions
171   G4int nofDets = fModuleConstructionVector.entries();
172   G4int i;
173   for (i=0; i<nofDets; i++)
174     fModuleConstructionVector[i]->SetWriteGeometry(writeGeometry);
175
176   // more modules construction
177   nofDets = fMoreModulesConstruction->GetNofModules();
178   for (i=0; i<nofDets; i++) { 
179     AliSingleModuleConstruction* moduleConstruction
180       = fMoreModulesConstruction->GetModuleConstruction(i);
181     moduleConstruction->SetWriteGeometry(writeGeometry);
182   }  
183 }    
184
185 void AliModulesComposition::SetAllLVSensitiveToModules(G4bool allSensitive)
186 {
187 // Sets setAllSensitive control to all modules.
188 // ---
189
190   // single module constructions
191   G4int nofDets = fModuleConstructionVector.entries();
192   G4int i;
193   for (i=0; i<nofDets; i++)
194     fModuleConstructionVector[i]->SetAllLVSensitive(allSensitive);
195
196   // more modules construction
197   nofDets = fMoreModulesConstruction->GetNofModules();
198   for (i=0; i<nofDets; i++) { 
199     AliSingleModuleConstruction* moduleConstruction
200       = fMoreModulesConstruction->GetModuleConstruction(i);
201     moduleConstruction->SetAllLVSensitive(allSensitive);
202   }  
203 }    
204
205 void AliModulesComposition::SetProcessConfigToModules(G4bool processConfig)
206 {
207 // Sets processConfig control to all modules.
208 // ---
209
210   // single module constructions
211   G4int nofDets = fModuleConstructionVector.entries();
212   G4int i;
213   for (i=0; i<nofDets; i++)
214     fModuleConstructionVector[i]->SetProcessConfig(processConfig);
215   
216   // more modules construction
217   nofDets = fMoreModulesConstruction->GetNofModules();
218   for (i=0; i<nofDets; i++) { 
219     AliSingleModuleConstruction* moduleConstruction
220       = fMoreModulesConstruction->GetModuleConstruction(i);
221     moduleConstruction->SetProcessConfig(processConfig);
222   }    
223 }    
224
225 // public methods
226
227 void AliModulesComposition::SwitchDetOn(G4String moduleNameVer)
228
229 // Switchs on module specified by name and version.
230 // ---
231
232   G4int nofDets = fDetSwitchVector.entries(); 
233   if (moduleNameVer == "ALL") {
234     for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnDefault(); 
235   }
236   else if (moduleNameVer == "PPR") {
237     for (G4int id=0; id<nofDets; id++) fDetSwitchVector[id]->SwitchOnPPR(); 
238     AliFiles::Instance()->SetMacroName("ConfigPPR");
239   }
240   else if (moduleNameVer == "NONE") {
241     for (G4int id=0; id<nofDets; id++)
242       fDetSwitchVector[id]->SwitchOff(); 
243   }
244   else {
245     // get version number
246     G4int len = moduleNameVer.length();
247     G4String moduleName = moduleNameVer(0, len-1);
248     G4String version = moduleNameVer(len-1, 1);
249     G4int iVersion = AliGlobals::StringToInt(version);
250
251     if (iVersion < 0) {
252       // in case the version number is not provided
253       // the default one is set
254       SwitchDetOnDefault(moduleNameVer);
255     }  
256     else 
257       SwitchDetOn(moduleName, iVersion);
258   }
259 }
260
261 void AliModulesComposition::SwitchDetOn(G4String moduleName, G4int version)
262
263 // Switchs on module specified by name and version.
264 // ---
265
266   G4int nofDets = fDetSwitchVector.entries(); 
267   for (G4int id=0; id<nofDets; id++) {
268     G4String iDetName = fDetSwitchVector[id]->GetDetName();
269     if (iDetName == moduleName) {
270       fDetSwitchVector[id]->SwitchOn(version);
271       return;
272     }
273   }
274   AliGlobals::Exception(
275     "AliModulesComposition: Wrong detector name for " + moduleName + ".");
276 }
277
278 void AliModulesComposition::SwitchDetOnDefault(G4String moduleName)
279
280 // Switchs on module specified by name with default version.
281 // ---
282
283   G4int nofDets = fDetSwitchVector.entries(); 
284   for (G4int id=0; id<nofDets; id++) {
285     G4String iDetName = fDetSwitchVector[id]->GetDetName();
286     if (iDetName == moduleName) {
287       fDetSwitchVector[id]->SwitchOnDefault();
288       return;
289     }
290   }
291   AliGlobals::Exception(
292     "AliModulesComposition: Wrong detector name for " + moduleName + ".");
293 }
294
295 void AliModulesComposition::SwitchDetOnPPR(G4String moduleName)
296
297 // Switchs on module specified by name with PPR version.
298 // ---
299
300   G4int nofDets = fDetSwitchVector.entries(); 
301   for (G4int id=0; id<nofDets; id++) {
302     G4String iDetName = fDetSwitchVector[id]->GetDetName();
303     if (iDetName == moduleName) {
304       fDetSwitchVector[id]->SwitchOnPPR();
305       return;
306     }
307   }
308   AliGlobals::Exception(
309     "AliModulesComposition: Wrong detector name for " + moduleName + ".");
310 }
311
312 void AliModulesComposition::SwitchDetOff(G4String moduleName)
313
314 // Switchs off module specified by name.
315 // ---
316
317   G4int nofDets = fDetSwitchVector.entries(); 
318   if (moduleName == "ALL") {
319     for (G4int id=0; id<nofDets; id++)
320       fDetSwitchVector[id]->SwitchOff(); 
321   }
322   else {
323     for (G4int id=0; id<nofDets; id++) {
324       G4String iDetName = fDetSwitchVector[id]->GetDetName();
325       if (iDetName == moduleName) { 
326         fDetSwitchVector[id]->SwitchOff();
327         return;
328       }
329     }
330   }
331   AliGlobals::Exception(
332     "AliModulesComposition: Wrong detector name for " + moduleName + ".");
333 }
334
335 void AliModulesComposition::PrintSwitchedDets() const
336
337 // Lists switched detectors.
338 // ---
339
340   G4String svList = GetSwitchedDetsList();
341     
342   G4cout << "Switched Alice detectors: " << G4endl;
343   G4cout << "--------------------------" << G4endl;
344   G4cout << svList << G4endl;
345 }
346
347 void AliModulesComposition::PrintAvailableDets() const
348
349 // Lists available detectors.
350 // ---
351
352   G4String avList = GetAvailableDetsList();
353     
354   G4cout << "Available Alice detectors: " << G4endl;
355   G4cout << "---------------------------" << G4endl;
356   G4cout << avList << G4endl;
357 }
358
359 void AliModulesComposition::PrintMaterials() const
360 {
361 // Prints all materials.
362 // ---
363
364   const G4MaterialTable* matTable = G4Material::GetMaterialTable();
365   G4cout << *matTable;
366 }
367
368 void AliModulesComposition::GenerateXMLGeometry() const 
369 {
370 // Generates XML geometry file from the top volume.
371 // The file name is set according the last switched detector
372 // registered in the det switch vector.
373 // ---
374
375   G4VPhysicalVolume* world = AliSingleModuleConstruction::GetWorld();
376
377   // XML filename
378   // according to last switched detector
379   G4String detName;
380   G4int version = -1;
381   for (G4int i=fDetSwitchVector.entries()-1; i>=0; i--) {
382     version = fDetSwitchVector[i]->GetSwitchedVersion();
383     if (version > -1) {
384       detName = fDetSwitchVector[i]->GetDetName();
385       break;
386     }  
387   }  
388   G4String filePath 
389     = AliFiles::Instance()->GetXMLFilePath(detName, version);
390   
391   // set top volume name
392   G4String topName = world->GetName() + "_comp";
393   
394   // generate XML
395   
396   TG4XMLGeometryGenerator xml;
397   xml.OpenFile(filePath);
398
399   // generate materials 
400   // not yet implemented
401   // xml.GenerateMaterials(version, "today", "Generated from G4",
402   //                     "v4", world->GetLogicalVolume());
403
404   // generate volumes tree
405   xml.GenerateSection(detName, version, "today", "Generated from Geant4",
406                       topName, world->GetLogicalVolume());
407   xml.CloseFile();
408   
409   // set verbose
410   G4cout << "File " << detName << "v" << version << ".xml has been generated." 
411          << G4endl;
412 }  
413
414
415 G4String AliModulesComposition::GetSwitchedDetsList() const
416
417 // Returns list of switched detectors.
418 // ---
419
420   G4String svList = "";
421   
422   G4int nofDets = fDetSwitchVector.entries(); 
423   G4int nofSwitchedDets = 0;
424   for (G4int id=0; id<nofDets; id++) {
425     G4int iVersion = fDetSwitchVector[id]->GetSwitchedVersion();
426     if (iVersion > -1) {
427       nofSwitchedDets++;
428       G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
429       AliGlobals::AppendNumberToString(moduleNameVer, iVersion);
430       svList += moduleNameVer;
431       svList += " "; 
432     }
433   }
434
435   if (nofSwitchedDets ==  nofDets) svList = "ALL: " + svList;
436   if (nofSwitchedDets ==  0)       svList = "NONE";   
437
438   return svList;
439 }
440
441 const G4RWTPtrOrderedVector<AliDetSwitch>& 
442 AliModulesComposition::GetDetSwitchVector() const
443 {
444 // Returns detSwitch vector.
445 // ---
446
447   //const AliDetSwitchVector& vector = fDetSwitchVector;
448   const G4RWTPtrOrderedVector<AliDetSwitch>& vector = fDetSwitchVector;
449   return vector;
450 }  
451
452 G4String AliModulesComposition::GetAvailableDetsList() const
453
454 // Returns list of available detectors.
455 // ---
456
457   G4String svList = "";
458   
459   G4int nofDets = fDetSwitchVector.entries(); 
460   for (G4int id=0; id<nofDets; id++) {
461     G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
462     for (G4int iv=0; iv<nofVersions; iv++) {
463       G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
464       AliGlobals::AppendNumberToString(moduleNameVer, iv);
465       svList += moduleNameVer;
466       svList += " ";
467     }
468   }
469
470   return svList;
471 }
472
473 G4String AliModulesComposition::GetAvailableDetsListWithCommas() const
474
475 // Returns list of available detectors with commas.
476 // ---
477
478   G4String svList = "";
479   
480   G4int nofDets = fDetSwitchVector.entries(); 
481   for (G4int id=0; id<nofDets; id++) {
482     G4int nofVersions = fDetSwitchVector[id]->GetNofVersions();
483     for (G4int iv=0; iv<nofVersions; iv++) {
484       G4String moduleNameVer = fDetSwitchVector[id]->GetDetName();
485       AliGlobals::AppendNumberToString(moduleNameVer, iv);
486       svList += moduleNameVer;
487       if (iv<nofVersions-1)    svList += "/";
488       else if (id < nofDets-1) svList += ", ";
489     }
490   }
491
492   return svList;
493 }
494
495 G4String AliModulesComposition::GetDetNamesList() const
496
497 // Returns list of detector names.
498 // ---
499
500   G4String svList = "";
501   
502   G4int nofDets = fDetSwitchVector.entries(); 
503   for (G4int id=0; id<nofDets; id++) { 
504     svList += fDetSwitchVector[id]->GetDetName();
505     svList += " ";
506   }
507
508   return svList;
509 }
510
511 G4String AliModulesComposition::GetDetNamesListWithCommas() const
512
513 // Returns list of detector names with commas.
514 // ---
515
516   G4String svList = "";
517   
518   G4int nofDets = fDetSwitchVector.entries(); 
519   for (G4int id=0; id<nofDets; id++) { 
520     svList += fDetSwitchVector[id]->GetDetName();
521     if (id < nofDets-1) svList += ", ";
522   }
523
524   return svList;
525 }
526
527 void AliModulesComposition::SetMagField(G4double fieldValue)
528 {
529 // Sets uniform magnetic field to specified value.
530 // ---
531
532   // create fields if it does not exist
533   if (!fMagneticField) fMagneticField = new AliMagneticField();
534   
535   // set value
536   fMagneticField->SetFieldValue(fieldValue);
537 }
538