# Break Segmentation violation with TMatrixD

**URL:** <https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593>\
**Category:** Newbie\
**Created:** [April 14, 2019, 7:16am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593 "2019-04-14T07:16:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BiaseGabriel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@BiaseGabriel](https://root-forum.cern.ch/u/BiaseGabriel)\
**Post date:** [April 14, 2019, 7:16am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593/1 "2019-04-14T07:16:44Z")

</div>

Hi,

I am a relatively new ROOT user working on big data from ATLAS experiment. I have been putting effort in take some data from a tree. This tree has one branch with some leafs. I took the data from the leaf &sample and filled in a vector Short\_t sample[4][[64][48][7]. But, I need to put the data from a specific location (i.e, sample[0][0][0][i] , 0\<i\<6) in a **TMatrixD** so that I can do some math with the data . The tree has 9258 entries. Unfortunately, the code below is not successful and show **_Break_ segmentation violation** specifically on line 21. Why could I not assign it to the vector **Double\_t data**?

```auto
1. TFile f("mu50.root");
2. TTree *h2000 = (TTree*)f.Get("h2000");
3. Short_t sample[4][64][48][7];
4. h2000->SetBranchAddress("sample",&sample);
5. Long_t nentries = h2000->GetEntries();
6. Int_t par = 2; 
7. Int_t mod = 30;
8. Int_t ch = 21;
9. Double_t data[7];
10. Double_t dataLog[7];

11. TMatrixD tmp(nentries,7);

12. for(Long_t entry = 0; entry < nentries; entry++)
13. {
14. h2000->GetEntry(entry);
15. 			
16. for(Int_t i = 0; i<7; i++)
17. {
18. data[i] = sample[par][mod][ch][i];
19. dataLog[i] = TMath::Log(sample[par][mod][ch][i]);
20. }

21. tmp.SetMatrixArray(data); 
22. }

```

---

<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:** [April 14, 2019, 7:31am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593/2 "2019-04-14T07:31:30Z")

</div>

What does the [SetMatrixArray](https://root.cern.ch/doc/master/classTMatrixTBase.html#ae51cb9af8472cf136286dbd19171d4b8) method description say about the minimal size of the input parameter “data”?

[ROOT User’s Guide -\> Linear Algebra in ROOT](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#linear-algebra-in-root)

---

<div class="post-metadata">

**Author:** ![BiaseGabriel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@BiaseGabriel](https://root-forum.cern.ch/u/BiaseGabriel)\
**Post date:** [April 14, 2019, 7:36am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593/3 "2019-04-14T07:36:30Z")

</div>

Sorry, I did not get what you mean. Is there a minimum limit to the vector size to be set to the **TMatrixD** with **SetMatrixArray()** method?  
I have already checked this documentation. I am able to do that on the prompt with an arbitrary matrix but not with the code above…

---

<div class="post-metadata">

**Author:** ![BiaseGabriel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@BiaseGabriel](https://root-forum.cern.ch/u/BiaseGabriel)\
**Post date:** [April 14, 2019, 8:01am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593/4 "2019-04-14T08:01:57Z")

</div>

I checked the documentation again. It seems to be an issue with the limits of the “data” array, as you suggested. But what do you think I could do in this case?  
Is there another better method that I could use for this class **TMatrixD**?

---

<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:** [April 14, 2019, 8:06am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593/5 "2019-04-14T08:06:44Z")

</div>

Try: `tmp[entry][i] = sample[par][mod][ch][i];`

---

<div class="post-metadata">

**Author:** ![BiaseGabriel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85f322/32.png) [@BiaseGabriel](https://root-forum.cern.ch/u/BiaseGabriel)\
**Post date:** [April 14, 2019, 8:13am UTC](https://root-forum.cern.ch/t/break-segmentation-violation-with-tmatrixd/33593/6 "2019-04-14T08:13:30Z")

</div>

It seems to be working for now as the script is running without errors.  
I will check it all for future problems with SetMatrixArray().

Thank you a lot
