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