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