Comparison of Input and Output ROOT files for data compression validation
The snippet can be accessed without any authentication.
Authored by
Yuriy Volkotrub
This test code compares the values of kinematical variables (px,py,pz,e) of particles stored in two ROOT files: an input file and an output file generated by a data compression algorithm.
compare_px_values.C 2.17 KiB
#include <TFile.h>
#include <TTree.h>
#include <vector>
#include <iostream>
void compare_px_values() {
TFile* file1 = TFile::Open("/home/yurii/DataCompression/data24_13p6TeV.00472677.physics_Main.deriv.DAOD_PHYSLITE.f1437_m2243_p6142/DAOD_PHYSLITE.38116464._000027.pool.root.1");
if (!file1 || file1->IsZombie()) {
std::cerr << "Error opening file: input" << std::endl;
return;
}
TTree* tree1 = (TTree*)file1->Get("CollectionTree");
if (!tree1) {
std::cerr << "Error: CollectionTree not found in input file" << std::endl;
file1->Close();
return;
}
TFile* file2 = TFile::Open("output.test2.root");
if (!file2 || file2->IsZombie()) {
std::cerr << "Error opening file: output.test2.root" << std::endl;
file1->Close();
return;
}
TTree* tree2 = (TTree*)file2->Get("CollectionTree");
if (!tree2) {
std::cerr << "Error: CollectionTree not found in output.test2.root" << std::endl;
file1->Close();
file2->Close();
return;
}
std::vector<float>* px1 = nullptr;
std::vector<float>* px2 = nullptr;
tree1->SetBranchAddress("HLTNav_RepackedFeatures_ParticleAuxDyn.px", &px1);
tree2->SetBranchAddress("HLTNav_RepackedFeatures_ParticleAuxDyn.px", &px2);
int nEntries = std::min(tree1->GetEntries(), tree2->GetEntries());
if (nEntries == 0) {
std::cerr << "No entries found in one or both trees." << std::endl;
file1->Close();
file2->Close();
return;
}
// Loop over the first 10 events
for (int i = 0; i < std::min(nEntries, 10); ++i) {
tree1->GetEntry(i);
tree2->GetEntry(i);
std::cout << "Event " << i << ":\n";
if (px1->size() != px2->size()) {
std::cerr << "Error: Mismatch in vector sizes for event " << i << std::endl;
continue;
}
for (size_t j = 0; j < px1->size(); ++j) {
std::cout << " Particle " << j << ": px1 = " << px1->at(j)
<< ", px2 = " << px2->at(j)
<< ", delta = " << (px2->at(j) - px1->at(j)) << std::endl;
}
}
file1->Close();
file2->Close();
}
Please register or sign in to comment