Skip to content

Commit

Permalink
add trk res in TOF match chi2
Browse files Browse the repository at this point in the history
  • Loading branch information
noferini committed May 8, 2024
1 parent b04a351 commit 1905aa5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ 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; }

private:
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
Expand Down
3 changes: 2 additions & 1 deletion Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class MatchTOF
///< per sector indices of track entry in mTracksWork
std::array<std::vector<int>, o2::constants::math::NSectors> mTracksSectIndexCache[trkType::SIZE];
std::array<std::vector<int>, o2::constants::math::NSectors> mTracksSeed[trkType::SIZE];
std::vector<float> mVZtpcOnly[o2::constants::math::NSectors];

std::vector<float> mExtraTPCFwdTime[o2::constants::math::NSectors]; ///< track extra params for TPC tracks: Fws Max time
std::vector<Cluster> mTOFClusWork; ///< track params prepared for matching
Expand Down Expand Up @@ -347,7 +348,7 @@ class MatchTOF
TStopwatch mTimerMatchITSTPC;
TStopwatch mTimerMatchTPC;
TStopwatch mTimerDBG;
ClassDefNV(MatchTOF, 5);
ClassDefNV(MatchTOF, 6);
};
} // namespace globaltracking
} // namespace o2
Expand Down
39 changes: 37 additions & 2 deletions Detectors/GlobalTracking/src/MatchTOF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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];
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -1076,6 +1093,7 @@ void MatchTOF::doMatchingForTPC(int sec)
std::vector<std::array<o2::track::TrackLTIntegral, 2>> trkLTInt;
std::vector<std::array<std::array<float, 3>, 2>> deltaPos;
std::vector<std::array<int, 2>> nStepsInsideSameStrip;
std::vector<std::array<float, 2>> Zshift;

LOG(debug) << "Trying to match %d tracks" << cacheTrk.size();

Expand All @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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];
Expand All @@ -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][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);
}
}
}
Expand Down

0 comments on commit 1905aa5

Please sign in to comment.