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 
31 namespace REX = ROOT::Experimental;
32 
34 
35 REX::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", "");
66 
67  for (auto &ie : eveMng->GetGlobalScene()->RefChildren())
69 
70  for (auto &ie : eveMng->GetEventScene()->RefChildren())
72 }
73 
74 TGeoNode* 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 
85 
86 void projection_prescale(std::string type = "RhPhi")
87 {
89 
90  // static scene
92  auto geoManager = eveMng->GetGeometry("http://root.cern.ch/files/cms.root");
93  TGeoNode* top = geoManager->GetTopVolume()->FindNode("CMSE_1");
94  auto holder = new REX::REveElement("MUON");
95  eveMng->GetGlobalScene()->AddElement(holder);
96  auto n = getNodeFromPath(top, "MUON_1/MB_1");
97  auto m = new REX::REveGeoShape("MB_1");
98  m->SetShape(n->GetVolume()->GetShape());
99  m->SetMainColor(kOrange);
100  holder->AddElement(m);
101 
102  auto bv = n->GetVolume();
103  for (int i = 1; i < 5; ++i ) {
104 
105  auto n = bv->FindNode(Form("MBXC_%d",i));
106  auto gss = n->GetVolume()->GetShape();
107  auto b1s = new REX::REveGeoShape(Form("Arc %d", i));
108  b1s->InitMainTrans();
109  const double* move = n->GetMatrix()->GetTranslation();
110  b1s->RefMainTrans().SetFrom( *(n->GetMatrix()));
111  b1s->SetShape(gss);
112  b1s->SetMainColor(kBlue);
113  holder->AddElement(b1s);
114  }
115 
116  // event scene
117  auto line = new REX::REveLine();
118  line->SetNextPoint(0, 0, 0);
119  float a = 300;
120  line->SetNextPoint(a, a, a);
122 
123  auto line2 = new REX::REveLine();
124  line2->SetNextPoint(0, 0, 0);
125  float b = 30;
126  line2->SetNextPoint(b, b+5, b);
127  line2->SetMainColor(kRed);
128  eveMng->GetEventScene()->AddElement(line2);
129 
130  auto points = getPointSet(10, 30);
132 
133  // make scaled and plain projected views
134  if (type == "RPhi") {
137  }
138  else {
141  }
142 
143  eveMng->Show();
144 }
145 
m
auto * m
Definition: textangle.C:8
n
const Int_t n
Definition: legend1.C:16
ROOT::Experimental::REveProjection::kPT_RPhi
@ kPT_RPhi
Definition: REveProjections.hxx:44
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
ROOT::Experimental::REveManager::SpawnNewScene
REveScene * SpawnNewScene(const char *name, const char *title="")
Create a new scene.
Definition: REveManager.cxx:216
f
#define f(i)
Definition: RSha256.hxx:122
ROOT::Experimental::REveGeoShape
Definition: REveGeoShape.hxx:33
TGeoNode::FindNode
Int_t FindNode(const TGeoNode *node, Int_t level)
Search for a node within the branch of this one.
Definition: TGeoNode.cxx:377
TFile::SetCacheFileDir
static Bool_t SetCacheFileDir(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition: TFile.h:324
REveProjectionBases.hxx
getPointSet
REX::REvePointSet * getPointSet(int npoints=2, float s=2, int color=28)
Definition: projection_prescale.C:35
Form
char * Form(const char *fmt,...)
ROOT::Experimental::REveManager::Create
static REveManager * Create()
If global REveManager* REX::gEve is not set initialize it.
Definition: REveManager.cxx:698
REveTrans.hxx
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::Experimental::REveProjection::AddPreScaleEntry
void AddPreScaleEntry(Int_t coord, Float_t max_val, Float_t scale)
Add new scaling range for given coordinate.
Definition: REveProjections.cxx:181
REveLine.hxx
ROOT::Experimental::REveManager::GetEventScene
REveScene * GetEventScene() const
Definition: REveManager.hxx:146
TGeoNode::GetVolume
TGeoVolume * GetVolume() const
Definition: TGeoNode.h:97
TRandom.h
TGeant4Unit::s
static constexpr double s
Definition: TGeant4SystemOfUnits.h:168
mngRhoPhi
REX::REveProjectionManager * mngRhoPhi
Definition: event_demo.C:43
ROOT::Experimental::REveProjection::EPType_e
EPType_e
Definition: REveProjections.hxx:44
Int_t
int Int_t
Definition: RtypesCore.h:45
TGeoVolume.h
ROOT::Experimental::REveProjectionManager::ImportElements
virtual REveElement * ImportElements(REveElement *el, REveElement *ext_list=nullptr)
Recursively import elements and apply projection to the newly imported objects.
Definition: REveProjectionManager.cxx:251
TGeant4Unit::ps
static constexpr double ps
Definition: TGeant4SystemOfUnits.h:171
kOrange
@ kOrange
Definition: Rtypes.h:67
REvePointSet.hxx
rPhiGeomScene
REX::REveScene * rPhiGeomScene
Definition: event_demo.C:45
ROOT::Experimental::REveElement
Definition: REveElement.hxx:79
TGeoNode
Definition: TGeoNode.h:39
b
#define b(i)
Definition: RSha256.hxx:118
TFile.h
ROOT::Experimental::REveProjection
REveProjection Base for specific classes that implement non-linear projections.
Definition: REveProjections.hxx:42
makeProjectedViewsAndScene
void makeProjectedViewsAndScene(REX::REveProjection::EPType_e type, bool scale)
Definition: projection_prescale.C:50
TRandom
Definition: TRandom.h:27
TSystem.h
REveElement.hxx
getNodeFromPath
TGeoNode * getNodeFromPath(TGeoNode *top, std::string path)
Definition: projection_prescale.C:74
REveScene.hxx
a
auto * a
Definition: textangle.C:12
TGeoMaterial.h
ROOT::Experimental::REveManager::SpawnNewViewer
REveViewer * SpawnNewViewer(const char *name, const char *title="")
Create a new GL viewer.
Definition: REveManager.cxx:206
projection_prescale
void projection_prescale(std::string type="RhPhi")
Definition: projection_prescale.C:86
gRandom
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
ROOT::Experimental::REvePointSet
Definition: REvePointSet.hxx:46
ROOT::Experimental::REveElement::RefChildren
List_t & RefChildren()
Definition: REveElement.hxx:201
kRed
@ kRed
Definition: Rtypes.h:66
line
TLine * line
Definition: entrylistblock_figure1.C:235
ROOT::Experimental::REveProjection::SetUsePreScale
void SetUsePreScale(Bool_t x)
Definition: REveProjections.hxx:122
REveGeoShape.hxx
TGeoMatrix.h
REveProjectionManager.hxx
rphiView
REX::REveViewer * rphiView
Definition: event_demo.C:47
TGeoManager.h
REveManager.hxx
ROOT::Experimental::REveProjection::kPT_RhoZ
@ kPT_RhoZ
Definition: REveProjections.hxx:44
ROOT::Experimental::REveElement::AddElement
virtual void AddElement(REveElement *el)
Add el to the list of children.
Definition: REveElement.cxx:842
points
point * points
Definition: X3DBuffer.c:22
TGeoVolume::FindNode
TGeoNode * FindNode(const char *name) const
search a daughter inside the list of nodes
Definition: TGeoVolume.cxx:1612
eveMng
REX::REveManager * eveMng
Definition: projection_prescale.C:33
ROOT::Experimental::REveViewer::AddScene
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
Definition: REveViewer.cxx:56
ROOT::Experimental::REveManager::Show
void Show(const RWebDisplayArgs &args="")
Show eve manager in specified browser.
Definition: REveManager.cxx:963
ROOT::Experimental::REveManager::GetGlobalScene
REveScene * GetGlobalScene() const
Definition: REveManager.hxx:145
kBlue
@ kBlue
Definition: Rtypes.h:66
ROOT::Experimental::REveManager
Definition: REveManager.hxx:43
ROOT::Experimental::REveProjectionManager::GetProjection
REveProjection * GetProjection()
Definition: REveProjectionManager.hxx:75
ROOT::Experimental::REveManager::GetGeometry
TGeoManager * GetGeometry(const TString &filename)
Get geometry with given filename.
Definition: REveManager.cxx:563
ROOT::Experimental
Definition: RDirectory.hxx:36
type
int type
Definition: TGX11.cxx:121
ROOT::Experimental::REveLine
REveLine An arbitrary polyline with fixed line and marker attributes.
Definition: REveLine.hxx:40
ROOT::Experimental::REveProjectionManager
REveProjectionManager Manager class for steering of projections and managing projected objects.
Definition: REveProjectionManager.hxx:39
REveViewer.hxx
rPhiEventScene
REX::REveScene * rPhiEventScene
Definition: event_demo.C:45