1 #include "gearimpl/FixedPadSizeDiskLayout.h"
23 for(
unsigned i=0; i<_padIndices.size(); ++i ){
24 delete _padIndices[i] ;
29 double padHeight,
double padWidth,
36 _padWidth( padWidth ) ,
37 _padHeight(padHeight) ,
42 if ( _padHeight <= 0.0 || _padWidth <= 0.0 ) {
45 s <<
" FixedPadSizeDiskLayout: missing or inconsistent parameters"
46 <<
" - padHeight: " << _padHeight
47 <<
" - padWidth : " << _padWidth ;
54 while( _phiMax < -2.*M_PI ) { _phiMax += 2. * M_PI ; }
55 while( _phiMax > 2.*M_PI ) { _phiMax -= 2. * M_PI ; }
62 _extent[3] = _phiMax ;
68 int nr = ( ( rMax + 0.01 - rMin ) / _padHeight ) ;
70 _nRow = ( nRow > 0 ) ? nRow : nr ;
74 std::cout <<
" WARNING: FixedPadSizeDiskLayout() : cannot place " << nRow
75 <<
" rows of height " << _padHeight
76 <<
" mm between rMin = " << rMin <<
" mm and rMax = " << rMax
77 <<
" mm - will use nRow = " << nr <<
" !! "
85 _padIndices.resize( _nRow ) ;
89 for (std::vector< std::vector<int>* >::iterator rowIter = _padIndices.begin() ;
90 rowIter < _padIndices.end(); rowIter++)
95 _rowHeight = ( rMax - rMin ) / _nRow ;
99 for(
int i = 0 ; i < _nRow ; i++ ) {
103 row.RCenter = rMin + ( i * _rowHeight ) + .5 * _rowHeight ;
105 double u = row.RCenter * _phiMax ;
107 row.NPad =
static_cast<int>( std::floor( u / (_padWidth + padGap ) ) );
109 row.PhiPad = _phiMax / row.NPad ;
116 _rows.push_back( row ) ;
137 _phiMax = right._phiMax;
138 _rowHeight = right._rowHeight;
139 _padWidth = right._padWidth;
140 _padHeight = right._padHeight;
141 _padGap = right._padGap;
145 _extent = right._extent;
151 _padIndices.resize( _nRow ) ;
152 for (std::vector< std::vector<int>* >::iterator rowIter = _padIndices.begin() ;
153 rowIter < _padIndices.end(); rowIter++)
162 return _rows.size() ;
173 return _padWidth / _rows.at( rowNum ).RCenter ;
176 catch(std::out_of_range){
188 return _rows.at( rowNum ).PhiPad;
191 catch(std::out_of_range){
203 double r = _rows[ rowNum ].RCenter ;
205 double phi = ( padNum + 0.5 ) * _rows[ rowNum ].PhiPad ;
213 static std::vector<int> empty ;
215 if( _padIndices.at(rowNumber ) == 0 ) {
217 int nPad = _rows.at(rowNumber).NPad ;
219 _padIndices[ rowNumber ] =
new std::vector<int>( nPad ) ;
221 for(
int i = 0 ; i < nPad ; i++){
223 _padIndices[rowNumber]->operator[](i) =
getPadIndex( rowNumber , i ) ;
227 }
catch( std::out_of_range& r) {
234 return *_padIndices[ rowNumber ] ;
240 if( (
unsigned) rowNum > _rows.size() - 1 ) {
242 throw std::out_of_range(
" FixedPadSizeDiskLayout::getPadIndex row number too large !");
245 if( padNum > _rows[rowNum].NPad - 1 ) {
247 std::stringstream sstr ;
249 sstr <<
"FixedPadSizeDiskLayout::getPadIndex: pad number too large: "
250 << padNum <<
" only " << _rows[rowNum].NPad <<
" pads in row " << rowNum ;
252 throw std::out_of_range( sstr.str() );
255 return (rowNum << 16 ) | ( 0x0000ffff & padNum ) ;
263 throw Exception(
"FixedPadSizeDiskLayout::getNearestPad: r can't be zero !");
267 double rProjectedOnPhiMax = r;
268 double rProjectedOnPhiMin = r;
270 if (fabs(_phiMax - 2*M_PI) < 1e-6) {
273 while( phi < 0 ) { phi += 2. * M_PI ; }
274 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
278 while( phi < -2*M_PI ) { phi += 2. * M_PI ; }
279 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
281 rProjectedOnPhiMax = r * cos(phi - _phiMax);
282 rProjectedOnPhiMin = r * cos(phi - 0.);
298 if ( r > 0. && phi >= 0. && phi <= _phiMax) {
299 rowNum = r < _rMin ? 0 : (int) std::floor( ( r - _rMin ) / _rowHeight ) ;
301 if( rowNum >= _nRow )
304 padNum = (int) std::floor( phi / _rows[ rowNum ].PhiPad ) ;
306 if( padNum >= _rows[ rowNum ].NPad )
307 padNum = _rows[ rowNum ].NPad - 1 ;
322 else if ( rProjectedOnPhiMin < _rMin && phi < 0 ) {
329 else if ( rProjectedOnPhiMin > _rMax && phi < 0 ) {
336 else if ( rProjectedOnPhiMax < _rMin && phi > _phiMax ) {
340 padNum = _rows[ rowNum ].NPad - 1 ;
343 else if ( rProjectedOnPhiMax > _rMax && phi > _phiMax ) {
347 padNum = _rows[ rowNum ].NPad - 1 ;
350 else if ( rProjectedOnPhiMin >= _rMin && rProjectedOnPhiMin <= _rMax && phi < 0 ) {
353 r = rProjectedOnPhiMin;
355 rowNum = (int) std::floor( ( r - _rMin ) / _rowHeight ) ;
357 rowNum = rowNum < 0 ? 0 : rowNum;
358 rowNum = rowNum >= _nRow ? _nRow -1 : rowNum;
363 else if ( rProjectedOnPhiMax >= _rMin && rProjectedOnPhiMax <= _rMax && phi > _phiMax ) {
366 r = rProjectedOnPhiMax;
368 rowNum = (int) std::floor( ( r - _rMin ) / _rowHeight ) ;
370 rowNum = rowNum < 0 ? 0 : rowNum;
371 rowNum = rowNum >= _nRow ? _nRow -1 : rowNum;
373 padNum = _rows[ rowNum ].NPad - 1 ;
378 <<
"I have no idea where the nearest pad is for the point ("
459 int nPad = _rows.at(rn).NPad ;
464 if (fabs(_phiMax - 2*M_PI) < 1e-6)
468 throw Exception(
"FixedPadSizeDiskLayout::getLeftNeighbour: no left neighbour pad !");
481 int nPad = _rows.at(rn).NPad ;
486 if (fabs(_phiMax - 2*M_PI) < 1e-6)
490 throw Exception(
"FixedPadSizeDiskLayout::getRightNeighbour: no right neighbour pad !");
508 if( r < _rMin || r > _rMax )
513 while( phi < 0 ) { phi += 2. * M_PI ; }
514 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
520 double phiPadHalf = 0.5 *
getPadWidth( padIndex ) ;
532 return ( std::abs( r - p[0] ) <= 0.5 * _padHeight &&
533 std::abs( phi - p[1] ) <= phiPadHalf ) ;
539 if( r < _rMin || r > _rMax )
544 while( phi < 0 ) { phi += 2. * M_PI ; }
545 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
FixedPadSizeDiskLayout(double rMin, double rMax, double padHeight, double PadWidth, int nRow=0, double padGap=0., double phiMax=2 *M_PI)
Construct the FixedPadSizeDiskLayout from the given parameters rMin, rMax, padHeight and PadWidth whe...
FixedPadSizeDiskLayout & operator=(const FixedPadSizeDiskLayout &)
The assignment operator.
virtual int getNRows() const
The number of rows.
Abstract description of a planar subdetector with pads (cells) that are positioned in rows (circular ...
virtual double getPadPitch(int padIndex) const
The pitch of the pad in radians (metal + gap)
void copy_and_assign(const FixedPadSizeDiskLayout &)
function to copy all internal variables, incl.
virtual int getPadNumber(int padIndex) const
The pad number (column) within the row - numbering starts at phi/x =.
Base exception class for GEAR - all other exceptions extend this.
void cleanup()
function to delete all the objects pointed to and owned by the FixedPadSizeDiskLayout.
Implementation of PadRowLayout2D for a disk with fixed sized keystone pads.
virtual int getNearestPad(double c0, double c1) const
The index of the pad nearest to the given point in 2d coordinates (x,y,) or (r,phi).
virtual int getRightNeighbour(int padIndex) const
The index of the right neighbour pad.
virtual bool isInsidePad(double c0, double c1, int padIndex) const
True if coordinate (c0,c1) is within the given pad.
ParseException used for parse errors, e.g.
Internal helper class for FixedPadSizeDiskLayout.
virtual int getLeftNeighbour(int padIndex) const
The index of the left neighbour pad.
virtual int getPadIndex(int rowNum, int padNum) const
Create a padIndex for the given row and pad ( column ) number.
virtual const std::vector< int > & getPadsInRow(int rowNumber) const
Indices of all pads in row rowNumber (row indices start from 0 at the bottom (CARTESIAN) or at the ce...
virtual int getRowNumber(int padIndex) const
The number of the row that contains the pad at padIndex - numbering starts at r/y==0.
virtual Vector2D getPadCenter(int padIndex) const
The center of the pad in 2d coordinates, (x,y) or (r,phi).
PadRowLayout2D * clone() const
Returns a copy (clone) of this class.
virtual ~FixedPadSizeDiskLayout()
Destructor.
virtual double getPadWidth(int padIndex) const
The width of the pad in radians (only the metal)