Loading [MathJax]/jax/output/HTML-CSS/config.js
Iguana 0.9.0
Implementation Guardian of Analysis Algorithms
iguana_ex_cpp_dataframes.cc
Go to the documentation of this file.
1
18
19#include <hipo4/RHipoDS.hxx>
20#include <iguana/algorithms/clas12/EventBuilderFilter/Algorithm.h>
21
22#include <TApplication.h>
23#include <TCanvas.h>
24
26int main(int argc, char** argv)
27{
28
29 // parse arguments
30 char const* in_file = argc > 1 ? argv[1] : "data.hipo";
31 int const num_events = argc > 2 ? std::stoi(argv[2]) : 100;
32 bool const interactive_mode = argc > 3 ? std::string(argv[3]) == "true" : false;
33
34 // iguana algorithms
35 iguana::clas12::EventBuilderFilter algo_eventbuilder_filter;
36 algo_eventbuilder_filter.SetOption<std::vector<int>>("pids", {11, 211, -211});
37 algo_eventbuilder_filter.Start();
38
39 // enable interactive mode
40 auto app = interactive_mode ? new TApplication("app", &argc, argv) : nullptr;
41
42 // enable multi-threading
43 // ROOT::EnableImplicitMT();
44
45 // open the HIPO file
46 auto frame_init = MakeHipoDataFrame(in_file).Range(0, num_events);
47
48 // print the column names
49 fmt::print("DATAFRAME COLUMNS:\n");
50 for(auto const& column_name : frame_init.GetColumnNames())
51 fmt::print(" - {}\n", column_name);
52
53 // run algorithms
54 // FIXME: we want to be able to apply an Iguana Filter as an RDataFrame Filter to a set of columns;
55 // this example chain filters only `REC::Particle::pid`, whereas ideally we want all of `REC::Particle`'s columns
56 // to be filtered
57 auto frame_filtered = frame_init
58 .Define( // define a filter column, type std::deque<bool> (to avoid std::vector<bool>)
59 "REC_Particle_EventBuilderFilter",
60 [&](std::vector<int> const& pids)
61 { return algo_eventbuilder_filter.Filter(pids); },
62 {"REC_Particle_pid"})
63 .Define( // apply the filtering column to `REC_Particle_pid`
64 "REC_Particle_pid_good",
65 [](std::vector<int> const& pids, std::deque<bool>& filter)
66 {
67 std::vector<int> result;
68 for(std::deque<bool>::size_type i = 0; i < filter.size(); i++) {
69 if(filter.at(i))
70 result.push_back(pids.at(i));
71 }
72 return result;
73 },
74 {"REC_Particle_pid", "REC_Particle_EventBuilderFilter"});
75
76 // draw
77 auto hist = frame_filtered.Histo1D({"pid_filter", "PDG", 6000, -3000, 3000}, "REC_Particle_pid_good");
78
79 // write or hold open
80 auto canv = new TCanvas("canv", "canv", 1600, 1200);
81 canv->SetGrid(1, 1);
82 hist->Draw();
83 if(interactive_mode) {
84 fmt::print("\n\nShowing plots interactively;\npress ^C to exit.\n\n");
85 app->Run();
86 }
87 else {
88 canv->SaveAs("out-iguana-dataframe-example.png");
89 }
90
91 return 0;
92}
OPTION_TYPE SetOption(std::string const &key, const OPTION_TYPE val)
Definition Algorithm.h:80
Algorithm: Filter the REC::Particle (or similar) bank by PID from the Event Builder
Definition Algorithm.h:18
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks
bool Filter(int const pid) const
Action Function: checks if the PDG pid is a part of the list of user-specified PDGs
int main(int argc, char **argv)
main function