Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:11:58

0001 void splitNtuple(TString inputfname = "./Data_CombinedNtuple_Run20869_HotDead_BCO_ADC_Survey.root", TString outputdir = "./Data_CombinedNtuple_Run20869_HotDead_BCO_ADC_Survey")
0002 {
0003     system(Form("mkdir -p %s", outputdir.Data()));
0004 
0005     TFile *f = TFile::Open(inputfname.Data(), "READ");
0006     TTree *t = (TTree *)f->Get("EventTree");
0007     Long64_t Nevent = t->GetEntries();
0008     Long64_t NeventPerFile = 1000;
0009     Long64_t Nfile = ceil(double(Nevent) / double(NeventPerFile));
0010 
0011     cout << "Nevent: " << Nevent << ", Nfile: " << Nfile << endl;
0012 
0013     for (Long64_t i = 0; i < Nfile; i++)
0014     {
0015         TString outputfile = Form("%s/ntuple_%05d.root", outputdir.Data(), int(i));
0016         cout << "outputfile: " << outputfile << endl;
0017         
0018         TFile *fout = TFile::Open(outputfile.Data(), "recreate");
0019         TTree *tnew = t->CloneTree(0);
0020         for (Long64_t j = 0; j < NeventPerFile; j++)
0021         {
0022             Long64_t k = i * NeventPerFile + j;
0023             if (k >= Nevent)
0024             {
0025                 break;
0026             }
0027             t->GetEntry(k);
0028             tnew->Fill();
0029         }
0030         tnew->Write("", TObject::kWriteDelete);
0031         fout->Close();
0032     }
0033     f->Close();
0034 }