Iguana
1.0.0
Implementation Guardian of Analysis Algorithms
Toggle main menu visibility
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
26
int
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) {
return
algo_eventbuilder_filter.
Filter
(pids); },
61
{
"REC_Particle_pid"
})
62
.Define(
// apply the filtering column to `REC_Particle_pid`
63
"REC_Particle_pid_good"
,
64
[](std::vector<int>
const
& pids, std::deque<bool>& filter) {
65
std::vector<int> result;
66
for
(std::deque<bool>::size_type i = 0; i < filter.size(); i++) {
67
if
(filter.at(i))
68
result.push_back(pids.at(i));
69
}
70
return
result;
71
},
72
{
"REC_Particle_pid"
,
"REC_Particle_EventBuilderFilter"
});
73
74
// draw
75
auto
hist = frame_filtered.Histo1D({
"pid_filter"
,
"PDG"
, 6000, -3000, 3000},
"REC_Particle_pid_good"
);
76
77
// write or hold open
78
auto
canv =
new
TCanvas(
"canv"
,
"canv"
, 1600, 1200);
79
canv->SetGrid(1, 1);
80
hist->Draw();
81
if
(interactive_mode) {
82
fmt::print(
"\n\nShowing plots interactively;\npress ^C to exit.\n\n"
);
83
app->Run();
84
}
85
else
{
86
canv->SaveAs(
"out-iguana-dataframe-example.png"
);
87
}
88
89
return
0;
90
}
iguana::Algorithm::SetOption
OPTION_TYPE SetOption(std::string const &key, const OPTION_TYPE val)
Definition
Algorithm.h:84
iguana::clas12::EventBuilderFilter
Algorithm: Filter the REC::Particle (or similar) bank by PID from the Event Builder
Definition
Algorithm.h:14
iguana::clas12::EventBuilderFilter::Start
void Start(hipo::banklist &banks) override
Initialize this algorithm before any events are processed, with the intent to process banks.
iguana::clas12::EventBuilderFilter::Filter
bool Filter(int const pid) const
Action Function: checks if the PDG pid is a part of the list of user-specified PDGs
main
int main(int argc, char **argv)
main function
Definition
iguana_ex_cpp_00_run_functions.cc:25
iguana_v1.0.0
examples
iguana_ex_cpp_dataframes.cc
Generated by
1.18.0