Learn how access and work with MC data

Source: mcHistograms.cxx
Executable: o2-analysistutorial-mc-histograms

Working with MC data

The MC truth and MC reconstructed information can be accessed separately but are related by dedicated index columns.


The data model includes a set of MC related tables (see also datamodel) which contain the MC truth information. In task VertexDistribution the process function loops over the rows of the MC truth McCollisions table.

struct VertexDistribution {
  OutputObj<TH1F> vertex{TH1F("vertex", "vertex", 100, -10, 10)};

  // loop over MC truth McCollisions
  void process(aod::McCollision const& mcCollision)
    LOGF(info, "MC. vtx-z = %f", mcCollision.posZ());


The task AccessMCTruth demonstrates how to access MC truth information for a given reconstructed item. In this example the MC truth McParticle for a given reconstructed Track is searched for.

In order to relate the MC reconstructed information with the MC truth information specific index columns are used. In order to make these index columns available they are joined with the related tables. Hence

soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks

is needed to relate the reconstructed Tracks information with the corresponding MC truth McParticles information and

soa::Join<aod::Collisions, aod::McCollisionLabels>

is needed to relate table Collisions with MC truth table McCollisions. With these joins in place the access of MC truth information is made easy. The MC truth corresponding to Collision collision is obtained with collision.mcCollision() and the MC truth McParticle corresponding to Track track is available with track.mcParticle().

// access MC truth information with mcCollision() and mcParticle() methods
LOGF(info, "vtx-z (data) = %f | vtx-z (MC) = %f", collision.posZ(), collision.mcCollision().posZ());
for (auto& track : tracks) {
  etaDiff->Fill(track.mcParticle().eta() - track.eta());
  auto delta = track.mcParticle().phi() - track.phi();