#ifndef TCDCWireManager_hxx #define TCDCWireManager_hxx #include "ICDCWireInfo.hxx" #include "ICDCGeom.hxx" #include #include #include class TGeoManager; class TGeoNode; namespace COMET { class ICDCWireManager; class IGeometryId; } /// Provide low level interfaces to the CDC sense wire geometry data base. /// The CDCWireManager interface is used by oaGeomInfo which provides a higher /// level (more friendly) interface. The low level interface is primarily /// used to store the CDC wire geometry inside of the event stream, or to /// interface to external data bases. /// /// Index Definitions: /// * Wire ID = [0,4481], an index running over all wires /// * Layer ID = [0, 19], an index running over all layers /// (including two guard layers) /// * Cell ID = [0, nWiresInLayer-1], an index running over each layer /// * Board ID = [0, 103], an index for each readout RECBE board /// * Channel ID (currently is the same as Wire ID, but this may change) /// /// The Information Stored: /// -# Layer Information /// * The number of layers /// * The number of wires /// * The first wire index in each layer /// * The total number of wires /// -# Wire Information (keyed by wire ID) /// * TGeoNode ID /// * Layer ID /// * Cell ID /// * Channel ID /// * RECBE board ID /// * Wire Length /// * Wire centre position /// * Wire end positions /// /// Interface between channel ID and geometry: /// -# Channel ID to TGeoNode* instance of corresponding wire /// -# Channel ID to global position /// -# Global coordinates to Channel ID /// /// All other information can be found using a combination of the methods /// provided by this class and the ROOT geometry manager. The oaGeomInfo /// library provides the user interface. /// class COMET::ICDCWireManager { public: ICDCWireManager(); ~ICDCWireManager(); /// @name Initializers /// Initialize the wire manager, plus helper functions /// /// @{ /// Initialise the wire configuration from the ROOT geometry and geometry id. /// This will return -1 if there are no CyDet geometry with CDC wires. int Init(const std::vector< std::vector< int > >& wiremap, int detSolNodeId, int innerMostLayerNodeId); /// Set the mapping from wireID to TGeoNode ID from the wiremap bool SetWireMap(const std::vector< std::vector< int > >& wiremap); /// Add the board ID information as set from the ROOT file void GetBoardMap(std::string rootFile, std::map >& boardMap); /// @} /// @name CDC Wire Array Information /// Get information about the whole CDC wire array /// /// @{ /// Get the number of layers. int GetNumberOfLayers() const {return fNumberOfLayers;} /// Get the number of sense wires. int GetNumberOfWires() const {return fNumberOfWires;} /// Get the number of sense wires in a layer. int GetNumberOfWiresPerLayer(int layer) const { return fWireToNodeId.at(layer).size();} /// Get the first wire index in a layer. int GetFirstWireIndexAt(int layer) const{ if (layer<0||layer>=(int)fFirstWireIndex.size()) return -1; return fFirstWireIndex.at(layer);} /// @} /// @name Wire Information /// Get wire information based on wire ID /// /// @{ /// Convert a wire number to a TGeoNode ID /// Returns -1 if wire is not valid int GetWireNode(int wire) const; /// Get cell Id just based on the wire number /// Returns -1 if wire is not valid int GetCellId(int wire) const; /// Convert a wire number to a layer. /// Returns -1 if wire is not valid int GetLayer(int wire) const; /// Convert a wire number to the connected RECBE board. /// This will return -1 if the wire is not a CDC wire int GetBoard(int wire) const; /// Get a length of wire from a wire number. /// This will return 1e9 if the channel is not CDC wire. double GetWireLength(int wire) const; /// Get a global position of wire from a wire number. /// This will return false if the channel is not CDC wire. TVector3 GetWirePosition(int wire) const; /// Get a global end0 position of wire from a wire number. /// This will return false if the channel is not CDC wire. TVector3 GetWireEnd0(int wire) const; /// Get a global end1 position of wire from a wire number. /// This will return false if the channel is not CDC wire. TVector3 GetWireEnd1(int wire) const; /// Get a global direction of wire from a wire number. ///This will return false if the channel is not CDC wire. TVector3 GetWireDirection(int wire) const; /// @} /// @name Index Conversion /// Convert from one type of geometrical index to another /// /// @{ /// Convert the layer and cell number to a wire number int GetWireId(int layer, int cellID) const{ return GetFirstWireIndexAt(layer) + cellID;} /// Convert a global channel number into a wire number. /// This will return -1 if the channel is not in the CDC. int ChannelToWire(int channel) const {return channel;} /// Convert a wire number to a global channel number. /// This will return -1 if the wire is not in the CDC. int WireToChannel(int wire) const {return wire;} /// @} /// @name Channel conversion /// Function to convert channel to position/geometry and vice versa /// /// @{ /// Convert a global channel number into a module TGeoNode. /// This will return NULL if the channel is not in the CDC. TGeoNode* ChannelToModuleNode(int channel) const; /// Convert a global channel number into a global channel position. /// This will return false if the channel is not a CDC wire. bool ChannelToGlobalPosition(int channel, TVector3& global) const; /// Convert a global position into a global channel number. /// This will return false if the channel is not a CDC wire. COMET::ECDCHitVolume GlobalPositionToChannel(const TVector3& global, int& channel) const; /// Convert a local position into a global channel number. /// This will return false if the channel is not a CDC wire. bool LocalPositionToChannel(const TVector3& local, int layer, int& channel) const; /// @} /// @name Distance Information /// Getters to do with channel ID and distance /// /// @{ /// Convert a global position into a local position at a wire. /// This will return false if the wire number is invalid or local position is too far from a wire. bool GetDistanceFromWire(const TVector3& global, int wire, TVector3& local) const; /// Convert a distance from a wire into global position /// This will return false if the wire number is invalid or local position is too far from a wire bool GetGlobalFromWireDistance(const TVector3& local, int wire, TVector3& global) const; /// Get a local xy position of wire from a wire number. /// This will return false if the channel is not CDC wire. bool GetWirePositionXY(int wire, double zpos, TVector2& xypos) const; /// Get a wire Id from a layer number and a local position. /// This will return -1 if the cell is not inside the CDC. int GetWireNumber(int layer, const TVector3& local) const; /// Get poca on wire, poca on track from a given hit segment (prePoint and postPoint) bool CalcSegToWire(const TVector3& pre, const TVector3& post, int wire, TVector3& pocaW, TVector3& pocaT, int & lr) const; /// @} private: /// Make the copy constructor private. ICDCWireManager(const ICDCWireManager&) {MayNotUse("Copy Constructor");} /// Access the full wire information by wire index const COMET::ICDCWireInfo* GetWireInfo (int wire) const; /// Number of layers in the CDC int fNumberOfLayers; /// Number of sense wires in the CDC int fNumberOfWires; /// Wire index of the first wire in each layer std::vector fFirstWireIndex; /// Mapping from layer ID, cell ID to TGeoNode ID for all wires std::vector > fWireToNodeId; /// Mapping from wire ID to full wire information std::map fWireInfoMap; /// node id of CyDet int fInnerMostLayerNodeId; /// Is the a single cydet world? bool fIsSingleCyDet; }; #endif