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;
}
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.
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 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…
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:
Download Pythia8
Build a dictionary for the Event class
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:
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);
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
-----------------------------------------------------------------
| 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.
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
And, yes, Defineslot entered the repository at some point in 2017.
Let us know how the upgrade to a recent tag goes.
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