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 {
53 
54  SetElementName("3D Geometry");
55 }
56 
57 // FW3DViewGeometry::FW3DViewGeometry(const FW3DViewGeometry& rhs)
58 // {
59 // // do actual copying here;
60 // }
61 
63 {
64 }
65 
66 
67 //
68 // member functions
69 //
70 
71 //
72 // const member functions
73 //
74 
75 //
76 // static member functions
77 //
78 
79 void
81 {
82  if( !m_muonBarrelElements && showMuonBarrel )
83  {
84  m_muonBarrelElements = new TEveElementList( "DT" );
85  for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
86  {
87  for ( Int_t iStation = 1; iStation <= 4; ++iStation )
88  {
89  // We display only the outer chambers to make the event look more
90  // prominent
91  if( iWheel == -2 || iWheel == 2 || iStation == 4 )
92  {
93  std::ostringstream s;
94  s << "Station" << iStation;
95  TEveElementList* cStation = new TEveElementList( s.str().c_str() );
96  m_muonBarrelElements->AddElement( cStation );
97  for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
98  {
99  if( iStation < 4 && iSector > 12 ) continue;
100  DTChamberId id( iWheel, iStation, iSector );
101  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
103  cStation->AddElement( shape );
104  }
105  }
106  }
107  }
108  AddElement( m_muonBarrelElements );
109  }
110 
112  {
113  m_muonBarrelElements->SetRnrState( showMuonBarrel );
114  gEve->Redraw3D();
115  }
116 }
117 
118 void
120 {
121  if (!m_muonBarrelFullElements && showMuonBarrel)
122  {
123  m_muonBarrelFullElements = new TEveElementList( "DT Full" );
124  for (Int_t iWheel = -2; iWheel <= 2; ++iWheel)
125  {
126  TEveElementList* cWheel = new TEveElementList(TString::Format("Wheel %d", iWheel));
127  m_muonBarrelFullElements->AddElement(cWheel);
128  for (Int_t iStation = 1; iStation <= 4; ++iStation)
129  {
130  TEveElementList* cStation = new TEveElementList(TString::Format("Station %d", iStation));
131  cWheel->AddElement(cStation);
132  for (Int_t iSector = 1 ; iSector <= 14; ++iSector)
133  {
134  if( iStation < 4 && iSector > 12 ) continue;
135  DTChamberId id( iWheel, iStation, iSector );
136  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
137  shape->SetTitle(TString::Format("DT: W=%d, S=%d, Sec=%d\ndet-id=%u",
138  iWheel, iStation, iSector, id.rawId()));
140  cStation->AddElement(shape);
141  }
142  }
143  }
144  AddElement(m_muonBarrelFullElements);
145  }
146 
148  {
149  m_muonBarrelFullElements->SetRnrState(showMuonBarrel);
150  gEve->Redraw3D();
151  }
152 }
153 
154 //______________________________________________________________________________
155 void
157 {
158  if( showMuonEndcap && !m_muonEndcapElements )
159  {
160  m_muonEndcapElements = new TEveElementList( "EndCap" );
161 
162  for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
163  {
164  TEveElementList* cEndcap = nullptr;
165  if( iEndcap == 1 )
166  cEndcap = new TEveElementList( "CSC Forward" );
167  else
168  cEndcap = new TEveElementList( "CSC Backward" );
169  m_muonEndcapElements->AddElement( cEndcap );
170  // Actual CSC geometry:
171  // Station 1 has 4 rings with 36 chambers in each
172  // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
173  // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
174  // Station 4: ring 1 has 18 chambers
175  Int_t maxChambers = 36;
176  for( Int_t iStation = 1; iStation <= 4; ++iStation )
177  {
178  std::ostringstream s; s << "Station" << iStation;
179  TEveElementList* cStation = new TEveElementList( s.str().c_str() );
180  cEndcap->AddElement( cStation );
181  for( Int_t iRing = 1; iRing <= 4; ++iRing )
182  {
183  if( iStation > 1 && iRing > 2 ) continue;
184  // if( iStation > 3 && iRing > 1 ) continue;
185  std::ostringstream s; s << "Ring" << iRing;
186  TEveElementList* cRing = new TEveElementList( s.str().c_str() );
187  cStation->AddElement( cRing );
188  ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
189  for( Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber )
190  {
191  Int_t iLayer = 0; // chamber
192  CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
193  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
194  shape->SetTitle(TString::Format("CSC: %s, S=%d, R=%d, C=%d\ndet-id=%u",
195  cEndcap->GetName(), iStation, iRing, iChamber, id.rawId()));
196 
198  cRing->AddElement( shape );
199  }
200  }
201  }
202  }
203  // hardcoded gem and me0; need to find better way for different gem geometries
204  for( Int_t iRegion = GEMDetId::minRegionId; iRegion <= GEMDetId::maxRegionId; iRegion= iRegion+2){
205  TEveElementList* teEndcap = nullptr;
206  if( iRegion == 1 )
207  teEndcap = new TEveElementList( "GEM Forward" );
208  else
209  teEndcap = new TEveElementList( "GEM Backward" );
210  m_muonEndcapElements->AddElement( teEndcap );
211 
212  int mxSt = m_geom->versionInfo().haveExtraDet("GE2") ? GEMDetId::maxStationId :1;
213 
214  for( Int_t iStation = GEMDetId::minStationId; iStation <= mxSt; ++iStation ){
215  std::ostringstream s; s << "Station" << iStation;
216  TEveElementList* cStation = new TEveElementList( s.str().c_str() );
217  teEndcap->AddElement( cStation );
218 
219  Int_t iRing = 1;
220  for( Int_t iLayer = GEMDetId::minLayerId; iLayer <= GEMDetId::maxLayerId ; ++iLayer ){
221  int maxChamber = 36;
222  if (iStation >= 2) maxChamber = 18;
223 
224  for( Int_t iChamber = 1; iChamber <= maxChamber; ++iChamber ){
225  int maxRoll = iChamber%2 ? 9:10;
226  if (iStation == 2) maxRoll = 8;
227  if (iStation == 3) maxRoll = 12;
228 
229  for (Int_t iRoll = GEMDetId::minRollId; iRoll <= maxRoll ; ++iRoll ){
230  GEMDetId id( iRegion, iRing, iStation, iLayer, iChamber, iRoll );
231  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
232  if (shape){
233  shape->SetTitle(TString::Format("GEM: , Rng=%d, St=%d, Ch=%d Rl=%d\ndet-id=%u",
234  iRing, iStation, iChamber, iRoll, id.rawId()));
235 
236  cStation->AddElement( shape );
238  }
239  }
240  }
241  }
242  }
243  }
244 
245  // adding me0
246  if (m_geom->versionInfo().haveExtraDet("ME0") ){
247  for( Int_t iRegion = ME0DetId::minRegionId; iRegion <= ME0DetId::maxRegionId; iRegion= iRegion+2 ){
248  TEveElementList* teEndcap = nullptr;
249  if( iRegion == 1 )
250  teEndcap = new TEveElementList( "ME0 Forward" );
251  else
252  teEndcap = new TEveElementList( "ME0 Backward" );
253  m_muonEndcapElements->AddElement( teEndcap );
254 
255  for( Int_t iLayer = 1; iLayer <= 6 ; ++iLayer ){
256  std::ostringstream s; s << "Layer" << iLayer;
257  TEveElementList* cLayer = new TEveElementList( s.str().c_str() );
258  teEndcap->AddElement( cLayer );
259 
260  for( Int_t iChamber = 1; iChamber <= 18; ++iChamber ){
261  Int_t iRoll = 1;
262  // for (Int_t iRoll = ME0DetId::minRollId; iRoll <= ME0DetId::maxRollId ; ++iRoll ){
263  ME0DetId id( iRegion, iLayer, iChamber, iRoll );
264  TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
265  if (shape){
266  shape->SetTitle(TString::Format("ME0: , Ch=%d Rl=%d\ndet-id=%u",
267  iChamber, iRoll, id.rawId()));
268 
270  cLayer->AddElement( shape );
271  }
272  }
273  }
274  }
275  }
276 
277  AddElement( m_muonEndcapElements );
278  }
279 
281  {
282  m_muonEndcapElements->SetRnrState( showMuonEndcap );
283  gEve->Redraw3D();
284  }
285 }
286 
287 //______________________________________________________________________________
288 void
290 {
291  if( showPixelBarrel && !m_pixelBarrelElements )
292  {
293  m_pixelBarrelElements = new TEveElementList( "PixelBarrel" );
294  m_pixelBarrelElements->SetRnrState( showPixelBarrel );
295  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelBarrel );
296  for( std::vector<unsigned int>::const_iterator id = ids.begin();
297  id != ids.end(); ++id )
298  {
299  TEveGeoShape* shape = m_geom->getEveShape( *id );
300 
301  uint32_t rawId = *id;
302  DetId did = DetId(rawId);
304  shape->SetTitle( title.c_str());
305 
307  m_pixelBarrelElements->AddElement( shape );
308  }
309  AddElement( m_pixelBarrelElements );
310  }
311 
313  {
314  m_pixelBarrelElements->SetRnrState( showPixelBarrel );
315  gEve->Redraw3D();
316  }
317 }
318 
319 //______________________________________________________________________________
320 void
322 {
323  if( showPixelEndcap && ! m_pixelEndcapElements )
324  {
325  m_pixelEndcapElements = new TEveElementList( "PixelEndcap" );
326  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelEndcap );
327  for( std::vector<unsigned int>::const_iterator id = ids.begin();
328  id != ids.end(); ++id )
329  {
330  TEveGeoShape* shape = m_geom->getEveShape( *id );
331  uint32_t rawId = *id;
332  DetId did = DetId(rawId);
334  shape->SetTitle( title.c_str());
336  m_pixelEndcapElements->AddElement( shape );
337  }
338  AddElement( m_pixelEndcapElements );
339  }
340 
342  {
343  m_pixelEndcapElements->SetRnrState( showPixelEndcap );
344  gEve->Redraw3D();
345  }
346 }
347 
348 //______________________________________________________________________________
349 void
351 {
352  if( showTrackerBarrel && ! m_trackerBarrelElements )
353  {
354  m_trackerBarrelElements = new TEveElementList( "TrackerBarrel" );
355  m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
356  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TIB );
357  for( std::vector<unsigned int>::const_iterator id = ids.begin();
358  id != ids.end(); ++id )
359  {
360  TEveGeoShape* shape = m_geom->getEveShape( *id );
362  m_trackerBarrelElements->AddElement( shape );
363  }
365  for( std::vector<unsigned int>::const_iterator id = ids.begin();
366  id != ids.end(); ++id )
367  {
368  TEveGeoShape* shape = m_geom->getEveShape( *id );
369  shape->SetTitle(Form("TrackerBarrel %d",*id));
371  m_trackerBarrelElements->AddElement( shape );
372  }
373  AddElement( m_trackerBarrelElements );
374  }
375 
377  {
378  m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
379  gEve->Redraw3D();
380  }
381 }
382 
383 //______________________________________________________________________________
384 void
386 {
387  if( showTrackerEndcap && ! m_trackerEndcapElements )
388  {
389  m_trackerEndcapElements = new TEveElementList( "TrackerEndcap" );
390  std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TID );
391  for( std::vector<unsigned int>::const_iterator id = ids.begin();
392  id != ids.end(); ++id )
393  {
394  TEveGeoShape* shape = m_geom->getEveShape( *id );
396  m_trackerEndcapElements->AddElement( shape );
397  }
399  for( std::vector<unsigned int>::const_iterator id = ids.begin();
400  id != ids.end(); ++id )
401  {
402  TEveGeoShape* shape = m_geom->getEveShape( *id );
403 
404  shape->SetTitle(Form("TrackerEndcap %d",*id));
406  m_trackerEndcapElements->AddElement( shape );
407  }
408  AddElement( m_trackerEndcapElements );
409  }
410 
412  {
413  m_trackerEndcapElements->SetRnrState( showTrackerEndcap );
414  gEve->Redraw3D();
415  }
416 }
417 
418 
~FW3DViewGeometry() override
void showMuonBarrel(bool)
TEveElementList * m_pixelBarrelElements
void showTrackerEndcap(bool)
static const int minRegionId
Definition: GEMDetId.h:94
#define nullptr
std::string print(DetId detid) const
static const int maxRegionId
Definition: ME0DetId.h:87
void showMuonBarrelFull(bool)
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:123
void showTrackerBarrel(bool)
static const int maxLayerId
Definition: GEMDetId.h:108
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:396
void showMuonEndcap(bool)
TEveElementList * m_pixelEndcapElements
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:270
TEveElementList * m_muonEndcapElements
TEveElementList * m_muonBarrelElements
static const int minRollId
Definition: GEMDetId.h:110
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:129
static const int maxRegionId
Definition: GEMDetId.h:95