3333#include " TTreeReaderValue.h"
3434#include " ROOT/TTreeProcessorMT.hxx"
3535#include < algorithm>
36+ #include < sstream>
3637
3738using namespace o2 ::gpu;
3839
@@ -381,7 +382,9 @@ void TPCFastSpaceChargeCorrectionHelper::testGeometry(const TPCFastTransformGeo&
381382}
382383
383384std::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