Iguana 0.0.0
Implementation Guardian of Analysis Algorithms
Loading...
Searching...
No Matches
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 int argi = 1;
31 char const* in_file = argc > argi ? argv[argi++] : "data.hipo";
32 int const num_events = argc > argi ? std::stoi(argv[argi++]) : 100;
33 bool const interactive_mode = argc > argi ? std::string(argv[argi++]) == "true" : false;
34
35 // iguana algorithms
36 iguana::clas12::EventBuilderFilter algo_eventbuilder_filter;
37 algo_eventbuilder_filter.SetOption<std::vector<int>>("pids", {11, 211, -211});
38 algo_eventbuilder_filter.Start();
39
40 // enable interactive mode
41 auto app = interactive_mode ? new TApplication("app", &argc, argv) : nullptr;
42
43 // enable multi-threading
44 // ROOT::EnableImplicitMT();
45
46 // open the HIPO file
47 auto frame_init = MakeHipoDataFrame(in_file).Range(0, num_events);
48
49 // print the column names
50 fmt::print("DATAFRAME COLUMNS:\n");
51 for(auto const& column_name : frame_init.GetColumnNames())
52 fmt::print(" - {}\n", column_name);
53
54 // run algorithms
55 // FIXME: we want to be able to apply an Iguana Filter as an RDataFrame Filter to a set of columns;
56 // this example chain filters only `REC::Particle::pid`, whereas ideally we want all of `REC::Particle`'s columns
57 // to be filtered
58 auto frame_filtered = frame_init
59 .Define( // define a filter column, type std::deque<bool> (to avoid std::vector<bool>)
60 "REC_Particle_EventBuilderFilter",
61 [&](std::vector<int> const& pids)
62 { return algo_eventbuilder_filter.Filter(pids); },
63 {"REC_Particle_pid"})
64 .Define( // apply the filtering column to `REC_Particle_pid`
65 "REC_Particle_pid_good",
66 [](std::vector<int> const& pids, std::deque<bool>& filter)
67 {
68 std::vector<int> result;
69 for(std::deque<bool>::size_type i = 0; i < filter.size(); i++) {
70 if(filter.at(i))
71 result.push_back(pids.at(i));
72 }
73 return result;
74 },
75 {"REC_Particle_pid", "REC_Particle_EventBuilderFilter"});
76
77 // draw
78 auto hist = frame_filtered.Histo1D({"pid_filter", "PDG", 6000, -3000, 3000}, "REC_Particle_pid_good");
79
80 // write or hold open
81 auto canv = new TCanvas("canv", "canv", 1600, 1200);
82 canv->SetGrid(1, 1);
83 hist->Draw();
84 if(interactive_mode) {
85 fmt::print("\n\nShowing plots interactively;\npress ^C to exit.\n\n");
86 app->Run();
87 }
88 else {
89 canv->SaveAs("out-iguana-dataframe-example.png");
90 }
91
92 return 0;
93}
OPTION_TYPE SetOption(std::string const &key, const OPTION_TYPE val)
Definition Algorithm.h:79
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