31constexpr int kNEvents = 10000;
33void Write(std::string_view ntupleName, std::string_view ntupleFileName)
35 auto model = RNTupleModel::Create();
37 auto fldVpx = model->MakeField<std::vector<float>>(
"vpx");
38 auto fldVpy = model->MakeField<std::vector<float>>(
"vpy");
39 auto fldVpz = model->MakeField<std::vector<float>>(
"vpz");
40 auto fldN = model->MakeField<std::uint64_t>(
"vn");
42 auto ntuple = RNTupleWriter::Recreate(std::move(model), ntupleName, ntupleFileName);
44 for (
int i = 0; i < kNEvents; ++i) {
50 for (
int j = 0; j < *fldN; ++j) {
53 pz = px * px + py * py;
55 fldVpx->emplace_back(px);
56 fldVpy->emplace_back(py);
57 fldVpz->emplace_back(pz);
64void Read(
const std::vector<RNTupleSourceSpec> &ntuples)
66 auto c =
new TCanvas(
"c",
"RNTupleProcessor Example", 200, 10, 700, 500);
67 TH1F hPx(
"h",
"This is the px distribution", 100, -4, 4);
71 auto ptrPx = processor.GetEntry().GetPtr<std::vector<float>>(
"vpx");
73 for (
const auto &entry : processor) {
77 if (entry.GetLocalEntryIndex() == 0) {
78 std::cout <<
"Processing " << ntuples.at(entry.GetNTupleIndex()).fName <<
" (" << entry.GetGlobalEntryIndex()
79 <<
" total entries processed so far)" << std::endl;
83 for (
auto x : *ptrPx) {
91void ntpl012_processor()
95 std::vector<RNTupleSourceSpec> ntuples = {
96 {
"ntuple1",
"ntuple1.root"}, {
"ntuple2",
"ntuple2.root"}, {
"ntuple3",
"ntuple3.root"}};
98 for (
const auto &ntuple : ntuples) {
99 Write(ntuple.fName, ntuple.fLocation);
R__EXTERN TRandom * gRandom
The RNTupleModel encapulates the schema of an ntuple.
Interface for iterating over entries of RNTuples and vertically concatenated RNTuples (chains).
An RNTuple that gets filled with entries (data) and writes them to storage.
1-D histogram with a float per channel (see TH1 documentation)
virtual void Rannor(Float_t &a, Float_t &b)
Return 2 numbers distributed following a gaussian with mean=0 and sigma=1.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
Helper type representing the name and storage location of an RNTuple.