Project
Loading...
Searching...
No Matches
o2SimpleTracksAnalysis.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
16
17#include <ROOT/RDataFrame.hxx>
18
19#include <cmath>
20
21using namespace ROOT::RDF;
22using namespace o2;
23using namespace o2::framework;
24
25namespace o2::aod
26{
27namespace tracks
28{
29DECLARE_SOA_COLUMN(Eta, eta, float);
30DECLARE_SOA_COLUMN(Phi, phi, float);
31} // namespace tracks
32
34} // namespace o2::aod
35
36// A dummy workflow which creates a few of the tables proposed by Ruben,
37// using ARROW
39{
40 // Workflow definition. A workflow can be one or more DataProcessors
41 // each implementing (part of) an analysis. Each DataProcessor has
42 // (at least) a name, some Inputs, some Outputs and they get arranged
43 // together accordingly.
44 WorkflowSpec workflow{
45 // Multiple DataProcessor specs
46 // can be provided per workflow
48 // The name of my analysis
49 "tracks-analysis",
50 Inputs{
51 // Dangling inputs of type AOD will be automatically picked up by DPL
52 // and an extra reader device will be instanciated to read them from
53 // file. In this particular case the signature AOD/TRACKPAR is
54 // associated to the basic trajectory parameters for a track described
55 // in Ruben's table. The first string is just a label so that the
56 // algorithm can be in principle be reused for different kind of
57 // tracks.
58 InputSpec{"Tracks", "DYN", "TRACKPAR"},
59 InputSpec{"TracksExtension", "AOD", "TRACKPAR"}},
60 // No outputs for the time being.
61 Outputs{
62 OutputSpec{{"derived"}, "AOD", "TRACKDERIVED"}},
64 // This is the actual per "message" loop, where a message could
65 // be the contents of a file or part of it.
66 // FIXME: Too much boilerplate.
67 adaptStateless([](InputRecord& inputs, DataAllocator& outputs) {
69 auto input1 = inputs.get<TableConsumer>("Tracks");
70 auto input2 = inputs.get<TableConsumer>("TracksExtension");
72 auto etaPhiBuilder = outputs.make<TableBuilder>(Output{"AOD", "TRACKDERIVED"});
73 auto etaPhiWriter = etaPhiBuilder->cursor<o2::aod::TracksDerived>();
74
75 auto tracks = aod::Tracks({input1->asArrowTable(), input2->asArrowTable()});
76
77 for (auto& track : tracks) {
78 auto phi = asin(track.snp()) + track.alpha() + M_PI;
79 auto eta = log(tan(0.25 * M_PI - 0.5 * atan(track.tgl())));
80 etaPhiWriter(0, eta, phi);
81 }
82 })}},
84 "phi-consumer",
85 Inputs{
86 InputSpec{"etaphi", "AOD", "TRACKDERIVED"}},
87 Outputs{},
89 adaptStateless([](InputRecord& inputs) {
90 auto input = inputs.get<TableConsumer>("etaphi");
91 auto tracks = o2::analysis::doSingleLoopOn(input);
92
93 auto h = tracks.Histo1D("fPhi");
94
95 TFile f("result1.root", "RECREATE");
96 h->SetName("Phi");
97 h->Write();
98 })}},
100 "eta-consumer",
101 Inputs{
102 InputSpec{"etaphi", "AOD", "TRACKDERIVED"}},
103 Outputs{},
105 adaptStateless([](InputRecord& inputs) {
106 auto input = inputs.get<TableConsumer>("etaphi");
107 auto tracks = o2::analysis::doSingleLoopOn(input);
108
109 auto h2 = tracks.Histo1D("fEta");
110
111 TFile f("result2.root", "RECREATE");
112 h2->SetName("Eta");
113 h2->Write();
114 })}}};
115 return workflow;
116}
#define DECLARE_SOA_COLUMN(_Name_, _Getter_, _Type_)
Definition ASoA.h:2314
Class for time synchronization of RawReader instances.
decltype(auto) make(const Output &spec, Args... args)
The input API of the Data Processing Layer This class holds the inputs which are valid for processing...
decltype(auto) get(R binding, int part=0) const
std::shared_ptr< arrow::Table > asArrowTable()
Return the table in the message as a arrow::Table instance.
GLdouble f
Definition glcorearb.h:310
ROOT::RDataFrame doSingleLoopOn(std::unique_ptr< framework::TableConsumer > &input)
Do a single loop on all the entries of the input table.
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< DataProcessorSpec > WorkflowSpec
AlgorithmSpec::ProcessCallback adaptStateless(LAMBDA l)
std::vector< InputSpec > Inputs
std::vector< OutputSpec > Outputs
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
WorkflowSpec defineDataProcessing(ConfigContext const &specs)
This function hooks up the the workflow specifications into the DPL driver.