#include #include #include #include #include #include #include #include #include "IGeomVisitor.hxx" #include "ICTHGeom.hxx" #include #include #include #include #include namespace COMET { /// For information see the discription of the base class 'IGeomVisitor' class ICTHGeomVisitor: public COMET::IGeomVisitor { public: explicit ICTHGeomVisitor(COMET::ICTHGeom* geom) { fCTHGeom = geom; } bool VisitNode(int d, const std::string& name, const TGeoNode* node); COMET::ICTHGeom::IGeoNodeList_t fCounters; /// List of TGeoNode for all counters, /// int key is the size of this node /// (to be replaced to the counter Id) private: COMET::ICTHGeom* fCTHGeom; }; }; bool COMET::ICTHGeomVisitor::VisitNode(int, const std::string& name, const TGeoNode* node) { //COMETLog("COMET::ICTHGeomVisitor::VisitNode, visiting :" << name); /// If the node isn't in the CyDet, skip this node. if (name.find("/CylindricalDetector") == std::string::npos) return true; int nodeId = -1; int index = -1; gGeoManager->cd(name.c_str()); nodeId = gGeoManager->GetCurrentNodeId(); std::pair tmp(nodeId,node); index = fCounters.size(); if ( name.find(fCTHGeom->GetComponentType(0).Data()) != std::string::npos ) { // US Cherenkov fCTHGeom->fNumberOfCherenUS++; fCTHGeom->fNumberOfCounters++; fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(1).Data()) != std::string::npos ) { // DS Cherenkov fCTHGeom->fNumberOfCherenDS++; fCTHGeom->fNumberOfCounters++; fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(2).Data()) != std::string::npos ) { // US Scintillator fCTHGeom->fNumberOfScintUS++; fCTHGeom->fNumberOfCounters++; fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(3).Data()) != std::string::npos ) { // DS Scintillator fCTHGeom->fNumberOfScintDS++; fCTHGeom->fNumberOfCounters++; fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(4).Data()) != std::string::npos ) { // US Cherenkov fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(5).Data()) != std::string::npos ) { // DS Cherenkov fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(6).Data()) != std::string::npos ) { // DS Scintillator fCounters[index] = tmp; } else if ( name.find(fCTHGeom->GetComponentType(7).Data()) != std::string::npos ) { // DS Scintillator fCounters[index] = tmp; } return true; } COMET::ICTHGeom::ICTHGeom() :IGeomBase() ,fNumberOfCounters(0) ,fNumberOfModules(2) ,fNumberOfSegments(0) ,fNumberOfLayers(2) ,fNumberOfScintUS(0) ,fNumberOfScintDS(0) ,fNumberOfCherenUS(0) ,fNumberOfCherenDS(0) { COMETNamedTrace("ICTHGeom","ICTHGeom()"); fCounterMap.clear(); fComponentType.resize(8); fComponentType.at(0) = "CherenkovUS_pv_0"; fComponentType.at(1) = "CherenkovDS_pv_0"; fComponentType.at(2) = "ScintillatorUS_pv_0"; fComponentType.at(3) = "ScintillatorDS_pv_0"; fComponentType.at(4) = "CherenkovLightGuideUS_pv_1"; fComponentType.at(5) = "CherenkovLightGuideDS_pv_1"; fComponentType.at(6) = "ScintLightGuideUS_pv_1"; fComponentType.at(7) = "ScintLightGuideDS_pv_1"; } COMET::ICTHGeom::~ICTHGeom() { Clear(); } void COMET::ICTHGeom::Fill() { COMETNamedTrace("ICTHGeom","Fill()"); ICTHGeomVisitor visitor(this); visitor.VisitGeometry(); fCounters = visitor.fCounters; /// all of them should be the same, but in case of future possibilities.. fNumberOfSegments = std::max(fNumberOfScintUS, fNumberOfCherenUS); fNumberOfSegments = std::max(fNumberOfScintDS, fNumberOfSegments); fNumberOfSegments = std::max(fNumberOfCherenDS,fNumberOfSegments); COMETNamedTrace("ICTHGeom","CTH Geometry info\n" "Number of modules = " << GetNumberOfModules() <<", " "Number of types = " << GetNumberOfLayers() <<", " "Number of segments = " << GetNumberOfSegments()); BuildGeomMap(); } void COMET::ICTHGeom::ls(const char *opt) { COMETInfo( "// --------------------------------------------------------------------- "); COMETInfo( "// CTH geometry "); COMETInfo( "// --------------------------------------------------------------------- "); COMETInfo( "// Number of Modules = " << GetNumberOfModules()); /// 2 COMETInfo( "// Number of Layers = " << GetNumberOfLayers()); /// 2 COMETInfo( "// Number of Segments = " << GetNumberOfSegments()); COMETInfo( "// --------------------------------------------------------------------- "); if ( strcmp(opt,"VERBOSE") ) return ; } void COMET::ICTHGeom::Clear(void) { std::vector::iterator modules_it = fModules.begin(); std::vector::iterator modules_end = fModules.end(); for ( ; modules_it != modules_end; ++modules_it) { if (*modules_it) delete (*modules_it); } fModules.clear(); } bool COMET::ICTHGeom::ChannelToGeomId(int channel, COMET::IGeometryId& id) const { int counter = ChannelToCounterId(channel); int module = GetModuleId(counter); int segId = GetSegmentId(counter); int scint = GetLayerType(counter); int lightGuide = 0; /// never assign channel to light guide separately id = COMET::GeomId::CTH::Counter(module, segId, scint, lightGuide); return id.IsValid(); } TGeoNode* COMET::ICTHGeom::CounterToNode(int counter) const { if (counter<0) return NULL; int nodeId = GetCounterNodeId(counter); if(nodeId<0) return NULL; std::string name = ""; TGeoNode * node = COMET::IOADatabase::Get().GeomId().GetNode(nodeId); if (node) { name = node->GetName(); } else { COMETWarn("Cannot find TGeoNode for counter: "<GetName(); int counter(-1); bool found=false; // Find counter ID from name int seg_id = std::stoi(name.substr(name.find_last_of('_')+1)); // Find the component type for(unsigned int icmp=0;icmp used(2*fNumberOfCounters,false); int counter(-1); fCounterMap.resize(2*fNumberOfCounters,-1); for(it = nodes.begin(); it != nodes.end(); it++){ int node_id = (*it).second.first; std::string path = COMET::IOADatabase::Get().GeomId().FullNodePath(node_id); if (path.find("Scint") == std::string::npos && path.find("Cherenkov") == std::string::npos) continue; // Find the segment ID from the full node path int seg_id = std::stoi(path.substr(path.find_last_of('_')+1)); // Find the type of component for(unsigned int icmp=0;icmp " << node_id); used[counter] = true; break; } } } }