Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
write_geo_extract.C
Go to the documentation of this file.
1
5#include "TFile.h"
6
7#include <set>
8#include <vector>
9#include <iostream>
10
11
12// \file
13/// \ingroup tutorial_eve7
14/// Helper script to create REveGeoShapeExtract fro TGeo geometry
15/// One can rely on GeoTable to access paths
16/// \macro_code
17///
18/// \author Alja Mrak Tadel
19
20using namespace ROOT::Experimental;
21
22REveGeoShape *makeShape(const std::string &targetPath, const char* name)
23{
24 // for the moment top node is tracker at the startup
25
26 TGeoIterator next(gGeoManager->GetTopVolume());
27 TGeoNode *currentNode;
28
29 while ((currentNode = next())) {
30 TString currentPath;
31 next.GetPath(currentPath); // Retrieves the full hierarchy path
32 // std::cout << "compare" << currentPath << "\n";
33 if (currentPath == targetPath) {
34 // Found the node via path matching
35 printf("Node found: %s\n", currentNode->GetName());
36 break;
37 }
38 }
39
40 const TGeoMatrix *mat = next.GetCurrentMatrix();
41 const Double_t *t = mat->GetTranslation(); // size 3
42 const Double_t *r = mat->GetRotationMatrix(); // size 9 (3x3)
43
44 Double_t m[16];
45 if (mat->IsScale()) {
46 const Double_t *s = mat->GetScale();
47 m[0] = r[0] * s[0];
48 m[1] = r[3] * s[0];
49 m[2] = r[6] * s[0];
50 m[3] = 0;
51 m[4] = r[1] * s[1];
52 m[5] = r[4] * s[1];
53 m[6] = r[7] * s[1];
54 m[7] = 0;
55 m[8] = r[2] * s[2];
56 m[9] = r[5] * s[2];
57 m[10] = r[8] * s[2];
58 m[11] = 0;
59 m[12] = t[0];
60 m[13] = t[1];
61 m[14] = t[2];
62 m[15] = 1;
63 } else {
64 m[0] = r[0];
65 m[1] = r[3];
66 m[2] = r[6];
67 m[3] = 0;
68 m[4] = r[1];
69 m[5] = r[4];
70 m[6] = r[7];
71 m[7] = 0;
72 m[8] = r[2];
73 m[9] = r[5];
74 m[10] = r[8];
75 m[11] = 0;
76 m[12] = t[0];
77 m[13] = t[1];
78 m[14] = t[2];
79 m[15] = 1;
80 }
81
82 TGeoShape *shape = currentNode->GetVolume()->GetShape();
83 shape->SetName(name);
84 REveGeoShape* rgs = new REveGeoShape(name);
85 rgs->SetShape(shape);
86
87 rgs->InitMainTrans();
88 rgs->RefMainTrans().SetFrom(m);
89 return rgs;
90}
91
92void write_geo_extract()
93{
95
97 // eveMng->AllowMultipleRemoteConnections(false, false);
98 auto s_geoManager = TGeoManager::Import("http://xrd-cache-1.t2.ucsd.edu/alja/mail/geo/cmsSimGeo2026.root");
99
100 // tracker wrapper
101 REveGeoShape *tracker = makeShape("cms:OCMS/tracker:Tracker_1/otst:supportR1190Z1450_1", "tracker");
102 tracker->SetMainColor(kRed);
103 tracker->SetMainTransparency(50);
104
105 // tracker barrel
106 REveGeoShape *barrel =
107 makeShape("cms:OCMS/tracker:Tracker_1/pixbar:Phase2OTBarrel_1/tracker:supportR212Z604_1", "barrel");
108 tracker->AddElement(barrel);
109
110 // front and back endcaps
111 REveGeoShape *e1 = makeShape("cms:OCMS/tracker:Tracker_1/pixfwd:Phase2OTForward_1", "endcap_1");
112 tracker->AddElement(e1);
113 REveGeoShape *e2 = makeShape("cms:OCMS/tracker:Tracker_1/pixfwd:Phase2OTForward_2", "endcap_2");
114 tracker->AddElement(e2);
115
116 // save extract on top element
117 tracker->SaveExtract("testShapeExtract.root", "VSDGeo");
118
119 eveMng->GetEventScene()->AddElement(tracker);
120 eveMng->Show();
121}
ROOT::R::TRInterface & r
Definition Object.C:4
double Double_t
Double 8 bytes.
Definition RtypesCore.h:73
@ kRed
Definition Rtypes.h:67
char name[80]
Definition TGX11.cxx:148
externTGeoManager * gGeoManager
Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TG...
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
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:4328
A geometry iterator.
Definition TGeoNode.h:249
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
Geometrical transformation package.
Definition TGeoMatrix.h:39
Bool_t IsScale() const
Definition TGeoMatrix.h:68
virtual const Double_t * GetTranslation() const =0
virtual const Double_t * GetScale() 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:100
Base abstract class for all shapes.
Definition TGeoShape.h:25
TGeoShape * GetShape() const
Definition TGeoVolume.h:191
const char * GetName() const override
Returns name of object.
Definition TNamed.h:49
virtual void SetName(const char *name)
Set the name of the TNamed.
Definition TNamed.cxx:149
Basic string class.
Definition TString.h:138
ROOT::Experimental::REveManager * eveMng
Namespace for ROOT features in testing.
Definition TROOT.h:100
TMarker m
Definition textangle.C:8