CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <boost/shared_ptr.hpp>
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 
29 #define protected public
30 #include "TEveCalo.h"
31 #undef protected
32 
33 // user include files
43 
44 
45 const float FWRPZView::s_distortF = 0.001;
46 const float FWRPZView::s_distortFInv = 1000;
47 //
48 // constructors and destructor
49 //
50 FWRPZView::FWRPZView(TEveWindowSlot* iParent, FWViewType::EType id) :
51  FWEveView(iParent, id, 7),
52  m_geometryList(0),
53  m_projMgr(0),
54  m_axes(0),
55 
56  m_calo(0),
57 
58  m_showPixelBarrel(this, "Show Pixel Barrel", false ),
59  m_showPixelEndcap(this, "Show Pixel Endcap", false),
60  m_showTrackerBarrel(this, "Show Tracker Barrel", false ),
61  m_showTrackerEndcap(this, "Show Tracker Endcap", false),
62  m_showRpcEndcap(this, "Show RPC Endcap", false ),
63  m_showGEM(this, "Show GEM", false ),
64  m_showME0(this, "Show ME0", false ),
65 
66  m_shiftOrigin(this,"Shift origin to beam-spot", false),
67  m_fishEyeDistortion(this,"Distortion",0., 0., 100.),
68  m_fishEyeR(this,"FixedRadius",(double)fireworks::Context::caloR1(), 0.0, 150.0),
69 
70  m_caloDistortion(this,"Calo compression",1.0,0.01,10.),
71  m_muonDistortion(this,"Muon compression",0.2,0.01,10.),
72  m_showProjectionAxes(this,"Show projection axis", false),
73  m_projectionAxesLabelSize(this,"Projection axis label size", 0.015, 0.001, 0.2),
74  m_compressMuon(this,"Compress detectors",false),
75  m_showHF(0),
76  m_showEndcaps(0)
77 {
78  TEveProjection::EPType_e projType = (id == FWViewType::kRhoZ) ? TEveProjection::kPT_RhoZ : TEveProjection::kPT_RPhi;
79 
80  m_projMgr = new TEveProjectionManager(projType);
81  m_projMgr->IncDenyDestroy();
82  m_projMgr->SetImportEmpty(kTRUE);
83 
84  m_projMgr->GetProjection()->SetDistortion(m_fishEyeDistortion.value()*s_distortF);
85  m_projMgr->GetProjection()->SetFixR(m_fishEyeR.value());
86 
87 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
88  m_projMgr->GetProjection()->SetDisplaceOrigin( m_shiftOrigin.value());
89 #endif
90 
91  if ( id == FWViewType::kRhoPhi || id == FWViewType::kRhoPhiPF) {
92  m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
93  m_projMgr->GetProjection()->AddPreScaleEntry(0, 300, 0.2);
94  } else {
95  m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
96  m_projMgr->GetProjection()->AddPreScaleEntry(1, 310, 1.0);
97  m_projMgr->GetProjection()->AddPreScaleEntry(0, 370, 0.2);
98  m_projMgr->GetProjection()->AddPreScaleEntry(1, 580, 0.2);
99  }
100 
101 
102  // camera
103  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
104  if ( TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>( &(viewerGL()->CurrentCamera()) ) ) {
105  camera->SetZoomMax(1e6);
106  }
107  geoScene()->GetGLScene()->SetSelectable(kFALSE);
108 
109  m_axes = new TEveProjectionAxes(m_projMgr);
110  m_axes->SetRnrState(m_showProjectionAxes.value());
111  m_axes->SetLabelSize(m_projectionAxesLabelSize.value());
112  m_showProjectionAxes.changed_.connect(boost::bind(&FWRPZView::showProjectionAxes,this));
114  eventScene()->AddElement(m_axes);
115 
116  if ( id != FWViewType::kRhoZ ) {
117  m_showEndcaps = new FWBoolParameter(this,"Include EndCaps", true);
118  m_showEndcaps->changed_.connect( boost::bind(&FWRPZView::setEtaRng, this) );
119  m_showHF = new FWBoolParameter(this,"Include HF", true);
120  m_showHF->changed_.connect( boost::bind(&FWRPZView::setEtaRng, this) );
121  }
122 
123  m_shiftOrigin.changed_.connect(boost::bind(&FWRPZView::doShiftOriginToBeamSpot,this));
124 
125  m_fishEyeDistortion.changed_.connect(boost::bind(&FWRPZView::doFishEyeDistortion,this));
126 
127  m_fishEyeR.changed_.connect(boost::bind(&FWRPZView::doFishEyeDistortion,this));
128 
129  m_caloDistortion.changed_.connect(boost::bind(&FWRPZView::doPreScaleDistortion,this));
130  m_muonDistortion.changed_.connect(boost::bind(&FWRPZView::doPreScaleDistortion,this));
131  m_compressMuon.changed_.connect(boost::bind(&FWRPZView::doCompression,this,_1));
132 }
133 
135 {
136  m_calo->Destroy();
137  m_projMgr->DecDenyDestroy();
138 }
139 
140 //
141 // member functions
142 //
143 
144 TEveCaloViz*
146 {
147  return static_cast<TEveCaloViz*>(m_calo);
148 }
149 
150 void
152 {
154 
156  m_geometryList->IncDenyDestroy();
158  TEveElement* p = m_projMgr->ImportElements(m_geometryList);
159  geoScene()->AddElement(p);
160 
161  TEveCaloData* data = context().getCaloData();
162 
163  TEveCalo3D* calo3d = new TEveCalo3D(data);
164 
165  m_calo = static_cast<TEveCalo2D*> (m_projMgr->ImportElements(calo3d, eventScene()));
166 
167  if (typeId() == FWViewType::kRhoPhiPF)
168  m_calo->SetBarrelRadius(177);
169  else
170  m_calo->SetBarrelRadius(context().caloR1(false));
171 
172  m_calo->SetEndCapPos(context().caloZ1(false));
173  m_calo->SetAutoRange(false);
174  m_calo->SetScaleAbs(true);
175 
183 
184 }
185 
186 void
188 {
189  if (context().getBeamSpot())
190  {
191  FWBeamSpot& b = *(context().getBeamSpot());
192  fwLog(fwlog::kDebug) << Form("%s::eventBegin Set projection center (%f, %f, %f) \n", typeName().c_str(), b.x0(), b.y0(), b.z0());
193 
194  // projection center
195  TEveVector center(b.x0(), b.y0(), b.z0());
196  m_projMgr->GetProjection()->SetCenter(center);
197 
198  // camera move
199  TGLCamera& cam = viewerGL()->CurrentCamera();
200  cam.SetExternalCenter(true);
201  if (typeId() != FWViewType::kRhoZ)
202  {
203  double r = TMath::Sqrt( b.x0()*b.x0() + b.y0()*b.y0());
204  cam.SetCenterVec(b.z0(), TMath::Sign(r, b.y0()), 0);
205  }
206  else
207  {
208  cam.SetCenterVec(b.x0(), b.y0(), b.z0());
209  }
210  }
211 }
212 
213 void
215 {
216 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
217 
218  TEveProjection* p = m_projMgr->GetProjection();
219  if (p->GetDisplaceOrigin() != m_shiftOrigin.value())
220  {
221  p->SetDisplaceOrigin( m_shiftOrigin.value());
222  m_projMgr->ProjectChildren();
223  gEve->Redraw3D();
224  }
225 #endif
226 }
227 
228 void
229 FWRPZView::shiftOrigin(TEveVector& center)
230 {
231 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
232  // re-project with new center
233  m_projMgr->GetProjection()->SetCenter(center);
234  m_projMgr->ProjectChildren();
235 
236  // draw projected center
237  float* pc = m_projMgr->GetProjection()->GetProjectedCenter();
238  viewerGL()->CurrentCamera().SetExternalCenter(true);
239  viewerGL()->CurrentCamera().SetCenterVec(pc[0], pc[1], pc[2]);
240  viewerGL()->SetDrawCameraCenter(true);
241 
242  gEve->Redraw3D();
243 #endif
244 }
245 
246 void
248 {
249  // set center back to beam spot
250 
251 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
252  FWBeamSpot& b = *(context().getBeamSpot());
253  TEveVector center(b.x0(), b.y0(), b.z0());
254  m_projMgr->GetProjection()->SetCenter(center);
255 
256  m_projMgr->ProjectChildren();
257  gEve->Redraw3D();
258 #endif
259 }
260 
261 
262 void
264 {
265  TEveProjection* p = m_projMgr->GetProjection();
266  if (p->GetDistortion() != m_fishEyeDistortion.value()*s_distortFInv)
267  p->SetDistortion(m_fishEyeDistortion.value()*s_distortF);
268  if (p->GetFixR() != m_fishEyeR.value())
269  p->SetFixR(m_fishEyeR.value());
270 
271  m_projMgr->ProjectChildren();
272  gEve->Redraw3D();
273 }
274 
275 void
277 {
279  m_projMgr->GetProjection()->ChangePreScaleEntry(0,1,m_caloDistortion.value());
280  m_projMgr->GetProjection()->ChangePreScaleEntry(0,2,m_muonDistortion.value());
281  } else {
282  m_projMgr->GetProjection()->ChangePreScaleEntry(0,1,m_caloDistortion.value());
283  m_projMgr->GetProjection()->ChangePreScaleEntry(0,2,m_muonDistortion.value());
284  m_projMgr->GetProjection()->ChangePreScaleEntry(1,1,m_caloDistortion.value());
285  m_projMgr->GetProjection()->ChangePreScaleEntry(1,2,m_muonDistortion.value());
286  }
287  m_projMgr->UpdateName();
288  m_projMgr->ProjectChildren();
289  gEve->Redraw3D();
290 }
291 
292 void
294 {
295  m_projMgr->GetProjection()->SetUsePreScale(flag);
296  m_projMgr->UpdateName();
297  m_projMgr->ProjectChildren();
298  gEve->Redraw3D();
299 }
300 
301 void
302 FWRPZView::importElements(TEveElement* iChildren, float iLayer, TEveElement* iProjectedParent)
303 {
304  float oldLayer = m_projMgr->GetCurrentDepth();
305  m_projMgr->SetCurrentDepth(iLayer);
306  //make sure current depth is reset even if an exception is thrown
307  boost::shared_ptr<TEveProjectionManager> sentry(m_projMgr,
308  boost::bind(&TEveProjectionManager::SetCurrentDepth,
309  _1,oldLayer));
310  m_projMgr->ImportElements(iChildren,iProjectedParent);
311 }
312 
313 
314 void
316 {
317  FWEveView::addTo(iTo);
318  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>( &(viewerGL()->CurrentCamera()) );
319  if (camera) addToOrthoCamera(camera, iTo);
320 }
321 
322 void
324 {
325  FWEveView::setFrom(iFrom);
326 
327  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>( &(viewerGL()->CurrentCamera()) );
328  if (camera) setFromOrthoCamera(camera, iFrom);
329 
330  if (iFrom.version() < 7)
331  {
332  const FWConfiguration* value = iFrom.valueForKey("Show projection axes");
333  if (value)
334  m_showProjectionAxes.set(value->value() == "1");
335  }
336 }
337 
338 void
340 {
341  if (typeId() != FWViewType::kRhoZ)
342  {
343  // rng controllers only in RhoPhi
344  double eta_range = context().caloMaxEta();
345  if (!m_showHF->value() ) eta_range = 3.0;
346  if (!m_showEndcaps->value() ) eta_range = context().caloTransEta();
347  m_calo->SetEta(-eta_range,eta_range);
348  }
349 
351 }
352 
353 void
355 {
356  if (! m_calo->GetData()->Empty())
357  {
358  m_calo->AssertCellIdCache();
359  Float_t sumEt, sumE;
360  TEveCaloData::CellData_t cellData;
361  typedef std::vector<TEveCaloData::vCellId_t*> vBinCells_t;
362  typedef std::vector<TEveCaloData::vCellId_t*>::iterator vBinCells_i;
363 
364  vBinCells_t cellLists = m_calo->fCellLists;
365  for (vBinCells_i it = cellLists.begin(); it != cellLists.end(); it++)
366  {
367  TEveCaloData::vCellId_t* binCells = *it;
368  if (binCells) {
369  sumEt = 0; sumE = 0;
370  TEveCaloData::vCellId_i a = binCells->end();
371 
372  for (TEveCaloData::vCellId_i k = binCells->begin(); k != a; ++k)
373  {
374  m_calo->GetData()->GetCellData((*k), cellData);
375  sumEt += cellData.Value(true);
376  sumE += cellData.Value(false);
377  }
378  // printf("vote sum %f %f \n", sumEt , sumE);
379  context().voteMaxEtAndEnergy(sumEt, sumE);
380  }
381  }
382  }
383 }
384 
386 {
387  m_axes->SetRnrState(m_showProjectionAxes.value());
388  gEve->Redraw3D();
389  viewerGL()->RequestDraw();
390 }
391 
393 {
394  m_axes->SetLabelSize(m_projectionAxesLabelSize.value());
395  viewerGL()->RequestDraw();
396 }
397 
398 void
400 {
402 
403  ViewerParameterGUI& det = gui.requestTab("Detector");;
405 
406  if (typeId() == FWViewType::kRhoZ)
407  {
411  bool showGEM = m_context->getGeom()->versionInfo().haveExtraDet("GEM");
412  if (showGEM) det.addParam(&m_showGEM);
413  bool showME0 = m_context->getGeom()->versionInfo().haveExtraDet("ME0");
414  if (showME0) det.addParam(&m_showME0);
415  }
416 
417 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
418  gui.requestTab("Projection").addParam(&m_shiftOrigin);
419 #endif
420 
421  gui.requestTab("Projection").
422  addParam(&m_showProjectionAxes).
423  addParam(&m_projectionAxesLabelSize).
424  separator();
425 
426  TGCompositeFrame* f = gui.getTabContainer();
427 
428  f->AddFrame(new TGLabel(f, "FishEye:"));
430  addParam(&m_fishEyeR).
431  separator();
432 
433  f->AddFrame(new TGLabel(f, "PreScales:"));
434 
435  gui.requestTab("Projection").
436  addParam(&m_compressMuon).
437  addParam(&m_muonDistortion).
438  addParam(&m_caloDistortion);
439 
440 
442  {
443  gui.requestTab("Calo").
444  addParam(m_showHF).
445  addParam(m_showEndcaps);
446  }
447 }
448 
static float caloTransEta()
Definition: Context.cc:230
void doShiftOriginToBeamSpot()
Definition: FWRPZView.cc:214
void addToOrthoCamera(TGLOrthoCamera *, FWConfiguration &) const
Definition: FWEveView.cc:418
void doFishEyeDistortion()
Definition: FWRPZView.cc:263
virtual void populateController(ViewerParameterGUI &) const
Definition: FWRPZView.cc:399
FWBoolParameter m_shiftOrigin
Definition: FWRPZView.h:99
TEveScene * eventScene()
Definition: FWEveView.h:82
FWBoolParameter m_showProjectionAxes
Definition: FWRPZView.h:105
double x0() const
Definition: FWBeamSpot.cc:30
FWRPZView(TEveWindowSlot *iParent, FWViewType::EType)
Definition: FWRPZView.cc:50
T Sign(T A, T B)
Definition: MathUtil.h:54
virtual TEveCaloViz * getEveCalo() const
Definition: FWRPZView.cc:145
TEveCalo2D * m_calo
Definition: FWRPZView.h:86
double z0() const
Definition: FWBeamSpot.cc:40
double y0() const
Definition: FWBeamSpot.cc:35
virtual void setContext(const fireworks::Context &)
Definition: FWRPZView.cc:151
FWBoolParameter m_showME0
Definition: FWRPZView.h:97
FWDoubleParameter m_projectionAxesLabelSize
Definition: FWRPZView.h:106
virtual void populateController(ViewerParameterGUI &) const
Definition: FWEveView.cc:551
const FWGeometry * getGeom() const
Definition: Context.h:83
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:185
ViewerParameterGUI & requestTab(const char *)
virtual void setFrom(const FWConfiguration &)
Definition: FWEveView.cc:364
const std::string & typeName() const
Definition: FWViewBase.cc:120
unsigned int version() const
virtual void setupEnergyScale()
Definition: FWEveView.cc:307
TEveProjectionAxes * m_axes
Definition: FWRPZView.h:85
TGLViewer * viewerGL() const
Definition: FWEveView.cc:194
sigc::signal< void, T > changed_
FWParameters::Bool FWBoolParameter
Definition: FWParameters.h:38
const fireworks::Context * m_context
Definition: FWEveView.h:111
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:117
FWBoolParameter * m_showHF
Definition: FWRPZView.h:109
TEveProjectionManager * m_projMgr
Definition: FWRPZView.h:84
FWDoubleParameter m_fishEyeR
Definition: FWRPZView.h:101
void resetOrigin()
Definition: FWRPZView.cc:247
FWBoolParameter m_showRpcEndcap
Definition: FWRPZView.h:95
float caloR1()
Definition: FWPFGeom.h:21
void initStdGeoElements(const FWViewType::EType id)
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:379
void doCompression(bool)
Definition: FWRPZView.cc:293
FWBeamSpot * getBeamSpot() const
Definition: Context.h:78
virtual void setFrom(const FWConfiguration &)
Definition: FWRPZView.cc:323
void setEtaRng()
Definition: FWRPZView.cc:339
virtual void voteCaloMaxVal()
Definition: FWRPZView.cc:354
FWBoolParameter m_showTrackerBarrel
Definition: FWRPZView.h:93
void showProjectionAxes()
Definition: FWRPZView.cc:385
static float caloR1(bool offset=true)
Definition: Context.cc:210
double f[11][100]
void importElements(TEveElement *iProjectableChild, float layer, TEveElement *iProjectedParent=0)
Definition: FWRPZView.cc:302
TEveCaloDataHist * getCaloData() const
Definition: Context.h:80
virtual void addTo(FWConfiguration &) const
Definition: FWRPZView.cc:315
FWBoolParameter m_compressMuon
Definition: FWRPZView.h:107
FWRPZViewGeometry * m_geometryList
Definition: FWRPZView.h:83
void shiftOrigin(TEveVector &center)
Definition: FWRPZView.cc:229
const std::string & value(unsigned int iIndex=0) const
const fireworks::Context & context()
Definition: FWEveView.h:67
virtual ~FWRPZView()
Definition: FWRPZView.cc:134
virtual void eventBegin()
Definition: FWRPZView.cc:187
#define fwLog(_level_)
Definition: fwLog.h:50
void doPreScaleDistortion()
Definition: FWRPZView.cc:276
FWBoolParameter * m_showEndcaps
Definition: FWRPZView.h:110
FWBoolParameter m_showGEM
Definition: FWRPZView.h:96
float caloZ1()
Definition: FWPFGeom.h:22
static const float s_distortFInv
Definition: FWRPZView.h:81
double b
Definition: hdecay.h:120
void showTrackerBarrel(bool)
FWDoubleParameter m_fishEyeDistortion
Definition: FWRPZView.h:100
TEveScene * geoScene()
Definition: FWEveView.h:83
ViewerParameterGUI & addParam(const FWParameterBase *)
FWBoolParameter m_showTrackerEndcap
Definition: FWRPZView.h:94
TGCompositeFrame * getTabContainer()
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static double caloMaxEta()
Definition: Context.cc:240
double a
Definition: hdecay.h:121
FWDoubleParameter m_muonDistortion
Definition: FWRPZView.h:104
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
volatile std::atomic< bool > shutdown_flag false
FWBoolParameter m_showPixelBarrel
Definition: FWRPZView.h:91
void setFromOrthoCamera(TGLOrthoCamera *, const FWConfiguration &)
Definition: FWEveView.cc:436
virtual void addTo(FWConfiguration &) const
Definition: FWEveView.cc:346
static const float s_distortF
Definition: FWRPZView.h:80
void projectionAxesLabelSize()
Definition: FWRPZView.cc:392
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:275
FWViewType::EType typeId() const
Definition: FWViewBase.h:41