TTree filling problems

Hello!

I am trying to make my own root tree and fill it with some numbers. But it doesn’t seem to fill with the numbers I assign. I have attached the code below :
What is it am I doing wrong?

[code]//
// Sample for accessing the Picasso data
//
// Sujeewa Kumaratunga 07/06/2008
//
//

#include “iostream”
#include “iomanip”
#include <TTree.h>
#include “TFile.h”

//#include “PData.hh”
//#include “PBubble.hh”
//#include “Pio.hh”

#include “TH1D.h”

using namespace std;

class STKPhy
{
public:

//Physics Variables; these will be your leaves
Int_t Smaxamp ;
Int_t Smaxampbin;
};

int main(){

TFile *sIGnal = new TFile (“TreeTest.root”,“RECREATE”);

TTree *tree;
tree = new TTree(“StreeVarPhy”,“Stuple tree Variables, Physics”);

STKPhy *stkphy = new STKPhy;

tree->Branch(“PhysVariables”,&stkphy);

for (Int_t ii=0; ii<10; ii++)
{
//PhysVariables branch

  cout<<"ii = "<<ii<<endl;
  stkphy->Smaxamp = 2;
  stkphy->Smaxampbin = ii+2;
   
  tree->Fill();
   
}

sIGnal->cd();
tree->SetDirectory(sIGnal);
tree->Print();
tree->Write();
sIGnal->Write();
sIGnal->Close();

}[/code]

Ideally I would like to have my code like this (as Int_t main) without a name, because I will eventually compile them all using a Makefile. But even if I give the macro a name and run it with ACLiC I still get an error as in this time the tree doesn’t properly fill - it seems to take the first number that was assigned to the first leaf and assign it to all subsequent leaves.

I am using root_v5.16.00

Thank you in advance!

  • Sujeewa

Hi,

Please note that since you are using a class, you must generate a dictionary for that class and compile the class. Note that ACliC will do that for you.

I can not reproduce your problem when using ACLiC. After renaming your function simple01 and the file simple01.C, I did and got:

[code][pcanal@hennequeville tmp]$ root.exe -b -l
root [0] .x simple01.C++
Info in TUnixSystem::ACLiC: creating shared library /var/tmp/./simple01_C.so
/var/tmp/./simple01.C: In function ‘int simple01()’:
/var/tmp/./simple01.C:64: warning: control reaches end of non-void function
ii = 0
ii = 1
ii = 2
ii = 3
ii = 4
ii = 5
ii = 6
ii = 7
ii = 8
ii = 9


*Tree :StreeVarPhy: Stuple tree Variables, Physics *
*Entries : 10 : Total = 2535 bytes File Size = 0 *

  •    :          : Tree compression factor =   1.00                       *
    

*Branch :PhysVariables *
*Entries : 10 : BranchElement (see below) *

*Br 0 :Smaxamp : *
*Entries : 10 : Total Size= 696 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

*Br 1 :Smaxampbin : *
*Entries : 10 : Total Size= 714 bytes One basket in memory *
*Baskets : 0 : Basket Size= 32000 bytes Compression= 1.00 *

(int)6693
root [1] .q
[pcanal@hennequeville tmp]$ root.exe -b -l TreeTest.root
root [0]
Attaching file TreeTest.root as _file0…
Warning in TClass::TClass: no dictionary for class STKPhy is available
root [1] StreeVarPhy->Scan()


  • Row * Smaxamp * Smaxampbi *

  •    0 *         2 *         2 *
    
  •    1 *         2 *         3 *
    
  •    2 *         2 *         4 *
    
  •    3 *         2 *         5 *
    
  •    4 *         2 *         6 *
    
  •    5 *         2 *         7 *
    
  •    6 *         2 *         8 *
    
  •    7 *         2 *         9 *
    
  •    8 *         2 *        10 *
    
  •    9 *         2 *        11 *
    

(Long64_t)10
root [2] .q
[/code]

How is your run different?
Cheers,
Philippe.

Hi Philippe,

Ok, yes you are right, when given a name and ACliCed it will work.

But I also found another way around, ie, to “generate a dictionary for that class and compile the class” as you said without ACliCing the whole macro. I just put my class in a separate header file and loaded that with an ACliC, ie .L Var.C++ and then just ran my macro without ACliCing.

My problem was I could not ACliC my macro. Because the actual code I use relies on existing libraries, and if I try to compile my macro stand alone, as in ACliC it, it will throw a million errors about the existing libraries. And if I try to compile it together with the existing framework using a make install, the whole make install will fault.

Thank you for your time!

  • Sujeewa