Logo ROOT   6.18/05
Reference Guide
geom_cms.C
Go to the documentation of this file.
1#include <sstream>
2#include <iostream>
3
4#include "TGeoManager.h"
5#include "TGeoVolume.h"
6#include "TGeoMaterial.h"
7#include "TGeoMatrix.h"
8#include "TSystem.h"
9#include "TFile.h"
10#include <ROOT/REveGeoShape.hxx>
11#include <ROOT/REveTrans.hxx>
12#include <ROOT/REveScene.hxx>
13#include <ROOT/REveViewer.hxx>
14#include <ROOT/REveElement.hxx>
15#include <ROOT/REveManager.hxx>
16
18R__LOAD_LIBRARY(libROOTEve);
19
20namespace REX = ROOT::Experimental;
21
22void makeEveGeoShape(TGeoNode* n, REX::REveTrans& trans, REX::REveElement* holder)
23{
24 auto gss = n->GetVolume()->GetShape();
25 auto b1s = new REX::REveGeoShape(n->GetName());
26 b1s->InitMainTrans();
27 b1s->RefMainTrans().SetFrom(trans.Array());
28 b1s->SetShape(gss);
29 b1s->SetMainColor(kCyan);
30 holder->AddElement(b1s);
31}
32
33
34void filterChildNodes(TGeoNode* pn, REX::REveTrans& trans, REX::REveElement* holder, std::string mat, int maxlevel, int level)
35{
36 ++level;
37 if (level > maxlevel)
38 return;
39
40 for (int i = 0; i < pn->GetNdaughters(); ++i)
41 {
42 TGeoNode* n = pn->GetDaughter(i);
43 TGeoMaterial* material = n->GetVolume()->GetMaterial();
44 REX::REveTrans ctrans;
45 ctrans.SetFrom(trans.Array());
46
47 {
48 TGeoMatrix *gm = n->GetMatrix();
49 const Double_t *rm = gm->GetRotationMatrix();
50 const Double_t *tv = gm->GetTranslation();
51 REX::REveTrans t;
52 t(1,1) = rm[0]; t(1,2) = rm[1]; t(1,3) = rm[2];
53 t(2,1) = rm[3]; t(2,2) = rm[4]; t(2,3) = rm[5];
54 t(3,1) = rm[6]; t(3,2) = rm[7]; t(3,3) = rm[8];
55 t(1,4) = tv[0]; t(2,4) = tv[1]; t(3,4) = tv[2];
56 ctrans *= t;
57 }
58
59 std::string mn = material->GetName();
60 if (mn == mat) {
61 n->ls();
62 makeEveGeoShape(n, ctrans, holder);
63 }
64 filterChildNodes(n, ctrans,holder, mat, maxlevel, level);
65 }
66}
67
68TGeoNode* getNodeFromPath( TGeoNode* top, std::string path)
69{
70 TGeoNode* node = top;
71 istringstream f(path);
72 string s;
73 while (getline(f, s, '/'))
74 node = node->GetVolume()->FindNode(s.c_str());
75
76 return node;
77}
78
80{
81
82 auto eveMng = REX::REveManager::Create();
83
85
86 auto geoManager = eveMng->GetGeometry("http://root.cern.ch/files/cms.root");
87 TGeoNode* top = geoManager->GetTopVolume()->FindNode("CMSE_1");
88
89 // tracker
90 {
91 auto holder = new REX::REveElement("Tracker");
92 eveMng->GetGlobalScene()->AddElement(holder);
93 TGeoNode* n = getNodeFromPath(top, "TRAK_1/SVTX_1/TGBX_1/GAW1_1");
94 REX::REveTrans trans;
95 std::string material = "TOB_Silicon";
96 filterChildNodes(n, trans, holder, material, 6, 0);
97 }
98
99 // muon
100 {
101 auto holder = new REX::REveElement("MUON");
102 eveMng->GetGlobalScene()->AddElement(holder);
103
104 auto n = getNodeFromPath(top, "MUON_1/MB_1");
105
106 std::string material = "M_B_Air";
107 REX::REveTrans trans;
108 filterChildNodes(n, trans, holder, material, 1, 0);
109
110 auto bv = n->GetVolume();
111 for (int i = 1; i < 5; ++i ) {
112 auto n = bv->FindNode(Form("MBXC_%d",i));
113 auto gss = n->GetVolume()->GetShape();
114 auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
115 b1s->InitMainTrans();
116 const double* move = n->GetMatrix()->GetTranslation();
117 b1s->RefMainTrans().SetFrom( *(n->GetMatrix()));
118 b1s->SetShape(gss);
119 b1s->SetMainColor(kBlue);
120 holder->AddElement(b1s);
121 }
122 }
123
124 eveMng->Show();
125}
#define f(i)
Definition: RSha256.hxx:104
double Double_t
Definition: RtypesCore.h:55
@ kCyan
Definition: Rtypes.h:64
@ kBlue
Definition: Rtypes.h:64
char * Form(const char *fmt,...)
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition: TFile.h:316
Base class describing materials.
Definition: TGeoMaterial.h:31
Geometrical transformation package.
Definition: TGeoMatrix.h:41
virtual const Double_t * GetTranslation() const =0
virtual const Double_t * GetRotationMatrix() const =0
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition: TGeoNode.h:41
TGeoVolume * GetVolume() const
Definition: TGeoNode.h:94
Int_t GetNdaughters() const
Definition: TGeoNode.h:90
TGeoNode * GetDaughter(Int_t ind) const
Definition: TGeoNode.h:82
Int_t FindNode(const TGeoNode *node, Int_t level)
Search for a node within the branch of this one.
Definition: TGeoNode.cxx:412
TGeoNode * FindNode(const char *name) const
search a daughter inside the list of nodes
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
REX::REveManager * eveMng
R__LOAD_LIBRARY(libGeom)
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
Definition: geom_cms.C:68
void makeEveGeoShape(TGeoNode *n, REX::REveTrans &trans, REX::REveElement *holder)
Definition: geom_cms.C:22
void filterChildNodes(TGeoNode *pn, REX::REveTrans &trans, REX::REveElement *holder, std::string mat, int maxlevel, int level)
Definition: geom_cms.C:34
void geom_cms()
Definition: geom_cms.C:79
const Int_t n
Definition: legend1.C:16
static constexpr double s