Logo ROOT   6.16/01
Reference Guide
projection_prescale.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 "TRandom.h"
11#include <ROOT/REveGeoShape.hxx>
12#include <ROOT/REveTrans.hxx>
13#include <ROOT/REveScene.hxx>
14#include <ROOT/REveViewer.hxx>
15#include <ROOT/REveElement.hxx>
16#include <ROOT/REveManager.hxx>
17#include <ROOT/REvePointSet.hxx>
18#include <ROOT/REveLine.hxx>
19
20#include <ROOT/REveProjectionManager.hxx>
21#include <ROOT/REveProjectionBases.hxx>
23R__LOAD_LIBRARY(libROOTEve);
24
25namespace REX = ROOT::Experimental;
26
27REX::REvePointSet* getPointSet(int npoints = 2, float s=2, int color=28)
28{
29 TRandom &r = *gRandom;
30
31 auto ps = new REX::REvePointSet("testPnts", npoints);
32
33 for (Int_t i=0; i<npoints; ++i)
34 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
35
36 ps->SetMarkerColor(color);
37 ps->SetMarkerSize(3+r.Uniform(1, 2));
38 // ps->SetMarkerStyle(4);
39 return ps;
40}
41
42void makeProjectedViewsAndScene(REX::REveProjection::EPType_e type, bool scale)
43{
44 auto rPhiGeomScene = REX::gEve->SpawnNewScene(Form("Project%s Geo", scale ? "PreScaled" : ""));
45 auto rPhiEventScene = REX::gEve->SpawnNewScene(Form("Project%s Event", scale ? "PreScaled" : ""));
46
47 auto mngRhoPhi = new REX::REveProjectionManager(type);
48 if (scale) {
49 REX::REveProjection* p = mngRhoPhi->GetProjection();
50 p->AddPreScaleEntry(0, 0, 4); // r scale 4 from 0
51 p->AddPreScaleEntry(0, 45, 1); // r scale 1 from 45
52 p->AddPreScaleEntry(0, 310, 0.5);
53 p->SetUsePreScale(kTRUE);
54 }
55 auto rphiView = REX::gEve->SpawnNewViewer("Projected View", "");
56 rphiView->AddScene(rPhiGeomScene);
57 rphiView->AddScene(rPhiEventScene);
58
59 for (auto & ie : REX::gEve->GetGlobalScene()->RefChildren())
60 mngRhoPhi->ImportElements(ie, rPhiGeomScene);
61
62 for (auto & ie : REX::gEve->GetEventScene()->RefChildren())
63 mngRhoPhi->ImportElements(ie, rPhiEventScene);
64}
65
66TGeoNode* getNodeFromPath( TGeoNode* top, std::string path)
67{
68 TGeoNode* node = top;
69 istringstream f(path);
70 string s;
71 while (getline(f, s, '/'))
72 node = node->GetVolume()->FindNode(s.c_str());
73
74 return node;
75}
76
77
78void projection_prescale(std::string type = "RhPhi")
79{
80 REX::REveManager::Create();
81
82 // static scene
84 auto geoManager = REX::gEve->GetGeometry("http://root.cern.ch/files/cms.root");
85 TGeoNode* top = geoManager->GetTopVolume()->FindNode("CMSE_1");
86 auto holder = new REX::REveElementList("MUON");
88 auto n = getNodeFromPath(top, "MUON_1/MB_1");
89 auto m = new REX::REveGeoShape("MB_1");
90 m->SetShape(n->GetVolume()->GetShape());
91 m->SetMainColor(kOrange);
92 holder->AddElement(m);
93
94 auto bv = n->GetVolume();
95 for (int i = 1; i < 5; ++i ) {
96
97 auto n = bv->FindNode(Form("MBXC_%d",i));
98 auto gss = n->GetVolume()->GetShape();
99 auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
100 b1s->InitMainTrans();
101 const double* move = n->GetMatrix()->GetTranslation();
102 b1s->RefMainTrans().SetFrom( *(n->GetMatrix()));
103 b1s->SetShape(gss);
104 b1s->SetMainColor(kBlue);
105 holder->AddElement(b1s);
106 }
107
108 // event scene
109 auto line = new REX::REveLine();
110 line->SetNextPoint(0, 0, 0);
111 float a = 300;
112 line->SetNextPoint(a, a, a);
114
115 auto line2 = new REX::REveLine();
116 line2->SetNextPoint(0, 0, 0);
117 float b = 30;
118 line2->SetNextPoint(b, b+5, b);
119 line2->SetMainColor(kRed);
121
122 auto points = getPointSet(10, 30);
124
125 // make scaled and plain projected views
126 if (type == "RPhi") {
127 makeProjectedViewsAndScene(REX::REveProjection::kPT_RPhi, true);
128 makeProjectedViewsAndScene(REX::REveProjection::kPT_RPhi, false);
129 }
130 else {
131 makeProjectedViewsAndScene(REX::REveProjection::kPT_RhoZ, true);
132 makeProjectedViewsAndScene(REX::REveProjection::kPT_RhoZ, false);
133 }
134}
135
ROOT::R::TRInterface & r
Definition: Object.C:4
#define b(i)
Definition: RSha256.hxx:100
#define f(i)
Definition: RSha256.hxx:104
int Int_t
Definition: RtypesCore.h:41
const Bool_t kTRUE
Definition: RtypesCore.h:87
@ kRed
Definition: Rtypes.h:63
@ kOrange
Definition: Rtypes.h:64
@ kBlue
Definition: Rtypes.h:63
R__EXTERN TEveManager * gEve
Definition: TEveManager.h:243
int type
Definition: TGX11.cxx:120
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
char * Form(const char *fmt,...)
point * points
Definition: X3DBuffer.c:22
virtual void AddElement(TEveElement *el)
Add el to the list of children.
TEveScene * GetGlobalScene() const
Definition: TEveManager.h:147
TEveViewer * SpawnNewViewer(const char *name, const char *title="", Bool_t embed=kTRUE)
Create a new GL viewer.
TGeoManager * GetGeometry(const TString &filename)
Get geometry with given filename.
TEveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
TEveScene * GetEventScene() const
Definition: TEveManager.h:148
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition: TFile.h:316
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 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
This is the base class for the ROOT Random number generators.
Definition: TRandom.h:27
REX::REveScene * rPhiGeomScene
Definition: collection.C:33
REX::REveScene * rPhiEventScene
Definition: collection.C:33
REX::REveViewer * rphiView
Definition: collection.C:35
REX::REveProjectionManager * mngRhoPhi
Definition: collection.C:31
TLine * line
R__LOAD_LIBRARY(libGeom)
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
void makeProjectedViewsAndScene(REX::REveProjection::EPType_e type, bool scale)
void projection_prescale(std::string type="RhPhi")
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
const Int_t n
Definition: legend1.C:16
static constexpr double s
static constexpr double ps
auto * m
Definition: textangle.C:8
auto * a
Definition: textangle.C:12