//----------------------------------------------------------- // File and Version Information: // $Id$ // // Description: // Implementation of class TpcPadPlane // see TpcPadPlane.h for details // // Environment: // Software developed for the PANDA Detector at FAIR. // // Author List: // Sebastian Neubert TUM (original author) // // //----------------------------------------------------------- // This Class' Header ------------------ #include "TpcPadPlane.h" // C/C++ Headers ---------------------- #include #include #include #include // Collaborating Class Headers -------- #include "TError.h" #include "TpcPadShapePool.h" // Class Member definitions ----------- class TpcAbsPadShape; TpcPadPlane::TpcPadPlane(int _nx, int _ny, double _xbin, double _ybin, double _x0, double _y0) : nx(_nx),ny(_ny),xbin(_xbin),ybin(_ybin),x0(_x0),y0(_y0), _nSectors(0), Indexer(_nx,_ny,_xbin,_ybin,_x0,_y0) { int nRegions=nx*ny; for(int iRegion=0; iRegion); } } TpcPadPlane::TpcPadPlane(const char* const filename, const TpcPadShapePool* const pspool) : Indexer(0,0,0.,0.,0.,0.) { //open file to construct Indexer std::ifstream infile(filename, std::fstream::in); Warning("TpcPadPlane::TpcPadPlane","Reading file..."); if (!infile.good()) Fatal("TpcPadPlane::TpcPadPlane","The file can not be found."); //search the file for the line describing the Indexer while (infile.good()) { char line[256]; infile.getline(line, 256); //cancel comments char* com=strchr(line, '*'); if (com != 0) *com = '\0'; //the line has to begin with "PadPlaneSubDivision" char* ppSub = strstr(line, "PadPlaneSubDivision"); if (ppSub == 0) continue; //reading the values ppSub = &(ppSub[strlen("PadPlaneSubDivision")]); char* rest; int _nx = (int) strtol(ppSub, &rest, 10); int _ny = (int) strtol(rest, &rest, 10); double _xbin = strtod(rest,&rest); double _ybin = strtod(rest,&rest); double _x0 = strtod(rest,&rest); char* end; double _y0 = strtod(rest,&end); if (rest == end)//It was impossible to read double _y0 Fatal("TpcPadPlane::TpcPadPlane","Too less arguments in input file."); //Create the Indexer and the regions (like in the simple constructor) Indexer.nx = nx =_nx; Indexer.ny = ny =_ny; Indexer.xbin = xbin =_xbin; Indexer.ybin = ybin =_ybin; Indexer.x0 = x0 =_x0; Indexer.y0 = y0 =_y0; int nRegions=nx*ny; for(int iRegion=0; iRegion); infile.unget();//if it was the last line=>eof=>without this !infile.good() break; } if (!infile.good())//e.g. eof Fatal("TpcPadPlane::TpcPadPlane","Error searching a line of the form:\n PadPlaneSubDivision int int double double double double \n Pad Plane can't be build."); infile.close(); ReadFromFile(filename, pspool); } // PadPlane Takes Ownership over Pads! TpcPadPlane::~TpcPadPlane(){ int n=PadReferences.size(); for(int i=0;i& buffer) const { for(int iy=-1; iy<=1; ++iy){ for(int ix=-1; ix<=1; ++ix){ double xin = x+ix*xbin; double yin = y+iy*ybin; if (xinnx*xbin+x0 || yinny*ybin+y0) continue; //Get Regions int iRegion=Indexer(xin,yin); int nPads=Regions[iRegion]->size(); for(int iPad=0; iPadCircleIntersection(x,y,r))buffer.push_back(aPad); } } } } void TpcPadPlane::GetPadXY(const unsigned int PadID, double& x, double& y) const { TpcPad* pad=GetPad(PadID); x=pad->x(); y=pad->y(); } TpcPad* TpcPadPlane::GetPad(const unsigned int PadID) const { if (PadID >= PadReferences.size()) throw unknown_padID(); TpcPad* pad=PadReferences[PadID]; if(pad==0)throw unknown_padID(); return(pad); } unsigned int TpcPadPlane::GetNPads() const { unsigned int np=0; for (unsigned int i=0; ipush_back(pad); _Sectors[pad->sectorId()].minx=std::min(_Sectors[pad->sectorId()].minx,pad->x()); _Sectors[pad->sectorId()].miny=std::min(_Sectors[pad->sectorId()].miny,pad->y()); _Sectors[pad->sectorId()].maxx=std::max(_Sectors[pad->sectorId()].maxx,pad->x()); _Sectors[pad->sectorId()].maxy=std::max(_Sectors[pad->sectorId()].maxy,pad->y()); // this assumes continually nummbered sectors: if(pad->sectorId()>=_nSectors)_nSectors=pad->sectorId()+1; } catch (std::exception& e) { std::cerr<<"Index="<id(); try { GetPad(ID); } catch (unknown_padID& e)//the desired case { if(PadReferences.size()<=ID)PadReferences.resize(ID+1,0); PadReferences[ID]=pad; if(_SectorLists[pad->sectorId()]==0)_SectorLists[pad->sectorId()]=new std::map; (*_SectorLists[pad->sectorId()])[pad->padId()]=pad; return; } //the padID is not unknown=> some other pad has this ID Regions.at(i)->pop_back(); throw used_padID(); } void TpcPadPlane::ReadFromFile(const char* const filename, const TpcPadShapePool* const pspool) { bool noproblem = true; std::ifstream infile(filename, std::fstream::in); Warning("TpcPadPlane::ReadFromFile","Reading file %s",filename); if (!infile.good()) Fatal("TpcPadPlane::ReadFromFile","The file %s can not be found.",filename); while (infile.good() && noproblem) { char line[256]; infile.getline(line, 256); noproblem = ReadLine(line, pspool); } if (!infile.eof()) Fatal("TpcPadPlane::ReadFromFile","The file %s can not be read.",filename); infile.close(); if (noproblem == false) Fatal("TpcPadPlane::ReadFromFile","The file %s does not correspond to the required format.",filename); } bool TpcPadPlane::ReadLine(const char* const line, const TpcPadShapePool* const pspool) { //remove comments at end of line char* com=strchr(line, '*');//comment if (com != 0) *com = '\0'; if (line[0] == '\0') return(true); //Is either read by the right constructor or ignored if (strstr(line, "PadPlaneSubDivision") != 0) return(true); char* rest; unsigned int ID; unsigned int sectorID; unsigned int shapeID; double x; double y; double angle; ID = (unsigned int) strtoul(line, &rest, 10); sectorID = (unsigned int) strtoul(rest, &rest, 10); shapeID = (unsigned int) strtoul(rest, &rest, 10); x = strtod(rest,&rest); y = strtod(rest,&rest); char* end; angle = strtod(rest,&end); if (rest == line)//No reading happened (e.g. only blanks) return(true); if (rest == end)//It was impossible to read angle { Warning("TpcPadPlane::ReadLine","In line: %i \n Too less arguments.",line); return(false); } TpcAbsPadShape* shape=pspool->GetPadShape(shapeID); if (shape == 0)//shapeId does not exist { Warning("TpcPadPlane::ReadLine","In line: %i \n There is no TpcPadShape with ID= %i",line,shapeID); return(false); } TpcPad* pad = new TpcPad(x, y, angle, shape, sectorID, ID); // read in neighbour ids if available char* end2; unsigned int nid= (unsigned int) strtoul(end, &end2, 10); while(end!=end2){ pad->addNeighbour(nid); end=end2; nid= (unsigned int) strtoul(end, &end2, 10); } try { AddPad(pad); } catch (std::exception& e) { Warning("TpcPadPlane::ReadLine","The pad from line: %i \ncould not be added.Reason: \n %s",line,e.what()); return(false); } return(true); } std::vector TpcPadPlane::GetSectorIds()const { std::map*>::const_iterator sIt=_SectorLists.begin(); std::vector ids; while(sIt!=_SectorLists.end()){ ids.push_back(sIt->first); ++sIt; } return ids; } // Operators std::ostream& operator<< (std::ostream& s, const TpcPadPlane& me){ return s << "TpcPadPlane:\n" << " nx="<("<