#include <cstdint>
constexpr char const *kNTupleInputName = "ntpl";
constexpr char const *kNTupleInputFileName = "ntpl010_input.root";
constexpr char const *kNTupleOutputName = "ntpl_skim";
constexpr char const *kNTupleOutputFileName = "ntpl010_skim.root";
constexpr int kNEvents = 25000;
static void Write()
{
auto fldVpx = model->MakeField<std::vector<float>>("vpx");
auto fldVpy = model->MakeField<std::vector<float>>("vpy");
auto fldVpz = model->MakeField<std::vector<float>>("vpz");
auto fldN = model->MakeField<float>("n");
for (int i = 0; i < kNEvents; i++) {
*fldN =
static_cast<int>(
gRandom->Rndm(1) * 15);
fldVpx->clear();
fldVpy->clear();
fldVpz->clear();
for (int j = 0; j < *fldN; ++j) {
float px, py, pz;
pz = px * px + py * py;
fldVpx->emplace_back(px);
fldVpy->emplace_back(py);
fldVpz->emplace_back(pz);
}
}
}
void ntpl010_skim()
{
Write();
for (const auto &value : reader->GetModel().GetDefaultEntry()) {
if (value.GetField().GetFieldName() == "n")
continue;
const std::string newName = "skim_" + value.GetField().GetFieldName();
skimModel->AddField(value.GetField().Clone(newName));
skimModel->GetDefaultEntry().BindValue<void>(newName, value.GetPtr<void>());
}
auto ptrSkip = skimModel->MakeField<std::uint16_t>("skip");
auto hSkip =
new TH1F(
"h",
"distribution of skipped entries", 10, 0, 10);
auto ptrN = reader->GetModel().GetDefaultEntry().GetPtr<float>("n");
for (auto numEntry : *reader) {
reader->LoadEntry(numEntry);
if (*ptrN <= 7) {
(*ptrSkip)++;
continue;
}
hSkip->Fill(*ptrSkip);
*ptrSkip = 0;
}
hSkip->DrawCopy();
}
static std::unique_ptr< RNTupleModel > Create()
static std::unique_ptr< RNTupleReader > Open(std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleReadOptions &options=ROOT::RNTupleReadOptions())
Open an RNTuple for reading.
static std::unique_ptr< RNTupleWriter > Recreate(std::unique_ptr< ROOT::RNTupleModel > model, std::string_view ntupleName, std::string_view storage, const ROOT::RNTupleWriteOptions &options=ROOT::RNTupleWriteOptions())
Creates an RNTupleWriter backed by storage, overwriting it if one with the same URI exists.
1-D histogram with a float per channel (see TH1 documentation)