Skip to content
Merged
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
103 changes: 84 additions & 19 deletions PWGDQ/Tasks/mftMchMatcher.cxx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.

Check failure on line 1 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/workflow-file]

Name of a workflow file must match the name of the main struct in it (without the PWG prefix). (Class implementation files should be in "Core" directories.)
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
Expand Down Expand Up @@ -48,6 +48,7 @@
#include <RtypesCore.h>

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <map>
#include <memory>
Expand Down Expand Up @@ -142,9 +143,10 @@
DECLARE_SOA_COLUMN(Chi2Glob, chi2Glob, float);
DECLARE_SOA_COLUMN(Chi2Match, chi2Match, float);
DECLARE_SOA_COLUMN(IsAmbig, isAmbig, bool);
DECLARE_SOA_COLUMN(MFTMult, mftMult, int);

Check failure on line 146 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/o2-column]

Use UpperCamelCase for names of O2 columns and matching lowerCamelCase names for their getters.
DECLARE_SOA_COLUMN(MatchAttempts, matchAttempts, int);
DECLARE_SOA_COLUMN(DCAX, dcaX, float);

Check failure on line 148 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/o2-column]

Use UpperCamelCase for names of O2 columns and matching lowerCamelCase names for their getters.
DECLARE_SOA_COLUMN(DCAY, dcaY, float);

Check failure on line 149 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/o2-column]

Use UpperCamelCase for names of O2 columns and matching lowerCamelCase names for their getters.
DECLARE_SOA_COLUMN(McMaskGlob, mcMaskGlob, int);
DECLARE_SOA_COLUMN(MatchLabel, matchLabel, int);
DECLARE_SOA_COLUMN(IsSignal, isSignal, bool);
Expand Down Expand Up @@ -207,6 +209,7 @@
fwdmatchcandidates::DCAY,
fwdmatchcandidates::IsAmbig,
fwdmatchcandidates::MFTMult,
fwdmatchcandidates::MatchAttempts,
fwdmatchcandidates::McMaskMCH,
fwdmatchcandidates::McMaskMFT,
fwdmatchcandidates::McMaskGlob,
Expand All @@ -217,8 +220,8 @@
struct mftMchMatcher {
Produces<o2::aod::FwdMatchMLCandidates> fwdMatchMLCandidates;
//// Variables for selecting muon tracks
Configurable<float> fPMchLow{"cfgPMchLow", 0.0f, ""};

Check failure on line 223 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
Configurable<float> fPtMchLow{"cfgPtMchLow", 0.7f, ""};

Check failure on line 224 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[name/configurable]

Use lowerCamelCase for names of configurables and use the same name for the struct member as for the JSON string. (Declare the type and names on the same line.)
Configurable<float> fEtaMchLow{"cfgEtaMchLow", -4.0f, ""};
Configurable<float> fEtaMchUp{"cfgEtaMchUp", -2.5f, ""};
Configurable<float> fRabsLow{"cfgRabsLow", 17.6f, ""};
Expand Down Expand Up @@ -265,14 +268,13 @@
kMatchTypeWrongNonLeading = 5,
kMatchTypeDecayNonLeading = 6,
kMatchTypeFakeNonLeading = 7,
kMatchTypeUndefined
kMatchTypeUndefined = 8
};

double mBzAtMftCenter{0};
o2::globaltracking::MatchGlobalFwd mExtrap;

int mRunNumber{0}; // needed to detect if the run changed and trigger update of magnetic field
Service<o2::ccdb::BasicCCDBManager> ccdbManager;
Service<o2::ccdb::BasicCCDBManager> ccdbManager{};
o2::ccdb::CcdbApi fCCDBApi;

o2::parameters::GRPMagField* fGrpMag = nullptr;
Expand All @@ -288,6 +290,22 @@

HistogramRegistry registry{"registry", {}};

template <typename T, typename C>
o2::dataformats::GlobalFwdTrack trackToGlobalFwd(const T& track, const C& cov)
{
double chi2 = track.chi2();
SMatrix5 tpars(track.x(), track.y(), track.phi(), track.tgl(), track.signed1Pt());
std::vector<double> v1{cov.cXX(), cov.cXY(), cov.cYY(), cov.cPhiX(), cov.cPhiY(),
cov.cPhiPhi(), cov.cTglX(), cov.cTglY(), cov.cTglPhi(), cov.cTglTgl(),
cov.c1PtX(), cov.c1PtY(), cov.c1PtPhi(), cov.c1PtTgl(), cov.c1Pt21Pt2()};
SMatrix55 tcovs(v1.begin(), v1.end());
o2::track::TrackParCovFwd trackparCov{track.z(), tpars, tcovs, chi2};
o2::dataformats::GlobalFwdTrack fwdtrack;
fwdtrack.setParameters(trackparCov.getParameters());
fwdtrack.setCovariances(trackparCov.getCovariances());
return fwdtrack;
}

template <class T, class C>
bool pDCACut(const T& mchTrack, const C& collision, double nSigmaPDCA)
{
Expand All @@ -311,16 +329,13 @@
double p = mchTrackAtVertex.p();

double pDCA = mchTrack.pDca();
double sigmaPDCA = (thetaAbs < 3) ? sigmaPDCA23 : sigmaPDCA310;

Check failure on line 332 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
double nrp = nSigmaPDCA * relPRes * p;
double pResEffect = sigmaPDCA / (1. - nrp / (1. + nrp));
double slopeResEffect = 535. * slopeRes * p;
double sigmaPDCAWithRes = TMath::Sqrt(pResEffect * pResEffect + slopeResEffect * slopeResEffect);
if (pDCA > nSigmaPDCA * sigmaPDCAWithRes) {
return false;
}

return true;
return (pDCA <= nSigmaPDCA * sigmaPDCAWithRes);
}

template <class T, class C>
Expand All @@ -333,8 +348,9 @@
double nSigmaPdcaCut)
{
// chi2 cut
if (mchTrack.chi2() > chi2Cut)
if (mchTrack.chi2() > chi2Cut) {
return false;
}

// momentum cut
if (mchTrack.p() < pCut) {
Expand Down Expand Up @@ -373,8 +389,9 @@
std::array<double, 2> etaCut)
{
// chi2 cut
if (mftTrack.chi2() > chi2Cut)
if (mftTrack.chi2() > chi2Cut) {
return false;
}

// transverse momentum cut
if (mftTrack.pt() < pTCut) {
Expand All @@ -393,8 +410,9 @@
template <typename BC>
void initCCDB(BC const& bc)
{
if (mRunNumber == bc.runNumber())
if (mRunNumber == bc.runNumber()) {
return;
}

fGrpMag = ccdbManager->getForTimeStamp<o2::parameters::GRPMagField>(grpmagPath, bc.timestamp());

Expand Down Expand Up @@ -458,7 +476,7 @@
fBestMatch.clear();
std::unordered_map<int, std::pair<float, int>> mCandidates;
for (const auto& muon : muons) {
if (static_cast<int>(muon.trackType()) < 2) {

Check failure on line 479 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
auto muonID = muon.matchMCHTrackId();
auto chi2 = muon.chi2MatchMCHMFT();
if (mCandidates.find(muonID) == mCandidates.end()) {
Expand All @@ -470,7 +488,7 @@
}
}
}
for (auto& pairCand : mCandidates) {
for (const auto& pairCand : mCandidates) {
fBestMatch[pairCand.second.second] = true;
}
}
Expand All @@ -483,7 +501,7 @@
// outer loop on muon tracks
for (const auto& muonTrack : muonTracks) {
// only consider MCH standalone or MCH-MID matches
if (static_cast<int>(muonTrack.trackType()) <= 2) {

Check failure on line 504 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
continue;
}

Expand Down Expand Up @@ -522,8 +540,9 @@
bool isPairedMuon(int64_t muonTrackId, const std::vector<std::pair<int64_t, int64_t>>& matchablePairs)
{
for (const auto& [id1, id2] : matchablePairs) {
if (muonTrackId == id1)
if (muonTrackId == id1) {
return true;
}
}
return false;
}
Expand All @@ -542,8 +561,9 @@
// search for an MFT track that is associated to the MCH mother particle
for (const auto& mftTrack : mftTracks) {
// skip tracks that do not have an associated MC particle
if (!mftTrack.has_mcParticle())
if (!mftTrack.has_mcParticle()) {
continue;
}

if (mftTrack.mcParticle().globalIndex() == mchMotherParticle.globalIndex()) {
return true;
Expand All @@ -562,7 +582,7 @@
{
MuonMatchType result{kMatchTypeUndefined};

if (static_cast<int>(muonTrack.trackType()) > 2) {

Check failure on line 585 in PWGDQ/Tasks/mftMchMatcher.cxx

View workflow job for this annotation

GitHub Actions / O2 linter

[magic-number]

Avoid magic numbers in expressions. Assign the value to a clearly named variable or constant.
return result;
}

Expand Down Expand Up @@ -593,14 +613,50 @@

return result;
}
template <class EVT, class BC, class TMUON, class TMFTS>
int getMftMchMatchAttempts(EVT const& collisions,
BC const& bcs,
TMUON const& mchTrack,
TMFTS const& mftTracks)
{
if (!mchTrack.has_collision()) {
return 0;
}
const auto& collMch = collisions.rawIteratorAt(mchTrack.collisionId());
const auto& bcMch = bcs.rawIteratorAt(collMch.bcId());

int attempts{0};
for (const auto& mftTrack : mftTracks) {
if (!mftTrack.has_collision()) {
continue;
}

const auto& collMft = collisions.rawIteratorAt(mftTrack.collisionId());
const auto& bcMft = bcs.rawIteratorAt(collMft.bcId());

int64_t deltaBc = static_cast<int64_t>(bcMft.globalBC()) - static_cast<int64_t>(bcMch.globalBC());
double deltaBcNS = o2::constants::lhc::LHCBunchSpacingNS * deltaBc;
double deltaTrackTime = mftTrack.trackTime() - mchTrack.trackTime() + deltaBcNS;
double trackTimeResTot = mftTrack.trackTimeRes() + mchTrack.trackTimeRes();

if (std::fabs(deltaTrackTime) > trackTimeResTot) {
continue;
}
attempts += 1;
}

return attempts;
}

template <bool isMc, class TCOLLS, class TBCS, class TMUONS, class TMFTS, class TCOVS>
void fillTable(TCOLLS const& collisions,
TBCS const& /*bcs*/,
TBCS const& bcs,
TMUONS const& muonTracks,
TMFTS const& mftTracks,
TCOVS const& mftCovs)
{
std::unordered_map<int64_t, int> matchAttemptsMap;

registry.get<TH1>(HIST("acceptedEvents"))->Fill(0);
// reject a randomly selected fraction of events
if (fSamplingFraction < 1.0) {
Expand All @@ -619,11 +675,11 @@
}

mftCovIndexes.clear();
for (auto& mftTrackCov : mftCovs) {
for (const auto& mftTrackCov : mftCovs) {
mftCovIndexes[mftTrackCov.matchMFTTrackId()] = mftTrackCov.globalIndex();
}

for (auto muon : muonTracks) {
for (const auto& muon : muonTracks) {
// only consider global MFT-MCH-MID matches
if (static_cast<int>(muon.trackType()) != 0) {
continue;
Expand All @@ -650,7 +706,7 @@
auto mftTime = mfttrack.trackTime() + bc_coll.globalBC() * o2::constants::lhc::LHCBunchSpacingNS;

o2::track::TrackParCovFwd mftprop = VarManager::FwdToTrackPar(mfttrack, mfttrackcov);
o2::track::TrackParCovFwd muonprop = VarManager::FwdToTrackPar(muontrack, muontrack);
o2::dataformats::GlobalFwdTrack muonprop = trackToGlobalFwd(muontrack, muontrack);
if (fzMatching.value < 0.) {
mftprop = VarManager::PropagateFwd(mfttrack, mfttrackcov, fzMatching.value);
muonprop = VarManager::PropagateMuon(muontrack, collision, VarManager::kToMatching);
Expand All @@ -670,6 +726,14 @@

bool IsAmbig = (muon.compatibleCollIds().size() != 1);
int MFTMult = collision.mftNtracks();
int matchAttempts = 0;
auto matchAttemptsIt = matchAttemptsMap.find(muontrack.globalIndex());
if (matchAttemptsIt == matchAttemptsMap.end()) {
matchAttempts = getMftMchMatchAttempts(collisions, bcs, muontrack, mftTracks);
matchAttemptsMap.insert(std::make_pair(static_cast<int64_t>(muontrack.globalIndex()), matchAttempts));
} else {
matchAttempts = matchAttemptsIt->second;
}

auto matchType = kMatchTypeUndefined;
if constexpr (isMc) {
Expand Down Expand Up @@ -789,6 +853,7 @@
muon.fwdDcaY(),
IsAmbig,
MFTMult,
matchAttempts,
mcMaskMuon,
mcMaskMft,
ncMaskGlob,
Expand Down Expand Up @@ -833,8 +898,8 @@
PROCESS_SWITCH(mftMchMatcher, processRD, "process_RD", false);
};

WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
WorkflowSpec defineDataProcessing(ConfigContext const& context)
{
return WorkflowSpec{
adaptAnalysisTask<mftMchMatcher>(cfgc)};
adaptAnalysisTask<mftMchMatcher>(context)};
};
Loading