Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-13 23:03:10

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FW3DViewGeometry
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Alja Mrak-Tadel
0010 //         Created:  Thu Mar 25 22:06:57 CET 2010
0011 //
0012 
0013 // system include files
0014 #include <sstream>
0015 
0016 // user include files
0017 
0018 #include "TEveManager.h"
0019 #include "TEveGeoNode.h"
0020 #include "TEveGeoShape.h"
0021 #include "TEveCompound.h"
0022 
0023 #include "Fireworks/Core/interface/FW3DViewGeometry.h"
0024 #include "Fireworks/Core/interface/FWGeometry.h"
0025 #include "Fireworks/Core/interface/TEveElementIter.h"
0026 #include "Fireworks/Core/interface/Context.h"
0027 #include "Fireworks/Core/interface/FWColorManager.h"
0028 #include "Fireworks/Core/interface/fwLog.h"
0029 
0030 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
0031 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
0032 #include "DataFormats/MuonDetId/interface/GEMDetId.h"
0033 #include "DataFormats/MuonDetId/interface/ME0DetId.h"
0034 
0035 //
0036 // constants, enums and typedefs
0037 //
0038 
0039 //
0040 // static data member definitions
0041 //
0042 
0043 //
0044 // constructors and destructor
0045 //
0046 FW3DViewGeometry::FW3DViewGeometry(const fireworks::Context& context)
0047     : FWViewGeometryList(context, false),
0048       m_muonBarrelElements(nullptr),
0049       m_muonBarrelFullElements(nullptr),
0050       m_muonEndcapElements(nullptr),
0051       m_muonEndcapFullElements(nullptr),
0052       m_pixelBarrelElements(nullptr),
0053       m_pixelEndcapElements(nullptr),
0054       m_trackerBarrelElements(nullptr),
0055       m_trackerEndcapElements(nullptr),
0056       m_HGCalEEElements(nullptr),
0057       m_HGCalHSiElements(nullptr),
0058       m_HGCalHScElements(nullptr) {
0059   SetElementName("3D Geometry");
0060 }
0061 
0062 // FW3DViewGeometry::FW3DViewGeometry(const FW3DViewGeometry& rhs)
0063 // {
0064 //    // do actual copying here;
0065 // }
0066 
0067 FW3DViewGeometry::~FW3DViewGeometry() {}
0068 
0069 //
0070 // member functions
0071 //
0072 
0073 //
0074 // const member functions
0075 //
0076 
0077 //
0078 // static member functions
0079 //
0080 
0081 void FW3DViewGeometry::showMuonBarrel(bool showMuonBarrel) {
0082   if (!m_muonBarrelElements && showMuonBarrel) {
0083     m_muonBarrelElements = new TEveElementList("DT");
0084     for (Int_t iWheel = -2; iWheel <= 2; ++iWheel) {
0085       for (Int_t iStation = 1; iStation <= 4; ++iStation) {
0086         // We display only the outer chambers to make the event look more
0087         // prominent
0088         if (iWheel == -2 || iWheel == 2 || iStation == 4) {
0089           std::ostringstream s;
0090           s << "Station" << iStation;
0091           TEveElementList* cStation = new TEveElementList(s.str().c_str());
0092           m_muonBarrelElements->AddElement(cStation);
0093           for (Int_t iSector = 1; iSector <= 14; ++iSector) {
0094             if (iStation < 4 && iSector > 12)
0095               continue;
0096             DTChamberId id(iWheel, iStation, iSector);
0097             TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
0098             addToCompound(shape, kFWMuonBarrelLineColorIndex);
0099             cStation->AddElement(shape);
0100           }
0101         }
0102       }
0103     }
0104     AddElement(m_muonBarrelElements);
0105   }
0106 
0107   if (m_muonBarrelElements) {
0108     m_muonBarrelElements->SetRnrState(showMuonBarrel);
0109     gEve->Redraw3D();
0110   }
0111 }
0112 
0113 void FW3DViewGeometry::showMuonBarrelFull(bool showMuonBarrel) {
0114   if (!m_muonBarrelFullElements && showMuonBarrel) {
0115     m_muonBarrelFullElements = new TEveElementList("DT Full");
0116     for (Int_t iWheel = -2; iWheel <= 2; ++iWheel) {
0117       TEveElementList* cWheel = new TEveElementList(TString::Format("Wheel %d", iWheel));
0118       m_muonBarrelFullElements->AddElement(cWheel);
0119       for (Int_t iStation = 1; iStation <= 4; ++iStation) {
0120         TEveElementList* cStation = new TEveElementList(TString::Format("Station %d", iStation));
0121         cWheel->AddElement(cStation);
0122         for (Int_t iSector = 1; iSector <= 14; ++iSector) {
0123           if (iStation < 4 && iSector > 12)
0124             continue;
0125           DTChamberId id(iWheel, iStation, iSector);
0126           TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
0127           shape->SetTitle(TString::Format("DT: W=%d, S=%d, Sec=%d\ndet-id=%u", iWheel, iStation, iSector, id.rawId()));
0128           addToCompound(shape, kFWMuonBarrelLineColorIndex);
0129           cStation->AddElement(shape);
0130         }
0131       }
0132     }
0133     AddElement(m_muonBarrelFullElements);
0134   }
0135 
0136   if (m_muonBarrelFullElements) {
0137     m_muonBarrelFullElements->SetRnrState(showMuonBarrel);
0138     gEve->Redraw3D();
0139   }
0140 }
0141 
0142 //______________________________________________________________________________
0143 void FW3DViewGeometry::showMuonEndcap(bool showMuonEndcap) {
0144   if (showMuonEndcap && !m_muonEndcapElements) {
0145     m_muonEndcapElements = new TEveElementList("EndCap");
0146 
0147     for (Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap)  // 1=forward (+Z), 2=backward(-Z)
0148     {
0149       TEveElementList* cEndcap = nullptr;
0150       if (iEndcap == 1)
0151         cEndcap = new TEveElementList("CSC Forward");
0152       else
0153         cEndcap = new TEveElementList("CSC Backward");
0154       m_muonEndcapElements->AddElement(cEndcap);
0155       // Actual CSC geometry:
0156       // Station 1 has 4 rings with 36 chambers in each
0157       // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
0158       // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
0159       // Station 4: ring 1 has 18 chambers
0160       Int_t maxChambers = 36;
0161       for (Int_t iStation = 1; iStation <= 4; ++iStation) {
0162         std::ostringstream s;
0163         s << "Station" << iStation;
0164         TEveElementList* cStation = new TEveElementList(s.str().c_str());
0165         cEndcap->AddElement(cStation);
0166         for (Int_t iRing = 1; iRing <= 4; ++iRing) {
0167           if (iStation > 1 && iRing > 2)
0168             continue;
0169           // if( iStation > 3 && iRing > 1 ) continue;
0170           std::ostringstream s;
0171           s << "Ring" << iRing;
0172           TEveElementList* cRing = new TEveElementList(s.str().c_str());
0173           cStation->AddElement(cRing);
0174           (iRing == 1 && iStation > 1) ? (maxChambers = 18) : (maxChambers = 36);
0175           for (Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber) {
0176             Int_t iLayer = 0;  // chamber
0177             CSCDetId id(iEndcap, iStation, iRing, iChamber, iLayer);
0178             TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
0179             shape->SetTitle(TString::Format(
0180                 "CSC: %s, S=%d, R=%d, C=%d\ndet-id=%u", cEndcap->GetName(), iStation, iRing, iChamber, id.rawId()));
0181 
0182             addToCompound(shape, kFWMuonEndcapLineColorIndex);
0183             cRing->AddElement(shape);
0184           }
0185         }
0186       }
0187     }
0188 
0189     // hardcoded gem and me0; need to find better way for different gem geometries
0190     for (Int_t iRegion = GEMDetId::minRegionId; iRegion <= GEMDetId::maxRegionId; iRegion += 2) {
0191       TEveElementList* teEndcap = nullptr;
0192       teEndcap = new TEveElementList(Form("GEM Reg=%d", iRegion));
0193       m_muonEndcapElements->AddElement(teEndcap);
0194       int iStation = 1;
0195       {
0196         std::ostringstream s;
0197         s << "Station" << iStation;
0198         TEveElementList* cStation = new TEveElementList(s.str().c_str());
0199         teEndcap->AddElement(cStation);
0200 
0201         for (Int_t iLayer = GEMDetId::minLayerId; iLayer <= GEMDetId::maxLayerId; ++iLayer) {
0202           int maxChamber = GEMDetId::maxChamberId;
0203           std::ostringstream sl;
0204           sl << "Layer" << iLayer;
0205           TEveElementList* elayer = new TEveElementList(sl.str().c_str());
0206           cStation->AddElement(elayer);
0207 
0208           for (Int_t iChamber = 1; iChamber <= maxChamber; ++iChamber) {
0209             std::ostringstream cl;
0210             cl << "Chamber" << iChamber;
0211             TEveElementList* cha = new TEveElementList(cl.str().c_str());
0212             elayer->AddElement(cha);
0213 
0214             Int_t iRing = 1;
0215             Int_t iRoll = 0;
0216             try {
0217               GEMDetId id(iRegion, iRing, iStation, iLayer, iChamber, iRoll);
0218               TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
0219               if (shape) {
0220                 shape->SetTitle(TString::Format(
0221                     "GEM: , Rng=%d, St=%d, Ch=%d Rl=%d\ndet-id=%u", iRing, iStation, iChamber, iRoll, id.rawId()));
0222 
0223                 cha->AddElement(shape);
0224                 addToCompound(shape, kFWMuonEndcapLineColorIndex);
0225               }
0226             } catch (cms::Exception& e) {
0227               fwLog(fwlog::kError) << "FW3DViewGeomtery " << e << std::endl;
0228             }
0229           }
0230         }
0231       }
0232     }
0233 
0234     // adding me0
0235     if (m_geom->versionInfo().haveExtraDet("ME0")) {
0236       for (Int_t iRegion = ME0DetId::minRegionId; iRegion <= ME0DetId::maxRegionId; iRegion = iRegion + 2) {
0237         TEveElementList* teEndcap = nullptr;
0238         if (iRegion == 1)
0239           teEndcap = new TEveElementList("ME0 Forward");
0240         else
0241           teEndcap = new TEveElementList("ME0 Backward");
0242         m_muonEndcapElements->AddElement(teEndcap);
0243 
0244         for (Int_t iLayer = 1; iLayer <= 6; ++iLayer) {
0245           std::ostringstream s;
0246           s << "Layer" << iLayer;
0247           TEveElementList* cLayer = new TEveElementList(s.str().c_str());
0248           teEndcap->AddElement(cLayer);
0249 
0250           for (Int_t iChamber = 1; iChamber <= 18; ++iChamber) {
0251             Int_t iRoll = 1;
0252             // for (Int_t iRoll = ME0DetId::minRollId; iRoll <= ME0DetId::maxRollId ; ++iRoll ){
0253             ME0DetId id(iRegion, iLayer, iChamber, iRoll);
0254             TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
0255             if (shape) {
0256               shape->SetTitle(TString::Format("ME0: , Ch=%d Rl=%d\ndet-id=%u", iChamber, iRoll, id.rawId()));
0257 
0258               addToCompound(shape, kFWMuonEndcapLineColorIndex);
0259               cLayer->AddElement(shape);
0260             }
0261           }
0262         }
0263       }
0264     }
0265 
0266     AddElement(m_muonEndcapElements);
0267   }
0268 
0269   if (m_muonEndcapElements) {
0270     m_muonEndcapElements->SetRnrState(showMuonEndcap);
0271     gEve->Redraw3D();
0272   }
0273 }
0274 
0275 //______________________________________________________________________________
0276 void FW3DViewGeometry::showPixelBarrel(bool showPixelBarrel) {
0277   if (showPixelBarrel && !m_pixelBarrelElements) {
0278     m_pixelBarrelElements = new TEveElementList("PixelBarrel");
0279     m_pixelBarrelElements->SetRnrState(showPixelBarrel);
0280     std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::PixelBarrel);
0281     for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
0282       TEveGeoShape* shape = m_geom->getEveShape(*id);
0283 
0284       uint32_t rawId = *id;
0285       DetId did = DetId(rawId);
0286       std::string title = m_geom->getTrackerTopology()->print(did);
0287       shape->SetTitle(title.c_str());
0288 
0289       addToCompound(shape, kFWPixelBarrelColorIndex);
0290       m_pixelBarrelElements->AddElement(shape);
0291     }
0292     AddElement(m_pixelBarrelElements);
0293   }
0294 
0295   if (m_pixelBarrelElements) {
0296     m_pixelBarrelElements->SetRnrState(showPixelBarrel);
0297     gEve->Redraw3D();
0298   }
0299 }
0300 
0301 //______________________________________________________________________________
0302 void FW3DViewGeometry::showPixelEndcap(bool showPixelEndcap) {
0303   if (showPixelEndcap && !m_pixelEndcapElements) {
0304     m_pixelEndcapElements = new TEveElementList("PixelEndcap");
0305     std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::PixelEndcap);
0306     for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
0307       TEveGeoShape* shape = m_geom->getEveShape(*id);
0308       uint32_t rawId = *id;
0309       DetId did = DetId(rawId);
0310       std::string title = m_geom->getTrackerTopology()->print(did);
0311       shape->SetTitle(title.c_str());
0312       addToCompound(shape, kFWPixelEndcapColorIndex);
0313       m_pixelEndcapElements->AddElement(shape);
0314     }
0315     AddElement(m_pixelEndcapElements);
0316   }
0317 
0318   if (m_pixelEndcapElements) {
0319     m_pixelEndcapElements->SetRnrState(showPixelEndcap);
0320     gEve->Redraw3D();
0321   }
0322 }
0323 
0324 //______________________________________________________________________________
0325 void FW3DViewGeometry::showTrackerBarrel(bool showTrackerBarrel) {
0326   if (showTrackerBarrel && !m_trackerBarrelElements) {
0327     m_trackerBarrelElements = new TEveElementList("TrackerBarrel");
0328     m_trackerBarrelElements->SetRnrState(showTrackerBarrel);
0329     std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TIB);
0330     for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
0331       TEveGeoShape* shape = m_geom->getEveShape(*id);
0332       addToCompound(shape, kFWTrackerBarrelColorIndex);
0333       m_trackerBarrelElements->AddElement(shape);
0334     }
0335     ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TOB);
0336     for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
0337       TEveGeoShape* shape = m_geom->getEveShape(*id);
0338       shape->SetTitle(Form("TrackerBarrel %d", *id));
0339       addToCompound(shape, kFWTrackerBarrelColorIndex);
0340       m_trackerBarrelElements->AddElement(shape);
0341     }
0342     AddElement(m_trackerBarrelElements);
0343   }
0344 
0345   if (m_trackerBarrelElements) {
0346     m_trackerBarrelElements->SetRnrState(showTrackerBarrel);
0347     gEve->Redraw3D();
0348   }
0349 }
0350 
0351 //______________________________________________________________________________
0352 void FW3DViewGeometry::showTrackerEndcap(bool showTrackerEndcap) {
0353   if (showTrackerEndcap && !m_trackerEndcapElements) {
0354     m_trackerEndcapElements = new TEveElementList("TrackerEndcap");
0355     std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TID);
0356     for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
0357       TEveGeoShape* shape = m_geom->getEveShape(*id);
0358       addToCompound(shape, kFWTrackerEndcapColorIndex);
0359       m_trackerEndcapElements->AddElement(shape);
0360     }
0361     ids = m_geom->getMatchedIds(FWGeometry::Tracker, FWGeometry::TEC);
0362     for (std::vector<unsigned int>::const_iterator id = ids.begin(); id != ids.end(); ++id) {
0363       TEveGeoShape* shape = m_geom->getEveShape(*id);
0364 
0365       shape->SetTitle(Form("TrackerEndcap %d", *id));
0366       addToCompound(shape, kFWTrackerEndcapColorIndex);
0367       m_trackerEndcapElements->AddElement(shape);
0368     }
0369     AddElement(m_trackerEndcapElements);
0370   }
0371 
0372   if (m_trackerEndcapElements) {
0373     m_trackerEndcapElements->SetRnrState(showTrackerEndcap);
0374     gEve->Redraw3D();
0375   }
0376 }
0377 
0378 //______________________________________________________________________________
0379 void FW3DViewGeometry::showHGCalEE(bool showHGCalEE) {
0380   if (showHGCalEE && !m_HGCalEEElements) {
0381     m_HGCalEEElements = new TEveElementList("HGCalEE");
0382     auto const ids = m_geom->getMatchedIds(FWGeometry::HGCalEE);
0383     for (const auto& id : ids) {
0384       TEveGeoShape* shape = m_geom->getHGCSiliconEveShape(id);
0385       const unsigned int layer = m_geom->getParameters(id)[1];
0386       const int siIndex = m_geom->getParameters(id)[4];
0387       shape->SetTitle(Form("HGCalEE %d", layer));
0388       {
0389         float color[3] = {0., 0., 0.};
0390         if (siIndex >= 0 && siIndex < 3)
0391           color[siIndex] = 1.f;
0392         shape->SetMainColorRGB(color[0], color[1], color[2]);
0393         shape->SetPickable(false);
0394         m_colorComp[kFwHGCalEEColorIndex]->AddElement(shape);
0395       }
0396       m_HGCalEEElements->AddElement(shape);
0397     }
0398     AddElement(m_HGCalEEElements);
0399   }
0400   if (m_HGCalEEElements) {
0401     m_HGCalEEElements->SetRnrState(showHGCalEE);
0402     gEve->Redraw3D();
0403   }
0404 }
0405 
0406 void FW3DViewGeometry::showHGCalHSi(bool showHGCalHSi) {
0407   if (showHGCalHSi && !m_HGCalHSiElements) {
0408     m_HGCalHSiElements = new TEveElementList("HGCalHSi");
0409     auto const ids = m_geom->getMatchedIds(FWGeometry::HGCalHSi);
0410     for (const auto& id : ids) {
0411       TEveGeoShape* shape = m_geom->getHGCSiliconEveShape(id);
0412       const unsigned int layer = m_geom->getParameters(id)[1];
0413       const int siIndex = m_geom->getParameters(id)[4];
0414       shape->SetTitle(Form("HGCalHSi %d", layer));
0415       {
0416         float color[3] = {0., 0., 0.};
0417         if (siIndex >= 0 && siIndex < 3)
0418           color[siIndex] = 1.f;
0419         shape->SetMainColorRGB(color[0], color[1], color[2]);
0420         shape->SetPickable(false);
0421         m_colorComp[kFwHGCalHSiColorIndex]->AddElement(shape);
0422       }
0423       m_HGCalHSiElements->AddElement(shape);
0424     }
0425     AddElement(m_HGCalHSiElements);
0426   }
0427   if (m_HGCalHSiElements) {
0428     m_HGCalHSiElements->SetRnrState(showHGCalHSi);
0429     gEve->Redraw3D();
0430   }
0431 }
0432 
0433 void FW3DViewGeometry::showHGCalHSc(bool showHGCalHSc) {
0434   if (showHGCalHSc && !m_HGCalHScElements) {
0435     m_HGCalHScElements = new TEveElementList("HGCalHSc");
0436     std::vector<unsigned int> ids = m_geom->getMatchedIds(FWGeometry::HGCalHSc);
0437     for (const auto& id : m_geom->getMatchedIds(FWGeometry::HGCalHSc)) {
0438       TEveGeoShape* shape = m_geom->getHGCScintillatorEveShape(id);
0439       const unsigned int layer = m_geom->getParameters(id)[1];
0440       shape->SetTitle(Form("HGCalHSc %d", layer));
0441       addToCompound(shape, kFwHGCalHScColorIndex);
0442       m_HGCalHScElements->AddElement(shape);
0443     }
0444     AddElement(m_HGCalHScElements);
0445   }
0446   if (m_HGCalHScElements) {
0447     m_HGCalHScElements->SetRnrState(showHGCalHSc);
0448     gEve->Redraw3D();
0449   }
0450 }