Data types order in branches filling

Dear all,
I want to fill a branch of my TTree with the following structure:

struct trk_t { Long_t idppart; Long_t idmpart; Long_t idlpart; Double_t px; Double_t py; Double_t pz; Double_t sx; Double_t sy; Double_t E; Double_t Enu; Int_t idev; Int_t id; Int_t layer; Int_t lp; Int_t mp; Int_t pp; }; trk_t trk;
af the branch declaration is the following:

When I try in this way, the leaves are not correctly filled (for example the leave called idppart is filled with idmpart, or the leave called idev with layer, some other leaves have entries like 1x10e12, etc…)!

Is this the correct order of data types? Am I doing something wrong?

Thanks a lot,
Fabio

I suggest a simplification of your program as shown in the example below.
run it with
root > .x trk.C+

Rene

[code]//file trk.C
#include “TFile.h”
#include “TTree.h”
#include "TRandom.h"
struct trk_t {
Long_t idppart;
Long_t idmpart;
Long_t idlpart;
Double_t px;
Double_t py;
Double_t pz;
Double_t sx;
Double_t sy;
Double_t E;
Double_t Enu;
Int_t idev;
Int_t id;
Int_t layer;
Int_t lp;
Int_t mp;
Int_t pp;
};
void trk() {
trk_t trk;
TFile *f = new TFile(“trk.root”,“recreate”);
TTree *T = new TTree(“t”,“test”);
T->Branch(“trk”,&trk,16000,99);

  TRandom r;
  for (Int_t i=0;i<100;i++) {
     trk.idppart=i;
     trk.idmpart=i+10;
     trk.idlpart=i+20;
     trk.px = r.Gaus(0,1);
     trk.py = trk.px+10.;
     trk.pz = trk.px+20.;
     trk.sx = trk.px+1000.;;
     trk.sy = trk.px+2000.;;
     trk.E  = trk.px+i;;
     trk.Enu = trk.px+5000;
     trk.idev = i+1000;;
     trk.id = i+2000;;     
     trk.layer = i+3000;;
     trk.lp = i+4000;;
     trk.mp = i+5000;;
     trk.pp = i+6000;;
     T->Fill();
  }
  T->Print();
  T->Write();
  T->Show(10);
  delete f;

}
[/code]

Dear Rene,
thanks for your example, it works fine if I run it with
root > .x trk.C+

But if I try to run it with
root > .L trk.C
root > trk()

I have the following error:
Error in TClass::BuildRealData: Cannot find any ShowMembers function for trk_t!

Later on, it try to fill the tree, but this is the result:


*Tree :t : test *
*Entries : 100 : Total = 11422 bytes File Size = 0 *

  •    :          : Tree compression factor =   1.00                       *
    

*Branch :trk *
*Entries : 100 : BranchElement (see below) *

*Br 0 :idppart : *
*Entries : 100 : Total Size= 644 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 1 :idmpart : *
*Entries : 100 : Total Size= 644 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 2 :idlpart : *
*Entries : 100 : Total Size= 644 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 3 :px : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 4 :py : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 5 :pz : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 6 :sx : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 7 :sy : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 8 :E : *
*Entries : 100 : Total Size= 608 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 9 :Enu : *
*Entries : 100 : Total Size= 620 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 10 :idev : *
*Entries : 100 : Total Size= 626 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 11 :id : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 12 :layer : *
*Entries : 100 : Total Size= 632 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 13 :lp : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 14 :mp : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

*Br 15 :pp : *
*Entries : 100 : Total Size= 614 bytes One basket in memory *
*Baskets : 0 : Basket Size= 16000 bytes Compression= 1.00 *

and then there is this message:

*** Break *** segmentation violation

===========================================================
There was a crash (#7 0x009bb89d in SigHandler(ESignals) ()).
This is the entire stack trace of all threads:

followed by the list of threads

Can you explain me why?

Thanks a lot,
Fabio

[quote]Is this the correct order of data types? Am I doing something wrong?[/quote]Rather than a struct, I recommend you use a compiled class (using ACLiC it is very simple to do). If you must use a struct then you ought to sort the member is decreasing sizeof order, so first Double_t then Long_t the Int_t.

Cheers,
Philippe.

[quote]But if I try to run it with
root > .L trk.C
root > trk()

I have the following error:
Error in TClass::BuildRealData: Cannot find any ShowMembers function for trk_t![/quote]This is the expected result. This example does not use the leaflist branch creation method and thus requires a dictionary for a compiled class (i.e. you must do .L trk.C+).

Cheers,
Philippe.