Skip to content

Commit 0c24a22

Browse files
authored
DPL Analysis: Update mc histograms example to use generic grouping (#235)
1 parent 2421bca commit 0c24a22

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

Tutorials/src/mcHistograms.cxx

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ struct AccessMcTruth {
9090

9191
// Loop over MCColisions and get corresponding collisions (there can be more than one)
9292
// For each of them get the corresponding tracks
93-
// NOTE This does not work with the Run 3 data model at present. You will receive an exception about an unsorted index. Please use the next tutorial example.
93+
// Note the use of "SmallGroups" template, that allows to handle both Run 2, where
94+
// we have exactly 1-to-1 correspondence between collisions and mc collisions, and
95+
// Run 3, where we can have 0, 1, or more collisions for a given mc collision
9496
struct LoopOverMcMatched {
9597
OutputObj<TH1F> etaDiff{TH1F("etaDiff", ";eta_{MC} - eta_{Rec}", 100, -2, 2)};
96-
void process(aod::McCollision const& mcCollision, soa::Join<aod::McCollisionLabels, aod::Collisions> const& collisions,
98+
void process(aod::McCollision const& mcCollision, soa::SmallGroups<soa::Join<aod::McCollisionLabels, aod::Collisions>> const& collisions,
9799
soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks, aod::McParticles const& mcParticles)
98100
{
99101
// access MC truth information with mcCollision() and mcParticle() methods
@@ -111,41 +113,11 @@ struct LoopOverMcMatched {
111113
}
112114
};
113115

114-
// WORKAROUND of previous example for Run 3 data model (see remarks above)
115-
struct LoopOverMcMatchedRun3 {
116-
OutputObj<TH1F> etaDiff{TH1F("etaDiff", ";eta_{MC} - eta_{Rec}", 100, -2, 2)};
117-
void process(aod::McCollisions const& mcCollisions, soa::Join<aod::McCollisionLabels, aod::Collisions> const& allCollisions,
118-
soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks, aod::McParticles const& allMcParticles)
119-
{
120-
for (auto& mcCollision : mcCollisions) {
121-
122-
// Do grouping by hand
123-
auto collisions = allCollisions.select(aod::mccollisionlabel::mcCollisionId == mcCollision.globalIndex());
124-
auto mcParticles = allMcParticles.sliceBy(aod::mcparticle::mcCollisionId, mcCollision.globalIndex());
125-
126-
// access MC truth information with mcCollision() and mcParticle() methods
127-
LOGF(info, "MC collision at vtx-z = %f with %d mc particles and %d reconstructed collisions", mcCollision.posZ(), mcParticles.size(), collisions.size());
128-
for (auto& collision : collisions) {
129-
LOGF(info, " Reconstructed collision at vtx-z = %f", collision.posZ());
130-
131-
// NOTE this will be replaced by a improved grouping in the future
132-
auto groupedTracks = tracks.sliceBy(aod::track::collisionId, collision.globalIndex());
133-
LOGF(info, " which has %d tracks", groupedTracks.size());
134-
for (auto& track : groupedTracks) {
135-
etaDiff->Fill(track.mcParticle().eta() - track.eta());
136-
}
137-
}
138-
}
139-
}
140-
};
141-
142116
WorkflowSpec defineDataProcessing(ConfigContext const& cfgc)
143117
{
144118
return WorkflowSpec{
145119
adaptAnalysisTask<VertexDistribution>(cfgc),
146120
adaptAnalysisTask<AccessMcData>(cfgc),
147121
adaptAnalysisTask<AccessMcTruth>(cfgc),
148-
// adaptAnalysisTask<LoopOverMcMatched>(cfgc),
149-
adaptAnalysisTask<LoopOverMcMatchedRun3>(cfgc),
150-
};
122+
adaptAnalysisTask<LoopOverMcMatched>(cfgc)};
151123
}

0 commit comments

Comments
 (0)