Using a TChain of several .root files containing events, I’d like to extract a subset of the events into a new .root file, depending on some calculated event properties. So I would like to make a “skim”.
I’ve looked around at various TTree and TChain cloning documentation, and came up with the following code:
TChain * chain = new TChain("CITTree");
chain->Add("Run123596/analysis_cit_1.root");
TFile *skimfile = new TFile("Skim.root","recreate");
TTree *newtree = chain->CloneTree(0);
newtree->Print("p");
So far so good … I see a nice print of the cloned tree. Now I try to extract what I need into the “Skim.root” file:
chain->SetBranchAddress("Run",&myRun);
chain->SetBranchAddress("Event",&myEvent);
(etc.etc. there are a lot of these!)
Int_t nevents = (Int_t)chain->GetEntries();
Int_t nbytes = 0;
Int_t nselected = 0;
for(int ievent=0; ievent<nevents; ievent++)
{
nbytes += chain->GetEntry(ievent);
if(nTracks <= 0) continue; // or something more complex
nselected++;
newtree->Fill();
}
newtree->Write();
skimfile->Close();
Root.exe crashes at the point I call “newtree->Fill()”.
What am I doing wrong?
(This is on Windows 7 running ROOT 5.21/04)
Thanks!
Julian