Re: Double_t Trouble?

From: Rene Brun (Rene.Brun@cern.ch)
Date: Thu Aug 26 1999 - 09:30:31 MEST


Hi Christopher,
When using structs one has to be very careful with the alignment of
members
in the struct. In your case the Double_t is following Int_t and Float_t
and may be at an odd address.
Two solutions:
  1- specify Double_t as the first element
  2- Create a separate branch for temperature.

Rene Brun


Christopher A. Stevens wrote:
> 
> Redhat 6.0 Linux with SMP kernel with ROOT 2.22/10.
> I've been having problems moving from simple TNtuples to TTrees.
> I took the "simple example" from the TTree Class Description,
> made it into an macro, and simplified it to:
> {
>    TFile hfile("htree.root","RECREATE","Demo ROOT file with histograms &
> trees")
> 
>    typedef struct {
>       Int_t ntrack,nseg,nvertex;
>       UInt_t flag;
>       Float_t temperature;
> //      Double_t temperature;
>    } EVENTN;
>    static EVENTN eventn;
> 
>    TTree *tree = new TTree("T","An example of ROOT tree with a few
> branches");
> 
> tree->Branch("eventn",&eventn,"ntrack/I:nseg:nvertex:flag/i:temperature/F");
> //
> tree->Branch("eventn",&eventn,"ntrack/I:nseg:nvertex:flag/i:temperature/D")
> 
>    for ( Int_t i=0; i<1000; i++) {
>       Float_t random = gRandom->Rndm(1);
> 
>       eventn.ntrack  = Int_t(100*random);
>       eventn.nseg    = Int_t(2*eventn.ntrack);
>       eventn.nvertex = 1;
>       eventn.flag    = Int_t(random+0.5);
>       eventn.temperature = Float_t(20+random);
> //      eventn.temperature = Double_t (20+random);
> 
>       tree->Fill();
>    }
> 
>    hfile.Write();
> 
>    hfile.Close();
> 
> }
> I get what looks like a good histogram with the Float_t lines,
> but when I use the Double_t lines I get a histogram with a
> single spike at zero.
> What am I doing wrong?
> 
> Chris Stevens



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:38 MET