#include #include #include #include int main() { // Open the ROOT file TFile *file = TFile::Open("3097_anasig_mc_279.root"); if (!file || file->IsZombie()) { std::cerr << "Error opening file" << std::endl; return 1; } // Get the TTree TTree *tree = (TTree*)file->Get("track"); if (!tree) { std::cerr << "Error getting tree" << std::endl; return 1; } //tree->Print(); // Prepare variable to read array branch Int_t pdgid[12984]; // Assuming the array branch contains 10 elements //std::vector *pdgid = nullptr; tree->SetBranchAddress("pdgid", pdgid); // Create a histogram TH1F *hist = new TH1F("hist", "Histogram of Array Values;Value;Entries", 100, -20000, 20000); // Loop over entries Long64_t nEntries = tree->GetEntries(); for (Long64_t i = 0; i < nEntries; ++i) { if (tree->GetEntry(i) <= 0) { std::cerr << "Error reading entry " << i << std::endl; continue; } } // Fill the histogram for (int j = 0; j < 12984; ++j) { hist->Fill(pdgid[j]); } // Draw the histogram hist->Draw(); // Clean up //delete file; //return 0; }