Skip to content

Commit

Permalink
adjusting TOF calib info alignment to BC
Browse files Browse the repository at this point in the history
  • Loading branch information
noferini committed Sep 18, 2023
1 parent 8e4388b commit 3a79a2c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
8 changes: 5 additions & 3 deletions Detectors/GlobalTracking/include/GlobalTracking/MatchTOF.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -216,8 +216,8 @@ class MatchTOF
void doMatching(int sec);
void doMatchingForTPC(int sec);
void selectBestMatches();
static void BestMatches(std::vector<o2::dataformats::MatchInfoTOFReco>& matchedTracksPairs, std::vector<o2::dataformats::MatchInfoTOF>* matchedTracks, std::vector<int>* matchedTracksIndex, int* matchedClustersIndex, const gsl::span<const o2::ft0::RecPoints>& FITRecPoints, const std::vector<Cluster>& TOFClusWork, const std::vector<matchTrack>* TracksWork, std::vector<o2::dataformats::CalibInfoTOF>& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer<o2::MCCompLabel>* TOFClusLabels, const std::vector<o2::MCCompLabel>* TracksLblWork, std::vector<o2::MCCompLabel>* OutTOFLabels, float calibMaxChi2);
static void BestMatchesHP(std::vector<o2::dataformats::MatchInfoTOFReco>& matchedTracksPairs, std::vector<o2::dataformats::MatchInfoTOF>* matchedTracks, std::vector<int>* matchedTracksIndex, int* matchedClustersIndex, const gsl::span<const o2::ft0::RecPoints>& FITRecPoints, const std::vector<Cluster>& TOFClusWork, std::vector<o2::dataformats::CalibInfoTOF>& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer<o2::MCCompLabel>* TOFClusLabels, const std::vector<o2::MCCompLabel>* TracksLblWork, std::vector<o2::MCCompLabel>* OutTOFLabels);
void BestMatches(std::vector<o2::dataformats::MatchInfoTOFReco>& matchedTracksPairs, std::vector<o2::dataformats::MatchInfoTOF>* matchedTracks, std::vector<int>* matchedTracksIndex, int* matchedClustersIndex, const gsl::span<const o2::ft0::RecPoints>& FITRecPoints, const std::vector<Cluster>& TOFClusWork, const std::vector<matchTrack>* TracksWork, std::vector<o2::dataformats::CalibInfoTOF>& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer<o2::MCCompLabel>* TOFClusLabels, const std::vector<o2::MCCompLabel>* TracksLblWork, std::vector<o2::MCCompLabel>* OutTOFLabels, float calibMaxChi2);
void BestMatchesHP(std::vector<o2::dataformats::MatchInfoTOFReco>& matchedTracksPairs, std::vector<o2::dataformats::MatchInfoTOF>* matchedTracks, std::vector<int>* matchedTracksIndex, int* matchedClustersIndex, const gsl::span<const o2::ft0::RecPoints>& FITRecPoints, const std::vector<Cluster>& TOFClusWork, std::vector<o2::dataformats::CalibInfoTOF>& CalibInfoTOF, unsigned long Timestamp, bool MCTruthON, const o2::dataformats::MCTruthContainer<o2::MCCompLabel>* TOFClusLabels, const std::vector<o2::MCCompLabel>* TracksLblWork, std::vector<o2::MCCompLabel>* 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);

Expand Down Expand Up @@ -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<const o2::tpc::TrackTPC> mTPCTracksArray; ///< input TPC tracks span

Expand Down
39 changes: 27 additions & 12 deletions Detectors/GlobalTracking/src/MatchTOF.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ using Cluster = o2::tof::Cluster;
using GTrackID = o2::dataformats::GlobalTrackID;
using timeEst = o2::dataformats::TimeStampWithError<float, float>;

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;
Expand Down Expand Up @@ -1185,16 +1189,18 @@ void MatchTOF::doMatchingForTPC(int sec)
//______________________________________________
int MatchTOF::findFITIndex(int bc, const gsl::span<const o2::ft0::RecPoints>& 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) {
Expand Down Expand Up @@ -1254,14 +1260,15 @@ void MatchTOF::BestMatches(std::vector<o2::dataformats::MatchInfoTOFReco>& 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;
Expand All @@ -1280,7 +1287,14 @@ void MatchTOF::BestMatches(std::vector<o2::dataformats::MatchInfoTOFReco>& 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!
Expand All @@ -1301,7 +1315,7 @@ void MatchTOF::BestMatches(std::vector<o2::dataformats::MatchInfoTOFReco>& 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,
Expand Down Expand Up @@ -1394,12 +1408,13 @@ void MatchTOF::BestMatchesHP(std::vector<o2::dataformats::MatchInfoTOFReco>& 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);
Expand Down
4 changes: 2 additions & 2 deletions Detectors/GlobalTrackingWorkflow/src/TOFMatcherSpec.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void TOFMatcherSpec::run(ProcessingContext& pc)

mMatcher.setTS(creationTime);

mMatcher.run(recoData);
mMatcher.run(recoData, pc.services().get<o2::framework::TimingInfo>().firstTForbit);

if (isTPCused) {
pc.outputs().snapshot(Output{o2::header::gDataOriginTOF, "MTC_TPC", ss, Lifetime::Timeframe}, mMatcher.getMatchedTrackVector(o2::dataformats::MatchInfoTOFReco::TrackType::TPC));
Expand Down Expand Up @@ -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<o2::base::GRPGeomRequest>(false, // orbitResetTime
Expand Down
22 changes: 18 additions & 4 deletions Detectors/TOF/base/src/Utils.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3a79a2c

Please sign in to comment.