I'm using ROOT 6.15/01 Built for linuxx8664gcc From heads/master@v6-13-04-218-g3ec307bbe3
Hi, All
I am trying to use the ROOT class in one example main112.cc (PYTHIA8230)
To download and Install in the Linux Ubuntu, the command line:
$ wget http://home.thep.lu.se/~torbjorn/pythia8/pythia8230.tgz
$ tar -zxf pythia8230.tgz
$ cd pythia8230
$ ./configure --enable-shared --with-root=$ROOTSYS
$ sudo make -j4 && sudo make install
After install:
Put in the bashrc the following lines:
open the bashrc: gedit ~/.bashrc
#Pythia/root Env. Variables
export PYTHIA8=/home/user/pythia8230
export PYTHIA8DATA=$PYTHIA8/xmldoc
export ROOTSYS=/opt/root6
export PATH=$ROOTSYS/bin:$PATH
export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH
#end of My variables
Update the bashrc . ~/.bashrc
$ cd examples$ ls
main112.cc main112Dct.cc main112Dct_rdict.pcm main112.h main112LinkDef.h Makefile
main112.h (447 Bytes)
main112Dct.cc (209.1 KB)
main112LinkDef.h (2.2 KB)
makefile.txt (6.5 KB) (change this file to stay without extension i.e. Makefile)
the change the example main112.cc to put my ROOT classes:
I’m using this example to get the output : px, py, pz
My new main112.cc (3.9 KB):
// main112.cc is a part of the PYTHIA event generator.
// Copyright (C) 2017 Torbjorn Sjostrand.
// Simple program Heavy Ion Collisions.
// Modified by Andre Vieira da Silva in 2018-05-30
// This file contains the main class for event generation.
// Pythia: provide the main user interface to everything else.
#include "Pythia8/Pythia.h"
// You need to include this to get access to the HIInfo object for HeavyIons.
#include "Pythia8/HeavyIons.h"
// ROOT, for saving Pythia events as trees in a file.
#include "TTree.h"
#include "TFile.h"
//Library Math
#include "TMath.h"
#include "sstream"
//load Library
#include "MyParticle.cxx"
#include "MyEvent.cxx"
using namespace Pythia8;
int main() {
Pythia pythia;
//define variables:
Double_t px, py, pz, pt, E, eta, phi;
int id;
// Set up the ROOT TFile and TTree.
TFile *file = TFile::Open("pythia_heavy_ion.root","recreate");
//Define TTRee "Tree" with the variable of the event
TTree *Tree = new TTree("Tree","Tree");
MyEvent *event = new MyEvent;
Tree->Branch("event", &event);
// Setting the beams.
pythia.readString("Beams:idA = 2212"); // proton
pythia.readString("Beams:idB = 1000822080"); // Lead Ion
pythia.readString("Beams:eA = 4000"); // Energy beam A
pythia.readString("Beams:eB = 1570"); // Energy beam B
pythia.readString("Beams:frameType = 2"); // LAB Frame
// Initialize the Angantyr model to fit the total and semi-includive
// cross sections in Pythia within some tolerance.
pythia.readString("HeavyIon:SigFitErr = "
"0.02,0.02,0.1,0.05,0.05,0.0,0.1,0.0");
// These parameters are typicall suitable for sqrt(S_NN)= 5.02 TeV
pythia.readString("HeavyIon:SigFitDefPar = "
"17.24,2.15,0.33,0.0,0.0,0.0,0.0,0.0");
// A simple genetic algorithm is run for 20 generations
// to fit the parameters.
pythia.readString("HeavyIon:SigFitNGen = 20");
// Initialise Pythia.
pythia.init();
// Number of events!
int nEvents = 10;
// Loop over events.
for ( int iEvent = 0; iEvent < nEvents; ++iEvent ) {
// make sure the event object is empty
event->Clear();
if ( !pythia.next() ) continue;
//Loop over the particles of the event
for (int i = 0; i < pythia.event.size(); ++i) {
if ( pythia.event[i].isFinal()) {
// Create a particle and set its properties
MyParticle *part = new MyParticle();
px = pythia.event[i].px();
py = pythia.event[i].py();
pz = pythia.event[i].pz();
part->SetPx(px);
part->SetPy(py);
part->SetPz(pz);
part->PrintInfo();
// add this particle to the current event
event->AddParticle(part);
}
}
//Fill the TTRee "Tree" with this event
Tree->Fill();
}
// Print the screen (terminal) the information about the TTRee particle
// Tree->Print();
// Record Tree Object in the file
Tree->Write();
// The run is over, so we write out some statistics.
// I moved the delete statement here.
file->Close();
delete file;
cout<< " And we're done!" << endl;
return 0;
}
This is running with the following files:
Load library:
MyParticle.cxx (893 Bytes) - Class implementation of MyParticle
MyParticle.h (2.2 KB) - Class definition of MyParticle
MyEvent.cxx (1.9 KB) - Class implementation of MyEvent
MyEvent.h (1.2 KB) - Class definition of MyEvent
My problem is: `undefined reference to MyEvent::Class() and
undefined reference to MyParticle::Class()
Error:
andre@andre-QBEX-H61H2-M17:~/pythia8230/examples$ make main112
g++ main112.cc main112.so -o main112 -w -I/opt/root6/include -I../include -O2 -pedantic -W -Wall -Wshadow -fPIC -L../lib -Wl,-rpath,../lib -lpythia8 -ldl \
`root-config --cflags` -Wl,-rpath,./\
-Wl,-rpath,/opt/root6/lib `/opt/root6/bin/root-config --glibs`
/tmp/ccmBzrIp.o: In function `MyEvent::IsA() const':
main112.cc:(.text._ZNK7MyEvent3IsAEv[_ZNK7MyEvent3IsAEv]+0x1): undefined reference to `MyEvent::Class()'
/tmp/ccmBzrIp.o: In function `MyEvent::ShowMembers(TMemberInspector&) const':
main112.cc:(.text._ZNK7MyEvent11ShowMembersER16TMemberInspector[_ZNK7MyEvent11ShowMembersER16TMemberInspector]+0xd): undefined reference to `MyEvent::Class()'
/tmp/ccmBzrIp.o: In function `MyParticle::ShowMembers(TMemberInspector&) const':
main112.cc:(.text._ZNK10MyParticle11ShowMembersER16TMemberInspector[_ZNK10MyParticle11ShowMembersER16TMemberInspector]+0xd): undefined reference to `MyParticle::Class()'
/tmp/ccmBzrIp.o: In function `MyParticle::IsA() const':
main112.cc:(.text._ZNK10MyParticle3IsAEv[_ZNK10MyParticle3IsAEv]+0x1): undefined reference to `MyParticle::Class()'
/tmp/ccmBzrIp.o: In function `MyEvent::CheckTObjectHashConsistency() const':
main112.cc:(.text._ZNK7MyEvent27CheckTObjectHashConsistencyEv[_ZNK7MyEvent27CheckTObjectHashConsistencyEv]+0x77): undefined reference to `MyEvent::Class()'
/tmp/ccmBzrIp.o: In function `MyParticle::CheckTObjectHashConsistency() const':
main112.cc:(.text._ZNK10MyParticle27CheckTObjectHashConsistencyEv[_ZNK10MyParticle27CheckTObjectHashConsistencyEv]+0x7a): undefined reference to `MyParticle::Class()'
/tmp/ccmBzrIp.o: In function `_GLOBAL__sub_I_main112.cc':
main112.cc:(.text.startup+0x5de): undefined reference to `ROOT::GenerateInitInstance(MyParticle const*)'
main112.cc:(.text.startup+0x5f9): undefined reference to `ROOT::GenerateInitInstance(MyEvent const*)'
/tmp/ccmBzrIp.o:(.data.rel.ro._ZTV10MyParticle[_ZTV10MyParticle]+0x1e0): undefined reference to `MyParticle::Streamer(TBuffer&)'
/tmp/ccmBzrIp.o:(.data.rel.ro._ZTV7MyEvent[_ZTV7MyEvent]+0x48): undefined reference to `MyEvent::Streamer(TBuffer&)'
collect2: error: ld returned 1 exit status
Makefile:165: recipe for target 'main112' failed
make: *** [main112] Error 1
Sorry for a long description,
Someone can help me with some tip?
Thanks,
Cheers, Andre