Skip to content

Commit c365c50

Browse files
authored
PWG-UD: update of skimmer DGBCCandProducer (#2823)
* Ar the end reset the bc iterator to the original position * Improve processing speed of DGBCCandProducer * Several updates of DGCanAnalyzer * clang-format * Megalinter warning
1 parent 4c3c202 commit c365c50

3 files changed

Lines changed: 189 additions & 90 deletions

File tree

PWGUD/Core/UDHelpers.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,19 +172,22 @@ T compatibleBCs(I& bcIter, uint64_t meanBC, int deltaBC, T const& bcs)
172172
LOGF(debug, " minBC %d maxBC %d bcIterator %d (%d)", minBC, maxBC, bcIter.globalBC(), bcIter.globalIndex());
173173

174174
// find slice of BCs table with BC in [minBC, maxBC]
175+
int moveCount = 0;
175176
int64_t minBCId = bcIter.globalIndex();
176177
int64_t maxBCId = bcIter.globalIndex();
177178

178179
// lower limit
179180
if (bcIter.globalBC() < minBC) {
180181
while (bcIter != bcs.end() && bcIter.globalBC() < minBC) {
181182
++bcIter;
183+
++moveCount;
182184
minBCId = bcIter.globalIndex();
183185
}
184186
} else {
185187
while (bcIter.globalIndex() > 0 && bcIter.globalBC() >= minBC) {
186188
minBCId = bcIter.globalIndex();
187189
--bcIter;
190+
--moveCount;
188191
}
189192
}
190193

@@ -193,16 +196,22 @@ T compatibleBCs(I& bcIter, uint64_t meanBC, int deltaBC, T const& bcs)
193196
while (bcIter != bcs.end() && bcIter.globalBC() <= maxBC) {
194197
maxBCId = bcIter.globalIndex();
195198
++bcIter;
199+
++moveCount;
196200
}
197201

198202
} else {
199203
while (bcIter.globalIndex() > 0 && bcIter.globalBC() > maxBC) {
200204
--bcIter;
205+
--moveCount;
201206
maxBCId = bcIter.globalIndex();
202207
}
203208
}
204209
LOGF(debug, " BC range: %d - %d", minBCId, maxBCId);
205210

211+
// reset bcIter
212+
bcIter.moveByIndex(-moveCount);
213+
214+
// create bc slice
206215
T slice{{bcs.asArrowTable()->Slice(minBCId, maxBCId - minBCId + 1)}, (uint64_t)minBCId};
207216
bcs.copyIndexBindings(slice);
208217
LOGF(debug, " size of slice %d", slice.size());

PWGUD/TableProducer/DGBCCandProducer.cxx

Lines changed: 92 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
/// \author Paul Buehler, paul.buehler@oeaw.ac.at
1515
/// \since 30.09.2022
1616

17+
#include <algorithm>
1718
#include "Framework/runDataProcessing.h"
1819
#include "Framework/AnalysisTask.h"
1920
#include "PWGUD/DataModel/UDTables.h"
@@ -26,7 +27,6 @@ using namespace o2;
2627
using namespace o2::framework;
2728
using namespace o2::framework::expressions;
2829

29-
// -----------------------------------------------------------------------------
3030
struct tracksWGTInBCs {
3131
Produces<aod::TracksWGTInBCs> tracksWGTInBCs;
3232
Produces<aod::FwdTracksWGTInBCs> fwdTracksWGTInBCs;
@@ -72,6 +72,7 @@ struct tracksWGTInBCs {
7272
LOGF(debug, "Number of barrel tracks: %d", tracks.size());
7373
for (auto const& track : tracks) {
7474
registry.get<TH1>(HIST("barrel/Tracks"))->Fill(0., 1.);
75+
// is this track an ambiguous track?
7576
auto ambTracksSlice = ambTracks.sliceBy(perTrack, track.globalIndex());
7677
if (ambTracksSlice.size() > 0) {
7778
registry.get<TH1>(HIST("barrel/Tracks"))->Fill(2., 1.);
@@ -122,7 +123,7 @@ struct tracksWGTInBCs {
122123
tracksWGTInBCs(indBCToSave, rnum, tracksInBC.first, tracksInBC.second);
123124
LOGF(debug, " BC %i/%u with %i tracks with good timing", indBCToSave, tracksInBC.first, tracksInBC.second.size());
124125
}
125-
LOGF(debug, "barrel done");
126+
LOGF(info, "barrel done");
126127
}
127128
PROCESS_SWITCH(tracksWGTInBCs, processBarrel, "Process barrel tracks", false);
128129

@@ -142,6 +143,7 @@ struct tracksWGTInBCs {
142143
LOGF(debug, "Number of forward tracks: %d", fwdTracks.size());
143144
for (auto const& fwdTrack : fwdTracks) {
144145
registry.get<TH1>(HIST("forward/Tracks"))->Fill(0., 1.);
146+
// is this track an ambiguous track?
145147
auto ambFwdTracksSlice = ambFwdTracks.sliceBy(perFwdTrack, fwdTrack.globalIndex());
146148
if (ambFwdTracksSlice.size() > 0) {
147149
registry.get<TH1>(HIST("forward/Tracks"))->Fill(2., 1.);
@@ -194,7 +196,7 @@ struct tracksWGTInBCs {
194196
fwdTracksWGTInBCs(indBCToSave, rnum, fwdTracksInBC.first, fwdTracksInBC.second);
195197
LOGF(debug, " BC %i/%u with %i forward tracks with good timing", indBCToSave, fwdTracksInBC.first, fwdTracksInBC.second.size());
196198
}
197-
LOGF(debug, "fwd done");
199+
LOGF(info, "fwd done");
198200
}
199201
PROCESS_SWITCH(tracksWGTInBCs, processForward, "Process forward tracks", false);
200202

@@ -223,7 +225,7 @@ struct DGBCCandProducer {
223225
Configurable<DGCutparHolder> DGCuts{"DGCuts", {}, "DG event cuts"};
224226

225227
// DG selector
226-
DGSelector dgSelector = DGSelector();
228+
DGSelector dgSelector;
227229

228230
HistogramRegistry registry{
229231
"registry",
@@ -275,10 +277,9 @@ struct DGBCCandProducer {
275277
}
276278

277279
// extract FIT information
278-
upchelpers::FITInfo getFITinfo(uint64_t const& bcnum, BCs const& bcs, aod::FT0s const& ft0s, aod::FV0As const& fv0as, aod::FDDs const& fdds)
280+
void getFITinfo(upchelpers::FITInfo info, uint64_t const& bcnum, BCs const& bcs, aod::FT0s const& ft0s, aod::FV0As const& fv0as, aod::FDDs const& fdds)
279281
{
280282
// FITinfo
281-
upchelpers::FITInfo info{};
282283
uint64_t minbc = bcnum > 16 ? bcnum - 16 : 0;
283284

284285
// find bc with globalBC = bcnum
@@ -343,7 +344,6 @@ struct DGBCCandProducer {
343344
auto bcrange = udhelpers::compatibleBCs(bcnum, 16, bcs);
344345
fillBGBBFlags(info, minbc, bcrange);
345346
}
346-
return info;
347347
}
348348

349349
// function to update UDTracks, UDTracksCov, UDTracksDCA, UDTracksPID, UDTracksExtra, UDTracksFlag,
@@ -444,7 +444,8 @@ struct DGBCCandProducer {
444444
{
445445
// fill FITInfo
446446
auto bcnum = tibc.bcnum();
447-
upchelpers::FITInfo fitInfo = getFITinfo(bcnum, bcs, ft0s, fv0as, fdds);
447+
upchelpers::FITInfo fitInfo{};
448+
getFITinfo(fitInfo, bcnum, bcs, ft0s, fv0as, fdds);
448449

449450
// check if DG event
450451
// distinguish between cases with and without associated BC
@@ -528,7 +529,7 @@ struct DGBCCandProducer {
528529
outputZdcs(outputCollisions.lastIndex(), enes, chEs, amps, times, chTs);
529530
}
530531
} else {
531-
LOGF(info, "3. BC NOT found");
532+
LOGF(info, " 3. BC NOT found");
532533

533534
// the BC is not contained in the BCs table
534535
auto tracksArray = tibc.track_as<TCs>();
@@ -599,50 +600,72 @@ struct DGBCCandProducer {
599600
return;
600601
}
601602

602-
// run over globalBC [minGlobalBC, maxGlobalBC] ...
603+
// run over all BC in bcs and tibcs
604+
int64_t lastCollision = 0;
603605
float vpos[3];
604-
uint64_t minGlobalBC = bcs.iteratorAt(0).globalBC();
605-
uint64_t maxGlobalBC = bcs.iteratorAt(bcs.size() - 1).globalBC();
606-
// ... and advance these pointers step-by-step
606+
upchelpers::FITInfo fitInfo{};
607+
auto col = collisions.iteratorAt(0);
607608
auto bc = bcs.iteratorAt(0);
608609
auto tibc = tibcs.iteratorAt(0);
609610
auto ftibc = ftibcs.iteratorAt(0);
611+
auto lastcol = collisions.iteratorAt(collisions.size() - 1);
610612
auto lastbc = bcs.iteratorAt(bcs.size() - 1);
611613
auto lasttibc = tibcs.iteratorAt(tibcs.size() - 1);
612614
auto lastftibc = ftibcs.iteratorAt(ftibcs.size() - 1);
613-
LOGF(debug, "bcs %d tibcs %d ftibcs %d", bcs.size(), tibcs.size(), ftibcs.size());
614-
615-
for (auto bcnum = minGlobalBC; bcnum <= maxGlobalBC; bcnum++) {
616-
LOGF(debug, "max %d now %d", maxGlobalBC, bcnum);
617-
615+
LOGF(info, "bcs %d tibcs %d ftibcs %d", bcs.size(), tibcs.size(), ftibcs.size());
616+
617+
// set first bcnum
618+
bool bc2go = bc != lastbc;
619+
bool tibc2go = tibcs.size() > 0 ? tibc != lasttibc : false;
620+
auto bcnum = bc.globalBC();
621+
if (tibc2go) {
622+
if (tibc.bcnum() < bcnum) {
623+
bcnum = tibc.bcnum();
624+
}
625+
}
626+
bool withCollision = false;
627+
while (bc2go || tibc2go) {
628+
LOGF(debug, "Testing bc %d", bcnum);
618629
// reset counters
619630
bcFlag = 1; // bit 0 is always set
620631
isDG1 = -1;
621632
isDG2 = -1;
622633
ntr1 = -1;
623634
ntr2 = -1;
624635

625-
// find BC in BCs table
626-
while (bc.globalBC() < bcnum && bc != lastbc) {
627-
++bc;
628-
}
629-
// find associated collision
630-
Partition<CCs> colSlize = aod::evsel::foundBCId == bc.globalIndex();
631-
colSlize.bindTable(collisions);
632-
colSlize.bindExternalIndices(&bcs);
633-
634636
if (bc.globalBC() == bcnum) {
635637
SETBIT(bcFlag, 1);
636638

637-
if (colSlize.size() > 0) {
639+
// find associated collision
640+
withCollision = false;
641+
auto goOn = col != lastcol;
642+
while (goOn) {
643+
if (col.has_foundBC()) {
644+
auto bc2u = col.foundBC_as<BCs>();
645+
if (bc2u.globalBC() >= bcnum) {
646+
goOn = false;
647+
if (bc2u.globalBC() == bcnum) {
648+
withCollision = true;
649+
}
650+
} else {
651+
col++;
652+
}
653+
} else {
654+
col++;
655+
}
656+
goOn &= col != lastcol;
657+
}
658+
LOGF(debug, " withCollision %d", withCollision);
659+
660+
if (withCollision) {
638661
// -> vertex position: col.[posX(), posY(), posZ()]
639662
SETBIT(bcFlag, 2);
663+
lastCollision = col.globalIndex();
640664

641-
auto col = colSlize.begin();
642665
ntr1 = col.numContrib();
666+
auto bcRange = udhelpers::compatibleBCs(bc, bcnum, diffCuts.minNBCs(), bcs);
643667
auto colTracks = tracks.sliceBy(TCperCollision, col.globalIndex());
644668
auto colFwdTracks = fwdtracks.sliceBy(FWperCollision, col.globalIndex());
645-
auto bcRange = udhelpers::compatibleBCs1(col, diffCuts.NDtcoll(), bcs, diffCuts.minNBCs());
646669
isDG1 = dgSelector.IsSelected(diffCuts, col, bcRange, colTracks, colFwdTracks);
647670
if (isDG1 == 0) {
648671
// this is a DG candidate with proper collision vertex
@@ -651,28 +674,25 @@ struct DGBCCandProducer {
651674

652675
auto rtrwTOF = udhelpers::rPVtrwTOF<true>(colTracks, col.numContrib());
653676
auto nCharge = udhelpers::netCharge<true>(colTracks);
654-
auto fitInfo = getFITinfo(bcnum, bcs, ft0s, fv0as, fdds);
677+
getFITinfo(fitInfo, bcnum, bcs, ft0s, fv0as, fdds);
655678
updateUDTables(false, bcnum, bc.runNumber(), col.posX(), col.posY(), col.posZ(),
656679
col.numContrib(), nCharge, rtrwTOF, colTracks, fitInfo);
657680
// fill UDZdcs
658681
if (bc.has_zdc()) {
659682
auto zdc = bc.zdc();
660-
std::vector<float> enes(zdc.energy()[0]);
661-
std::vector<uint8_t> chEs(zdc.channelE()[0]);
662-
std::vector<float> amps(zdc.amplitude()[0]);
663-
std::vector<float> times(zdc.time()[0]);
664-
std::vector<uint8_t> chTs(zdc.channelT()[0]);
683+
auto enes = std::vector(zdc.energy().begin(), zdc.energy().end());
684+
auto chEs = std::vector(zdc.channelE().begin(), zdc.channelE().end());
685+
auto amps = std::vector(zdc.amplitude().begin(), zdc.amplitude().end());
686+
auto times = std::vector(zdc.time().begin(), zdc.time().end());
687+
auto chTs = std::vector(zdc.channelT().begin(), zdc.channelT().end());
665688
outputZdcs(outputCollisions.lastIndex(), enes, chEs, amps, times, chTs);
666689
}
667690
}
668691
}
669692
}
670693

671694
// find BC in TracksWGTInBCs table
672-
if (tibcs.size() > 0) {
673-
while (tibc.bcnum() < bcnum && tibc != lasttibc) {
674-
++tibc;
675-
}
695+
if (tibc2go) {
676696
if (tibc.bcnum() == bcnum) {
677697
SETBIT(bcFlag, 4);
678698

@@ -703,11 +723,11 @@ struct DGBCCandProducer {
703723

704724
auto rtrwTOF = udhelpers::rPVtrwTOF<false>(tracksArray, tracksArray.size());
705725
auto nCharge = udhelpers::netCharge<false>(tracksArray);
706-
auto fitInfo = getFITinfo(bcnum, bcs, ft0s, fv0as, fdds);
726+
getFITinfo(fitInfo, bcnum, bcs, ft0s, fv0as, fdds);
707727

708728
// distinguish different cases
709729
if (bc.globalBC() == bcnum) {
710-
if (colSlize.size() > 0) {
730+
if (withCollision) {
711731
vpos[0] = -1.;
712732
vpos[1] = 1.;
713733
vpos[2] = -1.;
@@ -729,11 +749,11 @@ struct DGBCCandProducer {
729749
if (bc.globalBC() == bcnum) {
730750
if (bc.has_zdc()) {
731751
auto zdc = bc.zdc();
732-
std::vector<float> enes(zdc.energy()[0]);
733-
std::vector<uint8_t> chEs(zdc.channelE()[0]);
734-
std::vector<float> amps(zdc.amplitude()[0]);
735-
std::vector<float> times(zdc.time()[0]);
736-
std::vector<uint8_t> chTs(zdc.channelT()[0]);
752+
auto enes = std::vector(zdc.energy().begin(), zdc.energy().end());
753+
auto chEs = std::vector(zdc.channelE().begin(), zdc.channelE().end());
754+
auto amps = std::vector(zdc.amplitude().begin(), zdc.amplitude().end());
755+
auto times = std::vector(zdc.time().begin(), zdc.time().end());
756+
auto chTs = std::vector(zdc.channelT().begin(), zdc.channelT().end());
737757
outputZdcs(outputCollisions.lastIndex(), enes, chEs, amps, times, chTs);
738758
}
739759
}
@@ -748,6 +768,31 @@ struct DGBCCandProducer {
748768
if (isDG1 == 0 && isDG2 == 0) {
749769
registry.get<TH2>(HIST("data/ntr1vsntr2Cand"))->Fill(ntr1, ntr2);
750770
}
771+
772+
// update bc and tibc
773+
if (bc2go) {
774+
if (bc.globalBC() == bcnum) {
775+
bc++;
776+
}
777+
}
778+
if (tibc2go) {
779+
if (tibc.bcnum() == bcnum) {
780+
tibc++;
781+
}
782+
}
783+
// determine next bcnum
784+
bc2go = bc != lastbc;
785+
tibc2go = tibcs.size() > 0 ? tibc != lasttibc : false;
786+
if (bc2go) {
787+
bcnum = bc.globalBC();
788+
if (tibc2go) {
789+
bcnum = std::min(bc.globalBC(), tibc.bcnum());
790+
}
791+
} else {
792+
if (tibc2go) {
793+
bcnum = tibc.bcnum();
794+
}
795+
}
751796
}
752797
}
753798

0 commit comments

Comments
 (0)