Please read tips for efficient and successful posting and posting code
_ROOT Version: 6.26/11
_Platform: Scientific Linux 6.7
Compiler: Not Provided
Hi everyone,
I have some ROOT files, named HistoOutMcDY_1.root
, HistoOutMcDY_2.root
and so on. Inside these files there are many TH1 and TH2 histograms, some of them with the same name, and I want to create a macro that opens these files, and plot one or more of them (in a stacked way). The code I wrote so far is the following
#include<string>
void graph(){
string histogram = "MuonEtaHistoGL"; //name of the histogram inside the file
TFile *f = new TFile("HistoOutMcDY_1.root", "read");
TH1F *Histo= (TH1F*)f->Get(histogram.c_str());
Histo->Draw();
}
This works fine, but now I want to open all the files at the same time, and retrieve the desired histogram (or histograms) but I don’t know how to do that. I thought to use TChain, but (correct me if I’m wrong), it works only if there are Trees inside the file, which is not my case. I thought also to use the hadd method to merge the files, but as far as I know it works only from terminal, whereas i’d like to call it inside the macro. I thought then to use a TList of files, as I saw in this example, but the section to access the single file and objects inside it’s not clear to me. Could someone explain me a way to solve this problem? Or if there’s a better solution to do what I need?