13 using FourVectors = std::vector<FourVector>;
18 void fill_tree(
const char *filename,
const char *treeName)
20 TFile f(filename,
"RECREATE");
21 TTree t(treeName, treeName);
23 t.Branch(
"tracks", &tracks);
25 const double M = 0.13957;
28 for (
int i = 0; i < 50; ++i) {
29 auto nPart =
R.Poisson(15);
31 tracks.reserve(nPart);
32 for (
int j = 0; j < nPart; ++j) {
33 double px =
R.Gaus(0, 10);
34 double py =
R.Gaus(0, 10);
35 double pt =
sqrt(px * px + py * py);
36 double eta =
R.Uniform(-3, 3);
38 CylFourVector vcyl(pt, eta, phi);
40 double E =
sqrt(vcyl.R() * vcyl.R() + M * M);
41 FourVector
q(vcyl.X(), vcyl.Y(), vcyl.Z(),
E);
43 tracks.emplace_back(
q);
57 auto fileName =
"tdf002_dataModel.root";
58 auto treeName =
"myTree";
59 fill_tree(fileName, treeName);
68 auto n_cut = [](
const FourVectors &tracks) {
return tracks.size() > 8; };
69 auto nentries = d.Filter(n_cut, {
"tracks"}).Count();
71 std::cout << *
nentries <<
" passed all filters" << std::endl;
77 auto getPt = [](
const FourVectors &tracks) {
78 std::vector<double> pts;
79 pts.reserve(tracks.size());
80 for (
auto &t : tracks)
81 pts.emplace_back(t.Pt());
86 auto getPtWeights = [](
const FourVectors &tracks) {
87 std::vector<double> ptsw;
88 ptsw.reserve(tracks.size());
89 for (
auto &t : tracks)
90 ptsw.emplace_back(1. / t.Pt());
94 auto augmented_d = d.Define(
"tracks_n", [](
const FourVectors &tracks) {
return (
int)tracks.size(); })
95 .Filter([](
int tracks_n) {
return tracks_n > 2; }, {
"tracks_n"})
96 .Define(
"tracks_pts", getPt)
97 .Define(
"tracks_pts_weights", getPtWeights);
99 auto trN = augmented_d.Histo1D({
"",
"", 40, -.5, 39.5},
"tracks_n");
100 auto trPts = augmented_d.Histo1D(
"tracks_pts");
101 auto trWPts = augmented_d.Histo1D(
"tracks_pts",
"tracks_pts_weights");
105 c1.
Print(
"tracks_n.png");
109 c2.
Print(
"tracks_pt.png");
113 c3.
Print(
"tracks_Wpt.png");
Random number generator class based on M.
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
DisplacementVector3D< CylindricalEta3D< double >, DefaultCoordinateSystemTag > RhoEtaPhiVector
3D Vector based on the eta based cylindrical coordinates rho, eta, phi in double precision.
LorentzVector< PxPyPzE4D< double > > XYZTVector
LorentzVector based on x,y,x,t (or px,py,pz,E) coordinates in double precision with metric (-...
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
ROOT's TDataFrame offers a high level interface for analyses of data stored in TTrees.
A TTree object has a header with a name and a title.