I have 8 different root files and from each root file I want to extract two histograms of the same name (data_29599 and data_2199). My printout statements indicate that the histograms are not found.
void Fitting_Code() { //OPENING BRACE
int numfiles = 8;
int histograms= 2;
TFile* s[numfiles];
std::vector<std::string> root_File_Names = {"Plots_Cos_CS_Theta_Squared_MC.root",
"Plots_Cos_CS_Theta_Squared_MC_Low_Q.root",
"Plots_Cos_CS_Theta_Squared_MC_High_Q.root",
"Plots_Cos_CS_Theta_Squared_MC_Low_qT.root",
"Plots_Cos_CS_Theta_Squared_MC_High_qT.root",
"Plots_Cos_CS_Theta_Squared_MC_Low_Photon_Pt.root",
"Plots_Cos_CS_Theta_Squared_MC_Mid_Photon_Pt.root",
"Plots_Cos_CS_Theta_Squared_MC_High_Photon_Pt.root"
}; //The file containing all the root files needs to be transformed into a string, one string per file and be named the same as the file name
std::vector<std::string> Hist_List = {"Data_29599", "Data_29199"};
for (Int_t i = 0; i <numfiles; i++)
{
s[i] = TFile::Open(root_File_Names[i].c_str()); //Loops through the file names in the .c_str file
std::cout << root_File_Names[i].c_str() << std::endl;
for (Int_t j=0; j<histograms; j++)
{
std::cout << Hist_List[j].c_str() << std::endl;
TH1D *h1 = (TH1D*)s[i]->Get("Data_29599");
if(h1==0){
std::cout << "h1 found" << std::endl;
}
else { std::cout <<"h1 not found" << std::endl;
}
}
}
Thank you for this. I wouldn’t have realised I needed GetObject (from my googlings I’ve yet to see this used in this way), so thank you. I will have a read up on GetObject now for future reference.