Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Loading...
Searching...
No Matches
geom_cms.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3///
4/// \macro_code
5///
6
7#include <sstream>
8#include <iostream>
9
10#include "TGeoManager.h"
11#include "TGeoVolume.h"
12#include "TGeoMaterial.h"
13#include "TGeoMatrix.h"
14#include "TSystem.h"
15#include "TFile.h"
16#include <ROOT/REveGeoShape.hxx>
17#include <ROOT/REveTrans.hxx>
18#include <ROOT/REveScene.hxx>
19#include <ROOT/REveViewer.hxx>
20#include <ROOT/REveElement.hxx>
21#include <ROOT/REveManager.hxx>
22
23namespace REX = ROOT::Experimental;
24
26{
27 auto gss = n->GetVolume()->GetShape();
28 auto b1s = new REX::REveGeoShape(n->GetName());
29 b1s->InitMainTrans();
30 b1s->RefMainTrans().SetFrom(trans.Array());
31 b1s->SetShape(gss);
32 b1s->SetMainColor(kCyan);
33 holder->AddElement(b1s);
34}
35
37 int level)
38{
39 ++level;
40 if (level > maxlevel)
41 return;
42
43 for (int i = 0; i < pn->GetNdaughters(); ++i) {
44 TGeoNode *n = pn->GetDaughter(i);
45 TGeoMaterial *material = n->GetVolume()->GetMaterial();
47 ctrans.SetFrom(trans.Array());
48
49 {
50 TGeoMatrix *gm = n->GetMatrix();
51 const Double_t *rm = gm->GetRotationMatrix();
52 const Double_t *tv = gm->GetTranslation();
54 t(1, 1) = rm[0];
55 t(1, 2) = rm[1];
56 t(1, 3) = rm[2];
57 t(2, 1) = rm[3];
58 t(2, 2) = rm[4];
59 t(2, 3) = rm[5];
60 t(3, 1) = rm[6];
61 t(3, 2) = rm[7];
62 t(3, 3) = rm[8];
63 t(1, 4) = tv[0];
64 t(2, 4) = tv[1];
65 t(3, 4) = tv[2];
66 ctrans *= t;
67 }
68
69 std::string mn = material->GetName();
70 if (mn == mat) {
71 n->ls();
73 }
75 }
76}
77
78TGeoNode *getNodeFromPath(TGeoNode *top, std::string path)
79{
80 TGeoNode *node = top;
81 istringstream f(path);
82 string s;
83 while (getline(f, s, '/'))
84 node = node->GetVolume()->FindNode(s.c_str());
85
86 return node;
87}
88
90{
91
92 auto eveMng = REX::REveManager::Create();
93
95
96 auto geoManager = eveMng->GetGeometry("http://root.cern/files/cms.root");
97 TGeoNode *top = geoManager->GetTopVolume()->FindNode("CMSE_1");
98
99 // tracker
100 {
101 auto holder = new REX::REveElement("Tracker");
103 TGeoNode *n = getNodeFromPath(top, "TRAK_1/SVTX_1/TGBX_1/GAW1_1");
104 REX::REveTrans trans;
105 std::string material = "TOB_Silicon";
106 filterChildNodes(n, trans, holder, material, 6, 0);
107 }
108
109 // muon
110 {
111 auto holder = new REX::REveElement("MUON");
113
114 auto n = getNodeFromPath(top, "MUON_1/MB_1");
115
116 std::string material = "M_B_Air";
117 REX::REveTrans trans;
118 filterChildNodes(n, trans, holder, material, 1, 0);
119
120 auto bv = n->GetVolume();
121 for (int i = 1; i < 5; ++i) {
122 auto n = bv->FindNode(Form("MBXC_%d", i));
123 auto gss = n->GetVolume()->GetShape();
124 auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
125 b1s->InitMainTrans();
126 const double *move = n->GetMatrix()->GetTranslation();
127 b1s->RefMainTrans().SetFrom(*(n->GetMatrix()));
128 b1s->SetShape(gss);
129 b1s->SetMainColor(kBlue);
130 holder->AddElement(b1s);
131 }
132 }
133
134 eveMng->Show();
135}
#define f(i)
Definition RSha256.hxx:104
double Double_t
Definition RtypesCore.h:59
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2489
virtual void AddElement(REveElement *el)
Add el to the list of children.
TGeoManager * GetGeometry(const TString &filename)
Get geometry with given filename.
REveScene * GetGlobalScene() const
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4673
Base class describing materials.
Geometrical transformation package.
Definition TGeoMatrix.h:38
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
TGeoVolume * GetVolume() const
Definition TGeoNode.h:99
TGeoNode * FindNode(const char *name) const
search a daughter inside the list of nodes
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
ROOT::Experimental::REveManager * eveMng
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
Definition geom_cms.C:78
void makeEveGeoShape(TGeoNode *n, REX::REveTrans &trans, REX::REveElement *holder)
Definition geom_cms.C:25
void filterChildNodes(TGeoNode *pn, REX::REveTrans &trans, REX::REveElement *holder, std::string mat, int maxlevel, int level)
Definition geom_cms.C:36
void geom_cms()
Definition geom_cms.C:89
const Int_t n
Definition legend1.C:16