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 // $Id: FWRPZView.cc,v 1.41 2011/03/17 12:02:44 amraktad Exp $
12 //
13 
14 // system include files
15 #include <stdexcept>
16 #include <boost/bind.hpp>
17 #include <boost/shared_ptr.hpp>
18 
19 #include "TGLViewer.h"
20 #include "TGLScenePad.h"
21 #include "TEveManager.h"
22 #include "TEveElement.h"
23 #include "TEveScene.h"
24 #include "TEveProjections.h"
25 #include "TEveProjectionAxes.h"
26 #include "TGLabel.h"
27 #include "TEveProjectionManager.h"
28 
30 #define protected public
31 #include "TEveCalo.h"
32 #undef protected
33 
34 // user include files
44 
46 const float FWRPZView::s_distortF = 0.001;
47 const float FWRPZView::s_distortFInv = 1000;
48 //
49 // constructors and destructor
50 //
51 FWRPZView::FWRPZView(TEveWindowSlot* iParent, FWViewType::EType id) :
52  FWEveView(iParent, id, 7),
53  m_calo(0),
54  m_shiftOrigin(this,"Shift origin to beam-spot", true),
55  m_fishEyeDistortion(this,"Distortion",0., 0., 100.),
56  m_fishEyeR(this,"FixedRadius",(double)fireworks::Context::caloR1(), 0.0, 150.0),
57 
58  m_caloDistortion(this,"Calo compression",1.0,0.01,10.),
59  m_muonDistortion(this,"Muon compression",0.2,0.01,10.),
60  m_showProjectionAxes(this,"Show projection axis", false),
61  m_compressMuon(this,"Compress detectors",false),
62  m_showHF(0),
63  m_showEndcaps(0)
64 {
65 
66  TEveProjection::EPType_e projType = (id == FWViewType::kRhoZ) ? TEveProjection::kPT_RhoZ : TEveProjection::kPT_RPhi;
67 
68  m_projMgr = new TEveProjectionManager(projType);
69  m_projMgr->IncDenyDestroy();
70  m_projMgr->SetImportEmpty(kTRUE);
71 
72  m_projMgr->GetProjection()->SetDistortion(m_fishEyeDistortion.value()*s_distortF);
73  m_projMgr->GetProjection()->SetFixR(m_fishEyeR.value());
74 
75 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
76  m_projMgr->GetProjection()->SetDisplaceOrigin( m_shiftOrigin.value());
77 #endif
78 
79  if ( id == FWViewType::kRhoPhi || id == FWViewType::kRhoPhiPF) {
80  m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
81  m_projMgr->GetProjection()->AddPreScaleEntry(0, 300, 0.2);
82  } else {
83  m_projMgr->GetProjection()->AddPreScaleEntry(0, fireworks::Context::caloR1(), 1.0);
84  m_projMgr->GetProjection()->AddPreScaleEntry(1, 310, 1.0);
85  m_projMgr->GetProjection()->AddPreScaleEntry(0, 370, 0.2);
86  m_projMgr->GetProjection()->AddPreScaleEntry(1, 580, 0.2);
87  }
88 
89 
90  // camera
91  viewerGL()->SetCurrentCamera(TGLViewer::kCameraOrthoXOY);
92  if ( TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>( &(viewerGL()->CurrentCamera()) ) ) {
93  camera->SetZoomMax(1e6);
94  }
95  geoScene()->GetGLScene()->SetSelectable(kFALSE);
96 
97  m_axes = new TEveProjectionAxes(m_projMgr);
98  m_axes->SetRnrState(m_showProjectionAxes.value());
99  m_axes->SetLabelSize(0.015);
100  m_showProjectionAxes.changed_.connect(boost::bind(&FWRPZView::showProjectionAxes,this));
101  eventScene()->AddElement(m_axes);
102 
103  if ( id != FWViewType::kRhoZ ) {
104  m_showEndcaps = new FWBoolParameter(this,"Include EndCaps", true);
105  m_showEndcaps->changed_.connect( boost::bind(&FWRPZView::setEtaRng, this) );
106  m_showHF = new FWBoolParameter(this,"Include HF", true);
107  m_showHF->changed_.connect( boost::bind(&FWRPZView::setEtaRng, this) );
108  }
109 
110  m_shiftOrigin.changed_.connect(boost::bind(&FWRPZView::doShiftOrigin,this));
111 
112  m_fishEyeDistortion.changed_.connect(boost::bind(&FWRPZView::doFishEyeDistortion,this));
113  m_fishEyeR.changed_.connect(boost::bind(&FWRPZView::doFishEyeDistortion,this));
114 
115  m_caloDistortion.changed_.connect(boost::bind(&FWRPZView::doPreScaleDistortion,this));
116  m_muonDistortion.changed_.connect(boost::bind(&FWRPZView::doPreScaleDistortion,this));
117  m_compressMuon.changed_.connect(boost::bind(&FWRPZView::doCompression,this,_1));
118 }
119 
121 {
122  m_calo->Destroy();
123  m_projMgr->DecDenyDestroy();
124 }
125 
126 //
127 // member functions
128 //
129 
130 TEveCaloViz*
132 {
133  return static_cast<TEveCaloViz*>(m_calo);
134 }
135 
136 void
138 {
140 
141  if (!s_geometryList)
142  {
144  s_geometryList->IncDenyDestroy();
145  }
146  m_projMgr->ImportElements(s_geometryList->getGeoElements(typeId()), geoScene());
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 }
163 
164 void
166 {
167  if (context().getBeamSpot())
168  {
169  FWBeamSpot& b = *(context().getBeamSpot());
170  fwLog(fwlog::kDebug) << Form("%s::eventBegin Set projection center (%f, %f, %f) \n", typeName().c_str(), b.x0(), b.y0(), b.z0());
171 
172  // projection center
173  TEveVector center(b.x0(), b.y0(), b.z0());
174  m_projMgr->GetProjection()->SetCenter(center);
175 
176  // camera move
177  TGLCamera& cam = viewerGL()->CurrentCamera();
178  cam.SetExternalCenter(true);
179  if (typeId() != FWViewType::kRhoZ)
180  {
181  double r = TMath::Sqrt( b.x0()*b.x0() + b.y0()*b.y0());
182  cam.SetCenterVec(b.z0(), TMath::Sign(r, b.y0()), 0);
183  }
184  else
185  {
186  cam.SetCenterVec(b.x0(), b.y0(), b.z0());
187  }
188  }
189 }
190 
191 void
193 {
194 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
195 
196  TEveProjection* p = m_projMgr->GetProjection();
197  if (p->GetDisplaceOrigin() != m_shiftOrigin.value())
198  {
199  p->SetDisplaceOrigin( m_shiftOrigin.value());
200  m_projMgr->ProjectChildren();
201  gEve->Redraw3D();
202  }
203 #endif
204 }
205 
206 void
208 {
209  TEveProjection* p = m_projMgr->GetProjection();
210  if (p->GetDistortion() != m_fishEyeDistortion.value()*s_distortFInv)
211  p->SetDistortion(m_fishEyeDistortion.value()*s_distortF);
212  if (p->GetFixR() != m_fishEyeR.value())
213  p->SetFixR(m_fishEyeR.value());
214 
215  m_projMgr->ProjectChildren();
216  gEve->Redraw3D();
217 }
218 
219 void
221 {
223  m_projMgr->GetProjection()->ChangePreScaleEntry(0,1,m_caloDistortion.value());
224  m_projMgr->GetProjection()->ChangePreScaleEntry(0,2,m_muonDistortion.value());
225  } else {
226  m_projMgr->GetProjection()->ChangePreScaleEntry(0,1,m_caloDistortion.value());
227  m_projMgr->GetProjection()->ChangePreScaleEntry(0,2,m_muonDistortion.value());
228  m_projMgr->GetProjection()->ChangePreScaleEntry(1,1,m_caloDistortion.value());
229  m_projMgr->GetProjection()->ChangePreScaleEntry(1,2,m_muonDistortion.value());
230  }
231  m_projMgr->UpdateName();
232  m_projMgr->ProjectChildren();
233  gEve->Redraw3D();
234 }
235 
236 void
238 {
239  m_projMgr->GetProjection()->SetUsePreScale(flag);
240  m_projMgr->UpdateName();
241  m_projMgr->ProjectChildren();
242  gEve->Redraw3D();
243 }
244 
245 void
246 FWRPZView::importElements(TEveElement* iChildren, float iLayer, TEveElement* iProjectedParent)
247 {
248  float oldLayer = m_projMgr->GetCurrentDepth();
249  m_projMgr->SetCurrentDepth(iLayer);
250  //make sure current depth is reset even if an exception is thrown
251  boost::shared_ptr<TEveProjectionManager> sentry(m_projMgr,
252  boost::bind(&TEveProjectionManager::SetCurrentDepth,
253  _1,oldLayer));
254  m_projMgr->ImportElements(iChildren,iProjectedParent);
255 }
256 
257 
258 void
260 {
261  FWEveView::addTo(iTo);
262  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>( &(viewerGL()->CurrentCamera()) );
263  if (camera) addToOrthoCamera(camera, iTo);
264 }
265 
266 void
268 {
269  FWEveView::setFrom(iFrom);
270 
271  TGLOrthoCamera* camera = dynamic_cast<TGLOrthoCamera*>( &(viewerGL()->CurrentCamera()) );
272  if (camera) setFromOrthoCamera(camera, iFrom);
273 
274  if (iFrom.version() < 7)
275  {
276  const FWConfiguration* value = iFrom.valueForKey("Show projection axes");
277  if (value)
278  m_showProjectionAxes.set(value->value() == "1");
279  }
280 }
281 
282 void
284 {
285  if (typeId() != FWViewType::kRhoZ)
286  {
287  // rng controllers only in RhoPhi
288  double eta_range = context().caloMaxEta();
289  if (!m_showHF->value() ) eta_range = 3.0;
290  if (!m_showEndcaps->value() ) eta_range = context().caloTransEta();
291  m_calo->SetEta(-eta_range,eta_range);
292  }
293 
295 }
296 
297 void
299 {
300  if (! m_calo->GetData()->Empty())
301  {
302  m_calo->AssertCellIdCache();
303  Float_t sumEt, sumE;
304  TEveCaloData::CellData_t cellData;
305  typedef std::vector<TEveCaloData::vCellId_t*> vBinCells_t;
306  typedef std::vector<TEveCaloData::vCellId_t*>::iterator vBinCells_i;
307 
308  vBinCells_t cellLists = m_calo->fCellLists;
309  for (vBinCells_i it = cellLists.begin(); it != cellLists.end(); it++)
310  {
311  TEveCaloData::vCellId_t* binCells = *it;
312  if (binCells) {
313  sumEt = 0; sumE = 0;
314  TEveCaloData::vCellId_i a = binCells->end();
315 
316  for (TEveCaloData::vCellId_i k = binCells->begin(); k != a; ++k)
317  {
318  m_calo->GetData()->GetCellData((*k), cellData);
319  sumEt += cellData.Value(true);
320  sumE += cellData.Value(false);
321  }
322  // printf("vote sum %f %f \n", sumEt , sumE);
323  context().voteMaxEtAndEnergy(sumEt, sumE);
324  }
325  }
326  }
327 }
328 
330 {
331  if ( m_showProjectionAxes.value() )
332  m_axes->SetRnrState(kTRUE);
333  else
334  m_axes->SetRnrState(kFALSE);
335  gEve->Redraw3D();
336 }
337 
338 void
340 {
342 
343 #ifdef TEVEPROJECTIONS_DISPLACE_ORIGIN_MODE
344  gui.requestTab("Projection").addParam(&m_shiftOrigin);
345 #endif
346 
347  gui.requestTab("Projection").addParam(&m_showProjectionAxes).separator();
348 
349  TGCompositeFrame* f = gui.getTabContainer();
350 
351  f->AddFrame(new TGLabel(f, "FishEye:"));
353  addParam(&m_fishEyeR).
354  separator();
355 
356  f->AddFrame(new TGLabel(f, "PreScales:"));
357 
358  gui.requestTab("Projection").
359  addParam(&m_compressMuon).
360  addParam(&m_muonDistortion).
361  addParam(&m_caloDistortion);
362 
363 
365  {
366  gui.requestTab("Calo").
367  addParam(m_showHF).
368  addParam(m_showEndcaps);
369  }
370 }
371 
static float caloTransEta()
Definition: Context.cc:230
TEveElement * getGeoElements(const FWViewType::EType id)
static FWRPZViewGeometry * s_geometryList
Definition: FWRPZView.h:76
void addToOrthoCamera(TGLOrthoCamera *, FWConfiguration &) const
Definition: FWEveView.cc:393
void doFishEyeDistortion()
Definition: FWRPZView.cc:207
virtual void populateController(ViewerParameterGUI &) const
Definition: FWRPZView.cc:339
long int flag
Definition: mlp_lapack.h:47
FWBoolParameter m_shiftOrigin
Definition: FWRPZView.h:86
TEveScene * eventScene()
Definition: FWEveView.h:76
FWBoolParameter m_showProjectionAxes
Definition: FWRPZView.h:92
double x0() const
Definition: FWBeamSpot.cc:21
FWRPZView(TEveWindowSlot *iParent, FWViewType::EType)
Definition: FWRPZView.cc:51
virtual TEveCaloViz * getEveCalo() const
Definition: FWRPZView.cc:131
TEveCalo2D * m_calo
Definition: FWRPZView.h:82
double z0() const
Definition: FWBeamSpot.cc:31
double y0() const
Definition: FWBeamSpot.cc:26
virtual void setContext(const fireworks::Context &)
Definition: FWRPZView.cc:137
virtual void populateController(ViewerParameterGUI &) const
Definition: FWEveView.cc:531
void voteMaxEtAndEnergy(float Et, float energy) const
Definition: Context.cc:185
ViewerParameterGUI & requestTab(const char *)
virtual void setFrom(const FWConfiguration &)
Definition: FWEveView.cc:356
ViewerParameterGUI & separator()
const std::string & typeName() const
Definition: FWViewBase.cc:114
unsigned int version() const
virtual void setupEnergyScale()
Definition: FWEveView.cc:299
TEveProjectionAxes * m_axes
Definition: FWRPZView.h:81
TGLViewer * viewerGL() const
Definition: FWEveView.cc:198
sigc::signal< void, T > changed_
FWParameters::Bool FWBoolParameter
Definition: FWParameters.h:39
FWBoolParameter * m_showHF
Definition: FWRPZView.h:95
TEveProjectionManager * m_projMgr
Definition: FWRPZView.h:80
FWDoubleParameter m_fishEyeR
Definition: FWRPZView.h:88
void doCompression(bool)
Definition: FWRPZView.cc:237
FWBeamSpot * getBeamSpot() const
Definition: Context.h:79
virtual void setFrom(const FWConfiguration &)
Definition: FWRPZView.cc:267
void doShiftOrigin()
Definition: FWRPZView.cc:192
void setEtaRng()
Definition: FWRPZView.cc:283
virtual void voteCaloMaxVal()
Definition: FWRPZView.cc:298
void showProjectionAxes()
Definition: FWRPZView.cc:329
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:246
TEveCaloDataHist * getCaloData() const
Definition: Context.h:81
virtual void addTo(FWConfiguration &) const
Definition: FWRPZView.cc:259
FWBoolParameter m_compressMuon
Definition: FWRPZView.h:93
int k[5][pyjets_maxn]
const std::string & value(unsigned int iIndex=0) const
const fireworks::Context & context()
Definition: FWEveView.h:65
virtual ~FWRPZView()
Definition: FWRPZView.cc:120
virtual void eventBegin()
Definition: FWRPZView.cc:165
#define fwLog(_level_)
Definition: fwLog.h:51
void doPreScaleDistortion()
Definition: FWRPZView.cc:220
FWBoolParameter * m_showEndcaps
Definition: FWRPZView.h:96
static const float s_distortFInv
Definition: FWRPZView.h:78
double b
Definition: hdecay.h:120
FWDoubleParameter m_fishEyeDistortion
Definition: FWRPZView.h:87
TEveScene * geoScene()
Definition: FWEveView.h:77
ViewerParameterGUI & addParam(const FWParameterBase *)
TGCompositeFrame * getTabContainer()
static double caloMaxEta()
Definition: Context.cc:240
double a
Definition: hdecay.h:121
FWDoubleParameter m_muonDistortion
Definition: FWRPZView.h:91
FWDoubleParameter m_caloDistortion
Definition: FWRPZView.h:90
const FWConfiguration * valueForKey(const std::string &iKey) const
void setFromOrthoCamera(TGLOrthoCamera *, const FWConfiguration &)
Definition: FWEveView.cc:413
virtual void addTo(FWConfiguration &) const
Definition: FWEveView.cc:338
static const float s_distortF
Definition: FWRPZView.h:77
virtual void setContext(const fireworks::Context &x)
Definition: FWEveView.cc:267
FWViewType::EType typeId() const
Definition: FWViewBase.h:42