Maximum number of object? (TH1D* and TTree*)

ROOT Version: 6.28/04 & also tested on 6.26/02
Platform: MacOS Ventura 13.5, Apple M1 Pro
Compiler: Using macro file command with .L

Hi experts,

I’m trying to write a macro code using ROOT.
1 Reads ROOT file and read tree.
2 Create a std::vector<TH1D*> histoContainer
3 Create n histograms (n = numSeg) and push_back to the histoContainer
4 and fill the histograms using the data in the tree.
5 Repeat process 1-4

It works for first few files. But when the number of histogram reaches ~60, it cannot read the tree (printing “tree”, see code example at the bottom). Here’s what I tried and stopped point.
15th file, numSeg = 2
12th file, numSeg = 3
7th file, numSeg = 6
2nd file, numSeg = 64
1st file, numSeg = 100

So, I assume that is there a global limit for the number of objects can be created in the gDirectory. Another hypothesis is memory management of apple silicone chips. Is there anybody who has similar case and solution?

Thank you,

Here’s my macro code example.

for(int j =0; j < fileNames.size(); j++)
{
        TFile* afile = new TFile(filename, "READ");
        if(!afile) std::cerr << "file"; else afile->GetListOfKeys()->Print();
        TTree* aTree = (TTree*) afile->Get(treename);
        if(!aTree) std::cerr << "tree";
        TBranch* tsBranch = aTree->GetBranch("time_stamp");
        if(!tsBranch) std::cerr << "ts Branch";
        tsBranch->SetAddress(&timeStamp);
        TBranch* longBranch = aTree->GetBranch("energy_long");
        if(!longBranch) std::cerr << "long Branch";
        longBranch->SetAddress(&energyLong);

         for(int i = 0; i < numSeg; i++)
        {
            TH1D* h1 = new TH1D(Form("h1_%d_%d", j, i), Form("Time seg #%d", i), 512, 0, 4096);   
            histoContainer.push_back(h1);
            std::cout << "make histograms " << h1->GetName() << std::endl;
        } 
}```

Hi,
There is only a limit for storing objects in th TTree in a single buffer, but this is at around 1 GB. You are creating 1D histograms with 512 bins, so you should be able to create many of them.
Please post your full running script so we can reproduce your problem

Lorenzo

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