CMS 3D CMS Logo

FW3DViewGeometry.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FW3DViewGeometry
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Thu Mar 25 22:06:57 CET 2010
11 //
12 
13 // system include files
14 #include <sstream>
15 
16 // user include files
17 
18 #include "TEveManager.h"
19 #include "TEveGeoNode.h"
20 #include "TEveCompound.h"
21 
27 
32 
33 //
34 // constants, enums and typedefs
35 //
36 
37 //
38 // static data member definitions
39 //
40 
41 //
42 // constructors and destructor
43 //
45  FWViewGeometryList(context, false),
46  m_muonBarrelElements(nullptr), m_muonBarrelFullElements(nullptr),
47  m_muonEndcapElements(nullptr), m_muonEndcapFullElements(nullptr),
48  m_pixelBarrelElements(nullptr),
49  m_pixelEndcapElements(nullptr),
50  m_trackerBarrelElements(nullptr),
51  m_trackerEndcapElements(nullptr),
52  m_HGCalEEElements(nullptr), m_HGCalHSiElements(nullptr), m_HGCalHScElements(nullptr)
53 {
54 
55  SetElementName("3D Geometry");
56 }
57 
58 // FW3DViewGeometry::FW3DViewGeometry(const FW3DViewGeometry& rhs)
59 // {
60 // // do actual copying here;
61 // }
62 
64 {
65 }
66 
67 
68 //
69 // member functions
70 //
71 
72 //
73 // const member functions
74 //
75 
76 //
77 // static member functions
78 //
79 
80 void
82 {
83  if( !m_muonBarrelElements && showMuonBarrel )
84  {
85  m_muonBarrelElements = new TEveElementList( "DT" );
86  for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
87  {
88  for ( Int_t iStation = 1; iStation <= 4; ++iStation )
89  {
90  // We display only the outer chambers to make the event look more
91  // prominent
92  if( iWheel == -2 || iWheel == 2 || iStation == 4 )
93  {
94  std::ostringstream s;
95  s << "Station" << iStation;
96  TEveElementList* cStation = new TEveElementList( s.str().c_str() );
97  m_muonBarrelElements->AddElement( cStation );
98  for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
99  {
100  if( iStation < 4 && iSector > 12 ) continue;
101  DTChamberId id( iWheel, iStation, iSector );
102  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
104  cStation->AddElement( shape );
105  }
106  }
107  }
108  }
109  AddElement( m_muonBarrelElements );
110  }
111 
113  {
114  m_muonBarrelElements->SetRnrState( showMuonBarrel );
115  gEve->Redraw3D();
116  }
117 }
118 
119 void
121 {
122  if (!m_muonBarrelFullElements && showMuonBarrel)
123  {
124  m_muonBarrelFullElements = new TEveElementList( "DT Full" );
125  for (Int_t iWheel = -2; iWheel <= 2; ++iWheel)
126  {
127  TEveElementList* cWheel = new TEveElementList(TString::Format("Wheel %d", iWheel));
128  m_muonBarrelFullElements->AddElement(cWheel);
129  for (Int_t iStation = 1; iStation <= 4; ++iStation)
130  {
131  TEveElementList* cStation = new TEveElementList(TString::Format("Station %d", iStation));
132  cWheel->AddElement(cStation);
133  for (Int_t iSector = 1 ; iSector <= 14; ++iSector)
134  {
135  if( iStation < 4 && iSector > 12 ) continue;
136  DTChamberId id( iWheel, iStation, iSector );
137  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
138  shape->SetTitle(TString::Format("DT: W=%d, S=%d, Sec=%d\ndet-id=%u",
139  iWheel, iStation, iSector, id.rawId()));
141  cStation->AddElement(shape);
142  }
143  }
144  }
145  AddElement(m_muonBarrelFullElements);
146  }
147 
149  {
150  m_muonBarrelFullElements->SetRnrState(showMuonBarrel);
151  gEve->Redraw3D();
152  }
153 }
154 
155 //______________________________________________________________________________
156 void
158 {
159  if( showMuonEndcap && !m_muonEndcapElements )
160  {
161  m_muonEndcapElements = new TEveElementList( "EndCap" );
162 
163  for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
164  {
165  TEveElementList* cEndcap = nullptr;
166  if( iEndcap == 1 )
167  cEndcap = new TEveElementList( "CSC Forward" );
168  else
169  cEndcap = new TEveElementList( "CSC Backward" );
170  m_muonEndcapElements->AddElement( cEndcap );
171  // Actual CSC geometry:
172  // Station 1 has 4 rings with 36 chambers in each
173  // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
174  // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
175  // Station 4: ring 1 has 18 chambers
176  Int_t maxChambers = 36;
177  for( Int_t iStation = 1; iStation <= 4; ++iStation )
178  {
179  std::ostringstream s; s << "Station" << iStation;
180  TEveElementList* cStation = new TEveElementList( s.str().c_str() );
181  cEndcap->AddElement( cStation );
182  for( Int_t iRing = 1; iRing <= 4; ++iRing )
183  {
184  if( iStation > 1 && iRing > 2 ) continue;
185  // if( iStation > 3 && iRing > 1 ) continue;
186  std::ostringstream s; s << "Ring" << iRing;
187  TEveElementList* cRing = new TEveElementList( s.str().c_str() );
188  cStation->AddElement( cRing );
189  ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
190  for( Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber )
191  {
192  Int_t iLayer = 0; // chamber
193  CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
194  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
195  shape->SetTitle(TString::Format("CSC: %s, S=%d, R=%d, C=%d\ndet-id=%u",
196  cEndcap->GetName(), iStation, iRing, iChamber, id.rawId()));
197 
199  cRing->AddElement( shape );
200  }
201  }
202  }
203  }
204  // hardcoded gem and me0; need to find better way for different gem geometries
205  for( Int_t iRegion = GEMDetId::minRegionId; iRegion <= GEMDetId::maxRegionId; iRegion= iRegion+2){
206  TEveElementList* teEndcap = nullptr;
207  if( iRegion == 1 )
208  teEndcap = new TEveElementList( "GEM Forward" );
209  else
210  teEndcap = new TEveElementList( "GEM Backward" );
211  m_muonEndcapElements->AddElement( teEndcap );
212 
213  int mxSt = m_geom->versionInfo().haveExtraDet("GE2") ? GEMDetId::maxStationId :1;
214 
215  for( Int_t iStation = GEMDetId::minStationId; iStation <= mxSt; ++iStation ){
216  std::ostringstream s; s << "Station" << iStation;
217  TEveElementList* cStation = new TEveElementList( s.str().c_str() );
218  teEndcap->AddElement( cStation );
219 
220  Int_t iRing = 1;
221  for( Int_t iLayer = GEMDetId::minLayerId; iLayer <= GEMDetId::maxLayerId ; ++iLayer ){
222  int maxChamber = 36;
223  if (iStation >= 2) maxChamber = 18;
224 
225  for( Int_t iChamber = 1; iChamber <= maxChamber; ++iChamber ){
226  int maxRoll = iChamber%2 ? 9:10;
227  if (iStation == 2) maxRoll = 8;
228  if (iStation == 3) maxRoll = 12;
229 
230  for (Int_t iRoll = GEMDetId::minRollId; iRoll <= maxRoll ; ++iRoll ){
231  GEMDetId id( iRegion, iRing, iStation, iLayer, iChamber, iRoll );
232  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
233  if (shape){
234  shape->SetTitle(TString::Format("GEM: , Rng=%d, St=%d, Ch=%d Rl=%d\ndet-id=%u",
235  iRing, iStation, iChamber, iRoll, id.rawId()));
236 
237  cStation->AddElement( shape );
239  }
240  }
241  }
242  }
243  }
244  }
245 
246  // adding me0
247  if (m_geom->versionInfo().haveExtraDet("ME0") ){
248  for( Int_t iRegion = ME0DetId::minRegionId; iRegion <= ME0DetId::maxRegionId; iRegion= iRegion+2 ){
249  TEveElementList* teEndcap = nullptr;
250  if( iRegion == 1 )
251  teEndcap = new TEveElementList( "ME0 Forward" );
252  else
253  teEndcap = new TEveElementList( "ME0 Backward" );
254  m_muonEndcapElements->AddElement( teEndcap );
255 
256  for( Int_t iLayer = 1; iLayer <= 6 ; ++iLayer ){
257  std::ostringstream s; s << "Layer" << iLayer;
258  TEveElementList* cLayer = new TEveElementList( s.str().c_str() );
259  teEndcap->AddElement( cLayer );
260 
261  for( Int_t iChamber = 1; iChamber <= 18; ++iChamber ){
262  Int_t iRoll = 1;
263  // for (Int_t iRoll = ME0DetId::minRollId; iRoll <= ME0DetId::maxRollId ; ++iRoll ){
264  ME0DetId id( iRegion, iLayer, iChamber, iRoll );
265  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
266  if (shape){
267  shape->SetTitle(TString::Format("ME0: , Ch=%d Rl=%d\ndet-id=%u",
268  iChamber, iRoll, id.rawId()));
269 
271  cLayer->AddElement( shape );
272  }
273  }
274  }
275  }
276  }
277 
278  AddElement( m_muonEndcapElements );
279  }
280 
282  {
283  m_muonEndcapElements->SetRnrState( showMuonEndcap );
284  gEve->Redraw3D();
285  }
286 }
287 
288 //______________________________________________________________________________
289 void
291 {
292  if( showPixelBarrel && !m_pixelBarrelElements )
293  {
294  m_pixelBarrelElements = new TEveElementList( "PixelBarrel" );
295  m_pixelBarrelElements->SetRnrState( showPixelBarrel );
296  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelBarrel );
297  for( std::vector<unsigned int>::const_iterator id = ids.begin();
298  id != ids.end(); ++id )
299  {
300  TEveGeoShape* shape = m_geom->getEveShape( *id );
301 
302  uint32_t rawId = *id;
303  DetId did = DetId(rawId);
305  shape->SetTitle( title.c_str());
306 
308  m_pixelBarrelElements->AddElement( shape );
309  }
310  AddElement( m_pixelBarrelElements );
311  }
312 
314  {
315  m_pixelBarrelElements->SetRnrState( showPixelBarrel );
316  gEve->Redraw3D();
317  }
318 }
319 
320 //______________________________________________________________________________
321 void
323 {
324  if( showPixelEndcap && ! m_pixelEndcapElements )
325  {
326  m_pixelEndcapElements = new TEveElementList( "PixelEndcap" );
327  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelEndcap );
328  for( std::vector<unsigned int>::const_iterator id = ids.begin();
329  id != ids.end(); ++id )
330  {
331  TEveGeoShape* shape = m_geom->getEveShape( *id );
332  uint32_t rawId = *id;
333  DetId did = DetId(rawId);
335  shape->SetTitle( title.c_str());
337  m_pixelEndcapElements->AddElement( shape );
338  }
339  AddElement( m_pixelEndcapElements );
340  }
341 
343  {
344  m_pixelEndcapElements->SetRnrState( showPixelEndcap );
345  gEve->Redraw3D();
346  }
347 }
348 
349 //______________________________________________________________________________
350 void
352 {
353  if( showTrackerBarrel && ! m_trackerBarrelElements )
354  {
355  m_trackerBarrelElements = new TEveElementList( "TrackerBarrel" );
356  m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
357  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TIB );
358  for( std::vector<unsigned int>::const_iterator id = ids.begin();
359  id != ids.end(); ++id )
360  {
361  TEveGeoShape* shape = m_geom->getEveShape( *id );
363  m_trackerBarrelElements->AddElement( shape );
364  }
366  for( std::vector<unsigned int>::const_iterator id = ids.begin();
367  id != ids.end(); ++id )
368  {
369  TEveGeoShape* shape = m_geom->getEveShape( *id );
370  shape->SetTitle(Form("TrackerBarrel %d",*id));
372  m_trackerBarrelElements->AddElement( shape );
373  }
374  AddElement( m_trackerBarrelElements );
375  }
376 
378  {
379  m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
380  gEve->Redraw3D();
381  }
382 }
383 
384 //______________________________________________________________________________
385 void
387 {
388  if( showTrackerEndcap && ! m_trackerEndcapElements )
389  {
390  m_trackerEndcapElements = new TEveElementList( "TrackerEndcap" );
391  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TID );
392  for( std::vector<unsigned int>::const_iterator id = ids.begin();
393  id != ids.end(); ++id )
394  {
395  TEveGeoShape* shape = m_geom->getEveShape( *id );
397  m_trackerEndcapElements->AddElement( shape );
398  }
400  for( std::vector<unsigned int>::const_iterator id = ids.begin();
401  id != ids.end(); ++id )
402  {
403  TEveGeoShape* shape = m_geom->getEveShape( *id );
404 
405  shape->SetTitle(Form("TrackerEndcap %d",*id));
407  m_trackerEndcapElements->AddElement( shape );
408  }
409  AddElement( m_trackerEndcapElements );
410  }
411 
413  {
414  m_trackerEndcapElements->SetRnrState( showTrackerEndcap );
415  gEve->Redraw3D();
416  }
417 }
418 
419 //______________________________________________________________________________
420 void
422  if( showHGCalEE && !m_HGCalEEElements ){
423  m_HGCalEEElements = new TEveElementList("HGCalEE");
424  for( const auto& id : m_geom->getMatchedIds( FWGeometry::HGCalEE ))
425  {
426  TEveGeoShape* shape = m_geom->getHGCSiliconEveShape( id );
427  const unsigned int layer = (id>>20)&0x1F;
428  shape->SetTitle(Form("HGCalEE %d", layer));
429  {
430  float color[3];
431  color[0] = color[1] = color[2] = 0.3f + 0.7f*(1.0f-layer/28.0f);
432  color[1] = 0.5f*(layer&2U) + 0.5f*color[1];
433  const bool isFine = ((id>>26)&0x3) == 0;
434  color[0] *= isFine ? 1.0f : 1.0f;
435  color[1] *= isFine ? 1.0f : 0.4f;
436  color[2] *= isFine ? 0.0f : 0.0f;
437  shape->SetMainColorRGB( color[0], color[1], color[2] );
438  shape->SetPickable(false);
439  m_colorComp[kFwHGCalEEColorIndex]->AddElement(shape);
440  }
441  m_HGCalEEElements->AddElement( shape );
442  }
443  AddElement( m_HGCalEEElements );
444  }
445  if (m_HGCalEEElements ){
446  m_HGCalEEElements->SetRnrState( showHGCalEE );
447  gEve->Redraw3D();
448  }
449 }
450 
451 void
453  if( showHGCalHSi && !m_HGCalHSiElements ){
454  m_HGCalHSiElements = new TEveElementList("HGCalHSi");
455  for( const auto& id : m_geom->getMatchedIds( FWGeometry::HGCalHSi ))
456  {
457  TEveGeoShape* shape = m_geom->getHGCSiliconEveShape( id );
458  const unsigned int layer = (id>>20)&0x1F;
459  shape->SetTitle(Form("HGCalHSi %d",layer));
460  {
461  float color[3];
462  color[0] = color[1] = color[2] = 0.3f + 0.7f*(1.0f-layer/28.0f);
463  color[0] = 0.5f*(layer&2U) + 0.5f*color[0];
464  const bool isFine = ((id>>26)&0x3) == 0;
465  color[0] *= isFine ? 1.0f : 0.4f;
466  color[1] *= isFine ? 0.7f : 0.7f;
467  color[2] *= isFine ? 0.2f : 0.2f;
468  shape->SetMainColorRGB( color[0], color[1], color[2] );
469  shape->SetPickable(false);
470  m_colorComp[kFwHGCalHSiColorIndex]->AddElement(shape);
471  }
472  m_HGCalHSiElements->AddElement( shape );
473  }
474  AddElement( m_HGCalHSiElements );
475  }
476  if (m_HGCalHSiElements ){
477  m_HGCalHSiElements->SetRnrState( showHGCalHSi );
478  gEve->Redraw3D();
479  }
480 }
481 
483  if( showHGCalHSc && !m_HGCalHScElements )
484  {
485  m_HGCalHScElements = new TEveElementList( "HGCalHSc" );
486  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::HGCalHSc );
487  for( const auto& id : m_geom->getMatchedIds( FWGeometry::HGCalHSc ))
488  {
489  TEveGeoShape* shape = m_geom->getHGCScintillatorEveShape( id );
490  const unsigned int layer = (id>>17)&0x1F;
491  shape->SetTitle(Form("HGCalHSc %d", layer));
493  m_HGCalHScElements->AddElement( shape );
494  }
495  AddElement( m_HGCalHScElements );
496  }
497  if( m_HGCalHScElements )
498  {
499  m_HGCalHScElements->SetRnrState( showHGCalHSc );
500  gEve->Redraw3D();
501  }
502 }
~FW3DViewGeometry() override
TEveGeoShape * getHGCSiliconEveShape(unsigned int id) const
Definition: FWGeometry.cc:325
TEveCompound * m_colorComp[kFWGeomColorSize]
void showMuonBarrel(bool)
TEveElementList * m_pixelBarrelElements
TEveElementList * m_HGCalEEElements
#define nullptr
void showTrackerEndcap(bool)
static const int minRegionId
Definition: GEMDetId.h:94
std::string print(DetId detid) const
static const int maxRegionId
Definition: ME0DetId.h:87
void showMuonBarrelFull(bool)
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:127
TEveElementList * m_HGCalHSiElements
void showTrackerBarrel(bool)
static const int maxLayerId
Definition: GEMDetId.h:108
TEveElementList * m_HGCalHScElements
void addToCompound(TEveElement *el, FWGeomColorIndex idx, bool applyTransp=true) const
static const int minRegionId
Definition: ME0DetId.h:86
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:529
void showMuonEndcap(bool)
TEveElementList * m_pixelEndcapElements
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:298
TEveElementList * m_muonEndcapElements
TEveElementList * m_muonBarrelElements
static const int minRollId
Definition: GEMDetId.h:110
double f[11][100]
const FWGeometry * m_geom
static const int maxStationId
Definition: GEMDetId.h:101
TEveElementList * m_trackerEndcapElements
TEveElementList * m_trackerBarrelElements
const fireworks::Context & context()
Definition: FWEveView.h:67
Definition: DetId.h:18
static const int minStationId
Definition: GEMDetId.h:100
void showPixelBarrel(bool)
TEveElementList * m_muonBarrelFullElements
FW3DViewGeometry(const fireworks::Context &context)
void showPixelEndcap(bool)
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:214
static const int minLayerId
Definition: GEMDetId.h:107
const TrackerTopology * getTrackerTopology() const
Definition: FWGeometry.h:133
static const int maxRegionId
Definition: GEMDetId.h:95
TEveGeoShape * getHGCScintillatorEveShape(unsigned int id) const
Definition: FWGeometry.cc:391