CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/Fireworks/Core/src/FWRPZViewGeometry.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWRPZViewGeometry
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Alja Mrak-Tadel
00010 //         Created:  Thu Mar 25 20:33:06 CET 2010
00011 // $Id: FWRPZViewGeometry.cc,v 1.17 2010/12/16 16:40:56 yana Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 
00017 // user include files
00018 
00019 #include <iostream>
00020 #include "TGeoBBox.h"
00021 
00022 #include "TEveElement.h"
00023 #include "TEveCompound.h"
00024 #include "TEveScene.h"
00025 #include "TEvePointSet.h"
00026 #include "TEveStraightLineSet.h"
00027 #include "TEveGeoNode.h"
00028 
00029 #include "Fireworks/Core/interface/FWRPZViewGeometry.h"
00030 #include "Fireworks/Core/interface/FWGeometry.h"
00031 #include "Fireworks/Core/interface/FWColorManager.h"
00032 #include "Fireworks/Core/interface/Context.h"
00033 #include "Fireworks/Core/interface/fwLog.h"
00034 
00035 #include "DataFormats/MuonDetId/interface/DTChamberId.h"
00036 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00037 
00038 //
00039 //
00040 //
00041 // constants, enums and typedefs
00042 //
00043 
00044 //
00045 // static data member definitions
00046 //
00047 
00048 //
00049 // constructors and destructor
00050 //
00051 FWRPZViewGeometry::FWRPZViewGeometry(const fireworks::Context& context):
00052    FWViewGeometryList(context),
00053    m_rhoPhiGeo(0),
00054    m_rhoZGeo(0)
00055 {
00056    SetElementName("RPZGeomShared");
00057 }
00058 
00059 // FWRPZViewGeometry::FWRPZViewGeometry(const FWRPZViewGeometry& rhs)
00060 // {
00061 //    // do actual copying here;
00062 // }
00063 
00064 FWRPZViewGeometry::~FWRPZViewGeometry()
00065 {
00066    m_rhoPhiGeo->DecDenyDestroy();
00067    m_rhoZGeo->DecDenyDestroy();
00068 }
00069 
00070 //______________________________________________________________________________
00071 
00072 
00073 TEveElement*
00074 FWRPZViewGeometry::getGeoElements(const FWViewType::EType type)
00075 {
00076    if( !m_geom ) return ( new TEveCompound( "dummy" ));
00077 
00078    if (type == FWViewType::kRhoZ)
00079    {
00080       if ( !m_rhoZGeo)
00081       {
00082          m_rhoZGeo = new TEveElementList("Geomtery RhoZ");
00083          
00084          m_rhoZGeo->IncDenyDestroy();
00085          m_rhoZGeo->AddElement(makeMuonGeometryRhoZ());
00086          m_rhoZGeo->AddElement(makeCaloOutlineRhoZ());
00087       }
00088       return m_rhoZGeo;
00089    }
00090    else 
00091    {
00092       if ( !m_rhoPhiGeo)
00093       {
00094          m_rhoPhiGeo = new TEveElementList("Geomtery RhoPhi");
00095          m_rhoPhiGeo->IncDenyDestroy();
00096          m_rhoPhiGeo->AddElement(makeMuonGeometryRhoPhi());
00097          m_rhoPhiGeo->AddElement(makeCaloOutlineRhoPhi());
00098 
00099       }
00100       return m_rhoPhiGeo;
00101    }
00102    return 0;
00103 }
00104 
00105 //______________________________________________________________________________
00106 
00107 
00108 TEveElement*
00109 FWRPZViewGeometry::makeCaloOutlineRhoZ()
00110 {
00111    using namespace fireworks;
00112 
00113    float ri = m_context.caloZ2()*tan(2*atan(exp(-m_context.caloMaxEta())));
00114 
00115    TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoZoutline" );
00116    el->SetPickable(kFALSE);
00117    addToCompound(el, kFWTrackerBarrelColorIndex, false);
00118 
00119    el->AddLine(0,  m_context.caloR1(), -m_context.caloZ1(), 0,  m_context.caloR1(),  m_context.caloZ1());
00120    el->AddLine(0, -m_context.caloR1(),  m_context.caloZ1(), 0, -m_context.caloR1(), -m_context.caloZ1());
00121 
00122    el->AddLine(0, -m_context.caloR2(),   m_context.caloZ2(), 0,  -ri,   m_context.caloZ2());
00123    el->AddLine(0, ri,  m_context.caloZ2(), 0,  m_context.caloR2(), m_context.caloZ2());
00124 
00125    el->AddLine(0, -m_context.caloR2(),   -m_context.caloZ2(), 0,  -ri,   -m_context.caloZ2());
00126    el->AddLine(0, ri,  -m_context.caloZ2(), 0,  m_context.caloR2(), -m_context.caloZ2());
00127  
00128    return el;
00129 }
00130 
00131 TEveElement*
00132 FWRPZViewGeometry::makeCaloOutlineRhoPhi()
00133 { 
00134    TEveStraightLineSet* el = new TEveStraightLineSet( "TrackerRhoPhi" );
00135    addToCompound(el, kFWTrackerBarrelColorIndex, false);
00136 
00137    el->SetLineColor(m_context.colorManager()->geomColor(kFWTrackerBarrelColorIndex));
00138    const unsigned int nSegments = 100;
00139    const double r =  m_context.caloR1();
00140    for ( unsigned int i = 1; i <= nSegments; ++i )
00141       el->AddLine(r*sin(TMath::TwoPi()/nSegments*(i-1)), r*cos(TMath::TwoPi()/nSegments*(i-1)), 0,
00142                   r*sin(TMath::TwoPi()/nSegments*i), r*cos(TMath::TwoPi()/nSegments*i), 0);
00143 
00144    TEvePointSet* ref = new TEvePointSet("reference");
00145    ref->SetTitle("(0,0,0)");
00146    ref->SetMarkerStyle(4);
00147    ref->SetMarkerColor(kWhite);
00148    ref->SetNextPoint(0.,0.,0.);
00149    el->AddElement(ref);
00150 
00151    return el;
00152 }
00153 
00154 //______________________________________________________________________________
00155 
00156 TEveElement*
00157 FWRPZViewGeometry::makeMuonGeometryRhoPhi( void )
00158 {
00159    Int_t iWheel = 0;
00160  
00161    // rho-phi view
00162    TEveCompound* container = new TEveCompound( "MuonRhoPhi" );
00163 
00164 
00165    for( Int_t iStation = 1; iStation <= 4; ++iStation )
00166    {
00167       for( Int_t iSector = 1 ; iSector <= 14; ++iSector )
00168       {
00169          if( iStation < 4 && iSector > 12 ) continue;
00170          DTChamberId id( iWheel, iStation, iSector );
00171          TEveGeoShape* shape = m_geom->getEveShape( id.rawId() );
00172          if( shape ) 
00173          {
00174             shape->SetMainColor(m_colorComp[kFWMuonBarrelLineColorIndex]->GetMainColor());
00175             addToCompound(shape, kFWMuonBarrelLineColorIndex);
00176             container->AddElement( shape );
00177          }
00178       }
00179    }
00180    return container;
00181 }
00182 
00183 //______________________________________________________________________________
00184 
00185 TEveElement*
00186 FWRPZViewGeometry::makeMuonGeometryRhoZ( void )
00187 {
00188    TEveElementList* container = new TEveElementList( "MuonRhoZ" );
00189 
00190    {
00191       TEveCompound* dtContainer = new TEveCompound( "DT" );
00192       for( Int_t iWheel = -2; iWheel <= 2; ++iWheel )
00193       {
00194          for( Int_t iStation = 1; iStation <= 4; ++iStation )
00195          {
00196             float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
00197 
00198             // This will give us a quarter of DTs
00199             // which is enough for our projection
00200             for( Int_t iSector = 1; iSector <= 4; ++iSector )
00201             {
00202                DTChamberId id( iWheel, iStation, iSector );
00203                unsigned int rawid = id.rawId();
00204                FWGeometry::IdToInfoItr det = m_geom->find( rawid );
00205                estimateProjectionSizeDT( *det, min_rho, max_rho, min_z, max_z );
00206             }
00207             if ( min_rho > max_rho || min_z > max_z ) continue;
00208             TEveElement* se =  makeShape( min_rho, max_rho, min_z, max_z );
00209             addToCompound(se, kFWMuonBarrelLineColorIndex);
00210             dtContainer->AddElement(se);
00211             se =  makeShape( -max_rho, -min_rho, min_z, max_z );
00212             addToCompound(se, kFWMuonBarrelLineColorIndex);
00213             dtContainer->AddElement(se);
00214          }
00215       }
00216 
00217       container->AddElement( dtContainer );
00218    }
00219    {
00220       TEveCompound* cscContainer = new TEveCompound( "CSC" );
00221    
00222       Int_t maxChambers = 36;
00223       Int_t step = 9;
00224       Int_t iLayer = 0; // chamber
00225       for( Int_t iEndcap = 1; iEndcap <= 2; ++iEndcap ) // 1=forward (+Z), 2=backward(-Z)
00226       {
00227          // Actual CSC geometry:
00228          // Station 1 has 4 rings with 36 chambers in each
00229          // Station 2: ring 1 has 18 chambers, ring 2 has 36 chambers
00230          // Station 3: ring 1 has 18 chambers, ring 2 has 36 chambers
00231          // Station 4: ring 1 has 18 chambers
00232          for( Int_t iStation = 1; iStation <= 4; ++iStation )
00233          {
00234             for( Int_t iRing = 1; iRing <= 4; ++iRing )
00235             {
00236                if( iStation > 1 && iRing > 2 ) continue;
00237                if( iStation > 3 && iRing > 1 ) continue;
00238                float min_rho(1000), max_rho(0), min_z(2000), max_z(-2000);
00239                ( iRing == 1 && iStation > 1 ) ? ( maxChambers = 18 ) : ( maxChambers = 36 );
00240                ( iRing == 1 && iStation > 1 ) ? ( step = 5 ) : (  step = 18 );
00241             
00242                // Skip most of the chambers since they will project
00243                // the same way as the two top ones and the two bottom ones
00244                for( Int_t iChamber = step; iChamber <= maxChambers; iChamber += step )
00245                {
00246                   CSCDetId id( iEndcap, iStation, iRing, iChamber, iLayer );
00247                   FWGeometry::IdToInfoItr det = m_geom->find( id.rawId() );
00248                   estimateProjectionSizeCSC( *det, min_rho, max_rho, min_z, max_z );
00249 
00250                   // and a chamber next to it
00251                   ++iChamber;
00252                   CSCDetId nextid( iEndcap, iStation, iRing, iChamber, iLayer );
00253                   det = m_geom->find( nextid.rawId() );
00254                   estimateProjectionSizeCSC( *det, min_rho, max_rho, min_z, max_z );
00255                }
00256                if ( min_rho > max_rho || min_z > max_z ) continue;
00257 
00258                TEveElement* se = makeShape( min_rho, max_rho, min_z, max_z);
00259                addToCompound(se, kFWMuonEndcapLineColorIndex);
00260                cscContainer->AddElement(se);
00261 
00262                se = makeShape( -max_rho, -min_rho, min_z, max_z );
00263                addToCompound(se, kFWMuonEndcapLineColorIndex);
00264                cscContainer->AddElement(se);
00265             }
00266          }
00267       }
00268       container->AddElement( cscContainer );
00269    }
00270    return container;
00271 }
00272 
00273 //______________________________________________________________________________
00274 
00275 TEveGeoShape*
00276 FWRPZViewGeometry::makeShape( double min_rho, double max_rho, double min_z, double max_z)
00277 {
00278    TEveTrans t;
00279    t(1,1) = 1; t(1,2) = 0; t(1,3) = 0;
00280    t(2,1) = 0; t(2,2) = 1; t(2,3) = 0;
00281    t(3,1) = 0; t(3,2) = 0; t(3,3) = 1;
00282    t(1,4) = 0; t(2,4) = (min_rho+max_rho)/2; t(3,4) = (min_z+max_z)/2;
00283 
00284    TEveGeoShape* shape = new TEveGeoShape;
00285    shape->SetTransMatrix(t.Array());
00286 
00287    shape->SetRnrSelf(kTRUE);
00288    shape->SetRnrChildren(kTRUE);
00289    TGeoBBox* box = new TGeoBBox( 0, (max_rho-min_rho)/2, (max_z-min_z)/2 );
00290    shape->SetShape( box );
00291 
00292    return shape;
00293 }
00294 
00295 //______________________________________________________________________________
00296 
00297 void
00298 FWRPZViewGeometry::estimateProjectionSizeDT( const FWGeometry::GeomDetInfo& info,
00299                                              float& min_rho, float& max_rho, float& min_z, float& max_z )
00300 {
00301    // we will test 5 points on both sides ( +/- z)
00302    float local[3], global[3];
00303 
00304    float dX = info.shape[1];
00305    float dY = info.shape[2];
00306    float dZ = info.shape[3];
00307 
00308    local[0] = 0; local[1] = 0; local[2] = dZ;
00309    m_geom->localToGlobal( info, local, global );
00310    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00311 
00312    local[0] = dX; local[1] = dY; local[2] = dZ;
00313    m_geom->localToGlobal( info, local, global );
00314    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00315 
00316    local[0] = -dX; local[1] = dY; local[2] = dZ;
00317    m_geom->localToGlobal( info, local, global );
00318    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00319 
00320    local[0] = dX; local[1] = -dY; local[2] = dZ;
00321    m_geom->localToGlobal( info, local, global );
00322    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00323 
00324    local[0] = -dX; local[1] = -dY; local[2] = dZ;
00325    m_geom->localToGlobal( info, local, global );
00326    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00327 
00328    local[0] = 0; local[1] = 0; local[2] = -dZ;
00329    m_geom->localToGlobal( info, local, global );
00330    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00331 
00332    local[0] = dX; local[1] = dY; local[2] = -dZ;
00333    m_geom->localToGlobal( info, local, global );
00334    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00335 
00336    local[0] = -dX; local[1] = dY; local[2] = -dZ;
00337    m_geom->localToGlobal( info, local, global );
00338    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00339 
00340    local[0] = dX; local[1] = -dY; local[2] = -dZ;
00341    m_geom->localToGlobal( info, local, global );
00342    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00343 
00344    local[0] = -dX; local[1] = -dY; local[2] = -dZ;
00345    m_geom->localToGlobal( info, local, global );
00346    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00347 }
00348 
00349 void
00350 FWRPZViewGeometry::estimateProjectionSizeCSC( const FWGeometry::GeomDetInfo& info,
00351                                               float& min_rho, float& max_rho, float& min_z, float& max_z )
00352 {
00353    float local[3], global[3];
00354 
00355    float dX = info.shape[2] - info.shape[1];
00356    float dY = info.shape[4];
00357    float ddY = sqrt( 4 * dY * dY + dX * dX ) * 0.5;
00358    float dZ = info.shape[3];
00359    
00360    local[0] = info.shape[2]; local[1] = ddY; local[2] = -dZ;
00361    m_geom->localToGlobal( info, local, global );
00362    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00363 
00364    local[0] = info.shape[1]; local[1] = -ddY; local[2] = -dZ;
00365    m_geom->localToGlobal( info, local, global );
00366    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00367 
00368    local[0] = info.shape[1]; local[1] = -ddY; local[2] = dZ;
00369    m_geom->localToGlobal( info, local, global );
00370    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00371 
00372    local[0] = info.shape[2]; local[1] = ddY; local[2] = dZ;
00373    m_geom->localToGlobal( info, local, global );
00374    estimateProjectionSize( global, min_rho, max_rho, min_z, max_z );
00375 }
00376 
00377 void
00378 FWRPZViewGeometry::estimateProjectionSize( const float* global,
00379                                            float& min_rho, float& max_rho, float& min_z, float& max_z )
00380 {
00381    double rho = sqrt(global[0] *global[0]+global[1] *global[1]);
00382    if ( min_rho > rho ) min_rho = rho;
00383    if ( max_rho < rho ) max_rho = rho;
00384    if ( min_z > global[2] ) min_z = global[2];
00385    if ( max_z < global[2] ) max_z = global[2];
00386 }
00387 
00388 
00389 // ATODO:: check white vertex -> shouldn't be relative to background
00390 //         when detruction ?
00391 
00392 
00393 // ATODO why color is not set in 3D original, why cast to polygonsetprojected after projected ????
00394 // is geom color dynamic --- independent of projection manager
00395 
00396 // NOTE geomtry MuonRhoZAdanced renamed to  MuonRhoZ
00397 
00398