Skip to content

Commit fe15e1e

Browse files
authored
Adding MC example (#3744)
1 parent ee8c472 commit fe15e1e

3 files changed

Lines changed: 79 additions & 4 deletions

File tree

Analysis/Tutorials/CMakeLists.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ o2_add_dpl_workflow(jet-analysis
8282
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel
8383
COMPONENT_NAME AnalysisTutorial)
8484

85-
o2_add_executable(tracks-combinations
85+
o2_add_dpl_workflow(tracks-combinations
8686
SOURCES src/tracksCombinations.cxx
8787
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel
8888
COMPONENT_NAME AnalysisTutorial)
8989

90-
o2_add_executable(event-mixing
90+
o2_add_dpl_workflow(event-mixing
9191
SOURCES src/eventMixing.cxx
9292
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel
9393
COMPONENT_NAME AnalysisTutorial)
94+
95+
o2_add_dpl_workflow(mc-histograms
96+
SOURCES src/mcHistograms.cxx
97+
PUBLIC_LINK_LIBRARIES O2::Framework O2::AnalysisDataModel
98+
COMPONENT_NAME AnalysisTutorial)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
#include "Framework/runDataProcessing.h"
11+
#include "Framework/AnalysisTask.h"
12+
#include "Framework/AnalysisDataModel.h"
13+
#include <TH1F.h>
14+
15+
#include <cmath>
16+
17+
using namespace o2;
18+
using namespace o2::framework;
19+
20+
// Simple access to collision
21+
struct ATask {
22+
OutputObj<TH1F> vertex{TH1F("vertex", "vertex", 100, -10, 10)};
23+
24+
void process(aod::McCollision const& mcCollision)
25+
{
26+
LOGF(info, "MC. vtx-z = %f", mcCollision.z());
27+
vertex->Fill(mcCollision.z());
28+
}
29+
};
30+
31+
// Grouping between MC particles and collisions
32+
struct BTask {
33+
OutputObj<TH1F> phiH{TH1F("phi", "phi", 100, 0., 2. * M_PI)};
34+
OutputObj<TH1F> etaH{TH1F("eta", "eta", 102, -2.01, 2.01)};
35+
36+
void process(aod::McCollision const& mcCollision, aod::McParticles const& mcParticles)
37+
{
38+
for (auto& mcParticle : mcParticles) {
39+
phiH->Fill(mcParticle.phi());
40+
etaH->Fill(mcParticle.eta());
41+
}
42+
}
43+
};
44+
45+
// Access from tracks to MC particle
46+
struct CTask {
47+
OutputObj<TH1F> etaDiff{TH1F("etaDiff", ";eta_{MC} - eta_{Rec}", 100, -0.1, 0.1)};
48+
49+
void process(aod::Collision const& collision, soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks, aod::McParticles const& mcParticles)
50+
{
51+
for (auto& track : tracks) {
52+
etaDiff->Fill(track.label().eta() - track.eta());
53+
}
54+
}
55+
};
56+
57+
WorkflowSpec defineDataProcessing(ConfigContext const&)
58+
{
59+
return WorkflowSpec{
60+
adaptAnalysisTask<ATask>("vertex-histogram"),
61+
adaptAnalysisTask<BTask>("etaphi-histogram"),
62+
adaptAnalysisTask<CTask>("eta-resolution-histogram"),
63+
};
64+
}

Framework/Core/include/Framework/AnalysisDataModel.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ DECLARE_SOA_COLUMN(Snp, snp, float);
7777
DECLARE_SOA_COLUMN(Tgl, tgl, float);
7878
DECLARE_SOA_COLUMN(Signed1Pt, signed1Pt, float);
7979
DECLARE_SOA_DYNAMIC_COLUMN(Phi, phi, [](float snp, float alpha) -> float { return asinf(snp) + alpha + static_cast<float>(M_PI); });
80-
DECLARE_SOA_DYNAMIC_COLUMN(Eta, eta, [](float tgl) -> float { return logf(tanf(0.25f * static_cast<float>(M_PI) - 0.5f * atanf(tgl))); });
80+
DECLARE_SOA_DYNAMIC_COLUMN(Eta, eta, [](float tgl) -> float { return std::log(std::tan(0.25f * static_cast<float>(M_PI) - 0.5f * std::atan(tgl))); });
8181
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, [](float signed1Pt) -> float { return std::abs(1.0f / signed1Pt); });
8282
DECLARE_SOA_DYNAMIC_COLUMN(Charge, charge, [](float signed1Pt) -> short { return (signed1Pt > 0) ? 1 : -1; });
8383
DECLARE_SOA_DYNAMIC_COLUMN(Px, px, [](float signed1Pt, float snp, float alpha) -> float {
@@ -434,14 +434,20 @@ DECLARE_SOA_COLUMN(Vx, vx, float);
434434
DECLARE_SOA_COLUMN(Vy, vy, float);
435435
DECLARE_SOA_COLUMN(Vz, vz, float);
436436
DECLARE_SOA_COLUMN(Vt, vt, float);
437+
DECLARE_SOA_DYNAMIC_COLUMN(Phi, phi, [](float px, float py) -> float { return static_cast<float>(M_PI) + std::atan2(-py, -px); });
438+
DECLARE_SOA_DYNAMIC_COLUMN(Eta, eta, [](float px, float py, float pz) -> float { return 0.5f * std::log((std::sqrt(px * px + py * py + pz * pz) + pz) / (std::sqrt(px * px + py * py + pz * pz) - pz)); });
439+
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, [](float px, float py) -> float { return std::sqrt(px * px + py * py); });
437440
} // namespace mcparticle
438441

439442
DECLARE_SOA_TABLE(McParticles, "AOD", "MCPARTICLE",
440443
o2::soa::Index<>, mcparticle::McCollisionId,
441444
mcparticle::PdgCode, mcparticle::StatusCode,
442445
mcparticle::Mother, mcparticle::Daughter, mcparticle::Weight,
443446
mcparticle::Px, mcparticle::Py, mcparticle::Pz, mcparticle::E,
444-
mcparticle::Vx, mcparticle::Vy, mcparticle::Vz, mcparticle::Vt);
447+
mcparticle::Vx, mcparticle::Vy, mcparticle::Vz, mcparticle::Vt,
448+
mcparticle::Phi<mcparticle::Px, mcparticle::Py>,
449+
mcparticle::Eta<mcparticle::Px, mcparticle::Py, mcparticle::Pz>,
450+
mcparticle::Pt<mcparticle::Px, mcparticle::Py>);
445451
using McParticle = McParticles::iterator;
446452

447453
namespace mctracklabel

0 commit comments

Comments
 (0)