1
0
Fork 0

Ex4.2 feedback: setup Calorimeter class

This commit is contained in:
Eric Teunis de Boone 2020-07-01 16:29:22 +02:00
parent 9ea32ed1c0
commit c79e9e4af7
4 changed files with 58 additions and 11 deletions

View File

@ -40,6 +40,13 @@ class CaloGrid
// contigious cells
cells = new CaloCell[ nx*ny ];
// set Cell Ids
for ( int i = 0; i < nx ; i++ ) {
for ( int j = 0; j < ny ; j++ ) {
cells[i*ny +j].setId( i*ny+j );
}
}
}
} ;
#endif

View File

@ -5,5 +5,34 @@
class Calorimeter
{
}
public:
Calorimeter( int nx, int ny, double x = 0, double y = 0, double z = 0) :
calogrid(nx, ny),
point(x, y, z)
{}
Calorimeter( const Calorimeter& other ) :
calogrid( other.calogrid ),
point( other.point )
{}
CaloGrid& grid() {
return calogrid;
}
const CaloGrid& grid() const {
return calogrid;
}
Point& position() {
return point;
}
const Point& position() const {
return point;
}
private:
Point point;
CaloGrid calogrid;
};
#endif

View File

@ -6,28 +6,29 @@
class Point
{
public:
Point() { init(0, 0, 0) ; }
Point( double x, double y, double z ) { init( x, y, z ); }
Point( double x = 0, double y = 0, double z = 0) { init( x, y, z ) ; }
// No need for Constructor or Destructor
int getX() const { return x ; }
bool setX( int new_x ) { return ( x = new_x ) ; }
void setX( double new_x ) { x = new_x ; }
int getY() const { return y ; }
bool setY( int new_y ) { return ( y = new_y ) ; }
void setY( double new_y ) { y = new_y ; }
int getZ() const { return z ; }
bool setZ( int new_z ) { return ( z = new_z ) ; }
void setZ( double new_z ) { z = new_z ; }
void setPoint( double in_x, double in_y, double in_z ) {
x = in_x ;
y = in_y ;
z = in_z ;
void setPoint( double x, double y, double z ) {
setX(x) ;
setY(y) ;
setZ(z) ;
}
private:
void init( double x, double y, double z ) {
setPoint( x, y, z );
setPoint( x, y, z ) ;
}
double x, y, z = 0 ;

View File

@ -1,6 +1,8 @@
#include "iostream"
#include "CaloCell.hh"
#include "CaloGrid.hh"
#include "Point.hh"
#include "Calorimeter.hh"
int main() {
CaloCell cell(0, 1) ;
@ -10,4 +12,12 @@ int main() {
grid.cell(1, 1);
int nx = 2;
int ny = 2;
Calorimeter calo(nx, ny) ;
std::cout << calo.grid().cell(0,0)->getId() << std::endl;
std::cout << calo.grid().cell(nx-1,ny-1)->getId() << std::endl;
}