Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions DataFormats/Detectors/TPC/src/CalibdEdxCorrection.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <string_view>

// o2 includes
#include "Framework/Logger.h"
#include "DataFormatsTPC/Defs.h"
#include "CommonUtils/TreeStreamRedirector.h"

Expand All @@ -39,15 +40,27 @@ void CalibdEdxCorrection::clear()
void CalibdEdxCorrection::writeToFile(std::string_view fileName, std::string_view objName) const
{
std::unique_ptr<TFile> 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<TFile> file(TFile::Open(fileName.data()));
if (!file || file->IsZombie()) {
LOGP(error, "Failed to open file {}", fileName.data());
return;
}

auto tmp = file->Get<CalibdEdxCorrection>(objName.data());
if (tmp != nullptr) {
*this = *tmp;
} else {
LOGP(error, "Failed to load object with name {} from file {}", objName.data(), fileName.data());
}
}

Expand Down
5 changes: 5 additions & 0 deletions Detectors/TPC/base/src/DeadChannelMapCreator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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);
};
Expand Down Expand Up @@ -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<o2::dataformats::GlobalTrackID> mGIDs{}; ///< GIDs of input tracks
std::vector<o2::globaltracking::RecoContainer::GlobalIDSet> mGIDtables{}; ///< GIDs of contributors from single detectors for each seed
std::vector<float> mTrackTimes{}; ///< time estimates for all input tracks in micro seconds
std::vector<o2::track::TrackParCov> mSeeds{}; ///< seeding track parameters (ITS tracks)
std::map<int, int> mTrackTypes; ///< mapping of track source to array index in mTrackIndices
std::array<std::vector<uint32_t>, 4> mTrackIndices; ///< keep GIDs of input tracks separately for each track type
gsl::span<const TPCClRefElem> 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<o2::dataformats::GlobalTrackID> mGIDs{}; ///< GIDs of input tracks
std::vector<o2::globaltracking::RecoContainer::GlobalIDSet> mGIDtables{}; ///< GIDs of contributors from single detectors for each seed
std::vector<float> mTrackTimes{}; ///< time estimates for all input tracks in micro seconds
std::vector<o2::track::TrackParCov> mSeeds{}; ///< seeding track parameters (ITS tracks)
std::map<int, int> mTrackTypes; ///< mapping of track source to array index in mTrackIndices
std::array<std::vector<uint32_t>, 4> mTrackIndices; ///< keep GIDs of input tracks separately for each track type
gsl::span<const TPCClRefElem> 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<const int> mITSTrackClusIdx; ///< input ITS track cluster indices span
std::vector<o2::BaseCluster<float>> mITSClustersArray; ///< ITS clusters created in run() method from compact clusters
Expand All @@ -329,6 +324,7 @@ class TrackInterpolation
std::unique_ptr<TPCFastTransform> 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);
};
Expand Down
71 changes: 45 additions & 26 deletions Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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();
Expand All @@ -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<o2::trd::TrackTRD>(gidTable[GTrackID::ITSTPCTRD]).getChi2() : 0;
Expand All @@ -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));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Detectors/TPC/workflow/src/CalibdEdxSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
5 changes: 5 additions & 0 deletions Detectors/TPC/workflow/src/TPCRefitter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
5 changes: 3 additions & 2 deletions Detectors/TPC/workflow/src/tpc-refitter-workflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
{
// option allowing to set parameters
std::vector<o2::framework::ConfigParamSpec> 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"}},
Expand All @@ -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<std::string>("configKeyValues"));
auto useMC = configcontext.options().get<bool>("enable-mc");
auto useMC = configcontext.options().get<bool>("use-mc");
auto sclOpt = o2::tpc::CorrectionMapsLoader::parseGlobalOptions(configcontext.options());
const auto enableCosmics = configcontext.options().get<bool>("enable-cosmics");

Expand Down