Double_t against G4double

I am trying to use ROOT Trees to store data from my Geant4 montecarlo. But when I define the class containing tree elements, I must use the Double_t/Int_t/… formats from ROOT. However my results are from G4, and then I can fill that class with G4double/G4int/… values only! What I get is a good ROOT file, with wrong numbers inside. I am preatty sure that there is something very stupid that I am missing to solve the conversion: could someone give me a hint?

G4double and G4int are simply typedefs to double and int respectively.
There should be no problems with these types.
Could you send more information or provide a small ROOT file
filled with these types?

Rene

The entire program is too long to be explained. I put on www.pi.infn.it/~vecchio/work ASCII files with the part of the code related to the tree creation. Files are called problema_albero.* (cc for the source pieces and hh for the header pieces). The result printed on my screen is:

Z 4, A 8, position (-181.86205,0.83498924,0.069129021);
Z 4, A 8, position (-197.93016,1.0865305,1.0587331);
Z 4, A 8, position (-193.38001,-1.030061,-1.0510456);

while the strange result stored on the root file can be seen in stacking.root (in the above mentioned web page).

In your function HadrontherapyRunAction::BeginOfRunAction
replace the line

tree->Branch("branch",&fEvent,"Event/F:Nz:Na:x:y:z"); by

tree->Branch("branch","TreeEvent",&fEvent);

When giving the pointer to an object, you do not have to descriibe the branch
elements. They are automatically known from ROOT (assuming that
you have generated a dictionory for TreeEvent)

Rene

I have tried to do it, but an error appears while executing the program:

(where does “Bronch” come from?) and the tree stores only the column “Row”.

The string #include “TreeEvent.h” is inserted in the RunAction header file. But I made my own made class TreeEvent coming from TObject, and not from TBranch! Is that the error?

This is one of my first attempts in creating classes, I apologize if my mistakes are more due to C++ ignorance, rather than ROOT…

:confused:
I forgot to tell it: I am using ROOT v4.03/02, with gcc v3.3.4 and GEANT4 v7.1

It means that you did not generate the dictionary for your classes.
If you do not know how to do this (or do not want to learn it ::slight_smile:
I suggest the following simple change in your code that will work
providing that all data members of your class TreeEvent are doubles.

Rene

Hi,

You need to generate the dictionary (see ROOT Users’ guide) for the class TreeEvent.

Cheers,
Philippe

Once I solved my problems with rootcint,
with the line

I get:

[quote]Z 4, A 8, position (-181.86205,0.83498924,0.069129021);
Z 4, A 8, position (-197.93016,1.0865305,1.0587331);
Z 4, A 8, position (-193.38001,-1.030061,-1.0510456);


  • Row * Nz * Na * x * y * z *

  •    0 *         0 *         0 *         0 *         0 *         0 *
    
  •    1 *         0 *         0 *         0 *         0 *         0 *
    
  •    2 *         0 *         0 *         0 *         0 *         0 *
    

[/quote]
with the line:

I get:

[quote]Z 4, A 8, position (-181.86205,0.83498924,0.069129021);
Z 4, A 8, position (-197.93016,1.0865305,1.0587331);
Z 4, A 8, position (-193.38001,-1.030061,-1.0510456);


  • Row * Nz * Na * x * y * z *

  •    0 *         0 *         0 *         0 *         0 *         0 *
    
  •    1 *         0 *         0 *         0 *         0 *         0 *
    
  •    2 *         0 *         0 *         0 *         0 *         0 *
    

*****************************************************[/quote]
That is… the same! :frowning:

Hi,

Are you sure that &fEvent is the address of a pointer to your event class?
Are you sure that &fEvent->Event is the starting address of the data?

Since you have not given us a complete example this is unclear and I have no idea if there are other issues.

Philippe.

I was quite sure that the sintax is the correct one. Now I am not anymore…

You can find my files in
http://www.pi.infn.it/~vecchio/work/ROOT-G4problem

you cannot compile them, but all the reference to ROOT are contained only there.

in the portion of code your provided, I did not understand how you insured that the value of fEvent is properly passed between your 2 classes (RunAction and StackingAction).

Philippe

:smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley: :smiley:

What a stupid mistake I was doing!!! Thank you, it’s all ok now!

:laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: :laughing: