CMS 3D CMS Logo

FWRPZView.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWRPZView
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Feb 19 10:33:25 EST 2008
11 //
12 
13 // system include files
14 #include <stdexcept>
15 #include <boost/bind.hpp>
16 #include <memory>
17 
18 #include "TGLViewer.h"
19 #include "TGLScenePad.h"
20 #include "TEveManager.h"
21 #include "TEveElement.h"
22 #include "TEveScene.h"
23 #include "TEveProjections.h"
24 #include "TEveProjectionAxes.h"
25 #include "TGLabel.h"
26 #include "TEveProjectionManager.h"
27 #include "TEveCalo.h"
28 
29 // user include files
40 
41 const float FWRPZView::s_distortF = 0.001;
42 const float FWRPZView::s_distortFInv = 1000;
43 //
44 // constructors and destructor
45 //
46 FWRPZView::FWRPZView(TEveWindowSlot* iParent, FWViewType::EType id)
47  : FWEveView(iParent, id, 7),
48  m_geometryList(nullptr),
49  m_projMgr(nullptr),
50  m_axes(nullptr),
51 
52  m_calo(nullptr),
53 
54  m_showPixelBarrel(this, "Show Pixel Barrel", false),
55  m_showPixelEndcap(this, "Show Pixel Endcap", false),
56  m_showTrackerBarrel(this, "Show Tracker Barrel", false),
57  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
58  m_showRpcEndcap(this, "Show RPC Endcap", false),
59  m_showGEM(this, "Show GEM", false),
60  m_showME0(this, "Show ME0", false),
61 
62  m_shiftOrigin(this, "Shift origin to beam-spot", false),
63  m_fishEyeDistortion(this, "Distortion", 0., 0., 100.),
64  m_fishEyeR(this, "FixedRadius", (double)fireworks::Context::caloR1(), 0.0, 150.0),
65 
66  m_caloDistortion(this, "Calo compression", 1.0, 0.01, 10.),
67  m_muonDistortion(this, "Muon compression", 0.2, 0.01, 10.),
68  m_showProjectionAxes(this, "Show projection axis", false),
69  m_projectionAxesLabelSize(this, "Projection axis label size", 0.015, 0.001, 0.2),
70  m_compressMuon(this, "Compress detectors", false),
71  m_showHF(nullptr),
72  m_showEndcaps(nullptr) {
73  TEveProjection::EPType_e projType = (id == FWViewType::kRhoZ) ? TEveProjection::kPT_RhoZ : TEveProjection::kPT_RPhi;
74 
75  m_projMgr = new TEveProjectionManager(projType);
76  m_projMgr->IncDenyDestroy();
77  m_projMgr->SetImportEmpty(kTRUE);
78 
79  m_projMgr->GetProjection()->SetDistortion(m_fishEyeDistortion.value() * s_distortF);
80  m_projMgr->GetProjection()->SetFixR(m_fishEyeR.value());
81 
82 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
83  m_projMgr->GetProjection()->SetDisplaceOrigin(m_shiftOrigin.value());
84 #endif
85 
86  if (id == FWViewType::kRhoPhi || id == FWViewType::kRhoPhiPF) {
87  m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
88  m_projMgr->GetProjection()->AddPreScaleEntry(0, 300, 0.2);
89  } else {
90  m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
91  m_projMgr->GetProjection()->AddPreScaleEntry(1, 310, 1.0);
92  m_projMgr->GetProjection()->AddPreScaleEntry(0, 370, 0.2);
93  m_projMgr->GetProjection()->AddPreScaleEntry(1, 580, 0.2);
94  }
95 
96  // camera
97  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
98  if (TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->CurrentCamera()))) {
99  camera->SetZoomMax(1e6);
100  }
101  geoScene()->GetGLScene()->SetSelectable(kFALSE);
102 
103  m_axes = new TEveProjectionAxes(m_projMgr);
104  m_axes->SetRnrState(m_showProjectionAxes.value());
105  m_axes->SetLabelSize(m_projectionAxesLabelSize.value());
106  m_showProjectionAxes.changed_.connect(boost::bind(&FWRPZView::showProjectionAxes, this));
108  eventScene()->AddElement(m_axes);
109 
110  if (id != FWViewType::kRhoZ) {
111  m_showEndcaps = new FWBoolParameter(this, "Include EndCaps", true);
112  m_showEndcaps->changed_.connect(boost::bind(&FWRPZView::setEtaRng, this));
113  m_showHF = new FWBoolParameter(this, "Include HF", true);
114  m_showHF->changed_.connect(boost::bind(&FWRPZView::setEtaRng, this));
115  }
116 
117  m_shiftOrigin.changed_.connect(boost::bind(&FWRPZView::doShiftOriginToBeamSpot, this));
118 
119  m_fishEyeDistortion.changed_.connect(boost::bind(&FWRPZView::doFishEyeDistortion, this));
120 
121  m_fishEyeR.changed_.connect(boost::bind(&FWRPZView::doFishEyeDistortion, this));
122 
123  m_caloDistortion.changed_.connect(boost::bind(&FWRPZView::doPreScaleDistortion, this));
124  m_muonDistortion.changed_.connect(boost::bind(&FWRPZView::doPreScaleDistortion, this));
125  m_compressMuon.changed_.connect(boost::bind(&FWRPZView::doCompression, this, _1));
126 }
127 
129  m_calo->Destroy();
130  m_projMgr->DecDenyDestroy();
131 }
132 
133 //
134 // member functions
135 //
136 
137 TEveCaloViz* FWRPZView::getEveCalo() const { return static_cast<TEveCaloViz*>(m_calo); }
138 
141 
143  m_geometryList->IncDenyDestroy();
145  TEveElement* p = m_projMgr->ImportElements(m_geometryList);
146  geoScene()->AddElement(p);
147 
148  TEveCaloData* data = context().getCaloData();
149 
150  TEveCalo3D* calo3d = new TEveCalo3D(data);
151 
152  m_calo = static_cast<TEveCalo2D*>(m_projMgr->ImportElements(calo3d, eventScene()));
153 
154  if (typeId() == FWViewType::kRhoPhiPF)
155  m_calo->SetBarrelRadius(177);
156  else
157  m_calo->SetBarrelRadius(context().caloR1(false));
158 
159  m_calo->SetEndCapPos(context().caloZ1(false));
160  m_calo->SetAutoRange(false);
161  m_calo->SetScaleAbs(true);
162 
168  m_showGEM.changed_.connect(boost::bind(&FWRPZViewGeometry::showGEM, m_geometryList, _1));
169  m_showME0.changed_.connect(boost::bind(&FWRPZViewGeometry::showME0, m_geometryList, _1));
170 }
171 
173  if (context().getBeamSpot()) {
174  float c[3] = {0, 0, 0};
176 
177  // projection center
178  TEveVector center(c[0], c[1], c[2]);
179  m_projMgr->GetProjection()->SetCenter(center);
180 
181  // camera move
182  TGLCamera& cam = viewerGL()->CurrentCamera();
183  cam.SetExternalCenter(true);
184  if (typeId() != FWViewType::kRhoZ) {
185  double r = center.Mag();
186  cam.SetCenterVec(center.fZ, TMath::Sign(r, center.fY), 0);
187  } else {
188  cam.SetCenterVec(c[0], c[1], c[2]);
189  }
190  }
191 }
192 
194  float c[3];
196  m_projMgr->SetCenter(c[0], c[1], c[2]);
198 }
199 
201  float c[3];
203  m_projMgr->SetCenter(c[0], c[1], c[2]);
205 }
206 
208 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
209 
210  TEveProjection* p = m_projMgr->GetProjection();
211  if (p->GetDisplaceOrigin() != m_shiftOrigin.value()) {
212  p->SetDisplaceOrigin(m_shiftOrigin.value());
213  m_projMgr->ProjectChildren();
214  gEve->Redraw3D();
215  }
216 #endif
217 }
218 
219 void FWRPZView::shiftOrigin(TEveVector& center) {
220 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
221  // re-project with new center
222  m_projMgr->GetProjection()->SetCenter(center);
223  m_projMgr->ProjectChildren();
224 
225  // draw projected center
226  float* pc = m_projMgr->GetProjection()->GetProjectedCenter();
227  viewerGL()->CurrentCamera().SetExternalCenter(true);
228  viewerGL()->CurrentCamera().SetCenterVec(pc[0], pc[1], pc[2]);
229  viewerGL()->SetDrawCameraCenter(true);
230 
231  gEve->Redraw3D();
232 #endif
233 }
234 
236  // set center back to beam spot
237 
238 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
239  FWBeamSpot& b = *(context().getBeamSpot());
240  TEveVector center(b.x0(), b.y0(), b.z0());
241  m_projMgr->GetProjection()->SetCenter(center);
242 
243  m_projMgr->ProjectChildren();
244  gEve->Redraw3D();
245 #endif
246 }
247 
249  TEveProjection* p = m_projMgr->GetProjection();
250  if (p->GetDistortion() != m_fishEyeDistortion.value() * s_distortFInv)
251  p->SetDistortion(m_fishEyeDistortion.value() * s_distortF);
252  if (p->GetFixR() != m_fishEyeR.value())
253  p->SetFixR(m_fishEyeR.value());
254 
255  m_projMgr->ProjectChildren();
256  gEve->Redraw3D();
257 }
258 
261  m_projMgr->GetProjection()->ChangePreScaleEntry(0, 1, m_caloDistortion.value());
262  m_projMgr->GetProjection()->ChangePreScaleEntry(0, 2, m_muonDistortion.value());
263  } else {
264  m_projMgr->GetProjection()->ChangePreScaleEntry(0, 1, m_caloDistortion.value());
265  m_projMgr->GetProjection()->ChangePreScaleEntry(0, 2, m_muonDistortion.value());
266  m_projMgr->GetProjection()->ChangePreScaleEntry(1, 1, m_caloDistortion.value());
267  m_projMgr->GetProjection()->ChangePreScaleEntry(1, 2, m_muonDistortion.value());
268  }
269  m_projMgr->UpdateName();
270  m_projMgr->ProjectChildren();
271  gEve->Redraw3D();
272 }
273 
275  m_projMgr->GetProjection()->SetUsePreScale(flag);
276  m_projMgr->UpdateName();
277  m_projMgr->ProjectChildren();
278  gEve->Redraw3D();
279 }
280 
281 void FWRPZView::importElements(TEveElement* iChildren, float iLayer, TEveElement* iProjectedParent) {
282  float oldLayer = m_projMgr->GetCurrentDepth();
283  m_projMgr->SetCurrentDepth(iLayer);
284  //make sure current depth is reset even if an exception is thrown
285  std::shared_ptr<TEveProjectionManager> sentry(m_projMgr,
286  boost::bind(&TEveProjectionManager::SetCurrentDepth, _1, oldLayer));
287  m_projMgr->ImportElements(iChildren, iProjectedParent);
288 }
289 
291  FWEveView::addTo(iTo);
292  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->CurrentCamera()));
293  if (camera)
294  addToOrthoCamera(camera, iTo);
295 }
296 
298  FWEveView::setFrom(iFrom);
299 
300  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>(&(viewerGL()->CurrentCamera()));
301  if (camera)
302  setFromOrthoCamera(camera, iFrom);
303 
304  if (iFrom.version() < 7) {
305  const FWConfiguration* value = iFrom.valueForKey("Show projection axes");
306  if (value)
307  m_showProjectionAxes.set(value->value() == "1");
308  }
309 }
310 
312  if (typeId() != FWViewType::kRhoZ) {
313  // rng controllers only in RhoPhi
314  double eta_range = context().caloMaxEta();
315  if (!m_showHF->value())
316  eta_range = 3.0;
317  if (!m_showEndcaps->value())
318  eta_range = context().caloTransEta();
319  m_calo->SetEta(-eta_range, eta_range);
320  }
321 
323 }
324 
326  if (!m_calo->GetData()->Empty()) {
327  m_calo->AssertCellIdCache();
328  Float_t sumEt, sumE;
329  TEveCaloData::CellData_t cellData;
330  typedef std::vector<TEveCaloData::vCellId_t*> vBinCells_t;
331  typedef std::vector<TEveCaloData::vCellId_t*>::iterator vBinCells_i;
332 
333  vBinCells_t cellLists = m_calo->GetBinLists();
334  for (vBinCells_i it = cellLists.begin(); it != cellLists.end(); it++) {
335  TEveCaloData::vCellId_t* binCells = *it;
336  if (binCells) {
337  sumEt = 0;
338  sumE = 0;
339  TEveCaloData::vCellId_i a = binCells->end();
340 
341  for (TEveCaloData::vCellId_i k = binCells->begin(); k != a; ++k) {
342  m_calo->GetData()->GetCellData((*k), cellData);
343  sumEt += cellData.Value(true);
344  sumE += cellData.Value(false);
345  }
346  // printf("vote sum %f %f \n", sumEt , sumE);
347  context().voteMaxEtAndEnergy(sumEt, sumE);
348  }
349  }
350  }
351 }
352 
354  m_axes->SetRnrState(m_showProjectionAxes.value());
355  gEve->Redraw3D();
356  viewerGL()->RequestDraw();
357 }
358 
360  m_axes->SetLabelSize(m_projectionAxesLabelSize.value());
361  viewerGL()->RequestDraw();
362 }
363 
366 
367  ViewerParameterGUI& det = gui.requestTab("Detector");
368  ;
370 
371  if (typeId() == FWViewType::kRhoZ) {
375  bool showGEM = m_context->getGeom()->versionInfo().haveExtraDet("GEM");
376  if (showGEM)
377  det.addParam(&m_showGEM);
378  bool showME0 = m_context->getGeom()->versionInfo().haveExtraDet("ME0");
379  if (showME0)
380  det.addParam(&m_showME0);
381  }
382 
383 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
384  gui.requestTab("Projection").addParam(&m_shiftOrigin);
385 #endif
386 
388 
389  TGCompositeFrame* f = gui.getTabContainer();
390 
391  f->AddFrame(new TGLabel(f, "FishEye:"));
393 
394  f->AddFrame(new TGLabel(f, "PreScales:"));
395 
397 
400  }
401 }
static float caloTransEta()
Definition: Context.cc:187
void doShiftOriginToBeamSpot()
Definition: FWRPZView.cc:207
void addToOrthoCamera(TGLOrthoCamera *, FWConfiguration &) const
Definition: FWEveView.cc:352
void doFishEyeDistortion()
Definition: FWRPZView.cc:248
FWBoolParameter m_shiftOrigin
Definition: FWRPZView.h:99
TEveScene * eventScene()
Definition: FWEveView.h:79
void setupEventCenter() override
Definition: FWRPZView.cc:200
FWBoolParameter m_showProjectionAxes
Definition: FWRPZView.h:105
double x0() const
Definition: FWBeamSpot.cc:23
FWRPZView(TEveWindowSlot *iParent, FWViewType::EType)
Definition: FWRPZView.cc:46
T Sign(T A, T B)
Definition: MathUtil.h:54
TEveCalo2D * m_calo
Definition: FWRPZView.h:87
double z0() const
Definition: FWBeamSpot.cc:27
double y0() const
Definition: FWBeamSpot.cc:25
FWBoolParameter m_showME0
Definition: FWRPZView.h:97
FWDoubleParameter m_projectionAxesLabelSize
Definition: FWRPZView.h:106
const FWGeometry * getGeom() const
Definition: Context.h:72
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:162
ViewerParameterGUI & requestTab(const char *)
#define nullptr
ViewerParameterGUI & separator()
void getEventCenter(float *inC) const
void voteCaloMaxVal() override
Definition: FWRPZView.cc:325
void eventEnd() override
Definition: FWRPZView.cc:193
unsigned int version() const
void setFrom(const FWConfiguration &) override
Definition: FWRPZView.cc:297
virtual void setupEventCenter()
Definition: FWEveView.cc:283
void setContext(const fireworks::Context &) override
Definition: FWRPZView.cc:139
virtual void setupEnergyScale()
Definition: FWEveView.cc:251
TEveProjectionAxes * m_axes
Definition: FWRPZView.h:86
TGLViewer * viewerGL() const
Definition: FWEveView.cc:177
FWParameters::Bool FWBoolParameter
Definition: FWParameters.h:37
const fireworks::Context * m_context
Definition: FWEveView.h:109
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:150
FWBoolParameter * m_showHF
Definition: FWRPZView.h:109
virtual void eventEnd()
Definition: FWEveView.cc:217
TEveProjectionManager * m_projMgr
Definition: FWRPZView.h:85
FWDoubleParameter m_fishEyeR
Definition: FWRPZView.h:101
void resetOrigin()
Definition: FWRPZView.cc:235
FWBoolParameter m_showRpcEndcap
Definition: FWRPZView.h:95
float caloR1()
Definition: FWPFGeom.h:20
void initStdGeoElements(const FWViewType::EType id)
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:473
void doCompression(bool)
Definition: FWRPZView.cc:274
FWBeamSpot * getBeamSpot() const
Definition: Context.h:67
void setEtaRng()
Definition: FWRPZView.cc:311
FWBoolParameter m_showTrackerBarrel
Definition: FWRPZView.h:93
void showProjectionAxes()
Definition: FWRPZView.cc:353
static float caloR1(bool offset=true)
Definition: Context.cc:180
double f[11][100]
TEveCaloDataHist * getCaloData() const
Definition: Context.h:69
~FWRPZView() override
Definition: FWRPZView.cc:128
Definition: value.py:1
void eventBegin() override
Definition: FWRPZView.cc:172
FWBoolParameter m_compressMuon
Definition: FWRPZView.h:107
FWRPZViewGeometry * m_geometryList
Definition: FWRPZView.h:84
void shiftOrigin(TEveVector &center)
Definition: FWRPZView.cc:219
const std::string & value(unsigned int iIndex=0) const
const fireworks::Context & context()
Definition: FWEveView.h:64
void setFrom(const FWConfiguration &) override
Definition: FWEveView.cc:307
TEveCaloViz * getEveCalo() const override
Definition: FWRPZView.cc:137
void doPreScaleDistortion()
Definition: FWRPZView.cc:259
FWBoolParameter * m_showEndcaps
Definition: FWRPZView.h:110
FWBoolParameter m_showGEM
Definition: FWRPZView.h:96
float caloZ1()
Definition: FWPFGeom.h:21
static const float s_distortFInv
Definition: FWRPZView.h:82
double b
Definition: hdecay.h:118
void showTrackerBarrel(bool)
FWDoubleParameter m_fishEyeDistortion
Definition: FWRPZView.h:100
TEveScene * geoScene()
Definition: FWEveView.h:80
void importElements(TEveElement *iProjectableChild, float layer, TEveElement *iProjectedParent=nullptr)
Definition: FWRPZView.cc:281
ViewerParameterGUI & addParam(const FWParameterBase *)
CmsShowCommon * commonPrefs() const
Definition: Context.cc:160
FWBoolParameter m_showTrackerEndcap
Definition: FWRPZView.h:94
TGCompositeFrame * getTabContainer()
sigc::signal< void, T > changed_
void addTo(FWConfiguration &) const override
Definition: FWEveView.cc:291
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
static double caloMaxEta()
Definition: Context.cc:191
double a
Definition: hdecay.h:119
FWDoubleParameter m_muonDistortion
Definition: FWRPZView.h:104
void addTo(FWConfiguration &) const override
Definition: FWRPZView.cc:290
FWBoolParameter m_showPixelEndcap
Definition: FWRPZView.h:92
FWDoubleParameter m_caloDistortion
Definition: FWRPZView.h:103
void showTrackerEndcap(bool)
const FWConfiguration * valueForKey(const std::string &iKey) const
FWBoolParameter m_showPixelBarrel
Definition: FWRPZView.h:91
void setFromOrthoCamera(TGLOrthoCamera *, const FWConfiguration &)
Definition: FWEveView.cc:368
void populateController(ViewerParameterGUI &) const override
Definition: FWRPZView.cc:364
static const float s_distortF
Definition: FWRPZView.h:81
void projectionAxesLabelSize()
Definition: FWRPZView.cc:359
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:227
void populateController(ViewerParameterGUI &) const override
Definition: FWEveView.cc:466
FWViewType::EType typeId() const
Definition: FWViewBase.h:42