Skip to content

Commit 7dd7c39

Browse files
cbmswdavidrohr
authored andcommitted
TPC Splines: correct biased voxels; features for debugging
1 parent 22c28cd commit 7dd7c39

File tree

3 files changed

+419
-209
lines changed

3 files changed

+419
-209
lines changed

Detectors/TPC/calibration/include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ class TPCFastSpaceChargeCorrectionHelper
9090
/// \param voxResTreeInverse TTree with inverse voxel residuals
9191
/// \param useSmoothed if true, use smoothed residuals
9292
/// \param invertSigns if true, invert the signs of the residuals
93+
/// \param fitPointsDirect debug: pointer to the data used for the direct correction
94+
/// \param fitPointsInverse debug: pointer to the data used for the inverse correction
9395
/// \return pointer to the created TPCFastSpaceChargeCorrection object
9496
/// \note voxel trees wont be changed. They are read as non-const because of the ROOT::TTreeProcessorMT interface
97+
///
9598
std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> createFromTrackResiduals(
9699
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, //
97-
bool useSmoothed, bool invertSigns);
100+
bool useSmoothed, bool invertSigns, //
101+
TPCFastSpaceChargeCorrectionMap* fitPointsDirect = nullptr,
102+
TPCFastSpaceChargeCorrectionMap* fitPointsInverse = nullptr);
98103

99104
/// _______________ Utilities ________________________
100105

@@ -116,10 +121,28 @@ class TPCFastSpaceChargeCorrectionHelper
116121
/// \param additionalCorrections vector of pairs of additional corrections and their scaling factors
117122
/// \param prn printout flag
118123
/// \return main correction merged with additional corrections
119-
void MergeCorrections(
124+
void mergeCorrections(
120125
o2::gpu::TPCFastSpaceChargeCorrection& mainCorrection, float scale,
121126
const std::vector<std::pair<const o2::gpu::TPCFastSpaceChargeCorrection*, float>>& additionalCorrections, bool prn);
122127

128+
/// how far the voxel mean is allowed to be outside of the voxel (1.1 means 10%)
129+
void setVoxelMeanValidityRange(double range)
130+
{
131+
mVoxelMeanValidityRange = range;
132+
}
133+
134+
double getVoxelMeanValidityRange() const { return mVoxelMeanValidityRange; }
135+
136+
/// debug: if true, use voxel centers instead of the fitted positions for correction
137+
void setDebugUseVoxelCenters();
138+
139+
bool isDebugUseVoxelCenters() const { return mDebugUseVoxelCenters; }
140+
141+
/// debug: if true, mirror the data from the A side to the C side of the TPC
142+
void setDebugMirrorAdata2C();
143+
144+
bool isDebugMirrorAdata2C() const { return mDebugMirrorAdata2C; }
145+
123146
private:
124147
/// geometry initialization
125148
void initGeometry();
@@ -133,6 +156,11 @@ class TPCFastSpaceChargeCorrectionHelper
133156

134157
TPCFastSpaceChargeCorrectionMap mCorrectionMap{0, 0};
135158

159+
double mVoxelMeanValidityRange{1.1}; ///< debug: how far the voxel mean is allowed to be outside of the voxel (1.1 means 10%)
160+
161+
bool mDebugUseVoxelCenters{false}; ///< debug: if true, use voxel centers instead of the fitted positions for correction
162+
bool mDebugMirrorAdata2C{false}; ///< debug: if true, mirror the data from the A side to the C side of the TPC
163+
136164
ClassDefNV(TPCFastSpaceChargeCorrectionHelper, 0);
137165
};
138166

Detectors/TPC/calibration/src/TPCFastSpaceChargeCorrectionHelper.cxx

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "TTreeReaderValue.h"
3434
#include "ROOT/TTreeProcessorMT.hxx"
3535
#include <algorithm>
36+
#include <sstream>
3637

3738
using namespace o2::gpu;
3839

@@ -381,7 +382,9 @@ void TPCFastSpaceChargeCorrectionHelper::testGeometry(const TPCFastTransformGeo&
381382
}
382383

383384
std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrectionHelper::createFromTrackResiduals(
384-
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, bool useSmoothed, bool invertSigns)
385+
const o2::tpc::TrackResiduals& trackResiduals, TTree* voxResTree, TTree* voxResTreeInverse, bool useSmoothed, bool invertSigns,
386+
TPCFastSpaceChargeCorrectionMap* fitPointsDirect,
387+
TPCFastSpaceChargeCorrectionMap* fitPointsInverse)
385388
{
386389
// create o2::gpu::TPCFastSpaceChargeCorrection from o2::tpc::TrackResiduals::VoxRes voxel tree
387390

@@ -603,6 +606,24 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
603606
processor.Process(myThread);
604607
}
605608

609+
// debug: mirror the data for TPC C side
610+
611+
if (mDebugMirrorAdata2C) {
612+
for (int iSector = 0; iSector < geo.getNumberOfSectorsA(); iSector++) {
613+
for (int iRow = 0; iRow < nRows; iRow++) {
614+
for (int iy = 0; iy < nY2Xbins; iy++) {
615+
for (int iz = 0; iz < nZ2Xbins; iz++) {
616+
auto& dataA = vSectorData[iSector * nRows + iRow][iy * nZ2Xbins + iz];
617+
auto& dataC = vSectorData[(iSector + geo.getNumberOfSectorsA()) * nRows + iRow][iy * nZ2Xbins + iz];
618+
dataC = dataA; // copy the data
619+
dataC.mZ = -dataC.mZ; // mirror the Z coordinate
620+
dataC.mCz = -dataC.mCz; // mirror the Z correction
621+
}
622+
}
623+
}
624+
}
625+
}
626+
606627
for (int iSector = 0; iSector < nSectors; iSector++) {
607628

608629
// now process the data row-by-row
@@ -623,6 +644,7 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
623644
{
624645
int xBin = iRow;
625646
double x = trackResiduals.getX(xBin); // radius of the pad row
647+
double dx = 1. / trackResiduals.getDXI(xBin);
626648
bool isDataFound = false;
627649
for (int iy = 0; iy < nY2Xbins; iy++) {
628650
for (int iz = 0; iz < nZ2Xbins; iz++) {
@@ -642,13 +664,29 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
642664
if (data.mNentries > 0) { // voxel contains data
643665
vox.mSmoothingStep = 0; // take original data
644666
isDataFound = true;
645-
if (fabs(x - data.mX) > 1. || fabs(vox.mY - data.mY) > 5. || fabs(vox.mZ - data.mZ) > 5.) {
646-
std::cout << directionName << ": fitted voxel is too far from the nominal position: "
647-
<< " sector " << iSector << " row " << iRow
648-
<< " center x " << x << " y " << vox.mY << " z " << vox.mZ
649-
<< " fitted x " << data.mX << " y " << data.mY << " z " << data.mZ
650-
<< std::endl;
667+
668+
// correct the mean position if it is outside the voxel
669+
std::stringstream msg;
670+
if (fabs(x - data.mX) > mVoxelMeanValidityRange * dx / 2.) {
671+
msg << "\n x: center " << x << " dx " << data.mX - x << " half bin size: " << dx / 2;
672+
}
673+
674+
if (fabs(vox.mY - data.mY) > mVoxelMeanValidityRange * vox.mDy / 2.) {
675+
msg << "\n y: center " << vox.mY << " dy " << data.mY - vox.mY << " half bin size: " << vox.mDy / 2;
676+
data.mY = vox.mY;
677+
}
678+
679+
if (fabs(vox.mZ - data.mZ) > mVoxelMeanValidityRange * vox.mDz / 2.) {
680+
msg << "\n z: center " << vox.mZ << " dz " << data.mZ - vox.mZ << " half bin size: " << vox.mDz / 2;
681+
data.mZ = vox.mZ;
651682
}
683+
684+
if (!msg.str().empty()) {
685+
LOG(warning) << directionName << " correction: fitted voxel position is outside the voxel: "
686+
<< " sector " << iSector << " row " << iRow << " bin: " << iy << " " << iz
687+
<< msg.str();
688+
}
689+
652690
} else { // no data, take voxel center position
653691
data.mCx = 0.;
654692
data.mCy = 0.;
@@ -658,7 +696,7 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
658696
data.mZ = vox.mZ;
659697
vox.mSmoothingStep = 100; // fill this data point with smoothed values from the neighbours
660698
}
661-
if (0) { // debug: always use voxel center instead of the mean position
699+
if (mDebugUseVoxelCenters) { // debug: always use voxel center instead of the mean position
662700
data.mY = vox.mY;
663701
data.mZ = vox.mZ;
664702
}
@@ -809,6 +847,13 @@ std::unique_ptr<o2::gpu::TPCFastSpaceChargeCorrection> TPCFastSpaceChargeCorrect
809847

810848
TStopwatch watch4;
811849

850+
if (!processingInverseCorrection && fitPointsDirect) {
851+
*fitPointsDirect = helper->getCorrectionMap();
852+
}
853+
if (processingInverseCorrection && fitPointsInverse) {
854+
*fitPointsInverse = helper->getCorrectionMap();
855+
}
856+
812857
helper->fillSpaceChargeCorrectionFromMap(correction, processingInverseCorrection);
813858

814859
LOG(info) << "fast space charge correction helper: creation from the data map took " << watch4.RealTime() << "s";
@@ -956,7 +1001,7 @@ void TPCFastSpaceChargeCorrectionHelper::initInverse(std::vector<o2::gpu::TPCFas
9561001
LOGP(info, "Inverse tooks: {}s", duration);
9571002
}
9581003

959-
void TPCFastSpaceChargeCorrectionHelper::MergeCorrections(
1004+
void TPCFastSpaceChargeCorrectionHelper::mergeCorrections(
9601005
o2::gpu::TPCFastSpaceChargeCorrection& mainCorrection, float mainScale,
9611006
const std::vector<std::pair<const o2::gpu::TPCFastSpaceChargeCorrection*, float>>& additionalCorrections, bool /*prn*/)
9621007
{
@@ -1099,5 +1144,17 @@ void TPCFastSpaceChargeCorrectionHelper::MergeCorrections(
10991144
LOGP(info, "Merge of corrections tooks: {}s", duration);
11001145
}
11011146

1147+
void TPCFastSpaceChargeCorrectionHelper::setDebugUseVoxelCenters()
1148+
{
1149+
LOG(info) << "fast space charge correction helper: use voxel centers for correction";
1150+
mDebugUseVoxelCenters = true;
1151+
}
1152+
1153+
void TPCFastSpaceChargeCorrectionHelper::setDebugMirrorAdata2C()
1154+
{
1155+
LOG(info) << "fast space charge correction helper: mirror A data to C data";
1156+
mDebugMirrorAdata2C = true;
1157+
}
1158+
11021159
} // namespace tpc
11031160
} // namespace o2

0 commit comments

Comments
 (0)