|
| 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/AnalysisTask.h" |
| 11 | +#include "Framework/AnalysisDataModel.h" |
| 12 | +#include "AnalysisCore/MC.h" |
| 13 | + |
| 14 | +#include <TH1F.h> |
| 15 | +#include <cmath> |
| 16 | + |
| 17 | +using namespace o2; |
| 18 | +using namespace o2::framework; |
| 19 | +using namespace o2::framework::expressions; |
| 20 | + |
| 21 | +void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions) |
| 22 | +{ |
| 23 | + ConfigParamSpec optionDoMC{"doMC", VariantType::Bool, false, {"Use MC info"}}; |
| 24 | + workflowOptions.push_back(optionDoMC); |
| 25 | +} |
| 26 | + |
| 27 | +#include "Framework/runDataProcessing.h" |
| 28 | + |
| 29 | +namespace |
| 30 | +{ |
| 31 | +inline auto normalize(float a) |
| 32 | +{ |
| 33 | + if (a > M_PI) { |
| 34 | + a -= 2 * M_PI; |
| 35 | + } |
| 36 | + if (a < -M_PI) { |
| 37 | + a += 2 * M_PI; |
| 38 | + } |
| 39 | + return a; |
| 40 | +} |
| 41 | +} // namespace |
| 42 | + |
| 43 | +// Analysis task with several process functions with different signatures |
| 44 | +struct MultipleProcessExample { |
| 45 | + HistogramRegistry registry{ |
| 46 | + "registry", |
| 47 | + { |
| 48 | + {"etaDiff", ";#eta_{MC} - #eta_{Rec}", {HistType::kTH1F, {{100, -2, 2}}}}, |
| 49 | + {"phiDiff", ";#phi_{MC} - #phi_{Rec}", {HistType::kTH1F, {{100, -M_PI, M_PI}}}}, |
| 50 | + {"etaRec", ";#eta_{Rec}", {HistType::kTH1F, {{100, -2, 2}}}}, |
| 51 | + {"phiRec", ";#phi_{Rec}", {HistType::kTH1F, {{100, 0, 2 * M_PI}}}}, |
| 52 | + {"etaMC", ";#eta_{MC}", {HistType::kTH1F, {{100, -2, 2}}}}, |
| 53 | + {"phiMC", ";#phi_{MC}", {HistType::kTH1F, {{100, 0, 2 * M_PI}}}} /// |
| 54 | + } /// |
| 55 | + }; |
| 56 | + |
| 57 | + Filter RecColVtxZ = nabs(aod::collision::posZ) < 10.f; |
| 58 | + Filter GenColVtxZ = nabs(aod::mccollision::posZ) < 10.f; |
| 59 | + |
| 60 | + void processRec(soa::Filtered<aod::Collisions>::iterator const& collision, aod::Tracks const& tracks) |
| 61 | + { |
| 62 | + for (auto& track : tracks) { |
| 63 | + registry.fill(HIST("etaRec"), track.eta()); |
| 64 | + registry.fill(HIST("phiRec"), track.phi()); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + void processGen(soa::Filtered<aod::McCollisions>::iterator const& mcCollision, aod::McParticles const& mcParticles) |
| 69 | + { |
| 70 | + for (auto& particle : mcParticles) { |
| 71 | + registry.fill(HIST("etaMC"), particle.eta()); |
| 72 | + registry.fill(HIST("phiMC"), particle.phi()); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + void processResolution(soa::Filtered<soa::Join<aod::Collisions, aod::McCollisionLabels>>::iterator const& collision, soa::Join<aod::Tracks, aod::McTrackLabels> const& tracks, aod::McParticles const& mcParticles, aod::McCollisions const& mcCollisions) |
| 77 | + { |
| 78 | + LOGF(info, "vtx-z (data) = %f | vtx-z (MC) = %f", collision.posZ(), collision.mcCollision().posZ()); |
| 79 | + for (auto& track : tracks) { |
| 80 | + registry.fill(HIST("etaDiff"), track.mcParticle().eta() - track.eta()); |
| 81 | + registry.fill(HIST("phiDiff"), normalize(track.mcParticle().phi() - track.phi())); |
| 82 | + } |
| 83 | + } |
| 84 | +}; |
| 85 | + |
| 86 | +WorkflowSpec defineDataProcessing(ConfigContext const& cfgc) |
| 87 | +{ |
| 88 | + if (!cfgc.options().get<bool>("doMC")) { |
| 89 | + return WorkflowSpec{ |
| 90 | + // only use rec-level process when MC info is not there |
| 91 | + adaptAnalysisTask<MultipleProcessExample>(cfgc, Processes{&MultipleProcessExample::processRec})}; |
| 92 | + } |
| 93 | + return WorkflowSpec{ |
| 94 | + // use additional process functions when MC info is present |
| 95 | + // functions will be executed in the sequence they are listed - allows to use, for example, |
| 96 | + // histograms that were filled previously |
| 97 | + // produced tables *cannot* be used |
| 98 | + // filters will be applied *to all* processes |
| 99 | + adaptAnalysisTask<MultipleProcessExample>(cfgc, Processes{&MultipleProcessExample::processRec, |
| 100 | + &MultipleProcessExample::processGen, |
| 101 | + &MultipleProcessExample::processResolution})}; |
| 102 | +} |
0 commit comments