Skip to content

Commit df3f84d

Browse files
authored
[PWGUD] enable skimmers to save all McCollisions, even if they are not reconstructed (AliceO2Group#10393)
1 parent 2064355 commit df3f84d

File tree

3 files changed

+153
-65
lines changed

3 files changed

+153
-65
lines changed

PWGUD/Core/UDHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ T compatibleBCs(B const& bc, uint64_t const& meanBC, int const& deltaBC, T const
122122

123123
// check [min,max]BC to overlap with [bcs.iteratorAt([0,bcs.size() - 1])
124124
if (maxBC < bcs.iteratorAt(0).globalBC() || minBC > bcs.iteratorAt(bcs.size() - 1).globalBC()) {
125-
LOGF(info, "<compatibleBCs> No overlap of [%d, %d] and [%d, %d]", minBC, maxBC, bcs.iteratorAt(0).globalBC(), bcs.iteratorAt(bcs.size() - 1).globalBC());
125+
LOGF(debug, "<compatibleBCs> No overlap of [%d, %d] and [%d, %d]", minBC, maxBC, bcs.iteratorAt(0).globalBC(), bcs.iteratorAt(bcs.size() - 1).globalBC());
126126
return T{{bcs.asArrowTable()->Slice(0, 0)}, static_cast<uint64_t>(0)};
127127
}
128128

PWGUD/TableProducer/DGCandProducer.cxx

Lines changed: 73 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ struct McDGCandProducer {
472472
Produces<aod::UDMcCollsLabels> outputMcCollsLabels;
473473
Produces<aod::UDMcTrackLabels> outputMcTrackLabels;
474474

475+
// save all McTruth, even if the collisions is not reconstructed
476+
Configurable<bool> saveAllMcCollisions{"saveAllMcCollisions", true, "save all McCollisions"};
477+
475478
using CCs = soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels>;
476479
using BCs = soa::Join<aod::BCsWithTimestamps, aod::BcSels, aod::Run3MatchedToBCSparse>;
477480
using TCs = soa::Join<aod::Tracks, aod::McTrackLabels>;
@@ -670,30 +673,10 @@ struct McDGCandProducer {
670673
}
671674
}
672675

673-
void init(InitContext& context)
674-
{
675-
// add histograms for the different process functions
676-
if (context.mOptions.get<bool>("processMCTruth")) {
677-
registry.add("mcTruth/collisions", "Number of associated collisions", {HistType::kTH1F, {{11, -0.5, 10.5}}});
678-
registry.add("mcTruth/collType", "Collision type", {HistType::kTH1F, {{5, -0.5, 4.5}}});
679-
registry.add("mcTruth/IVMpt", "Invariant mass versus p_{T}", {HistType::kTH2F, {{150, 0.0, 3.0}, {150, 0.0, 3.0}}});
680-
}
681-
}
682-
683-
// process function for MC data
684-
// save the MC truth of all events of interest and of the DG events
685-
void processMCTruth(aod::McCollisions const& mccols, aod::McParticles const& mcparts,
686-
UDCCs const& dgcands, UDTCs const& udtracks,
687-
CCs const& /*collisions*/, BCs const& /*bcs*/, TCs const& /*tracks*/)
676+
// updating McTruth data and links to reconstructed data
677+
void procWithDgCand(aod::McCollisions const& mccols, aod::McParticles const& mcparts,
678+
UDCCs const& dgcands, UDTCs const& udtracks)
688679
{
689-
LOGF(debug, "Number of McCollisions %d", mccols.size());
690-
LOGF(debug, "Number of DG candidates %d", dgcands.size());
691-
LOGF(debug, "Number of UD tracks %d", udtracks.size());
692-
if (dgcands.size() <= 0) {
693-
LOGF(info, "No DG candidates to save!");
694-
return;
695-
}
696-
697680
// use a hash table to keep track of the McCollisions which have been added to the UDMcCollision table
698681
// {McCollisionId : udMcCollisionId}
699682
// similar for the McParticles which have been added to the UDMcParticle table
@@ -703,18 +686,19 @@ struct McDGCandProducer {
703686

704687
// loop over McCollisions and UDCCs simultaneously
705688
auto mccol = mccols.iteratorAt(0);
706-
auto dgcand = dgcands.iteratorAt(0);
707689
auto lastmccol = mccols.iteratorAt(mccols.size() - 1);
690+
auto mccolAtEnd = false;
691+
692+
auto dgcand = dgcands.iteratorAt(0);
708693
auto lastdgcand = dgcands.iteratorAt(dgcands.size() - 1);
694+
auto dgcandAtEnd = false;
709695

710696
// advance dgcand and mccol until both are AtEnd
711697
int64_t mccolId = mccol.globalIndex();
712698
int64_t mcdgId = -1;
713699
int64_t colId = -1;
714-
auto dgcandAtEnd = dgcand == lastdgcand;
715-
auto mccolAtEnd = mccol == lastmccol;
716-
bool goon = !dgcandAtEnd || !mccolAtEnd;
717700

701+
bool goon = true;
718702
while (goon) {
719703
// check if dgcand has an associated Collision and McCollision
720704
if (dgcand.has_collision()) {
@@ -825,10 +809,71 @@ struct McDGCandProducer {
825809
mccolAtEnd = true;
826810
}
827811
}
828-
LOGF(debug, " UDMcCollsLabels %d (of %d) UDMcCollisions %d", outputMcCollsLabels.lastIndex(), dgcands.size() - 1, outputMcCollisions.lastIndex());
812+
LOGF(info, " UDMcCollsLabels %d (of %d) UDMcCollisions %d", outputMcCollsLabels.lastIndex(), dgcands.size() - 1, outputMcCollisions.lastIndex());
829813
goon = !dgcandAtEnd || !mccolAtEnd;
830814
}
831815
}
816+
817+
// updating McTruth data only
818+
void procWithoutDgCand(aod::McCollisions const& mccols, aod::McParticles const& mcparts)
819+
{
820+
// use a hash table to keep track of the McCollisions which have been added to the UDMcCollision table
821+
// {McCollisionId : udMcCollisionId}
822+
// similar for the McParticles which have been added to the UDMcParticle table
823+
// {McParticleId : udMcParticleId}
824+
std::map<int64_t, int64_t> mcColIsSaved;
825+
std::map<int64_t, int64_t> mcPartIsSaved;
826+
827+
// loop over McCollisions
828+
for (auto const& mccol : mccols) {
829+
int64_t mccolId = mccol.globalIndex();
830+
831+
// update UDMcCollisions and UDMcParticles
832+
if (mcColIsSaved.find(mccolId) == mcColIsSaved.end()) {
833+
834+
// update UDMcCollisions
835+
LOGF(debug, " writing mcCollision %d to UDMcCollisions", mccolId);
836+
updateUDMcCollisions(mccol);
837+
mcColIsSaved[mccolId] = outputMcCollisions.lastIndex();
838+
839+
// update UDMcParticles
840+
auto mcPartsSlice = mcparts.sliceBy(mcPartsPerMcCollision, mccolId);
841+
updateUDMcParticles(mcPartsSlice, mcColIsSaved[mccolId], mcPartIsSaved);
842+
}
843+
}
844+
}
845+
846+
void init(InitContext& context)
847+
{
848+
// add histograms for the different process functions
849+
if (context.mOptions.get<bool>("processMCTruth")) {
850+
LOGF(info, "Preparing histograms for processMCTruth.");
851+
registry.add("mcTruth/collisions", "Number of associated collisions", {HistType::kTH1F, {{11, -0.5, 10.5}}});
852+
registry.add("mcTruth/collType", "Collision type", {HistType::kTH1F, {{5, -0.5, 4.5}}});
853+
registry.add("mcTruth/IVMpt", "Invariant mass versus p_{T}", {HistType::kTH2F, {{150, 0.0, 3.0}, {150, 0.0, 3.0}}});
854+
}
855+
}
856+
857+
// process function for MC data
858+
// save the MC truth of all events of interest and of the DG events
859+
void processMCTruth(aod::McCollisions const& mccols, aod::McParticles const& mcparts,
860+
UDCCs const& dgcands, UDTCs const& udtracks,
861+
CCs const& /*collisions*/, BCs const& /*bcs*/, TCs const& /*tracks*/)
862+
{
863+
LOGF(info, "Number of McCollisions %d", mccols.size());
864+
LOGF(info, "Number of DG candidates %d", dgcands.size());
865+
LOGF(info, "Number of UD tracks %d", udtracks.size());
866+
867+
if (mccols.size() > 0) {
868+
if (dgcands.size() > 0) {
869+
procWithDgCand(mccols, mcparts, dgcands, udtracks);
870+
} else {
871+
if (saveAllMcCollisions) {
872+
procWithoutDgCand(mccols, mcparts);
873+
}
874+
}
875+
}
876+
}
832877
PROCESS_SWITCH(McDGCandProducer, processMCTruth, "Produce MC tables", false);
833878

834879
void processDummy(aod::Collisions const& /*collisions*/)

PWGUD/TableProducer/SGCandProducer.cxx

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ struct McSGCandProducer {
365365
Produces<aod::UDMcCollsLabels> outputMcCollsLabels;
366366
Produces<aod::UDMcTrackLabels> outputMcTrackLabels;
367367

368+
// save all McTruth, even if the collisions is not reconstructed
369+
Configurable<bool> saveAllMcCollisions{"saveAllMcCollisions", true, "save all McCollisions"};
370+
368371
using CCs = soa::Join<aod::Collisions, aod::EvSels, aod::McCollisionLabels>;
369372
using BCs = soa::Join<aod::BCsWithTimestamps, aod::BcSels, aod::Run3MatchedToBCSparse>;
370373
using TCs = soa::Join<aod::Tracks, aod::McTrackLabels>;
@@ -539,33 +542,10 @@ struct McSGCandProducer {
539542
}
540543
}
541544

542-
void init(InitContext& context)
545+
// updating McTruth data and links to reconstructed data
546+
void procWithSgCand(aod::McCollisions const& mccols, aod::McParticles const& mcparts,
547+
UDCCs const& sgcands, UDTCs const& udtracks)
543548
{
544-
// add histograms for the different process functions
545-
if (context.mOptions.get<bool>("processMC")) {
546-
registry.add("mcTruth/collisions", "Number of associated collisions", {HistType::kTH1F, {{11, -0.5, 10.5}}});
547-
registry.add("mcTruth/collType", "Collision type", {HistType::kTH1F, {{5, -0.5, 4.5}}});
548-
registry.add("mcTruth/IVMpt", "Invariant mass versus p_{T}", {HistType::kTH2F, {{150, 0.0, 3.0}, {150, 0.0, 3.0}}});
549-
}
550-
}
551-
552-
// process function for MC data
553-
// save the MC truth of all events of interest and of the DG events
554-
void processMC(aod::McCollisions const& mccols, aod::McParticles const& mcparts,
555-
UDCCs const& sgcands, UDTCs const& udtracks,
556-
CCs const& /*collisions*/, BCs const& /*bcs*/, TCs const& /*tracks*/)
557-
{
558-
if (verboseInfoMC) {
559-
LOGF(info, "Number of McCollisions %d", mccols.size());
560-
LOGF(info, "Number of SG candidates %d", sgcands.size());
561-
LOGF(info, "Number of UD tracks %d", udtracks.size());
562-
}
563-
if (sgcands.size() <= 0) {
564-
if (verboseInfoMC)
565-
LOGF(info, "No DG candidates to save!");
566-
return;
567-
}
568-
569549
// use a hash table to keep track of the McCollisions which have been added to the UDMcCollision table
570550
// {McCollisionId : udMcCollisionId}
571551
// similar for the McParticles which have been added to the UDMcParticle table
@@ -575,21 +555,20 @@ struct McSGCandProducer {
575555

576556
// loop over McCollisions and UDCCs simultaneously
577557
auto mccol = mccols.iteratorAt(0);
578-
auto sgcand = sgcands.iteratorAt(0);
579558
auto lastmccol = mccols.iteratorAt(mccols.size() - 1);
559+
auto mccolAtEnd = false;
560+
561+
auto sgcand = sgcands.iteratorAt(0);
580562
auto lastsgcand = sgcands.iteratorAt(sgcands.size() - 1);
563+
auto sgcandAtEnd = false;
581564

582565
// advance dgcand and mccol until both are AtEnd
583566
int64_t mccolId = mccol.globalIndex();
584567
int64_t mcsgId = -1;
585-
// int64_t colId = -1;
586-
auto sgcandAtEnd = sgcand == lastsgcand;
587-
auto mccolAtEnd = mccol == lastmccol;
588-
bool goon = !sgcandAtEnd || !mccolAtEnd;
568+
569+
bool goon = true;
589570
while (goon) {
590-
auto bcIter = mccol.bc_as<BCs>();
591-
uint64_t globBC = bcIter.globalBC();
592-
// uint64_t globBC = 0;
571+
auto globBC = mccol.bc_as<BCs>().globalBC();
593572
// check if dgcand has an associated McCollision
594573
if (sgcand.has_collision()) {
595574
auto sgcandCol = sgcand.collision_as<CCs>();
@@ -600,7 +579,6 @@ struct McSGCandProducer {
600579
mcsgId = -1;
601580
}
602581
} else {
603-
// colId = -1;
604582
mcsgId = -1;
605583
}
606584
if (verboseInfoMC)
@@ -659,7 +637,7 @@ struct McSGCandProducer {
659637
auto mcPart = track.mcParticle();
660638
auto mcCol = mcPart.mcCollision();
661639
if (mcColIsSaved.find(mcCol.globalIndex()) == mcColIsSaved.end()) {
662-
updateUDMcCollisions(mcCol, mcCol.bc_as<BCs>().globalBC());
640+
updateUDMcCollisions(mcCol, globBC);
663641
mcColIsSaved[mcCol.globalIndex()] = outputMcCollisions.lastIndex();
664642
}
665643
updateUDMcParticle(mcPart, mcColIsSaved[mcCol.globalIndex()], mcPartIsSaved);
@@ -687,6 +665,7 @@ struct McSGCandProducer {
687665
if (mcColIsSaved.find(mccolId) == mcColIsSaved.end()) {
688666
if (verboseInfoMC)
689667
LOGF(info, " Saving McCollision %d", mccolId);
668+
690669
// update UDMcCollisions
691670
updateUDMcCollisions(mccol, globBC);
692671
mcColIsSaved[mccolId] = outputMcCollisions.lastIndex();
@@ -710,7 +689,71 @@ struct McSGCandProducer {
710689
LOGF(info, "End of loop mcsgId %d mccolId %d", mcsgId, mccolId);
711690
}
712691
}
692+
693+
// updating McTruth data only
694+
void procWithoutSgCand(aod::McCollisions const& mccols, aod::McParticles const& mcparts)
695+
{
696+
// use a hash table to keep track of the McCollisions which have been added to the UDMcCollision table
697+
// {McCollisionId : udMcCollisionId}
698+
// similar for the McParticles which have been added to the UDMcParticle table
699+
// {McParticleId : udMcParticleId}
700+
std::map<int64_t, int64_t> mcColIsSaved;
701+
std::map<int64_t, int64_t> mcPartIsSaved;
702+
703+
// loop over McCollisions
704+
for (auto const& mccol : mccols) {
705+
int64_t mccolId = mccol.globalIndex();
706+
uint64_t globBC = mccol.bc_as<BCs>().globalBC();
707+
708+
// update UDMcCollisions and UDMcParticles
709+
if (mcColIsSaved.find(mccolId) == mcColIsSaved.end()) {
710+
if (verboseInfoMC)
711+
LOGF(info, " Saving McCollision %d", mccolId);
712+
713+
// update UDMcCollisions
714+
updateUDMcCollisions(mccol, globBC);
715+
mcColIsSaved[mccolId] = outputMcCollisions.lastIndex();
716+
717+
// update UDMcParticles
718+
auto mcPartsSlice = mcparts.sliceBy(mcPartsPerMcCollision, mccolId);
719+
updateUDMcParticles(mcPartsSlice, mcColIsSaved[mccolId], mcPartIsSaved);
720+
}
721+
}
722+
}
723+
724+
void init(InitContext& context)
725+
{
726+
// add histograms for the different process functions
727+
if (context.mOptions.get<bool>("processMC")) {
728+
registry.add("mcTruth/collisions", "Number of associated collisions", {HistType::kTH1F, {{11, -0.5, 10.5}}});
729+
registry.add("mcTruth/collType", "Collision type", {HistType::kTH1F, {{5, -0.5, 4.5}}});
730+
registry.add("mcTruth/IVMpt", "Invariant mass versus p_{T}", {HistType::kTH2F, {{150, 0.0, 3.0}, {150, 0.0, 3.0}}});
731+
}
732+
}
733+
734+
// process function for MC data
735+
// save the MC truth of all events of interest and of the DG events
736+
void processMC(aod::McCollisions const& mccols, aod::McParticles const& mcparts,
737+
UDCCs const& sgcands, UDTCs const& udtracks,
738+
CCs const& /*collisions*/, BCs const& /*bcs*/, TCs const& /*tracks*/)
739+
{
740+
if (verboseInfoMC) {
741+
LOGF(info, "Number of McCollisions %d", mccols.size());
742+
LOGF(info, "Number of SG candidates %d", sgcands.size());
743+
LOGF(info, "Number of UD tracks %d", udtracks.size());
744+
}
745+
if (mccols.size() > 0) {
746+
if (sgcands.size() > 0) {
747+
procWithSgCand(mccols, mcparts, sgcands, udtracks);
748+
} else {
749+
if (saveAllMcCollisions) {
750+
procWithoutSgCand(mccols, mcparts);
751+
}
752+
}
753+
}
754+
}
713755
PROCESS_SWITCH(McSGCandProducer, processMC, "Produce MC tables", false);
756+
714757
void processDummy(aod::Collisions const& /*collisions*/)
715758
{
716759
// do nothing

0 commit comments

Comments
 (0)