CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/Fireworks/Core/src/FW3DViewGeometry.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FW3DViewGeometry
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Thu Mar 25 22:06:57 CET 2010
00011 // $Id: FW3DViewGeometry.cc,v 1.16 2011/09/27 17:22:17 matevz Exp $
00012 //
00013 
00014 // system include files
00015 #include <sstream>
00016 
00017 // user include files
00018 
00019 #include "TEveManager.h"
00020 #include "TEveGeoNode.h"
00021 
00022 #include "Fireworks/Core/interface/FW3DViewGeometry.h"
00023 #include "Fireworks/Core/interface/FWGeometry.h"
00024 #include "Fireworks/Core/interface/TEveElementIter.h"
00025 #include "Fireworks/Core/interface/Context.h"
00026 #include "Fireworks/Core/interface/FWColorManager.h"
00027 
00028 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00029 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00030 
00031 //
00032 // constants, enums and typedefs
00033 //
00034 
00035 //
00036 // static data member definitions
00037 //
00038 
00039 //
00040 // constructors and destructor
00041 //
00042 FW3DViewGeometry::FW3DViewGeometry(const fireworks::Context& context):
00043    FWViewGeometryList(context, false),
00044    m_muonBarrelElements(0), m_muonBarrelFullElements(0),
00045    m_muonEndcapElements(0), m_muonEndcapFullElements(0),
00046    m_pixelBarrelElements(0),
00047    m_pixelEndcapElements(0),
00048    m_trackerBarrelElements(0),
00049    m_trackerEndcapElements(0)
00050 {  
00051 
00052    SetElementName("3D Geometry");
00053 }
00054 
00055 // FW3DViewGeometry::FW3DViewGeometry(const FW3DViewGeometry& rhs)
00056 // {
00057 //    // do actual copying here;
00058 // }
00059 
00060 FW3DViewGeometry::~FW3DViewGeometry()
00061 {
00062 }
00063 
00064 
00065 //
00066 // member functions
00067 //
00068 
00069 //
00070 // const member functions
00071 //
00072 
00073 //
00074 // static member functions
00075 //
00076 
00077 void
00078 FW3DViewGeometry::showMuonBarrel( bool showMuonBarrel )
00079 {
00080    if( !m_muonBarrelElements && showMuonBarrel )
00081    {
00082       m_muonBarrelElements = new TEveElementList( "DT" );
00083       for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
00084       {
00085          for ( Int_t iStation = 1; iStation <= 4; ++iStation )
00086          {
00087             // We display only the outer chambers to make the event look more
00088             // prominent
00089             if( iWheel == -2 || iWheel == 2 || iStation == 4 )
00090             {
00091                std::ostringstream s;
00092                s << "Station" << iStation;
00093                TEveElementList* cStation  = new TEveElementList( s.str().c_str() );
00094                m_muonBarrelElements->AddElement( cStation );
00095                for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
00096                {
00097                   if( iStation < 4 && iSector > 12 ) continue;
00098                   DTChamberId id( iWheel, iStation, iSector );
00099                   TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
00100                   addToCompound(shape, kFWMuonBarrelLineColorIndex);
00101                   cStation->AddElement( shape );
00102                }
00103             }
00104          }
00105       }
00106       AddElement( m_muonBarrelElements );
00107    }
00108 
00109    if( m_muonBarrelElements )
00110    {
00111       m_muonBarrelElements->SetRnrState( showMuonBarrel );
00112       gEve->Redraw3D();
00113    }
00114 }
00115 
00116 void
00117 FW3DViewGeometry::showMuonBarrelFull(bool showMuonBarrel)
00118 {
00119    if (!m_muonBarrelFullElements && showMuonBarrel)
00120    {
00121       m_muonBarrelFullElements = new TEveElementList( "DT Full" );
00122       for (Int_t iWheel = -2; iWheel <= 2; ++iWheel)
00123       {
00124          TEveElementList* cWheel = new TEveElementList(TString::Format("Wheel %d", iWheel));
00125          m_muonBarrelFullElements->AddElement(cWheel);
00126          for (Int_t iStation = 1; iStation <= 4; ++iStation)
00127          {
00128             TEveElementList* cStation  = new TEveElementList(TString::Format("Station %d", iStation));
00129             cWheel->AddElement(cStation);
00130             for (Int_t iSector = 1 ; iSector <= 14; ++iSector)
00131             {
00132                if( iStation < 4 && iSector > 12 ) continue;
00133                DTChamberId id( iWheel, iStation, iSector );
00134                TEveGeoShape* shape = m_geom->getEveShape(id.rawId());
00135                shape->SetTitle(TString::Format("DT: W=%d, S=%d, Sec=%d\ndet-id=%u",
00136                                                iWheel, iStation, iSector, id.rawId()));
00137                addToCompound(shape, kFWMuonBarrelLineColorIndex);
00138                cStation->AddElement(shape);
00139             }
00140          }
00141       }
00142       AddElement(m_muonBarrelFullElements);
00143    }
00144 
00145    if (m_muonBarrelFullElements)
00146    {
00147       m_muonBarrelFullElements->SetRnrState(showMuonBarrel);
00148       gEve->Redraw3D();
00149    }
00150 }
00151 
00152 //______________________________________________________________________________
00153 void
00154 FW3DViewGeometry::showMuonEndcap( bool showMuonEndcap )
00155 {
00156    if( showMuonEndcap && !m_muonEndcapElements )
00157    {
00158       m_muonEndcapElements = new TEveElementList( "CSC" );
00159       for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
00160       { 
00161          TEveElementList* cEndcap = 0;
00162          if( iEndcap == 1 )
00163             cEndcap = new TEveElementList( "Forward" );
00164          else
00165             cEndcap = new TEveElementList( "Backward" );
00166          m_muonEndcapElements->AddElement( cEndcap );
00167          // Actual CSC geometry:
00168          // Station 1 has 4 rings with 36 chambers in each
00169          // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
00170          // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
00171          // Station 4: ring 1 has 18 chambers
00172          Int_t maxChambers = 36;
00173          for( Int_t iStation = 1; iStation <= 4; ++iStation )
00174          {
00175             std::ostringstream s; s << "Station" << iStation;
00176             TEveElementList* cStation  = new TEveElementList( s.str().c_str() );
00177             cEndcap->AddElement( cStation );
00178             for( Int_t iRing = 1; iRing <= 4; ++iRing )
00179             {
00180                if( iStation > 1 && iRing > 2 ) continue;
00181                if( iStation > 3 && iRing > 1 ) continue;
00182                std::ostringstream s; s << "Ring" << iRing;
00183                TEveElementList* cRing  = new TEveElementList( s.str().c_str() );
00184                cStation->AddElement( cRing );
00185                ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
00186                for( Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber )
00187                {
00188                   Int_t iLayer = 0; // chamber
00189                   CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
00190                   TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
00191                   shape->SetTitle(TString::Format("CSC: %s, S=%d, R=%d, C=%d\ndet-id=%u",
00192                                                   cEndcap->GetName(), iStation, iRing, iChamber, id.rawId()));
00193                             
00194                   addToCompound(shape, kFWMuonEndcapLineColorIndex);
00195                   cRing->AddElement( shape );
00196                }
00197             }
00198          }
00199       }
00200       AddElement( m_muonEndcapElements );
00201    }
00202 
00203    if( m_muonEndcapElements )
00204    {
00205       m_muonEndcapElements->SetRnrState( showMuonEndcap );
00206       gEve->Redraw3D();
00207    }
00208 }
00209 
00210 //______________________________________________________________________________
00211 void
00212 FW3DViewGeometry::showPixelBarrel( bool showPixelBarrel )
00213 {
00214    if( showPixelBarrel && !m_pixelBarrelElements )
00215    {
00216       m_pixelBarrelElements = new TEveElementList( "PixelBarrel" );
00217       m_pixelBarrelElements->SetRnrState( showPixelBarrel );
00218       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelBarrel );
00219       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00220            id != ids.end(); ++id )
00221       {
00222          TEveGeoShape* shape = m_geom->getEveShape( *id );
00223          shape->SetTitle(Form("PixelBarrel %d",*id));
00224          addToCompound(shape, kFWPixelBarrelColorIndex);
00225          m_pixelBarrelElements->AddElement( shape );
00226       }
00227       AddElement( m_pixelBarrelElements );
00228    }
00229 
00230    if( m_pixelBarrelElements )
00231    {
00232       m_pixelBarrelElements->SetRnrState( showPixelBarrel );
00233       gEve->Redraw3D();
00234    }
00235 }
00236 
00237 //______________________________________________________________________________
00238 void
00239 FW3DViewGeometry::showPixelEndcap(bool  showPixelEndcap )
00240 {
00241    if( showPixelEndcap && ! m_pixelEndcapElements )
00242    {
00243       m_pixelEndcapElements = new TEveElementList( "PixelEndcap" );
00244       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelEndcap );
00245       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00246            id != ids.end(); ++id )
00247       {
00248          TEveGeoShape* shape = m_geom->getEveShape( *id );
00249 
00250          shape->SetTitle(Form("PixelEndCap %d",*id));
00251          addToCompound(shape, kFWPixelEndcapColorIndex);
00252          m_pixelEndcapElements->AddElement( shape );
00253       }
00254       AddElement( m_pixelEndcapElements );
00255    }
00256 
00257    if( m_pixelEndcapElements )
00258    {
00259       m_pixelEndcapElements->SetRnrState( showPixelEndcap );
00260       gEve->Redraw3D();
00261    }
00262 }
00263 
00264 //______________________________________________________________________________
00265 void
00266 FW3DViewGeometry::showTrackerBarrel( bool  showTrackerBarrel )
00267 {
00268    if( showTrackerBarrel && ! m_trackerBarrelElements )
00269    {
00270       m_trackerBarrelElements = new TEveElementList( "TrackerBarrel" );
00271       m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
00272       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TIB );
00273       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00274            id != ids.end(); ++id )
00275       {
00276          TEveGeoShape* shape = m_geom->getEveShape( *id ); 
00277          addToCompound(shape, kFWTrackerBarrelColorIndex);
00278          m_trackerBarrelElements->AddElement( shape );
00279       }
00280       ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TOB );
00281       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00282            id != ids.end(); ++id )
00283       {
00284          TEveGeoShape* shape = m_geom->getEveShape( *id );
00285 
00286          shape->SetTitle(Form("TrackerBarrel %d",*id));
00287          addToCompound(shape, kFWTrackerBarrelColorIndex);
00288          m_trackerBarrelElements->AddElement( shape );
00289       }
00290       AddElement( m_trackerBarrelElements );
00291    }
00292 
00293    if( m_trackerBarrelElements )
00294    {
00295       m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
00296       gEve->Redraw3D();
00297    }
00298 }
00299 
00300 //______________________________________________________________________________
00301 void
00302 FW3DViewGeometry::showTrackerEndcap( bool showTrackerEndcap )
00303 {
00304    if( showTrackerEndcap && ! m_trackerEndcapElements )
00305    {
00306       m_trackerEndcapElements = new TEveElementList( "TrackerEndcap" );
00307       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TID );
00308       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00309            id != ids.end(); ++id )
00310       {
00311          TEveGeoShape* shape = m_geom->getEveShape( *id );
00312          addToCompound(shape, kFWTrackerEndcapColorIndex);
00313          m_trackerEndcapElements->AddElement( shape );
00314       }
00315       ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TEC );
00316       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00317            id != ids.end(); ++id )
00318       {
00319          TEveGeoShape* shape = m_geom->getEveShape( *id );
00320 
00321          shape->SetTitle(Form("TrackerEndcap %d",*id));
00322          addToCompound(shape, kFWTrackerEndcapColorIndex);
00323          m_trackerEndcapElements->AddElement( shape );
00324       }
00325       AddElement( m_trackerEndcapElements );
00326    }
00327 
00328    if (m_trackerEndcapElements )
00329    {
00330       m_trackerEndcapElements->SetRnrState( showTrackerEndcap );
00331       gEve->Redraw3D();
00332    }
00333 }
00334 
00335