CMS 3D CMS Logo

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