Hello,
First, TDF is awesome! It is a real game changer. Kudos to everyone involved.
My question is this: how can I fill a histogram multiple times per event using a vector of hits?
Perhaps I have overlooked this in the documentation but I would like to do the following:
TDataframe d(t, {"my_hits"}); // where my_hits is a std::vector<Hit>
double x0 = 5.0;
// I want to use this lambda to fill
auto fill_all_hits = [=](const std::vector<Hit>& hits){
for(const auto& ahit : hits){
double diff = ahit.x() - x0;
//Fill histogram here or add to return type which then fills histogram
}
};
auto h1 = d.Histo1D(TH1D("h0", "dx; ", 20, 0,20),"???");
Ideally there would be an extra argument before the the branch list argument.
I can see maybe two ways of doing this:
- Passing the “hist” object to the lambda
auto fill_all_hits = [=](const std::vector<Hit>& hits, auto& hist){
for(const auto& ahit : hits){
double diff = ahit.x() - x0;
hist.Fill({diff});
}
};
auto h1 = d.Histo1D(TH1D("h0", "dx; ", 20, 0,20),fill_all_hits,{"my_hits"});
I would imagine there are some multithreading issues here.
- Return a vector values to fill:
auto fill_all_hits = [=](const std::vector<Hit>& hits){
std::vector<Hist::CoordArray_t<1>> result;
for(const auto& ahit : hits){
double diff = ahit.x() - x0;
result.push_back({diff});
}
return result;
};
auto h1 = d.Histo1D(TH1D("h0", "dx; ", 20, 0,20),fill_all_hits,{"my_hits"});
Problem with both: all filled with default weights but this is already the case. (Maybe return a tuple for non-default weights?)
Cheers,