Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
projection_prescale.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// This example display projection prescale
4///
5/// \macro_code
6///
7
8#include <sstream>
9#include <iostream>
10
11#include "TGeoManager.h"
12#include "TGeoVolume.h"
13#include "TGeoMaterial.h"
14#include "TGeoMatrix.h"
15#include "TSystem.h"
16#include "TFile.h"
17#include "TRandom.h"
18
19#include <ROOT/REveGeoShape.hxx>
20#include <ROOT/REveTrans.hxx>
21#include <ROOT/REveScene.hxx>
22#include <ROOT/REveViewer.hxx>
23#include <ROOT/REveElement.hxx>
24#include <ROOT/REveManager.hxx>
25#include <ROOT/REvePointSet.hxx>
26#include <ROOT/REveLine.hxx>
29
30namespace REX = ROOT::Experimental;
31
33
34REX::REvePointSet *getPointSet(int npoints = 2, float s = 2, int color = 28)
35{
36 TRandom &r = *gRandom;
37
38 auto ps = new REX::REvePointSet("testPnts", "title", npoints);
39
40 for (Int_t i = 0; i < npoints; ++i)
41 ps->SetNextPoint(r.Uniform(-s, s), r.Uniform(-s, s), r.Uniform(-s, s));
42
43 ps->SetMarkerColor(color);
44 ps->SetMarkerSize(3 + r.Uniform(1, 2));
45 // ps->SetMarkerStyle(4);
46 return ps;
47}
48
50{
51 auto rPhiGeomScene = eveMng->SpawnNewScene(Form("Project%s Geo", scale ? "PreScaled" : ""));
52 auto rPhiEventScene = eveMng->SpawnNewScene(Form("Project%s Event", scale ? "PreScaled" : ""));
53
55 if (scale) {
56 REX::REveProjection *p = mngRhoPhi->GetProjection();
57 p->AddPreScaleEntry(0, 0, 4); // r scale 4 from 0
58 p->AddPreScaleEntry(0, 45, 1); // r scale 1 from 45
59 p->AddPreScaleEntry(0, 310, 0.5);
61 }
62 auto rphiView = eveMng->SpawnNewViewer("Projected View", "");
63 rphiView->AddScene(rPhiGeomScene);
64 rphiView->AddScene(rPhiEventScene);
66
67 for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
68 mngRhoPhi->ImportElements(ie, rPhiGeomScene);
69
70 for (auto &ie : eveMng->GetEventScene()->RefChildren())
71 mngRhoPhi->ImportElements(ie, rPhiEventScene);
72}
73
74TGeoNode *getNodeFromPath(TGeoNode *top, std::string path)
75{
76 TGeoNode *node = top;
77 istringstream f(path);
78 string s;
79 while (getline(f, s, '/'))
80 node = node->GetVolume()->FindNode(s.c_str());
81
82 return node;
83}
84
85void projection_prescale(std::string type = "RPhi")
86{
88
89 // static scene
91 auto geoManager = eveMng->GetGeometry("http://root.cern/files/cms.root");
92 TGeoNode *top = geoManager->GetTopVolume()->FindNode("CMSE_1");
93 auto holder = new REX::REveElement("MUON");
94 eveMng->GetGlobalScene()->AddElement(holder);
95 auto n = getNodeFromPath(top, "MUON_1/MB_1");
96 auto m = new REX::REveGeoShape("MB_1");
97 m->SetShape(n->GetVolume()->GetShape());
98 m->SetMainColor(kOrange);
99 holder->AddElement(m);
100
101 auto bv = n->GetVolume();
102 for (int i = 1; i < 5; ++i) {
103
104 auto n = bv->FindNode(Form("MBXC_%d", i));
105 auto gss = n->GetVolume()->GetShape();
106 auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
107 b1s->InitMainTrans();
108 const double *move = n->GetMatrix()->GetTranslation();
109 b1s->RefMainTrans().SetFrom(*(n->GetMatrix()));
110 b1s->SetShape(gss);
111 b1s->SetMainColor(kBlue);
112 holder->AddElement(b1s);
113 }
114
115 // event scene
116 auto line = new REX::REveLine();
117 line->SetNextPoint(0, 0, 0);
118 float a = 300;
119 line->SetNextPoint(a, a, a);
120 eveMng->GetEventScene()->AddElement(line);
121
122 auto line2 = new REX::REveLine();
123 line2->SetNextPoint(0, 0, 0);
124 float b = 30;
125 line2->SetNextPoint(b, b + 5, b);
126 line2->SetMainColor(kRed);
127 eveMng->GetEventScene()->AddElement(line2);
128
129 auto points = getPointSet(10, 30);
130 eveMng->GetEventScene()->AddElement(points);
131
132 // make scaled and plain projected views
133 if (type == "RPhi") {
136 } else {
139 }
140
141 eveMng->Show();
142}
ROOT::R::TRInterface & r
Definition Object.C:4
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
int Int_t
Signed integer 4 bytes (int).
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
@ kRed
Definition Rtypes.h:67
@ kOrange
Definition Rtypes.h:68
@ kBlue
Definition Rtypes.h:67
externTRandom * gRandom
Definition TRandom.h:62
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2496
point * points
Definition X3DBuffer.c:22
REveLine An arbitrary polyline with fixed line and marker attributes.
Definition REveLine.hxx:30
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
REveProjectionManager Manager class for steering of projections and managing projected objects.
REveProjection Base for specific classes that implement non-linear projections.
void AddPreScaleEntry(Int_t coord, Float_t max_val, Float_t scale)
Add new scaling range for given coordinate.
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 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
Int_t FindNode(const TGeoNode *node, Int_t level)
Search for a node within the branch of this one.
Definition TGeoNode.cxx:539
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
ROOT::Experimental::REveManager * eveMng
TLine * line
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
void makeProjectedViewsAndScene(REX::REveProjection::EPType_e type, bool scale)
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
void projection_prescale(std::string type="RPhi")
REX::REveScene * rPhiGeomScene
Definition event_demo.C:44
REX::REveScene * rPhiEventScene
Definition event_demo.C:44
REX::REveViewer * rphiView
Definition event_demo.C:46
REX::REveProjectionManager * mngRhoPhi
Definition event_demo.C:42
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100
TMarker m
Definition textangle.C:8