CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWLegoViewBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWLegoViewBase
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Feb 21 11:22:41 EST 2008
11 //
12 
13 // system include files
14 #include <functional>
15 
16 #include "TAxis.h"
17 #include "TH2.h"
18 
19 #include "TGLViewer.h"
20 #include "TGLLightSet.h"
21 #include "TGLPerspectiveCamera.h"
22 #include "TGLOrthoCamera.h"
23 #include "TEveManager.h"
24 #include "TEveElement.h"
25 #include "TEveScene.h"
26 #include "TEveCalo.h"
27 #include "TEveTrans.h"
28 #include "TEveScene.h"
29 #include "TEveCaloLegoOverlay.h"
30 
31 // user include files
39 
40 //
41 // constants, enums and typedefs
42 //
43 
44 //
45 // static data member definitions
46 //
47 
48 //
49 // constructors and destructor
50 //
51 FWLegoViewBase::FWLegoViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId)
52  : FWEveView(iParent, typeId),
53  m_lego(nullptr),
54  m_overlay(nullptr),
55  m_autoRebin(this, "Auto rebin on zoom-out", false),
56  m_pixelsPerBin(this, "Pixels per bin", 10., 1., 20.),
57  m_projectionMode(this, "Projection", 0l, 0l, 2l),
58  m_cell2DMode(this, "Cell2DMode", 1l, 1l, 2l),
59  m_drawValuesIn2D(this, "Draw Cell2D threshold (pixels)", 40l, 16l, 1200l),
60  m_showOverlay(this, "Draw scales", true) {
61  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
62  viewerGL()->GetLightSet()->SetUseSpecular(false);
63 
64  m_projectionMode.addEntry(0, "Auto");
65  m_projectionMode.addEntry(1, "3D");
66  m_projectionMode.addEntry(2, "2D");
67 
68  m_cell2DMode.addEntry(1, "Plain");
69  m_cell2DMode.addEntry(2, "Outline");
70  if (typeId == FWViewType::kLegoHF)
71  m_cell2DMode.set(2); // different default for HF view
72 
73  m_autoRebin.changed_.connect(std::bind(&FWLegoViewBase::setAutoRebin, this));
74  m_pixelsPerBin.changed_.connect(std::bind(&FWLegoViewBase::setPixelsPerBin, this));
76  m_showOverlay.changed_.connect(std::bind(&FWLegoViewBase::showOverlay, this));
78  m_cell2DMode.changed_.connect(std::bind(&FWLegoViewBase::setCell2DMode, this));
79 }
80 
82  viewerGL()->RemoveOverlayElement(m_overlay);
83  m_lego->Destroy();
84 }
85 
86 TEveCaloViz* FWLegoViewBase::getEveCalo() const { return static_cast<TEveCaloViz*>(m_lego); }
87 
90 
91  TEveCaloData* data;
92  if (typeId() == FWViewType::kLego) {
93  data = static_cast<TEveCaloData*>(ctx.getCaloData());
94  } else if (typeId() == FWViewType::kLegoHF) {
95  data = static_cast<TEveCaloData*>(ctx.getCaloDataHF());
96  } else {
97  // create empty data locally instead of context
98  TEveCaloDataHist* hdata = new TEveCaloDataHist();
99  hdata->IncDenyDestroy();
100 
101  Bool_t status = TH1::AddDirectoryStatus();
102  TH1::AddDirectory(kFALSE); //Keeps histogram from going into memory
103  TH2F* dummy =
104  new TH2F("background", "background", fw3dlego::xbins_n - 1, fw3dlego::xbins, 72, -1 * TMath::Pi(), TMath::Pi());
105 
106  TH1::AddDirectory(status);
107  Int_t sliceIndex = hdata->AddHistogram(dummy);
108  (hdata)->RefSliceInfo(sliceIndex).Setup("background", 0., 0);
109  data = hdata;
110  }
111 
112  data->GetEtaBins()->SetNdivisions(710);
113  data->GetPhiBins()->SetNdivisions(510);
114  data->GetEtaBins()->SetTitleFont(120);
115  data->GetEtaBins()->SetTitle("h");
116  data->GetPhiBins()->SetTitleFont(120);
117  data->GetPhiBins()->SetTitle("f");
118  data->GetEtaBins()->SetLabelSize(0.02);
119  data->GetEtaBins()->SetTitleSize(0.03);
120 
121  m_lego = new TEveCaloLego(data);
122  m_lego->Set2DMode((TEveCaloLego::E2DMode_e)m_cell2DMode.value());
123  m_lego->SetDrawNumberCellPixels(m_drawValuesIn2D.value());
124  m_lego->SetAutoRebin(m_autoRebin.value());
125  m_lego->SetPixelsPerBin(m_pixelsPerBin.value());
126 
127  m_lego->InitMainTrans();
128  m_lego->RefMainTrans().SetScale(TMath::TwoPi(), TMath::TwoPi(), TMath::Pi());
129  m_lego->SetScaleAbs(true);
130 
131  // set flat in 2D
132  m_lego->SetHasFixedHeightIn2DMode(true);
133  m_lego->SetFixedHeightValIn2DMode(0.001);
134  eventScene()->AddElement(m_lego);
135 
136  TEveLegoEventHandler* eh = dynamic_cast<TEveLegoEventHandler*>(viewerGL()->GetEventHandler());
137  if (eh)
138  eh->SetLego(m_lego);
139 
140  m_overlay = new TEveCaloLegoOverlay();
141  m_overlay->SetCaloLego(m_lego);
142  m_overlay->SetShowPlane(kFALSE);
143  m_overlay->SetScalePosition(0.8, 0.6);
144  m_overlay->SetShowScales(true); //temporary
145  viewerGL()->AddOverlayElement(m_overlay);
146 }
147 
149  m_lego->SetAutoRebin(m_autoRebin.value());
150  m_lego->ElementChanged(kTRUE, kTRUE);
151 }
152 
154  m_lego->SetPixelsPerBin((Int_t)(m_pixelsPerBin.value()));
155  m_lego->ElementChanged(kTRUE, kTRUE);
156 }
157 
159  if (m_overlay)
160  m_overlay->SetShowScales(m_showOverlay.value());
161  viewerGL()->Changed();
162  gEve->Redraw3D();
163 }
164 
165 //_______________________________________________________________________________
166 
168  FWEveView::setFrom(iFrom);
169 
170  // cell 2D style
171  if (iFrom.version() < 5) {
172  const FWConfiguration* value = iFrom.valueForKey("Cell2DMode");
173  if (value != nullptr) {
174  int mode;
175  std::istringstream s(value->value());
176  s >> mode;
177  m_cell2DMode.set(mode);
178  }
179  }
180 
181  // view controller parameters, changed name in version 4
182  if (iFrom.version() < 4) {
183  bool xb; /* double xd;
184  {
185  std::istringstream s(iFrom.valueForKey("Lego auto scale")->value());
186  s >> xb; m_energyScaleMode.set(xb ? FWEveView::kAutoScale : FWEveView::kFixedScale);
187  }
188  {
189  std::istringstream s(iFrom.valueForKey("Lego scale GeV)")->value());
190  s >> xd; m_energyMaxAbsVal.set(xd);
191  }*/
192  {
193  std::istringstream s(iFrom.valueForKey("Show scales")->value());
194  s >> xb;
195  m_showOverlay.set(xb);
196  }
197  {
198  std::istringstream s(iFrom.valueForKey("Show scales")->value());
199  s >> xb;
200  m_showOverlay.set(xb);
201  }
202  {
203  std::istringstream s(iFrom.valueForKey("Auto rebin on zoom")->value());
204  s >> xb;
205  m_autoRebin.set(xb);
206  }
207  }
208 
209  //
210  // camera restore
211 
212  if (iFrom.version() > 1) {
213  bool topView = true;
214  std::string stateName("topView");
215  stateName += typeName();
216  assert(nullptr != iFrom.valueForKey(stateName));
217  std::istringstream s(iFrom.valueForKey(stateName)->value());
218  s >> topView;
219 
220  if (topView) {
221  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
222  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraOrthoXOY)));
223  setFromOrthoCamera(camera, iFrom);
224  } else {
225  viewerGL()->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
226  TGLPerspectiveCamera* camera =
227  dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraPerspXOY)));
228  setFromPerspectiveCamera(camera, typeName(), iFrom);
229  }
230  } else {
231  // reset camera if version not supported
232  viewerGL()->ResetCamerasAfterNextUpdate();
233  }
234 }
235 
237  FWEveView::addTo(iTo);
238 
239  bool topView = viewerGL()->CurrentCamera().IsOrthographic();
240  std::ostringstream s;
241  s << topView;
242  std::string name = "topView";
243  iTo.addKeyValue(name + typeName(), FWConfiguration(s.str()));
244 
245  if (topView) {
246  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraOrthoXOY)));
247  addToOrthoCamera(camera, iTo);
248  } else {
249  TGLPerspectiveCamera* camera =
250  dynamic_cast<TGLPerspectiveCamera*>(&(viewerGL()->RefCamera(TGLViewer::kCameraPerspXOY)));
251  addToPerspectiveCamera(camera, typeName(), iTo);
252  }
253 }
254 
256  m_lego->SetDrawNumberCellPixels(m_drawValuesIn2D.value());
257  m_lego->ElementChanged(kTRUE, kTRUE);
258 }
259 
261  m_lego->SetProjection((TEveCaloLego::EProjection_e)m_projectionMode.value());
262  m_lego->ElementChanged();
263  viewerGL()->Changed();
264  gEve->Redraw3D();
265 }
266 
268  m_lego->Set2DMode((TEveCaloLego::E2DMode_e)m_cell2DMode.value());
269  m_lego->ElementChanged();
270  viewerGL()->Changed();
271  gEve->Redraw3D();
272 }
273 
276 
278 
279  gui.requestTab("Scales").separator().addParam(&m_showOverlay);
280 
282 }
const double TwoPi
const double Pi
void addToOrthoCamera(TGLOrthoCamera *, FWConfiguration &) const
Definition: FWEveView.cc:352
TEveCaloDataVec * getCaloDataHF() const
Definition: Context.h:70
TEveScene * eventScene()
Definition: FWEveView.h:79
FWEnumParameter m_projectionMode
const double xbins[]
FWDoubleParameter m_pixelsPerBin
~FWLegoViewBase() override
ViewerParameterGUI & requestTab(const char *)
ViewerParameterGUI & separator()
list status
Definition: mps_update.py:107
const std::string & typeName() const
Definition: FWViewBase.cc:107
unsigned int version() const
FWLegoViewBase(TEveWindowSlot *, FWViewType::EType)
TGLViewer * viewerGL() const
Definition: FWEveView.cc:177
assert(be >=bs)
bool addEntry(Long_t id, const std::string &txt)
TEveCaloLego * m_lego
TEveCaloDataHist * getCaloData() const
Definition: Context.h:69
void populateController(ViewerParameterGUI &) const override
FWBoolParameter m_showOverlay
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
FWLongParameter m_drawValuesIn2D
const int xbins_n
void setContext(const fireworks::Context &) override
TEveCaloLegoOverlay * m_overlay
FWBoolParameter m_autoRebin
const std::string & value(unsigned int iIndex=0) const
void setProjectionMode()
void populateController(ViewerParameterGUI &) const override
Definition: FWEveView.cc:466
void setFrom(const FWConfiguration &) override
Definition: FWEveView.cc:307
void setFromPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, const FWConfiguration &)
Definition: FWEveView.cc:420
TEveCaloViz * getEveCalo() const override
ViewerParameterGUI & addParam(const FWParameterBase *)
sigc::signal< void, T > changed_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
void addTo(FWConfiguration &) const override
FWEnumParameter m_cell2DMode
const FWConfiguration * valueForKey(const std::string &iKey) const
void addTo(FWConfiguration &) const override
Definition: FWEveView.cc:291
void setFromOrthoCamera(TGLOrthoCamera *, const FWConfiguration &)
Definition: FWEveView.cc:368
void setFrom(const FWConfiguration &) override
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:227
FWViewType::EType typeId() const
Definition: FWViewBase.h:42
void addToPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, FWConfiguration &) const
Definition: FWEveView.cc:397