Skip to content
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
131 changes: 53 additions & 78 deletions Detectors/GlobalTracking/include/GlobalTracking/MatchGlobalFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// or submit itself to any jurisdiction.

/// \file MatchGlobalFwd.h
/// \brief Class to perform MCH MFT matching
/// \brief Class to perform MFT MCH (and MID) matching
/// \author rafael.pezzi@cern.ch

#ifndef ALICEO2_GLOBTRACKING_MATCHGLOBALFWD_
Expand All @@ -23,6 +23,7 @@
#include <gsl/span>
#include <TStopwatch.h>
#include "CommonConstants/LHCConstants.h"
#include "CommonUtils/ConfigurationMacroHelper.h"
#include "CommonDataFormat/BunchFilling.h"
#include "ITSMFTReconstruction/ChipMappingMFT.h"
#include "MCHTracking/TrackExtrap.h"
Expand Down Expand Up @@ -78,34 +79,39 @@ struct TrackLocMCH : public o2::dataformats::GlobalFwdTrack {
ClassDefNV(TrackLocMCH, 0);
};

using o2::dataformats::GlobalFwdTrack;
using o2::track::TrackParCovFwd;
typedef std::function<double(const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack)> MatchingFunc_t;
typedef std::function<bool(const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack)> CutFunc_t;

using MFTCluster = o2::BaseCluster<float>;
using BracketF = o2::math_utils::Bracket<float>;
using SMatrix55Std = ROOT::Math::SMatrix<double, 5>;
using SMatrix55Sym = ROOT::Math::SMatrix<double, 5, 5, ROOT::Math::MatRepSym<double, 5>>;

using SVector2 = ROOT::Math::SVector<double, 2>;
using SVector4 = ROOT::Math::SVector<double, 4>;
using SVector5 = ROOT::Math::SVector<double, 5>;

using SMatrix44 = ROOT::Math::SMatrix<double, 4>;
using SMatrix45 = ROOT::Math::SMatrix<double, 4, 5>;
using SMatrix54 = ROOT::Math::SMatrix<double, 5, 4>;
using SMatrix22 = ROOT::Math::SMatrix<double, 2>;
using SMatrix25 = ROOT::Math::SMatrix<double, 2, 5>;
using SMatrix52 = ROOT::Math::SMatrix<double, 5, 2>;

class MatchGlobalFwd
{
public:
using MFTCluster = o2::BaseCluster<float>;
using BracketF = o2::math_utils::Bracket<float>;
using SMatrix55Std = ROOT::Math::SMatrix<double, 5>;
using SMatrix55Sym = ROOT::Math::SMatrix<double, 5, 5, ROOT::Math::MatRepSym<double, 5>>;

using SVector2 = ROOT::Math::SVector<double, 2>;
using SVector4 = ROOT::Math::SVector<double, 4>;
using SVector5 = ROOT::Math::SVector<double, 5>;

using SMatrix44 = ROOT::Math::SMatrix<double, 4>;
using SMatrix45 = ROOT::Math::SMatrix<double, 4, 5>;
using SMatrix54 = ROOT::Math::SMatrix<double, 5, 4>;
using SMatrix22 = ROOT::Math::SMatrix<double, 2>;
using SMatrix25 = ROOT::Math::SMatrix<double, 2, 5>;
using SMatrix52 = ROOT::Math::SMatrix<double, 5, 2>;

enum MatchingType : uint8_t { ///< MFT-MCH matching modes
MATCHINGFUNC, ///< Matching function-based MFT-MCH track matching
MATCHINGMCLABEL, ///< Monte Carlo label-based MFT-MCH track matching
MATCHINGUPSTREAM ///< MFT-MCH track matching loaded from input file
MATCHINGUPSTREAM, ///< MFT-MCH track matching loaded from input file
MATCHINGUNDEFINED
};

static constexpr Double_t sLastMFTPlaneZ = o2::mft::constants::mft::LayerZCoordinate()[9];

MatchGlobalFwd() = default;
MatchGlobalFwd();
~MatchGlobalFwd() = default;

void run(const o2::globaltracking::RecoContainer& inp);
Expand Down Expand Up @@ -133,6 +139,7 @@ class MatchGlobalFwd

private:
void updateTimeDependentParams();
void fillBuiltinFunctions();

bool prepareMCHData();
bool prepareMFTData();
Expand All @@ -148,8 +155,9 @@ class MatchGlobalFwd
///< Matches MFT tracks in one MFT ROFrame with all MCH tracks in the overlapping MCH ROFrames
template <bool saveAllMode = false>
void ROFMatch(int MFTROFId, int firstMCHROFId, int lastMCHROFId);
void fitTracks(); // Fit all matched tracks
void fitGlobalMuonTrack(o2::dataformats::GlobalFwdTrack&); // Kalman filter fit global Forward track by attaching MFT clusters

void fitTracks(); ///< Fit all matched tracks
void fitGlobalMuonTrack(o2::dataformats::GlobalFwdTrack&); ///< Kalman filter fit global Forward track by attaching MFT clusters
bool computeCluster(o2::dataformats::GlobalFwdTrack& track, const MFTCluster& cluster, int& startingLayerID);

template <typename T>
Expand Down Expand Up @@ -223,77 +231,44 @@ class MatchGlobalFwd
return true;
}

void configMatching(const std::string& matchingFcn, const std::string& cutFcn);
double matchingEval(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack);
bool matchingCut(const TrackLocMCH&, const TrackLocMFT&);
double (MatchGlobalFwd::*mMatchFunc)(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack) = &MatchGlobalFwd::noMatchFcn;
void setMatchingFunction(double (MatchGlobalFwd::*func)(const TrackLocMCH&, const TrackLocMFT&))
{
mMatchFunc = func;
}
bool (MatchGlobalFwd::*mCutFunc)(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack);
MatchingFunc_t mMatchFunc = [](const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack) -> double {
throw std::runtime_error("MatchGlobalFwd: matching function not configured!");
};

void setCutFunction(bool (MatchGlobalFwd::*func)(const TrackLocMCH&, const TrackLocMFT&))
{
mCutFunc = func;
}
/// Matching methods
/// Position
double matchMFT_MCH_TracksXY(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack);
/// Position & Angles
double matchMFT_MCH_TracksXYPhiTanl(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack);
/// Position, Angles & Charged Momentum
double matchMFT_MCH_TracksAllParam(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack);
/// Hiroshima's Matching
double matchHiroshima(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack);
/// MC label matching
double noMatchFcn(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack)
CutFunc_t mCutFunc = [](const GlobalFwdTrack& mchtrack, const TrackParCovFwd& mfttrack) -> bool {
throw std::runtime_error("MatchGlobalFwd: track pair candidate cut function not configured!");
};

bool loadExternalMatchingFunction()
{
throw std::runtime_error("noMatchFcn function must not be called!");
}
// Loads MFTMCH Matching function from external file

/// Cut functions
bool cutDisabled(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack) { return true; };
auto& matchingParam = GlobalFwdMatchingParam::Instance();

bool matchCut3Sigma(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack)
{
auto dx = mchTrack.getX() - mftTrack.getX();
auto dy = mchTrack.getY() - mftTrack.getY();
auto dPhi = mchTrack.getPhi() - mftTrack.getPhi();
auto dTanl = TMath::Abs(mchTrack.getTanl() - mftTrack.getTanl());
auto dInvQPt = TMath::Abs(mchTrack.getInvQPt() - mftTrack.getInvQPt());
auto distanceSq = dx * dx + dy * dy;
auto cutDistanceSq = 9 * (mchTrack.getSigma2X() + mchTrack.getSigma2Y());
auto cutPhiSq = 9 * (mchTrack.getSigma2Phi() + mftTrack.getSigma2Phi());
auto cutTanlSq = 9 * (mchTrack.getSigma2Tanl() + mftTrack.getSigma2Tanl());
auto cutInvQPtSq = 9 * (mchTrack.getSigma2InvQPt() + mftTrack.getSigma2InvQPt());
return (distanceSq < cutDistanceSq) and (dPhi * dPhi < cutPhiSq) and (dTanl * dTanl < cutTanlSq) and (dInvQPt * dInvQPt < cutInvQPtSq);
};
const auto& extFuncMacroFile = matchingParam.extMatchFuncFile;
const auto& extFuncName = matchingParam.extMatchFuncName;

bool matchCut3SigmaXYAngles(const TrackLocMCH& mchTrack, const TrackLocMFT& mftTrack)
{
auto dx = mchTrack.getX() - mftTrack.getX();
auto dy = mchTrack.getY() - mftTrack.getY();
auto dPhi = mchTrack.getPhi() - mftTrack.getPhi();
auto dTanl = TMath::Abs(mchTrack.getTanl() - mftTrack.getTanl());
auto distanceSq = dx * dx + dy * dy;
auto cutDistanceSq = 9 * (mchTrack.getSigma2X() + mchTrack.getSigma2Y());
auto cutPhiSq = 9 * (mchTrack.getSigma2Phi() + mftTrack.getSigma2Phi());
auto cutTanlSq = 9 * (mchTrack.getSigma2Tanl() + mftTrack.getSigma2Tanl());
return (distanceSq < cutDistanceSq) and (dPhi * dPhi < cutPhiSq) and (dTanl * dTanl < cutTanlSq);
};
LOG(info) << "Loading external MFTMCH matching function: function name = " << extFuncName << " ; Filename = " << extFuncMacroFile;

auto func = o2::conf::GetFromMacro<MatchingFunc_t*>(extFuncMacroFile.c_str(), extFuncName.c_str(), "o2::globaltracking::MatchingFunc_t*", "mtcFcn");
mMatchFunc = (*func);
return true;
}

/// Converts mchTrack parameters to Forward coordinate system
o2::dataformats::GlobalFwdTrack MCHtoFwd(const o2::mch::TrackParam& mchTrack);

float mBz = -5.f; ///< nominal Bz in kGauss
float mMatchingPlaneZ = sLastMFTPlaneZ; ///< MCH-MFT matching plane Z position TODO: Make configurable
float mMatchingPlaneZ = sLastMFTPlaneZ; ///< MCH-MFT matching plane Z position
Float_t mMFTDiskThicknessInX0 = 0.042 / 5;
o2::InteractionRecord mStartIR{0, 0}; ///< IR corresponding to the start of the TF
int mMFTROFrameLengthInBC = 0; ///< MFT RO frame in BC (for MFT cont. mode only)
float mMFTROFrameLengthMUS = -1.; ///< MFT RO frame in \mus
float mMFTROFrameLengthMUSInv = -1.; ///< MFT RO frame in \mus inverse

std::map<std::string, MatchingFunc_t> mMatchingFunctionMap; ///< MFT-MCH Matching function
std::map<std::string, CutFunc_t> mCutFunctionMap; ///< MFT-MCH Candidate cut function

o2::BunchFilling mBunchFilling;
std::array<int16_t, o2::constants::lhc::LHCMaxBunches> mClosestBunchAbove; // closest filled bunch from above
std::array<int16_t, o2::constants::lhc::LHCMaxBunches> mClosestBunchBelow; // closest filled bunch from below
Expand Down Expand Up @@ -329,7 +304,7 @@ class MatchGlobalFwd
bool mMCTruthON = false; ///< Flag availability of MC truth
bool mUseMIDMCHMatch = false; ///< Flag for using MCHMID matches (TrackMCHMID)
bool mSaveAll = false; ///< Flag to save all MCH-MFT matching pairs
MatchingType mMatchingType = MATCHINGFUNC;
MatchingType mMatchingType = MATCHINGUNDEFINED;
TGeoManager* mGeoManager;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ namespace globaltracking
// ** Parameters for Global forward matching
// **
struct GlobalFwdMatchingParam : public o2::conf::ConfigurableParamHelper<GlobalFwdMatchingParam> {
bool useMIDMatch = false;
std::string matchFcn = "matchALL"; ///< MFT-MCH matching score evaluation
std::string cutFcn = "cutDisabled"; ///< MFT-MCH candicate cut function
double matchPlaneZ = -77.5; ///< MFT-MCH matching plane z coordinate
bool useMIDMatch = false; ///< Use input from MCH-MID mathing
std::string matchFcn = "matchALL"; ///< MFT-MCH matching score evaluation
std::string extMatchFuncFile = "FwdMatchFunc.C"; ///< File name for external input matching function
std::string extMatchFuncName = "getMatchingFunction()"; ///< Name of external matching function getter
std::string cutFcn = "cutDisabled"; ///< MFT-MCH candicate cut function
bool MCMatching = false; ///< MFT-MCH matching computed from MCLabels
double matchPlaneZ = -77.5; ///< MFT-MCH matching plane z coordinate

bool isMatchUpstream() const { return matchFcn.find("matchUpstream") < matchFcn.length(); }
bool matchingExternalFunction() const { return matchFcn.find("matchExternal") < matchFcn.length(); }
bool saveAll = false; ///< Option to save all MFTMCH pair combinations.

O2ParamDef(GlobalFwdMatchingParam, "FwdMatching");
Expand Down
Loading