Skip to content

Commit f93946f

Browse files
authored
Merge 0ea9033 into sapling-pr-archive-ktf
2 parents a7348a3 + 0ea9033 commit f93946f

File tree

44 files changed

+776
-618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+776
-618
lines changed

Common/ML/include/ML/3rdparty/GPUORTFloat16.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,11 @@ GPUdi() uint16_t BFloat16Impl<Derived>::ToUint16Impl(float v) noexcept
568568
template <class Derived>
569569
GPUdi() float BFloat16Impl<Derived>::ToFloatImpl() const noexcept
570570
{
571+
#ifndef __FAST_MATH__
571572
if (IsNaN()) {
572573
return o2::gpu::CAMath::QuietNaN();
573574
}
575+
#endif
574576
float result;
575577
char* const first = reinterpret_cast<char*>(&result);
576578
char* const second = first + sizeof(uint16_t);

DataFormats/Detectors/EMCAL/include/DataFormatsEMCAL/CellLabel.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <cstddef>
1616
#include <cstdint>
1717
#include <gsl/span>
18+
#include <vector>
1819

1920
namespace o2
2021
{
@@ -34,10 +35,15 @@ class CellLabel
3435
public:
3536
// CellLabel() = default;
3637

37-
/// \brief Constructor
38+
/// \brief Constructor using std::vector by moving NOT copying
3839
/// \param labels list of mc labels
3940
/// \param amplitudeFractions list of amplitude fractions
40-
CellLabel(const gsl::span<const int> labels, const gsl::span<const float> amplitudeFractions);
41+
CellLabel(std::vector<int> labels, std::vector<float> amplitudeFractions);
42+
43+
/// \brief Constructor using gsl::span
44+
/// \param labels list of mc labels
45+
/// \param amplitudeFractions list of amplitude fractions
46+
CellLabel(gsl::span<const int> labels, gsl::span<const float> amplitudeFractions);
4147

4248
// ~CellLabel() = default;
4349
// CellLabel(const CellLabel& clus) = default;
@@ -52,21 +58,21 @@ class CellLabel
5258
int32_t GetLabel(size_t index) const { return mLabels[index]; }
5359

5460
/// \brief Getter for labels
55-
gsl::span<const int32_t> GetLabels() const { return mLabels; }
61+
std::vector<int32_t> GetLabels() const { return mLabels; }
5662

5763
/// \brief Getter for amplitude fraction
5864
/// \param index index which amplitude fraction to get
5965
float GetAmplitudeFraction(size_t index) const { return mAmplitudeFraction[index]; }
6066

6167
/// \brief Getter for amplitude fractions
62-
gsl::span<const float> GetAmplitudeFractions() const { return mAmplitudeFraction; }
68+
std::vector<float> GetAmplitudeFractions() const { return mAmplitudeFraction; }
6369

6470
/// \brief Getter for label with leading amplitude fraction
6571
int32_t GetLeadingMCLabel() const;
6672

6773
protected:
68-
gsl::span<const int32_t> mLabels; ///< List of MC particles that generated the cluster, ordered in deposited energy.
69-
gsl::span<const float> mAmplitudeFraction; ///< List of the fraction of the cell energy coming from a MC particle. Index aligns with mLabels!
74+
std::vector<int32_t> mLabels; ///< List of MC particles that generated the cluster, ordered in deposited energy.
75+
std::vector<float> mAmplitudeFraction; ///< List of the fraction of the cell energy coming from a MC particle. Index aligns with mLabels!
7076
};
7177

7278
} // namespace emcal

DataFormats/Detectors/EMCAL/src/CellLabel.cxx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,19 @@
1616
#include <cstddef>
1717
#include <cstdint>
1818
#include <gsl/span>
19+
#include <vector>
20+
#include <utility>
1921

2022
using namespace o2::emcal;
2123

22-
CellLabel::CellLabel(const gsl::span<const int> labels, const gsl::span<const float> amplitudeFractions) : mLabels(labels), mAmplitudeFraction(amplitudeFractions)
24+
CellLabel::CellLabel(std::vector<int> labels, std::vector<float> amplitudeFractions) : mLabels(std::move(labels)), mAmplitudeFraction(std::move(amplitudeFractions))
25+
{
26+
if (labels.size() != amplitudeFractions.size()) {
27+
LOG(error) << "Size of labels " << labels.size() << " does not match size of amplitude fraction " << amplitudeFractions.size() << " !";
28+
}
29+
}
30+
31+
CellLabel::CellLabel(gsl::span<const int> labels, gsl::span<const float> amplitudeFractions) : mLabels(labels.begin(), labels.end()), mAmplitudeFraction(amplitudeFractions.begin(), amplitudeFractions.end())
2332
{
2433
if (labels.size() != amplitudeFractions.size()) {
2534
LOG(error) << "Size of labels " << labels.size() << " does not match size of amplitude fraction " << amplitudeFractions.size() << " !";

Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudyConfig.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ struct TrackMCStudyConfig : o2::conf::ConfigurableParamHelper<TrackMCStudyConfig
2828
bool requireITSorTPCTrackRefs = true;
2929
bool requireTopBottomRefs = false;
3030
int minTPCRefsToExtractClRes = 2;
31-
float rejectClustersResStat = 0.;
31+
int nOccBinsDrift = 10; // number of bins for TPC max drift time, where we integrate the occupancies
32+
int nTBPerOccBin = 48; // number of TB per occ bin
33+
float rejectClustersResStat = 0.1;
3234
float maxTPCRefExtrap = 2; // max dX to extrapolate the track ref when extrapolating track true posions
3335
int decayPDG[5] = {310, 3122, 411, 421, -1}; // decays to study, must end by -1
3436
O2ParamDef(TrackMCStudyConfig, "trmcconf");

Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/TrackMCStudyTypes.h

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct MCTrackInfo {
3232
int getNITSClusForAB() const;
3333
int getLowestITSLayer() const;
3434
int getHighestITSLayer() const;
35-
35+
std::vector<float> occTPCV{};
3636
o2::track::TrackPar track{};
3737
o2::MCCompLabel label{};
3838
float occTPC = -1.f;
@@ -52,7 +52,24 @@ struct MCTrackInfo {
5252
uint8_t maxTPCRowSect = -1;
5353
int8_t nITSCl = 0;
5454
int8_t pattITSCl = 0;
55-
ClassDefNV(MCTrackInfo, 4);
55+
uint8_t flags = 0;
56+
57+
enum Flags : uint32_t { Primary = 0,
58+
AddedAtRecStage = 2,
59+
BitMask = 0xff };
60+
61+
bool isPrimary() const { return isBitSet(Primary); }
62+
bool isAddedAtRecStage() const { return isBitSet(AddedAtRecStage); }
63+
void setPrimary() { setBit(Primary); }
64+
void setAddedAtRecStage() { setBit(AddedAtRecStage); }
65+
66+
uint8_t getBits() const { return flags; }
67+
bool isBitSet(int bit) const { return flags & (0xff & (0x1 << bit)); }
68+
void setBits(std::uint8_t b) { flags = b; }
69+
void setBit(int bit) { flags |= BitMask & (0x1 << bit); }
70+
void resetBit(int bit) { flags &= ~(BitMask & (0x1 << bit)); }
71+
72+
ClassDefNV(MCTrackInfo, 7);
5673
};
5774

5875
struct RecTrack {
@@ -75,6 +92,7 @@ struct RecTrack {
7592
uint8_t nClTPC = 0;
7693
uint8_t pattITS = 0;
7794
int8_t lowestPadRow = -1;
95+
int8_t padFromEdge = -1;
7896

7997
bool isFakeGLO() const { return flags & FakeGLO; }
8098
bool isFakeITS() const { return flags & FakeITS; }
@@ -83,7 +101,7 @@ struct RecTrack {
83101
bool isFakeTOF() const { return flags & FakeTOF; }
84102
bool isFakeITSTPC() const { return flags & FakeITSTPC; }
85103

86-
ClassDefNV(RecTrack, 1);
104+
ClassDefNV(RecTrack, 2);
87105
};
88106

89107
struct TrackPairInfo {
@@ -270,7 +288,8 @@ struct MCVertex {
270288
int nTrackSel = 0; // number of selected MC charged tracks
271289
int ID = -1;
272290
std::vector<RecPV> recVtx{};
273-
ClassDefNV(MCVertex, 1);
291+
std::vector<float> occTPCV{};
292+
ClassDefNV(MCVertex, 2);
274293
};
275294

276295
} // namespace o2::trackstudy

Detectors/GlobalTrackingWorkflow/study/src/TrackMCStudy.cxx

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class TrackMCStudy : public Task
109109
void updateTimeDependentParams(ProcessingContext& pc);
110110
float getDCAYCut(float pt) const;
111111

112-
gsl::span<const MCTrack> mCurrMCTracks;
112+
const std::vector<o2::MCTrack>* mCurrMCTracks = nullptr;
113113
TVector3 mCurrMCVertex;
114114
o2::tpc::VDriftHelper mTPCVDriftHelper{};
115115
o2::tpc::CorrectionMapsLoader mTPCCorrMapsLoader{};
@@ -122,8 +122,9 @@ class TrackMCStudy : public Task
122122
std::vector<float> mTPCOcc; ///< TPC occupancy for this interaction time
123123
std::vector<int> mITSOcc; //< N ITS clusters in the ROF containing collision
124124
bool mCheckSV = false; //< check SV binding (apart from prongs availability)
125+
bool mRecProcStage = false; //< flag that the MC particle was added only at the stage of reco tracks processing
125126
int mNTPCOccBinLength = 0; ///< TPC occ. histo bin length in TBs
126-
float mNTPCOccBinLengthInv;
127+
float mNTPCOccBinLengthInv = -1.f;
127128
int mVerbose = 0;
128129
float mITSTimeBiasMUS = 0.f;
129130
float mITSROFrameLengthMUS = 0.f; ///< ITS RO frame in mus
@@ -181,10 +182,11 @@ void TrackMCStudy::run(ProcessingContext& pc)
181182
}
182183
mDecProdLblPool.clear();
183184
mMCVtVec.clear();
184-
mCurrMCTracks = {};
185+
mCurrMCTracks = nullptr;
185186

186187
recoData.collectData(pc, *mDataRequest.get()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer
187188
updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
189+
mRecProcStage = false;
188190
process(recoData);
189191
}
190192

@@ -278,15 +280,21 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
278280
return patt;
279281
};
280282

281-
auto getLowestPadrow = [&recoData](const o2::tpc::TrackTPC& trc) {
283+
auto getLowestPadrow = [&recoData](const o2::tpc::TrackTPC& trc, RecTrack& tref) {
282284
if (recoData.inputsTPCclusters) {
283285
uint8_t clSect = 0, clRow = 0;
284286
uint32_t clIdx = 0;
285287
const auto clRefs = recoData.getTPCTracksClusterRefs();
288+
const auto tpcClusAcc = recoData.getTPCClusters();
286289
trc.getClusterReference(clRefs, trc.getNClusterReferences() - 1, clSect, clRow, clIdx);
287-
return int(clRow);
290+
const auto& clus = tpcClusAcc.clusters[clSect][clRow][clIdx];
291+
int padFromEdge = int(clus.getPad()), npads = o2::gpu::GPUTPCGeometry::NPads(clRow);
292+
if (padFromEdge > npads / 2) {
293+
padFromEdge = npads - 1 - padFromEdge;
294+
}
295+
tref.padFromEdge = uint8_t(padFromEdge);
296+
tref.lowestPadRow = clRow;
288297
}
289-
return -1;
290298
};
291299

292300
auto flagTPCClusters = [&recoData](const o2::tpc::TrackTPC& trc, o2::MCCompLabel lbTrc) {
@@ -338,6 +346,21 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
338346
}
339347
break;
340348
}
349+
if (mNTPCOccBinLengthInv > 0.f) {
350+
mcVtx.occTPCV.resize(params.nOccBinsDrift);
351+
int grp = TMath::Max(1, TMath::Nint(params.nTBPerOccBin * mNTPCOccBinLengthInv));
352+
for (int ib = 0; ib < params.nOccBinsDrift; ib++) {
353+
float smb = 0;
354+
int tbs = occBin + TMath::Nint(ib * params.nTBPerOccBin * mNTPCOccBinLengthInv);
355+
for (int ig = 0; ig < grp; ig++) {
356+
if (tbs >= 0 && tbs < int(mTBinClOccHist.size())) {
357+
smb += mTBinClOccHist[tbs];
358+
}
359+
tbs++;
360+
}
361+
mcVtx.occTPCV[ib] = smb;
362+
}
363+
}
341364
if (rofCount >= ITSClusROFRec.size()) {
342365
mITSOcc.push_back(0); // IR after the last ROF
343366
}
@@ -352,15 +375,17 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
352375
int nev = mcReader.getNEvents(curSrcMC);
353376
bool okAccVtx = true;
354377
if (nev != (int)mMCVtVec.size()) {
355-
LOGP(error, "source {} has {} events while {} MC vertices were booked", curSrcMC, nev, mMCVtVec.size());
378+
LOGP(debug, "source {} has {} events while {} MC vertices were booked", curSrcMC, nev, mMCVtVec.size());
356379
okAccVtx = false;
380+
if (nev > (int)mMCVtVec.size()) { // QED
381+
continue;
382+
}
357383
}
358384
for (curEvMC = 0; curEvMC < nev; curEvMC++) {
359385
if (mVerbose > 1) {
360386
LOGP(info, "Event {}", curEvMC);
361387
}
362-
const auto& mt = mcReader.getTracks(curSrcMC, curEvMC);
363-
mCurrMCTracks = gsl::span<const MCTrack>(mt.data(), mt.size());
388+
mCurrMCTracks = &mcReader.getTracks(curSrcMC, curEvMC);
364389
const_cast<o2::dataformats::MCEventHeader&>(mcReader.getMCEventHeader(curSrcMC, curEvMC)).GetVertex(mCurrMCVertex);
365390
if (okAccVtx) {
366391
auto& pos = mMCVtVec[curEvMC].pos;
@@ -370,7 +395,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
370395
pos[2] = mCurrMCVertex.Z();
371396
}
372397
}
373-
for (int itr = 0; itr < mCurrMCTracks.size(); itr++) {
398+
for (int itr = 0; itr < mCurrMCTracks->size(); itr++) {
374399
processMCParticle(curSrcMC, curEvMC, itr);
375400
}
376401
}
@@ -382,6 +407,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
382407
}
383408

384409
// add reconstruction info to MC particles. If MC particle was not selected before but was reconstrected, account MC info
410+
mRecProcStage = true; // MC particles accepted only at this stage will be flagged
385411
for (int iv = 0; iv < nv; iv++) {
386412
if (mVerbose > 1) {
387413
LOGP(info, "processing PV {} of {}", iv, nv);
@@ -416,11 +442,10 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
416442
if (lbl.getSourceID() != curSrcMC || lbl.getEventID() != curEvMC) {
417443
curSrcMC = lbl.getSourceID();
418444
curEvMC = lbl.getEventID();
419-
const auto& mt = mcReader.getTracks(curSrcMC, curEvMC);
420-
mCurrMCTracks = gsl::span<const MCTrack>(mt.data(), mt.size());
445+
mCurrMCTracks = &mcReader.getTracks(curSrcMC, curEvMC);
421446
const_cast<o2::dataformats::MCEventHeader&>(mcReader.getMCEventHeader(curSrcMC, curEvMC)).GetVertex(mCurrMCVertex);
422447
}
423-
if (!acceptMCCharged(mCurrMCTracks[lbl.getTrackID()], lbl)) {
448+
if (!acceptMCCharged((*mCurrMCTracks)[lbl.getTrackID()], lbl)) {
424449
continue;
425450
}
426451
entry = mSelMCTracks.find(lbl);
@@ -532,7 +557,7 @@ void TrackMCStudy::process(const o2::globaltracking::RecoContainer& recoData)
532557
if (msk[DetID::TPC]) {
533558
const auto& trtpc = recoData.getTPCTrack(gidSet[GTrackID::TPC]);
534559
tref.nClTPC = trtpc.getNClusters();
535-
tref.lowestPadRow = getLowestPadrow(trtpc);
560+
getLowestPadrow(trtpc, tref);
536561
flagTPCClusters(trtpc, entry.first);
537562
if (trackFam.entTPC < 0) {
538563
trackFam.entTPC = tcnt;
@@ -968,7 +993,7 @@ float TrackMCStudy::getDCAYCut(float pt) const
968993

969994
bool TrackMCStudy::processMCParticle(int src, int ev, int trid)
970995
{
971-
const auto& mcPart = mCurrMCTracks[trid];
996+
const auto& mcPart = (*mCurrMCTracks)[trid];
972997
int pdg = mcPart.GetPdgCode();
973998
bool res = false;
974999
while (true) {
@@ -990,7 +1015,7 @@ bool TrackMCStudy::processMCParticle(int src, int ev, int trid)
9901015
break;
9911016
}
9921017
for (int idd = idd0; idd <= idd1; idd++) {
993-
const auto& product = mCurrMCTracks[idd];
1018+
const auto& product = (*mCurrMCTracks)[idd];
9941019
auto lbld = o2::MCCompLabel(idd, ev, src);
9951020
if (!acceptMCCharged(product, lbld, decay)) {
9961021
decay = -1; // discard decay
@@ -1088,10 +1113,17 @@ bool TrackMCStudy::addMCParticle(const MCTrack& mcPart, const o2::MCCompLabel& l
10881113
mcEntry.mcTrackInfo.bcInTF = mIntBC[lb.getEventID()];
10891114
mcEntry.mcTrackInfo.occTPC = mTPCOcc[lb.getEventID()];
10901115
mcEntry.mcTrackInfo.occITS = mITSOcc[lb.getEventID()];
1116+
mcEntry.mcTrackInfo.occTPCV = mMCVtVec[lb.getEventID()].occTPCV;
1117+
if (mRecProcStage) {
1118+
mcEntry.mcTrackInfo.setAddedAtRecStage();
1119+
}
1120+
if (o2::mcutils::MCTrackNavigator::isPhysicalPrimary(mcPart, *mCurrMCTracks)) {
1121+
mcEntry.mcTrackInfo.setPrimary();
1122+
}
10911123
int moth = -1;
10921124
o2::MCCompLabel mclbPar;
10931125
if ((moth = mcPart.getMotherTrackId()) >= 0) {
1094-
const auto& mcPartPar = mCurrMCTracks[moth];
1126+
const auto& mcPartPar = (*mCurrMCTracks)[moth];
10951127
mcEntry.mcTrackInfo.pdgParent = mcPartPar.GetPdgCode();
10961128
}
10971129
if (mcPart.isPrimary() && mcReader.getNEvents(lb.getSourceID()) == mMCVtVec.size()) {

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TimeFrame.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ struct TimeFrame {
9191
gsl::span<const unsigned char>::iterator& pattIt,
9292
const itsmft::TopologyDictionary* dict,
9393
const dataformats::MCTruthContainer<MCCompLabel>* mcLabels = nullptr);
94+
void resetROFrameData();
9495

9596
int getTotalClusters() const;
9697
auto& getTotVertIteration() { return mTotVertPerIteration; }
@@ -138,7 +139,7 @@ struct TimeFrame {
138139
gsl::span<const MCCompLabel> getClusterLabels(int layerId, const int clId) const { return mClusterLabels->getLabels(mClusterExternalIndices[layerId][clId]); }
139140
int getClusterExternalIndex(int layerId, const int clId) const { return mClusterExternalIndices[layerId][clId]; }
140141
int getClusterSize(int clusterId) const { return mClusterSize[clusterId]; }
141-
void setClusterSize(const bounded_vector<uint8_t>& v) { mClusterSize = v; }
142+
void setClusterSize(bounded_vector<uint8_t>& v) { mClusterSize = std::move(v); }
142143

143144
auto& getTrackletsLabel(int layer) { return mTrackletLabels[layer]; }
144145
auto& getCellsLabel(int layer) { return mCellLabels[layer]; }

Detectors/ITSMFT/ITS/tracking/include/ITStracking/Tracker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include <utility>
2828
#include <sstream>
2929

30+
#include <oneapi/tbb/task_arena.h>
31+
3032
#include "ITStracking/Configuration.h"
3133
#include "CommonConstants/MathConstants.h"
3234
#include "ITStracking/Definitions.h"
@@ -73,8 +75,7 @@ class Tracker
7375
void setBz(float bz) { mTraits->setBz(bz); }
7476
void setCorrType(const o2::base::PropagatorImpl<float>::MatCorrType type) { mTraits->setCorrType(type); }
7577
bool isMatLUT() const { return mTraits->isMatLUT(); }
76-
void setNThreads(int n) { mTraits->setNThreads(n); }
77-
int getNThreads() const { return mTraits->getNThreads(); }
78+
void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena) { mTraits->setNThreads(n, arena); }
7879
void printSummary() const;
7980

8081
private:

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TrackerTraits.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ class TrackerTraits
8080
void SetRecoChain(o2::gpu::GPUChainITS* chain) { mChain = chain; }
8181
void setSmoothing(bool v) { mApplySmoothing = v; }
8282
bool getSmoothing() const { return mApplySmoothing; }
83-
void setNThreads(int n);
84-
int getNThreads() const { return mNThreads; }
83+
void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena);
84+
int getNThreads() { return mTaskArena->max_concurrency(); }
8585

8686
o2::gpu::GPUChainITS* getChain() const { return mChain; }
8787

@@ -94,10 +94,9 @@ class TrackerTraits
9494
track::TrackParCov buildTrackSeed(const Cluster& cluster1, const Cluster& cluster2, const TrackingFrameInfo& tf3);
9595
bool fitTrack(TrackITSExt& track, int start, int end, int step, float chi2clcut = o2::constants::math::VeryBig, float chi2ndfcut = o2::constants::math::VeryBig, float maxQoverPt = o2::constants::math::VeryBig, int nCl = 0);
9696

97-
int mNThreads = 1;
9897
bool mApplySmoothing = false;
9998
std::shared_ptr<BoundedMemoryResource> mMemoryPool;
100-
tbb::task_arena mTaskArena;
99+
std::shared_ptr<tbb::task_arena> mTaskArena;
101100

102101
protected:
103102
o2::base::PropagatorImpl<float>::MatCorrType mCorrType = o2::base::PropagatorImpl<float>::MatCorrType::USEMatCorrNONE;

0 commit comments

Comments
 (0)