# How to access to std::vector\<TVector3\> in a TBranch?

**URL:** <https://root-forum.cern.ch/t/how-to-access-to-std-vector-tvector3-in-a-tbranch/60346>\
**Category:** Newbie\
**Created:** [July 28, 2024, 9:19am UTC](https://root-forum.cern.ch/t/how-to-access-to-std-vector-tvector3-in-a-tbranch/60346 "2024-07-28T09:19:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [July 28, 2024, 9:19am UTC](https://root-forum.cern.ch/t/how-to-access-to-std-vector-tvector3-in-a-tbranch/60346/1 "2024-07-28T09:19:00Z")

</div>

Dear experts

I want to read a `std::vector<TVector3>` branch and here is what I do:

```auto
//include files
#pragma link C++ class std::vector<TVector3>+;
void drawShape(){
    TFile* f = new TFile("file.root", "READ");
    TTree* t = (TTree*)f->Get("t");
    std::vector<TVector3>* pos;
    t->SetBranchAddress("pos", &pos);
    for(int i=0; i<t->GetEntries(); ++t){
        t->GetEntry(i);
        for(auto& p : (*pos)){
            //do something
        }
    }
}

```

And I do: `root -l drawShape.cxx+`  
But I got seg fault with the message:

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/9/6/96a0e377b1584d328d4d6b77cfc4ac4126097613.png)  
Sorry I was not able to copy error message, what did I do wrong to get this error?

\_ROOT Version: 6.18.00  
\_Platform: CentOS 7  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![devajith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/devajith/32/37165_2.png) [@devajith](https://root-forum.cern.ch/u/devajith)\
**Post date:** [July 28, 2024, 3:34pm UTC](https://root-forum.cern.ch/t/how-to-access-to-std-vector-tvector3-in-a-tbranch/60346/2 "2024-07-28T15:34:09Z")

</div>

Hi @Crisps,

Thanks for your question.

Sorry that you’re experiencing issues. Would it be possible for you to provide a minimal reproducer with the root file so that I can try to reproduce the issue locally.

Cheers,  
Dev

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [July 28, 2024, 7:53pm UTC](https://root-forum.cern.ch/t/how-to-access-to-std-vector-tvector3-in-a-tbranch/60346/3 "2024-07-28T19:53:00Z")

</div>

Most likely replacing

> [@Crisps](#):
>
> ` std::vector<TVector3>* pos;`

with

```auto
    std::vector<TVector3>* pos = nullptr;

```

should solve the problem (without this the `TTree` used some arbitrary memory location as the place where to write the vector)

---

<div class="post-metadata">

**Author:** ![Crisps](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/crisps/32/39101_2.png) [@Crisps](https://root-forum.cern.ch/u/Crisps)\
**Post date:** [July 29, 2024, 6:19am UTC](https://root-forum.cern.ch/t/how-to-access-to-std-vector-tvector3-in-a-tbranch/60346/4 "2024-07-29T06:19:36Z")

</div>

You are right! This solves the problem
