# Updating a histogram in THashList in a root file

**URL:** <https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461>\
**Category:** Newbie\
**Created:** [February 9, 2021, 12:10pm UTC](https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461 "2021-02-09T12:10:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haidar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/96bed5/32.png) [@Haidar](https://root-forum.cern.ch/u/Haidar)\
**Post date:** [February 9, 2021, 12:10pm UTC](https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461/1 "2021-02-09T12:10:10Z")

</div>

Dear rooters,  
I would like to modify a histogram in a root file inside a THashList and save it back to the file. So try something like this:

```auto
TFile *file = TFile("myFile.root", "update");

TList *list = (TList*)file->Get("myList;1");

THashList *subList = (THashList*)list->FindObject("mySubList");

TH2D *myHisto = (TH2D*)subList->FindObject("myObject");
// Do something to myHisto 
// Write myHisto back to subList

```

Please guide me how to achieve this.

* * *

\_ROOT Version: Root 6  
\_Platform: Ubuntu 18  
\_Compiler: gcc 7.5.0

---

<div class="post-metadata">

**Author:** ![Haidar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/96bed5/32.png) [@Haidar](https://root-forum.cern.ch/u/Haidar)\
**Post date:** [February 11, 2021, 7:26am UTC](https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461/2 "2021-02-11T07:26:46Z")

</div>

Hello ROOTers,  
please any help???

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 11, 2021, 7:35am UTC](https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461/3 "2021-02-11T07:35:13Z")

</div>

Do you have a problem with the piece of code you posted ? it looks a good start. Does it work ?

---

<div class="post-metadata">

**Author:** ![Haidar](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/96bed5/32.png) [@Haidar](https://root-forum.cern.ch/u/Haidar)\
**Post date:** [February 11, 2021, 7:42am UTC](https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461/4 "2021-02-11T07:42:00Z")

</div>

The problem is I don’t know how to remove the old histogram and write the updated one to the THashList to the root file.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [February 11, 2021, 10:14am UTC](https://root-forum.cern.ch/t/updating-a-histogram-in-thashlist-in-a-root-file/43461/5 "2021-02-11T10:14:02Z")

</div>

> [@Haidar](#):
>
> to remove the old histogram

With [Remove()](https://root.cern/doc/master/classTHashList.html#a6dd88745e8afe83bdac4709463ebc3ff)
