CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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.12 2010/09/28 11:39:51 amraktad 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),
00045    m_muonEndcapElements(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 //______________________________________________________________________________
00117 void
00118 FW3DViewGeometry::showMuonEndcap( bool showMuonEndcap )
00119 {
00120    if( showMuonEndcap && !m_muonEndcapElements )
00121    {
00122       m_muonEndcapElements = new TEveElementList( "CSC" );
00123       for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
00124       { 
00125          TEveElementList* cEndcap = 0;
00126          if( iEndcap == 1 )
00127             cEndcap = new TEveElementList( "Forward" );
00128          else
00129             cEndcap = new TEveElementList( "Backward" );
00130          m_muonEndcapElements->AddElement( cEndcap );
00131          // Actual CSC geometry:
00132          // Station 1 has 4 rings with 36 chambers in each
00133          // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
00134          // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
00135          // Station 4: ring 1 has 18 chambers
00136          Int_t maxChambers = 36;
00137          for( Int_t iStation = 1; iStation <= 4; ++iStation )
00138          {
00139             std::ostringstream s; s << "Station" << iStation;
00140             TEveElementList* cStation  = new TEveElementList( s.str().c_str() );
00141             cEndcap->AddElement( cStation );
00142             for( Int_t iRing = 1; iRing <= 4; ++iRing )
00143             {
00144                if( iStation > 1 && iRing > 2 ) continue;
00145                if( iStation > 3 && iRing > 1 ) continue;
00146                std::ostringstream s; s << "Ring" << iRing;
00147                TEveElementList* cRing  = new TEveElementList( s.str().c_str() );
00148                cStation->AddElement( cRing );
00149                ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
00150                for( Int_t iChamber = 1; iChamber <= maxChambers; ++iChamber )
00151                {
00152                   Int_t iLayer = 0; // chamber
00153                   CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
00154                   TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
00155                   addToCompound(shape, kFWMuonEndcapLineColorIndex);
00156                   cRing->AddElement( shape );
00157                }
00158             }
00159          }
00160       }
00161       AddElement( m_muonEndcapElements );
00162    }
00163 
00164    if( m_muonEndcapElements )
00165    {
00166       m_muonEndcapElements->SetRnrState( showMuonEndcap );
00167       gEve->Redraw3D();
00168    }
00169 }
00170 
00171 //______________________________________________________________________________
00172 void
00173 FW3DViewGeometry::showPixelBarrel( bool showPixelBarrel )
00174 {
00175    if( showPixelBarrel && !m_pixelBarrelElements )
00176    {
00177       m_pixelBarrelElements = new TEveElementList( "PixelBarrel" );
00178       m_pixelBarrelElements->SetRnrState( showPixelBarrel );
00179       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelBarrel );
00180       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00181            id != ids.end(); ++id )
00182       {
00183          TEveGeoShape* shape = m_geom->getEveShape( *id );
00184          addToCompound(shape, kFWPixelBarrelColorIndex);
00185          m_pixelBarrelElements->AddElement( shape );
00186       }
00187       AddElement( m_pixelBarrelElements );
00188    }
00189 
00190    if( m_pixelBarrelElements )
00191    {
00192       m_pixelBarrelElements->SetRnrState( showPixelBarrel );
00193       gEve->Redraw3D();
00194    }
00195 }
00196 
00197 //______________________________________________________________________________
00198 void
00199 FW3DViewGeometry::showPixelEndcap(bool  showPixelEndcap )
00200 {
00201    if( showPixelEndcap && ! m_pixelEndcapElements )
00202    {
00203       m_pixelEndcapElements = new TEveElementList( "PixelEndcap" );
00204       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::PixelEndcap );
00205       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00206            id != ids.end(); ++id )
00207       {
00208          TEveGeoShape* shape = m_geom->getEveShape( *id );
00209          addToCompound(shape, kFWPixelEndcapColorIndex);
00210          m_pixelEndcapElements->AddElement( shape );
00211       }
00212       AddElement( m_pixelEndcapElements );
00213    }
00214 
00215    if( m_pixelEndcapElements )
00216    {
00217       m_pixelEndcapElements->SetRnrState( showPixelEndcap );
00218       gEve->Redraw3D();
00219    }
00220 }
00221 
00222 //______________________________________________________________________________
00223 void
00224 FW3DViewGeometry::showTrackerBarrel( bool  showTrackerBarrel )
00225 {
00226    if( showTrackerBarrel && ! m_trackerBarrelElements )
00227    {
00228       m_trackerBarrelElements = new TEveElementList( "TrackerBarrel" );
00229       m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
00230       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TIB );
00231       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00232            id != ids.end(); ++id )
00233       {
00234          TEveGeoShape* shape = m_geom->getEveShape( *id ); 
00235          addToCompound(shape, kFWTrackerBarrelColorIndex);
00236          m_trackerBarrelElements->AddElement( shape );
00237       }
00238       ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TOB );
00239       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00240            id != ids.end(); ++id )
00241       {
00242          TEveGeoShape* shape = m_geom->getEveShape( *id );
00243          addToCompound(shape, kFWTrackerBarrelColorIndex);
00244          m_trackerBarrelElements->AddElement( shape );
00245       }
00246       AddElement( m_trackerBarrelElements );
00247    }
00248 
00249    if( m_trackerBarrelElements )
00250    {
00251       m_trackerBarrelElements->SetRnrState( showTrackerBarrel );
00252       gEve->Redraw3D();
00253    }
00254 }
00255 
00256 //______________________________________________________________________________
00257 void
00258 FW3DViewGeometry::showTrackerEndcap( bool showTrackerEndcap )
00259 {
00260    if( showTrackerEndcap && ! m_trackerEndcapElements )
00261    {
00262       m_trackerEndcapElements = new TEveElementList( "TrackerEndcap" );
00263       std::vector<unsigned int> ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TID );
00264       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00265            id != ids.end(); ++id )
00266       {
00267          TEveGeoShape* shape = m_geom->getEveShape( *id );
00268          addToCompound(shape, kFWTrackerEndcapColorIndex);
00269          m_trackerEndcapElements->AddElement( shape );
00270       }
00271       ids = m_geom->getMatchedIds( FWGeometry::Tracker, FWGeometry::TEC );
00272       for( std::vector<unsigned int>::const_iterator id = ids.begin();
00273            id != ids.end(); ++id )
00274       {
00275          TEveGeoShape* shape = m_geom->getEveShape( *id );
00276          addToCompound(shape, kFWTrackerEndcapColorIndex);
00277          m_trackerEndcapElements->AddElement( shape );
00278       }
00279       AddElement( m_trackerEndcapElements );
00280    }
00281 
00282    if (m_trackerEndcapElements )
00283    {
00284       m_trackerEndcapElements->SetRnrState( showTrackerEndcap );
00285       gEve->Redraw3D();
00286    }
00287 }
00288 
00289