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