CMS 3D CMS Logo

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");
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;
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 }
fw3dlego::xbins
const double xbins[]
Definition: fw3dlego_xbins.cc:16
fireworks::Context
Definition: Context.h:41
TwoPi
const double TwoPi
Definition: CosmicMuonParameters.h:19
FWGLEventHandler.h
funct::false
false
Definition: Factorize.h:29
FWViewType::EType
EType
Definition: FWViewType.h:31
ViewerParameterGUI
Definition: CmsShowViewPopup.h:49
FWViewBase::typeName
const std::string & typeName() const
Definition: FWViewBase.cc:107
mps_update.status
status
Definition: mps_update.py:68
FWLegoViewBase::m_projectionMode
FWEnumParameter m_projectionMode
Definition: FWLegoViewBase.h:79
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
FWEveView::populateController
void populateController(ViewerParameterGUI &) const override
Definition: FWEveView.cc:466
FWEveView::setFrom
void setFrom(const FWConfiguration &) override
Definition: FWEveView.cc:307
FWEnumParameter::addEntry
bool addEntry(Long_t id, const std::string &txt)
Definition: FWEnumParameter.h:53
cms::cuda::assert
assert(be >=bs)
FWLegoViewBase::setCell2DMode
void setCell2DMode()
Definition: FWLegoViewBase.cc:267
FWGenericParameter::set
void set(T iValue)
Definition: FWGenericParameter.h:70
FWLegoViewBase::setAutoRebin
void setAutoRebin()
Definition: FWLegoViewBase.cc:148
fw3dlego::xbins_n
const int xbins_n
Definition: fw3dlego_xbins.cc:15
fireworks::Context::getCaloDataHF
TEveCaloDataVec * getCaloDataHF() const
Definition: Context.h:70
FWLegoViewBase::m_overlay
TEveCaloLegoOverlay * m_overlay
Definition: FWLegoViewBase.h:59
FWEveView::eventScene
TEveScene * eventScene()
Definition: FWEveView.h:79
FWViewBase::typeId
FWViewType::EType typeId() const
Definition: FWViewBase.h:42
FWViewContext.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
FWGenericParameter::changed_
sigc::signal< void, T > changed_
Definition: FWGenericParameter.h:75
FWLegoViewBase::m_drawValuesIn2D
FWLongParameter m_drawValuesIn2D
Definition: FWLegoViewBase.h:81
ViewerParameterGUI::separator
ViewerParameterGUI & separator()
Definition: CmsShowViewPopup.cc:232
FWEveView
Definition: FWEveView.h:53
FWEveView::setFromPerspectiveCamera
void setFromPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, const FWConfiguration &)
Definition: FWEveView.cc:420
FWLegoViewBase::FWLegoViewBase
FWLegoViewBase(TEveWindowSlot *, FWViewType::EType)
Definition: FWLegoViewBase.cc:51
FWViewType::kLego
Definition: FWViewType.h:36
FWLegoViewBase::setPixelsPerBin
void setPixelsPerBin()
Definition: FWLegoViewBase.cc:153
FWLegoViewBase::~FWLegoViewBase
~FWLegoViewBase() override
Definition: FWLegoViewBase.cc:81
FWConfiguration::valueForKey
const FWConfiguration * valueForKey(const std::string &iKey) const
Definition: FWConfiguration.cc:122
FWLegoViewBase::m_cell2DMode
FWEnumParameter m_cell2DMode
Definition: FWLegoViewBase.h:80
FWEveView::addToOrthoCamera
void addToOrthoCamera(TGLOrthoCamera *, FWConfiguration &) const
Definition: FWEveView.cc:352
FWConfiguration::value
const std::string & value(unsigned int iIndex=0) const
Definition: FWConfiguration.cc:115
funct::true
true
Definition: Factorize.h:173
FWLegoViewBase.h
FWLegoViewBase::populateController
void populateController(ViewerParameterGUI &) const override
Definition: FWLegoViewBase.cc:274
FWLegoViewBase::m_lego
TEveCaloLego * m_lego
Definition: FWLegoViewBase.h:58
value
Definition: value.py:1
FWLegoViewBase::setFontSizein2D
void setFontSizein2D()
Definition: FWLegoViewBase.cc:255
FWViewType::kLegoHF
Definition: FWViewType.h:37
FWConfiguration::version
unsigned int version() const
Definition: FWConfiguration.h:49
FWLegoViewBase::getEveCalo
TEveCaloViz * getEveCalo() const override
Definition: FWLegoViewBase.cc:86
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
FWGenericParameter::value
T value() const
Definition: FWGenericParameter.h:50
FWConfiguration::addKeyValue
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
Definition: FWConfiguration.cc:58
FWEveView::addToPerspectiveCamera
void addToPerspectiveCamera(TGLPerspectiveCamera *, const std::string &, FWConfiguration &) const
Definition: FWEveView.cc:397
FWEveView::setFromOrthoCamera
void setFromOrthoCamera(TGLOrthoCamera *, const FWConfiguration &)
Definition: FWEveView.cc:368
FWLegoViewBase::setProjectionMode
void setProjectionMode()
Definition: FWLegoViewBase.cc:260
FWEveView::addTo
void addTo(FWConfiguration &) const override
Definition: FWEveView.cc:291
CmsShowViewPopup.h
fireworks::Context::getCaloData
TEveCaloDataHist * getCaloData() const
Definition: Context.h:69
FWLegoViewBase::m_showOverlay
FWBoolParameter m_showOverlay
Definition: FWLegoViewBase.h:82
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
FWLegoViewBase::setContext
void setContext(const fireworks::Context &) override
Definition: FWLegoViewBase.cc:88
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
FWEveView::viewerGL
TGLViewer * viewerGL() const
Definition: FWEveView.cc:177
Pi
const double Pi
Definition: CosmicMuonParameters.h:18
FWViewEnergyScale.h
FWConfiguration
Definition: FWConfiguration.h:31
FWEveView::setContext
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:227
dummy
Definition: DummySelector.h:38
FWLegoViewBase::m_pixelsPerBin
FWDoubleParameter m_pixelsPerBin
Definition: FWLegoViewBase.h:78
FWLegoViewBase::showOverlay
void showOverlay()
Definition: FWLegoViewBase.cc:158
FWLegoViewBase::addTo
void addTo(FWConfiguration &) const override
Definition: FWLegoViewBase.cc:236
fw3dlego_xbins.h
ViewerParameterGUI::addParam
ViewerParameterGUI & addParam(const FWParameterBase *)
Definition: CmsShowViewPopup.cc:212
FWLegoViewBase::setFrom
void setFrom(const FWConfiguration &) override
Definition: FWLegoViewBase.cc:167
FWLegoViewBase::m_autoRebin
FWBoolParameter m_autoRebin
Definition: FWLegoViewBase.h:77
FWConfiguration.h
ViewerParameterGUI::requestTab
ViewerParameterGUI & requestTab(const char *)
Definition: CmsShowViewPopup.cc:197