const std::string kMainNTupleName = "mainNTuple";
const std::string kMainNTuplePath = "main_ntuple.root";
const std::string kAuxNTupleName = "auxNTuple";
const std::string kAuxNTuplePath = "aux_ntuple.root";
constexpr int kNEvents = 10000;
void WriteMain(std::string_view ntupleName, std::string_view ntupleFileName)
{
auto model = RNTupleModel::Create();
auto fldI = model->MakeField<std::uint32_t>("i");
auto fldVpx = model->MakeField<float>("vpx");
auto ntuple = RNTupleWriter::Recreate(std::move(model), ntupleName, ntupleFileName);
for (int i = 0; i < kNEvents; i += 5) {
*fldI = i;
ntuple->Fill();
}
std::cout << "Wrote " << ntuple->GetNEntries() << " to the main RNTuple" << std::endl;
}
void WriteAux(std::string_view ntupleName, std::string_view ntupleFileName)
{
auto model = RNTupleModel::Create();
auto fldI = model->MakeField<std::uint32_t>("i");
auto fldVpy = model->MakeField<float>("vpy");
auto ntuple = RNTupleWriter::Recreate(std::move(model), ntupleName, ntupleFileName);
for (int i = 0; i < kNEvents; ++i) {
*fldI = i;
ntuple->Fill();
}
std::cout << "Wrote " << ntuple->GetNEntries() << " to the auxiliary RNTuple" << std::endl;
}
void Read()
{
auto c =
new TCanvas(
"c",
"RNTupleJoinProcessor Example", 200, 10, 700, 500);
TH1F hPy(
"h",
"This is the px + py distribution", 100, -4, 4);
hPy.SetFillColor(48);
std::vector<RNTupleOpenSpec> ntuples = {{kMainNTupleName, kMainNTuplePath}, {kAuxNTupleName, kAuxNTuplePath}};
auto processor = RNTupleProcessor::CreateJoin(ntuples, {"i"});
float px, py;
for (const auto &entry : *processor) {
px = *entry.GetPtr<float>("vpx");
py = *entry.GetPtr<float>(kAuxNTupleName + ".vpy");
hPy.Fill(px + py);
}
std::cout << "Processed a total of " << processor->GetNEntriesProcessed() << " entries" << std::endl;
hPy.DrawCopy();
}
void ntpl015_processor_join()
{
WriteMain(kMainNTupleName, kMainNTuplePath);
WriteAux(kAuxNTupleName, kAuxNTuplePath);
Read();
}
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 Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Used to specify the underlying RNTuples in RNTupleProcessor.