Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
projection_prescale.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_eve
3 /// Demonstrates usage pre-scaling for automatic 2D projections.
4 ///
5 /// \image html eve_projection_prescale.png
6 /// \macro_code
7 ///
8 /// \author Matevz Tadel
9 
10 const char* esd_geom_file_name =
11  "http://root.cern.ch/files/alice_ESDgeometry.root";
12 
13 void projection_prescale()
14 {
15  TFile::SetCacheFileDir(".");
16  TEveManager::Create();
17 
18  auto pev = gEve->SpawnNewViewer("Projections");
19 
20  // camera
21  auto s = gEve->SpawnNewScene("Projected Geom");
22  pev->AddScene(s);
23 
24  auto pgv = pev->GetGLViewer();
25  pgv->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
26  TGLOrthoCamera& cam = (TGLOrthoCamera&) pgv->CurrentCamera();
27  cam.SetZoomMinMax(0.2, 20);
28 
29  // projections
30  auto mng = new TEveProjectionManager();
31  {
32  mng->SetProjection(TEveProjection::kPT_RPhi);
33  auto p = mng->GetProjection();
34  p->AddPreScaleEntry(0, 0, 4); // r scale 4 from 0
35  p->AddPreScaleEntry(0, 45, 1); // r scale 1 from 45
36  p->AddPreScaleEntry(0, 310, 0.5);
37  p->SetUsePreScale(kTRUE);
38  }
39  {
40  mng->SetProjection(TEveProjection::kPT_RhoZ);
41  auto p = mng->GetProjection();
42  // Increase silicon tracker
43  p->AddPreScaleEntry(0, 0, 4); // rho scale 4 from 0
44  p->AddPreScaleEntry(1, 0, 4); // z scale 4 from 0
45  // Normal for TPC
46  p->AddPreScaleEntry(0, 45, 1); // rho scale 1 from 45
47  p->AddPreScaleEntry(1, 110, 1); // z scale 1 from 110
48  // Reduce the rest
49  p->AddPreScaleEntry(0, 310, 0.5);
50  p->AddPreScaleEntry(1, 250, 0.5);
51  p->SetUsePreScale(kTRUE);
52  }
53  mng->SetProjection(TEveProjection::kPT_RPhi);
54  s->AddElement(mng);
55 
56  auto axes = new TEveProjectionAxes(mng);
57  s->AddElement(axes);
58  gEve->AddToListTree(axes, kTRUE);
59  gEve->AddToListTree(mng, kTRUE);
60 
61  // Simple geometry
62  auto geom = TFile::Open(esd_geom_file_name, "CACHEREAD");
63  if (!geom)
64  return;
65 
66  auto gse = (TEveGeoShapeExtract*) geom->Get("Gentle");
67  auto gsre = TEveGeoShape::ImportShapeExtract(gse, 0);
68  geom->Close();
69  delete geom;
70  gEve->AddGlobalElement(gsre);
71  mng->ImportElements(gsre);
72 
73  auto line = new TEveLine;
74  line->SetMainColor(kGreen);
75  for (Int_t i=0; i<160; ++i)
76  line->SetNextPoint(120*sin(0.2*i), 120*cos(0.2*i), 80-i);
77  gEve->AddElement(line);
78  mng->ImportElements(line);
79  line->SetRnrSelf(kFALSE);
80 
81 
82  //-------------------------------------------------------------------------
83  // Scaled 3D "projection"
84  //-------------------------------------------------------------------------
85 
86  auto sev = gEve->SpawnNewViewer("Scaled 3D");
87  auto smng = new TEveProjectionManager(TEveProjection::kPT_3D);
88  auto sp = smng->GetProjection();
89  sp->SetUsePreScale(kTRUE);
90  sp->AddPreScaleEntry(2, 0, 1);
91  sp->AddPreScaleEntry(2, 100, 0.2);
92 
93  auto ss = gEve->SpawnNewScene("Scaled Geom");
94  sev->AddScene(ss);
95  ss->AddElement(smng);
96 
97  smng->ImportElements(gsre);
98 
99  //-------------------------------------------------------------------------
100 
101  gEve->GetBrowser()->GetTabRight()->SetTab(1);
102 
103  gEve->Redraw3D(kTRUE);
104 }