TFile * file = new TFile("example.root", "RECREATE"); TH1D * hist = new TH1D("hist", "My Histogram", 100, 0, 10); hist->SetDirectory(file->mkdir("mydir"));
TFile * file = new TFile("example.root", "RECREATE"); TDirectory * dir = file->mkdir("mydir"); dir->cd(); TH1D * hist = new TH1D("hist", "My Histogram", 100, 0, 10); hist->SetDirectory(dir);This example is similar to the first one, but instead of passing in a TString argument, SetDirectory is called with a TDirectory object. Package/library: ROOT (CERN)