#ifndef TECALGeom_hxx_seen #define TECALGeom_hxx_seen #include #include #include #include #include #include #include #include #include "IGeomBase.hxx" #include #include class TVector3; class TGeoNode; namespace COMET { OA_EXCEPTION(ENoECAL,EoaGeomInfo); class IECALGeom; class IECALGeomVisitor; class IGeomInfo; } /// Summary of the ECAL Geometry. /** * This contains useful * information about the ECAL geometry which is derived from the ROOT * TGeoManager geometry description of the CyDet. This must * accessed through IGeomInfo::ECAL(). IECALGeom is a "singleton" object * that is managed by the IGeomInfo class which really is a singleton. */ class COMET::IECALGeom : public COMET::IGeomBase { friend class IECALGeomVisitor; private: int fECALNodeId; COMET::IECALCrystalManager *fECALCrystalManager; double fCrystalWidth; double fCrystalLength; double fBlockWidth; double fBlockLength; int fNumberOfBlocks; int fNumberOfCrystals; std::vector fNodeId; COMET::IECALCrystalManager::INodeIdMap fNodeIdMap; public: IECALGeom(); ~IECALGeom(); /// Fill ECAL geometry information void Fill(); /// Clear ECAL geometry information void Clear(); /// Printout geometry information void ls(const char* opt); /// Similar with IGeomIdManager::GetGeometryId(), but adittionally special care is taken for ECAL bool GetGeomIdFromGlobalPosition(const TVector3& global, IGeometryId& id) const { return fECALCrystalManager->GetGeomIdFromGlobalPosition(global, id); } /// Similar with IGeomIdManager::GetGeometryId(), but adittionally special care is taken for ECAL bool GetGeomIdFromGlobalPosition(const double* global, IGeometryId& id) const { return fECALCrystalManager->GetGeomIdFromGlobalPosition(global, id); } /// Get geometry Id corresponding to the sequence Id bool GetGeomIdFromSequenceId(const int sequenceId, IGeometryId& id) const { return fECALCrystalManager->GetGeomIdFromSequenceId(sequenceId, id); } /// Get Geometry information from oaEvent/src/IECALCrystalManager.[hxx, cxx] in which wire information are stored int GetSequenceIdFromECAL(const int block, const int crystal) const { if ( (block >=0 && block < GetNumberOfBlocks() ) && (crystal >=0 && crystal < GetNumberOfCrystals()) ) return fECALCrystalManager->GetSequenceIdFromECAL(block, crystal); else return -1; } int GetSequenceIdFromGlobalPosition(const TVector3& global) const { return fECALCrystalManager->GetSequenceIdFromGlobalPosition(global); } int GetSequenceIdFromGlobalPosition(const double* global) const { double tglob[3] = {global[0], global[1], global[2]}; return fECALCrystalManager->GetSequenceIdFromGlobalPosition(tglob); } int GetSequenceIdFromNodeId(const int nodeId) const { return fECALCrystalManager->GetSequenceIdFromNodeId(nodeId); } int GetSequenceIdFromChannelId(const COMET::IChannelId& chanId) const { return fECALCrystalManager->GetSequenceIdFromChannelId(chanId); } int GetSequenceIdFromGeometryId(const COMET::IGeometryId& geomId) const { return fECALCrystalManager->GetSequenceIdFromGeomId(geomId); } int GetBlockIdFromSequenceId(const int sequenceId) const { return fECALCrystalManager->GetBlockIdFromSequenceId(sequenceId); } int GetCrystalIdFromSequenceId(const int sequenceId) const { return fECALCrystalManager->GetCrystalIdFromSequenceId(sequenceId); } TGeoNode *GetNode(const int block, const int crystal) const { return fECALCrystalManager->GetNode(block, crystal); } TVector3 GetCrystalPosition(const int sequenceId) const { if (0 <= sequenceId && sequenceId < GetNumberOfChannels()) return fECALCrystalManager->GetCrystalPosition(sequenceId); else return TVector3(1e10,1e10,1e10); } TVector3 GetCrystalPosition(const IGeometryId& id) const { return fECALCrystalManager->GetCrystalPosition(id); } TVector3 GetCrystalPosition(const int block, const int crystal) const { if ( (block >=0 && block < GetNumberOfBlocks() ) && (crystal >=0 && crystal < GetNumberOfCrystals()) ) return fECALCrystalManager->GetCrystalPosition(block, crystal); else return TVector3(1e10,1e10,1e10); } int GetBlockIdFromGeomId(const COMET::IGeometryId& id) const { return fECALCrystalManager->GetBlockIdFromGeomId(id); } int GetCrystalIdFromGeomId(const COMET::IGeometryId& id) const { return fECALCrystalManager->GetCrystalIdFromGeomId(id); } template COMET::IECALCrystalMap CreateCrystalMapWith(T* initValue = NULL) const { return fECALCrystalManager->GetCrystalInfoMap().CreateMapWith(initValue); } template COMET::IECALCrystalMap CreateBlockMapWith(T* initValue = NULL) const { return fECALCrystalManager->GetCrystalInfoMap().CreateBlockMapWith(initValue); } double GetCrystalWidth() const {return fCrystalWidth;} double GetCrystalLength() const {return fCrystalLength;} double GetBlockWidth() const {return fBlockWidth;} double GetBlockLength() const {return fBlockLength;} int GetNumberOfChannels() const {return fECALCrystalManager->GetNumberOfChannels();} int GetNumberOfBlocks() const {return fECALCrystalManager->GetNumberOfBlocks();} int GetNumberOfCrystals() const {return fECALCrystalManager->GetNumberOfCrystals();} void BuildNodeIdMap(); /// Convert the global position into relative position in ECAL coordinate. /// This will return false if ECAL doesn't exist. bool MasterToECALLocal(const TVector3& global, TVector3& local) const; /// Convert the local position in ECAL coordinate into the global position. /// This will return false if ECAL doesn't exist. bool ECALLocalToMaster(const TVector3& local, TVector3& global) const; /// Project the global position on the ECAL plane /// This will return false if ECAL doesn't exist. bool ProjectOnECALPlane(const TVector3& global, TVector3& pos) const; /// Construct block number map COMET::IECALCrystalMap ConstructBlockMap() const; }; // ------------------------------------------------------------------------------------- /// For information see the discription of the base class 'IGeomVisitor' class COMET::IECALGeomVisitor : public COMET::IGeomVisitor { private: COMET::IECALGeom* fECALGeom; public: explicit IECALGeomVisitor(COMET::IECALGeom* geom) { fECALGeom = geom; } bool VisitNode(int depth, const std::string& name, const TGeoNode* node); }; #endif