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