Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
geom_alice_its.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_eve
3 /// Shows geometry of ALICE ITS.
4 ///
5 /// \image html eve_geom_alice_its.png
6 /// \macro_code
7 ///
8 /// \author Matevz Tadel
9 
10 #include "TEveManager.h"
11 #include "TEveGeoNode.h"
12 
13 #include "TGeoManager.h"
14 #include "TGeoNode.h"
15 #include "TGeoVolume.h"
16 #include "TGeoMedium.h"
17 
18 #include "TString.h"
19 
20 void geom_alice_its()
21 {
22  TEveManager::Create();
23 
24  gGeoManager = gEve->GetGeometry("http://root.cern.ch/files/alice.root");
25 
26  TGeoNode* node = gGeoManager->GetTopVolume()->FindNode("ITSV_1");
27  TEveGeoTopNode* its = new TEveGeoTopNode(gGeoManager, node);
28  gEve->AddGlobalElement(its);
29 
30  gEve->Redraw3D(kTRUE);
31 }
32 
33 
34 //==============================================================================
35 // Demonstrate extraction of volumes matching certain criteria.
36 //==============================================================================
37 
38 // Should be run in compiled mode -- CINT has issues with recursion.
39 //
40 // 1. Creation:
41 // root
42 // .L geom_alice_its.C+
43 // extract_ssd_modules()
44 // .q
45 // This creates file "test-extract.root" in current dir.
46 //
47 // 2. Viewing:
48 // root
49 // .x show_extract.C("test-extract.root")
50 
51 TEveGeoNode* descend_extract(TGeoNode* node)
52 {
53  // We only return something if:
54  // - this is a node of interest;
55  // - one of the daughters returns something of interest.
56 
57  const TString material("ITS_SI$");
58 
59  TEveGeoNode *res = 0;
60 
61  auto medium = node->GetVolume()->GetMedium();
62  if (medium && material == medium->GetName()) {
63  // Node of interest - instantiate eve representation and return.
64  res = new TEveGeoNode(node);
65  return res;
66  }
67 
68  Int_t nd = node->GetNdaughters();
69  for (Int_t i = 0; i < nd; ++i) {
70  auto ed = descend_extract(node->GetDaughter(i));
71 
72  if (ed) {
73  if (res == 0) res = new TEveGeoNode(node);
74  res->AddElement(ed);
75  }
76  }
77 
78  return res;
79 }
80 
81 void extract_ssd_modules()
82 {
83  const TString kEH("extract_ssd_modules");
84 
85  TEveManager::Create();
86 
87  gGeoManager = gEve->GetGeometry("http://root.cern.ch/files/alice.root");
88 
89  Bool_t s = gGeoManager->cd("/ITSV_1/ITSD_1/IT56_1");
90  if (!s) {
91  Error(kEH, "Start node not found.");
92  return;
93  }
94 
95  auto node = gGeoManager->GetCurrentNode();
96 
97  TEveGeoNode *egn = descend_extract(node);
98 
99  if (egn == 0) {
100  Warning(kEH, "No matching nodes found.");
101  return;
102  }
103 
104  egn->SaveExtract("test-extract.root", "AliSDD", kTRUE);
105 }