#ifndef TCDCGeom_hxx_seen #define TCDCGeom_hxx_seen #include #include #include #include #include #include "ICDCWireManager.hxx" #include "EoaGeomInfo.hxx" #include #include #include #include #include "IGeomBase.hxx" #include namespace COMET { OA_EXCEPTION(ENoCDC,EoaGeomInfo); class ICDCGeom; class ICDCGeomVisitor; class IGeomInfo; const int kMaxNumWires = 20000;// Maximum number of sense wires const int kMaxNumLayers = 20; // Maximum number of layers }; /// Summary of the CDC Geometry. This contains useful /// information about the CDC geometry which is derived from the ROOT /// TGeoManager geometry description of the CyDet. This must /// accessed through IGeomInfo::CDC(). ICDCGeom is a "singleton" object /// that is managed by the IGeomInfo class which really is a singleton. class COMET::ICDCGeom : public COMET::IGeomBase { friend class ICDCGeomVisitor; friend class IGeomInfo; public: ICDCGeom(); ~ICDCGeom(); void Clear(); // fill CDC geometry information void Fill(); void ls(const char* opt); /// Convert a global channel number into a wire number. /// This will return -1 if the channel is not in the CDC. int ChannelToWire(const int& channel) const { return fCDCWireManager->ChannelToWire(channel);} /// Get Geometry coordinates (layer and wire) from GeometryId int GeomIdToLayer(const COMET::IGeometryId& id) const; int GeomIdToWire(const COMET::IGeometryId& id) const; /// Get Cell Id from the GeometryId and position int GeomIdToCell(const COMET::IGeometryId& id) const; bool GetGeometryInfo(const COMET::IGeometryId& id, int& layer, int& wire) const; /// Convert from Geometry Id to GeoNode int GeomIdToNodeId(const COMET::IGeometryId& id) const; /// Convert from (GeoNode, Key) to IGeometryId bool ChannelToGeomId(int node, int channel, COMET::IGeometryId& id) const; /// Convert a global channel number into a module TGeoNode. /// This will return NULL if the channel is not in the CDC. TGeoNode* ChannelToModuleNode(const int& channel, int& node) const { return fCDCWireManager->ChannelToModuleNode(channel, node); } TGeoNode* GeomIdToModuleNode(const COMET::IGeometryId& id) const; /// Convert a global channel number into a global channel position. /// This will return false if the channel is not a CDC wire. /// Global position is defined as the center of wire position in global coordinate bool ChannelToGlobalPosition(const int& channel, TVector3& global) const { return fCDCWireManager->ChannelToGlobalPosition(channel,global); } bool GeomIdToGlobalPosition(const COMET::IGeometryId& id, TVector3& global) const; /// Convert a global position into a global channel number. /// This will return false if the channel is not a CDC wire. bool GlobalPositionToChannel(const TVector3& global, int& channel) const { return fCDCWireManager->GlobalPositionToChannel(global, channel);} bool GlobalPositionToGeomId(const TVector3& global, COMET::IGeometryId& id) const ; /// 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, const int& wire, TVector3& local) const { return fCDCWireManager->GetDistanceFromWire(global, wire, local); } /// Convert the wire position in relative to the CDC gas volume TVector3 GetWirePosition(const int& wire) const { if (wire>=0 && wireGetWirePosition(wire); else return TVector3(1e10,1e10,1e10); } /// Convert the wire end position in relative to the CDC gas volume TVector3 GetWireEnd0(const int& wire) const { if (wire>=0 && wireGetWireEnd0(wire); else return TVector3(1e10,1e10,1e10); } /// Convert the wire end position in relative to the CDC gas volume TVector3 GetWireEnd1(const int& wire) const { if (wire>=0 && wireGetWireEnd1(wire); else return TVector3(1e10,1e10,1e10); } /// Convert the wire number into a wire length double GetWireLength(const int& wire) const { if (wire >= 0 && wire < GetNumberOfWires()) return fCDCWireManager->GetWireLength(wire); else return 1e+10; } /// Convert a wire number to a layer int GetLayer(const int& wire) const { if(wire >= 0 && wire < GetNumberOfWires()) return fCDCWireManager->GetLayer(wire); else return -1; } /// Get the number of layers. int GetNumberOfLayers() const {return fCDCWireManager->GetNumberOfLayers();} /// Get the number of anode wires. int GetNumberOfWires() const {return fCDCWireManager->GetNumberOfWires();} /// Get number of wires in a layer int GetNumberOfWiresPerLayer(int layer) const {return fCDCWireManager->GetNumberOfWiresPerLayer(layer);} /// Get the list of wires in a layer bool GetWiresInLayer(const int& layer, std::vector& list); std::map > GetCDCWireVolumes(void) { return fCDCWireVolumes; } const TGeoNode *GetCDC(int id) { fCDCWireVolumes[id].second; return NULL; } const int GetCDCNodeID(unsigned int i) { if (i >= fCDCWireVolumes.size()) return -1; return fCDCWireVolumes[i].first; } const TGeoNode *SenseLayer(unsigned int i) { if(i >= fSenseLayers.size()) return NULL; return fSenseLayers[i].second; } const int SenseLayerNodeID(unsigned int i) { if(i >= fSenseLayers.size()) return -1; return fSenseLayers[i].first; } double GetSenseWireRadius(void) { double radius = 0.0; const TGeoNode* senseWire = SenseWire(0); radius = ((TGeoTube*) senseWire->GetVolume()->GetShape())->GetRmax(); return radius; } const TGeoNode *SenseWire(unsigned int i) { if(i >= fSenseWires.size()) return NULL; return fSenseWires[i].second; } const int SenseWireNodeID(unsigned int i) { if(i >= fSenseWires.size()) return -1; return fSenseWires[i].first; } const TGeoNode *FieldWire(unsigned int i) { if(i >= fFieldWires.size()) return NULL; return fFieldWires[i].second; } const int FieldWireNodeID(unsigned int i) { if(i >= fFieldWires.size()) return -1; return fFieldWires[i].first; } void BuildWireMap(); int GetCDCWireGeoNode(const int& cdc, const int& layer) const; private: COMET::ICDCWireManager *fCDCWireManager; double fWireDiameter; typedef std::map > IGeoNodeList_t; IGeoNodeList_t fCDCWireVolumes; /// List of TGeoNode for sense layers, int key is the size of this node (to be replaced to the layer Id) IGeoNodeList_t fSenseLayers; /// List of TGeoNode for sense wires, int key is the size of this node (to be replaced to the wire Id) IGeoNodeList_t fSenseWires; /// List of TGeoNode for field wires, int key is the size of this node (to be replaced to the wire Id) IGeoNodeList_t fFieldWires; std::vector < std::vector < int > > fWireMap; }; #endif