CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWRPZViewGeometry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWRPZViewGeometry
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Thu Mar 25 20:33:06 CET 2010
11 // $Id: FWRPZViewGeometry.cc,v 1.19 2011/10/15 02:33:30 amraktad Exp $
12 //
13 
14 // system include files
15 #include <iostream>
16 #include <cassert>
17 
18 // user include files
19 #include "TGeoBBox.h"
20 
21 #include "TEveElement.h"
22 #include "TEveCompound.h"
23 #include "TEveScene.h"
24 #include "TEvePointSet.h"
25 #include "TEveStraightLineSet.h"
26 #include "TEveGeoNode.h"
27 #include "TEveManager.h"
28 #include "TEveProjectionManager.h"
29 
35 
38 
39 //
40 //
41 //
42 // constants, enums and typedefs
43 //
44 
45 //
46 // static data member definitions
47 //
48 
49 //
50 // constructors and destructor
51 //
53  FWViewGeometryList(context),
54 
55  m_rhoPhiGeo(0),
56  m_rhoZGeo(0),
57 
58  m_pixelBarrelElements(0),
59  m_pixelEndcapElements(0),
60  m_trackerBarrelElements(0),
61  m_trackerEndcapElements(0)
62 {
63  SetElementName("RPZGeomShared");
64 }
65 
66 // FWRPZViewGeometry::FWRPZViewGeometry(const FWRPZViewGeometry& rhs)
67 // {
68 // // do actual copying here;
69 // }
70 
72 {
73  m_rhoPhiGeo->DecDenyDestroy();
74  m_rhoZGeo->DecDenyDestroy();
75 }
76 
77 //______________________________________________________________________________
78 
79 void
81 {
82  assert(m_geom != 0);
83 
84  if (type == FWViewType::kRhoZ)
85  {
86  AddElement(makeMuonGeometryRhoZ());
87  AddElement(makeCaloOutlineRhoZ());
88  }
89  else
90  {
91  AddElement(makeMuonGeometryRhoPhi());
92  AddElement(makeCaloOutlineRhoPhi());
93  }
94 }
95 
96 //______________________________________________________________________________
97 
98 
99 TEveElement*
101 {
102  using namespace fireworks;
103 
104  float ri = m_context.caloZ2()*tan(2*atan(exp(-m_context.caloMaxEta())));
105 
106  TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoZoutline" );
107  el->SetPickable(kFALSE);
109 
110  el->AddLine(0, m_context.caloR1(), -m_context.caloZ1(), 0, m_context.caloR1(), m_context.caloZ1());
111  el->AddLine(0, -m_context.caloR1(), m_context.caloZ1(), 0, -m_context.caloR1(), -m_context.caloZ1());
112 
113  el->AddLine(0, -m_context.caloR2(), m_context.caloZ2(), 0, -ri, m_context.caloZ2());
114  el->AddLine(0, ri, m_context.caloZ2(), 0, m_context.caloR2(), m_context.caloZ2());
115 
116  el->AddLine(0, -m_context.caloR2(), -m_context.caloZ2(), 0, -ri, -m_context.caloZ2());
117  el->AddLine(0, ri, -m_context.caloZ2(), 0, m_context.caloR2(), -m_context.caloZ2());
118 
119  return el;
120 }
121 
122 TEveElement*
124 {
125  TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoPhi" );
127 
129  const unsigned int nSegments = 100;
130  const double r = m_context.caloR1();
131  for ( unsigned int i = 1; i <= nSegments; ++i )
132  el->AddLine(r*sin(TMath::TwoPi()/nSegments*(i-1)), r*cos(TMath::TwoPi()/nSegments*(i-1)), 0,
133  r*sin(TMath::TwoPi()/nSegments*i), r*cos(TMath::TwoPi()/nSegments*i), 0);
134 
135  TEvePointSet* ref = new TEvePointSet("reference");
136  ref->SetTitle("(0,0,0)");
137  ref->SetMarkerStyle(4);
138  ref->SetMarkerColor(kWhite);
139  ref->SetNextPoint(0.,0.,0.);
140  el->AddElement(ref);
141 
142  return el;
143 }
144 
145 //______________________________________________________________________________
146 
147 TEveElement*
149 {
150  Int_t iWheel = 0;
151 
152  // rho-phi view
153  TEveCompound* container = new TEveCompound( "MuonRhoPhi" );
154 
155 
156  for( Int_t iStation = 1; iStation <= 4; ++iStation )
157  {
158  for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
159  {
160  if( iStation < 4 && iSector > 12 ) continue;
161  DTChamberId id( iWheel, iStation, iSector );
162  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
163  if( shape )
164  {
165  shape->SetMainColor(m_colorComp[kFWMuonBarrelLineColorIndex]->GetMainColor());
167  container->AddElement( shape );
168  }
169  }
170  }
171  return container;
172 }
173 
174 //______________________________________________________________________________
175 
176 TEveElement*
178 {
179  TEveElementList* container = new TEveElementList( "MuonRhoZ" );
180 
181  {
182  TEveCompound* dtContainer = new TEveCompound( "DT" );
183  for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
184  {
185  for( Int_t iStation = 1; iStation <= 4; ++iStation )
186  {
187  float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
188 
189  // This will give us a quarter of DTs
190  // which is enough for our projection
191  for( Int_t iSector = 1; iSector <= 4; ++iSector )
192  {
193  DTChamberId id( iWheel, iStation, iSector );
194  unsigned int rawid = id.rawId();
195  FWGeometry::IdToInfoItr det = m_geom->find( rawid );
196  estimateProjectionSizeDT( *det, min_rho, max_rho, min_z, max_z );
197  }
198  if ( min_rho > max_rho || min_z > max_z ) continue;
199  TEveElement* se = makeShape( min_rho, max_rho, min_z, max_z );
201  dtContainer->AddElement(se);
202  se = makeShape( -max_rho, -min_rho, min_z, max_z );
204  dtContainer->AddElement(se);
205  }
206  }
207 
208  container->AddElement( dtContainer );
209  }
210  {
211  TEveCompound* cscContainer = new TEveCompound( "CSC" );
212 
213  Int_t maxChambers = 36;
214  Int_t step = 9;
215  Int_t iLayer = 0; // chamber
216  for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
217  {
218  // Actual CSC geometry:
219  // Station 1 has 4 rings with 36 chambers in each
220  // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
221  // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
222  // Station 4: ring 1 has 18 chambers
223  for( Int_t iStation = 1; iStation <= 4; ++iStation )
224  {
225  for( Int_t iRing = 1; iRing <= 4; ++iRing )
226  {
227  if( iStation > 1 && iRing > 2 ) continue;
228  if( iStation > 3 && iRing > 1 ) continue;
229  float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
230  ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
231  ( iRing == 1 && iStation > 1 ) ? ( step = 5 ) : ( step = 18 );
232 
233  // Skip most of the chambers since they will project
234  // the same way as the two top ones and the two bottom ones
235  for( Int_t iChamber = step; iChamber <= maxChambers; iChamber += step )
236  {
237  CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
238  FWGeometry::IdToInfoItr det = m_geom->find( id.rawId() );
239  estimateProjectionSizeCSC( *det, min_rho, max_rho, min_z, max_z );
240 
241  // and a chamber next to it
242  ++iChamber;
243  CSCDetId nextid( iEndcap, iStation, iRing, iChamber, iLayer );
244  det = m_geom->find( nextid.rawId() );
245  estimateProjectionSizeCSC( *det, min_rho, max_rho, min_z, max_z );
246  }
247  if ( min_rho > max_rho || min_z > max_z ) continue;
248 
249  TEveElement* se = makeShape( min_rho, max_rho, min_z, max_z);
251  cscContainer->AddElement(se);
252 
253  se = makeShape( -max_rho, -min_rho, min_z, max_z );
255  cscContainer->AddElement(se);
256  }
257  }
258  }
259  container->AddElement( cscContainer );
260  }
261  return container;
262 }
263 
264 //______________________________________________________________________________
265 
266 TEveGeoShape*
267 FWRPZViewGeometry::makeShape( double min_rho, double max_rho, double min_z, double max_z)
268 {
269  TEveTrans t;
270  t(1,1) = 1; t(1,2) = 0; t(1,3) = 0;
271  t(2,1) = 0; t(2,2) = 1; t(2,3) = 0;
272  t(3,1) = 0; t(3,2) = 0; t(3,3) = 1;
273  t(1,4) = 0; t(2,4) = (min_rho+max_rho)/2; t(3,4) = (min_z+max_z)/2;
274 
275  TEveGeoShape* shape = new TEveGeoShape;
276  shape->SetTransMatrix(t.Array());
277 
278  shape->SetRnrSelf(kTRUE);
279  shape->SetRnrChildren(kTRUE);
280  TGeoBBox* box = new TGeoBBox( 0, (max_rho-min_rho)/2, (max_z-min_z)/2 );
281  shape->SetShape( box );
282 
283  return shape;
284 }
285 
286 //______________________________________________________________________________
287 
288 void
290  float& min_rho, float& max_rho, float& min_z, float& max_z )
291 {
292  // we will test 5 points on both sides ( +/- z)
293  float local[3], global[3];
294 
295  float dX = info.shape[1];
296  float dY = info.shape[2];
297  float dZ = info.shape[3];
298 
299  local[0] = 0; local[1] = 0; local[2] = dZ;
300  m_geom->localToGlobal( info, local, global );
301  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
302 
303  local[0] = dX; local[1] = dY; local[2] = dZ;
304  m_geom->localToGlobal( info, local, global );
305  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
306 
307  local[0] = -dX; local[1] = dY; local[2] = dZ;
308  m_geom->localToGlobal( info, local, global );
309  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
310 
311  local[0] = dX; local[1] = -dY; local[2] = dZ;
312  m_geom->localToGlobal( info, local, global );
313  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
314 
315  local[0] = -dX; local[1] = -dY; local[2] = dZ;
316  m_geom->localToGlobal( info, local, global );
317  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
318 
319  local[0] = 0; local[1] = 0; local[2] = -dZ;
320  m_geom->localToGlobal( info, local, global );
321  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
322 
323  local[0] = dX; local[1] = dY; local[2] = -dZ;
324  m_geom->localToGlobal( info, local, global );
325  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
326 
327  local[0] = -dX; local[1] = dY; local[2] = -dZ;
328  m_geom->localToGlobal( info, local, global );
329  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
330 
331  local[0] = dX; local[1] = -dY; local[2] = -dZ;
332  m_geom->localToGlobal( info, local, global );
333  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
334 
335  local[0] = -dX; local[1] = -dY; local[2] = -dZ;
336  m_geom->localToGlobal( info, local, global );
337  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
338 }
339 
340 void
342  float& min_rho, float& max_rho, float& min_z, float& max_z )
343 {
344  float local[3], global[3];
345 
346  float dX = info.shape[2] - info.shape[1];
347  float dY = info.shape[4];
348  float ddY = sqrt( 4 * dY * dY + dX * dX ) * 0.5;
349  float dZ = info.shape[3];
350 
351  local[0] = info.shape[2]; local[1] = ddY; local[2] = -dZ;
352  m_geom->localToGlobal( info, local, global );
353  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
354 
355  local[0] = info.shape[1]; local[1] = -ddY; local[2] = -dZ;
356  m_geom->localToGlobal( info, local, global );
357  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
358 
359  local[0] = info.shape[1]; local[1] = -ddY; local[2] = dZ;
360  m_geom->localToGlobal( info, local, global );
361  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
362 
363  local[0] = info.shape[2]; local[1] = ddY; local[2] = dZ;
364  m_geom->localToGlobal( info, local, global );
365  estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
366 }
367 
368 void
370  float& min_rho, float& max_rho, float& min_z, float& max_z )
371 {
372  double rho = sqrt(global[0] *global[0]+global[1] *global[1]);
373  if ( min_rho > rho ) min_rho = rho;
374  if ( max_rho < rho ) max_rho = rho;
375  if ( min_z > global[2] ) min_z = global[2];
376  if ( max_z < global[2] ) max_z = global[2];
377 }
378 
379 
380 // ATODO:: check white vertex -> shouldn't be relative to background
381 // when detruction ?
382 
383 
384 // ATODO why color is not set in 3D original, why cast to polygonsetprojected after projected ????
385 // is geom color dynamic --- independent of projection manager
386 
387 // NOTE geomtry MuonRhoZAdanced renamed to MuonRhoZ
388 
389 
390 //==============================================================================
391 //==============================================================================
392 
393 
394 
395 void
397 {
398  if( !m_pixelBarrelElements && show )
399  {
400  m_pixelBarrelElements = new TEveElementList("PixelBarrel");
401  AddElement(m_pixelBarrelElements);
402  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelBarrel );
403  for( std::vector<unsigned int>::const_iterator id = ids.begin();
404  id != ids.end(); ++id )
405  {
406  TEveGeoShape* shape = m_geom->getEveShape( *id );
407  shape->SetTitle(Form("PixelBarrel %d",*id));
409  m_pixelBarrelElements->AddElement( shape );
410  }
412  }
413 
415  {
416  m_pixelBarrelElements->SetRnrState(show);
417  gEve->Redraw3D();
418  }
419 }
420 
421 void
423 {
424  if( !m_pixelEndcapElements && show )
425  {
426  m_pixelEndcapElements = new TEveElementList("PixelEndcap");
427 
428  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelEndcap );
429  for( std::vector<unsigned int>::const_iterator id = ids.begin();
430  id != ids.end(); ++id )
431  {
432  TEveGeoShape* shape = m_geom->getEveShape( *id );
433 
434  shape->SetTitle(Form("PixelEndCap %d",*id));
436  m_pixelEndcapElements->AddElement( shape );
437  }
438 
439  AddElement(m_pixelEndcapElements);
441  }
442 
444  {
445  m_pixelEndcapElements->SetRnrState(show);
446  gEve->Redraw3D();
447  }
448 }
449 
450 
451 void
453 {
454  if( !m_trackerBarrelElements && show )
455  {
456  m_trackerBarrelElements = new TEveElementList("TrackerBarrel");
457 
458  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TIB );
459  for( std::vector<unsigned int>::const_iterator id = ids.begin();
460  id != ids.end(); ++id )
461  {
462  TEveGeoShape* shape = m_geom->getEveShape( *id );
464  m_trackerBarrelElements->AddElement( shape );
465  }
467  for( std::vector<unsigned int>::const_iterator id = ids.begin();
468  id != ids.end(); ++id )
469  {
470  TEveGeoShape* shape = m_geom->getEveShape( *id );
471 
472  shape->SetTitle(Form("TrackerBarrel %d",*id));
474  m_trackerBarrelElements->AddElement( shape );
475  }
476 
477  AddElement(m_trackerBarrelElements);
479  }
480 
482  {
483  m_trackerBarrelElements->SetRnrState(show);
484  gEve->Redraw3D();
485  }
486 }
487 
488 void
490 {
491  if( !m_trackerEndcapElements && show )
492  {
493  m_trackerEndcapElements = new TEveElementList("TrackerEndcap");
494 
495  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TID );
496  for( std::vector<unsigned int>::const_iterator id = ids.begin();
497  id != ids.end(); ++id )
498  {
499  TEveGeoShape* shape = m_geom->getEveShape( *id );
501  m_trackerEndcapElements->AddElement( shape );
502  }
504  for( std::vector<unsigned int>::const_iterator id = ids.begin();
505  id != ids.end(); ++id )
506  {
507  TEveGeoShape* shape = m_geom->getEveShape( *id );
508 
509  shape->SetTitle(Form("TrackerEndcap %d",*id));
511  m_trackerEndcapElements->AddElement( shape );
512  }
513 
514  AddElement(m_trackerEndcapElements);
516  }
517 
519  {
520  m_trackerEndcapElements->SetRnrState(show);
521  gEve->Redraw3D();
522  }
523 }
524 
525 
526 void FWRPZViewGeometry::importNew(TEveElementList* x)
527 {
528  TEveProjected* proj = *BeginProjecteds();
529  proj->GetManager()->SubImportElements(x, proj->GetProjectedAsElement());
530 
531 }
const double TwoPi
type
Definition: HCALResponse.h:21
TEveElementList * m_pixelBarrelElements
int i
Definition: DBlmapReader.cc:9
FWRPZViewGeometry(const fireworks::Context &context)
TEveCompound * m_colorComp[kFWGeomColorSize]
void estimateProjectionSizeDT(const FWGeometry::GeomDetInfo &info, float &, float &, float &, float &)
IdToInfoItr find(unsigned int) const
Definition: FWGeometry.cc:354
TEveElementList * m_rhoPhiGeo
TEveElement * makeCaloOutlineRhoPhi()
void estimateProjectionSizeCSC(const FWGeometry::GeomDetInfo &info, float &, float &, float &, float &)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
FWColorManager * colorManager() const
Definition: Context.h:66
Definition: DDAxes.h:10
static float caloZ2(bool offset=true)
Definition: Context.cc:225
void localToGlobal(unsigned int id, const float *local, float *global) const
Definition: FWGeometry.cc:325
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
void addToCompound(TEveElement *el, FWGeomColorIndex idx, bool applyTransp=true) const
TEveGeoShape * makeShape(double, double, double, double)
void initStdGeoElements(const FWViewType::EType id)
static float caloR2(bool offset=true)
Definition: Context.cc:215
TEveElement * makeMuonGeometryRhoPhi()
void importNew(TEveElementList *x)
TEveElementList * m_trackerBarrelElements
void estimateProjectionSize(const float *, float &, float &, float &, float &)
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:250
TEveElementList * m_pixelEndcapElements
T sqrt(T t)
Definition: SSEVec.h:48
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
static float caloR1(bool offset=true)
Definition: Context.cc:210
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
const FWGeometry * m_geom
TEveElementList * m_rhoZGeo
TEveElement * makeCaloOutlineRhoZ()
void showTrackerBarrel(bool)
TEveElementList * m_trackerEndcapElements
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:194
TEveElement * makeMuonGeometryRhoZ()
static double caloMaxEta()
Definition: Context.cc:240
static float caloZ1(bool offset=true)
Definition: Context.cc:220
void showTrackerEndcap(bool)
Definition: DDAxes.h:10
Color_t geomColor(FWGeomColorIndex) const
const fireworks::Context & m_context
virtual ~FWRPZViewGeometry()
std::vector< FWGeometry::GeomDetInfo >::const_iterator IdToInfoItr
Definition: FWGeometry.h:96