16#ifndef ALICEO2_GLOBTRACKING_MATCHTPCITS_
17#define ALICEO2_GLOBTRACKING_MATCHTPCITS_
19#define _ALLOW_DEBUG_TREES_
21#define _ALLOW_DEBUG_AB_
29#include <TStopwatch.h>
61#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
73namespace globaltracking
80template <
typename TruthElement>
105namespace globaltracking
281 linkID =
link.parentID;
293 linkID =
link.parentID;
315 float y = 0.f,
z = 0.f;
326 std::vector<ABClusterInfo>
clus;
380#if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__ROOTCLING__) && !defined(__CLING__)
460 float tMin = (nBC + mITSTimeBiasInBC[lr]) * o2::constants::lhc::LHCBunchSpacingMUS;
461 return {tMin, tMin + mITSROFrameLengthMUS[lr]};
466#ifdef ENABLE_UPGRADES
498#ifdef _ALLOW_DEBUG_TREES_
518 mDebugTreeFileName =
name;
532 void updateTimeDependentParams();
535 std::array<int, MaxLadderCand>& lad2Check)
const;
537 std::array<int, MatchTPCITS::MaxLadderCand>& lad2Check)
const;
538 bool prepareTPCData();
539 bool prepareITSData();
540 bool prepareFITData();
541 int prepareInteractionTimes();
542 int prepareTPCTracksAfterBurner();
545 int preselectChipClusters(std::vector<int>& clVecOut,
const ClusRange& clRange,
const ABLayerView& clView,
546 float trackY,
float trackZ,
float tolerY,
float tolerZ)
const;
549 void doMatching(
int sec);
553 void selectBestMatches();
554 bool validateTPCMatch(
int iTPC);
555 void removeITSfromTPC(
int itsID,
int tpcID);
556 void removeTPCfromITS(
int tpcID,
int itsID);
568 bool registerMatchRecordTPC(
int iITS,
int iTPC,
float chi2,
int candIC =
MinusOne);
569 void registerMatchRecordITS(
int iITS,
int iTPC,
float chi2,
int candIC =
MinusOne);
570 void suppressMatchRecordITS(
int iITS,
int iTPC);
573 int getNMatchRecordsTPC(
const TrackLocTPC& tTPC)
const;
576 int getNMatchRecordsITS(
const TrackLocITS& tITS)
const;
582 int time2ITSROFrameCont(
float t)
const
584 int rof = (t - mITSTimeBiasMUS[mITSClockLayer]) * mITSROFrameLengthMUSInv[mITSClockLayer];
589 return rof < int(mITSTrackROFContMapping.size()) ? mITSTrackROFContMapping[rof] : mITSTrackROFContMapping.back();
593 int time2ITSROFrameTrig(
float t,
int start)
const
595 t -= mITSTimeBiasMUS[mITSClockLayer];
596 while (
start <
int(mITSROFTimes.size())) {
597 if (mITSROFTimes[
start].getMax() > t) {
606 float tpcTimeBin2Z(
float tbn)
const {
return tbn * mTPCBin2Z; }
609 float tpcTimeBin2MUS(
float tbn)
const {
return tbn * mTPCTBinMUS; }
612 float tpcTimeBin2NS(
float tbn)
const {
return tbn * mTPCTBinNS; }
615 float z2TPCBin(
float z)
const {
return z * mZ2TPCBin; }
618 float tpcBin2Z(
float t)
const {
return t * mTPCBin2Z; }
621 int roughCheckDif(
float delta,
float toler,
int rejFlag)
const
623 return delta > toler ? rejFlag : (delta < -toler ? -rejFlag :
Accept);
626 const ITSCluster& getITSCluster(
int composedID)
const
632 int prepareABSeeds();
633 void prepareABClusters();
634 void updateABLayerView(ABLayerView& view,
int lr,
int rof,
int nROFs)
const;
635 void processABSeed(
int sid,
const ABThreadClusterViews& itsClViews, uint8_t tID);
636 int followABSeed(
const o2::track::TrackParCov& seed,
const ABLayerView& clView,
int seedID,
int lrID, TPCABSeed& ABSeed);
637 int registerABTrackLink(TPCABSeed& ABSeed,
const o2::track::TrackParCov& trc,
int clID,
int parentID,
int lr,
int laddID,
float chi2Cl);
638 bool isBetter(
float chi2A,
float chi2B) {
return chi2A <
chi2B; }
639 void accountForOverlapsAB(
int lrSeed);
640 float correctTPCTrack(
o2::track::TrackParCov& trc,
const TrackLocTPC& tTPC,
const InteractionCandidate& cand)
const;
643 bool mInitDone =
false;
644 bool mFieldON =
true;
645 bool mCosmics =
false;
646 bool mMCTruthON =
false;
651 int mNTPCOccBinLength = 0;
652 float mNTPCOccBinLengthInv;
656 const Params* mParams =
nullptr;
660 MatCorrType mUseMatCorrFlag = MatCorrType::USEMatCorrTGeo;
661 bool mUseBCFilling =
false;
662 bool mSkipTPCOnly =
false;
663 bool mITSTriggered =
false;
664 bool mUseFT0 =
false;
667 bool mCompareTracksDZ =
false;
669 float YMaxAtXMatchingRef = 999.;
671 float mSectEdgeMargin = 0.;
675 float mTPCTimeEdgeTSafeMargin = 0.f;
676 float mTPCExtConstrainedNSigmaInv = 0.f;
679 int mITSClockLayer = 0;
680 std::array<int, NITSLayers> mITSROFrameLengthInBC{};
681 std::array<float, NITSLayers> mITSROFrameLengthMUS{};
682 std::array<float, NITSLayers> mITSROFrameLengthMUSInv{};
683 std::array<float, NITSLayers> mITSTimeResMUS{};
684 std::array<int, NITSLayers> mITSTimeBiasInBC{};
685 std::array<float, NITSLayers> mITSTimeBiasMUS{};
686 float mTPCVDrift = -1.;
687 float mTPCVDriftInv = -1.;
688 float mTPCDriftTimeOffset = 0;
689 float mTPCTBinMUS = 0.;
690 float mTPCTBinNS = 0.;
691 float mTPCTBinMUSInv = 0.;
692 float mZ2TPCBin = 0.;
693 float mTPCBin2Z = 0.;
694 float mNTPCBinsFullDrift = 0.;
696 float mTPCmeanX0Inv = 1. / 31850.;
698 float mMinTPCTrackPtInv = 999.;
699 float mMinITSTrackPtInv = 999.;
700 bool mVDriftCalibOn =
false;
705 std::unique_ptr<o2::gpu::GPUO2InterfaceRefit> mTPCRefitter;
708 std::array<int16_t, o2::constants::lhc::LHCMaxBunches> mClosestBunchAbove;
709 std::array<int16_t, o2::constants::lhc::LHCMaxBunches> mClosestBunchBelow;
711 std::array<float, 5> mCovDiagInner{};
712 std::array<float, 5> mCovDiagOuter{};
719 gsl::span<const o2::tpc::TrackTPC> mTPCTracksArray;
720 gsl::span<const o2::tpc::TPCClRefElem> mTPCTrackClusIdx;
721 gsl::span<const o2::itsmft::ROFRecord> mITSTrackROFRec;
722 gsl::span<const o2::its::TrackITS> mITSTracksArray;
723 gsl::span<const int> mITSTrackClusIdx;
724 std::array<std::vector<ITSCluster>,
NITSLayers> mITSClustersArray{};
725 std::array<std::vector<uint8_t>,
NITSLayers> mITSClusterSizes{};
726 std::array<gsl::span<const o2::itsmft::ROFRecord>,
NITSLayers> mITSClusterROFRec;
727 int mNITSClusters = 0;
728 gsl::span<const o2::ft0::RecPoints> mFITInfo;
730 gsl::span<const unsigned char> mTPCRefitterShMap;
731 gsl::span<const unsigned int> mTPCRefitterOccMap;
733#ifdef ENABLE_UPGRADES
739 std::array<const o2::dataformats::MCTruthContainer<o2::MCCompLabel>*,
NITSLayers> mITSClsLabels{};
740 gsl::span<const o2::MCCompLabel> mITSTrkLabels;
741 gsl::span<const o2::MCCompLabel> mTPCTrkLabels;
744 size_t mNMatches = 0;
745 size_t mNCalibPrelim = 0;
746 size_t mNMatchesControl = 0;
748 size_t mNABRefsClus = 0;
749 float mAB2MatchGuess = 0.2;
750 std::vector<InteractionCandidate> mInteractions;
751 std::vector<int> mInteractionMUSLUT;
754 std::vector<MatchRecord> mMatchRecordsTPC;
756 std::vector<MatchRecord> mMatchRecordsITS;
759 std::vector<BracketF> mITSROFTimes;
760 std::vector<TrackLocTPC> mTPCWork;
761 std::vector<TrackLocITS> mITSWork;
762 std::vector<o2::MCCompLabel> mTPCLblWork;
763 std::vector<o2::MCCompLabel> mITSLblWork;
764 std::vector<float> mWinnerChi2Refit;
765 std::vector<float> mTBinClOcc;
768 std::vector<TPCABSeed> mTPCABSeeds;
770 std::vector<int> mTPCABIndexCache;
771 std::vector<int> mABWinnersIDs;
775 std::array<ABLayerClusters, NITSLayers> mABLayerClusters;
776 std::array<int, NITSLayers + 1> mABChipsBounds{};
777 float mABROFMarginMUS = 0.f;
778 float mITSMaxROFOverhangMUS = 0.f;
779 LinksPoolMT mABLinksPool;
782 std::array<std::vector<int>, o2::constants::math::NSectors> mTPCSectIndexCache;
784 std::array<std::vector<int>, o2::constants::math::NSectors> mITSSectIndexCache;
787 std::array<std::vector<int>, o2::constants::math::NSectors> mTPCTimeStart;
789 std::array<std::vector<int>, o2::constants::math::NSectors> mITSTimeStart;
792 std::vector<int> mITSTrackROFContMapping;
796#ifdef _ALLOW_DEBUG_TREES_
797 std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
798 UInt_t mDBGFlags = 0;
799 std::string mDebugTreeFileName =
"dbg_TPCITSmatch.root";
803 static constexpr float Tan70 = 2.74747771e+00;
804 static constexpr float Cos70I2 = 1. + Tan70 * Tan70;
805 static constexpr float MaxSnp = 0.9;
806 static constexpr float MaxTgp = 2.064;
807 static constexpr float MinTBToCleanCache = 600.;
810 enum TimerIDs { SWTot,
823 static constexpr std::string_view TimerName[] = {
"Total",
"PrepareITS",
"PrepareTPC",
"DoMatching",
"SelectBest",
"Refit",
824 "ABSeeds",
"ABMatching",
"ABWinners",
"ABRefit",
"IO",
"Debug"};
825 TStopwatch mTimer[NStopWatches];
829inline bool MatchTPCITS::isValidatedTPC(
const TrackLocTPC& t)
const
831 return t.matchID >
MinusOne && mMatchRecordsTPC[t.matchID].nextRecID ==
Validated;
835inline bool MatchTPCITS::isValidatedITS(
const TrackLocITS& t)
const
837 return t.matchID >
MinusOne && mMatchRecordsITS[t.matchID].nextRecID ==
Validated;
841inline bool MatchTPCITS::isDisabledITS(
const TrackLocITS& t)
const {
return t.matchID < 0; }
844inline bool MatchTPCITS::isDisabledTPC(
const TrackLocTPC& t)
const {
return t.matchID < 0; }
Composition/decomposition of the ITS/MFT cluster IDs referring to per-layer cluster arrays.
Helper class to read the binary format of TPC ClusterNative.
Definition of the BuildTopologyDictionary class for ITS3.
Class to store event ID and index in the event for objects like track, cluster...
Global index for barrel track: provides provenance (detectors combination), index in respective array...
Configurable params for TPC ITS matching.
Declarations of 2D primitives.
Class to refer to the 1st entry and N elements of some group in the continuous container.
Declarations of the helper class for clusters / roadwidth matching.
o2::track::TrackParCov TrackParCov
Definition of the ITS track.
Result of refitting TPC-ITS matched track.
Reference on ITS/MFT clusters set.
calibration data from laser track calibration
bool isITSTriggered() const
void setUseMatCorrFlag(MatCorrType f)
void setDebugTreeFileName(std::string name)
get the name of output debug file
static constexpr int MaxLadderCand
void fillCalibDebug(int ifit, int iTPC, const o2::dataformats::TrackTPCITS &match, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
void setUseBCFilling(bool v)
o2::BaseCluster< float > ITSCluster
void reportTiming()
clear results of previous event reco
int getITSClockLayer() const
per-layer ITS ROF length and bias, always defined for all NITSLayers
bool getUseBCFilling() const
@ MatchTreeAccOnly
fill the matching candidates tree only once the cut is passed
@ TPCOrigTree
original TPC tracks with some aux info
@ MatchTreeAll
produce matching candidates tree for all candidates
@ WinnerMatchesTree
separate debug tree for winner matches
void clear()
set Bunch filling and init helpers for validation by BCs
float getITSTimeBiasMUS(int lr) const
time bracket (wrt TF start) of the ROF starting at nBC of the given layer
void refitWinners(pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
void refitABWinners(pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::MCCompLabel > &ABTrackletLabels, pmr::vector< int > &ABTrackletClusterIDs, pmr::vector< o2::itsmft::TrkClusRef > &ABTrackletRefs, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
BracketF getITSROFTimeBracket(long nBC, int lr) const
bool refitABTrack(int iITSAB, const TPCABSeed &seed, pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< int > &ABTrackletClusterIDs, pmr::vector< o2::itsmft::TrkClusRef > &ABTrackletRefs)
void setAlpideParam(const AlpParamITS *p)
void setTPCVDrift(const o2::tpc::VDriftCorrFact &v)
void setNHBPerTF(int n)
ITS readout mode.
bool isDebugFlag(UInt_t flags) const
get debug trees flags
int getITSTimeBiasInBC(int lr) const
void setITSTriggered(bool v)
void printCandidatesITS() const
void setTPCCorrMaps(const o2::gpu::TPCFastTransformPOD *maph, float lumi)
print settings
bool runAfterBurner(pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::MCCompLabel > &ABTrackletLabels, pmr::vector< int > &ABTrackletClusterIDs, pmr::vector< o2::itsmft::TrkClusRef > &ABTrackletRefs, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
const AlpParamITS * getAlpideParam() const
layer whose ROF defines the granularity of the ITS tracks ROFRecords (0 if all layers share the same ...
void reportSizes(pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::itsmft::TrkClusRef > &ABTrackletRefs, pmr::vector< int > &ABTrackletClusterIDs, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::MCCompLabel > &ABTrackletLabels, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
float getITSROFrameLengthMUS(int lr) const
void printCandidatesTPC() const
void setSkipTPCOnly(bool v)
void setMCTruthOn(bool v)
request VDrift calibration
int getITSROFrameLengthInBC(int lr) const
static constexpr int MaxSeedsPerLayer
void fillTPCITSmatchTree(int itsID, int tpcID, int rejFlag, float chi2=-1., float tCorr=0.)
bool refitTrackTPCITS(int slot, int iTPC, int &iITS, pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
static constexpr int MaxUpDnLadders
void run(const o2::globaltracking::RecoContainer &inp, pmr::vector< o2::dataformats::TrackTPCITS > &matchedTracks, pmr::vector< o2::itsmft::TrkClusRef > &ABTrackletRefs, pmr::vector< int > &ABTrackletClusterIDs, pmr::vector< o2::MCCompLabel > &matchLabels, pmr::vector< o2::MCCompLabel > &ABTrackletLabels, pmr::vector< o2::dataformats::Triplet< float, float, float > > &calib)
perform matching for provided input
void setVDriftCalib(bool v)
void setBunchFilling(const o2::BunchFilling &bf)
void dumpTPCOrig(bool acc, int tpcIndex)
void setDebugFlag(UInt_t flag, bool on=true)
set the name of output debug file
o2::globaltracking::MatchTPCITSParams Params
o2::itsmft::DPLAlpideParam< o2::detectors::DetID::ITS > AlpParamITS
void setITSDictionary(const o2::itsmft::TopologyDictionary *d)
set flag to use MC truth
static constexpr int NITSLayers
const std::string & getDebugTreeFileName() const
fill matching debug tree
float getITSROFrameLengthMUSInv(int lr) const
auto getUseMatCorrFlag() const
UInt_t getDebugFlags() const
set or unset debug stream flag
float getITSTimeResMUS(int lr) const
void setNThreads(int n)
perform all initializations
HMPID cluster implementation.
bool match(const std::vector< std::string > &queries, const char *pattern)
GLuint const GLchar * name
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
GLdouble GLdouble GLdouble z
std::array< std::vector< int >, o2::its::RecoGeomHelper::getNLayers()> ITSClusStatus
flags to tell the status of TPC-ITS tracks comparison
constexpr int Validated
per-layer status of ITS clusters (e.g. for the AfterBurner)
const float const int const float chi2B
constexpr int clusID2Layer(int id)
constexpr int MaxITSClusLayers
constexpr int clusID2Index(int id)
detail::Bracket< float > Bracketf_t
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
int chip
global chip (sensor) ID
std::vector< uint8_t > needROF
scratch buffer: blocks to build for the current TF
o2::dataformats::RangeReference< int, int > ClusRange
size_t sizeInternal() const
size_t capInternal() const
std::vector< ABClusterInfo > clus
clusters of the built blocks
std::vector< o2::math_utils::Bracketf_t > rofTimes
time brackets of all cluster ROFs of the layer
std::vector< ClusRange > rofRefs
block of every ROF in the clus vector, firstEntry < 0 if the block was not built
int nData
number of clusters in the view
int chipOffs
global ID of the 1st chip of the layer
int rofKey
1st ROF of the loaded block(s): -1: no compatible ROF, -2: nothing loaded yet
std::vector< ClusRange > chipRefs
cluster range in data for every chip of the layer
std::vector< ABClusterInfo > merged
buffer to merge 2 blocks when the candidate time is compatible with 2 ROFs
std::vector< int > touchedChips
chips with non-empty chipRefs, for fast reset
int nROFsKey
number of consecutive ROFs loaded (1 or 2)
std::array< ABLayerView, o2::its::RecoGeomHelper::getNLayers()> layers
< per-thread views of the AB clusters of all layers
float chi2
chi2 after update
int parentID
ID of the parent link (on prev layer) or parent TPC seed.
uint8_t nDaughters
number of daughter links on lower layers
static constexpr int Disabled
uint8_t ladderID
ladder ID in the layer (used for seeds with 2 hits in the layer)
int8_t nContLayers
number of contributing layers
ABTrackLink(const o2::track::TrackParCov &tr, int cl, int parID, int nextID, int lr, int nc, int ld, float _chi2)
int clID
ID of the attached cluster, MinusOne: no attachment on this layer.
float chi2NormPredict(float chi2cl) const
int nextOnLr
ID of the next (in quality) link on the same layer.
o2::math_utils::Bracketf_t tBracket
o2::dataformats::RangeReference< int, int > seedsRef
std::array< int, o2::its::RecoGeomHelper::getNLayers()> rofLr
InteractionCandidate(const o2::InteractionRecord &ir, float t, float dt, int rof, uint32_t f=0)
std::vector< std::deque< ABTrackLink > > threadPool
bool isBetter(const MatchRecord &other) const
int partnerID
id of parnter track entry in mTPCWork or mITSWork containers
int nextRecID
index of eventual next record
int matchedIC
index of eventually matched InteractionCandidate
MatchRecord(int partID, float chi2match, int nxt=MinusOne, int candIC=MinusOne)
bool isBetter(float otherChi2, int otherIC=MinusOne) const
auto getBestLinkID() const
std::array< int, o2::its::RecoGeomHelper::getNLayers()> firstInLr
entry of 1st (best) hypothesis on each layer
int8_t status
status (RS TODO)
size_t sizeInternal() const
int8_t getNLayers() const
int winLinkID
ID of the validated link.
TPCABSeed(int id, int ic, const o2::track::TrackParCov &trc)
void addLink(const o2::track::TrackParCov &trc, int clID, int parentID, int nextID, int lr, int nc, int laddID, float chi2)
const ABTrackLink & getLink(int i) const
size_t capInternal() const
int ICCanID
interaction candidate ID (they are sorted in increasing time)
ABTrackLink & getLink(int i)
uint32_t linksEntry
1st entry of the link
void flagLinkUsedClusters(int linkID, ITSClusStatus &clStatus) const
uint8_t threadID
thread ID
static constexpr int8_t NeedAlternative
o2::track::TrackParCov track
Seed propagated to the outer layer under certain time constraint.
int nLinks
number of links
static LinksPoolMT * gLinksPool
pool of links per thread
bool needAlteranative() const
void setNeedAlternative()
bool checkLinkHasUsedClusters(int linkID, const ITSClusStatus &clStatus) const
int8_t lowestLayer
lowest layer reached
int roFrame
ITS readout frame assigned to this track.
o2::math_utils::Bracketf_t tBracket
bracketing time in \mus
bool hasCloneAfter() const
int getCloneShift() const
float dL
distance integrated during propagation to reference X (as pion)
int matchID
entry (non if MinusOne) of its matchCand struct in the mMatchesITS
float xrho
x*rho seen during propagation to reference X (as pion)
int sourceID
track origin id
ClassDefNV(TrackLocITS, 1)
bool hasCloneBefore() const
float time0
nominal time in \mus since start of TF (time0 for bare TPC tracks, constrained time for TRD/TOF const...
int sourceID
TPC track origin in.
float getSignedDT(float dt) const
o2::math_utils::Bracketf_t tBracket
bracketing time in \mus
int matchID
entry (non if MinusOne) of its matchTPC struct in the mMatchesTPC
float getCorrectedTime(float dt) const
float timeErr
time sigma (makes sense for constrained tracks only)
ClassDefNV(TrackLocTPC, 3)
o2::dataformats::GlobalTrackID gid
static constexpr int getNLayers()
static constexpr int getNLayers()
VectorOfTObjectPtrs other
o2::InteractionRecord ir(0, 0)