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 "TEveGeoShape.h"
21 #include "TEveCompound.h"
22 
29 
34 
36 
37 //
38 // constants, enums and typedefs
39 //
40 
41 //
42 // static data member definitions
43 //
44 
45 //
46 // constructors and destructor
47 //
50  m_muonBarrelElements(nullptr),
51  m_muonBarrelFullElements(nullptr),
52  m_muonEndcapElements(nullptr),
53  m_muonEndcapFullElements(nullptr),
54  m_pixelBarrelElements(nullptr),
55  m_pixelEndcapElements(nullptr),
56  m_trackerBarrelElements(nullptr),
57  m_trackerEndcapElements(nullptr),
58  m_HGCalEEElements(nullptr),
59  m_HGCalHSiElements(nullptr),
60  m_HGCalHScElements(nullptr),
61  m_mtdBarrelElements(nullptr),
62  m_mtdEndcapElements(nullptr) {
63  SetElementName("3D Geometry");
64 }
65 
66 // FW3DViewGeometry::FW3DViewGeometry(const FW3DViewGeometry& rhs)
67 // {
68 // // do actual copying here;
69 // }
70 
72 
73 //
74 // member functions
75 //
76 
77 //
78 // const member functions
79 //
80 
81 //
82 // static member functions
83 //
84 
87  m_muonBarrelElements = new TEveElementList("DT");
88  for (Int_t iWheel = -2; iWheel <= 2; ++iWheel) {
89  for (Int_t iStation = 1; iStation <= 4; ++iStation) {
90  // We display only the outer chambers to make the event look more
91  // prominent
92  if (iWheel == -2 || iWheel == 2 || iStation == 4) {
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  if (iStation < 4 && iSector > 12)
99  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 
111  if (m_muonBarrelElements) {
112  m_muonBarrelElements->SetRnrState(showMuonBarrel);
113  gEve->Redraw3D();
114  }
115 }
116 
119  m_muonBarrelFullElements = new TEveElementList("DT Full");
120  for (Int_t iWheel = -2; iWheel <= 2; ++iWheel) {
121  TEveElementList* cWheel = new TEveElementList(TString::Format("Wheel %d", iWheel));
122  m_muonBarrelFullElements->AddElement(cWheel);
123  for (Int_t iStation = 1; iStation <= 4; ++iStation) {
124  TEveElementList* cStation = new TEveElementList(TString::Format("Station %d", iStation));
125  cWheel->AddElement(cStation);
126  for (Int_t iSector = 1; iSector <= 14; ++iSector) {
127  if (iStation < 4 && iSector > 12)
128  continue;
129  DTChamberId id(iWheel, iStation, iSector);
130  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
131  shape->SetTitle(TString::Format("DT: W=%d, S=%d, Sec=%d\ndet-id=%u", iWheel, iStation, iSector, id.rawId()));
133  cStation->AddElement(shape);
134  }
135  }
136  }
137  AddElement(m_muonBarrelFullElements);
138  }
139 
142  gEve->Redraw3D();
143  }
144 }
145 
146 //______________________________________________________________________________
147 void FW3DViewGeometry::showMuonEndcap(bool showMuonEndcap) {
149  m_muonEndcapElements = new TEveElementList("EndCap");
150 
151  for (Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap) // 1=forward (+Z), 2=backward(-Z)
152  {
153  TEveElementList* cEndcap = nullptr;
154  if (iEndcap == 1)
155  cEndcap = new TEveElementList("CSC Forward");
156  else
157  cEndcap = new TEveElementList("CSC Backward");
158  m_muonEndcapElements->AddElement(cEndcap);
159  // Actual CSC geometry:
160  // Station 1 has 4 rings with 36 chambers in each
161  // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
162  // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
163  // Station 4: ring 1 has 18 chambers
164  Int_t maxChambers = 36;
165  for (Int_t iStation = 1; iStation <= 4; ++iStation) {
166  std::ostringstream s;
167  s << "Station" << iStation;
168  TEveElementList* cStation = new TEveElementList(s.str().c_str());
169  cEndcap->AddElement(cStation);
170  for (Int_t iRing = 1; iRing <= 4; ++iRing) {
171  if (iStation > 1 && iRing > 2)
172  continue;
173  // if( iStation > 3 && iRing > 1 ) continue;
174  std::ostringstream s;
175  s << "Ring" << iRing;
176  TEveElementList* cRing = new TEveElementList(s.str().c_str());
177  cStation->AddElement(cRing);
178  (iRing == 1 && iStation > 1) ? (maxChambers = 18) : (maxChambers = 36);
179  for (Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber) {
180  Int_t iLayer = 0; // chamber
181  CSCDetId id(iEndcap, iStation, iRing, iChamber, iLayer);
182  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
183  shape->SetTitle(TString::Format(
184  "CSC: %s, S=%d, R=%d, C=%d\ndet-id=%u", cEndcap->GetName(), iStation, iRing, iChamber, id.rawId()));
185 
187  cRing->AddElement(shape);
188  }
189  }
190  }
191  }
192 
193  // hardcoded gem and me0; need to find better way for different gem geometries
194  for (Int_t iRegion = GEMDetId::minRegionId; iRegion <= GEMDetId::maxRegionId; iRegion += 2) {
195  TEveElementList* teEndcap = nullptr;
196  teEndcap = new TEveElementList(Form("GEM Reg=%d", iRegion));
197  m_muonEndcapElements->AddElement(teEndcap);
198  int iStation = 1;
199  {
200  std::ostringstream s;
201  s << "Station" << iStation;
202  TEveElementList* cStation = new TEveElementList(s.str().c_str());
203  teEndcap->AddElement(cStation);
204 
205  for (Int_t iLayer = GEMDetId::minLayerId; iLayer <= GEMDetId::maxLayerId; ++iLayer) {
206  int maxChamber = GEMDetId::maxChamberId;
207  std::ostringstream sl;
208  sl << "Layer" << iLayer;
209  TEveElementList* elayer = new TEveElementList(sl.str().c_str());
210  cStation->AddElement(elayer);
211 
212  for (Int_t iChamber = 1; iChamber <= maxChamber; ++iChamber) {
213  std::ostringstream cl;
214  cl << "Chamber" << iChamber;
215  TEveElementList* cha = new TEveElementList(cl.str().c_str());
216  elayer->AddElement(cha);
217 
218  Int_t iRing = 1;
219  Int_t iRoll = 0;
220  try {
221  GEMDetId id(iRegion, iRing, iStation, iLayer, iChamber, iRoll);
222  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
223  if (shape) {
224  shape->SetTitle(TString::Format(
225  "GEM: , Rng=%d, St=%d, Ch=%d Rl=%d\ndet-id=%u", iRing, iStation, iChamber, iRoll, id.rawId()));
226 
227  cha->AddElement(shape);
229  }
230  } catch (cms::Exception& e) {
231  fwLog(fwlog::kError) << "FW3DViewGeomtery " << e << std::endl;
232  }
233  }
234  }
235  }
236  }
237 
238  // adding me0
239  if (m_geom->versionInfo().haveExtraDet("ME0")) {
240  for (Int_t iRegion = ME0DetId::minRegionId; iRegion <= ME0DetId::maxRegionId; iRegion = iRegion + 2) {
241  TEveElementList* teEndcap = nullptr;
242  if (iRegion == 1)
243  teEndcap = new TEveElementList("ME0 Forward");
244  else
245  teEndcap = new TEveElementList("ME0 Backward");
246  m_muonEndcapElements->AddElement(teEndcap);
247 
248  for (Int_t iLayer = 1; iLayer <= 6; ++iLayer) {
249  std::ostringstream s;
250  s << "Layer" << iLayer;
251  TEveElementList* cLayer = new TEveElementList(s.str().c_str());
252  teEndcap->AddElement(cLayer);
253 
254  for (Int_t iChamber = 1; iChamber <= 18; ++iChamber) {
255  Int_t iRoll = 1;
256  // for (Int_t iRoll = ME0DetId::minRollId; iRoll <= ME0DetId::maxRollId ; ++iRoll ){
257  ME0DetId id(iRegion, iLayer, iChamber, iRoll);
258  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
259  if (shape) {
260  shape->SetTitle(TString::Format("ME0: , Ch=%d Rl=%d\ndet-id=%u", iChamber, iRoll, id.rawId()));
261 
263  cLayer->AddElement(shape);
264  }
265  }
266  }
267  }
268  }
269 
270  AddElement(m_muonEndcapElements);
271  }
272 
273  if (m_muonEndcapElements) {
274  m_muonEndcapElements->SetRnrState(showMuonEndcap);
275  gEve->Redraw3D();
276  }
277 }
278 
279 //______________________________________________________________________________
280 void FW3DViewGeometry::showPixelBarrel(bool showPixelBarrel) {
282  m_pixelBarrelElements = new TEveElementList("PixelBarrel");
284  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::PixelBarrel);
285  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
286  TEveGeoShape* shape = m_geom->getEveShape(*id);
287 
288  uint32_t rawId = *id;
289  DetId did = DetId(rawId);
291  shape->SetTitle(title.c_str());
292 
294  m_pixelBarrelElements->AddElement(shape);
295  }
296  AddElement(m_pixelBarrelElements);
297  }
298 
299  if (m_pixelBarrelElements) {
301  gEve->Redraw3D();
302  }
303 }
304 
305 //______________________________________________________________________________
306 void FW3DViewGeometry::showPixelEndcap(bool showPixelEndcap) {
308  m_pixelEndcapElements = new TEveElementList("PixelEndcap");
309  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::PixelEndcap);
310  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
311  TEveGeoShape* shape = m_geom->getEveShape(*id);
312  uint32_t rawId = *id;
313  DetId did = DetId(rawId);
315  shape->SetTitle(title.c_str());
317  m_pixelEndcapElements->AddElement(shape);
318  }
319  AddElement(m_pixelEndcapElements);
320  }
321 
322  if (m_pixelEndcapElements) {
324  gEve->Redraw3D();
325  }
326 }
327 
328 //______________________________________________________________________________
329 void FW3DViewGeometry::showTrackerBarrel(bool showTrackerBarrel) {
331  m_trackerBarrelElements = new TEveElementList("TrackerBarrel");
333  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TIB);
334  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
335  TEveGeoShape* shape = m_geom->getEveShape(*id);
337  m_trackerBarrelElements->AddElement(shape);
338  }
340  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
341  TEveGeoShape* shape = m_geom->getEveShape(*id);
342  shape->SetTitle(Form("TrackerBarrel %d", *id));
344  m_trackerBarrelElements->AddElement(shape);
345  }
346  AddElement(m_trackerBarrelElements);
347  }
348 
351  gEve->Redraw3D();
352  }
353 }
354 
355 //______________________________________________________________________________
356 void FW3DViewGeometry::showTrackerEndcap(bool showTrackerEndcap) {
358  m_trackerEndcapElements = new TEveElementList("TrackerEndcap");
359  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TID);
360  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
361  TEveGeoShape* shape = m_geom->getEveShape(*id);
363  m_trackerEndcapElements->AddElement(shape);
364  }
366  for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
367  TEveGeoShape* shape = m_geom->getEveShape(*id);
368 
369  shape->SetTitle(Form("TrackerEndcap %d", *id));
371  m_trackerEndcapElements->AddElement(shape);
372  }
373  AddElement(m_trackerEndcapElements);
374  }
375 
378  gEve->Redraw3D();
379  }
380 }
381 
382 //______________________________________________________________________________
383 void FW3DViewGeometry::showHGCalEE(bool showHGCalEE) {
384  if (showHGCalEE && !m_HGCalEEElements) {
385  m_HGCalEEElements = new TEveElementList("HGCalEE");
386  auto const ids = m_geom->getMatchedIds(FWGeometry::HGCalEE);
387  for (const auto& id : ids) {
388  TEveGeoShape* shape = m_geom->getHGCSiliconEveShape(id);
389  const unsigned int layer = m_geom->getParameters(id)[1];
390  const int siIndex = m_geom->getParameters(id)[4];
391  shape->SetTitle(Form("HGCalEE %d", layer));
392  {
393  float color[3] = {0., 0., 0.};
394  if (siIndex >= 0 && siIndex < 3)
395  color[siIndex] = 1.f;
396  shape->SetMainColorRGB(color[0], color[1], color[2]);
397  shape->SetPickable(false);
398  m_colorComp[kFwHGCalEEColorIndex]->AddElement(shape);
399  }
400  m_HGCalEEElements->AddElement(shape);
401  }
402  AddElement(m_HGCalEEElements);
403  }
404  if (m_HGCalEEElements) {
405  m_HGCalEEElements->SetRnrState(showHGCalEE);
406  gEve->Redraw3D();
407  }
408 }
409 
410 void FW3DViewGeometry::showHGCalHSi(bool showHGCalHSi) {
412  m_HGCalHSiElements = new TEveElementList("HGCalHSi");
413  auto const ids = m_geom->getMatchedIds(FWGeometry::HGCalHSi);
414  for (const auto& id : ids) {
415  TEveGeoShape* shape = m_geom->getHGCSiliconEveShape(id);
416  const unsigned int layer = m_geom->getParameters(id)[1];
417  const int siIndex = m_geom->getParameters(id)[4];
418  shape->SetTitle(Form("HGCalHSi %d", layer));
419  {
420  float color[3] = {0., 0., 0.};
421  if (siIndex >= 0 && siIndex < 3)
422  color[siIndex] = 1.f;
423  shape->SetMainColorRGB(color[0], color[1], color[2]);
424  shape->SetPickable(false);
426  }
427  m_HGCalHSiElements->AddElement(shape);
428  }
429  AddElement(m_HGCalHSiElements);
430  }
431  if (m_HGCalHSiElements) {
432  m_HGCalHSiElements->SetRnrState(showHGCalHSi);
433  gEve->Redraw3D();
434  }
435 }
436 
437 void FW3DViewGeometry::showHGCalHSc(bool showHGCalHSc) {
439  m_HGCalHScElements = new TEveElementList("HGCalHSc");
440  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::HGCalHSc);
441  for (const auto& id : m_geom->getMatchedIds(FWGeometry::HGCalHSc)) {
442  TEveGeoShape* shape = m_geom->getHGCScintillatorEveShape(id);
443  const unsigned int layer = m_geom->getParameters(id)[1];
444  shape->SetTitle(Form("HGCalHSc %d", layer));
446  m_HGCalHScElements->AddElement(shape);
447  }
448  AddElement(m_HGCalHScElements);
449  }
450  if (m_HGCalHScElements) {
451  m_HGCalHScElements->SetRnrState(showHGCalHSc);
452  gEve->Redraw3D();
453  }
454 }
455 
456 //______________________________________________________________________________
457 void FW3DViewGeometry::showMtdBarrel(bool showMtdBarrel) {
459  m_mtdBarrelElements = new TEveElementList("MtdBarrel");
460 
461  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Forward, FWGeometry::PixelBarrel);
462  for (std::vector<unsigned int>::const_iterator mtdId = ids.begin(); mtdId != ids.end(); ++mtdId) {
463  MTDDetId id(*mtdId);
464  if (id.mtdSubDetector() != MTDDetId::MTDType::BTL)
465  continue;
466 
467  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
468  shape->SetTitle(Form("MTD barrel %d", id.rawId()));
469 
471  m_mtdBarrelElements->AddElement(shape);
472  }
473  AddElement(m_mtdBarrelElements);
474  }
475 
476  if (m_mtdBarrelElements) {
477  m_mtdBarrelElements->SetRnrState(showMtdBarrel);
478  gEve->Redraw3D();
479  }
480 }
481 
482 //______________________________________________________________________________
483 void FW3DViewGeometry::showMtdEndcap(bool showMtdEndcap) {
485  m_mtdEndcapElements = new TEveElementList("MtdEndcap");
486 
487  std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Forward, FWGeometry::PixelBarrel);
488  for (std::vector<unsigned int>::const_iterator mtdId = ids.begin(); mtdId != ids.end(); ++mtdId) {
489  MTDDetId id(*mtdId);
490  if (id.mtdSubDetector() != MTDDetId::MTDType::ETL)
491  continue;
492 
493  TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
494  shape->SetTitle(Form("MTD endcap %d", id.rawId()));
495 
497  m_mtdEndcapElements->AddElement(shape);
498  }
499  AddElement(m_mtdEndcapElements);
500  }
501 
502  if (m_mtdEndcapElements) {
503  m_mtdEndcapElements->SetRnrState(showMtdEndcap);
504  gEve->Redraw3D();
505  }
506 }
~FW3DViewGeometry() override
void showMuonBarrel(long)
TEveCompound * m_colorComp[kFWGeomColorSize]
std::vector< unsigned int > getMatchedIds(Detector det, SubDetector subdet) const
Definition: FWGeometry.cc:254
void showMuonBarrel(bool)
static constexpr int minRegionId
Definition: ME0DetId.h:63
void showMtdBarrel(bool)
TEveElementList * m_pixelBarrelElements
TEveElementList * m_mtdEndcapElements
void showMtdEndcap(bool)
std::string print(DetId detid) const
TEveElementList * m_HGCalEEElements
void showTrackerEndcap(bool)
static constexpr int32_t maxRegionId
Definition: GEMDetId.h:21
bool haveExtraDet(const char *) const
Definition: FWGeometry.cc:507
void showMuonBarrelFull(bool)
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
TEveElementList * m_HGCalHSiElements
void showTrackerBarrel(bool)
const VersionInfo & versionInfo() const
Definition: FWGeometry.h:151
TEveElementList * m_HGCalHScElements
TEveGeoShape * getHGCScintillatorEveShape(unsigned int id) const
Definition: FWGeometry.cc:395
void showMuonEndcap(bool)
TEveElementList * m_pixelEndcapElements
const TrackerTopology * getTrackerTopology() const
Definition: FWGeometry.h:157
TEveGeoShape * getHGCSiliconEveShape(unsigned int id) const
Definition: FWGeometry.cc:350
TEveElementList * m_muonEndcapElements
TEveElementList * m_muonBarrelElements
TEveElementList * m_mtdBarrelElements
const FWGeometry * m_geom
TEveElementList * m_trackerEndcapElements
TEveElementList * m_trackerBarrelElements
Definition: DetId.h:17
TEveGeoShape * getEveShape(unsigned int id) const
Definition: FWGeometry.cc:317
#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
void addToCompound(TEveElement *el, FWGeomColorIndex idx, bool applyTransp=true) const
const float * getParameters(unsigned int id) const
Definition: FWGeometry.cc:450
static constexpr int maxRegionId
Definition: ME0DetId.h:64
static constexpr int32_t minLayerId
Definition: GEMDetId.h:30
static constexpr int32_t minRegionId
Definition: GEMDetId.h:20