#include <ROOT/RNTuple.hxx>
#include <vector>
constexpr char const* kNTupleMainFileName = "ntpl006_data.root";
constexpr char const* kNTupleFriendFileName = "ntpl006_reco.root";
void Generate()
{
constexpr int kMaxTrack = 500;
auto modelData = RNTupleModel::Create();
auto fldPx = modelData->MakeField<std::vector<float>>("px");
auto fldPy = modelData->MakeField<std::vector<float>>("py");
auto fldPz = modelData->MakeField<std::vector<float>>("pz");
auto modelFriend = RNTupleModel::Create();
auto fldPt = modelFriend->MakeField<std::vector<float>>("pt");
auto ntupleData = RNTupleWriter::Recreate(std::move(modelData), "data", kNTupleMainFileName);
auto ntupleReco = RNTupleWriter::Recreate(std::move(modelFriend), "reco", kNTupleFriendFileName);
for (int i=0; i < 1000; i++) {
for (
int n = 0;
n < ntracks;
n++) {
fldPt->emplace_back(
TMath::Sqrt(fldPx->at(
n) * fldPx->at(
n) + fldPy->at(
n) * fldPy->at(
n)));
}
ntupleData->Fill();
ntupleReco->Fill();
fldPx->clear();
fldPy->clear();
fldPz->clear();
fldPt->clear();
}
}
void ntpl006_friends()
{
Generate();
std::vector<RNTupleReader::ROpenSpec> friends{
{"data", kNTupleMainFileName},
{"reco", kNTupleFriendFileName} };
auto ntuple = RNTupleReader::OpenFriends(friends);
auto c =
new TCanvas(
"c",
"", 200, 10, 700, 500);
TH1F h(
"h",
"pz {pt > 3.}", 100, -15, 35);
auto viewPz = ntuple->GetView<float>("data.pz._0");
auto viewPt = ntuple->GetView<float>("reco.pt._0");
for (auto i : viewPt.GetFieldRange()) {
if (viewPt(i) > 3.)
}
}
#define R__LOAD_LIBRARY(LIBRARY)
R__EXTERN TRandom * gRandom
The RNTupleModel encapulates the schema of an ntuple.
An RNTuple that is used to read data from storage.
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...
virtual Double_t Rndm()
Machine independent random number generator.
Double_t Sqrt(Double_t x)