TVectors3 Angle() method

I am new to TVectors3 class and I am trying to calculate angle between two gammas like this:

relative_angle = gamma_v2.Angle(gamma_v1);

I would then like to filld a 3D histogram

                     relative_angle_degrees = relative_angle*(180/M_PI);

                     // cout << " " << gamma1 << " " << gamma2 << " " << relative_angle_degrees << endl;

                     ggtheta->Fill(gamma1,gamma2,relative_angle_degrees); //Filling it in degrees and not radians!

But whenever I try to run it it gives me the *** Break *** segmentation violation error. It prints out the angles fine but the problem arises while trying to fill the 3D histogram.
Is there a particular way one needs to use the output of Angle?

Welcome @ShiShi1122 to the ROOT forum!

For the information you give, it’s impossible to tell where the error is. Can you maybe share the full output of the error and your analysis script, so we can reproduce the problem and help?


Here is the relevant part of the big script I have, hope it helps understand the issue better:
I am not sure if the Angle() method returns a value or a pointer to the value:

for (int index_m = l + 1; index_m < static_cast<int>(detector.size()); index_m++) {
    gamma1 = calibrated_energies[l];
    gamma2 = calibrated_energies[index_m];

    if (gamma1 > 0 && gamma2 > 0 && ( - < 10)) {
        gg->Fill(gamma1, gamma2);

        gamma_v1.SetMagThetaPhi(radius, thetas[l], phis[l]);
        gamma_v2.SetMagThetaPhi(radius, thetas[index_m], phis[index_m]);
        relative_angle = gamma_v2.Angle(gamma_v1);
        relative_angle_degrees = relative_angle * (180 / M_PI);

        // cout << " " << gamma1 << " " << gamma2 << " " << relative_angle_degrees << endl;

        ggtheta->Fill(gamma1, gamma2, relative_angle_degrees); // Filling it in degrees and not radians!

And here is the full error:

** Break *** segmentation violation
Generating stack trace…
0x00007f9f1350e869 in
0x00007f9f23ce712e in
0x00007f9f1f92d68a in cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) + 0x24a from /home/shishi/packages/root/root_install/lib/
0x00007f9f1f92f06d in cling::Interpreter::EvaluateInternal(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) + 0x15d from /home/shishi/packages/root/root_install/lib/
0x00007f9f1f92f2fc in cling::Interpreter::process(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, cling::Value*, cling::Transaction**) + 0x13c from /home/shishi/packages/root/root_install/lib/
0x00007f9f1f9be6df in cling::MetaProcessor::process(char const*, cling::Interpreter::CompilationResult&, cling::Value*) + 0x21f from /home/shishi/packages/root/root_install/lib/
0x00007f9f1f89ae16 in from /home/shishi/packages/root/root_install/lib/
0x00007f9f1f8ab0ad in TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) at /home/shishi/packages/root/root-6.08.06/core/meta/src/TCling.cxx:2049 from /home/shishi/packages/root/root_install/lib/
0x00007f9f2364c9c8 in TApplication::ProcessLine(char const*, bool, int*) at /home/shishi/packages/root/root-6.08.06/core/base/src/TApplication.cxx:1005 from /home/shishi/packages/root/root_install/lib/
0x00007f9f23a9e3ce in TRint::ProcessLineNr(char const*, char const*, int*) at /home/shishi/packages/root/root-6.08.06/core/rint/src/TRint.cxx:749 from /home/shishi/packages/root/root_install/lib/
0x00007f9f23a9e71f in TRint::HandleTermInput() at /home/shishi/packages/root/root-6.08.06/core/rint/src/TRint.cxx:616 from /home/shishi/packages/root/root_install/lib/
0x00007f9f2375a1ed in TUnixSystem::CheckDescriptors() at /home/shishi/packages/root/root-6.08.06/core/unix/src/TUnixSystem.cxx:1321 from /home/shishi/packages/root/root_install/lib/
0x00007f9f2375b4bb in TUnixSystem::DispatchOneEvent(bool) at /home/shishi/packages/root/root-6.08.06/core/unix/src/TUnixSystem.cxx:1077 from /home/shishi/packages/root/root_install/lib/
0x00007f9f236a83f4 in TSystem::InnerLoop() at /home/shishi/packages/root/root-6.08.06/core/base/src/TSystem.cxx:409 from /home/shishi/packages/root/root_install/lib/
0x00007f9f236a700f in TSystem::Run() at /home/shishi/packages/root/root-6.08.06/core/base/src/TSystem.cxx:359 from /home/shishi/packages/root/root_install/lib/
0x00007f9f23649f5f in TApplication::Run(bool) at /home/shishi/packages/root/root-6.08.06/core/base/src/TApplication.cxx:1158 from /home/shishi/packages/root/root_install/lib/
0x00007f9f23a9fc3e in TRint::Run(bool) at /home/shishi/packages/root/root-6.08.06/core/rint/src/TRint.cxx:466 from /home/shishi/packages/root/root_install/lib/
0x000055975bbc42fc in main + 0x4c from /home/shishi/packages/root/root_install/bin/root.exe
0x00007f9f226512e1 in __libc_start_main + 0xf1 from /lib/x86_64-linux-gnu/
0x000055975bbc435a in _start + 0x2a from /home/shishi/packages/root/root_install/bin/root.exe

I only get the error when I try:

ggtheta->Fill(gamma1, gamma2, relative_angle_degrees); 

otherwise the code works okay.

Looks like you have a messed up ROOT installation, like I can see for example at these lines here:

TRint::Run(bool) at ~/packages/root/root-6.08.06/core/rint/src/TRint.cxx:466 from ~/packages/root/root_install/lib/
main + 0x4c from ~/packages/root/root_install/bin/root.exe
__libc_start_main + 0xf1 from /lib/x86_64-linux-gnu/
_start + 0x2a from ~/packages/root/root_install/bin/root.exe

You start ROOT from root_install/bin, but then it loads libraries from some very old ROOT version in root/root-6.08.06. Can that folder maybe be deleted, or can you avoid sourcing it in your environment?

I do not have a choice on changing the root as I am working on some old shared cluster which has very old version of Debian. Is there any other way to fix it w/o changing the version?

Hi! You don’t have to change the version you are currently using. You should just make sure there is not also this old 6.08 version sourced in your environment (e.g. by deleting this folder, or renaming it for the moment if you are afraid to break someone elses workflow). Or maybe the path to it is set in .bashrc and you can remove the line there?

Sorry there is no other solution, if you have multiple ROOT library directories in the library path, things are bound to break.