using FourVectors = std::vector<FourVector>;
void fill_tree(const char *filename, const char *treeName)
{
TFile f(filename,
"RECREATE");
TTree t(treeName, treeName);
FourVectors tracks;
t.Branch("tracks", &tracks);
const double M = 0.13957;
for (int i = 0; i < 50; ++i) {
tracks.clear();
tracks.reserve(nPart);
for (int j = 0; j < nPart; ++j) {
double px =
R.
Gaus(0, 10);
double py =
R.
Gaus(0, 10);
double pt =
sqrt(px * px + py * py);
CylFourVector vcyl(pt, eta, phi);
double E =
sqrt(vcyl.R() * vcyl.R() + M * M);
FourVector
q(vcyl.X(), vcyl.Y(), vcyl.Z(),
E);
}
t.Fill();
}
return;
}
{
auto fileName = "tdf002_dataModel.root";
auto treeName = "myTree";
fill_tree(fileName, treeName);
auto n_cut = [](const FourVectors &tracks) { return tracks.size() > 8; };
auto nentries = d.Filter(n_cut, {
"tracks"}).Count();
std::cout << *
nentries <<
" passed all filters" << std::endl;
auto getPt = [](const FourVectors &tracks) {
std::vector<double> pts;
pts.reserve(tracks.size());
for (auto &t : tracks) pts.emplace_back(t.Pt());
return pts;
};
auto getPtWeights = [](const FourVectors &tracks) {
std::vector<double> ptsw;
ptsw.reserve(tracks.size());
for (auto &t : tracks) ptsw.emplace_back(1. / t.Pt());
return ptsw;
};
auto augmented_d = d.Define("tracks_n", [](const FourVectors &tracks) { return (int)tracks.size(); })
.Filter([](int tracks_n) { return tracks_n > 2; }, {"tracks_n"})
.Define("tracks_pts", getPt)
.Define("tracks_pts_weights", getPtWeights);
auto trN = augmented_d.Histo1D(
TH1F{
"",
"", 40, -.5, 39.5},
"tracks_n");
auto trPts = augmented_d.Histo1D("tracks_pts");
auto trWPts = augmented_d.Histo1D("tracks_pts", "tracks_pts_weights");
trN->Draw();
c1.
Print(
"tracks_n.png");
trPts->Draw();
c2.
Print(
"tracks_pt.png");
trWPts->Draw();
c3.
Print(
"tracks_Wpt.png");
return 0;
}
{
}