Reading Methods from A TTree

I have a TTree called TMBTree, with a branch Muon and a method Pt() in the muon branch.
I am trying to get the data from the method to fill histogram, the code I am using folows:

MuonPt = new TH1F("MuontPt", "Pt of the Muon", 100,0,150)
TClonesArray *Muon;
Long_t nentries = (Int_t)TMBTree->GetEntries();
TMBTree->SetBranchAddress("Muon", &Muon);

for(Int_t i = 0; i <nentries ; i++) {
    TMBMuon *themuons = (TMBMuon*)Muon->At(i);
    MuonPt->Fill(themuons->Pt());
}

but I get an error saying that ‘themuons’ is an illegal pointer
I have also tried something similar to what is given in trees1.C, but I can’t seem to modify it properly so that it works for methods.

Any suggestions would be greatly appreciated!

Kyle

Hi Kyle,

You example does not include actually reading the data.
You need to add something like

Then you also need to add an inner loop to loop over the element in the TClonesArray.

Cheers,
Philippe.

PS. Note that DZero does provide some precanned framework to read the TMBTree …

Hi Philippe,

I’ve looked at some of the framework, and as far as I can see it does exactly what I am doing and has no nested for loops unless I am not looking at what your suggestion pertains to… the code I am looking at is TMBExample.C, and TMBTreeSelector.h. If their are others it would be apperciated if you could direct me towards them…

Thanks

Kyle

[quote]If their are others it would be apperciated if you could direct me towards them.[/quote]I am not sure which one are currently and where but some of your DZero collegues should be able to help you.

[quote]and as far as I can see it does exactly what I am doing [/quote]This is very unlikely since what you are doing is wrong. In your example ‘nentries’ is the number of entry in the TTree object but you use the index with a TClonesArray (contained within the TTree). In other word for each value from 0 to nentries there is exactly one TClonesArray. For each of this TClonesArray (Muon) there is exactly ‘Muon->GetEntries()’ TMBMuon object.

Cheers,
Philippe