# Where to open TFile when using TTree Write?

**URL:** <https://root-forum.cern.ch/t/where-to-open-tfile-when-using-ttree-write/54695>\
**Category:** ROOT\
**Created:** [May 2, 2023, 2:02pm UTC](https://root-forum.cern.ch/t/where-to-open-tfile-when-using-ttree-write/54695 "2023-05-02T14:02:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![machiel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/f05b48/32.png) [@machiel](https://root-forum.cern.ch/u/machiel)\
**Post date:** [May 2, 2023, 3:48pm UTC](https://root-forum.cern.ch/t/where-to-open-tfile-when-using-ttree-write/54695/4 "2023-05-02T15:48:14Z")

</div>

Thank you, that works. At the end of the code before doing the Write, I will have to “cd” back to the “aFile” directory, right? Like this:

```auto
    TFile aFile("TEST.root", "RECREATE");
    TTree* tt_myTree = new TTree("myTree", "TEST");
    gROOT->cd();
    .... // do histogram stuff
    aFile.cd();
    tt_myTree->Write();

```

---

_[View the full topic](https://root-forum.cern.ch/t/where-to-open-tfile-when-using-ttree-write/54695)._
