Branches not filled

Hi all.

I’m working on a tree with two branches. First, I declare two types and the tree in the .h file

[code]
TTree *fTreeMuonInfo;

struct Opposite_t {

	Int_t runNumber;
	Int_t SPDtracklets;
	Float_t m;
	Float_t pt;

};

Opposite_t opposite;

struct Single_t {

	Int_t runNumber;
	Int_t SPDtracklets;
	Float_t pt;

};

Single_t single;[/code]

In my cxx file the tree and the two branches are declared like that:

fTreeMuonInfo = new TTree("fTreeMuonInfo","fTreeMuonInfo"); fTreeMuonInfo->Branch("Single_Muon",&single.runNumber,"runNumber/I:SPDtracklets:pt/F"); fTreeMuonInfo->Branch("Opposite_Muon",&opposite.runNumber,"runNumber/I:SPDtracklets:m/F:pt");

To fill the variable in the tree, I use for instance:

and finally, I fill the two branches (at different places in the macro)

fTreeMuonInfo->GetBranch("Single_Muon")->Fill(); fTreeMuonInfo->GetBranch("Opposite_Muon")->Fill();

But after running the macro, the tree is empty !

Hi,

simply fill the tree instead of each branch separately, otherwise the TTree itself is not aware that you have added an entry to it.

Cheers, Axel.

Ok but my code is like that:

[code]for (condition 1)
{

     Fill branch 1

         for (condition 2)
        {

                if ( test ok ) Fill branch 2

        }

}[/code]

I don’t see where to fill the tree.

Hi,

I am not sure I understand how you plan to use the resulting tree (if you had succeeded in filling it). Almost all the tools used to analyze TTrees requires each ‘corresponding’ entry of all the Branches to be semantically associated. Usually this means that the same entry in each branch belongs to the same ‘Event’ and they can all be retrieved using a single call (eg tree->GetEntry(3) )

If the entry of the branches are not correlated we recommend to use 2 trees: fTreeMuonInfo = new TTree("fTreeMuonInfo","fTreeMuonInfo"); fTreeMuonInfo->Branch("Single_Muon",&single.runNumber,"runNumber/I:SPDtracklets:pt/F"); fTreeMuonInfoOpposite = new TTree("fTreeMuonInfoOpposite","fTreeMuonInfo"); fTreeMuonInfoOpposite->Branch("Opposite_Muon",&opposite.runNumber,"runNumber/I:SPDtracklets:m/F:pt");and fTreeMuonInfo->Fill(); fTreeMuonInfoOpposite->Fill();

If the entries are correlated then you ought to just call Fill on the single tree …

Cheers,
Philippe.

PS. If the entries are correlated but you are really unable to call TTree::Fill, check TTree::SetEntries

Indeed the branches are not correlated. I will use 2 trees.

Thanks.