Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use recodata + ITS-V0 PV match #10460

Merged
merged 3 commits into from
Dec 12, 2022
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 @@ -19,16 +19,20 @@
#include <gsl/gsl>
#include <TLorentzVector.h>
#include "TMath.h"
#include "DataFormatsITSMFT/TopologyDictionary.h"
#include "StrangenessTracking/IndexTableUtils.h"
#include "StrangenessTracking/StrangenessTrackingConfigParam.h"
#include "ReconstructionDataFormats/PID.h"
#include "ReconstructionDataFormats/V0.h"
#include "ReconstructionDataFormats/Cascade.h"
#include "ReconstructionDataFormats/VtxTrackIndex.h"
#include "ReconstructionDataFormats/VtxTrackRef.h"

#include "DataFormatsITS/TrackITS.h"
#include "ITSBase/GeometryTGeo.h"
#include "ReconstructionDataFormats/Track.h"
#include "DataFormatsITSMFT/CompCluster.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"

#include "DetectorsVertexing/DCAFitterN.h"
#include "DetectorsBase/Propagator.h"
Expand Down Expand Up @@ -70,11 +74,12 @@ class StrangenessTracker
using GIndex = o2::dataformats::VtxTrackIndex;
using DCAFitter2 = o2::vertexing::DCAFitterN<2>;
using DCAFitter3 = o2::vertexing::DCAFitterN<3>;
using VBracket = o2::math_utils::Bracket<int>;

StrangenessTracker() = default;
~StrangenessTracker() = default;

void initialise();
void prepareITStracks();
void process();

std::vector<ClusAttachments>& getClusAttachments() { return mClusAttachments; };
Expand All @@ -83,6 +88,7 @@ class StrangenessTracker
float getBz() const { return mBz; }
void setBz(float d) { mBz = d; }
void setCorrType(const o2::base::PropagatorImpl<float>::MatCorrType& type) { mCorrType = type; }
void setConfigParams(const StrangenessTrackingParamConfig* params) { mStrParams = params; }

void setupFitters()
{
Expand All @@ -91,8 +97,9 @@ class StrangenessTracker
mFitterV0.setUseAbsDCA(true);
mFitter3Body.setUseAbsDCA(true);
}

bool loadData(gsl::span<const o2::its::TrackITS> InputITStracks, std::vector<ITSCluster>& InputITSclusters, gsl::span<const int> InputITSidxs, gsl::span<const V0> InputV0tracks, gsl::span<const Cascade> InputCascadeTracks, o2::its::GeometryTGeo* geomITS);
bool loadData(const o2::globaltracking::RecoContainer& recoData);
void clear();
void setClusterDictionary(const o2::itsmft::TopologyDictionary* d) { mDict = d; }
double calcV0alpha(const V0& v0);
std::vector<ITSCluster> getTrackClusters();
float getMatchingChi2(o2::track::TrackParCovF, const TrackITS ITSTrack, ITSCluster matchingClus);
Expand All @@ -103,6 +110,7 @@ class StrangenessTracker

protected:
gsl::span<const o2::its::TrackITS> mInputITStracks; // input ITS tracks
std::vector<VBracket> mITSvtxBrackets; // time brackets for ITS tracks
std::vector<int> mTracksIdxTable; // index table for ITS tracks
std::vector<ITSCluster> mInputITSclusters; // input ITS clusters
gsl::span<const int> mInputITSidxs; // input ITS track-cluster indexes
Expand All @@ -118,12 +126,12 @@ class StrangenessTracker

const StrangenessTrackingParamConfig* mStrParams = nullptr;
float mBz = -5; // Magnetic field
const o2::itsmft::TopologyDictionary* mDict = nullptr;

DCAFitter2 mFitterV0; // optional DCA Fitter for recreating V0 with hypertriton mass hypothesis
DCAFitter3 mFitter3Body; // optional DCA Fitter for final 3 Body refit

o2::base::PropagatorImpl<float>::MatCorrType mCorrType = o2::base::PropagatorImpl<float>::MatCorrType::USEMatCorrNONE; // use mat correction
o2::its::GeometryTGeo* mGeomITS; // ITS geometry
o2::base::PropagatorImpl<float>::MatCorrType mCorrType = o2::base::PropagatorImpl<float>::MatCorrType::USEMatCorrNONE; // use mat correction // ITS geometry

std::vector<o2::track::TrackParCovF> mDaughterTracks; // vector of daughter tracks
StrangeTrack mStrangeTrack; // structure containing updated mother and daughter track refs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ namespace strangeness_tracking
struct StrangenessTrackingParamConfig : public o2::conf::ConfigurableParamHelper<StrangenessTrackingParamConfig> {

// parameters
float mRadiusTolIB = .3; // Radius tolerance for matching V0s in the IB
float mRadiusTolOB = .1; // Radius tolerance for matching V0s in the OB
float mPhiBinSize = 0.1; // Phi bin size for the matching grid
float mEtaBinSize = 0.1; // Eta bin size for the matching grid
float mMinMotherClus = 3.; // minimum number of cluster to be attached to the mother
float mMaxChi2 = 50; // Maximum matching chi2
float mRadiusTolIB = .3; // Radius tolerance for matching V0s in the IB
float mRadiusTolOB = .1; // Radius tolerance for matching V0s in the OB
float mPhiBinSize = 0.1; // Phi bin size for the matching grid
float mEtaBinSize = 0.1; // Eta bin size for the matching grid
float mMinMotherClus = 3.; // minimum number of cluster to be attached to the mother
float mMaxChi2 = 50; // Maximum matching chi2
bool mVertexMatching = true; // Flag to enable/disable vertex matching

O2ParamDef(StrangenessTrackingParamConfig, "strtracker");
};
Expand Down
126 changes: 87 additions & 39 deletions Detectors/StrangenessTracking/tracking/src/StrangenessTracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,84 @@

#include <numeric>
#include "StrangenessTracking/StrangenessTracker.h"
#include "ITStracking/IOUtils.h"

namespace o2
{
namespace strangeness_tracking
{

bool StrangenessTracker::loadData(gsl::span<const o2::its::TrackITS> InputITStracks, std::vector<ITSCluster>& InputITSclusters, gsl::span<const int> InputITSidxs, gsl::span<const V0> InputV0tracks, gsl::span<const Cascade> InputCascadeTracks, o2::its::GeometryTGeo* geomITS)
void StrangenessTracker::clear()
{
mInputV0tracks = InputV0tracks;
mInputCascadeTracks = InputCascadeTracks;
mInputITStracks = InputITStracks;
mInputITSclusters = InputITSclusters;
mInputITSidxs = InputITSidxs;
LOG(info) << "all tracks loaded";
LOG(info) << "V0 tracks size: " << mInputV0tracks.size();
LOG(info) << "Cascade tracks size: " << mInputCascadeTracks.size();
LOG(info) << "ITS tracks size: " << mInputITStracks.size();
LOG(info) << "ITS clusters size: " << mInputITSclusters.size();
LOG(info) << "ITS idxs size: " << mInputITSidxs.size();
mGeomITS = geomITS;
setupFitters();
mDaughterTracks.clear();
mClusAttachments.clear();
mStrangeTrackVec.clear();
mTracksIdxTable.clear();
mSortedITStracks.clear();
mSortedITSindexes.clear();
mITSvtxBrackets.clear();
}

bool StrangenessTracker::loadData(const o2::globaltracking::RecoContainer& recoData)
{
clear();
mInputV0tracks = recoData.getV0s();
mInputCascadeTracks = recoData.getCascades();
mInputITStracks = recoData.getITSTracks();
mInputITSidxs = recoData.getITSTracksClusterRefs();

auto clusITS = recoData.getITSClusters();
auto clusPatt = recoData.getITSClustersPatterns();
auto pattIt = clusPatt.begin();
mInputITSclusters.reserve(clusITS.size());
o2::its::ioutils::convertCompactClusters(clusITS, pattIt, mInputITSclusters, mDict);

mITSvtxBrackets.resize(mInputITStracks.size());
for (int i = 0; i < mInputITStracks.size(); i++) {
mITSvtxBrackets[i] = {-1, -1};
}

// build time bracket for each ITS track
auto trackIndex = recoData.getPrimaryVertexMatchedTracks(); // Global ID's for associated tracks
auto vtxRefs = recoData.getPrimaryVertexMatchedTrackRefs(); // references from vertex to these track IDs

if (mStrParams->mVertexMatching) {
int nv = vtxRefs.size();
for (int iv = 0; iv < nv; iv++) {
const auto& vtref = vtxRefs[iv];
int it = vtref.getFirstEntry(), itLim = it + vtref.getEntries();
for (; it < itLim; it++) {
auto tvid = trackIndex[it];
if (!recoData.isTrackSourceLoaded(tvid.getSource()) || tvid.getSource() != GIndex::ITS) {
continue;
}
if (mITSvtxBrackets[tvid.getIndex()].getMin() == -1) {
mITSvtxBrackets[tvid.getIndex()].setMin(iv);
mITSvtxBrackets[tvid.getIndex()].setMax(iv);
} else {
mITSvtxBrackets[tvid.getIndex()].setMax(iv);
}
}
}
}

LOG(debug) << "V0 tracks size: " << mInputV0tracks.size();
LOG(debug) << "Cascade tracks size: " << mInputCascadeTracks.size();
LOG(debug) << "ITS tracks size: " << mInputITStracks.size();
LOG(debug) << "ITS idxs size: " << mInputITSidxs.size();
LOG(debug) << "ITS clusters size: " << mInputITSclusters.size();
LOG(debug) << "VtxRefs size: " << vtxRefs.size();

return true;
}

void StrangenessTracker::initialise()
void StrangenessTracker::prepareITStracks() // sort tracks by eta and phi and select only tracks with vertex matching
{
mTracksIdxTable.clear();
mSortedITStracks.clear();
mSortedITSindexes.clear();

for (int iTrack{0}; iTrack < mInputITStracks.size(); iTrack++) {
if (mStrParams->mVertexMatching && mITSvtxBrackets[iTrack].getMin() == -1) {
continue;
}
mSortedITStracks.push_back(mInputITStracks[iTrack]);
mSortedITSindexes.push_back(iTrack);
}
Expand All @@ -57,9 +104,6 @@ void StrangenessTracker::initialise()
}
std::exclusive_scan(mTracksIdxTable.begin(), mTracksIdxTable.begin() + mUtils.mPhiBins * mUtils.mEtaBins, mTracksIdxTable.begin(), 0);
mTracksIdxTable[mUtils.mPhiBins * mUtils.mEtaBins] = mSortedITStracks.size();

// create config param instance
mStrParams = &StrangenessTrackingParamConfig::Instance();
}

void StrangenessTracker::process()
Expand Down Expand Up @@ -92,8 +136,12 @@ void StrangenessTracker::process()
mDaughterTracks[0] = correctedV0.getProng(0);
mDaughterTracks[1] = correctedV0.getProng(1);
mITStrack = mSortedITStracks[iTrack];

auto& ITSindexRef = mSortedITSindexes[iTrack];
LOG(debug) << "V0 pos: " << v0.getProngID(0) << " V0 neg: " << v0.getProngID(1) << ", ITS track ref: " << mSortedITSindexes[iTrack];
if (mStrParams->mVertexMatching && (mITSvtxBrackets[ITSindexRef].getMin() > v0.getVertexID() ||
mITSvtxBrackets[ITSindexRef].getMax() < v0.getVertexID())) {
continue;
}

if (matchDecayToITStrack(sqrt(v0R2))) {
LOG(debug) << "ITS Track matched with a V0 decay topology ....";
Expand Down Expand Up @@ -129,6 +177,13 @@ void StrangenessTracker::process()
auto& ITSindexRef = mSortedITSindexes[iTrack];
LOG(debug) << "----------------------";
LOG(debug) << "CascV0: " << casc.getV0ID() << ", Bach ID: " << casc.getBachelorID() << ", ITS track ref: " << mSortedITSindexes[iTrack];

if (mStrParams->mVertexMatching && (mITSvtxBrackets[ITSindexRef].getMin() > casc.getVertexID() ||
mITSvtxBrackets[ITSindexRef].getMax() < casc.getVertexID())) {
LOG(debug) << "Vertex ID mismatch: " << mITSvtxBrackets[ITSindexRef].getMin() << " < " << casc.getVertexID() << " < " << mITSvtxBrackets[ITSindexRef].getMax();
continue;
}

if (matchDecayToITStrack(sqrt(cascR2))) {
LOG(debug) << "ITS Track matched with a Cascade decay topology ....";
LOG(debug) << "Number of ITS track clusters attached: " << mITStrack.getNumberOfClusters();
Expand All @@ -144,7 +199,7 @@ void StrangenessTracker::process()

bool StrangenessTracker::matchDecayToITStrack(float decayR)
{

auto geom = o2::its::GeometryTGeo::Instance();
auto trackClusters = getTrackClusters();
auto& lastClus = trackClusters[0];
mStrangeTrack.mMatchChi2 = getMatchingChi2(mStrangeTrack.mMother, mITStrack, lastClus);
Expand All @@ -164,13 +219,12 @@ bool StrangenessTracker::matchDecayToITStrack(float decayR)
auto diffR = decayR - clusRad;
auto relDiffR = diffR / decayR;
// Look for the Mother if the Decay radius allows for it, within a tolerance
LOG(debug) << "++++++++";
LOG(debug) << "decayR: " << decayR << ", diffR: " << diffR << ", clus rad: " << clusRad << ", radTol: " << radTol;
if (relDiffR > -radTol) {
LOG(debug) << "Try to attach cluster to Mother, layer: " << mGeomITS->getLayer(clus.getSensorID());
LOG(debug) << "Try to attach cluster to Mother, layer: " << geom->getLayer(clus.getSensorID());
if (updateTrack(clus, mStrangeTrack.mMother)) {
motherClusters.push_back(clus);
nAttachments[mGeomITS->getLayer(clus.getSensorID())] = 0;
nAttachments[geom->getLayer(clus.getSensorID())] = 0;
isMotherUpdated = true;
nUpdates++;
LOG(debug) << "Cluster attached to Mother";
Expand All @@ -181,11 +235,11 @@ bool StrangenessTracker::matchDecayToITStrack(float decayR)
// if Mother is not found, check for V0 daughters compatibility
if (relDiffR < radTol && !isMotherUpdated) {
bool isDauUpdated = false;
LOG(debug) << "Try to attach cluster to Daughters, layer: " << mGeomITS->getLayer(clus.getSensorID());
LOG(debug) << "Try to attach cluster to Daughters, layer: " << geom->getLayer(clus.getSensorID());
for (int iDau{0}; iDau < mDaughterTracks.size(); iDau++) {
auto& dauTrack = mDaughterTracks[iDau];
if (updateTrack(clus, dauTrack)) {
nAttachments[mGeomITS->getLayer(clus.getSensorID())] = iDau + 1;
nAttachments[geom->getLayer(clus.getSensorID())] = iDau + 1;
isDauUpdated = true;
break;
}
Expand Down Expand Up @@ -264,26 +318,19 @@ bool StrangenessTracker::matchDecayToITStrack(float decayR)

bool StrangenessTracker::updateTrack(const ITSCluster& clus, o2::track::TrackParCov& track)
{
auto geom = o2::its::GeometryTGeo::Instance();
auto propInstance = o2::base::Propagator::Instance();
float alpha = mGeomITS->getSensorRefAlpha(clus.getSensorID()), x = clus.getX();
int layer{mGeomITS->getLayer(clus.getSensorID())};

auto stringOld = track.asString();
LOG(debug) << "Track before update, Y2: " << track.getSigmaY2() << ", Z2: " << track.getSigmaZ2();
float alpha = geom->getSensorRefAlpha(clus.getSensorID()), x = clus.getX();
int layer{geom->getLayer(clus.getSensorID())};

if (!track.rotate(alpha)) {
return false;
}

LOG(debug) << "Track rotated, Y2: " << track.getSigmaY2() << ", Z2: " << track.getSigmaZ2();

if (!propInstance->propagateToX(track, x, getBz(), o2::base::PropagatorImpl<float>::MAX_SIN_PHI, o2::base::PropagatorImpl<float>::MAX_STEP, mCorrType)) {
return false;
}

auto stringNew = track.asString();
LOG(debug) << "Track after propagation, Y2: " << track.getSigmaY2() << ", Z2: " << track.getSigmaZ2();

if (mCorrType == o2::base::PropagatorF::MatCorrType::USEMatCorrNONE) {
float thick = layer < 3 ? 0.005 : 0.01;
constexpr float radl = 9.36f; // Radiation length of Si [cm]
Expand Down Expand Up @@ -344,7 +391,8 @@ std::vector<o2::strangeness_tracking::StrangenessTracker::ITSCluster> Strangenes

float StrangenessTracker::getMatchingChi2(o2::track::TrackParCovF v0, const TrackITS ITStrack, ITSCluster matchingClus)
{
float alpha = mGeomITS->getSensorRefAlpha(matchingClus.getSensorID()), x = matchingClus.getX();
auto geom = o2::its::GeometryTGeo::Instance();
float alpha = geom->getSensorRefAlpha(matchingClus.getSensorID()), x = matchingClus.getX();
if (v0.rotate(alpha)) {
if (v0.propagateTo(x, mBz)) {
return v0.getPredictedChi2(ITStrack.getParamOut());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "DetectorsBase/GRPGeomHelper.h"
#include "ITSMFTReconstruction/ClustererParam.h"
#include "DataFormatsITSMFT/TopologyDictionary.h"
#include "DataFormatsGlobalTracking/RecoContainer.h"
#include "ReconstructionDataFormats/GlobalTrackID.h"

#include "TStopwatch.h"

Expand All @@ -35,15 +37,16 @@ class StrangenessTrackerSpec : public framework::Task
{
public:
using ITSCluster = o2::BaseCluster<float>;
using DataRequest = o2::globaltracking::DataRequest;
using GTrackID = o2::dataformats::GlobalTrackID;

StrangenessTrackerSpec(std::shared_ptr<o2::base::GRPGeomRequest> gr, bool isMC);
StrangenessTrackerSpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, bool isMC);
~StrangenessTrackerSpec() override = default;

void init(framework::InitContext& ic) final;
void run(framework::ProcessingContext& pc) final;
void endOfStream(framework::EndOfStreamContext& ec) final;
void finaliseCCDB(framework::ConcreteDataMatcher& matcher, void* obj) final;
void setClusterDictionary(const o2::itsmft::TopologyDictionary* d) { mDict = d; }

private:
void updateTimeDependentParams(framework::ProcessingContext& pc);
Expand All @@ -52,11 +55,11 @@ class StrangenessTrackerSpec : public framework::Task
TStopwatch mTimer;
StrangenessTracker mTracker;
std::shared_ptr<o2::base::GRPGeomRequest> mGGCCDBRequest;
std::shared_ptr<DataRequest> mDataRequest;
std::unique_ptr<parameters::GRPObject> mGRP = nullptr;
const o2::itsmft::TopologyDictionary* mDict = nullptr;
};

o2::framework::DataProcessorSpec getStrangenessTrackerSpec();
o2::framework::DataProcessorSpec getStrangenessTrackerSpec(o2::dataformats::GlobalTrackID::mask_t src);
o2::framework::WorkflowSpec getWorkflow(bool upstreamClusters = false, bool upstreamV0s = false);

} // namespace strangeness_tracking
Expand Down
Loading