diff --git a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h index db0abf1233e00..6e48b445beb4a 100644 --- a/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h +++ b/Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h @@ -90,7 +90,7 @@ class MatchTOF public: ///< perform matching for provided input - void run(const o2::globaltracking::RecoContainer& inp); + void run(const o2::globaltracking::RecoContainer& inp, unsigned long firstTForbit = 0); void setCosmics() { @@ -216,8 +216,8 @@ class MatchTOF void doMatching(int sec); void doMatchingForTPC(int sec); void selectBestMatches(); - static void BestMatches(std::vector& matchedTracksPairs, std::vector* matchedTracks, std::vector* matchedTracksIndex, int* matchedClustersIndex, const gsl::span& FITRecPoints, const std::vector& TOFClusWork, const std::vector* TracksWork, std::vector& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer* TOFClusLabels, const std::vector* TracksLblWork, std::vector* OutTOFLabels, float calibMaxChi2); - static void BestMatchesHP(std::vector& matchedTracksPairs, std::vector* matchedTracks, std::vector* matchedTracksIndex, int* matchedClustersIndex, const gsl::span& FITRecPoints, const std::vector& TOFClusWork, std::vector& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer* TOFClusLabels, const std::vector* TracksLblWork, std::vector* OutTOFLabels); + void BestMatches(std::vector& matchedTracksPairs, std::vector* matchedTracks, std::vector* matchedTracksIndex, int* matchedClustersIndex, const gsl::span& FITRecPoints, const std::vector& TOFClusWork, const std::vector* TracksWork, std::vector& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer* TOFClusLabels, const std::vector* TracksLblWork, std::vector* OutTOFLabels, float calibMaxChi2); + void BestMatchesHP(std::vector& matchedTracksPairs, std::vector* matchedTracks, std::vector* matchedTracksIndex, int* matchedClustersIndex, const gsl::span& FITRecPoints, const std::vector& TOFClusWork, std::vector& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer* TOFClusLabels, const std::vector* TracksLblWork, std::vector* OutTOFLabels); bool propagateToRefX(o2::track::TrackParCov& trc, float xRef /*in cm*/, float stepInCm /*in cm*/, o2::track::TrackLTIntegral& intLT); bool propagateToRefXWithoutCov(o2::track::TrackParCov& trc, float xRef /*in cm*/, float stepInCm /*in cm*/, float bz); @@ -269,6 +269,8 @@ class MatchTOF unsigned long mTimestamp = 0; ///< in ms + static unsigned long mFirstTForbit; ///< First orbit in TF (needed to align FT0 recpoints) + // from ruben gsl::span mTPCTracksArray; ///< input TPC tracks span diff --git a/Detectors/GlobalTracking/src/MatchTOF.cxx b/Detectors/GlobalTracking/src/MatchTOF.cxx index 9cebaa73e24df..e5d994ed48126 100644 --- a/Detectors/GlobalTracking/src/MatchTOF.cxx +++ b/Detectors/GlobalTracking/src/MatchTOF.cxx @@ -53,11 +53,15 @@ using Cluster = o2::tof::Cluster; using GTrackID = o2::dataformats::GlobalTrackID; using timeEst = o2::dataformats::TimeStampWithError; +unsigned long MatchTOF::mFirstTForbit = 0; + ClassImp(MatchTOF); //______________________________________________ -void MatchTOF::run(const o2::globaltracking::RecoContainer& inp) +void MatchTOF::run(const o2::globaltracking::RecoContainer& inp, unsigned long firstTForbit) { + mFirstTForbit = firstTForbit; + if (!mMatchParams) { mMatchParams = &o2::globaltracking::MatchTOFParams::Instance(); mSigmaTimeCut = mMatchParams->nsigmaTimeCut; @@ -1185,16 +1189,18 @@ void MatchTOF::doMatchingForTPC(int sec) //______________________________________________ int MatchTOF::findFITIndex(int bc, const gsl::span& FITRecPoints) { + bc -= o2::tof::Geo::LATENCYWINDOW_IN_BC; + if (FITRecPoints.size() == 0) { return -1; } int index = -1; - int distMax = 5; // require bc distance below 5 + int distMax = 7; // require bc distance below 5 for (unsigned int i = 0; i < FITRecPoints.size(); i++) { const o2::InteractionRecord ir = FITRecPoints[i].getInteractionRecord(); - int bct0 = ir.orbit * o2::constants::lhc::LHCMaxBunches + ir.bc; + int bct0 = (ir.orbit - mFirstTForbit) * o2::constants::lhc::LHCMaxBunches + ir.bc; int dist = bc - bct0; if (dist < 0 || dist > distMax) { @@ -1254,14 +1260,15 @@ void MatchTOF::BestMatches(std::vector& match const o2::track::TrackLTIntegral& intLT = matchingPair.getLTIntegralOut(); - if (FITRecPoints.size() > 0) { - int index = findFITIndex(TOFClusWork[matchingPair.getTOFClIndex()].getBC(), FITRecPoints); + if (FITRecPoints.size() > 0 && mIsFIT) { + int index = findFITIndex(TOFClusWork[matchingPair.getTOFClIndex()].getBC() - o2::tof::Geo::LATENCYWINDOW_IN_BC, FITRecPoints); if (index > -1) { o2::InteractionRecord ir = FITRecPoints[index].getInteractionRecord(); - t0info = ir.bc2ns() * 1E3; + int bct0 = (ir.orbit - mFirstTForbit) * o2::constants::lhc::LHCMaxBunches + ir.bc; + t0info = bct0 * o2::tof::Geo::BC_TIME_INPS; } - } else { // move time to time in orbit to avoid loss of precision when truncating from double to float + } else if (!mIsFIT) { // move time to time in orbit to avoid loss of precision when truncating from double to float int bcStarOrbit = int((TOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - intLT.getTOF(o2::track::PID::Pion)) * o2::tof::Geo::BC_TIME_INPS_INV); bcStarOrbit = (bcStarOrbit / o2::constants::lhc::LHCMaxBunches) * o2::constants::lhc::LHCMaxBunches; // truncation t0info = bcStarOrbit * o2::tof::Geo::BC_TIME_INPS; @@ -1280,7 +1287,14 @@ void MatchTOF::BestMatches(std::vector& match } int mask = 0; - float deltat = o2::tof::Utils::subtractInteractionBC(TOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - t0info - intLT.getTOF(o2::track::PID::Pion), mask, true); + float deltat; + + if (t0info > 0 && mIsFIT) { // FT0 BC found + deltat = TOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - t0info - intLT.getTOF(o2::track::PID::Pion) - o2::tof::Geo::LATENCYWINDOW_IN_BC * o2::tof::Geo::BC_TIME_INPS; // latency subtracted + mask = 1 << 8; // only FT0 BC allowed (-> BC=0 since t0info already subtracted and assumed to be aligned to the true IntBC) + } else if (!mIsFIT) { + deltat = o2::tof::Utils::subtractInteractionBC(TOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - t0info - intLT.getTOF(o2::track::PID::Pion), mask, true); + } const o2::track::TrackParCov& trc = TracksWork[trkType][itrk].first; float pt = trc.getPt(); // from outer parameters! @@ -1301,7 +1315,7 @@ void MatchTOF::BestMatches(std::vector& match flags = flags | o2::dataformats::CalibInfoTOF::kMultiHit; } - if (matchingPair.getChi2() < calibMaxChi2) { // extra cut in ChiSquare for storing calib info + if (matchingPair.getChi2() < calibMaxChi2 && t0info > 0) { // extra cut in ChiSquare for storing calib info CalibInfoTOF.emplace_back(TOFClusWork[matchingPair.getTOFClIndex()].getMainContributingChannel(), Timestamp / 1000 + int(TOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() * 1E-12), // add time stamp deltat, @@ -1394,12 +1408,13 @@ void MatchTOF::BestMatchesHP(std::vector& mat // get fit info double t0info = 0; - if (FITRecPoints.size() > 0) { - int index = findFITIndex(TOFClusWork[matchingPair.getTOFClIndex()].getBC(), FITRecPoints); + if (FITRecPoints.size() > 0 && mIsFIT) { + int index = findFITIndex(TOFClusWork[matchingPair.getTOFClIndex()].getBC() - o2::tof::Geo::LATENCYWINDOW_IN_BC, FITRecPoints); if (index > -1) { o2::InteractionRecord ir = FITRecPoints[index].getInteractionRecord(); - t0info = ir.bc2ns() * 1E3; + int bct0 = (ir.orbit - mFirstTForbit) * o2::constants::lhc::LHCMaxBunches + ir.bc; + t0info = bct0 * o2::tof::Geo::BC_TIME_INPS; } } else { // move time to time in orbit to avoid loss of precision when truncating from double to float int bcStarOrbit = int((TOFClusWork[matchingPair.getTOFClIndex()].getTimeRaw() - intLT.getTOF(o2::track::PID::Pion)) * o2::tof::Geo::BC_TIME_INPS_INV); diff --git a/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx b/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx index 5b81466363710..a235242750ba3 100644 --- a/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx +++ b/Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx @@ -165,7 +165,7 @@ void TOFMatcherSpec::run(ProcessingContext& pc) mMatcher.setTS(creationTime); - mMatcher.run(recoData); + mMatcher.run(recoData, pc.services().get().firstTForbit); if (isTPCused) { pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe}, mMatcher.getMatchedTrackVector(o2::dataformats::MatchInfoTOFReco::TrackType::TPC)); @@ -248,7 +248,7 @@ DataProcessorSpec getTOFMatcherSpec(GID::mask_t src, bool useMC, bool useFIT, bo dataRequest->requestTracks(src, useMC); dataRequest->requestClusters(GID::getSourceMask(GID::TOF), useMC); if (useFIT) { - dataRequest->requestClusters(GID::getSourceMask(GID::FT0), false); + dataRequest->requestFT0RecPoints(false); } auto ggRequest = std::make_shared(false, // orbitResetTime diff --git a/Detectors/GlobalTrackingWorkflow/tofworkflow/src/tof-calibinfo-reader.cxx b/Detectors/GlobalTrackingWorkflow/tofworkflow/src/tof-calibinfo-reader.cxx index e9e7db4e6f339..27a48d93dac8b 100644 --- a/Detectors/GlobalTrackingWorkflow/tofworkflow/src/tof-calibinfo-reader.cxx +++ b/Detectors/GlobalTrackingWorkflow/tofworkflow/src/tof-calibinfo-reader.cxx @@ -74,8 +74,8 @@ WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) auto listname = cfgc.options().get("collection-infile"); auto toftpc = cfgc.options().get("tpc-matches"); - char* stringTBP = new char[listname.size()]; - snprintf(stringTBP, listname.size(), "%s", listname.c_str()); + char* stringTBP = new char[listname.size() + 1]; + snprintf(stringTBP, listname.size() + 1, "%s", listname.c_str()); // the lane configuration defines the subspecification ids to be distributed among the lanes. // auto tofSectors = o2::RangeTokenizer::tokenize(cfgc.options().get("tof-sectors")); diff --git a/Detectors/TOF/base/src/Utils.cxx b/Detectors/TOF/base/src/Utils.cxx index 02d0621c09752..265cb0247b544 100644 --- a/Detectors/TOF/base/src/Utils.cxx +++ b/Detectors/TOF/base/src/Utils.cxx @@ -272,14 +272,28 @@ int Utils::addMaskBC(int mask, int channel) int mask2 = (mask >> 16); int cmask = 1; int used = 0; + int weight = 1; + int candidates = 0; + for (int ibit = 0; ibit < 16; ibit++) { // counts candidates + if (mask & cmask) { + candidates++; + } + cmask *= 2; + } + + if (candidates) { + weight = 16 / candidates; + } + + cmask = 1; for (int ibit = 0; ibit < 16; ibit++) { if (mask & cmask) { - mMaskBCchan[channel][ibit]++; - mMaskBC[ibit]++; + mMaskBCchan[channel][ibit] += weight; + mMaskBC[ibit] += weight; } if (mask2 & cmask) { - mMaskBCchanUsed[channel][ibit]++; - mMaskBCUsed[ibit]++; + mMaskBCchanUsed[channel][ibit] += weight; + mMaskBCUsed[ibit] += weight; used = ibit - 8; } cmask *= 2;