# How to do both saving a root file and displaying

**URL:** <https://root-forum.cern.ch/t/how-to-do-both-saving-a-root-file-and-displaying/44153>\
**Category:** Newbie\
**Created:** [March 25, 2021, 5:06am UTC](https://root-forum.cern.ch/t/how-to-do-both-saving-a-root-file-and-displaying/44153 "2021-03-25T05:06:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hohshita](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/5f9b8f/32.png) [@hohshita](https://root-forum.cern.ch/u/hohshita)\
**Post date:** [March 25, 2021, 5:06am UTC](https://root-forum.cern.ch/t/how-to-do-both-saving-a-root-file-and-displaying/44153/1 "2021-03-25T05:06:29Z")

</div>

Dear all,

I’d like to save a histogram into a root file,  
and at the same time, to display the histogram  
via a x-terminal.

I attach a simple example.  
When you execute it, you will see a blank canvas.  
Of course, you can see the histogram from the root file.

Can I do both at the same time?[test.C](https://root-forum.cern.ch/uploads/short-url/6FuWMTmuXCQGbsT7yQiSyfyq7ix.C) (208 Bytes)

Best regards,  
Hide

\_ROOT Version: 6.22/06  
\_Platform: CentOS Linux 8.3.2011  
\_Compiler: gcc 8.3.1

* * *

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [March 25, 2021, 7:42am UTC](https://root-forum.cern.ch/t/how-to-do-both-saving-a-root-file-and-displaying/44153/2 "2021-03-25T07:42:11Z")

</div>

Hi Hide,

It is histograms ownership problem.  
You should call:

```auto
hist->SetDirectory(nullptr);

```

before closing file.  
See section [creating histogram](https://root.cern/doc/master/classTH1.html#creating-histograms) in TH1 docu

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![hohshita](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/5f9b8f/32.png) [@hohshita](https://root-forum.cern.ch/u/hohshita)\
**Post date:** [March 25, 2021, 8:02am UTC](https://root-forum.cern.ch/t/how-to-do-both-saving-a-root-file-and-displaying/44153/3 "2021-03-25T08:02:20Z")

</div>

Hi Sergey,

Thanks for your quick reply !  
It works GOOD for me !

Best regards,  
Hide
