#include "TFile.h" #include "TKey.h" #include "TH1.h" void read_hist(const char* filename, const char* histname) { TFile* file = TFile::Open(filename); if (!file) return; TKey* key = file->FindKey(histname); if (!key) return; TH1* hist = dynamic_castIn this example, we open a ROOT file using the TFile class. We then use the FindKey method of the TFile class to locate a specific key in the file with the name histname. If the key exists, we can retrieve its object using the ReadObj method of the TKey class. We cast the object to a TH1 histogram and draw it, before closing the file. The package library associated with TKey is ROOT, which provides a wide range of data analysis tools for C++ developers in high-energy physics and other fields that require complex data processing and visualization capabilities.(key->ReadObj()); if (!hist) return; hist->Draw(); file->Close(); }