1 #include "gearimpl/FixedPadAngleDiskLayout.h"
23 for(
unsigned i=0; i<_padIndices.size(); ++i ){
24 delete _padIndices[i] ;
29 double phiMin,
double phiMax,
int nPadsInRow )
35 _nPadsInRow( nPadsInRow )
38 _rowHeight = ( rMax - rMin ) / _nRow ;
39 _padAngle = (phiMax - phiMin) / nPadsInRow;
76 _padIndices.resize( nRow ) ;
80 for (std::vector< std::vector<int>* >::iterator rowIter = _padIndices.begin() ;
81 rowIter < _padIndices.end(); rowIter++)
87 _nPad = nRow * nPadsInRow ;
124 _padAngle = right._padAngle;
128 _rowHeight = right._rowHeight;
129 _phiMin = right._phiMin;
130 _phiMax = right._phiMax;
133 _nPadsInRow = right._nPadsInRow;
135 _extent = right._extent;
141 _padIndices.resize( _nRow ) ;
142 for (std::vector< std::vector<int>* >::iterator rowIter = _padIndices.begin() ;
143 rowIter < _padIndices.end(); rowIter++)
156 double r = (
static_cast<double>(rowNum)+0.5) * _rowHeight + _rMin;
158 double phi = (
static_cast<double>(padNum) + 0.5 ) * _padAngle + _phiMin ;
165 static std::vector<int> empty ;
168 if( _padIndices.at(rowNumber ) == 0 )
170 _padIndices[ rowNumber ] =
new std::vector<int>( _nPadsInRow ) ;
172 for(
int i = 0 ; i < _nPadsInRow ; i++)
174 _padIndices[rowNumber]->operator[](i) =
getPadIndex( rowNumber , i ) ;
178 }
catch( std::out_of_range& r) {
185 return *_padIndices[ rowNumber ] ;
191 if( rowNum > _nRow - 1 )
193 throw std::out_of_range(
" FixedPadAngleDiskLayout::getPadIndex row number too large !");
196 if( padNum > _nPadsInRow - 1 ) {
198 std::stringstream sstr ;
200 sstr <<
"FixedPadAngleDiskLayout::getPadIndex: pad number too large: "
201 << padNum <<
", only " << _nPadsInRow <<
" pads in row " << rowNum ;
203 throw std::out_of_range( sstr.str() );
206 return (rowNum << 16 ) | ( 0x0000ffff & padNum ) ;
215 throw std::out_of_range(
"FixedPadAngleDiskLayout::getNearestPad: radius must not be negative in polar coordinates!" );
217 double phiMean = (_phiMax+_phiMin)/2.;
220 while( phi < phiMean-M_PI ) { phi += 2. * M_PI ; }
221 while( phi > phiMean+M_PI ) { phi -= 2. * M_PI ; }
223 if ( (phi <= _phiMax) && (phi >= _phiMin) )
226 int padNumber =
static_cast<int>( (phi - _phiMin) / _padAngle );
228 int rowNum = r < _rMin ? 0 : (int) std::floor( ( r - _rMin ) / _rowHeight ) ;
230 if( rowNum >= _nRow )
237 if (fabs(phi - _phiMin) > M_PI_2)
253 double r_intersect_min = r * (cos(phi)*cos(_phiMin) + sin(phi)*sin(_phiMin));
257 rowNum_right = r_intersect_min < _rMin ? 0 : (int) std::floor( ( r - _rMin ) / _rowHeight ) ;
258 if( rowNum_right >= _nRow )
259 rowNum_right = _nRow -1 ;
264 if (fabs(phi - _phiMax) > M_PI_2)
270 double r_intersect_max = r * (cos(phi)*cos(_phiMax) + sin(phi)*sin(_phiMax));
274 rowNum_left = r_intersect_max < _rMin ? 0 : (int) std::floor( ( r - _rMin ) / _rowHeight ) ;
275 if( rowNum_left >= _nRow )
276 rowNum_left = _nRow -1 ;
282 return (distance_right < distance_left ?
getPadIndex( rowNum_right , 0 ) :
getPadIndex( rowNum_left , _nPadsInRow - 1 ) );
296 if (fabs(_phiMax - _phiMin - 2*M_PI) < 1e-6 )
297 pn = _nPadsInRow - 1;
299 throw Exception(
"FixedPadAngleDiskLayout::getRightNeighbour: no right neighbour pad !");
312 if (pn == _nPadsInRow)
315 if (fabs(_phiMax - _phiMin - 2*M_PI) < 1e-6 )
318 throw Exception(
"FixedPadAngleDiskLayout::getLeftNeighbour: no left neighbour pad !");
336 if( (r < padCenter[0] - _rowHeight/2.) || (r > padCenter[0] + _rowHeight/2.) ||
337 (phi < padCenter[1]- _padAngle/2.) || (phi > padCenter[1]+_padAngle/2. ) )
345 if( (r < _rMin) || (r > _rMax) || (phi < _phiMin) || (phi > _phiMax) )
virtual int getNearestPad(double c0, double c1) const
The index of the pad nearest to the given point in 2d coordinates (r, phi).
virtual Vector2D getPadCenter(int padIndex) const
The center of the pad in 2d coordinates (r,phi).
virtual ~FixedPadAngleDiskLayout()
Destructor.
Abstract description of a planar subdetector with pads (cells) that are positioned in rows (circular ...
Base exception class for GEAR - all other exceptions extend this.
virtual int getRightNeighbour(int padIndex) const
The index of the right neighbour pad.
virtual double getDistanceToPad(double c0, double c1, int padIndex) const
Returns the closest distance to the edge (outer border) of the pad.
Implementation of PadRowLayout2D for a disk with fixed angled keystone pads.
FixedPadAngleDiskLayout & operator=(const FixedPadAngleDiskLayout &)
The assignment operator.
virtual int getLeftNeighbour(int padIndex) const
The index of the left neighbour pad.
virtual bool isInsidePad(double c0, double c1, int padIndex) const
True if coordinate (c0,c1) is within the given pad.
void copy_and_assign(const FixedPadAngleDiskLayout &)
Function to copy all internal variables, incl. the objects pointed to and owned by the FixedPadAngleD...
FixedPadAngleDiskLayout(double rMin, double rMax, int nRow, double phiMin, double phiMax, int nPadsInRow)
Construct the FixedPadAngleDiskLayout from the given parameters rMin, rMax, nRow, phiMin...
virtual int getPadIndex(int rowNum, int padNum) const
Create a padIndex for the given row and pad ( column ) number.
virtual int getRowNumber(int padIndex) const
The number of the row that contains the pad at padIndex.
PadRowLayout2D * clone() const
Returns a copy (clone) of this class.
virtual const std::vector< int > & getPadsInRow(int rowNumber) const
Indices of all pads in row rowNumber (row indices start at rMin).
virtual int getPadNumber(int padIndex) const
The pad number (column) within the row.
void cleanup()
Function to delete all the objects pointed to and owned by the FixedPadAngleDiskLayout.