CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/Fireworks/Core/interface/FWGeometry.h

Go to the documentation of this file.
00001 #ifndef Fireworks_Core_FWGeometry_h
00002 #define Fireworks_Core_FWGeometry_h
00003 //
00004 //  Description: service class that implements access to geometry of a given DetId
00005 //
00006 //  Primary usage: raw detector id to full transformation matrix mapping
00007 //
00008 //  Original Author: D.Kovalskyi
00009 //
00010 class TEveGeoShape;
00011 class TGeoVolume;
00012 class TGeoShape;
00013 class TFile;
00014 
00015 #include "TEveVSDStructs.h"
00016 #include "TGeoMatrix.h"
00017 
00018 #include "Fireworks/Core/interface/FWRecoGeom.h"
00019 
00020 #include <map>
00021 #include <vector>
00022 
00023 class FWGeometry
00024 {
00025 public:
00026    static const int kDetOffset          = 28;
00027    static const int kSubdetOffset       = 25;
00028 
00029    enum Detector { Tracker = 1, Muon = 2, Ecal = 3, Hcal = 4, Calo = 5 };
00030    enum SubDetector { PixelBarrel = 1, PixelEndcap = 2, TIB = 3, TID = 4, TOB = 5, TEC = 6, CSC = 7, DT = 8, RPCBarrel = 9, RPCEndcap = 10 };
00031 
00032    struct Range {
00033       double min1;
00034       double max1;
00035       double min2;
00036       double max2;
00037       Range( void ) : min1( 9999 ), max1( -9999 ), min2( 9999 ), max2( -9999 ) {
00038       }
00039    };
00040 
00041    FWGeometry( void );
00042 
00043    ~FWGeometry( void );
00044 
00045    // load DetId to RecoGeomInfo map
00046    void loadMap( const char* fileName );
00047 
00048    void initMap( const FWRecoGeom::InfoMap& map );
00049 
00050    // get matrix for full local to global transformation
00051    const TGeoMatrix* getMatrix( unsigned int id ) const;
00052 
00053    static TFile* findFile( const char* fileName );
00054 
00055    // extract locally positioned shape for stand alone use
00056    TGeoShape* getShape( unsigned int id ) const;
00057   
00058    // extract globally positioned shape for stand alone use
00059    TEveGeoShape* getEveShape( unsigned int id  ) const;
00060   
00061    // get shape description parameters
00062    const float* getShapePars( unsigned int id  ) const;
00063 
00064    // get all known detector ids with id matching mask
00065    std::vector<unsigned int> getMatchedIds( Detector det, SubDetector subdet ) const;
00066 
00067    // get reco geometry
00068    const float* getCorners( unsigned int id ) const;
00069 
00070    // get reco topology/parameters
00071    const float* getParameters( unsigned int id ) const;
00072 
00073    void localToGlobal( unsigned int id, const float* local, float* global ) const;
00074    void localToGlobal( unsigned int id, const float* local1, float* global1, const float* local2, float* global2 ) const;
00075 
00076    struct GeomDetInfo
00077    {
00078       unsigned int id;
00079       float points[24];
00080       float parameters[9];
00081       float shape[5];
00082       float translation[3];
00083       float matrix[9];
00084      
00085       bool operator< ( unsigned int id ) const { 
00086          return ( this->id < id );
00087       }
00088    };
00089   
00090    bool match_id( const GeomDetInfo& o, unsigned int mask ) const {
00091      unsigned int id = o.id;
00092      return ((((( id >> kDetOffset ) & 0xF ) << 4) | (( id >> kSubdetOffset ) & 0x7 )) == mask );
00093    }
00094   
00095    typedef std::vector<FWGeometry::GeomDetInfo> IdToInfo;
00096    typedef std::vector<FWGeometry::GeomDetInfo>::const_iterator IdToInfoItr;
00097 
00098    bool contains( unsigned int id ) const {
00099      return FWGeometry::find( id ) != m_idToInfo.end();
00100    }
00101 
00102    void clear( void ) { m_idToInfo.clear(); m_idToMatrix.clear(); }
00103    IdToInfoItr find( unsigned int ) const;
00104    void localToGlobal( const GeomDetInfo& info, const float* local, float* global ) const;
00105  
00106 private:
00107    mutable std::map<unsigned int, TGeoMatrix*> m_idToMatrix;
00108 
00109    IdToInfo m_idToInfo;
00110 
00111    TGeoShape* getShape( const GeomDetInfo& info ) const;
00112 };
00113 
00114 #endif
00115