Skip to content

Commit 09a2030

Browse files
[SC] Adding possibility to use float for calculations (#6870)
* [SC] Adding possibility to use float for calculations - setting default values for omega tau - adding function to calculate the drift path for an electron - adding simple debug function - poisson solver: cleaning + using more than 1000 phi bins * fixing function name getChargeCyl -> getDensityCyl * fixing typo * fixing error during compiling of macro
1 parent 70f0944 commit 09a2030

10 files changed

Lines changed: 468 additions & 276 deletions

File tree

Detectors/TPC/reconstruction/macro/createTPCSpaceChargeCorrection.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void debugInterpolation(utils::TreeStreamRedirector& pcstream,
222222
float gxyzf[3] = {gx, gy, gz};
223223
float pointCyl[3] = {gz, r, phi};
224224
double efield[3] = {0.0, 0.0, 0.0};
225-
double charge = spaceCharge->getChargeCyl(pointCyl[0], pointCyl[1], pointCyl[2], side);
225+
double charge = spaceCharge->getDensityCyl(pointCyl[0], pointCyl[1], pointCyl[2], side);
226226
double potential = spaceCharge->getPotentialCyl(pointCyl[0], pointCyl[1], pointCyl[2], side);
227227
spaceCharge->getElectricFieldsCyl(pointCyl[0], pointCyl[1], pointCyl[2], side, efield[0], efield[1], efield[2]);
228228
spaceCharge->getLocalDistortionsCyl(pointCyl[0], pointCyl[1], pointCyl[2], side, ldD[0], ldD[1], ldD[2]);
@@ -379,7 +379,7 @@ void debugGridpoints(utils::TreeStreamRedirector& pcstream, const o2::gpu::TPCFa
379379
double efield[3] = {0.0, 0.0, 0.0};
380380
double distLocal[3] = {0.0, 0.0, 0.0};
381381
double dist[3] = {0.0, 0.0, 0.0};
382-
double charge = spaceCharge->getChargeCyl(pointCyl[0], pointCyl[1], pointCyl[2], side);
382+
double charge = spaceCharge->getDensityCyl(pointCyl[0], pointCyl[1], pointCyl[2], side);
383383
double potential = spaceCharge->getPotentialCyl(pointCyl[0], pointCyl[1], pointCyl[2], side);
384384
spaceCharge->getElectricFieldsCyl(pointCyl[0], pointCyl[1], pointCyl[2], side, efield[0], efield[1], efield[2]);
385385
spaceCharge->getLocalDistortionsCyl(pointCyl[0], pointCyl[1], pointCyl[2], side, distLocal[0], distLocal[1], distLocal[2]);

Detectors/TPC/spacecharge/include/TPCSpaceCharge/RegularGrid3D.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,19 @@ struct RegularGrid3D {
137137

138138
private:
139139
inline static auto& mParamGrid = ParameterSpaceCharge::Instance();
140-
static constexpr unsigned int FDIM = 3; ///< dimensions of the grid (only 3 supported)
141-
static constexpr unsigned int FZ = 0; ///< index for x coordinate
142-
static constexpr unsigned int FR = 1; ///< index for y coordinate
143-
static constexpr unsigned int FPHI = 2; ///< index for z coordinate
144-
const Vector<DataT, FDIM> mMin{}; ///< min vertices positions of the grid
145-
const Vector<DataT, FDIM> mMax{}; ///< max vertices positions of the grid
146-
const Vector<DataT, FDIM> mSpacing{}; ///< spacing of the grid
147-
const Vector<DataT, FDIM> mInvSpacing{}; ///< inverse spacing of grid
148-
const Vector<DataT, FDIM> sMaxIndex{{static_cast<double>(mParamGrid.NZVertices - 1.), static_cast<double>(mParamGrid.NRVertices - 1), static_cast<double>(mParamGrid.NPhiVertices - 1)}}; ///< max index which is on the grid in all dimensions
149-
const Vector<int, FDIM> sNdim{{static_cast<int>(mParamGrid.NZVertices), static_cast<int>(mParamGrid.NRVertices), static_cast<int>(mParamGrid.NPhiVertices)}}; ///< number of vertices for each dimension
150-
std::vector<DataT> mZVertices{}; ///< positions of vertices in x direction
151-
std::vector<DataT> mRVertices{}; ///< positions of vertices in y direction
152-
std::vector<DataT> mPhiVertices{}; ///< positions of vertices in z direction
140+
static constexpr unsigned int FDIM = 3; ///< dimensions of the grid (only 3 supported)
141+
static constexpr unsigned int FZ = 0; ///< index for x coordinate
142+
static constexpr unsigned int FR = 1; ///< index for y coordinate
143+
static constexpr unsigned int FPHI = 2; ///< index for z coordinate
144+
const Vector<DataT, FDIM> mMin{}; ///< min vertices positions of the grid
145+
const Vector<DataT, FDIM> mMax{}; ///< max vertices positions of the grid
146+
const Vector<DataT, FDIM> mSpacing{}; ///< spacing of the grid
147+
const Vector<DataT, FDIM> mInvSpacing{}; ///< inverse spacing of grid
148+
const Vector<DataT, FDIM> sMaxIndex{{static_cast<DataT>(mParamGrid.NZVertices - 1.), static_cast<DataT>(mParamGrid.NRVertices - 1), static_cast<DataT>(mParamGrid.NPhiVertices - 1)}}; ///< max index which is on the grid in all dimensions
149+
const Vector<int, FDIM> sNdim{{static_cast<int>(mParamGrid.NZVertices), static_cast<int>(mParamGrid.NRVertices), static_cast<int>(mParamGrid.NPhiVertices)}}; ///< number of vertices for each dimension
150+
std::vector<DataT> mZVertices{}; ///< positions of vertices in x direction
151+
std::vector<DataT> mRVertices{}; ///< positions of vertices in y direction
152+
std::vector<DataT> mPhiVertices{}; ///< positions of vertices in z direction
153153

154154
void initLists();
155155

Detectors/TPC/spacecharge/include/TPCSpaceCharge/SpaceCharge.h

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
class TH3;
3030
class TH3D;
31+
class TH3F;
3132

3233
namespace o2
3334
{
@@ -50,11 +51,15 @@ class SpaceCharge
5051
using DataContainer = DataContainer3D<DataT>;
5152
using GridProp = GridProperties<DataT>;
5253
using TriCubic = TriCubicInterpolator<DataT>;
54+
using TH3DataT = std::conditional_t<std::is_same<DataT, double>::value, TH3D, TH3F>; // datatype for TH3 (TH3F for DataT==float and TH3D for DataT==double)
5355

5456
public:
5557
/// default constructor
5658
/// grid granularity has to set before constructing an object using the static function setGrid(nZVertices, nRVertices, nPhiVertices)!
57-
SpaceCharge() = default;
59+
/// \param omegaTau \omega \tau value
60+
/// \param t1 value for t1
61+
/// \param t2 value for t2
62+
SpaceCharge(const DataT omegaTau = -0.35f, const DataT t1 = 1, const DataT t2 = 1) { setOmegaTauT1T2(omegaTau, t1, t2); };
5863

5964
/// \param nZVertices number of vertices of the grid in z direction
6065
/// \param nRVertices number of vertices of the grid in z direction
@@ -182,7 +187,7 @@ class SpaceCharge
182187
/// \param z global z coordinate
183188
/// \param r global r coordinate
184189
/// \param phi global phi coordinate
185-
DataT getChargeCyl(const DataT z, const DataT r, const DataT phi, const Side side) const;
190+
DataT getDensityCyl(const DataT z, const DataT r, const DataT phi, const Side side) const;
186191

187192
/// get the potential for given coordinate
188193
/// \param z global z coordinate
@@ -538,7 +543,7 @@ class SpaceCharge
538543
/// \param omegaTau \omega \tau value
539544
/// \param t1 value for t1 see: ???
540545
/// \param t2 value for t2 see: ???
541-
void setOmegaTauT1T2(const DataT omegaTau, const DataT t1, const DataT t2)
546+
void setOmegaTauT1T2(const DataT omegaTau = -0.35f, const DataT t1 = 1, const DataT t2 = 1)
542547
{
543548
const DataT wt0 = t2 * omegaTau;
544549
mC0 = 1 / (1 + wt0 * wt0);
@@ -567,7 +572,7 @@ class SpaceCharge
567572
static void setNThreads(const int nThreads)
568573
{
569574
sNThreads = nThreads;
570-
o2::tpc::TriCubicInterpolator<DataT>::setNThreads(nThreads);
575+
TriCubic::setNThreads(nThreads);
571576
}
572577

573578
/// set which kind of numerical integration is used for calcution of the integrals int Er/Ez dz, int Ephi/Ez dz, int Ez dz
@@ -597,6 +602,14 @@ class SpaceCharge
597602
/// \side side of the TPC
598603
void dumpToFile(TFile& outf, const Side side) const;
599604

605+
/// dump sc density, potential, electric fields, global distortions/corrections to tree
606+
/// \param outFileName name of the output file
607+
/// \side side of the TPC
608+
/// \param nZPoints number of vertices of the output in z
609+
/// \param nRPoints number of vertices of the output in r
610+
/// \param nPhiPoints number of vertices of the output in phi
611+
void dumpToTree(const char* outFileName, const Side side, const int nZPoints = 50, const int nRPoints = 150, const int nPhiPoints = 180) const;
612+
600613
/// write electric fields to root file
601614
/// \param outf output file where the electrical fields will be written to
602615
/// \side side of the TPC
@@ -716,7 +729,13 @@ class SpaceCharge
716729
/// \param nBinsZNew number of z bins of rebinned histogram
717730
/// \param nBinsRNew number of r bins of rebinned histogram
718731
/// \param nBinsPhiNew number of phi bins of rebinned histogram
719-
static TH3D rebinDensityHisto(const TH3& hOrig, const unsigned short nBinsZNew, const unsigned short nBinsRNew, const unsigned short nBinsPhiNew);
732+
static TH3DataT rebinDensityHisto(const TH3& hOrig, const unsigned short nBinsZNew, const unsigned short nBinsRNew, const unsigned short nBinsPhiNew);
733+
734+
/// function to calculate the drift paths of the electron whose starting position is delivered. Electric fields must be set!
735+
/// \param elePos global position of the start position of the electron
736+
/// \param nSamplingPoints number of output points of the electron drift path
737+
/// \return returns the input electron a vector of 3D-points describing the drift path of the electron
738+
std::vector<GlobalPosition3D> calculateElectronDriftPath(const GlobalPosition3D& elePos, const int nSamplingPoints) const;
720739

721740
private:
722741
inline static auto& mParamGrid = ParameterSpaceCharge::Instance(); ///< parameters of the grid on which the calculations are performed

Detectors/TPC/spacecharge/include/TPCSpaceCharge/Vector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#ifndef ALICEO2_TPC_VECTOR_H_
1818
#define ALICEO2_TPC_VECTOR_H_
1919

20-
#include <Vc/Vc>
20+
#include <Vc/vector>
21+
#include <Vc/Memory>
2122

2223
namespace o2
2324
{

Detectors/TPC/spacecharge/macro/calculateDistortionsCorrections.C

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
#include "CommonUtils/TreeStreamRedirector.h"
77

88
template <typename DataT>
9-
void calculateDistortionsAnalytical(const int globalEFieldTypeAna = 1, const int globalDistTypeAna = 1, const int eFieldTypeAna = 1, const int usePoissonSolverAna = 1, const int nSteps = 1, const int simpsonIterations = 3, const int nThreads = -1);
9+
void calculateDistortionsAnalytical(const int sides = 0, const int globalEFieldTypeAna = 1, const int globalDistTypeAna = 1, const int eFieldTypeAna = 1, const int usePoissonSolverAna = 1, const int nSteps = 1, const int simpsonIterations = 3, const int nThreads = -1);
1010

1111
template <typename DataT>
1212
void calculateDistortionsFromHist(const char* path, const char* histoName, const int sides, const int globalEFieldType = 1, const int globalDistType = 1, const int nSteps = 1, const int simpsonIterations = 3, const int nThreads = -1);
1313

14+
int getSideStart(const int sides);
15+
int getSideEnd(const int sides);
16+
17+
/// \param sides set which sides will be simulated. sides=0: A- and C-Side, sides=1: A-Side only, sides=2: C-Side only
1418
/// \param nZVertices number of vertices of the grid in z direction
1519
/// \param nRVertices number of vertices of the grid in z direction
1620
/// \param nPhiVertices number of vertices of the grid in z direction
@@ -21,10 +25,11 @@ void calculateDistortionsFromHist(const char* path, const char* histoName, const
2125
/// \param nSteps number of which are used for calculation of distortions/corrections per z-bin
2226
/// \param simpsonIterations number of iterations used in the simpson intergration
2327
/// \param nThreads number of threads which are used (if the value is -1 all threads should be used)
24-
void calcDistAna(const unsigned short nZVertices = 129, const unsigned short nRVertices = 129, const unsigned short nPhiVertices = 180, const int globalEFieldTypeAna = 1, const int globalDistTypeAna = 1, const int eFieldTypeAna = 1, const int usePoissonSolverAna = 1, const int nSteps = 1, const int simpsonIterations = 3, const int nThreads = -1)
28+
template <typename DataT>
29+
void calcDistAna(const int sides = 0, const unsigned short nZVertices = 129, const unsigned short nRVertices = 129, const unsigned short nPhiVertices = 180, const int globalEFieldTypeAna = 1, const int globalDistTypeAna = 1, const int eFieldTypeAna = 1, const int usePoissonSolverAna = 1, const int nSteps = 1, const int simpsonIterations = 3, const int nThreads = -1)
2530
{
26-
o2::tpc::SpaceCharge<double>::setGrid(nZVertices, nRVertices, nPhiVertices);
27-
calculateDistortionsAnalytical<double>(globalEFieldTypeAna, globalDistTypeAna, eFieldTypeAna, usePoissonSolverAna, nSteps, simpsonIterations, nThreads);
31+
o2::tpc::SpaceCharge<DataT>::setGrid(nZVertices, nRVertices, nPhiVertices);
32+
calculateDistortionsAnalytical<DataT>(sides, globalEFieldTypeAna, globalDistTypeAna, eFieldTypeAna, usePoissonSolverAna, nSteps, simpsonIterations, nThreads);
2833
}
2934

3035
/// \param path path to the root file containing the 3D density histogram
@@ -271,7 +276,7 @@ void writeToTree(o2::tpc::SpaceCharge<DataT>& spaceCharge3D, o2::utils::TreeStre
271276
/// \param nSteps number of which are used for calculation of distortions/corrections per z-bin
272277
/// \param simpsonIterations number of iterations used in the simpson intergration
273278
template <typename DataT = double>
274-
void calculateDistortionsAnalytical(const int globalEFieldTypeAna, const int globalDistTypeAna, const int eFieldTypeAna, const int usePoissonSolverAna, const int nSteps, const int simpsonIterations, const int nThreads)
279+
void calculateDistortionsAnalytical(const int sides, const int globalEFieldTypeAna, const int globalDistTypeAna, const int eFieldTypeAna, const int usePoissonSolverAna, const int nSteps, const int simpsonIterations, const int nThreads)
275280
{
276281
const auto integrationStrategy = o2::tpc::SpaceCharge<DataT>::IntegrationStrategy::SimpsonIterative;
277282
o2::tpc::SpaceCharge<DataT> spaceCharge3D;
@@ -286,7 +291,7 @@ void calculateDistortionsAnalytical(const int globalEFieldTypeAna, const int glo
286291
// write to root file
287292
o2::utils::TreeStreamRedirector pcstream(TString::Format("distortions_ana_nR%hu_nZ%hu_nPhi%hu_SimpsonsIter%i.root", spaceCharge3D.getNRVertices(), spaceCharge3D.getNZVertices(), spaceCharge3D.getNPhiVertices(), simpsonIterations).Data(), "RECREATE");
288293

289-
for (int iside = 0; iside < 2; ++iside) {
294+
for (int iside = getSideStart(sides); iside < getSideEnd(sides); ++iside) {
290295
std::cout << "side: " << iside << std::endl;
291296
o2::tpc::Side side = (iside == 0) ? o2::tpc::Side::A : o2::tpc::Side::C;
292297
o2::tpc::AnalyticalFields<DataT> anaFields(side);
@@ -327,16 +332,7 @@ void calculateDistortionsFromHist(const char* path, const char* histoName, const
327332
fileOutSCDensity.Close();
328333

329334
o2::utils::TreeStreamRedirector pcstream(TString::Format("distortions_real_nR%hu_nZ%hu_nPhi%hu_SimpsonsIter%i.root", spaceCharge3D.getNRVertices(), spaceCharge3D.getNZVertices(), spaceCharge3D.getNPhiVertices(), simpsonIterations).Data(), "RECREATE");
330-
int iSideStart = 0;
331-
int iSideEnd = 2;
332-
if (sides == 1) {
333-
// a side only
334-
iSideEnd = 1;
335-
} else if (sides == 2) {
336-
// c side only
337-
iSideStart = 1;
338-
}
339-
for (int iside = iSideStart; iside < iSideEnd; ++iside) {
335+
for (int iside = getSideStart(sides); iside < getSideEnd(sides); ++iside) {
340336
std::cout << "side: " << iside << std::endl;
341337
o2::tpc::Side side = (iside == 0) ? o2::tpc::Side::A : o2::tpc::Side::C;
342338
const auto distType = globalDistType == 0 ? SC::GlobalDistType::Standard : SC ::GlobalDistType::Fast;
@@ -364,3 +360,23 @@ void calculateDistortionsFromHist(const char* path, const char* histoName, const
364360
}
365361
fOut.Close();
366362
}
363+
364+
/// helper function to set the loop over the sides for the tpc
365+
/// \param sides set for which sides the distortions/corrections will be calculated. sides=0: A- and C-Side, sides=1: A-Side only, sides=2: C-Side only
366+
int getSideStart(const int sides)
367+
{
368+
if (sides == 2) {
369+
return 1;
370+
}
371+
return 0;
372+
}
373+
374+
/// helper function to set the loop over the sides for the tpc
375+
/// \param sides set for which sides the distortions/corrections will be calculated. sides=0: A- and C-Side, sides=1: A-Side only, sides=2: C-Side only
376+
int getSideEnd(const int sides)
377+
{
378+
if (sides == 1) {
379+
return 1;
380+
}
381+
return 2;
382+
}

0 commit comments

Comments
 (0)