Problem reading TClonesArray from TTrees

From: Suvayu Ali <fatkasuvayu_at_gmail.com>
Date: Mon, 23 Nov 2009 23:30:20 -0800


Hi everyone,

I think I am missing some extremely simple step, but I can't figure this one out. :(

I am creating some TLorentzVectors from a flat ntuple and saving them in a TTree using TClonesArray using a class originally created by TTree::MakeClass(). I have only edited the Loop() method. This is how I am attempting it.

> TFile fout("ttbar-dil.root","recreate");
> TTree *fEventsTree = new TTree("EventCollection", "Zprime-->ttbar");
> TClonesArray jetsLV("TLorentzVector", 2);
> TClonesArray lepLV("TLorentzVector", 2);
> TClonesArray metLV("TLorentzVector", 2);
> ...
> fEventsTree->Branch( "Jets", &jetsLV);
> fEventsTree->Branch( "Leptons", &lepLV);
> fEventsTree->Branch( "MET", &metLV);
> ...
> // code to implement cuts and fill the Tree,
> ...
> fout.Write();
> fout.Close();

Then I try to access it like this from my analysis macro.

> TFile *fin1 = new TFile("ttbar-dil.root", "read");
> TTree *fEvents1 = (TTree*) fin1->Get("EventCollection");
> TClonesArray *jetsLV1 = new TClonesArray("TLorentzVector");
> TClonesArray *lepLV1 = new TClonesArray("TLorentzVector");
> ...
> fEvents1->SetBranchAddress("Jets", &jetsLV1);
> fEvents1->SetBranchAddress("Leptons", &lepLV1);

But the following always gives me zero.

> Int_t njets = jetsLV1->GetEntriesFast();
> Int_t nlep = lepLV1->GetEntriesFast();

Now using a TBrowser from the ROOT interactive prompt I can see the Tree is not empty. I can even plot any quantity I want to and get histograms showing me the events are there exactly as I would expect it to be! Where am I going wrong?

I have attached my analysis macro. Since the list guidelines say large attachments are not welcome, I have put one of my small TTrees on a webpage @ http://hep.phys.sfu.ca/~suvayu/TTree-prob/

Thank you for any help on this.

ROOT version:
F11: ROOT 5.25/03 (trunk_at_30937, Oct 31 2009, 21:58:43 on linuxx8664gcc) Ubuntu 9.04: ROOT 5.25/01 (trunk_at_30039, Sep 04 2009, 13:39:06 on linux)

-- 
Suvayu

Open source is the future. It sets us free.

  • text/x-c++src attachment: ttbar.C
Received on Tue Nov 24 2009 - 08:30:31 CET

This archive was generated by hypermail 2.2.0 : Tue Nov 24 2009 - 11:50:03 CET