19#include "TStopwatch.h"
28template <
typename DataT>
29template <
typename DataTOut>
32 if (outf.IsZombie()) {
33 LOGP(error,
"Failed to write to file: {}", outf.GetName());
38 containerTmp.
getData() = std::vector<DataTOut>(mData.begin(), mData.end());
47template <
typename DataT>
48template <
typename DataTIn>
51 if (inpf.IsZombie()) {
52 LOGP(error,
"Failed to read from file: {}", inpf.GetName());
59 LOGP(error,
"Failed to load {} from {}",
name, inpf.GetName());
63 if (mZVertices != dataCont->getNZ() || mRVertices != dataCont->getNR() || mPhiVertices != dataCont->getNPhi()) {
64 LOGP(error,
"Data from input file has different definition of vertices!");
65 LOGP(error,
"set vertices before creating the sc object to: SpaceCharge<>::setGrid({}, {}, {})", dataCont->getNZ(), dataCont->getNR(), dataCont->getNPhi());
70 mData = std::vector<DataT>(dataCont->getData().begin(), dataCont->getData().end());
75template <
typename DataT>
78 if (inpf.IsZombie()) {
79 LOGP(error,
"Failed to read from file {}", inpf.GetName());
86 LOGP(error,
"Failed to load {} from {}",
name, inpf.GetName());
92template <
typename DataT>
97 auto&&
w = std::setw(9);
100 for (
unsigned int iz = 0; iz < mPhiVertices; ++iz) {
101 stream <<
"z layer: " << iz <<
"\n";
103 stream <<
"⎡" <<
w << (*this)(0, 0, iz);
104 for (
unsigned int ix = 1; ix < mZVertices; ++ix) {
105 stream <<
", " <<
w << (*this)(ix, 0, iz);
109 for (
unsigned int iy = 1; iy < mRVertices - 1; ++iy) {
110 stream <<
"⎢" <<
w << (*this)(0, iy, iz);
111 for (
unsigned int ix = 1; ix < mZVertices; ++ix) {
117 stream <<
"⎣" <<
w << (*this)(0, mRVertices - 1, iz);
118 for (
unsigned int ix = 1; ix < mZVertices; ++ix) {
119 stream <<
", " <<
w << (*this)(ix, mRVertices - 1, iz);
123 LOGP(info,
"{} \n \n",
stream.str());
127template <
typename DataT>
130 std::transform(mData.begin(), mData.end(), mData.begin(), [
value =
value](
auto&
val) { return val * value; });
134template <
typename DataT>
137 std::transform(mData.begin(), mData.end(),
other.mData.begin(), mData.begin(), std::plus<>());
141template <
typename DataT>
144 std::transform(mData.begin(), mData.end(),
other.mData.begin(), mData.begin(), std::minus<>());
148template <
typename DataT>
151 std::transform(mData.begin(), mData.end(),
other.mData.begin(), mData.begin(), std::multiplies<>());
155template <
typename DataT>
158 const size_t iphi =
index / (nz * nr);
159 index -= (iphi * nz * nr);
160 const size_t iz =
index % nz;
164template <
typename DataT>
167 const size_t iphi =
index / (nz * nr);
168 index -= (iphi * nz * nr);
173template <
typename DataT>
176 return index / (nz * nr);
179template <
typename DataT>
182 tree->SetAlias(
"ir",
"o2::tpc::DataContainer3D<float>::getIndexR(first + Iteration$, nz, nr, nphi)");
183 tree->SetAlias(
"iz",
"o2::tpc::DataContainer3D<float>::getIndexZ(first + Iteration$, nz, nr, nphi)");
184 tree->SetAlias(
"iphi",
"o2::tpc::DataContainer3D<float>::getIndexPhi(first + Iteration$, nz, nr, nphi)");
185 tree->SetAlias(
"r",
"o2::tpc::GridProperties<float>::getRMin() + o2::tpc::GridProperties<float>::getGridSpacingR(nr) * ir");
186 tree->SetAlias(
"z",
"o2::tpc::GridProperties<float>::getZMin() + o2::tpc::GridProperties<float>::getGridSpacingZ(nz) * iz");
187 tree->SetAlias(
"phi",
"o2::tpc::GridProperties<float>::getPhiMin() + o2::tpc::GridProperties<float>::getGridSpacingPhi(nphi) * iphi");
190template <
typename DataT>
197 tree->SetAlias(
"iz",
"_1");
198 tree->SetAlias(
"ir",
"_2");
199 tree->SetAlias(
"iphi",
"_3");
200 tree->SetAlias(
"z",
"_4");
201 tree->SetAlias(
"r",
"_5");
202 tree->SetAlias(
"phi",
"_6");
203 tree->SetAlias(
"lpos",
"_7");
204 tree->SetAlias(
"lx",
"lpos.fCoordinates.fX");
205 tree->SetAlias(
"ly",
"lpos.fCoordinates.fY");
206 tree->SetAlias(
"index",
"_8");
209template <
typename DataT>
216 mData.resize(nZ * nR *
static_cast<size_t>(nPhi));
221template <
typename DataT>
225 return interpolator(
z,
r, phi);
229template <
typename DataT>
232 TFile fTmp(fileIn.data(),
"READ");
233 TTree*
tree = (TTree*)fTmp.Get(treename.data());
235 LOGP(warning,
"Tree {} not found in input file {}", treename, fileIn);
238 tree->SetBranchAddress(
"nz", &nZ);
239 tree->SetBranchAddress(
"nr", &nR);
240 tree->SetBranchAddress(
"nphi", &nPhi);
246template <
typename DataT>
249 const int nZNew = gridNew.
getNZ();
250 const int nRNew = gridNew.
getNR();
251 const int nPhiNew = gridNew.
getNPhi();
253#pragma omp parallel for num_threads(threads)
254 for (
size_t iPhi = 0; iPhi < nPhiNew; ++iPhi) {
256 for (
size_t iR = 0; iR < nRNew; ++iR) {
258 for (
size_t iZ = 0; iZ < nZNew; ++iZ) {
260 contCont(iZ, iR, iPhi) = interpolate(
z, radius, phi, gridRef);
This class provides a simple method to store values on a large 3-Dim grid with ROOT io functionality.
Definition of RegularGrid3D class.
Definition of TriCubic class.
DataT getRVertex(const size_t vertexY) const
DataT getPhiVertex(const size_t vertexZ) const
DataT getZVertex(const size_t vertexX) const
GLuint const GLchar * name
GLsizei const GLfloat * value
GLubyte GLubyte GLubyte GLubyte w
GLdouble GLdouble GLdouble z
Global TPC definitions and constants.
const auto & getData() const
static size_t getIndexR(size_t index, const int nz, const int nr, const int nphi)
void print() const
print the matrix
bool initFromFile(TFile &inpf, const char *name="data")
set values from file
int writeToFile(TFile &outf, const char *name="data") const
void setGrid(unsigned short nZ, unsigned short nR, unsigned short nPhi, const bool resize)
set the grid points
static void setAliasesForDump(TTree *tree)
static void setAliases(TTree *tree)
DataT interpolate(const DataT z, const DataT r, const DataT phi, const o2::tpc::RegularGrid3D< DataT > &grid) const
DataContainer3D< DataT > & operator*=(const DataT value)
operator overload
static size_t getIndexZ(size_t index, const int nz, const int nr, const int nphi)
static size_t getIndexPhi(size_t index, const int nz, const int nr, const int nphi)
static bool getVertices(std::string_view treename, std::string_view fileIn, unsigned short &nR, unsigned short &nZ, unsigned short &nPhi)
static DataContainer3D< DataT > * loadFromFile(TFile &inpf, const char *name="data")
get pointer to object from file (deprecated!)
DataContainer3D< DataT > & operator-=(const DataContainer3D< DataT > &other)
DataContainer3D< DataT > & operator+=(const DataContainer3D< DataT > &other)
DataContainer3D< DataT > convert(const o2::tpc::RegularGrid3D< DataT > &gridNew, const o2::tpc::RegularGrid3D< DataT > &gridRef, const int threads=1) const
convert a data container to a new datacontainer with different grid definition (e....
VectorOfTObjectPtrs other
o2::InteractionRecord ir(0, 0)
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))