Skip to content

Commit 58542e4

Browse files
authored
[DPG] tpcSkimsTableCreator: bugfix reserve tables size (#16739)
1 parent 5e0f4ba commit 58542e4

1 file changed

Lines changed: 71 additions & 7 deletions

File tree

DPG/Tasks/TPC/tpcSkimsTableCreator.cxx

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include <Framework/AnalysisHelpers.h>
4343
#include <Framework/AnalysisTask.h>
4444
#include <Framework/Configurable.h>
45+
#include <Framework/HistogramRegistry.h>
46+
#include <Framework/HistogramSpec.h>
4547
#include <Framework/InitContext.h>
4648
#include <Framework/runDataProcessing.h>
4749
#include <ReconstructionDataFormats/PID.h>
@@ -101,6 +103,10 @@ struct TreeWriterTpcV0 {
101103
Configurable<float> maxPt4dwnsmplTsalisProtons{"maxPt4dwnsmplTsalisProtons", 100., "Maximum Pt for applying downsampling factor of protons"};
102104
Configurable<float> maxPt4dwnsmplTsalisElectrons{"maxPt4dwnsmplTsalisElectrons", 100., "Maximum Pt for applying downsampling factor of electrons"};
103105
Configurable<float> maxPt4dwnsmplTsalisKaons{"maxPt4dwnsmplTsalisKaons", 100., "Maximum Pt for applying downsampling factor of kaons"};
106+
// Configurables for output tables reservation size
107+
Configurable<float> reserveV0Ratio{"reserveV0Ratio", 0.05, "Ratio of how many tracks from V0s are expected in the output table to the input V0 table size"};
108+
Configurable<float> reserveCascRatio{"reserveCascRatio", 0.0025, "Ratio of how many tracks from cascades are expected in the output table to the input Cascade table size"};
109+
Configurable<bool> saveReserveQaHisto{"saveReserveQaHisto", true, "Flag to save the DF-wise ratio of output table size to that of input table"};
104110
// Configurables for run condtion table
105111
Configurable<std::string> rctLabel{"rctLabel", "CBT_hadronPID", "select 1 [CBT, CBT_hadronPID, CBT_muon_glo] see O2Physics/Common/CCDB/RCTSelectionFlags.h"};
106112
Configurable<bool> checkZdc{"checkZdc", false, "set ZDC flag for PbPb"};
@@ -109,6 +115,8 @@ struct TreeWriterTpcV0 {
109115
// Configurable for the path of CCDB General Run Parameters LHC Interface information
110116
Configurable<std::string> ccdbPathGrpLhcIf{"ccdbPathGrpLhcIf", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"};
111117

118+
HistogramRegistry registry{"registry", {}};
119+
112120
// an arbitrary value of N sigma TOF assigned by TOF task to tracks which are not matched to TOF hits
113121
constexpr static float NSigmaTofUnmatched{o2::aod::v0data::kNoTOFValue};
114122
const float nSigmaTofUnmatchedEqualityTolerance{std::fabs(NSigmaTofUnmatched) / 1e4f};
@@ -182,6 +190,11 @@ struct TreeWriterTpcV0 {
182190
ccdb->setFatalWhenNull(false);
183191

184192
rctChecker.init(rctLabel, checkZdc, treatLimitedAcceptanceAsBad);
193+
194+
if (saveReserveQaHisto) {
195+
registry.add("hV0OutputRatio", "V0 out/in ratio;V0 out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveV0Ratio}}});
196+
registry.add("hCascOutputRatio", "Casc out/in ratio;Casc out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveCascRatio}}});
197+
}
185198
}
186199

187200
template <bool IsCorrectedDeDx, typename V0Casc, typename T>
@@ -422,6 +435,16 @@ struct TreeWriterTpcV0 {
422435
aod::pidits::ITSNSigmaEl, aod::pidits::ITSNSigmaPi,
423436
aod::pidits::ITSNSigmaKa, aod::pidits::ITSNSigmaPr>(myTracks);
424437

438+
int nV0Entries{0};
439+
int nCascEntries{0};
440+
441+
const int64_t expectedOutputTableSize = static_cast<int64_t>(reserveV0Ratio * myV0s.size() + reserveCascRatio * myCascs.size());
442+
if constexpr (ModeId == ModeWithdEdxTrkQA || ModeId == ModeStandard) {
443+
rowTPCTree.reserve(expectedOutputTableSize);
444+
} else {
445+
rowTPCTreeWithTrkQA.reserve(expectedOutputTableSize);
446+
}
447+
425448
std::string irSource{};
426449
float sqrtSNN{};
427450
bool isFirstCollision{true};
@@ -448,11 +471,9 @@ struct TreeWriterTpcV0 {
448471
if constexpr (ModeId == ModeWithdEdxTrkQA || ModeId == ModeStandard) {
449472
bcTimeFrameId = UndefValueInt;
450473
bcBcInTimeFrame = UndefValueInt;
451-
rowTPCTree.reserve(2 * v0s.size() + cascs.size());
452474
} else if constexpr (ModeId == ModeWithTrkQA) {
453475
bcTimeFrameId = bc.tfId();
454476
bcBcInTimeFrame = bc.bcInTF();
455-
rowTPCTreeWithTrkQA.reserve(2 * v0s.size() + cascs.size());
456477
}
457478

458479
auto getTrackQA = [&](const TrksType::iterator& track) {
@@ -488,7 +509,9 @@ struct TreeWriterTpcV0 {
488509
evaluateOccupancyVariables(dauTrack, occValues);
489510
}
490511
fillSkimmedV0Table<IsCorrectedDeDx, ModeId>(mother, dauTrack, trackQAInstance, existTrkQA, collision, daughter.tpcNSigma, daughter.tofNSigma, daughter.itsNSigma, daughter.tpcExpSignal, daughter.id, runnumber, daughter.dwnSmplFactor, hadronicRate, bcGlobalIndex, bcTimeFrameId, bcBcInTimeFrame, occValues, isGoodRctEvent);
512+
return true;
491513
}
514+
return false;
492515
};
493516

494517
/// Loop over v0 candidates
@@ -500,8 +523,12 @@ struct TreeWriterTpcV0 {
500523
const auto posTrack = v0.posTrack_as<TrksType>();
501524
const auto negTrack = v0.negTrack_as<TrksType>();
502525

503-
fillDaughterTrack(v0, posTrack, v0, true);
504-
fillDaughterTrack(v0, negTrack, v0, false);
526+
if (fillDaughterTrack(v0, posTrack, v0, true)) {
527+
++nV0Entries;
528+
}
529+
if (fillDaughterTrack(v0, negTrack, v0, false)) {
530+
++nV0Entries;
531+
}
505532
}
506533

507534
/// Loop over cascade candidates
@@ -513,9 +540,23 @@ struct TreeWriterTpcV0 {
513540
const auto bachTrack = casc.bachelor_as<TrksType>();
514541
// Omega and antiomega
515542
const auto isDaughterPositive = cascId == MotherAntiOmega ? true : false;
516-
fillDaughterTrack(casc, bachTrack, casc, isDaughterPositive);
543+
if (fillDaughterTrack(casc, bachTrack, casc, isDaughterPositive)) {
544+
++nCascEntries;
545+
}
517546
}
518547
}
548+
LOG(info) << "runV0() summary:";
549+
LOG(info) << "V0 table size = " << myV0s.size();
550+
LOG(info) << "Cascade table size = " << myCascs.size();
551+
LOG(info) << "nV0Entries = " << nV0Entries;
552+
LOG(info) << "nCascEntries = " << nCascEntries;
553+
LOG(info) << "nV0Entries / V0 table size = " << static_cast<double>(nV0Entries) / myV0s.size();
554+
LOG(info) << "nCascEntries / Cascade table size = " << static_cast<double>(nCascEntries) / myCascs.size();
555+
556+
if (saveReserveQaHisto) {
557+
registry.fill(HIST("hV0OutputRatio"), static_cast<double>(nV0Entries) / myV0s.size());
558+
registry.fill(HIST("hCascOutputRatio"), static_cast<double>(nCascEntries) / myCascs.size());
559+
}
519560
} /// runV0
520561

521562
void processStandard(Colls const& collisions,
@@ -637,6 +678,9 @@ struct TreeWriterTpcTof {
637678
Configurable<float> downsamplingTsalisProtons{"downsamplingTsalisProtons", -1., "Downsampling factor to reduce the number of protons"};
638679
Configurable<float> downsamplingTsalisKaons{"downsamplingTsalisKaons", -1., "Downsampling factor to reduce the number of kaons"};
639680
Configurable<float> downsamplingTsalisPions{"downsamplingTsalisPions", -1., "Downsampling factor to reduce the number of pions"};
681+
// Configurable for output table reservation size
682+
Configurable<float> reserveTrackRatio{"reserveTrackRatio", 0.003, "Ratio of how many tracks are expected in the output table to the input Tracks table size"};
683+
Configurable<bool> saveReserveQaHisto{"saveReserveQaHisto", true, "Flag to save the DF-wise ratio of output table size to that of input table"};
640684
// Configurables for run condtion table
641685
Configurable<std::string> rctLabel{"rctLabel", "CBT_hadronPID", "select 1 [CBT, CBT_hadronPID, CBT_muon_glo] see O2Physics/Common/CCDB/RCTSelectionFlags.h"};
642686
Configurable<bool> checkZdc{"checkZdc", false, "set ZDC flag for PbPb"};
@@ -645,6 +689,8 @@ struct TreeWriterTpcTof {
645689
// Configurable for the path of CCDB General Run Parameters LHC Interface information
646690
Configurable<std::string> ccdbPathGrpLhcIf{"ccdbPathGrpLhcIf", "GLO/Config/GRPLHCIF", "Path on the CCDB for the GRPLHCIF object"};
647691

692+
HistogramRegistry registry{"registry", {}};
693+
648694
struct TofTrack {
649695
bool isApplyHardCutOnly;
650696
double maxMomHardCutOnly;
@@ -699,6 +745,10 @@ struct TreeWriterTpcTof {
699745
ccdb->setFatalWhenNull(false);
700746

701747
rctChecker.init(rctLabel, checkZdc, treatLimitedAcceptanceAsBad);
748+
749+
if (saveReserveQaHisto) {
750+
registry.add("hTrackOutputRatio", "Track out/in ratio;Track out/in ratio;Entries", {HistType::kTH1F, {{100, 0, reserveTrackRatio}}});
751+
}
702752
}
703753

704754
template <bool DoCorrectDeDx, int ModeId, typename T, typename C>
@@ -810,6 +860,14 @@ struct TreeWriterTpcTof {
810860
labelTrack2TrackQA.at(trackId) = trackQA.globalIndex();
811861
}
812862
}
863+
864+
const int64_t expectedOutputTableSize = static_cast<int64_t>(reserveTrackRatio * myTracks.size());
865+
if constexpr (ModeId == ModeWithdEdxTrkQA || ModeId == ModeStandard) {
866+
rowTPCTOFTree.reserve(expectedOutputTableSize);
867+
} else {
868+
rowTPCTOFTreeWithTrkQA.reserve(expectedOutputTableSize);
869+
}
870+
813871
std::string irSource{};
814872
float sqrtSNN{};
815873
bool isFirstCollision{true};
@@ -843,11 +901,9 @@ struct TreeWriterTpcTof {
843901
if constexpr (ModeId == ModeStandard || ModeId == ModeWithdEdxTrkQA) {
844902
bcTimeFrameId = UndefValueInt;
845903
bcBcInTimeFrame = UndefValueInt;
846-
rowTPCTOFTree.reserve(tracks.size());
847904
} else {
848905
bcTimeFrameId = bc.tfId();
849906
bcBcInTimeFrame = bc.bcInTF();
850-
rowTPCTOFTreeWithTrkQA.reserve(tracks.size());
851907
}
852908
for (auto const& trk : tracksWithITSPid) {
853909
if (!isTrackSelected(trk, trackSelection)) {
@@ -889,6 +945,14 @@ struct TreeWriterTpcTof {
889945
}
890946
} /// Loop tracks
891947
}
948+
LOG(info) << "runTof() summary:";
949+
LOG(info) << "Track table size = " << myTracks.size();
950+
LOG(info) << "nTrackEntries = " << rowTPCTOFTree.lastIndex() + 1;
951+
LOG(info) << "nTrackEntries / Track table size = " << static_cast<double>((rowTPCTOFTree.lastIndex() + 1)) / myTracks.size();
952+
953+
if (saveReserveQaHisto) {
954+
registry.fill(HIST("hTrackOutputRatio"), static_cast<double>((rowTPCTOFTree.lastIndex() + 1)) / myTracks.size());
955+
}
892956
} /// runTof
893957

894958
void processStandard(Colls const& collisions,

0 commit comments

Comments
 (0)