diff --git a/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h b/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h index 8a731a61c8a2d..1d7b10dc965f7 100644 --- a/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h +++ b/DataFormats/Detectors/TPC/include/DataFormatsTPC/CalibdEdxCorrection.h @@ -91,8 +91,8 @@ class CalibdEdxCorrection void clear(); - void writeToFile(std::string_view fileName, std::string_view objName = "CalibdEdxCorrection") const; - void loadFromFile(std::string_view fileName, std::string_view objName = "CalibdEdxCorrection"); + void writeToFile(std::string_view fileName, std::string_view objName = "ccdb_object") const; + void loadFromFile(std::string_view fileName, std::string_view objName = "ccdb_object"); /// \param outFileName name of the output file void dumpToTree(const char* outFileName = "calib_dedx.root") const; diff --git a/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx b/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx index c8224aca5b344..0991c8693d8e8 100644 --- a/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx +++ b/DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx @@ -15,6 +15,7 @@ #include // o2 includes +#include "Framework/Logger.h" #include "DataFormatsTPC/Defs.h" #include "CommonUtils/TreeStreamRedirector.h" @@ -39,15 +40,27 @@ void CalibdEdxCorrection::clear() void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const { std::unique_ptr file(TFile::Open(fileName.data(), "recreate")); + if (!file) { + LOGP(error, "Failed to open file {} for writing", fileName.data()); + return; + } + file->WriteObject(this, objName.data()); } void CalibdEdxCorrection::loadFromFile(std::string_view fileName, std::string_view objName) { std::unique_ptr file(TFile::Open(fileName.data())); + if (!file || file->IsZombie()) { + LOGP(error, "Failed to open file {}", fileName.data()); + return; + } + auto tmp = file->Get(objName.data()); if (tmp != nullptr) { *this = *tmp; + } else { + LOGP(error, "Failed to load object with name {} from file {}", objName.data(), fileName.data()); } } diff --git a/Detectors/TPC/base/src/DeadChannelMapCreator.cxx b/Detectors/TPC/base/src/DeadChannelMapCreator.cxx index bcbfa8fe68956..8c4e754fc5327 100644 --- a/Detectors/TPC/base/src/DeadChannelMapCreator.cxx +++ b/Detectors/TPC/base/src/DeadChannelMapCreator.cxx @@ -43,6 +43,11 @@ void DeadChannelMapCreator::loadFEEConfigViaRunInfoTS(long timeStamp) if (mObjectValidity[CDBType::ConfigRunInfo].isValid(timeStamp)) { return; } + + const auto meta = mCCDBApi.retrieveHeaders(CDBTypeMap.at(CDBType::ConfigRunInfo), {}, timeStamp); + mObjectValidity[CDBType::ConfigRunInfo].startvalidity = std::stol(meta.at("Valid-From")); + mObjectValidity[CDBType::ConfigRunInfo].endvalidity = std::stol(meta.at("Valid-Until")); + loadFEEConfig(timeStamp); } diff --git a/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/SpacePointsCalibParam.h b/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/SpacePointsCalibParam.h index 67226d108bae3..90b693820d0fa 100644 --- a/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/SpacePointsCalibParam.h +++ b/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/SpacePointsCalibParam.h @@ -56,7 +56,7 @@ static constexpr int NZ2XBins = 5; ///< number of bins in z/x static constexpr float MaxResid = 20.f; ///< max residual in y and z static constexpr float MaxY = 50.f; ///< max value for y position (sector coordinates) static constexpr float MaxZ = 300.f; ///< max value for z position -static constexpr float MaxTgSlp = 1.f; ///< max value for phi (from snp) +static constexpr float MaxTgSlp = 1.f; ///< max value for phi (from snp, converted to tangens) // miscellaneous static constexpr float sEps = 1e-6f; ///< small number for float comparisons diff --git a/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackInterpolation.h b/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackInterpolation.h index 4b74eaadf5d92..9cbcf3d117661 100644 --- a/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackInterpolation.h +++ b/Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackInterpolation.h @@ -60,11 +60,6 @@ struct TPCClusterResiduals { float snp{}; ///< sin of the phi angle between padrow and track unsigned char sec{}; ///< sector number 0..35 unsigned char dRow{}; ///< distance to previous row in units of pad rows - void setDY(float val) { dy = fabs(val) < param::MaxResid ? val : std::copysign(param::MaxResid, val); } - void setDZ(float val) { dz = fabs(val) < param::MaxResid ? val : std::copysign(param::MaxResid, val); } - void setY(float val) { y = fabs(val) < param::MaxY ? val : std::copysign(param::MaxY, val); } - void setZ(float val) { z = fabs(val) < param::MaxZ ? val : std::copysign(param::MaxZ, val); } - void setSnp(float val) { snp = fabs(val) < param::MaxTgSlp ? val : std::copysign(param::MaxTgSlp, val); } ClassDefNV(TPCClusterResiduals, 4); }; @@ -120,16 +115,16 @@ struct TrackDataExtended { /// Structure filled for each track with track quality information and a vector with TPCClusterResiduals struct TrackData { - o2::dataformats::GlobalTrackID gid{}; ///< global track ID for seeding track - o2::track::TrackPar par{}; ///< ITS track at inner TPC radius - float dEdxTPC{}; ///< TPC dEdx information - float chi2TPC{}; ///< chi2 of TPC track - float chi2ITS{}; ///< chi2 of ITS track - float chi2TRD{}; ///< chi2 of TRD track - unsigned short nClsTPC{}; ///< number of attached TPC clusters - unsigned short nClsITS{}; ///< number of attached ITS clusters - unsigned short nTrkltsTRD{}; ///< number of attached TRD tracklets - unsigned short clAvailTOF{}; ///< whether or not track seed has a matched TOF cluster + o2::dataformats::GlobalTrackID gid{}; ///< global track ID for seeding track + o2::track::TrackPar par{}; ///< ITS track at inner TPC radius + float dEdxTPC{}; ///< TPC dEdx information + float chi2TPC{}; ///< chi2 of TPC track + float chi2ITS{}; ///< chi2 of ITS track + float chi2TRD{}; ///< chi2 of TRD track + unsigned short nClsTPC{}; ///< number of attached TPC clusters + unsigned short nClsITS{}; ///< number of attached ITS clusters + unsigned short nTrkltsTRD{}; ///< number of attached TRD tracklets + unsigned short clAvailTOF{}; ///< whether or not track seed has a matched TOF cluster o2::dataformats::RangeReference<> clIdx{}; ///< index of first cluster residual and total number of cluster residuals of this track ClassDefNV(TrackData, 6); }; @@ -282,30 +277,30 @@ class TrackInterpolation static constexpr float sFloatEps{1.e-7f}; ///< float epsilon for robust linear fitting // parameters + settings const SpacePointsCalibConfParam* mParams = nullptr; - float mTPCTimeBinMUS{.2f}; ///< TPC time bin duration in us - float mTPCVDriftRef = -1.; ///< TPC nominal drift speed in cm/microseconds - float mTPCDriftTimeOffsetRef = 0.; ///< TPC nominal (e.g. at the start of run) drift time bias in cm/mus - float mSqrtS{13600.f}; ///< centre of mass energy set from LHC IF - MatCorrType mMatCorr{MatCorrType::USEMatCorrNONE}; ///< if material correction should be done - int mMaxTracksPerTF{-1}; ///< max number of tracks to be processed per TF (-1 means there is no limit) - int mAddTracksForMapPerTF{0}; ///< in case residuals from different track types are used for vDrift calibration and map creation this defines the statistics for the latter - bool mDumpTrackPoints{false}; ///< dump also track points in ITS, TRD and TOF - bool mProcessSeeds{false}; ///< in case for global tracks also their shorter parts are processed separately - bool mProcessITSTPConly{false}; ///< flag, whether or not to extrapolate ITS-only through TPC + float mTPCTimeBinMUS{.2f}; ///< TPC time bin duration in us + float mTPCVDriftRef = -1.; ///< TPC nominal drift speed in cm/microseconds + float mTPCDriftTimeOffsetRef = 0.; ///< TPC nominal (e.g. at the start of run) drift time bias in cm/mus + float mSqrtS{13600.f}; ///< centre of mass energy set from LHC IF + MatCorrType mMatCorr{MatCorrType::USEMatCorrNONE}; ///< if material correction should be done + int mMaxTracksPerTF{-1}; ///< max number of tracks to be processed per TF (-1 means there is no limit) + int mAddTracksForMapPerTF{0}; ///< in case residuals from different track types are used for vDrift calibration and map creation this defines the statistics for the latter + bool mDumpTrackPoints{false}; ///< dump also track points in ITS, TRD and TOF + bool mProcessSeeds{false}; ///< in case for global tracks also their shorter parts are processed separately + bool mProcessITSTPConly{false}; ///< flag, whether or not to extrapolate ITS-only through TPC o2::dataformats::GlobalTrackID::mask_t mSourcesConfigured; ///< the track sources taken into account for extra-/interpolation o2::dataformats::GlobalTrackID::mask_t mSourcesConfiguredMap; ///< possible subset of mSourcesConfigured bool mSingleSourcesConfigured{true}; ///< whether mSourcesConfigured == mSourcesConfiguredMap // input - const o2::globaltracking::RecoContainer* mRecoCont = nullptr; ///< input reco container - std::vector mGIDs{}; ///< GIDs of input tracks - std::vector mGIDtables{}; ///< GIDs of contributors from single detectors for each seed - std::vector mTrackTimes{}; ///< time estimates for all input tracks in micro seconds - std::vector mSeeds{}; ///< seeding track parameters (ITS tracks) - std::map mTrackTypes; ///< mapping of track source to array index in mTrackIndices - std::array, 4> mTrackIndices; ///< keep GIDs of input tracks separately for each track type - gsl::span mTPCTracksClusIdx; ///< input TPC cluster indices from span - const ClusterNativeAccess* mTPCClusterIdxStruct = nullptr; ///< struct holding the TPC cluster indices + const o2::globaltracking::RecoContainer* mRecoCont = nullptr; ///< input reco container + std::vector mGIDs{}; ///< GIDs of input tracks + std::vector mGIDtables{}; ///< GIDs of contributors from single detectors for each seed + std::vector mTrackTimes{}; ///< time estimates for all input tracks in micro seconds + std::vector mSeeds{}; ///< seeding track parameters (ITS tracks) + std::map mTrackTypes; ///< mapping of track source to array index in mTrackIndices + std::array, 4> mTrackIndices; ///< keep GIDs of input tracks separately for each track type + gsl::span mTPCTracksClusIdx; ///< input TPC cluster indices from span + const ClusterNativeAccess* mTPCClusterIdxStruct = nullptr; ///< struct holding the TPC cluster indices // ITS specific input only needed for debugging gsl::span mITSTrackClusIdx; ///< input ITS track cluster indices span std::vector> mITSClustersArray; ///< ITS clusters created in run() method from compact clusters @@ -329,6 +324,7 @@ class TrackInterpolation std::unique_ptr mFastTransform{}; ///< TPC cluster transformation float mBz; ///< required for helix approximation bool mInitDone{false}; ///< initialization done flag + size_t mRejectedResiduals{}; ///< number of rejected residuals ClassDefNV(TrackInterpolation, 1); }; diff --git a/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx b/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx index a32bf17fcd1c5..7c2110fd5b4e7 100644 --- a/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx +++ b/Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx @@ -334,7 +334,8 @@ void TrackInterpolation::process() extrapolateTrack(iSeed); } } - LOG(info) << "Could process " << mTrackData.size() << " tracks successfully"; + LOG(info) << "Could process " << mTrackData.size() << " tracks successfully. " << mRejectedResiduals << " residuals were rejected. " << mClRes.size() << " residuals were accepted."; + mRejectedResiduals = 0; } void TrackInterpolation::interpolateTrack(int iSeed) @@ -404,7 +405,7 @@ void TrackInterpolation::interpolateTrack(int iSeed) mCache[iRow].szy[ExtOut] = trkWork.getSigmaZY(); mCache[iRow].sz2[ExtOut] = trkWork.getSigmaZ2(); mCache[iRow].snp[ExtOut] = trkWork.getSnp(); - //printf("Track alpha at row %i: %.2f, Y(%.2f), Z(%.2f)\n", iRow, trkWork.getAlpha(), trkWork.getY(), trkWork.getZ()); + // printf("Track alpha at row %i: %.2f, Y(%.2f), Z(%.2f)\n", iRow, trkWork.getAlpha(), trkWork.getY(), trkWork.getZ()); } // start from outermost cluster with outer refit and back propagation @@ -431,7 +432,7 @@ void TrackInterpolation::interpolateTrack(int iSeed) // TODO: check if reset of covariance matrix is needed here (or, in case TOF point is not available at outermost TRD layer) if (!trkWork.update(clTOFYZ, clTOFCov)) { LOG(debug) << "Failed to update extrapolated ITS track with TOF cluster"; - //LOGF(info, "trkWork.y=%f, cl.y=%f, trkWork.z=%f, cl.z=%f", trkWork.getY(), clTOFYZ[0], trkWork.getZ(), clTOFYZ[1]); + // LOGF(info, "trkWork.y=%f, cl.y=%f, trkWork.z=%f, cl.z=%f", trkWork.getY(), clTOFYZ[0], trkWork.getZ(), clTOFYZ[1]); return; } } @@ -509,7 +510,7 @@ void TrackInterpolation::interpolateTrack(int iSeed) } if (!propagator->PropagateToXBxByBz(trkWork, param::RowX[iRow], mParams->maxSnp, mParams->maxStep, mMatCorr)) { LOG(debug) << "Failed on back propagation"; - //printf("trkX(%.2f), clX(%.2f), clY(%.2f), clZ(%.2f), alphaTOF(%.2f)\n", trkWork.getX(), param::RowX[iRow], clTOFYZ[0], clTOFYZ[1], clTOFAlpha); + // printf("trkX(%.2f), clX(%.2f), clY(%.2f), clZ(%.2f), alphaTOF(%.2f)\n", trkWork.getX(), param::RowX[iRow], clTOFYZ[0], clTOFYZ[1], clTOFAlpha); return; } mCache[iRow].y[ExtIn] = trkWork.getY(); @@ -535,15 +536,14 @@ void TrackInterpolation::interpolateTrack(int iSeed) // simple average w/o weighting for angle mCache[iRow].snp[Int] = (mCache[iRow].snp[ExtOut] + mCache[iRow].snp[ExtIn]) / 2.f; - TPCClusterResiduals res; - res.setDY(mCache[iRow].clY - mCache[iRow].y[Int]); - res.setDZ(mCache[iRow].clZ - mCache[iRow].z[Int]); - res.setY(mCache[iRow].y[Int]); - res.setZ(mCache[iRow].z[Int]); - res.setSnp(mCache[iRow].snp[Int]); - res.sec = mCache[iRow].clSec; - res.dRow = deltaRow; - clusterResiduals.push_back(std::move(res)); + const auto dY = mCache[iRow].clY - mCache[iRow].y[Int]; + const auto dZ = mCache[iRow].clZ - mCache[iRow].z[Int]; + const auto y = mCache[iRow].y[Int]; + const auto z = mCache[iRow].z[Int]; + const auto snp = mCache[iRow].snp[Int]; + const auto sec = mCache[iRow].clSec; + clusterResiduals.emplace_back(dY, dZ, y, z, snp, sec, deltaRow); + deltaRow = 1; } trackData.chi2TRD = gidTable[GTrackID::TRD].isIndexSet() ? mRecoCont->getITSTPCTRDTrack(gidTable[GTrackID::ITSTPCTRD]).getChi2() : 0; @@ -567,8 +567,17 @@ void TrackInterpolation::interpolateTrack(int iSeed) continue; } ++nClValidated; - float tgPhi = clusterResiduals[iCl].snp / std::sqrt((1.f - clusterResiduals[iCl].snp) * (1.f + clusterResiduals[iCl].snp)); - mClRes.emplace_back(clusterResiduals[iCl].dy, clusterResiduals[iCl].dz, tgPhi, clusterResiduals[iCl].y, clusterResiduals[iCl].z, iRow, clusterResiduals[iCl].sec); + const float tgPhi = clusterResiduals[iCl].snp / std::sqrt((1.f - clusterResiduals[iCl].snp) * (1.f + clusterResiduals[iCl].snp)); + const auto dy = clusterResiduals[iCl].dy; + const auto dz = clusterResiduals[iCl].dz; + const auto y = clusterResiduals[iCl].y; + const auto z = clusterResiduals[iCl].z; + const auto sec = clusterResiduals[iCl].sec; + if ((std::abs(dy) < param::MaxResid) && (std::abs(dz) < param::MaxResid) && (std::abs(y) < param::MaxY) && (std::abs(z) < param::MaxZ) && (std::abs(tgPhi) < param::MaxTgSlp)) { + mClRes.emplace_back(dy, dz, tgPhi, y, z, iRow, sec); + } else { + ++mRejectedResiduals; + } } trackData.clIdx.setEntries(nClValidated); mTrackData.push_back(std::move(trackData)); @@ -645,16 +654,17 @@ void TrackInterpolation::extrapolateTrack(int iSeed) if (!propagator->PropagateToXBxByBz(trkWork, x, mParams->maxSnp, mParams->maxStep, mMatCorr)) { return; } - TPCClusterResiduals res; - res.setDY(y - trkWork.getY()); - res.setDZ(z - trkWork.getZ()); - res.setY(trkWork.getY()); - res.setZ(trkWork.getZ()); - res.setSnp(trkWork.getSnp()); - res.sec = sector; - res.dRow = row - rowPrev; + + const auto dY = y - trkWork.getY(); + const auto dZ = z - trkWork.getZ(); + const auto ty = trkWork.getY(); + const auto tz = trkWork.getZ(); + const auto snp = trkWork.getSnp(); + const auto sec = sector; + + clusterResiduals.emplace_back(dY, dZ, ty, tz, snp, sec, row - rowPrev); + rowPrev = row; - clusterResiduals.push_back(std::move(res)); ++nMeasurements; } trackData.chi2TPC = trkTPC.getChi2(); @@ -683,8 +693,17 @@ void TrackInterpolation::extrapolateTrack(int iSeed) continue; } ++nClValidated; - float tgPhi = clusterResiduals[iCl].snp / std::sqrt((1.f - clusterResiduals[iCl].snp) * (1.f + clusterResiduals[iCl].snp)); - mClRes.emplace_back(clusterResiduals[iCl].dy, clusterResiduals[iCl].dz, tgPhi, clusterResiduals[iCl].y, clusterResiduals[iCl].z, iRow, clusterResiduals[iCl].sec); + const float tgPhi = clusterResiduals[iCl].snp / std::sqrt((1.f - clusterResiduals[iCl].snp) * (1.f + clusterResiduals[iCl].snp)); + const auto dy = clusterResiduals[iCl].dy; + const auto dz = clusterResiduals[iCl].dz; + const auto y = clusterResiduals[iCl].y; + const auto z = clusterResiduals[iCl].z; + const auto sec = clusterResiduals[iCl].sec; + if ((std::abs(dy) < param::MaxResid) && (std::abs(dz) < param::MaxResid) && (std::abs(y) < param::MaxY) && (std::abs(z) < param::MaxZ) && (std::abs(tgPhi) < param::MaxTgSlp)) { + mClRes.emplace_back(dy, dz, tgPhi, y, z, iRow, sec); + } else { + ++mRejectedResiduals; + } } trackData.clIdx.setEntries(nClValidated); mTrackData.push_back(std::move(trackData)); diff --git a/Detectors/TPC/workflow/src/CalibdEdxSpec.cxx b/Detectors/TPC/workflow/src/CalibdEdxSpec.cxx index 97b69156a2a6d..2eaf6125e6c29 100644 --- a/Detectors/TPC/workflow/src/CalibdEdxSpec.cxx +++ b/Detectors/TPC/workflow/src/CalibdEdxSpec.cxx @@ -134,7 +134,7 @@ class CalibdEdxDevice : public Task if (mDumpToFile) { mCalib->dumpToFile("calibdEdx_Obj.root", "calib"); - mCalib->getCalib().writeToFile("calibdEdx.root", "ccdb_object"); + mCalib->getCalib().writeToFile("calibdEdx.root"); if (mDumpToFile > 1) { mCalib->writeTTree("calibdEdx.histo.tree.root"); } diff --git a/Detectors/TPC/workflow/src/TPCRefitter.cxx b/Detectors/TPC/workflow/src/TPCRefitter.cxx index 211f14cfae184..3ebe32d12ddb8 100644 --- a/Detectors/TPC/workflow/src/TPCRefitter.cxx +++ b/Detectors/TPC/workflow/src/TPCRefitter.cxx @@ -637,6 +637,11 @@ bool TPCRefitterSpec::processTPCTrack(o2::tpc::TrackTPC tr, o2::MCCompLabel lbl, << "dcazRef=" << dcazRef; } + if (mUseMC) { + (*streamer) << "tpc" + << "mcLabel=" << lbl; + } + (*streamer) << "tpc" << "\n"; } diff --git a/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx b/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx index 264e7d8a98c60..78bf63a44d60f 100644 --- a/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx +++ b/Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx @@ -38,7 +38,8 @@ void customize(std::vector& workflowOptions) { // option allowing to set parameters std::vector options{ - {"enable-mc", o2::framework::VariantType::Bool, false, {"enable MC propagation"}}, + {"use-mc", o2::framework::VariantType::Bool, false, {"use MC information"}}, + {"disable-mc", o2::framework::VariantType::Bool, false, {"disable MC usage"}}, {"enable-cosmics", o2::framework::VariantType::Bool, false, {"enable reading cosmics"}}, {"track-sources", VariantType::String, std::string{GID::ALL}, {"comma-separated list of track sources to use"}}, {"cluster-sources", VariantType::String, std::string{GID::ALL}, {"comma-separated list of cluster sources to use"}}, @@ -61,7 +62,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext) // Update the (declared) parameters if changed from the command line o2::conf::ConfigurableParam::updateFromString(configcontext.options().get("configKeyValues")); - auto useMC = configcontext.options().get("enable-mc"); + auto useMC = configcontext.options().get("use-mc"); auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options()); const auto enableCosmics = configcontext.options().get("enable-cosmics");