]> git.uio.no Git - u/mrichter/AliRoot.git/blame - MUON/MUONGeometryViewingHelper.C
Main changes:
[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
32#include "AliMpCDB.h"
33
34#include "AliRun.h"
35
36#include <Riostream.h>
37#include <TObjArray.h>
38#include <TBrowser.h>
39#include <TGeoManager.h>
40#include <TGeoVolume.h>
41
42#endif
43
44
45void visibilityOff()
46{
47/// Set all volumes invisible
48
49 TObjArray* volumes = gGeoManager->GetListOfVolumes();
50 for (Int_t i=0; i<volumes->GetEntriesFast(); i++)
51 ((TGeoVolume*)volumes->At(i))->SetVisibility(kFALSE);
52
53}
54
55
56void setVisibility(const TString& volumeName, Bool_t visibility= kTRUE)
57{
58/// Set visibility to the volume specified by name
59
60 TGeoVolume* volume = gGeoManager->FindVolumeFast(volumeName.Data());
61
62 if ( ! volume ) {
63 cerr << "Volume " << volumeName.Data() << " not found." << endl;
64 return;
65 }
66
67 volume->SetVisibility(visibility);
68}
69
70void setDaughtersVisibility(const TString& volumeName, Bool_t visibility= kTRUE)
71{
72/// Set visibility to daughter of the volume specified by name.
73/// If the daughter volume is an assembly the visibility setting
74/// is propagated to its real volumes daughters.
75
76 TGeoVolume* volume = gGeoManager->FindVolumeFast(volumeName.Data());
77
78 if ( ! volume ) {
79 cerr << "Volume " << volumeName.Data() << " not found." << endl;
80 return;
81 }
82
83 //for ( Int_t i=0; i<10; i++ ) {
84 Int_t colourNo = 1;
85 for ( Int_t i=0; i<volume->GetNdaughters(); i++ ) {
86
87 TGeoVolume* dvolume = volume->GetNode(i)->GetVolume();
88 if ( dvolume->IsAssembly() ) {
89 // Do no set visibility to assembly but to its daughters
90 setDaughtersVisibility(dvolume->GetName(), visibility);
91 }
92 else {
93 cout << "Setting visibility to " << dvolume->GetName() << endl;
94 dvolume->SetVisibility(visibility);
95
96 // change colors
97 ++colourNo;
98 if ( colourNo > 9 ) colourNo = 1;
99 dvolume->SetLineColor(colourNo);
100 }
101 }
102}
103
104void buildGeometry(Bool_t allVisible = kFALSE )
105{
b9e49362 106/// Load geometry from the file, make all volumes invisible
fce55b81 107
b9e49362 108 TGeoManager::Import("geometry.root");
fce55b81 109
110 new TBrowser();
111
112 if ( ! allVisible ) visibilityOff();
113
114 gGeoManager->SetVisLevel(10);
115 gGeoManager->GetTopVolume()->SetVisContainers(kTRUE);
116 gGeoManager->GetTopVolume()->Draw("ogl");
117
118 cout << endl;
119 cout << "You can now add volumes in the scene: " << endl;
120 cout << " setVisibility(\"MyVolume\") " << endl;
121 cout << " setDaughtersVisibility(\"MyVolume\") " << endl;;
122 cout << "or remove them from the scene: " << endl;
123 cout << " setVisibility(\"MyVolume\", kFALSE);" << endl;
124 cout << " setDaughtersVisibility(\"MyVolume\", kFALSE);" << endl;
125 cout << endl;
126}