About Multithreading for reading and analyse root file in a loop

Hi,
I am reading a branch from a root file. Then using the branch to create a histogram in a loop and doing some calculations. So every time I need to make a histogram the first loop is for a variable and another loop over entries to fill the histogram. So it is taking too much time over my system and using only one CPU. My PC has 24 CPUs and I want to utilize all of them. I have tried implicit MT using ROOT::EnableImplicitMT(nThreads); but no benefit as it is then taking more time to perform. So is there a way so that I can distribute my loop over multiple threads. The loop looks like this…

TFile *input = new TFile(Form("%s",fname), "READ");
TTree *data = (TTree*) input->Get("data");
data->SetBranchAddress("q", &q);
int entries = data->GetEntries();

for(CHID=1;CHID<384;CHID++)
{
       TH1F* h1 = new TH1F("h1", "Spectrum of Gamma Rays", nbins, 0, 100);
        if(CHID >64 && CHID < 320){continue;}
        cout<<"Performing fit for Channel ID ="<<CHID<<"\n"; 		
		for(j=1;j<=entries1;j++)
		{
                 data->GetEntry(j);
		 if(q[CHID]>0)
		        {
                         h1->Fill(q[CHID]);
			}
			else{continue;}
                  }	
		h1->Draw("L")
}

ROOT Version: 6.22/08


Hi @Siddharth_Parashari ,
closing this post in favor of its duplicate About Multithreading for reading and analyse root file .

Cheers,
Enrico