Project
Loading...
Searching...
No Matches
o2D0Analysis.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.
14
15#include <ROOT/RDataFrame.hxx>
16
17using namespace ROOT::RDF;
18using namespace o2::framework;
19
20// A dummy workflow which creates a few of the tables proposed by Ruben,
21// using ARROW
23{
24 // Workflow definition. A workflow can be one or more DataProcessors
25 // each implementing (part of) an analysis. Each DataProcessor has
26 // (at least) a name, some Inputs, some Outputs and they get arranged
27 // together accordingly.
28 WorkflowSpec workflow{
29 // Multiple DataProcessor specs
30 // can be provided per workflow
32 // The name of my analysis
33 "d0-analysis",
34 Inputs{
35 // Dangling inputs of type AOD will be automatically picked up
36 // by DPL and an extra reader device will be instanciated to
37 // read them. In this particular case the signature
38 // AOD/DZEROFLAGGED is associated to Gianmichele's
39 // D0 candidates schema. The first string is just a label
40 // so that the algorithm can be in principle be reused for different
41 // kind of candidates.
42 InputSpec{"candidates", "AOD", "DZEROFLAGGED"},
43 },
44 // No outputs for the time being.
45 Outputs{},
47 // This is the actual per "message" loop, where a message could
48 // be the contents of a file or part of it.
49 // FIXME: Too much boilerplate.
50 adaptStateless([](InputRecord& inputs) {
51 auto input = inputs.get<TableConsumer>("candidates");
52
53 // This does a single loop on all the candidates in the input message
54 // using a simple mask on the cand_type_ML column and does
55 // a simple 1D histogram of the filtered entries.
56 auto candidates = o2::analysis::doSingleLoopOn(input);
57
58 auto h1 = candidates.Filter("(bool)(cand_type_ML & 0x1)").Histo1D("inv_mass_ML");
59
60 // A lambda function subtracting two quantities. This defines
61 // a function "delta" which can be invoked with
62 //
63 // delta(1,2)
64 //
65 // and will return 1 - 2.
66 auto delta = [](float x, float y) { return x - y; };
67
68 // This does all the combinations for all the candidates which have
69 // the same value for cand_evtID_ML (the Event ID).
70 // d0_ is the prefix assigned to the outer variable of the double loop.
71 // d0bar_ is the prefix assigned to the inner variable of the double loop.
72 //
73 // The lines below will:
74 // * Filter the combinations according to some mask
75 // * Define a column delta_phi with the difference in phi between d0 and d0bar phi
76 // * Define a column delta_eta with the difference in phi between d0 and d0bar eta
77 // * Do two histograms with delta_phi, delta_eta
78 auto combinations = o2::analysis::doSelfCombinationsWith(input, "d0", "cand_evtID_ML");
79 auto deltas = combinations.Filter("d0_cand_type_ML & 0x1 && d0bar_cand_type_ML & 0x1")
80 .Define("delta_phi", delta, {"d0_phi_cand_ML", "d0bar_phi_cand_ML"})
81 .Define("delta_eta", delta, {"d0_eta_cand_ML", "d0bar_eta_cand_ML"});
82 auto h2 = deltas.Histo1D("delta_phi");
83 auto h3 = deltas.Histo1D("delta_eta");
84
85 // FIXME: For the moment we hardcode saving the histograms.
86 // In reality it should send the results as outputs to a downstream merger
87 // process which merges them as wished.
88 TFile f("result.root", "RECREATE");
89 h1->SetName("InvariantMass");
90 h1->Write();
91 h2->SetName("DeltaPhi");
92 h2->Write();
93 h3->SetName("DeltaEta");
94 h3->Write();
95 })}}};
96 return workflow;
97}
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
GLint GLenum GLint x
Definition glcorearb.h:403
GLdouble f
Definition glcorearb.h:310
GLint y
Definition glcorearb.h:270
ROOT::RDataFrame doSelfCombinationsWith(std::unique_ptr< framework::TableConsumer > &input, std::string name="p", std::string grouping="eventID")
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
WorkflowSpec defineDataProcessing(ConfigContext const &specs)
This function hooks up the the workflow specifications into the DPL driver.