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 // contigious cells
cells = new CaloCell[ nx*ny ]; 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 #endif

View file

@ -5,5 +5,34 @@
class Calorimeter 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 #endif

View file

@ -6,22 +6,23 @@
class Point class Point
{ {
public: public:
Point() { init(0, 0, 0) ; } Point( double x = 0, double y = 0, double z = 0) { init( x, y, z ) ; }
Point( double x, double y, double z ) { init( x, y, z ); }
// No need for Constructor or Destructor
int getX() const { return x ; } 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 ; } 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 ; } 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 ) { void setPoint( double x, double y, double z ) {
x = in_x ; setX(x) ;
y = in_y ; setY(y) ;
z = in_z ; setZ(z) ;
} }

View file

@ -1,6 +1,8 @@
#include "iostream"
#include "CaloCell.hh" #include "CaloCell.hh"
#include "CaloGrid.hh" #include "CaloGrid.hh"
#include "Point.hh" #include "Point.hh"
#include "Calorimeter.hh"
int main() { int main() {
CaloCell cell(0, 1) ; CaloCell cell(0, 1) ;
@ -10,4 +12,12 @@ int main() {
grid.cell(1, 1); 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;
} }