Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
17R__LOAD_LIBRARY(libGeom);
18R__LOAD_LIBRARY(libROOTEve);
19
20namespace REX = ROOT::Experimental;
21
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 b1s->SetMainTransparency(30);
31 holder->AddElement(b1s);
32}
33
34
35void filterChildNodes(TGeoNode* pn, REX::REveTrans& trans, REX::REveElement* holder, std::string mat, int maxlevel, int level)
36{
37 ++level;
38 if (level > maxlevel)
39 return;
40
41 for (int i = 0; i < pn->GetNdaughters(); ++i)
42 {
43 TGeoNode* n = pn->GetDaughter(i);
44 TGeoMaterial* material = n->GetVolume()->GetMaterial();
45 REX::REveTrans ctrans;
46 ctrans.SetFrom(trans.Array());
47
48 {
49 TGeoMatrix *gm = n->GetMatrix();
50 const Double_t *rm = gm->GetRotationMatrix();
51 const Double_t *tv = gm->GetTranslation();
53 t(1,1) = rm[0]; t(1,2) = rm[1]; t(1,3) = rm[2];
54 t(2,1) = rm[3]; t(2,2) = rm[4]; t(2,3) = rm[5];
55 t(3,1) = rm[6]; t(3,2) = rm[7]; t(3,3) = rm[8];
56 t(1,4) = tv[0]; t(2,4) = tv[1]; t(3,4) = tv[2];
57 ctrans *= t;
58 }
59
60 std::string mn = material->GetName();
61 if (mn == mat) {
62 n->ls();
63 makeEveGeoShape(n, ctrans, holder);
64 }
65 filterChildNodes(n, ctrans,holder, mat, maxlevel, level);
66 }
67}
68
69TGeoNode* getNodeFromPath( TGeoNode* top, std::string path)
70{
71 TGeoNode* node = top;
72 istringstream f(path);
73 string s;
74 while (getline(f, s, '/'))
75 node = node->GetVolume()->FindNode(s.c_str());
76
77 return node;
78}
79
81{
82
83 auto eveMng = REX::REveManager::Create();
84
86
87 auto geoManager = eveMng->GetGeometry("http://root.cern.ch/files/cms.root");
88 TGeoNode* top = geoManager->GetTopVolume()->FindNode("CMSE_1");
89
90 // tracker
91 {
92 auto holder = new REX::REveElement("Tracker");
94 TGeoNode* n = getNodeFromPath(top, "TRAK_1/SVTX_1/TGBX_1/GAW1_1");
95 REX::REveTrans trans;
96 std::string material = "TOB_Silicon";
97 filterChildNodes(n, trans, holder, material, 6, 0);
98 }
99
100 // muon
101 {
102 auto holder = new REX::REveElement("MUON");
103 eveMng->GetGlobalScene()->AddElement(holder);
104
105 auto n = getNodeFromPath(top, "MUON_1/MB_1");
106
107 std::string material = "M_B_Air";
108 REX::REveTrans trans;
109 filterChildNodes(n, trans, holder, material, 1, 0);
110
111 auto bv = n->GetVolume();
112 for (int i = 1; i < 5; ++i ) {
113 auto n = bv->FindNode(Form("MBXC_%d",i));
114 auto gss = n->GetVolume()->GetShape();
115 auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
116 b1s->InitMainTrans();
117 const double* move = n->GetMatrix()->GetTranslation();
118 b1s->RefMainTrans().SetFrom( *(n->GetMatrix()));
119 b1s->SetShape(gss);
120 b1s->SetMainColor(kBlue);
121 holder->AddElement(b1s);
122 }
123 }
124
125 eveMng->Show();
126}
#define f(i)
Definition RSha256.hxx:104
double Double_t
Definition RtypesCore.h:59
#define R__LOAD_LIBRARY(LIBRARY)
Definition Rtypes.h:491
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
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.
void SetFrom(Double_t *carr)
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:332
Base class describing materials.
Geometrical transformation package.
Definition TGeoMatrix.h:38
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:39
TGeoVolume * GetVolume() const
Definition TGeoNode.h:99
Int_t GetNdaughters() const
Definition TGeoNode.h:91
TGeoNode * GetDaughter(Int_t ind) const
Definition TGeoNode.h:83
Int_t FindNode(const TGeoNode *node, Int_t level)
Search for a node within the branch of this one.
Definition TGeoNode.cxx:411
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:47
ROOT::Experimental::REveManager * eveMng
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
Definition geom_cms.C:69
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:35
void geom_cms()
Definition geom_cms.C:80
const Int_t n
Definition legend1.C:16