Strange behavior writting to a ntuple. Altered data!

Hi all!!! :slight_smile:

I’m trying to put some data in a ntuple from a file. I had found some strange behavior when this reachs values higher than 20,000,000. I wrote the code and the strange result from read the file:

Source code:
…
Int_t No, A, B, nlines;
TFile *f = new TFile (out_file, “RECREATE”);
ntuple = new TNtuple (“ntuple”, “Create ascii file”, “No:A:B”);

ifstream in;
in.open (“file”);
nlines = 0;

while (1)
{
in >> No >> A >> B;
if (!in.good ())
break;
if (nlines < 5)
printf
("[%2d] No=%d, A=%d, B=%d \n",
nlines, No, A, B);
ntuple->Fill (No, A, B);
nlines++;
}

f->Write ();

…

Output from root:
root [2] ntuple->Scan(“A:B:A + B”);


  • Row * A * B * A + B *

  •    0 *   5002001 *  20008000 *  25010001 *
    
  •    1 *   5141692 * [color=red] 19868308 *  25010000 [/color]*
    
  •    2 *   4480734 *  20529268 *  25010002 *
    
  •    3 *   4604719 *  20405282 *  25010001 *
    
  •    4 *   4337810 *  20672192 *  25010002 *
    
  •    5 *   4332777 *  20677224 *  25010001 *
    
  •    6 *   4204563 *  20805438 *  25010001 *
    
  •    7 *   4161242 *  20848760 *  25010002 *
    
  •    8 *   4084514 *  20925488 *  25010002 *
    
  •    9 *   4029885 *  20980116 *  25010001 *
    
  •   10 *   3970262 *  21039740 *  25010002 *
    
  •   11 *   3918864 *  21091136 *  25010000 *
    
  •   12 *   3867014 *  21142988 *  25010002 *
    
  •   13 *   3819439 *  21190562 *  25010001 *
    
  •   14 *   3773350 *  21236652 *  25010002 *
    
  •   15 *   3729043 *  21280958 *  25010001 *
    
  •   16 *   3685591 *  21324410 *  25010001 *
    
  •   17 *   3647538 *  21362464 *  25010002 *
    
  •   18 *   3607060 *  21402940 *  25010000 *
    
  •   19 *   3562283 *  21447718 *  25010001 *
    
  •   20 *   3528548 *  21481452 *  25010000 *
    
  •   21 *   3490165 *  21519836 *  25010001 *
    
  •   22 *   3453963 *  21556038 *  25010001 *
    
  •   23 *   3422837 *  21587164 *  25010001 *
    

source ascii file:
No A B
1 5002001 20008000
2 [color=red]5141692 19868309[/color]
3 4480734 20529267
4 4604719 20405282
5 4337810 20672191
6 4332777 20677224
7 4204563 20805438
8 4161242 20848759
9 4084514 20925487
10 4029885 20980116
11 3970262 21039739
12 3918864 21091137
13 3867014 21142987
14 3819439 21190562
15 3773350 21236651
16 3729043 21280958
17 3685591 21324410
18 3647538 21362463
19 3607060 21402941
20 3562283 21447718
21 3528548 21481453
22 3490165 21519836
23 3453963 21556038

As you can see, the sum of A + B should be 25010001, but in the B’s column root starts to add or sub values…

Please tell me what is wrong!!!

Thanks in advance
Rafael R.

p.s. I had saw that when float data are loaded to ntuple from files root change the precision. For example source=0.689114 target=0.6891139, I guest that it can be changed with some option.

A TNtuple store data internally as floats.
Use a TNtupleD to store your data as doubles.
What you observe is simply the limit of precision when adding two floats.

You can also use TTree and define a branch with 2 integers or two branches with one integer. See tutorials and Users Guide.

Rene Brun

In my reply, I forgot top add:

Do not submit to the CINT thread a mail that has nothing to do with CINT.

REne