#include "ModuleParameterisation.hh"
#include "G4SystemOfUnits.hh"
#include "G4PhysicalConstants.hh"

#include "G4VPhysicalVolume.hh"
#include "G4ThreeVector.hh"
#include "G4RotationMatrix.hh"
#include "G4Box.hh"


ModuleParameterisation::ModuleParameterisation(G4double barSide, G4double barLength, G4int nSide)
{
    fSpacing =  barSide;
    fLength  =  barLength;
    fSide    =  nSide;
}


ModuleParameterisation::~ModuleParameterisation() 
{;}


void ModuleParameterisation::ComputeTransformation (const G4int copyNo, G4VPhysicalVolume* physVol) const
{
    
    
    // ID number of the row
    G4int barNumberX = copyNo % fSide;
    G4int barNumberY = copyNo / fSide;

    
//    G4cout << "*** DEBUG ***: Replica number " << copyNo << G4endl;
//    G4cout << "*** DEBUG ***: barNumberX " << barNumberX << G4endl;
//    G4cout << "*** DEBUG ***: barNumberY " << barNumberY << G4endl;

    G4double xCell = 0.*cm;
    G4double yCell = 0.*cm;
    G4double zCell = 0.*cm;
    
    G4int rowID;
    G4int columnID;
//    zCell = - fLength/2.;
    
    rowID = barNumberX - fSide/2;
    columnID = barNumberY - fSide/2;

    if (fSide % 2 != 0) {
        // Odd number of bars per side
        xCell = rowID*fSpacing ;
        yCell = columnID*fSpacing ;
    }
    else
    {
        // Even number of bars per side
        xCell = rowID*fSpacing + fSpacing/2.;
        yCell = columnID*fSpacing + fSpacing/2.;
    }
    
//    G4cout << "*** DEBUG ***:  " << xCell << " " << yCell << " " << zCell << G4endl;

    physVol->SetTranslation(G4ThreeVector(xCell, yCell, zCell));
    
}



