Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 12, 2024
1 parent 812b97c commit 8e8727b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 70 deletions.
2 changes: 1 addition & 1 deletion inc/TRestAxionMagneticField.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class TRestAxionMagneticField : public TRestMetadata {
}
}

size_t GetArrayElement( MagneticFieldVolume &mVol, Int_t nx, Int_t ny, Int_t nz);
size_t GetArrayElement(MagneticFieldVolume& mVol, Int_t nx, Int_t ny, Int_t nz);

public:
void LoadMagneticVolumes();
Expand Down
67 changes: 40 additions & 27 deletions scripts/csvMentinkToBin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
print("Starting to read")
# loading the data into a matrix (xyzBdata)
file = r"../data/magneticField/Mentink_20240124.txt"
df = pd.read_csv(file, comment="%", sep='\t',header=None)
print( df.head() )
df = pd.read_csv(file, comment="%", sep="\t", header=None)
print(df.head())

print( "---" )
print("---")
print(df[0:5])
print( "---" )
print("---")

print("Translating to matrix")
xyzBdata = df.values

print( "#####" )
print("#####")
print(xyzBdata[0][0:6])
print(xyzBdata[1][0:6])
print(xyzBdata[2][0:6])
print( "#####" )
print("#####")

print(len(xyzBdata))

Expand All @@ -63,7 +63,20 @@
f = open("output.txt", "wt")

for x in xyzBdata:
f.write( str(x[0]) + "\t" + str(x[1]) + "\t" + str(x[2]) + "\t" + str(x[3]) + "\t" + str(x[4]) + "\t" + str(x[5]) + "\n")
f.write(
str(x[0])
+ "\t"
+ str(x[1])
+ "\t"
+ str(x[2])
+ "\t"
+ str(x[3])
+ "\t"
+ str(x[4])
+ "\t"
+ str(x[5])
+ "\n"
)
if xMax < x[0]:
xMax = x[0]
if yMax < x[1]:
Expand Down Expand Up @@ -117,25 +130,25 @@
# We recenter the volume and redefine axis (x becomes z, y becomes x and z becomes y)
# XLS file distances are expressed in m. We translate to mm.

if( x[2] <= zCutOffHigh and x[2] > zCutOffLow):
y = [
1000 * (x[0] - xCenter),
1000 * (x[1] - yCenter),
1000 * (x[2] - zCenter),
x[3],
x[4],
x[5],
]

# Baby-IAXO is symmetric respect to z (direction along axis) and x (direction parallel to the ground).
# I.e. x and y in the previous axis definition.
# The y-axis symmetry (in the new axis definition) affects the second bore that is not described in this map.
# We apply the corresponding symmetries to define the full map of one magnetic bore in the output binary file.
count = count + 1
fbin.write(struct.pack("<%df" % len(y), *y))
if count < 6:
print(len(y))
print(x[0:6])
print(y[0:6])
if x[2] <= zCutOffHigh and x[2] > zCutOffLow:
y = [
1000 * (x[0] - xCenter),
1000 * (x[1] - yCenter),
1000 * (x[2] - zCenter),
x[3],
x[4],
x[5],
]

# Baby-IAXO is symmetric respect to z (direction along axis) and x (direction parallel to the ground).
# I.e. x and y in the previous axis definition.
# The y-axis symmetry (in the new axis definition) affects the second bore that is not described in this map.
# We apply the corresponding symmetries to define the full map of one magnetic bore in the output binary file.
count = count + 1
fbin.write(struct.pack("<%df" % len(y), *y))
if count < 6:
print(len(y))
print(x[0:6])
print(y[0:6])
fbin.close()
print("Lines writen : " + str(count))
7 changes: 3 additions & 4 deletions src/TRestAxionFieldPropagationProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,7 @@ void TRestAxionFieldPropagationProcess::InitProcess() {
exit(0);
}

for( size_t n = 0; n < fMagneticField->GetNumberOfVolumes(); n++ )
fMagneticField->ReMap( n, fReMap );

for (size_t n = 0; n < fMagneticField->GetNumberOfVolumes(); n++) fMagneticField->ReMap(n, fReMap);

if (!fAxionField) {
fAxionField = new TRestAxionField();
Expand All @@ -184,7 +182,8 @@ void TRestAxionFieldPropagationProcess::InitProcess() {
fBufferGasAdditionalLength = 0;

fAxionField->AssignMagneticField(fMagneticField);
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info) fMagneticField->PrintMetadata();
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Info)
fMagneticField->PrintMetadata();
}

RESTDebug << "Axion-field : " << fAxionField << RESTendl;
Expand Down
74 changes: 36 additions & 38 deletions src/TRestAxionMagneticField.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,8 @@ TCanvas* TRestAxionMagneticField::DrawTracks(TVector3 vanishingPoint, Int_t divi
return fCanvas;
}

size_t TRestAxionMagneticField::GetArrayElement( MagneticFieldVolume &mVol, Int_t nx, Int_t ny, Int_t nz)
{
return (size_t) (nx*mVol.mesh.GetNodesY()*mVol.mesh.GetNodesZ() + ny*mVol.mesh.GetNodesZ() + nz);
size_t TRestAxionMagneticField::GetArrayElement(MagneticFieldVolume& mVol, Int_t nx, Int_t ny, Int_t nz) {
return (size_t)(nx * mVol.mesh.GetNodesY() * mVol.mesh.GetNodesZ() + ny * mVol.mesh.GetNodesZ() + nz);
}

///////////////////////////////////////////////
Expand All @@ -720,7 +719,7 @@ void TRestAxionMagneticField::LoadMagneticFieldData(MagneticFieldVolume& mVol,
Int_t nY = mVol.mesh.GetNodeY((Int_t)(data[n][1] + mVol.mesh.GetNetSizeY() / 2.), true);
Int_t nZ = mVol.mesh.GetNodeZ((Int_t)(data[n][2] + mVol.mesh.GetNetSizeZ() / 2.), true);

size_t element = GetArrayElement( mVol, nX, nY, nZ );
size_t element = GetArrayElement(mVol, nX, nY, nZ);

if (n < 5) {
RESTDebug << "X: " << data[n][0] << " Y: " << data[n][1] << " Z: " << data[n][2] << RESTendl;
Expand Down Expand Up @@ -749,7 +748,6 @@ void TRestAxionMagneticField::LoadMagneticFieldData(MagneticFieldVolume& mVol,
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Extreme) GetChar();
}


mVol.field[element] = TVector3(data[n][3], data[n][4], data[n][5]);
}
}
Expand Down Expand Up @@ -973,29 +971,29 @@ TVector3 TRestAxionMagneticField::GetMagneticField(TVector3 pos, Bool_t showWarn
else
nZ_1 = nZ;

size_t element;
element = GetArrayElement( fMagneticFieldVolumes[id], nX, nY, nZ );
size_t element;
element = GetArrayElement(fMagneticFieldVolumes[id], nX, nY, nZ);
TVector3 C000 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX_1, nY, nZ );
element = GetArrayElement(fMagneticFieldVolumes[id], nX_1, nY, nZ);
TVector3 C100 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX, nY_1, nZ );
element = GetArrayElement(fMagneticFieldVolumes[id], nX, nY_1, nZ);
TVector3 C010 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX_1, nY_1, nZ );
element = GetArrayElement(fMagneticFieldVolumes[id], nX_1, nY_1, nZ);
TVector3 C110 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX, nY, nZ_1 );
element = GetArrayElement(fMagneticFieldVolumes[id], nX, nY, nZ_1);
TVector3 C001 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX_1, nY, nZ_1 );
element = GetArrayElement(fMagneticFieldVolumes[id], nX_1, nY, nZ_1);
TVector3 C101 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX, nY_1, nZ_1 );
element = GetArrayElement(fMagneticFieldVolumes[id], nX, nY_1, nZ_1);
TVector3 C011 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

element = GetArrayElement( fMagneticFieldVolumes[id], nX_1, nY_1, nZ_1 );
element = GetArrayElement(fMagneticFieldVolumes[id], nX_1, nY_1, nZ_1);
TVector3 C111 = fMagneticFieldVolumes[id].field[element] + fConstantField[id];

Double_t x0 = fMagneticFieldVolumes[id].mesh.GetX(nX);
Expand Down Expand Up @@ -1108,31 +1106,31 @@ void TRestAxionMagneticField::ReMap(const size_t& n, const TVector3& newMapSize)
return;
}

/*
Int_t scaleX = (Int_t)(newMapSize.X() / fMeshSize[n].X());
Int_t scaleY = (Int_t)(newMapSize.Y() / fMeshSize[n].Y());
Int_t scaleZ = (Int_t)(newMapSize.Z() / fMeshSize[n].Z());
Int_t newNodesX = (fMagneticFieldVolumes[n].mesh.GetNodesX() - 1) / scaleX + 1;
Int_t newNodesY = (fMagneticFieldVolumes[n].mesh.GetNodesY() - 1) / scaleY + 1;
Int_t newNodesZ = (fMagneticFieldVolumes[n].mesh.GetNodesZ() - 1) / scaleZ + 1;
for (Int_t nx = 0; nx < newNodesX; nx++)
for (Int_t ny = 0; ny < newNodesY; ny++)
for (Int_t nz = 0; nz < newNodesZ; nz++)
fMagneticFieldVolumes[n].field[nx][ny][nz] =
fMagneticFieldVolumes[n].field[nx * scaleX][ny * scaleY][nz * scaleZ];
fMagneticFieldVolumes[n].mesh.SetNodes(newNodesX, newNodesY, newNodesZ);
fMagneticFieldVolumes[n].field.resize(fMagneticFieldVolumes[n].mesh.GetNodesX());
for (unsigned int i = 0; i < fMagneticFieldVolumes[n].field.size(); i++) {
fMagneticFieldVolumes[n].field[n].resize(fMagneticFieldVolumes[n].mesh.GetNodesY());
for (unsigned int j = 0; j < fMagneticFieldVolumes[n].field[i].size(); j++)
fMagneticFieldVolumes[n].field[i][j].resize(fMagneticFieldVolumes[n].mesh.GetNodesZ());
}
/*
Int_t scaleX = (Int_t)(newMapSize.X() / fMeshSize[n].X());
Int_t scaleY = (Int_t)(newMapSize.Y() / fMeshSize[n].Y());
Int_t scaleZ = (Int_t)(newMapSize.Z() / fMeshSize[n].Z());
Int_t newNodesX = (fMagneticFieldVolumes[n].mesh.GetNodesX() - 1) / scaleX + 1;
Int_t newNodesY = (fMagneticFieldVolumes[n].mesh.GetNodesY() - 1) / scaleY + 1;
Int_t newNodesZ = (fMagneticFieldVolumes[n].mesh.GetNodesZ() - 1) / scaleZ + 1;
for (Int_t nx = 0; nx < newNodesX; nx++)
for (Int_t ny = 0; ny < newNodesY; ny++)
for (Int_t nz = 0; nz < newNodesZ; nz++)
fMagneticFieldVolumes[n].field[nx][ny][nz] =
fMagneticFieldVolumes[n].field[nx * scaleX][ny * scaleY][nz * scaleZ];
fMagneticFieldVolumes[n].mesh.SetNodes(newNodesX, newNodesY, newNodesZ);
fMagneticFieldVolumes[n].field.resize(fMagneticFieldVolumes[n].mesh.GetNodesX());
for (unsigned int i = 0; i < fMagneticFieldVolumes[n].field.size(); i++) {
fMagneticFieldVolumes[n].field[n].resize(fMagneticFieldVolumes[n].mesh.GetNodesY());
for (unsigned int j = 0; j < fMagneticFieldVolumes[n].field[i].size(); j++)
fMagneticFieldVolumes[n].field[i][j].resize(fMagneticFieldVolumes[n].mesh.GetNodesZ());
}
fMeshSize[n] = TVector3(fMeshSize[n].X() * scaleX, fMeshSize[n].Y() * scaleY, fMeshSize[n].Z() * scaleZ);
*/
fMeshSize[n] = TVector3(fMeshSize[n].X() * scaleX, fMeshSize[n].Y() * scaleY, fMeshSize[n].Z() * scaleZ);
*/
}

///////////////////////////////////////////////
Expand Down

0 comments on commit 8e8727b

Please sign in to comment.