CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "TEveGeoShape.h"
21 #include "TEveCompound.h"
22 
29 
34 
35 //
36 // constants, enums and typedefs
37 //
38 
39 //
40 // static data member definitions
41 //
42 
43 //
44 // constructors and destructor
45 //
47  : FWViewGeometryList(context, false),
48  m_muonBarrelElements(nullptr),
49  m_muonBarrelFullElements(nullptr),
50  m_muonEndcapElements(nullptr),
51  m_muonEndcapFullElements(nullptr),
52  m_pixelBarrelElements(nullptr),
53  m_pixelEndcapElements(nullptr),
54  m_trackerBarrelElements(nullptr),
55  m_trackerEndcapElements(nullptr),
56  m_HGCalEEElements(nullptr),
57  m_HGCalHSiElements(nullptr),
58  m_HGCalHScElements(nullptr) {
59  SetElementName("3D Geometry");
60 }
61 
62 // FW3DViewGeometry::FW3DViewGeometry(const FW3DViewGeometry& rhs)
63 // {
64 // // do actual copying here;
65 // }
66 
68 
69 //
70 // member functions
71 //
72 
73 //
74 // const member functions
75 //
76 
77 //
78 // static member functions
79 //
80 
82  if (!m_muonBarrelElements && showMuonBarrel) {
83  m_muonBarrelElements = new TEveElementList("DT");
84  for (Int_t iWheel = -2; iWheel <= 2; ++iWheel) {
85  for (Int_t iStation = 1; iStation <= 4; ++iStation) {
86  // We display only the outer chambers to make the event look more
87  // prominent
88  if (iWheel == -2 || iWheel == 2 || iStation == 4) {
89  std::ostringstream s;
90  s << "Station" << iStation;
91  TEveElementList* cStation = new TEveElementList(s.str().c_str());
92  m_muonBarrelElements->AddElement(cStation);
93  for (Int_t iSector = 1; iSector <= 14; ++iSector) {
94  if (iStation < 4 && iSector > 12)
95  continue;
96  DTChamberId id(iWheel, iStation, iSector);
97  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
99  cStation->AddElement(shape);
100  }
101  }
102  }
103  }
104  AddElement(m_muonBarrelElements);
105  }
106 
107  if (m_muonBarrelElements) {
108  m_muonBarrelElements->SetRnrState(showMuonBarrel);
109  gEve->Redraw3D();
110  }
111 }
112 
114  if (!m_muonBarrelFullElements && showMuonBarrel) {
115  m_muonBarrelFullElements = new TEveElementList("DT Full");
116  for (Int_t iWheel = -2; iWheel <= 2; ++iWheel) {
117  TEveElementList* cWheel = new TEveElementList(TString::Format("Wheel %d", iWheel));
118  m_muonBarrelFullElements->AddElement(cWheel);
119  for (Int_t iStation = 1; iStation <= 4; ++iStation) {
120  TEveElementList* cStation = new TEveElementList(TString::Format("Station %d", iStation));
121  cWheel->AddElement(cStation);
122  for (Int_t iSector = 1; iSector <= 14; ++iSector) {
123  if (iStation < 4 && iSector > 12)
124  continue;
125  DTChamberId id(iWheel, iStation, iSector);
126  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
127  shape->SetTitle(TString::Format("DT: W=%d, S=%d, Sec=%d\ndet-id=%u", iWheel, iStation, iSector, id.rawId()));
129  cStation->AddElement(shape);
130  }
131  }
132  }
133  AddElement(m_muonBarrelFullElements);
134  }
135 
137  m_muonBarrelFullElements->SetRnrState(showMuonBarrel);
138  gEve->Redraw3D();
139  }
140 }
141 
142 //______________________________________________________________________________
143 void FW3DViewGeometry::showMuonEndcap(bool showMuonEndcap) {
144  if (showMuonEndcap && !m_muonEndcapElements) {
145  m_muonEndcapElements = new TEveElementList("EndCap");
146 
147  for (Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap) // 1=forward (+Z), 2=backward(-Z)
148  {
149  TEveElementList* cEndcap = nullptr;
150  if (iEndcap == 1)
151  cEndcap = new TEveElementList("CSC Forward");
152  else
153  cEndcap = new TEveElementList("CSC Backward");
154  m_muonEndcapElements->AddElement(cEndcap);
155  // Actual CSC geometry:
156  // Station 1 has 4 rings with 36 chambers in each
157  // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
158  // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
159  // Station 4: ring 1 has 18 chambers
160  Int_t maxChambers = 36;
161  for (Int_t iStation = 1; iStation <= 4; ++iStation) {
162  std::ostringstream s;
163  s << "Station" << iStation;
164  TEveElementList* cStation = new TEveElementList(s.str().c_str());
165  cEndcap->AddElement(cStation);
166  for (Int_t iRing = 1; iRing <= 4; ++iRing) {
167  if (iStation > 1 && iRing > 2)
168  continue;
169  // if( iStation > 3 && iRing > 1 ) continue;
170  std::ostringstream s;
171  s << "Ring" << iRing;
172  TEveElementList* cRing = new TEveElementList(s.str().c_str());
173  cStation->AddElement(cRing);
174  (iRing == 1 && iStation > 1) ? (maxChambers = 18) : (maxChambers = 36);
175  for (Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber) {
176  Int_t iLayer = 0; // chamber
177  CSCDetId id(iEndcap, iStation, iRing, iChamber, iLayer);
178  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
179  shape->SetTitle(TString::Format(
180  "CSC: %s, S=%d, R=%d, C=%d\ndet-id=%u", cEndcap->GetName(), iStation, iRing, iChamber, id.rawId()));
181 
183  cRing->AddElement(shape);
184  }
185  }
186  }
187  }
188 
189  // hardcoded gem and me0; need to find better way for different gem geometries
190  for (Int_t iRegion = GEMDetId::minRegionId; iRegion <= GEMDetId::maxRegionId; iRegion += 2) {
191  TEveElementList* teEndcap = nullptr;
192  teEndcap = new TEveElementList(Form("GEM Reg=%d", iRegion));
193  m_muonEndcapElements->AddElement(teEndcap);
194  int iStation = 1;
195  {
196  std::ostringstream s;
197  s << "Station" << iStation;
198  TEveElementList* cStation = new TEveElementList(s.str().c_str());
199  teEndcap->AddElement(cStation);
200 
201  for (Int_t iLayer = GEMDetId::minLayerId; iLayer <= GEMDetId::maxLayerId; ++iLayer) {
202  int maxChamber = GEMDetId::maxChamberId;
203  std::ostringstream sl;
204  sl << "Layer" << iLayer;
205  TEveElementList* elayer = new TEveElementList(sl.str().c_str());
206  cStation->AddElement(elayer);
207 
208  for (Int_t iChamber = 1; iChamber <= maxChamber; ++iChamber) {
209  std::ostringstream cl;
210  cl << "Chamber" << iChamber;
211  TEveElementList* cha = new TEveElementList(cl.str().c_str());
212  elayer->AddElement(cha);
213 
214  Int_t iRing = 1;
215  Int_t iRoll = 0;
216  try {
217  GEMDetId id(iRegion, iRing, iStation, iLayer, iChamber, iRoll);
218  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
219  if (shape) {
220  shape->SetTitle(TString::Format(
221  "GEM: , Rng=%d, St=%d, Ch=%d Rl=%d\ndet-id=%u", iRing, iStation, iChamber, iRoll, id.rawId()));
222 
223  cha->AddElement(shape);
225  }
226  } catch (cms::Exception& e) {
227  fwLog(fwlog::kError) << "FW3DViewGeomtery " << e << std::endl;
228  }
229  }
230  }
231  }
232  }
233 
234  // adding me0
235  if (m_geom->versionInfo().haveExtraDet("ME0")) {
236  for (Int_t iRegion = ME0DetId::minRegionId; iRegion <= ME0DetId::maxRegionId; iRegion = iRegion + 2) {
237  TEveElementList* teEndcap = nullptr;
238  if (iRegion == 1)
239  teEndcap = new TEveElementList("ME0 Forward");
240  else
241  teEndcap = new TEveElementList("ME0 Backward");
242  m_muonEndcapElements->AddElement(teEndcap);
243 
244  for (Int_t iLayer = 1; iLayer <= 6; ++iLayer) {
245  std::ostringstream s;
246  s << "Layer" << iLayer;
247  TEveElementList* cLayer = new TEveElementList(s.str().c_str());
248  teEndcap->AddElement(cLayer);
249 
250  for (Int_t iChamber = 1; iChamber <= 18; ++iChamber) {
251  Int_t iRoll = 1;
252  // for (Int_t iRoll = ME0DetId::minRollId; iRoll <= ME0DetId::maxRollId ; ++iRoll ){
253  ME0DetId id(iRegion, iLayer, iChamber, iRoll);
254  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
255  if (shape) {
256  shape->SetTitle(TString::Format("ME0: , Ch=%d Rl=%d\ndet-id=%u", iChamber, iRoll, id.rawId()));
257 
259  cLayer->AddElement(shape);
260  }
261  }
262  }
263  }
264  }
265 
266  AddElement(m_muonEndcapElements);
267  }
268 
269  if (m_muonEndcapElements) {
270  m_muonEndcapElements->SetRnrState(showMuonEndcap);
271  gEve->Redraw3D();
272  }
273 }
274 
275 //______________________________________________________________________________
276 void FW3DViewGeometry::showPixelBarrel(bool showPixelBarrel) {
277  if (showPixelBarrel && !m_pixelBarrelElements) {
278  m_pixelBarrelElements = new TEveElementList("PixelBarrel");
279  m_pixelBarrelElements->SetRnrState(showPixelBarrel);
280  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::PixelBarrel);
281  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
282  TEveGeoShape* shape = m_geom->getEveShape(*id);
283 
284  uint32_t rawId = *id;
285  DetId did = DetId(rawId);
287  shape->SetTitle(title.c_str());
288 
290  m_pixelBarrelElements->AddElement(shape);
291  }
292  AddElement(m_pixelBarrelElements);
293  }
294 
295  if (m_pixelBarrelElements) {
296  m_pixelBarrelElements->SetRnrState(showPixelBarrel);
297  gEve->Redraw3D();
298  }
299 }
300 
301 //______________________________________________________________________________
302 void FW3DViewGeometry::showPixelEndcap(bool showPixelEndcap) {
303  if (showPixelEndcap && !m_pixelEndcapElements) {
304  m_pixelEndcapElements = new TEveElementList("PixelEndcap");
305  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::PixelEndcap);
306  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
307  TEveGeoShape* shape = m_geom->getEveShape(*id);
308  uint32_t rawId = *id;
309  DetId did = DetId(rawId);
311  shape->SetTitle(title.c_str());
313  m_pixelEndcapElements->AddElement(shape);
314  }
315  AddElement(m_pixelEndcapElements);
316  }
317 
318  if (m_pixelEndcapElements) {
319  m_pixelEndcapElements->SetRnrState(showPixelEndcap);
320  gEve->Redraw3D();
321  }
322 }
323 
324 //______________________________________________________________________________
325 void FW3DViewGeometry::showTrackerBarrel(bool showTrackerBarrel) {
326  if (showTrackerBarrel && !m_trackerBarrelElements) {
327  m_trackerBarrelElements = new TEveElementList("TrackerBarrel");
328  m_trackerBarrelElements->SetRnrState(showTrackerBarrel);
329  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TIB);
330  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
331  TEveGeoShape* shape = m_geom->getEveShape(*id);
333  m_trackerBarrelElements->AddElement(shape);
334  }
336  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
337  TEveGeoShape* shape = m_geom->getEveShape(*id);
338  shape->SetTitle(Form("TrackerBarrel %d", *id));
340  m_trackerBarrelElements->AddElement(shape);
341  }
342  AddElement(m_trackerBarrelElements);
343  }
344 
346  m_trackerBarrelElements->SetRnrState(showTrackerBarrel);
347  gEve->Redraw3D();
348  }
349 }
350 
351 //______________________________________________________________________________
352 void FW3DViewGeometry::showTrackerEndcap(bool showTrackerEndcap) {
353  if (showTrackerEndcap && !m_trackerEndcapElements) {
354  m_trackerEndcapElements = new TEveElementList("TrackerEndcap");
355  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TID);
356  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
357  TEveGeoShape* shape = m_geom->getEveShape(*id);
359  m_trackerEndcapElements->AddElement(shape);
360  }
362  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
363  TEveGeoShape* shape = m_geom->getEveShape(*id);
364 
365  shape->SetTitle(Form("TrackerEndcap %d", *id));
367  m_trackerEndcapElements->AddElement(shape);
368  }
369  AddElement(m_trackerEndcapElements);
370  }
371 
373  m_trackerEndcapElements->SetRnrState(showTrackerEndcap);
374  gEve->Redraw3D();
375  }
376 }
377 
378 //______________________________________________________________________________
379 void FW3DViewGeometry::showHGCalEE(bool showHGCalEE) {
380  if (showHGCalEE && !m_HGCalEEElements) {
381  m_HGCalEEElements = new TEveElementList("HGCalEE");
382  auto const ids = m_geom->getMatchedIds(FWGeometry::HGCalEE);
383  for (const auto& id : ids) {
384  TEveGeoShape* shape = m_geom->getHGCSiliconEveShape(id);
385  const unsigned int layer = m_geom->getParameters(id)[1];
386  const int siIndex = m_geom->getParameters(id)[4];
387  shape->SetTitle(Form("HGCalEE %d", layer));
388  {
389  float color[3] = {0., 0., 0.};
390  if (siIndex >= 0 && siIndex < 3)
391  color[siIndex] = 1.f;
392  shape->SetMainColorRGB(color[0], color[1], color[2]);
393  shape->SetPickable(false);
394  m_colorComp[kFwHGCalEEColorIndex]->AddElement(shape);
395  }
396  m_HGCalEEElements->AddElement(shape);
397  }
398  AddElement(m_HGCalEEElements);
399  }
400  if (m_HGCalEEElements) {
401  m_HGCalEEElements->SetRnrState(showHGCalEE);
402  gEve->Redraw3D();
403  }
404 }
405 
406 void FW3DViewGeometry::showHGCalHSi(bool showHGCalHSi) {
407  if (showHGCalHSi && !m_HGCalHSiElements) {
408  m_HGCalHSiElements = new TEveElementList("HGCalHSi");
409  auto const ids = m_geom->getMatchedIds(FWGeometry::HGCalHSi);
410  for (const auto& id : ids) {
411  TEveGeoShape* shape = m_geom->getHGCSiliconEveShape(id);
412  const unsigned int layer = m_geom->getParameters(id)[1];
413  const int siIndex = m_geom->getParameters(id)[4];
414  shape->SetTitle(Form("HGCalHSi %d", layer));
415  {
416  float color[3] = {0., 0., 0.};
417  if (siIndex >= 0 && siIndex < 3)
418  color[siIndex] = 1.f;
419  shape->SetMainColorRGB(color[0], color[1], color[2]);
420  shape->SetPickable(false);
421  m_colorComp[kFwHGCalHSiColorIndex]->AddElement(shape);
422  }
423  m_HGCalHSiElements->AddElement(shape);
424  }
425  AddElement(m_HGCalHSiElements);
426  }
427  if (m_HGCalHSiElements) {
428  m_HGCalHSiElements->SetRnrState(showHGCalHSi);
429  gEve->Redraw3D();
430  }
431 }
432 
433 void FW3DViewGeometry::showHGCalHSc(bool showHGCalHSc) {
434  if (showHGCalHSc && !m_HGCalHScElements) {
435  m_HGCalHScElements = new TEveElementList("HGCalHSc");
436  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::HGCalHSc);
437  for (const auto& id : m_geom->getMatchedIds(FWGeometry::HGCalHSc)) {
438  TEveGeoShape* shape = m_geom->getHGCScintillatorEveShape(id);
439  const unsigned int layer = m_geom->getParameters(id)[1];
440  shape->SetTitle(Form("HGCalHSc %d", layer));
442  m_HGCalHScElements->AddElement(shape);
443  }
444  AddElement(m_HGCalHScElements);
445  }
446  if (m_HGCalHScElements) {
447  m_HGCalHScElements->SetRnrState(showHGCalHSc);
448  gEve->Redraw3D();
449  }
450 }
~FW3DViewGeometry() override
void showMuonBarrel(long)
uint16_t *__restrict__ id
TEveGeoShape * getHGCSiliconEveShape(unsigned int id) const
Definition: FWGeometry.cc:351
TEveCompound * m_colorComp[kFWGeomColorSize]
void showMuonBarrel(bool)
static constexpr int minRegionId
Definition: ME0DetId.h:63
TEveElementList * m_pixelBarrelElements
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:472
TEveElementList * m_HGCalEEElements
void showTrackerEndcap(bool)
static constexpr int32_t maxRegionId
Definition: GEMDetId.h:21
std::string print(DetId detid) const
void showMuonBarrelFull(bool)
tuple cl
Definition: haddnano.py:49
constexpr std::array< uint8_t, layerIndexSize > layer
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:150
TEveElementList * m_HGCalHSiElements
void showTrackerBarrel(bool)
TEveElementList * m_HGCalHScElements
void addToCompound(TEveElement *el, FWGeomColorIndex idx, bool applyTransp=true) const
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:529
void showMuonEndcap(bool)
TEveElementList * m_pixelEndcapElements
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:318
TEveElementList * m_muonEndcapElements
TEveElementList * m_muonBarrelElements
const FWGeometry * m_geom
TEveElementList * m_trackerEndcapElements
TEveElementList * m_trackerBarrelElements
Definition: DetId.h:17
#define fwLog(_level_)
Definition: fwLog.h:45
void showPixelBarrel(bool)
TEveElementList * m_muonBarrelFullElements
static constexpr int32_t maxLayerId
Definition: GEMDetId.h:32
FW3DViewGeometry(const fireworks::Context &context)
void showPixelEndcap(bool)
static constexpr int32_t maxChamberId
Definition: GEMDetId.h:29
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:254
static constexpr int maxRegionId
Definition: ME0DetId.h:64
const TrackerTopology * getTrackerTopology() const
Definition: FWGeometry.h:156
static constexpr int32_t minLayerId
Definition: GEMDetId.h:30
static constexpr int32_t minRegionId
Definition: GEMDetId.h:20
TEveGeoShape * getHGCScintillatorEveShape(unsigned int id) const
Definition: FWGeometry.cc:417