Creating an array of the names of the histograms of a ROOT file

Hello,

Is there any way to create an array of the names of the histograms of a root file from inputting the root file? I saw that there is a way to create it using TList, however, I already ran the code which took 3 days, and I do not want to rerun it again by revising the code with TList.

I am trying to create a way to save all graphs as PNG files by inputting a root file. My root file has around 100 histograms. I created a function to convert the histogram to a PNG file, however, I need to input the names of the histograms. Also, I have an older version of ROOT (5.34/10) so the rootprint command does not work for me.

Thank you very much and I really appreciate any help,
ppajarillo


ROOT Version: 5.34/10
Platform: Ubuntu 18.04 LTS
Compiler: Not Provided


Hello,

You can use TList::FindObject,

//TList * myHistoList = new TList();
// myHistoList->Add( ... )
TH1 * temp_h = (TH1*)myHistoList->FindObject( "myFancyHistogram" );
temp_h -> Draw();

you can store the name of the histogram (as the key) & pointer in a map,

std::map<std::string, TH1 * > myHisto_m;

//TList * myHistoList = new TList();
// myHistoList->Add( ... )
for( auto it = myHistoList->begin(); it != myHistoList->end(); ++it) 
{ 
  TH1* currentHisto = (TH1*)(*it); 
  myHisto_m.emplace( currentHisto->GetName() , currentHisto );
}
myHisto_m[ "myFancyHistogram" ]->Draw();

I don’t know if this can help.

Best regards,
atd

What is the obstacle which prevents you to use ROOT6 and therefore rootprint?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.