12 using FourVectorVec = std::vector<FourVector>;
18 void fill_tree(
const char *filename,
const char *treeName)
20 const double M = 0.13957;
23 auto genTracks = [&](){
25 const auto nPart =
R.Poisson(15);
26 tracks.reserve(nPart);
27 for (
int j = 0; j < nPart; ++j) {
28 const auto px =
R.Gaus(0, 10);
29 const auto py =
R.Gaus(0, 10);
30 const auto pt =
sqrt(px * px + py * py);
31 const auto eta =
R.Uniform(-3, 3);
32 const auto phi =
R.Uniform(0.0, 2 *
TMath::Pi());
33 CylFourVector vcyl(
pt, eta, phi);
35 auto E =
sqrt(vcyl.R() * vcyl.R() + M * M);
37 tracks.emplace_back(vcyl.X(), vcyl.Y(), vcyl.Z(),
E);
43 d.Define(
"tracks", genTracks).Snapshot<FourVectorVec>(treeName, filename, {
"tracks"});
50 auto fileName =
"df002_dataModel.root";
51 auto treeName =
"myTree";
52 fill_tree(fileName, treeName);
61 auto n_cut = [](
const FourVectorRVec &tracks) {
return tracks.size() > 8; };
62 auto nentries =
d.Filter(n_cut, {
"tracks"}).Count();
64 std::cout << *
nentries <<
" passed all filters" << std::endl;
70 auto getPt = [](
const FourVectorRVec &tracks) {
75 auto getPtWeights = [](
const FourVectorRVec &tracks) {
79 auto augmented_d =
d.Define(
"tracks_n", [](
const FourVectorRVec &tracks) {
return (
int)tracks.size(); })
80 .
Filter([](
int tracks_n) {
return tracks_n > 2; }, {
"tracks_n"})
81 .Define(
"tracks_pts", getPt)
82 .Define(
"tracks_pts_weights", getPtWeights);
84 auto trN = augmented_d.Histo1D({
"",
"", 40, -.5, 39.5},
"tracks_n");
85 auto trPts = augmented_d.Histo1D(
"tracks_pts");
86 auto trWPts = augmented_d.Histo1D(
"tracks_pts",
"tracks_pts_weights");
90 c1.
Print(
"tracks_n.png");
94 c2.
Print(
"tracks_pt.png");
98 c3.
Print(
"tracks_Wpt.png");
Random number generator class based on M.
auto Map(const RVec< T > &v, F &&f) -> RVec< decltype(f(v[0]))>
Create new collection applying a callable to the elements of the input collection.
DisplacementVector3D< CylindricalEta3D< double >, DefaultCoordinateSystemTag > RhoEtaPhiVector
3D Vector based on the eta based cylindrical coordinates rho, eta, phi in double precision.
#define R(a, b, c, d, e, f, g, h, i)
LorentzVector< PxPyPzE4D< double > > XYZTVector
LorentzVector based on x,y,x,t (or px,py,pz,E) coordinates in double precision with metric (-...
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
A "std::vector"-like collection of values implementing handy operation to analyse them...
virtual void Print(const char *filename="") const
Save Pad contents in a file in one of various formats.
constexpr Double_t E()
Base of natural log: .
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees, CSV's and other data formats.