]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONGeometryViewingHelper.C
In AliMUONPairLight, AliMUONTrackLight:
[u/mrichter/AliRoot.git] / MUON / MUONGeometryViewingHelper.C
CommitLineData
fce55b81 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16// $Id$
17//
18/// \ingroup macros
19/// \file MUONGeometryViewingHelper.C
20/// \brief Macro providing methods helping in viewing geometry
21///
22/// To be run from aliroot:
23/// <pre>
24/// root[0] .x MUONGeometryViewingHelper.C
25/// root[0] buildGeometry();
26/// </pre>
27///
28/// \author: I. Hrivnacova, IPN Orsay
29
30#if !defined(__CINT__) || defined(__MAKECINT__)
31
fce55b81 32#include <Riostream.h>
33#include <TObjArray.h>
34#include <TBrowser.h>
35#include <TGeoManager.h>
36#include <TGeoVolume.h>
37
38#endif
39
40
41void visibilityOff()
42{
43/// Set all volumes invisible
44
45 TObjArray* volumes = gGeoManager->GetListOfVolumes();
f20eff09 46 for (Int_t i=0; i<volumes->GetEntriesFast(); i++) {
47 if ( !((TGeoVolume*)volumes->At(i))->IsAssembly() )
48 ((TGeoVolume*)volumes->At(i))->SetVisibility(kFALSE);
49 }
fce55b81 50
51}
52
53
54void setVisibility(const TString& volumeName, Bool_t visibility= kTRUE)
55{
56/// Set visibility to the volume specified by name
57
58 TGeoVolume* volume = gGeoManager->FindVolumeFast(volumeName.Data());
59
60 if ( ! volume ) {
61 cerr << "Volume " << volumeName.Data() << " not found." << endl;
62 return;
63 }
64
65 volume->SetVisibility(visibility);
66}
67
68void setDaughtersVisibility(const TString& volumeName, Bool_t visibility= kTRUE)
69{
70/// Set visibility to daughter of the volume specified by name.
71/// If the daughter volume is an assembly the visibility setting
72/// is propagated to its real volumes daughters.
73
74 TGeoVolume* volume = gGeoManager->FindVolumeFast(volumeName.Data());
75
76 if ( ! volume ) {
77 cerr << "Volume " << volumeName.Data() << " not found." << endl;
78 return;
79 }
80
81 //for ( Int_t i=0; i<10; i++ ) {
82 Int_t colourNo = 1;
83 for ( Int_t i=0; i<volume->GetNdaughters(); i++ ) {
84
85 TGeoVolume* dvolume = volume->GetNode(i)->GetVolume();
86 if ( dvolume->IsAssembly() ) {
87 // Do no set visibility to assembly but to its daughters
88 setDaughtersVisibility(dvolume->GetName(), visibility);
89 }
90 else {
91 cout << "Setting visibility to " << dvolume->GetName() << endl;
92 dvolume->SetVisibility(visibility);
93
94 // change colors
95 ++colourNo;
96 if ( colourNo > 9 ) colourNo = 1;
97 dvolume->SetLineColor(colourNo);
98 }
99 }
100}
101
102void buildGeometry(Bool_t allVisible = kFALSE )
103{
b9e49362 104/// Load geometry from the file, make all volumes invisible
fce55b81 105
b9e49362 106 TGeoManager::Import("geometry.root");
fce55b81 107
108 new TBrowser();
109
110 if ( ! allVisible ) visibilityOff();
111
112 gGeoManager->SetVisLevel(10);
113 gGeoManager->GetTopVolume()->SetVisContainers(kTRUE);
114 gGeoManager->GetTopVolume()->Draw("ogl");
115
116 cout << endl;
117 cout << "You can now add volumes in the scene: " << endl;
118 cout << " setVisibility(\"MyVolume\") " << endl;
119 cout << " setDaughtersVisibility(\"MyVolume\") " << endl;;
120 cout << "or remove them from the scene: " << endl;
121 cout << " setVisibility(\"MyVolume\", kFALSE);" << endl;
122 cout << " setDaughtersVisibility(\"MyVolume\", kFALSE);" << endl;
123 cout << endl;
124}