Rounding problem

Hi,

I’m using ORCA class called TRootGenParticle for representing generated particles in a particular event and I have a problem with getting right values of energy, momentum,… because they are always rounded. To be more specific; all the values are stored in a ROOT tree and it’s possible to see their values by Scan function and there you would see for example value 4263.6835 but when you would want to read out only that specific energy by calling energy member from object of class TRootGenParticle, you would get 4263.68. Every time you get only 6 digits so 58.392398 would be read as 58.3924. Energy and other parameters are defined as Float_t.

The same thing happens when you try to read numbers as Double_t from ordinary text file using ifstream.

I’m using ROOT version 3.10/02 but the problem with text file happens also in ROOT version 5.02/00.

Thanks,

Dinko

Hi,

I am a little confused by your question. You seem to be saying that when you use TTree::Scan you get “for example value 4263.6835” but when you use the method of your class and use a mechanism you have not specified to print the result you get “4263.68”.

My interpretation (based on my weak understanding of your mail :slight_smile: ) is that it might be a consequence of the mechanism you use to print the result of the the method call.

Could please be more explicit (actually C++ code, root file, actual output, etc.) in what you are trying to do, so that we can be more helpful.

Cheers,
Philippe.

When I read my post again I relized myself that it is a little bit confusing :slight_smile:

Root file has around 36 MB so I’ll give part of the C++ code and the actual output that I get.

Content of C++ file chain.C is the following:

{

// Load shared library
gSystem->Load(“libExRootAnalysisReader”);

// Create chain of root trees
TChain chain(“Analysis”);
chain.Add(“file.root”);

// Create object of class ExRootTree
ExRootTreeReader *tree = new ExRootTreeReader(&chain);
Long64_t numberOfEntries = tree->GetEntries();
//Long64_t numberOfEntries = 1000;

// Get pointers to Generator branch used in this analysis
TClonesArray *branchGen = tree->UseBranch(“Gen”);

// Loop over all events
//for(Int_t entry = 0; entry < numberOfEntries; entry++) {
for(Int_t entry = 0; entry < 1; entry++) {

// Load selected branches with data from specified event

tree->ReadEntry(entry);

// If event …
if(branchGen->GetEntries() > 0) {

  // Loop over all particles in the event
  //for(int i=0; i<branchGen->GetEntries(); i++){
  for(int i=0; i<15; i++){

TRootGenParticle *rootGenParticle = (TRootGenParticle*) branchGen->At(i);

cout<<"E = "<<rootGenParticle->E<<endl;

  }
}

}
}

and what you get by executing .x chain.C is:

E = 7000
E = 7000
E = 14000
E = 264.06
E = 209.301
E = 478.697
E = 58.3924
E = 414.968
E = 250.994
E = 1.03074
E = 6.99013
E = 12.1702
E = 20.0739
E = 13.9282
E = 3.74274

If after that you execute chain.Scan(“Gen.E”) you get:


  • Row * Instance * Gen.E *

  •    0 *        0 *      7000 *
    
  •    0 *        1 *      7000 *
    
  •    0 *        2 *     14000 *
    
  •    0 *        3 * 264.05993 *
    
  •    0 *        4 * 209.30090 *
    
  •    0 *        5 * 478.69662 *
    
  •    0 *        6 * 58.392398 *
    
  •    0 *        7 * 414.96841 *
    
  •    0 *        8 * 250.99433 *
    
  •    0 *        9 * 1.0307350 *
    
  •    0 *       10 * 6.9901347 *
    
  •    0 *       11 * 12.170167 *
    
  •    0 *       12 * 20.073938 *
    
  •    0 *       13 * 13.928201 *
    

And if you try to calculate something with energy (similar thing is happening for other parameters), because of the rounding you get wrong results. From Scan it’s obvious that energy is given with greater precision than it is printed out.

Hi,
callcout.precision(10);before the linecout<<"E = "<<rootGenParticle->E<<endl;and you’ll see that cout was simply rounding your values when printing them.
Axel.

Hi,

This is a feature of the iostream. The default printed precision is 6.
To change it use:

[Caveat: this does not work yet in CINT]
Cheers,
Philippe

Thanks, now the cout output is OK. Thanks again.