]> git.uio.no Git - u/mrichter/AliRoot.git/blob - AliGeant4/AliSingleModuleConstruction.cxx
added methods FillHit(), FillPHOSHit(); LoadHistograms()
[u/mrichter/AliRoot.git] / AliGeant4 / AliSingleModuleConstruction.cxx
1 // $Id$
2 // Category: geometry
3 //
4 // Author: I. Hrivnacova
5 //
6 // Class AliSingleModuleConstruction
7 // ---------------------------------
8 // See the class description in the header file.
9
10 #include "AliSingleModuleConstruction.h"
11 #include "AliGlobals.h"
12 #include "AliFiles.h"
13 #include "AliRun.h"
14 #include "AliModule.h"
15
16 #include "TG4GeometryManager.h"
17
18 #include <G4UImanager.hh>
19 //#include <G4Element.hh>
20
21 #include <TROOT.h> 
22 #include <TCint.h> 
23
24 G4VPhysicalVolume* AliSingleModuleConstruction::fgWorld = 0;
25
26 //_____________________________________________________________________________
27 AliSingleModuleConstruction::AliSingleModuleConstruction(
28                                 G4String moduleName, G4int version,
29                                 AliModuleType moduleType)
30   : AliModuleConstruction(moduleName),
31     fVersion(version),
32     fType(moduleType),
33     fProcessConfig(true)
34 {
35 //
36 }
37
38 //_____________________________________________________________________________
39 AliSingleModuleConstruction::AliSingleModuleConstruction(
40                                 const AliSingleModuleConstruction& right)
41   : AliModuleConstruction(right)                                
42 {
43 //
44   // copy stuff
45   *this = right;
46 }
47
48 //_____________________________________________________________________________
49 AliSingleModuleConstruction::AliSingleModuleConstruction() {
50 //
51 }
52
53 //_____________________________________________________________________________
54 AliSingleModuleConstruction::~AliSingleModuleConstruction() {
55 //
56 }
57
58 // operators
59
60 //_____________________________________________________________________________
61 AliSingleModuleConstruction& 
62 AliSingleModuleConstruction::operator=(const AliSingleModuleConstruction& right)
63 {    
64   // check assignement to self
65   if (this == &right) return *this;
66   
67   // base class assignement
68   AliModuleConstruction::operator=(right);
69   
70   fVersion = right.fVersion;
71   fType = right.fType;
72   fProcessConfig = right.fProcessConfig;
73  
74   return *this;
75 }
76
77 // public methods 
78
79 //_____________________________________________________________________________
80 void AliSingleModuleConstruction::Configure(const AliFiles& files)
81
82 // Executes the detector setup Root macro
83 // (extracted from AliRoot Config.C) and
84 // G4 macro.
85 // ---
86
87   // filepaths and macro names 
88   G4bool isStructure = (fType == kStructure);
89   G4String rootFilePath 
90     = files.GetRootMacroPath(fModuleName, isStructure);
91   G4String g4FilePath
92     = files.GetG4MacroPath(fModuleName, isStructure);
93   fDataFilePath 
94     = files.GetG3CallsDatPath(fModuleName, fVersion, isStructure); 
95   
96   // load and execute aliroot config macro
97   if (fProcessConfig) {
98     gROOT->LoadMacro(rootFilePath);
99     G4String macroName = files.GetDefaultMacroName();
100     //macroName = macroName + "_" + fModuleName;
101     macroName = macroName + "(";
102     AliGlobals::AppendNumberToString(macroName, fVersion);
103     macroName = macroName + ")";
104     gInterpreter->ProcessLine(macroName);
105   } 
106   
107   // process g4 config macro
108   G4String command = "/control/execute ";
109   G4UImanager* pUI = G4UImanager::GetUIpointer();  
110   pUI->ApplyCommand(command + g4FilePath);
111   
112   // get AliModule created in Config.C macro
113   fAliModule = gAlice->GetModule(fModuleName);
114   if (!fAliModule) {
115     G4String text = "AliSingleModuleConstruction::Configure:\n";
116     text = text + "    AliModule " + fModuleName;
117     text = text + " has not been found in gAlice.";
118     AliGlobals::Exception(text);
119   }  
120 }
121
122 //_____________________________________________________________________________
123 void AliSingleModuleConstruction::Construct()
124
125 // Constructs geometry.
126 // ---
127
128   // print default element table
129   // const G4ElementTable* table = G4Element::GetElementTable();
130   // G4cout << "Default elemnt table: " << G4endl;
131   // for (G4int i=0; i<table->entries(); i++) {
132   //   G4cout << *(*table)[i] << G4endl;
133   // }  
134
135   // Configure();
136
137   // get geometry manager
138   TG4GeometryManager* pGeometryManager = TG4GeometryManager::Instance();
139
140   // register module name in the name map
141   pGeometryManager->SetMapSecond(fAliModule->GetName());        
142
143   if (fReadGeometry) {
144     // create G3 geometry from g3calls.dat
145     pGeometryManager->SetWriteGeometry(false);
146     pGeometryManager->ReadG3Geometry(fDataFilePath);
147   }
148   else {
149     // set geometry output stream for this module
150     pGeometryManager->SetWriteGeometry(fWriteGeometry);
151     if (fWriteGeometry) 
152       pGeometryManager->OpenOutFile(fDataFilePath);
153
154     // create geometry from AliRoot
155
156     // construct materials
157     fAliModule->CreateMaterials();
158
159     // construct G3 geometry
160     fAliModule->CreateGeometry();
161         
162     if (fWriteGeometry) 
163       pGeometryManager->CloseOutFile();
164   }  
165   
166   // construct G4 geometry
167   G4VPhysicalVolume* world = pGeometryManager->CreateG4Geometry();
168   if (!fgWorld) fgWorld = world; 
169   
170   // set the detector frame (envelope)
171   // (without warning output if enevelope is not defined)
172   SetDetFrame(false);
173
174   // construct geometry for display
175   fAliModule->BuildGeometry();
176
177   // reset TG4GeometryManager 
178   pGeometryManager->ClearG3Tables();
179
180 #ifdef ALICE_VISUALIZE
181   if (GetDetFrame()) {
182     // set visualization attributes
183     // if detector envelope is defined
184     SetDetVisibility(true);
185     SetDetColour("Yellow");
186   }  
187 #endif
188 }