Error in <TTree::Branch>: The pointer specified for event is not of a class known to ROOT

Hello,

I was running the pythia82 standalone with the library from ROOT and
I found the following error :

Error in <TTree::Branch>: The pointer specified for event is not of a class known to ROOT

But everything work fine and i can created file .root from the simulation of the pythia.

The file running in the pythia is:

// main92.cc is a part of the PYTHIA event generator.
// Copyright (C) 2017 Torbjorn Sjostrand.
// PYTHIA is licenced under the GNU GPL version 2, see COPYING for details.
// Please respect the MCnet Guidelines, see GUIDELINES for details.

// This is a simple test program.
// Modified by Rene Brun and Axel Naumann to put the Pythia::event
// into a TTree.

// 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 soft/hard QCD processes
  Pythia pythia;
  
  
  pythia.readString("Beams:idA = 2212");				// Specifies Proton Beam
  pythia.readString("Beams:idB = 2212");				// Specifies Proton Beam
  pythia.readString("HardQCD:all = on");
  pythia.readString("PhaseSpace:pTHatMin = 80.");
  //pythia.readString("PhaseSpace:pTHatMax = 2.");
  pythia.readString("Beams:eCM = 7000.");
  //pythia.readString("Beams:frameType = 2");  // frame LAB
  //pythia.readString("Beams:eA = 100000.");   // 100 TeV :p
  //pythia.readString("Beams:eB = 0.");        //   0 TeV :p is at rest frame
  pythia.init();
  
  Float_t px, py, pz, e, Eta, pt, Phi;
  int id, numparticles;

  // Set up the ROOT TFile and TTree.
  TFile *file = TFile::Open("pythia8tree.root","recreate");
  Event *event = &pythia.event;
  TTree *T = new TTree("T","Tree");
  T->Branch("event",&event);
  T->Branch("px",&px);
  T->Branch("py",&py);
  T->Branch("pt",&pt);
  T->Branch("pz",&pz);
  T->Branch("e",&e);
  T->Branch("id",&id);
  T->Branch("Eta",&Eta);
  T->Branch("Phi",&Phi);

 // Begin event loop. Generate event; skip if generation aborted.

       for (int iEvent = 0; iEvent < 1; ++iEvent) {
         if (!pythia.next()) continue;
         
         numparticles = pythia.event.size();
         
         for (int i = 0; i < numparticles; ++i) {

         // 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.
         px = pythia.event[i].px();
         py = pythia.event[i].py();
         pt = pythia.event[i].pT();
         pz = pythia.event[i].pz(); 
         e  = pythia.event[i].e();
         id = pythia.event[i].id();
         Eta = pythia.event[i].eta();
         Phi = pythia.event[i].phi();
         
         T->Fill();
         
         
         
       // End event loop.
       }
       }

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

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

  // Done.
  return 0;
}

File .root (TTree)

******************************************************************************
*Tree    :T         : Tree                                                   *
*Entries :     1892 : Total =           65697 bytes  File  Size =          0 *
*        :          : Tree compression factor =   1.00                       *
******************************************************************************
*Br    0 :px        : px/F                                                   *
*Entries :     1892 : Total  Size=       8178 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :py        : py/F                                                   *
*Entries :     1892 : Total  Size=       8178 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    2 :pt        : pt/F                                                   *
*Entries :     1892 : Total  Size=       8178 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    3 :pz        : pz/F                                                   *
*Entries :     1892 : Total  Size=       8178 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    4 :e         : e/F                                                    *
*Entries :     1892 : Total  Size=       8172 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    5 :id        : id/I                                                   *
*Entries :     1892 : Total  Size=       8178 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    6 :Eta       : Eta/F                                                  *
*Entries :     1892 : Total  Size=       8184 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    7 :Phi       : Phi/F                                                  *
*Entries :     1892 : Total  Size=       8184 bytes  One basket in memory    *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*

What could be this? Someone have any explanation to this?

Thanks in advanced.

That means that you do not have a ROOT dictionary for that particular class. Please take a look at how to generate dictionaries at https://root.cern.ch/faq/how-generate-dictionary. Once you have a dictionary for the class that error message will go away.

Cheers,

@amadio

Thanks for the reply!

Now I understand part of the solution, but for me isn’t so clear, how
to created a dictionary, Where I can find the file myScript.cxx+
to load the libraries.

I’m using root 6.11

Cheers,
Andre

Hi Andre,

I would have a question: why storing kinematic quantities coming from the event and then the event itself? In addition, the event is saved identical numparticles time per generated collision (columns in the dataset are compressed, but still…) .
Wouldn’t this be a duplication of information? You say, correctly, in the comment that the file can become very large very quickly…

The class ROOT is complaining about is the Pythia::Event. As @amadio says, in order to persistify classes, ROOT needs dictionaries. We can support you in this, but before maybe it’s better to go through the questions above…

Cheers,
D

Hi Andre,

since you are on 6.11, you can take advantage of TDataFrame. Basically, TDataFrame is a tool that allows you to formulate your analysis or MC generation in a declarative manner. TDataFrame is rather powerful: it aims to take away cumbersome tasks from users and get out of their way. It allows also to seamlessly write parallelised code. In the following example, I provide a recipe that will allow you:

  1. Download Pythia8
  2. Build a dictionary for the Event class
  3. Build a program to create a generated dataset in root format containing pythia events. Two parameters are available: number of cpus and total number of events to be generated.

The program tdfGeneration.cpp: As you can see the overhead of TDataFrame in terms of lines of code is minimal:

#include <ROOT/TDataFrame.hxx>
#include <Pythia8/Pythia.h>

int main(int argc, char** argv){

   int nworkers = 1;
   unsigned nevents = 1000;
   if (argc == 2) {
      nworkers = std::atoi(argv[1]);
   }
   if (argc == 3) {
      nworkers = std::atoi(argv[1]);
      nevents = std::atoi(argv[2]);
   }

   // Generate the Pythias. The random seed is different for each instance
   Pythia8::Pythia pythias[nworkers];
   auto seed = 1;
   for (auto&& pythia : pythias) {
      pythia.readString("Beams:idA = 2212");				// Specifies Proton Beam
      pythia.readString("Beams:idB = 2212");				// Specifies Proton Beam
      pythia.readString("HardQCD:all = on");
      pythia.readString("PhaseSpace:pTHatMin = 80.");
      pythia.readString("Beams:eCM = 7000.");
      pythia.readString("Random:setSeed = on");
      pythia.readString("Random:seed = " + std::to_string(seed++));
      pythia.init();
   }

   // go parallel if needed
   if (nworkers!=1) ROOT::EnableImplicitMT(nworkers);

   // The "generator function"
   auto genFunc = [&](unsigned int slot) { 
      while (!pythias[slot].next()) continue;
      return &pythias[slot].event;
   };

   // Use the TDF to write out
   ROOT::Experimental::TDataFrame tdf(nevents);
   tdf.DefineSlot("event", genFunc)
      .Snapshot<Pythia8::Event*>("tree", "hardQCD.root", {"event"});
}

Now, the instruction to get Pythia8:

wget http://home.thep.lu.se/~torbjorn/pythia8/pythia8226.tgz
tar -zxf pythia8226.tgz
mkdir pythia
cd pythia8226
./configure --with-root=$ROOTSYS --enable-shared --prefix=`pwd`/../pythia
make -j 6
make install
cd ..

And now, the instruction to setup the environment and build the dictionary:

export LD_LIBRARY_PATH=pythia/lib/:$LD_LIBRARY_PATH
export ROOT_INCLUDE_PATH=pythia/include
rootcling  -f pythiaDict.cc  -rml libpythiaDict.so -rmf libpythiaDict.rootmap pythia8226/examples/main92.h ./pythia8226/examples/main92LinkDef.h
g++ -fPIC -shared -o libpythiaDict.so pythiaDict.cc -I pythia/include/ -L pythia/lib/ -l pythia8 `root-config --cflags --libs`
g++ tdfGeneration.cpp -o tdfGeneration -I pythia/include/ -L pythia/lib/ -l pythia8 `root-config --cflags --libs` -lTreePlayer

Now, to generate 100 pp collisions resulting in hard QCD processes on 8 cpus in parallel, just type:

./tdfGeneration 8 100

This should allow you to profitably use all of the cores at your disposal.

I hope that helps.

Cheers,
D

1 Like

Ohh … I don’t see this. Now i understand your question, I’m storing kinematics variables because T->Branch("event",&event); wasn’t storing the variables from the event, but now I removed T->Branch("event",&event);

Thanks for the quick answer and very good script.

I’m following your instruction. But I got the error in the command line
g++ tdfGeneration.cpp -o tdfGeneration -I pythia/include/ -L pythia/lib/ -l pythia8root-config --cflags --libs-lTreePlayer

Error:

tdfGeneration.cpp: In function ‘int main(int, char**)’:
tdfGeneration.cpp:41:8: error: ‘class ROOT::Experimental::TDataFrame’ has no member named ‘DefineSlot’
    tdf.DefineSlot("event", genFunc)
        ^
tdfGeneration.cpp:42:31: error: expected primary-expression before ‘*’ token
       .Snapshot<Pythia8::Event*>("tree", "hardQCD.root", {"event"});
                               ^
tdfGeneration.cpp:42:32: error: expected primary-expression before ‘>’ token
       .Snapshot<Pythia8::Event*>("tree", "hardQCD.root", {"event"});
                                ^
tdfGeneration.cpp:42:58: error: expected primary-expression before ‘{’ token
       .Snapshot<Pythia8::Event*>("tree", "hardQCD.root", {"event"});
                                                          ^
tdfGeneration.cpp:42:58: error: expected ‘)’ before ‘{’ token

Cheers,
Andre

Hi Andre,

odd: it’s here https://root.cern.ch/doc/master/classROOT_1_1Experimental_1_1TDF_1_1TInterface.html#a662a9308c277f2067345233bba5c02c9

Are you sure that you are not using ROOT 6.10?

Cheers,
D

Hi Danilo,

I’m using the version:

   -----------------------------------------------------------------
  | Welcome to ROOT 6.11/01                     http://root.cern.ch |
  |                                    (c) 1995-2017, The ROOT Team |
  | Built for linuxx8664gcc                                         |
  | From heads/master@v6-09-02-1265-g778aaea, Jun 11 2017, 12:32:00 |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'      |
   -----------------------------------------------------------------

I’m trying to upgrade to version root 6.11/03,

In the version root 6.11/01 in the file TDataFrame.hxx(12/2016) is not define the function tdf.DefineSlot. But in the version root 6.11/03 in the file TDataFrame.hxx(03/2017) have the function tdf.DefineSlot.

Cheers,
Andre

Hi Andre,

that’s the answer.
If the version of ROOT is not released, we do not associate to a tag a particular commit. This means that X.YY/Z could mean several (hundred of) hashes :slight_smile:
And, yes, Defineslot entered the repository at some point in 2017.
Let us know how the upgrade to a recent tag goes.

Cheers,
D

Hi,
you should do a git fetch --tags and then git checkout v6-11-02, that’s the revision of the 6.11 devel release.

As @eguiraud said, or, fetch the tarball of the sources from here: https://root.cern.ch/content/release-61102

Cheers,
D

Thanks for the help, guys!

I did uninstall and install version of root 6.11/03, I don’t know how to use the command to upgrade the root:

git fetch --tags and git checkout v6-11-02 (You can explain to me how to use this command? )

Now I can running the pythia with your suggestion @Danilo and the file hardQCD.root is created, that I believe to be everything all right.

The function DefineSlot is define in the file: TDFInterface.hxx (03/2017) (root 6.11/03)

Cheers,
Andre

Hi Andre’,

so you installed from the tarball and it works? Great!
The question you have is more related to git and perhaps any of the answers a search engine can give you are far better than the ones you can get on this forum :slight_smile:

Cheers,
D

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.