Help with TClonesArray/TParticle

Greetings,

I am having trouble using TParticle and TClonesArray. I am new to using TClonesArray methods.

I have a simple .dat file I am reading and trying to output them into a tree of TParticles.
I have read the forums and manual, but I am still unclear.

Attached is my MWE and a small .dat file.
Thanks
trial.dat (515 Bytes)
Convert_GiBUU_2ROOT.C (3.34 KB)

I ran your macro using AClic and got some errors. May be you would like to fix them first ?

$ root Convert_GiBUU_2ROOT.C++
   ----------------------------------------------------------------
  | Welcome to ROOT 6.07/07                    http://root.cern.ch |
  |                                   (c) 1995-2016, The ROOT Team |
  | Built for macosx64                                             |
  | From heads/master@v6-07-06-645-g6594d17, Jun 20 2016, 12:53:42 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'     |
   ----------------------------------------------------------------

root [0] 
Processing Convert_GiBUU_2ROOT.C++...
Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/couet/Downloads/./Convert_GiBUU_2ROOT_C.so
In file included from input_line_12:9:
././Convert_GiBUU_2ROOT.C:49:27: error: allocation of incomplete type
      'TClonesArray'
  TClonesArray* arr = new TClonesArray("TParticle");
                          ^~~~~~~~~~~~
/Users/couet/git/roottrunk-bin/include/TObject.h:200:17: note: forward
      declaration of 'TClonesArray'
   friend class TClonesArray; // needs to reset kNotDeleted in fBits
                ^
In file included from input_line_12:9:
././Convert_GiBUU_2ROOT.C:52:6: error: member access into incomplete type
      'TClonesArray'
  arr->BypassStreamer();
     ^
/Users/couet/git/roottrunk-bin/include/TObject.h:200:17: note: forward
      declaration of 'TClonesArray'
   friend class TClonesArray; // needs to reset kNotDeleted in fBits
                ^
In file included from input_line_12:9:
././Convert_GiBUU_2ROOT.C:68:9: error: member access into incomplete type
      'TClonesArray'
      ar.Clear();
        ^
/Users/couet/git/roottrunk-bin/include/TObject.h:200:17: note: forward
      declaration of 'TClonesArray'
   friend class TClonesArray; // needs to reset kNotDeleted in fBits
                ^
In file included from input_line_12:9:
././Convert_GiBUU_2ROOT.C:82:13: error: type 'TClonesArray' does not provide a
      subscript operator
      new(ar[event.n_particles]) TParticle(event.particle_ID, 1, event.M...
          ~~^~~~~~~~~~~~~~~~~~
In file included from input_line_12:9:
In file included from ././Convert_GiBUU_2ROOT.C:8:
/Users/couet/git/roottrunk-bin/include/TTree.h:344:48: error: 'typeid' of
      incomplete type 'TClonesArray'
      return BranchImp(name, TBuffer::GetClass(typeid(T)), addobj, bufsi...
                                               ^
././Convert_GiBUU_2ROOT.C:51:6: note: in instantiation of function template
      specialization 'TTree::Branch<TClonesArray>' requested here
  t->Branch("b_TParticle",&arr,8000,99);
     ^
/Users/couet/git/roottrunk-bin/include/TObject.h:200:17: note: forward
      declaration of 'TClonesArray'
   friend class TClonesArray; // needs to reset kNotDeleted in fBits
                ^
Error in <ACLiC>: Dictionary generation failed!
root [1] 

Greetings,

I added the line

#include "TClonesArray.h"
To compile with AClic, now it gives me the different errors as when compiling without AClic.
Updated code attached.
Error I receive without AClic

[code]root [0]
Processing Convert_GiBUU_2ROOT.C…
Warning in TTree::Bronch: Using split mode on a class: TParticle with a custom Streamer
3 Number of particles in event

*** Break *** segmentation violation
Generating stack trace…
An admin user name and password is required to enter Developer Mode.
Admin user name ([/code]

No error with AClic, but there is no data in the tree and the output of the macro cannot be true, i.e.
root [0]
Processing Convert_GiBUU_2ROOT.C+…
Warning in TTree::Bronch: Using split mode on a class: TParticle with a custom Streamer
1514067120 total events (there is only 2 events in the file)

I modeled this macro after the one found on the ROOT page
https://root.cern.ch/root/html/tutorials/tree/tcl.C.html
Convert_GiBUU_2ROOT.C (3.41 KB)

Try the attached macro.
Convert_GiBUU_2ROOT.C (3.54 KB)

Greetings,

Thanks for that help.
The code works when AClic is not invoked, i.e.

root -q Convert_GiBUU_2ROOT.C ... ... Processing Convert_GiBUU_2ROOT.C... Warning in <TTree::Bronch>: Using split mode on a class: TParticle with a custom Streamer 3 Number of particles in event 4 Number of particles in event 2 total events
This is correct, 2 events in the test file, and the tree is filled appropriately.

When using AClic

root -q Convert_GiBUU_2ROOT.C+ ... ... Processing Convert_GiBUU_2ROOT.C+... Warning in <TTree::Bronch>: Using split mode on a class: TParticle with a custom Streamer 1459463344 total events
This is not correct, and the tree is empty.

I would like to use AClic, because I will be processing >10M lines.
Any further help would be greatly appreciated.
Thanks

Try:
root -q Convert_GiBUU_2ROOT.C++

Greetings,

Same result as is using AClic with single +.

Processing Convert_GiBUU_2ROOT.C++... Info in <TMacOSXSystem::ACLiC>: creating shared library /Users/michaelkunkel/WORK/GiBUU/release2016/testRun/Electroproduction/skimmer/./Convert_GiBUU_2ROOT_C.so Warning in <TTree::Bronch>: Using split mode on a class: TParticle with a custom Streamer 1408308402 total events
The tree is filled, but the number of reported events is incorrect. I am not sure on the reliability of the output.

Greetings,

Silly me, I forgot to initialize
event.eventNumber = 0;

Now all is fine with any method of compiling.

Thanks for the help.

This initialization was included in my version of your macro, wasn’t it.

Yes, but I missed it when reviewing your version to my version.
I like to understand my mistakes but comparison, that initialization missed my eye at first glance. :blush: