Errors when trying to write a Pythia event in a TTree

ROOT Version: 6.26/10
Pythia Version: 8.310
Platform: Ubuntu 22.04.3 LTS


I’ve been trying for a few days now to record a pythia8 event in a ROOT TTree file. I was trying to use the code suggested by brun in Storing Pythia8 Events In A TTree, which used to be provided with the Pythia distribution, and no longer is. I also made minor modifications due to time changes in Pythia, as you can see below

// File: tree.cc
// This is a simple test program.
// Modified by Rene Brun and Axcel Naumann to put the Pythia::event 
// into a TTree.
// Copyright C 2011 Torbjorn Sjostrand

// Header file to access Pythia 8 program elements.
#include "Pythia8/Pythia.h"

// ROOT, for saving Pythia events as trees in a file.
#include "TTree.h"
#include "TFile.h"

using namespace Pythia8;

int main() {

  // Create Pythia instance and set it up to generate hard QCD processes
  // above pTHat = 20 GeV for pp collisions at 14 TeV.
  Pythia pythia;
  pythia.readString("HardQCD:all = on");
  pythia.readString("PhaseSpace:pTHatMin = 20.");
  pythia.readString("Beams:eCM = 14000");

  // Set up the ROOT TFile and TTree.
  TFile *file = TFile::Open("pytree.root","recreate");
  Event *event = &pythia.event;
  TTree *T = new TTree("T","ev1 Tree");
  T->Branch("event",&event);

  pythia.init();

 // Begin event loop. Generate event; skip if generation aborted.
  for (int iEvent = 0; iEvent < 10; ++iEvent) {
    if (!pythia.next()) continue;

    // Optionally list first event.
    //if (iEvent < 1) {pythia.info.list(); pythia.event.list();}

    // Fill the pythia event into the TTree.  
    // Warning: the files will rapidly become large if all events 
    // are saved. In some cases it may be convenient to do some 
    // processing of events and only save those that appear 
    // interesting for future analyses.
    T->Fill();

  // End event loop.
  }

  // Statistics on event generation.
  pythia.stat();

  //  Write tree.
  T->Print();
  T->Write();
  delete file;

  // Done.
  return 0;
}

But when i try to run it, I get to problems. The first is that, soon after the program prints Pythia header, it starts printing several errors and warnings like these

Error in <TStreamerInfo::Build>: Pythia8::Event: Pythia8::ParticleData* has no streamer or dictionary, data member particleDataPtr will not be saved
Warning in <TStreamerInfo::Build>: Pythia8::Particle: Pythia8::Vec4 has no streamer or dictionary, data member "pSave" will not be saved
Warning in <TStreamerInfo::Build>: Pythia8::Particle: Pythia8::Vec4 has no streamer or dictionary, data member "vProdSave" will not be saved
Warning in <TStreamerInfo::Build>: Pythia8::Particle: shared_ptr<Pythia8::ParticleDataEntry> has no streamer or dictionary, data member "pdePtr" will not be saved
Error in <TStreamerInfo::Build>: Pythia8::Particle: Pythia8::Event* has no streamer or dictionary, data member evtPtr will not be saved
Warning in <TStreamerInfo::Build>: __shared_ptr<Pythia8::ParticleDataEntry>: base class __shared_ptr_access<Pythia8::ParticleDataEntry,__gnu_cxx::_S_atomic,false,false> has no streamer or dictionary it will not be saved

And this go on for several Pythia objects (of the form Pythia8::“Object”). I tried looking how to solve these in the forum but got no luck. But then comes my second problem: At first the program still produced a readable ROOT file despite those errors and warnings, but with a few branches that were inaccessible (they showed a leaf with a ! sign on top, and didn’t load when I tried to open them), but now it doesn’t even does that. Right after it gives the first event listing, default of pythia, the program gives a warning and then crashes

Warning in <TBufferFile::WriteObjectAny>: since locale::_Impl has no public constructor
	which can be called without argument, objects of this class
	can not be read with the current library. You will need to
	add a default constructor before attempting to read it.

 *** Break *** segmentation violation



===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0  0x00007f6f45cea45a in __GI___wait4 (pid=20080, stat_loc=stat_loc
entry=0x7fffbe680a58, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1  0x00007f6f45cea41b in __GI___waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7fffbe680a58, options=options
entry=0) at ./posix/waitpid.c:38
#2  0x00007f6f45c50bcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3  0x00007f6f46b16824 in TUnixSystem::StackTrace() () from /home/jhoao/ROOT/root_install/lib/libCore.so
#4  0x00007f6f46b13b35 in TUnixSystem::DispatchSignals(ESignals) () from /home/jhoao/ROOT/root_install/lib/libCore.so
#5  <signal handler called>
#6  0x00007f6f46ab658e in TClass::GetClass(std::type_info const&, bool, bool, unsigned long, unsigned long) () from /home/jhoao/ROOT/root_install/lib/libCore.so
#7  0x00007f6f46ad2d30 in TIsAProxy::operator()(void const*) () from /home/jhoao/ROOT/root_install/lib/libCore.so
#8  0x00007f6f464e14a0 in TBufferIO::WriteObjectAny(void const*, TClass const*, bool) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#9  0x00007f6f464d43c2 in TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#10 0x00007f6f46761c96 in int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#11 0x00007f6f465afb84 in TStreamerInfoActions::GenericWriteAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#12 0x00007f6f464da6d5 in TBufferFile::WriteClassBuffer(TClass const*, void*) () from /home/jhoao/ROOT/root_install/lib/libRIO.so

And it continues until it gets to

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6  0x00007f6f46ab658e in TClass::GetClass(std::type_info const&, bool, bool, unsigned long, unsigned long) () from /home/jhoao/ROOT/root_install/lib/libCore.so
#7  0x00007f6f46ad2d30 in TIsAProxy::operator()(void const*) () from /home/jhoao/ROOT/root_install/lib/libCore.so
#8  0x00007f6f464e14a0 in TBufferIO::WriteObjectAny(void const*, TClass const*, bool) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#9  0x00007f6f464d43c2 in TBufferFile::WriteFastArray(void**, TClass const*, int, bool, TMemberStreamer*) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#10 0x00007f6f46761c96 in int TStreamerInfo::WriteBufferAux<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#11 0x00007f6f465afb84 in TStreamerInfoActions::GenericWriteAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) () from /home/jhoao/ROOT/root_install/lib/libRIO.so
#12 0x00007f6f464da6d5 in TBufferFile::WriteClassBuffer(TClass const*, void*) () from /home/jhoao/ROOT/root_install/lib/libRIO.so

At total there are around 64 lines of error after the crash, and I don’t why it started to happen, since I’ve made no changes to the program from when it had finished running despite the errors. Also, if it helps, here is the snippet of the Makefile where the program is running (I’m calling the file neural02.cc)

neural%.so: neural%Dct.cc neural%.h
        $(CXX) $^ -o $@ -DPY8ROOT -w $(CXX_SHARED) $(CXX_COMMON)\
                $(ROOT_LIB) $(shell $(ROOT_CONFIG) --cflags)
neural%Dct.cc: neural%.h neural%LinkDef.h
ifeq ($(ROOT_USE),true)
        $(ROOT_BIN)rootcling -f $@ -DPY8ROOT -I$(PREFIX_INCLUDE) $^
else
        $(error Error: $@ requires ROOT)
endif

neural%: $(PYTHIA) $$@.cc
ifeq ($(ROOT_USE),true)
        $(CXX) $@.cc -o $@ -w $(CXX_COMMON) $(ROOT_LIB)\
                $(shell $(ROOT_CONFIG) --cflags --glibs)
else
        $(error Error: $@ requires ROOT)
endif

This Makefile is in the examples directory of Pythia, and I tried writing this bit based on what was written for other examples which used ROOT.

I’ve been trying to solve this on my own for a few weeks now, but all of the forum posts I find are a little outdated. Also I don’t know much about how to edit and use these stuff of Makefile. If there is anything more which you need to know to might help me solve my problem, please let me know!

Welcome to the ROOT forum.

May be @pcanal can help.