Hi,
I have a file with a bunch of histograms named “Varied0” “Varied1” “Varied2” etc etc.
I am trying to access them one by one in a loop as such
for (int i=0;i<100;i++){
std::string name{"Varied"};
name+= std::to_string(i);
TFile *dataFile = new TFile("file.root");
TH1F* dataHist = new TH1F(name.c_str(),name.c_str(), 100, 0, 4);
dataHist = (TH1F*) dataFile->Get(name.c_str());
dataHist->Draw();
}
However, doing this all the histograms are just the blank histogram initialized before Get(name.c_str()) is called, with the correct name for the title (e.g. Varied0)
I instead tried changing std::to_string(i) to std::to_string(0) just to test, and they are still blank.
However, if I replace dataHist = (TH1F*) dataFile->Get(name.c_str());
with dataHist = (TH1F*) dataFile->Get(“Varied0”);
Which should be identical, this time I do get the histogram Varied0.