Draw the 2-D histograms which in the subFolder

I have a file which have a Folder and a subFolder, in the subFolder there are some 2-D histograms. My question is: how to Draw the 2-D histograms using command method?

Any help is appreciated!

1 Like

Hi,

Humm do you mean:

TFile *f = TFile::Open("myfile.root");
f->cd("mydirectory");
myhist->Draw();

Philippe.

I am sorry! This is my .root file:run.root (228 KB) It contains shDsssdE histogram, how can I draw it use command method?

Try (the strange thing is that you have a “TFolder” in a file - as far as I am aware, the “TFolder” is memory specific, there is the “TDirectory” which is for disk resident structures as well as memory):

// http://root.cern.ch/root/html/TFile.html

TFile *file = new TFile("run.root", "READ");

file->ls();

//  http://root.cern.ch/root/html/TFolder.html

TFolder *histos = (TFolder*)(file->FindObjectAny("histos"));

histos->ls();
histos->FindObjectAny("shDsssdE")->Draw();
histos->FindObjectAny("chDsssdE")->Draw();
histos->GetListOfFolders()->Print();
histos->FindObject("singles")->ls();
histos->FindObject("singles (cut)")->ls();
((TFolder*)(histos->GetListOfFolders()->FindObject("singles")))->FindObjectAny("shDsssdE")->Draw();
histos->GetListOfFolders()->FindObject("singles")->FindObject("shDsssdE")->Draw();
std::cout << histos->FindFullPathName("shDsssdE") << std::endl;
histos->FindObject("coincidences")->ls();
((TFolder*)(histos->GetListOfFolders()->FindObject("coincidences")))->FindObjectAny("chDsssdE")->Draw();
histos->GetListOfFolders()->FindObject("coincidences")->FindObject("chDsssdE")->Draw();
std::cout << histos->FindFullPathName("chDsssdE") << std::endl;
histos->FindObject("coincidences (cut)")->ls();

// http://root.cern.ch/root/html/TH1.html

TH1F *shDsssdERf = (TH1F*)(histos->FindObjectAny("shDsssdERf"));
TH1F *chDsssdERf = (TH1F*)(histos->FindObjectAny("chDsssdERf"));

shDsssdERf->Draw();
std::cout << shDsssdERf->GetNbinsX() << std::endl;
std::cout << shDsssdERf->GetEntries() << std::endl;
std::cout << shDsssdERf->GetBinContent(shDsssdERf->FindBin(500.0)) << std::endl;

chDsssdERf->Draw();
std::cout << chDsssdERf->GetNbinsX() << std::endl;
std::cout << chDsssdERf->GetEntries() << std::endl;
std::cout << chDsssdERf->GetBinContent(chDsssdERf->FindBin(500.0)) << std::endl;

// http://root.cern.ch/root/html/TH2.html

TH2F *shDsssdE = (TH2F*)(histos->FindObjectAny("shDsssdE"));
TH2F *chDsssdE = (TH2F*)(histos->FindObjectAny("chDsssdE"));

shDsssdE->Draw();
shDsssdE->ProfileX()->Draw();
shDsssdE->ProfileY()->Draw();
shDsssdE->ProjectionX()->Draw();
shDsssdE->ProjectionY()->Draw();
std::cout << shDsssdE->GetNbinsX() << std::endl;
std::cout << shDsssdE->GetNbinsY() << std::endl;
std::cout << shDsssdE->GetEntries() << std::endl;
std::cout << shDsssdE->GetBinContent(shDsssdE->FindBin(2200.0, 8.0)) << std::endl;

chDsssdE->Draw();
chDsssdE->ProfileX()->Draw();
chDsssdE->ProfileY()->Draw();
chDsssdE->ProjectionX()->Draw();
chDsssdE->ProjectionY()->Draw();
std::cout << chDsssdE->GetNbinsX() << std::endl;
std::cout << chDsssdE->GetNbinsY() << std::endl;
std::cout << chDsssdE->GetEntries() << std::endl;
std::cout << chDsssdE->GetBinContent(chDsssdE->FindBin(2200.0, 8.0)) << std::endl;

// http://root.cern.ch/root/html/tutorials/hist/index.html
// http://root.cern.ch/download/doc/3Histograms.pdf

// http://root.cern.ch/drupal/content/tutorials-and-courses
// http://root.cern.ch/root/html/tutorials/
// http://root.cern.ch/drupal/content/howtos
// http://root.cern.ch/drupal/content/users-guide
// http://root.cern.ch/drupal/content/reference-guide

Thanks a lot!