4 // Author: I. Hrivnacova
6 // Class AliModuleConstruction
7 // ---------------------------
8 // See the class description in the header file.
10 #include "AliModuleConstruction.h"
11 #include "AliGlobals.h"
12 #include "AliLVStructure.h"
13 #include "AliModule.h"
14 #ifdef ALICE_VISUALIZE
15 #include "AliColourStore.h"
18 #include "TG4GeometryServices.h"
20 #include <G4LogicalVolumeStore.hh>
21 #include <G4LogicalVolume.hh>
22 #ifdef ALICE_VISUALIZE
23 #include <G4Colour.hh>
24 #include <G4VisAttributes.hh>
27 //_____________________________________________________________________________
28 AliModuleConstruction::AliModuleConstruction(const G4String& moduleName)
29 : fModuleName(moduleName),
30 fModuleFrameName(moduleName),
34 fWriteGeometry(false),
36 fMessenger(this, moduleName) {
40 //_____________________________________________________________________________
41 AliModuleConstruction::AliModuleConstruction(const AliModuleConstruction& right)
42 : fMessenger(this, right.fModuleName)
49 //_____________________________________________________________________________
50 AliModuleConstruction::AliModuleConstruction()
56 fWriteGeometry(false),
58 fMessenger(this, "") {
62 //_____________________________________________________________________________
63 AliModuleConstruction::~AliModuleConstruction()
71 //_____________________________________________________________________________
72 AliModuleConstruction&
73 AliModuleConstruction::operator=(const AliModuleConstruction& right)
75 // check assignement to self
76 if (this == &right) return *this;
78 fModuleName = right.fModuleName;
79 fModuleFrameName = right.fModuleFrameName;
80 fModuleFrameLV = right.fModuleFrameLV;
81 fAliModule = right.fAliModule;
82 fReadGeometry = right.fReadGeometry;
83 fWriteGeometry = right.fWriteGeometry;
84 fDataFilePath = right.fDataFilePath;
85 //fMessenger = right.fMessenger;
90 //_____________________________________________________________________________
92 AliModuleConstruction::operator==(const AliModuleConstruction& right) const
98 //_____________________________________________________________________________
100 AliModuleConstruction::operator!=(const AliModuleConstruction& right) const
103 G4int returnValue = 1;
104 if (*this == right) returnValue = 0;
111 //_____________________________________________________________________________
112 void AliModuleConstruction::RegisterLogicalVolume(
113 G4LogicalVolume* lv, const G4String& path,
114 AliLVStructure& lvStructure) const
116 // Registers logical volume lv in the structure.
119 G4String lvName = lv->GetName();
120 lvStructure.AddNewVolume(lv, path);
122 // register daughters
123 G4int nofDaughters = lv->GetNoDaughters();
124 if (nofDaughters>0) {
125 G4String previousName = "";
126 for (G4int i=0; i<nofDaughters; i++) {
127 G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume();
128 G4String currentName = lvd->GetName();
129 if (currentName != lvName && currentName != previousName) {
130 G4String newPath = path + lvName +"/";
131 RegisterLogicalVolume(lvd, newPath, lvStructure);
132 previousName = currentName;
140 //_____________________________________________________________________________
141 void AliModuleConstruction::SetDetFrame(G4bool warn)
143 // The logical volume with name identical with
144 // fModuleName is retrieved from G4LogicalVolumeStore.
148 = TG4GeometryServices::Instance()->FindLogicalVolume(fModuleFrameName, true);
150 if (fModuleFrameLV == 0 && warn) {
151 G4String text = "AliModuleConstruction: Detector frame for ";
152 text = text + fModuleFrameName + " has not been found.";
153 AliGlobals::Warning(text);
157 //_____________________________________________________________________________
158 void AliModuleConstruction::SetDetFrame(const G4String& frameName, G4bool warn)
160 // The logical volume with frameName
161 // is retrieved from G4LogicalVolumeStore.
164 fModuleFrameName = frameName;
168 //_____________________________________________________________________________
169 void AliModuleConstruction::ListAllLVTree() const
171 // Lists all logical volumes tree if the frame logical volume
176 ListLVTree(fModuleFrameLV->GetName());
178 G4String text = "AliModuleConstruction::ListAllLVTree:\n";
179 text = text + " Detector frame is not defined.";
180 AliGlobals::Warning(text);
184 //_____________________________________________________________________________
185 void AliModuleConstruction::ListAllLVTreeLong() const
187 // Lists all logical volume tree if the frame logical volume
188 // is defined with numbers of daughters (physical volumes).
192 ListLVTreeLong(fModuleFrameLV->GetName());
194 G4String text = "AliModuleConstruction::ListAllLVTreeLong:\n";
195 text = text + " Detector frame is not defined.";
196 AliGlobals::Warning(text);
200 //_____________________________________________________________________________
201 void AliModuleConstruction::ListLVTree(const G4String& lvName) const
203 // Lists logical volumes tree (daughters) of the logical volume
204 // with specified lvName.
208 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
213 AliLVStructure lvStructure(path);
214 RegisterLogicalVolume(lv, path, lvStructure);
215 lvStructure.ListTree();
219 //_____________________________________________________________________________
220 void AliModuleConstruction::ListLVTreeLong(const G4String& lvName) const
222 // Lists logical volumes tree (daughters) of the logical volume
223 // with specified lvName with numbers of daughters (physical volumes).
227 = TG4GeometryServices::Instance()->FindLogicalVolume(lvName);
231 AliLVStructure lvStructure(path);
232 RegisterLogicalVolume(lv, path, lvStructure);
233 lvStructure.ListTreeLong();
237 #ifdef ALICE_VISUALIZE
239 //_____________________________________________________________________________
240 void AliModuleConstruction::SetDetVisibility(G4bool visibility) const
242 // Sets visibility to all detector logical volumes if
243 // frame logical volume is defined.
247 SetLVTreeVisibility(fModuleFrameLV, visibility);
249 G4String text = "AliModuleConstruction::SetDetVisibility:\n";
250 text = text + " Detector frame is not defined.";
251 AliGlobals::Warning(text);
256 //_____________________________________________________________________________
257 void AliModuleConstruction::SetLVTreeVisibility(G4LogicalVolume* lv,
258 G4bool visibility) const
260 // Sets visibility to the logical volumes tree (daughters) of
261 // the logical volume lv.
266 AliLVStructure lvStructure(path);
267 RegisterLogicalVolume(lv, path, lvStructure);
268 lvStructure.SetTreeVisibility(visibility);
272 //_____________________________________________________________________________
273 void AliModuleConstruction::SetVolumeVisibility(G4LogicalVolume* lv,
274 G4bool visibility) const
276 // Sets visibility to the specified logical volume.
280 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
281 G4VisAttributes* newVisAttributes;
282 if (kpVisAttributes) {
283 G4Colour oldColour = kpVisAttributes->GetColour();
284 newVisAttributes = new G4VisAttributes(oldColour);
287 newVisAttributes = new G4VisAttributes();
288 delete kpVisAttributes;
290 newVisAttributes->SetVisibility(visibility);
292 lv->SetVisAttributes(newVisAttributes);
296 //_____________________________________________________________________________
297 void AliModuleConstruction::SetDetColour(G4String colName) const
299 // Sets colour to all detector logical volumes if
300 // frame logical volume is defined.
304 SetLVTreeColour(fModuleFrameLV, colName);
306 G4String text = "AliModuleConstruction::SetDetColour:\n";
307 text = text + " Detector frame is not defined.";
308 AliGlobals::Warning(text);
312 //_____________________________________________________________________________
313 void AliModuleConstruction::SetLVTreeColour(G4LogicalVolume* lv,
314 const G4String& colName) const
316 // Sets colour to the logical volumes tree (daughters) of
317 // the logical volume lv.
322 AliLVStructure lvStructure(path);
323 RegisterLogicalVolume(lv, path, lvStructure);
324 lvStructure.SetTreeVisibility(true);
325 lvStructure.SetTreeColour(colName);
329 //_____________________________________________________________________________
330 void AliModuleConstruction::SetVolumeColour(G4LogicalVolume* lv,
331 const G4String& colName) const
333 // Sets colour to the specified logical volume.
337 const G4VisAttributes* kpVisAttributes = lv->GetVisAttributes ();
338 delete kpVisAttributes;
340 G4VisAttributes* newVisAttributes = new G4VisAttributes();
342 AliColourStore* pColours = AliColourStore::Instance();
343 const G4Colour kColour = pColours->GetColour(colName);
344 newVisAttributes->SetVisibility(true);
345 newVisAttributes->SetColour(kColour);
347 lv->SetVisAttributes(newVisAttributes);
351 #endif //ALICE_VISUALIZE