Logo ROOT  
Reference Guide
projection_prescale.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve7
3/// This example display projection prescale
4///
5/// \macro_code
6///
7
8
9#include <sstream>
10#include <iostream>
11
12#include "TGeoManager.h"
13#include "TGeoVolume.h"
14#include "TGeoMaterial.h"
15#include "TGeoMatrix.h"
16#include "TSystem.h"
17#include "TFile.h"
18#include "TRandom.h"
19
20#include <ROOT/REveGeoShape.hxx>
21#include <ROOT/REveTrans.hxx>
22#include <ROOT/REveScene.hxx>
23#include <ROOT/REveViewer.hxx>
24#include <ROOT/REveElement.hxx>
25#include <ROOT/REveManager.hxx>
26#include <ROOT/REvePointSet.hxx>
27#include <ROOT/REveLine.hxx>
30
31namespace REX = ROOT::Experimental;
32
34
35REX::REvePointSet* getPointSet(int npoints = 2, float s=2, int color=28)
36{
37 TRandom &r = *gRandom;
38
39 auto ps = new REX::REvePointSet("testPnts", "title", npoints);
40
41 for (Int_t i=0; i<npoints; ++i)
42 ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
43
44 ps->SetMarkerColor(color);
45 ps->SetMarkerSize(3+r.Uniform(1, 2));
46 // ps->SetMarkerStyle(4);
47 return ps;
48}
49
51{
52 auto rPhiGeomScene = eveMng->SpawnNewScene(Form("Project%s Geo", scale ? "PreScaled" : ""));
53 auto rPhiEventScene = eveMng->SpawnNewScene(Form("Project%s Event", scale ? "PreScaled" : ""));
54
56 if (scale) {
58 p->AddPreScaleEntry(0, 0, 4); // r scale 4 from 0
59 p->AddPreScaleEntry(0, 45, 1); // r scale 1 from 45
60 p->AddPreScaleEntry(0, 310, 0.5);
62 }
63 auto rphiView = eveMng->SpawnNewViewer("Projected View", "");
67
68 for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
70
71 for (auto &ie : eveMng->GetEventScene()->RefChildren())
73}
74
75TGeoNode* getNodeFromPath( TGeoNode* top, std::string path)
76{
77 TGeoNode* node = top;
78 istringstream f(path);
79 string s;
80 while (getline(f, s, '/'))
81 node = node->GetVolume()->FindNode(s.c_str());
82
83 return node;
84}
85
86
87void projection_prescale(std::string type = "RhPhi")
88{
90
91 // static scene
93 auto geoManager = eveMng->GetGeometry("http://root.cern.ch/files/cms.root");
94 TGeoNode* top = geoManager->GetTopVolume()->FindNode("CMSE_1");
95 auto holder = new REX::REveElement("MUON");
97 auto n = getNodeFromPath(top, "MUON_1/MB_1");
98 auto m = new REX::REveGeoShape("MB_1");
99 m->SetShape(n->GetVolume()->GetShape());
100 m->SetMainColor(kOrange);
101 holder->AddElement(m);
102
103 auto bv = n->GetVolume();
104 for (int i = 1; i < 5; ++i ) {
105
106 auto n = bv->FindNode(Form("MBXC_%d",i));
107 auto gss = n->GetVolume()->GetShape();
108 auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
109 b1s->InitMainTrans();
110 const double* move = n->GetMatrix()->GetTranslation();
111 b1s->RefMainTrans().SetFrom( *(n->GetMatrix()));
112 b1s->SetShape(gss);
113 b1s->SetMainColor(kBlue);
114 holder->AddElement(b1s);
115 }
116
117 // event scene
118 auto line = new REX::REveLine();
119 line->SetNextPoint(0, 0, 0);
120 float a = 300;
121 line->SetNextPoint(a, a, a);
123
124 auto line2 = new REX::REveLine();
125 line2->SetNextPoint(0, 0, 0);
126 float b = 30;
127 line2->SetNextPoint(b, b+5, b);
128 line2->SetMainColor(kRed);
130
131 auto points = getPointSet(10, 30);
133
134 // make scaled and plain projected views
135 if (type == "RPhi") {
138 }
139 else {
142 }
143
144 eveMng->Show();
145}
146
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:45
const Bool_t kTRUE
Definition: RtypesCore.h:100
@ kRed
Definition: Rtypes.h:66
@ kOrange
Definition: Rtypes.h:67
@ kBlue
Definition: Rtypes.h:66
int type
Definition: TGX11.cxx:121
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
char * Form(const char *fmt,...)
point * points
Definition: X3DBuffer.c:22
virtual void AddElement(REveElement *el)
Add el to the list of children.
REveLine An arbitrary polyline with fixed line and marker attributes.
Definition: REveLine.hxx:30
REveScene * GetEventScene() const
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
TGeoManager * GetGeometry(const TString &filename)
Get geometry with given filename.
REveScene * GetGlobalScene() const
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
REveViewer * SpawnNewViewer(const char *name, const char *title="")
Create a new GL viewer.
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
REveProjectionManager Manager class for steering of projections and managing projected objects.
virtual REveElement * ImportElements(REveElement *el, REveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported 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.
void SetCameraType(ECameraType t)
Definition: REveViewer.hxx:47
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
Definition: REveViewer.cxx:58
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition: TFile.h:324
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:97
Int_t FindNode(const TGeoNode *node, Int_t level)
Search for a node within the branch of this one.
Definition: TGeoNode.cxx:377
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
TLine * line
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
REX::REveManager * eveMng
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)
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
static constexpr double s
static constexpr double ps
auto * m
Definition: textangle.C:8
auto * a
Definition: textangle.C:12