Error in reading root file generated by PYTHIA for heavy ion run

I am running PYTHIA 8.2 as a plugin to ROOT 6.14/06 in CentOS 7.
I have saved the output of PYTHIA run in a root tree format. I have generated root file for both pp and heavy ion collision. When I am trying to read this root file for the purpose of analyis, it is reading properly in case of pp data. However when I am trying to read charge of each track in case of heavy ion collision, I am gettinf following error

 **warning: null passed to a callee that requires a non-null argument [-Wnonnull]**
**Double_t ch = partPDG->Charge() ;**
**                        ^~~~~~~"**

Part of code which I am using to read this is

====================================================
//Particle Loop
      for (Int_t ip = 0; ip < np; ip++) {
TParticle* part = (TParticle*) particles->At(ip);
        Int_t ist = part->GetStatusCode();
        if (ist <= 0) continue;
         // Positive codes are final particles.

Int_t pdg = part->GetPdgCode();
TParticlePDG* partPDG = part->GetPDG(pdg);
Double_t ch = partPDG->Charge() ;
====================================================

1 Like

Hi,

this line

TParticlePDG* partPDG = part->GetPDG(pdg);

is pretty weird. You shouldn’t feed the pdg into the GetPDG(), so try

TParticlePDG* partPDG = part->GetPDG();

instead. Also, you don’t really need the previous line, the

Int_t pdg = part->GetPdgCode();

Hello @rohit,

Weclome to the ROOT forum! I agree with @yus; according to TParticle::GetPDG() documentation, you should pass 0 (or omit the argument) to get a (uncached) pointer to a TParticlePDG. Therefore, as @yus already suggested, that line should be changed to:

TParticlePDG *partPDG = part->GetPDG();

Cheers,
J.

Dear @yus @jalopezg
Thanks for your reply.
I tried implementing the changes suggested by you.
But the problem still exist for heavy-ion data.
Also the same code is working for pp data even after implementing the changes suggested above.
Below is the full error which I am getting on terminal

==================================================================
Generating stack trace…
0x00007f3717f10eb7 in from /home/grohit/HepSoft/root_6_14/lib/libCling.so
0x00007f3717f1130f in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0x1df from /home/grohit/HepSoft/root_6_14/lib/libCling.so
0x00007f3717f11af7 in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Value*, cling::Transaction**, bool) + 0x177 from /home/grohit/HepSoft/root_6_14/lib/libCling.so
0x00007f3717fc1acd in cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) + 0x1ed from /home/grohit/HepSoft/root_6_14/lib/libCling.so
0x00007f3717e66cce in from /home/grohit/HepSoft/root_6_14/lib/libCling.so
0x00007f3717e7c15d in from /home/grohit/HepSoft/root_6_14/lib/libCling.so
0x00007f371d535e4d in TApplication::ProcessLine(char const*, bool, int*) at /home/grohit/HepSoft/root_6_14/src/core/base/src/TApplication.cxx:1021 from /home/grohit/HepSoft/root_6_14/lib/libCore.so
0x00007f371d9fd7c2 in TRint::ProcessLineNr(char const*, char const*, int*) at /home/grohit/HepSoft/root_6_14/src/core/rint/src/TRint.cxx:741 from /home/grohit/HepSoft/root_6_14/lib/libRint.so
0x00007f371d9fdb34 in TRint::HandleTermInput() at /home/grohit/HepSoft/root_6_14/src/core/rint/src/TRint.cxx:608 from /home/grohit/HepSoft/root_6_14/lib/libRint.so
0x00007f371d68a900 in TUnixSystem::CheckDescriptors() at /home/grohit/HepSoft/root_6_14/src/core/unix/src/TUnixSystem.cxx:1322 from /home/grohit/HepSoft/root_6_14/lib/libCore.so
0x00007f371d68c298 in TUnixSystem::DispatchOneEvent(bool) at /home/grohit/HepSoft/root_6_14/src/core/unix/src/TUnixSystem.cxx:1078 from /home/grohit/HepSoft/root_6_14/lib/libCore.so
0x00007f371d5a15a1 in TSystem::Run() at /home/grohit/HepSoft/root_6_14/src/core/base/src/TSystem.cxx:411 from /home/grohit/HepSoft/root_6_14/lib/libCore.so
0x00007f371d533e3f in TApplication::Run(bool) at /home/grohit/HepSoft/root_6_14/src/core/base/src/TApplication.cxx:1174 from /home/grohit/HepSoft/root_6_14/lib/libCore.so
0x00007f371d9ff223 in TRint::Run(bool) at /home/grohit/HepSoft/root_6_14/src/core/rint/src/TRint.cxx:458 from /home/grohit/HepSoft/root_6_14/lib/libRint.so
0x00005612a5a7ca1c in from /home/grohit/HepSoft/root_6_14/bin/root.exe
0x00007f371c9c8b97 in __libc_start_main + 0xe7 from /lib/x86_64-linux-gnu/libc.so.6
0x00005612a5a7ca7a in _start + 0x2a from /home/grohit/HepSoft/root_6_14/bin/root.exe
Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.
Execution of your code was aborted.
In file included from input_line_10:1:
/home/grohit/HepSoft/pythia_in_root/from_VM/pythia/pythia_in_HIC_41_201/read_pythia_draw_N_ch.C:62:19: warning: null passed to a callee that requires a non-null argument [-Wnonnull]
Double_t charge = partPDG->Charge() ;
^~~~~~~

==================================================================

Hi,
the error seems to indicate that partPDF is a nullptr, or in other words that part->GetPDG(); returns nullptr. Can you verify that’s the case?

If yes, in case the other participants in the thread do not have better ideas, it would be great if you could provide a minimal setup with which we can reproduce the problem (e.g. ROOT file + a few lines of runnable code).

Cheers,
Enrico

Hi,

I agree with @eguiraud, try replacing

TParticlePDG* partPDG = part->GetPDG();
Double_t ch = partPDG->Charge() ;

with

TParticlePDG* partPDG = part->GetPDG();
if (partPDG)
    Double_t ch = partPDG->Charge();
else
    printf("partPDG is a null pointer!\n");

Hi,
I managed to find out the problem. The problem is indeed related to null pointer
Actually in case of PYTHIA event output, first two tracks are the beam particles, so for pp data, first two will have pdg 2212.
However in case of heavy ion, first two pdg are 1000381019 and 1000441039 which is not a standard pdg code. Hence if we pass it through
TParticlePDG* partPDG = part->GetPDG();
it will not be able to understand this pdg and hence it gives the error as warning: null passed to a callee that requires a non-null argument.
So while reading root file we have to somehow skip first two line.
Thanks everyone for help.

1 Like

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