Re: Splitting ROOT files according to sampling times

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Tue, 10 Nov 2009 12:17:54 +0100


Hi Ida,

You can close/open a new file under your control, eg with a logic like;

// at start create a file and a Tree

    TFile *f = new TFile("myfile_0.root","recreate");     TTree *T = new TTree("T","....);
    Int_t nfiles = 0;

//loop on your events

    for (int event =0; event<nevents; event++) {

       if (event && event%1000 == 0) {
          //Save Tree header, then move to a new file, resetting the Tree
          T->AutoSave();
          nfiles++;
          TFile *newfile = new TFile(Form("myfile_%d",nfiles),"recreate");
          T->Reset();
          T->SetDirectory(newfile);
          delete f;
          f = newfile;
        }
      
        // process your event;
        ...
        T->Fill();
     }
     T->AutoSave();
          

Rene Brun

Ida Häggström wrote:
> Dear all,

>

> I've run a 400 sec dynamic simulation of a PET acqusition (in Gate),
> resulting in one large ROOT file (A Tree containing branches of hits,
> singles and coincidences). There is also a time flag in the branches.
>

> What I wonder is if it is possible to split the single ROOT output
> file I get from the run into several ones according to the time
> sampling scheme I had during my simulation? I.e. one file containing
> all coincidences occurring between 0-1 s, next file coincidences
> between 1-2 s and so on. Or I could for example split the large ROOT
> file to one with coincidences 0-10 s, next 10-20 s and so on.
>

> I don't really know how to sort the data and match an event to the
> right time and so on.
> Thank you in advance for any help on how to get started or reading tips!
> Ida
Received on Tue Nov 10 2009 - 12:17:36 CET

This archive was generated by hypermail 2.2.0 : Tue Nov 10 2009 - 17:50:03 CET