1 #include "gearimpl/VersatileDiskRowLayout.h"
14 _nPad(0), _isFrayed(false)
41 for (std::vector< std::vector<int>* >::iterator rowIter =
_padIndices.begin() ;
54 double offset,
double padWidth,
double padHeight,
57 std::string routineName(
"gear::VersatileDiskRowLayout::addRow(): ");
61 throw Exception(routineName+
"Error, number of pads must be larger than 0!");
63 throw Exception(routineName+
"Error, pad pitch must be positive!");
65 throw Exception(routineName+
"Error, pad width must be positive!");
66 if ( padWidth > padPitch )
67 throw Exception(routineName+
"Error, pad width must be smaller or equal pad pitch!");
68 if ( rowHeight <= 0. )
69 throw Exception(routineName+
"Error, row height must be larger than 0!");
71 throw Exception(routineName+
"Error, number of repitions must be positive!");
76 padHeight = rowHeight;
78 double rCentre =
_extent[1] + rowHeight*0.5;
80 _nPad += repeat*nPads ;
82 for (
int i = 0; i < repeat; i++)
84 _rows.push_back(
Row(
_rows.size(), nPads, rCentre, padPitch , rowHeight ,
85 padWidth, padHeight, offset ) );
91 _extent[1]+= repeat * rowHeight;
105 return _rows.size() ;
110 return _rows.at(rowNumber).getRowHeight() ;
116 return _rows[rowNum].getPadHeight( ) ;
125 return _rows[rowNum].getPadWidth() ;
133 return _rows[rowNum].getPadPitch() ;
144 double phi = row.getOffset() + (
static_cast<double>(padNum) + 0.5) * row.getPadPitch();
146 double r = row.getRCentre() ;
180 static std::vector<int> empty ;
186 int nPad =
_rows.at(rowNumber).getNPads() ;
188 _padIndices[ rowNumber ] =
new std::vector<int>( nPad ) ;
190 for(
int i = 0 ; i < nPad ; i++){
196 }
catch( std::out_of_range& r) {
209 int rn = ( 0xffff0000 & padIndex ) >> 16 ;
211 if( rn < 0 || rn >
int(
_rows.size() - 1) ){
213 std::stringstream sstr ;
215 sstr <<
"VersatileDiskRowLayout::getRowNumber: illegal rownumber: "
216 << rn <<
" for padIndex 0x" << std::hex << padIndex <<
" nRows: " <<
_rows.size() << std::dec ;
228 if( (
unsigned) rowNum >
_rows.size() - 1 ) {
230 throw std::out_of_range(
" VersatileDiskRowLayout::getPadIndex row number too large !");
235 std::stringstream sstr ;
237 sstr <<
"VersatileDiskRowLayout::getPadIndex: pad number too large: "
238 << padNum <<
" only " <<
_rows[rowNum].getNPads() <<
" pads in row " << rowNum ;
240 throw std::out_of_range( sstr.str() );
243 return (rowNum << 16 ) | ( 0x0000ffff & padNum ) ;
259 pn =
_rows[rn].getNPads() -1 ;
261 throw Exception(
"VersatileDiskRowLayout::getRightNeighbour: no right neighbour pad !");
280 throw Exception(
"VersatileDiskRowLayout::getLeftNeighbour: no left neighbour pad !");
289 int nearestPad = -1 ;
291 for (std::vector<Row>::const_iterator rowIter =
_rows.begin()++;
292 rowIter <
_rows.end(); rowIter++)
295 double newDistance = rowIter->getDistanceToRow(r, phi);
297 if ( (newDistance < distance) || ( rowIter ==
_rows.begin() ) )
299 nearestPad = rowIter->getNearestPad(r, phi);
300 distance = newDistance;
304 if (nearestPad == -1)
305 throw Exception(std::string(
"VersatileDiskRowLayout::getNearestPad(): no pad rows defined."));
317 double rMin = row.getRCentre() - row.getRowHeight()*0.5;
318 double rMax = row.getRCentre() + row.getRowHeight()*0.5;
321 double phiMin = row.getOffset() + row.getPadPitch()*pn;
327 if (phi >= phiMin + 2*M_PI)
330 double phiMax = phiMin + row.getPadPitch();
332 return ( r >= rMin && r <= rMax &&
347 VersatileDiskRowLayout::Row::Row(
int rowNumber,
int nPads,
double rCentre,
double padPitch_mm,
349 double padWidth_mm,
double padHeight,
double offset_mm) :
350 _rowNumber(rowNumber), _nPads(nPads), _padPitch_mm(padPitch_mm), _padWidth_mm(padWidth_mm),
351 _rowHeight(rowHeight), _padHeight(padHeight), _offset_mm(offset_mm),
352 _rCentre(rCentre), _rMax(0.)
354 _offset = _offset_mm / rCentre;
357 if (_offset < - 2. * M_PI)
359 _offset += 2. * M_PI;
360 _offset_mm += rCentre*2. * M_PI;
363 if (_offset >= 2. * M_PI)
365 _offset -= 2. * M_PI;
366 _offset_mm += rCentre*2. * M_PI;
369 _padPitch = _padPitch_mm / rCentre;
370 if (_padPitch * nPads > 2*M_PI)
372 std::stringstream sstr;
373 sstr <<
"gear::VersatileDiskRowLayout::addRow(): "
374 <<
"Error: Too many pads ("<<nPads<<
" in row "<<rowNumber<<
"!";
375 throw Exception( sstr.str() );
378 _padWidth = _padWidth_mm / rCentre;
379 _offset = _offset_mm / rCentre;
381 _phiMax = _offset + _padPitch*_nPads;
382 _rMin = _rCentre - rowHeight*0.5;
383 _rMin = _rCentre + rowHeight*0.5;
390 while( phi < 0 ) { phi += 2. * M_PI ; }
391 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
399 int padNumber =
static_cast<int>(floor( (phi -
_offset)/ _padPitch ));
401 return ( (
_rowNumber<< 16) | (0x000ffff & padNumber) );
405 double distance1 = distanceToPhiMin( r , phi);
406 double distance2 = distanceToPhiMax( r , phi);
408 if ( distance1 < distance2)
419 while( phi < 0 ) { phi += 2. * M_PI ; }
420 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
424 double r_min = _rCentre - _rowHeight*0.5;
425 double r_max = _rCentre + _rowHeight*0.5;
426 double phi_min = _offset;
427 double phi_max = _offset + _nPads * _padPitch;
431 if ( (phi >= phi_min) && (phi <= phi_max ) )
434 if( (r >= r_min) && (r <= r_max) )
447 double distance_phiMin = distanceToPhiMin(r, phi);
448 double distance_phiMax = distanceToPhiMax(r, phi);
450 return (distance_phiMin < distance_phiMax ? distance_phiMin : distance_phiMax);
456 double VersatileDiskRowLayout::Row::distanceToPhiMin(
double r,
double phi)
const
460 while( phi < 0 ) { phi += 2. * M_PI ; }
461 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
465 double r_min = _rCentre - _rowHeight*0.5;
466 double r_max = _rCentre + _rowHeight*0.5;
467 double phi_min = _offset;
469 double distanceToCorner[2];
471 distanceToCorner[0] = r_min*r_min + r*r - 2*r_min*r*cos(phi_min - phi);
472 distanceToCorner[1] = r_max*r_max + r*r - 2*r_max*r*cos(phi_min - phi);
475 distanceToCorner[0] > distanceToCorner[1] ?
476 distanceToCorner[1] : distanceToCorner[0]
480 double VersatileDiskRowLayout::Row::distanceToPhiMax(
double r,
double phi)
const
484 while( phi < 0 ) { phi += 2. * M_PI ; }
485 while( phi > 2.*M_PI ) { phi -= 2. * M_PI ; }
489 double r_min = _rCentre - _rowHeight*0.5;
490 double r_max = _rCentre + _rowHeight*0.5;
491 double phi_max = _offset + _nPads * _padPitch;
493 double distanceToCorner[2];
495 distanceToCorner[0] = r_min*r_min + r*r - 2*r_min*r*cos(phi_max - phi);
496 distanceToCorner[1] = r_max*r_max + r*r - 2*r_max*r*cos(phi_max - phi);
499 distanceToCorner[0] > distanceToCorner[1] ?
500 distanceToCorner[1] : distanceToCorner[0]
double getDistanceToRow(double r, double phi) const
Function to calculate closest distance to the row.
bool _isFrayed
Flag that describes if the geometry is frayed.
Abstract description of a planar subdetector with pads (cells) that are positioned in rows (circular ...
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).
int _nPad
number of pads, keep for performance reasons
virtual bool isInsidePad(double c0, double c1, int padIndex) const
True if coordinate (c0,c1) is within the given pad.
Base exception class for GEAR - all other exceptions extend this.
PadRowLayout2D * clone() const
Returns a copy (clone) of this class.
int getNearestPad(double r, double phi) const
Function to determine the nearest pad in the row.
VersatileDiskRowLayout(double rMin)
Construct the VersatileDiskRowLayout.
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 getPadIndex(int rowNum, int padNum) const
Create a padIndex for the given row and pad ( column ) number.
VersatileDiskRowLayout & operator=(const VersatileDiskRowLayout &)
The assignment operator.
virtual int getNPads() const
The total number of pads in the TPC.
virtual void addRow(int nPads, double padPitch, double rowHeight, double offset=0., double padWidth=0., double padHeight=0., int repeat=1)
Add 'repeat' rows with the given parameters.
int _rowNumber
the row number
virtual int getRowNumber(int padIndex) const
The number of the row that contains the pad at padIndex - numbering starts at r/y==0.
virtual int getPadNumber(int padIndex) const
The pad number (column) within the row - numbering starts at phi/x =.
virtual int getNRows() const
The number of rows.
virtual Vector2D getPadCenter(int padIndex) const
The center of the pad in 2d coordinates, (x,y) or (r,phi).
double _padPitch
the pad pitch in radians
void cleanup()
function to delete all the objects pointed to and owned by the VersatileDiskRowLayout.
virtual int getCoordinateType() const
The type of the row layouts coordinate system: PadRowLayout2D.POLAR.
Internal helper class for VersatileDiskRowLayout, describing one row.
std::vector< std::vector< int > * > _padIndices
vector for getPadsInRow
void copy_and_assign(const VersatileDiskRowLayout &)
function to copy all internal variables, incl.
virtual double getPadHeight(int padIndex) const
The height of the pad in mm.
virtual double getRowHeight(int rowNumber) const
The row height in mm.
virtual double getPadPitch(int padIndex) const
The pitch of the pad in radians.
virtual ~VersatileDiskRowLayout()
Destructor.
virtual double getPadWidth(int padIndex) const
The width of the pad in radians.
std::vector< Row > _rows
vector with all the rows of the pad plane
std::vector< double > _extent
the plane extent
double _offset
the offset (staggering) with respect to phi=0 in radians, aka phiMin
Implementation of PadRowLayout2D for a wedge shaped module.
virtual int getLeftNeighbour(int padIndex) const
The index of the left neighbour pad.
virtual int getPadLayoutType() const
virtual int getRightNeighbour(int padIndex) const
The index of the right neighbour pad.
int _nPads
number of pads in the row