TH2 *t12d(TList *alist, const char *name2d=0) { //convert 1d histograms in list to a 2d histogram // Histograms in list are converted to a 2d histogram . // The 2d histogram is named names2d if name2d is not null if (!alist) return 0; Int_t nh = alist->GetSize(); if (!nh) return 0; TH1 *h1 = (TH1*)alist->At(0); TAxis *axis = h1->GetXaxis(); Int_t nbins = axis->GetNbins(); TH2F *h2 = new TH2F(name2d,h1->GetTitle(),nbins, axis->GetXmin(),axis->GetXmax(), nh,0,nh); Int_t biny = 0; Double_t nentries = 0; TIter next(alist); while ((h1 = (TH1*)next())) { biny++; nentries += h1->GetEntries(); for (Int_t i=0;iSetBinContent(i,biny,h1->GetBinContent(i)); } } h2->SetEntries(nentries); h2->SetDirectory(0); return h2; } TH2 *t12d(const char *names, const char *name2d=0) { //convert 1d histograms to a 2d histogram //if names = 0, all 1-d histograms in the current directory on disk // are converted to a 2d // if names = xxx all 1d histograms with a name starting with "xxx" // are converted to a 2d histogram . The 2d histogram is named names2d // if name2d is not null and xxx2d otherwise. TList *alist = new TList(); TIter next(gDirectory->GetListOfKeys()); TKey *key; while ((key = (TKey*)next())) { if (!names && !strstr(key->GetClassName(),"TH1")) continue; if (names && strstr(key->GetName(),names) != key->GetName()) continue; TObject *obj = key->ReadObj(); if (!obj->InheritsFrom("TH1")) continue; alist->Add(obj); } TH2 *h2 = t12d(alist,"h2d"); alist->Delete(); delete alist; return h2; } TH2 *t12d() { TFile f("All_chiSig-histos.root"); TH2 *h2 = t12d("hrAPD"); h2->Draw("box"); return h2; }