From 196966408584a911f93b6654e5f3c1f1df02ae8a Mon Sep 17 00:00:00 2001 From: noferini <9963644+noferini@users.noreply.github.com> Date: Sun, 21 Apr 2024 11:23:18 +0200 Subject: [PATCH] add trk res in TOF match chi2 --- .../ReconstructionDataFormats/MatchInfoTOF.h | 9 +++- .../MatchInfoTOFReco.h | 12 +++++- .../include/GlobalTracking/MatchTOF.h | 3 +- Detectors/GlobalTracking/src/MatchTOF.cxx | 41 +++++++++++++++++-- 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h index 29442325e2f66..c3cdae54823e6 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOF.h @@ -58,6 +58,11 @@ class MatchInfoTOF int getIdLocal() const { return mIdLocal; } + float getVz() const { return mVz; } + void setVz(float val) { mVz = val; } + int getChannel() const { return mChannel; } + void setChannel(int val) { mChannel = val; } + private: int mIdLocal; // track id in sector of the pair track-TOFcluster float mChi2; // chi2 of the pair track-TOFcluster @@ -69,8 +74,10 @@ class MatchInfoTOF float mDZatTOF = 0.0; ///< DZ position at TOF float mDeltaT = 0.0; ///< tTOF - TPC (microsec) double mSignal = 0.0; ///< TOF time in ps + float mVz = 0.0; ///< Vz from TOF match + int mChannel = -1; ///< channel - ClassDefNV(MatchInfoTOF, 5); + ClassDefNV(MatchInfoTOF, 6); }; } // namespace dataformats } // namespace o2 diff --git a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOFReco.h b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOFReco.h index aa955ca81c1c6..188b7b3ab121a 100644 --- a/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOFReco.h +++ b/DataFormats/Reconstruction/include/ReconstructionDataFormats/MatchInfoTOFReco.h @@ -45,6 +45,13 @@ class MatchInfoTOFReco : public MatchInfoTOF float pt() const { return mPt; } void setPt(float pt) { mPt = pt; } + void setResX(float val) { mResX = val; } + void setResZ(float val) { mResZ = val; } + void setResT(float val) { mResT = val; } + float getResX() const { return mResX; } + float getResZ() const { return mResZ; } + float getResT() const { return mResT; } + void setTrackType(TrackType value) { mTrackType = value; } TrackType getTrackType() const { return mTrackType; } @@ -52,7 +59,10 @@ class MatchInfoTOFReco : public MatchInfoTOF TrackType mTrackType; ///< track type (TPC, ITSTPC, TPCTRD, ITSTPCTRD) bool mFakeMC = false; float mPt = 0; - ClassDefNV(MatchInfoTOFReco, 4); + float mResX = 1; + float mResZ = 1; + float mResT = 1; + ClassDefNV(MatchInfoTOFReco, 5); }; } // namespace dataformats } // namespace o2 diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index 83f4dae0c2476..957ae07544cf4 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -309,6 +309,7 @@ class MatchTOF ///< per sector indices of track entry in mTracksWork std::array, o2::constants::math::NSectors> mTracksSectIndexCache[trkType::SIZE]; std::array, o2::constants::math::NSectors> mTracksSeed[trkType::SIZE]; + std::vector mVZtpcOnly[o2::constants::math::NSectors]; std::vector mExtraTPCFwdTime[o2::constants::math::NSectors]; ///< track extra params for TPC tracks: Fws Max time std::vector mTOFClusWork; ///< track params prepared for matching @@ -347,7 +348,7 @@ class MatchTOF TStopwatch mTimerMatchITSTPC; TStopwatch mTimerMatchTPC; TStopwatch mTimerDBG; - ClassDefNV(MatchTOF, 5); + ClassDefNV(MatchTOF, 6); }; } // namespace globaltracking } // namespace o2 diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index a384c489520fd..e2d96175796c0 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -701,6 +701,11 @@ void MatchTOF::addTPCSeed(const o2::tpc::TrackTPC& _tr, o2::dataformats::GlobalT o2::track::TrackLTIntegral intLT0; // mTPCTracksWork.back().getLTIntegralOut(); // we get the integrated length from TPC-ITC outward propagation // compute track length up to now mLTinfos[sector][trkType::UNCONS].emplace_back(intLT0); + float vz0 = _tr.getZAt(0, mBz); + if (abs(vz0) > 9000) { + vz0 = _tr.getZ() - _tr.getX() * _tr.getTgl(); + } + mVZtpcOnly[sector].push_back(vz0); /* const auto& trackTune = TrackTuneParams::Instance(); @@ -841,6 +846,8 @@ void MatchTOF::doMatching(int sec) // Printf("intLT (before doing anything): length = %f, time (Pion) = %f", intLT.getL(), intLT.getTOF(o2::track::PID::Pion)); float minTrkTime = (trackWork.second.getTimeStamp() - mSigmaTimeCut * trackWork.second.getTimeStampError()) * 1.E6 + timeShift; // minimum time in ps float maxTrkTime = (trackWork.second.getTimeStamp() + mSigmaTimeCut * trackWork.second.getTimeStampError()) * 1.E6 + timeShift + 100E3; // maximum time in ps + 100 ns for slow tracks (beta->0.2) + const float sqrt12inv = 1. / sqrt(12.); + float resT = (trackWork.second.getTimeStampError() + 100E-3) * sqrt12inv; int istep = 1; // number of steps float step = 1.0; // step size in cm @@ -1012,6 +1019,11 @@ void MatchTOF::doMatching(int sec) int eventIdTOF; int sourceIdTOF; for (auto iPropagation = 0; iPropagation < nStripsCrossedInPropagation; iPropagation++) { + float cosangle = TMath::Cos(Geo::getAngles(indices[1], indices[2]) * TMath::DegToRad()); + float errXinv2 = 1. / (trefTrk.getSigmaY2()); + float errZinv2 = 1. / (trefTrk.getSigmaZ2() * cosangle); // should be valid only at eta=0 + // look at getPadDxDyDz to understand how to convert track errors in TOF strip ref system (wip) + LOG(debug) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; LOG(debug) << "Propagated Track [" << itrk << "]: detId[" << iPropagation << "] = " << detId[iPropagation][0] << ", " << detId[iPropagation][1] << ", " << detId[iPropagation][2] << ", " << detId[iPropagation][3] << ", " << detId[iPropagation][4]; float resX = deltaPos[iPropagation][0] - (indices[4] - detId[iPropagation][4]) * Geo::XPAD + posCorr[0]; // readjusting the residuals due to the fact that the propagation fell in a pad that was not exactly the one of the cluster @@ -1028,7 +1040,7 @@ void MatchTOF::doMatching(int sec) if (indices[2] != detId[iPropagation][2]) { continue; } - float chi2 = res; // TODO: take into account also the time! + float chi2 = 0.5 * (resX * resX * errXinv2 + resZ * resZ * errZinv2); // TODO: take into account also the time! if (res < mSpaceTolerance) { // matching ok! LOG(debug) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[type][sec][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; @@ -1037,6 +1049,11 @@ void MatchTOF::doMatching(int sec) int eventIndexTOFCluster = mTOFClusSectIndexCache[indices[0]][itof]; mMatchedTracksPairsSec[sec].emplace_back(cacheTrk[itrk], eventIndexTOFCluster, mTOFClusWork[cacheTOF[itof]].getTime(), chi2, trkLTInt[iPropagation], mTrackGid[sec][type][cacheTrk[itrk]], type, (trefTOF.getTime() - (minTrkTime + maxTrkTime - 100E3) * 0.5) * 1E-6, trefTOF.getZ(), resX, resZ); // subracting 100 ns to max track which was artificially added mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setPt(pt); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setResX(sqrt(1. / errXinv2)); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setResZ(sqrt(1. / errZinv2)); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setResT(resT); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setVz(0.0); // not needed for constrained tracks + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setChannel(mainChannel); } } } @@ -1076,6 +1093,7 @@ void MatchTOF::doMatchingForTPC(int sec) std::vector> trkLTInt; std::vector, 2>> deltaPos; std::vector> nStepsInsideSameStrip; + std::vector> Zshift; LOG(debug) << "Trying to match %d tracks" << cacheTrk.size(); @@ -1097,6 +1115,8 @@ void MatchTOF::doMatchingForTPC(int sec) double minTrkTime = (tpctime - trackWork.second.getTimeStampError()) * 1.E6 + timeShift; // minimum time in ps minTrkTime = int(minTrkTime / BCgranularity) * BCgranularity; // align min to a BC double maxTrkTime = (tpctime + mExtraTPCFwdTime[sec][cacheTrk[itrk]]) * 1.E6 + timeShift; // maximum time in ps + const float sqrt12inv = 1. / sqrt(12.); + float resT = (maxTrkTime - minTrkTime) * sqrt12inv; if (mIsCosmics) { for (double tBC = minTrkTime; tBC < maxTrkTime; tBC += BCgranularity) { @@ -1147,6 +1167,8 @@ void MatchTOF::doMatchingForTPC(int sec) detId.reserve(BCcand.size()); trkLTInt.clear(); trkLTInt.reserve(BCcand.size()); + Zshift.clear(); + Zshift.reserve(BCcand.size()); deltaPos.clear(); deltaPos.reserve(BCcand.size()); nStepsInsideSameStrip.clear(); @@ -1209,6 +1231,8 @@ void MatchTOF::doMatchingForTPC(int sec) posFloat[2] = pos[2]; } + float ZshiftCurrent = posFloat[2] - pos[2]; + Geo::getPadDxDyDz(posFloat, detIdTemp, deltaPosTemp, sec); if (detIdTemp[2] == -1) { @@ -1238,6 +1262,7 @@ void MatchTOF::doMatchingForTPC(int sec) deltaPos[ibc][nStripsCrossedInPropagation[ibc] - 1][2] = deltaPosTemp[2]; trkLTInt[ibc][nStripsCrossedInPropagation[ibc] - 1] = intLT; + Zshift[ibc][nStripsCrossedInPropagation[ibc] - 1] = ZshiftCurrent; // Printf("intLT (after matching to strip %d): length = %f, time (Pion) = %f", nStripsCrossedInPropagation - 1, trkLTInt[nStripsCrossedInPropagation - 1].getL(), trkLTInt[nStripsCrossedInPropagation - 1].getTOF(o2::track::PID::Pion)); nStepsInsideSameStrip[ibc][nStripsCrossedInPropagation[ibc] - 1]++; } else { // a further propagation step in the same strip -> update info (we sum up on all matching with strip - we will divide for the number of steps a bit below) @@ -1337,6 +1362,10 @@ void MatchTOF::doMatchingForTPC(int sec) if (detId[ibc][iPropagation][1] != indices[1] || detId[ibc][iPropagation][2] != indices[2]) { continue; } + float cosangle = TMath::Cos(Geo::getAngles(indices[1], indices[2]) * TMath::DegToRad()); + float errXinv2 = 1. / (trefTrk.getSigmaY2()); + float errZinv2 = 1. / (trefTrk.getSigmaZ2() * cosangle); // should be valid only at eta=0 + // look at getPadDxDyDz to understand how to convert track errors in TOF strip ref system (wip) LOG(debug) << "TOF Cluster [" << itof << ", " << cacheTOF[itof] << "]: indices = " << indices[0] << ", " << indices[1] << ", " << indices[2] << ", " << indices[3] << ", " << indices[4]; LOG(debug) << "Propagated Track [" << itrk << "]: detId[" << iPropagation << "] = " << detId[ibc][iPropagation][0] << ", " << detId[ibc][iPropagation][1] << ", " << detId[ibc][iPropagation][2] << ", " << detId[ibc][iPropagation][3] << ", " << detId[ibc][iPropagation][4]; @@ -1360,15 +1389,21 @@ void MatchTOF::doMatchingForTPC(int sec) } LOG(debug) << "resX = " << resX << ", resZ = " << resZ << ", res = " << res; - float chi2 = mIsCosmics ? resX : res; // TODO: take into account also the time! + float chi2 = mIsCosmics ? resX : 0.5 * (resX * resX * errXinv2 + resZ * resZ * errZinv2); // TODO: take into account also the time! if (res < mSpaceTolerance) { // matching ok! LOG(debug) << "MATCHING FOUND: We have a match! between track " << mTracksSectIndexCache[trkType::UNCONS][sec][itrk] << " and TOF cluster " << mTOFClusSectIndexCache[indices[0]][itof]; foundCluster = true; // set event indexes (to be checked) + int eventIndexTOFCluster = mTOFClusSectIndexCache[indices[0]][itof]; - mMatchedTracksPairsSec[sec].emplace_back(cacheTrk[itrk], eventIndexTOFCluster, mTOFClusWork[cacheTOF[itof]].getTime(), chi2, trkLTInt[ibc][iPropagation], mTrackGid[sec][trkType::UNCONS][cacheTrk[itrk]], trkType::UNCONS, trefTOF.getTime() * 1E-6 - tpctime, trefTOF.getZ(), resX, resZ); // TODO: check if this is correct! + mMatchedTracksPairsSec[sec].emplace_back(cacheTrk[itrk], eventIndexTOFCluster, mTOFClusWork[cacheTOF[itof]].getTime(), chi2, trkLTInt[ibc][iPropagation], mTrackGid[sec][trkType::UNCONS][cacheTrk[itrk]], trkType::UNCONS, deltat, trefTOF.getZ(), resX, resZ); // TODO: check if this is correct! mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setPt(pt); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setResX(sqrt(1. / errXinv2)); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setResZ(sqrt(1. / errZinv2)); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setResT(resT); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setVz(mVZtpcOnly[sec][itrk] + Zshift[ibc][iPropagation]); + mMatchedTracksPairsSec[sec][mMatchedTracksPairsSec[sec].size() - 1].setChannel(mainChannel); } } }