# " \*\*\* Break \*\*\* segmentation violation " while trying to use TLorentzVector

**URL:** <https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845>\
**Category:** Newbie\
**Tags:** tree, hist, root\
**Created:** [October 5, 2022, 4:27pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845 "2022-10-05T16:27:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raseeb\_Haroon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/raseeb_haroon/32/30638_2.png) [@Raseeb\_Haroon](https://root-forum.cern.ch/u/Raseeb_Haroon)\
**Post date:** [October 5, 2022, 4:27pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/1 "2022-10-05T16:27:36Z")

</div>

Hi everybody, I have been trying to reconstruct the Z boson using Pythia output, I am getting a perfect .root file and histogram. Here I was trying to use the tree and LorentzVector to reconstruct the Z boson. Any help would be great.

`root [0]  
Processing tutorial9b.C…

\*\*\* Break \*\*\* segmentation violation

**===========================================================**  
**There was a crash.**  
**This is the entire stack trace of all threads:**  
**===========================================================**  
**#0 0x00007f49b3c3a45a in \_\_GI\_\_\_wait4 (pid=5723, stat\_loc=stat\_loc**  
**entry=0x7ffe9efe9298, options=options**  
**entry=0, usage=usage**  
**entry=0x0) at …/sysdeps/unix/sysv/linux/wait4.c:30**  
**#1 0x00007f49b3c3a41b in \_\_GI\_\_\_waitpid (pid=, stat\_loc=stat\_loc**  
**entry=0x7ffe9efe9298, options=options**  
**entry=0) at ./posix/waitpid.c:38**  
**#2 0x00007f49b3ba0bcb in do\_system (line=) at …/sysdeps/posix/system.c:171**  
**#3 0x00007f49b42ee2d4 in TUnixSystem::StackTrace() () from /home/raseeb/root/lib/libCore.so.6.26**  
**#4 0x00007f49b42eb5e5 in TUnixSystem::DispatchSignals(ESignals) () from /home/raseeb/root/lib/libCore.so.6.26**  
**#5**  
**#6 0x00007f49b3fc45b8 in ?? ()**  
**#7 0x01003a00872cf96d in ?? ()**  
**#8 0x6400000088010000 in ?? ()**  
**#9 0x00007f49afbad380 in ?? () from /home/raseeb/root/lib/libCling.so**  
**#10 0x0000000000000000 in ?? ()**  
**===========================================================**

**The lines below might hint at the cause of the crash.**  
**You may get help by asking at the ROOT forum [ROOT Forum](https://root.cern/forum)**  
**Only if you are really convinced it is a bug in ROOT then please submit a**  
**report at [Sign in to GitHub · GitHub](https://root.cern/bugs) Please post the ENTIRE stack trace**  
**from above as an attachment in addition to anything else**  
**that might help us fixing this issue.**  
**===========================================================**  
**#6 0x00007f49b3fc45b8 in ?? ()**  
**#7 0x01003a00872cf96d in ?? ()**  
**#8 0x6400000088010000 in ?? ()**  
**#9 0x00007f49afbad380 in ?? () from /home/raseeb/root/lib/libCling.so**  
**#10 0x0000000000000000 in ?? ()**  
**===========================================================**

`

_ROOT Version:_ 6.26/06  
_Platform:_ Ubuntu 22.04.1 LTS  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 5, 2022, 5:46pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/2 "2022-10-05T17:46:59Z")

</div>

Maybe you need to ask the author(s) of the “`tutorial9b.C`” macro.

---

<div class="post-metadata">

**Author:** ![Raseeb\_Haroon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/raseeb_haroon/32/30638_2.png) [@Raseeb\_Haroon](https://root-forum.cern.ch/u/Raseeb_Haroon)\
**Post date:** [October 5, 2022, 6:00pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/3 "2022-10-05T18:00:49Z")

</div>

I am the author of the file.  
[tutorial9b.C](https://root-forum.cern.ch/uploads/short-url/3YSdRggTYzRRLIo6qZqzWFaNhNj.C) (972 Bytes)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 5, 2022, 6:18pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/4 "2022-10-05T18:18:32Z")

</div>

What do you get from: `tree->Print();`

---

<div class="post-metadata">

**Author:** ![Raseeb\_Haroon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/raseeb_haroon/32/30638_2.png) [@Raseeb\_Haroon](https://root-forum.cern.ch/u/Raseeb_Haroon)\
**Post date:** [October 5, 2022, 6:34pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/5 "2022-10-05T18:34:21Z")

</div>

> [@Wile\_E\_Coyote](#):
>
> ;

This is what I’m getting.

```auto
root [0] 
Processing tutorial9b.C...
******************************************************************************
*Tree :tree : tree *
*Entries : 7811 : Total = 347702 bytes File Size = 242518 *
* : : Tree compression factor = 1.42 *
******************************************************************************
*Br 0 :id : id/I *
*Entries : 7811 : Total Size= 31786 bytes File Size = 258 *
*Baskets : 1 : Basket Size= 32000 bytes Compression= 121.37 *
*............................................................................*
*Br 1 :m : m/D *
*Entries : 7811 : Total Size= 63101 bytes File Size = 565 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 110.84 *
*............................................................................*
*Br 2 :pT : pT/D *
*Entries : 7811 : Total Size= 63107 bytes File Size = 59539 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.05 *
*............................................................................*
*Br 3 :eta : eta/D *
*Entries : 7811 : Total Size= 63113 bytes File Size = 60731 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.03 *
*............................................................................*
*Br 4 :phi : phi/D *
*Entries : 7811 : Total Size= 63113 bytes File Size = 60626 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.03 *
*............................................................................*
*Br 5 :eng : eng/D *
*Entries : 7811 : Total Size= 63113 bytes File Size = 60061 *
*Baskets : 2 : Basket Size= 32000 bytes Compression= 1.04 *
*............................................................................*

 ***Break*** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:
===========================================================
#0 0x00007f3d3e4f945a in __GI___ wait4 (pid=4571, stat_loc=stat_loc
entry=0x7ffc4530b898, options=options
entry=0, usage=usage
entry=0x0) at ../sysdeps/unix/sysv/linux/wait4.c:30
#1 0x00007f3d3e4f941b in __GI___ waitpid (pid=<optimized out>, stat_loc=stat_loc
entry=0x7ffc4530b898, options=options
entry=0) at ./posix/waitpid.c:38
#2 0x00007f3d3e45fbcb in do_system (line=<optimized out>) at ../sysdeps/posix/system.c:171
#3 0x00007f3d3ebad2d4 in TUnixSystem::StackTrace() () from /home/raseeb/root/lib/libCore.so.6.26
#4 0x00007f3d3ebaa5e5 in TUnixSystem::DispatchSignals(ESignals) () from /home/raseeb/root/lib/libCore.so.6.26
#5 <signal handler called>
#6 0x00007f3d3e8834e4 in ?? ()
#7 0x5f6461704762696c in ?? ()
#8 0x63702e7463696472 in ?? ()
#9 0x00007f3d3a46c380 in ?? () from /home/raseeb/root/lib/libCling.so
#10 0x0000000000000000 in ?? ()
===========================================================

The lines below might hint at the cause of the crash.
You may get help by asking at the ROOT forum https://root.cern/forum
Only if you are really convinced it is a bug in ROOT then please submit a
report at https://root.cern/bugs Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#6 0x00007f3d3e8834e4 in ?? ()
#7 0x5f6461704762696c in ?? ()
#8 0x63702e7463696472 in ?? ()
#9 0x00007f3d3a46c380 in ?? () from /home/raseeb/root/lib/libCling.so
#10 0x0000000000000000 in ?? ()
===========================================================

Root > 

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 5, 2022, 6:50pm UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/6 "2022-10-05T18:50:15Z")

</div>

```cpp
{
  TFile *f = TFile::Open("tutorial9.root");
  TTree *t; f->GetObject("tree", t);
  Int_t id;
  Double_t m, pT, eta, phi, eng;
  t->SetBranchAddress("id" , &id );
  t->SetBranchAddress("m" , &m );
  t->SetBranchAddress("pT" , &pT );
  t->SetBranchAddress("eta", &eta);
  t->SetBranchAddress("phi", &phi);
  t->SetBranchAddress("eng", &eng);
  gROOT->cd(); // newly created histograms should go here
  Long64_t n = t->GetEntries();
  for (Long64_t i = 0; i < n; i++) {
    t->GetEntry(i);
    std::cout << id << " " << m << " " << pT << " ... " << eng << "\n";
  }
  t->ResetBranchAddresses(); // disconnect from local variables
  delete f; // automatically deletes "t", too
}

```

---

<div class="post-metadata">

**Author:** ![Raseeb\_Haroon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/raseeb_haroon/32/30638_2.png) [@Raseeb\_Haroon](https://root-forum.cern.ch/u/Raseeb_Haroon)\
**Post date:** [October 6, 2022, 4:01am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/7 "2022-10-06T04:01:18Z")

</div>

I ran this code in a seperate macro. The forum wouldn’t let me post the entire output so I have saved it in a .txt file.  
[tutorial9c.txt](https://root-forum.cern.ch/uploads/short-url/fEX2ylv1y6g61mbuGRa0HbYvPj7.txt) (258.8 KB)

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [October 6, 2022, 5:47am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/8 "2022-10-06T05:47:51Z")

</div>

So, you now have a fully working example of how you can read your `"tree"` data (it only dumps events to “`std::cout`”).

BTW. For such a simple `"tree"` structure, (in the long run) you’d better switch to using: [RDataFrame](https://root.cern.ch/doc/master/classROOT_1_1RDataFrame.html)

---

<div class="post-metadata">

**Author:** ![Raseeb\_Haroon](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/raseeb_haroon/32/30638_2.png) [@Raseeb\_Haroon](https://root-forum.cern.ch/u/Raseeb_Haroon)\
**Post date:** [October 6, 2022, 7:37am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-while-trying-to-use-tlorentzvector/51845/9 "2022-10-06T07:37:57Z")

</div>

Ok, I will look into using it.
