Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:35

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