To Write objects in different files

Hello,

I want to divide all Entries into differrent output based on some selection.
Such as,

TFile* fout[10];
for(int i=0; i<10; i++){
   std::string outputfile_sec = outputfile + "_" + std::to_string(i) + ".root";
   fout[i] = new TFile(outputfile_sec.c_str(),"RECREATE");
 }

for(Long64_t ii=0; ii<n_entries; ii++){
tree->GetEntry(ii);
Double_t rannum = gRandom->Uniform(0, 1);   
bin = BinCreat->FindBin(rannum);
fout[bin-1]->cd(); // enter into differrent files. 
...
a->Fill(); 
b->Fill();
}

'But I don't know how to a->Write() to match different files in next Write section?'


You need to create separate trees in each output file.

Thanks, I created an array for file, and the correspoonding arrays for the histograms, and resloved the problem.

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