# How to store histograms in different folders in a root file?

**URL:** <https://root-forum.cern.ch/t/how-to-store-histograms-in-different-folders-in-a-root-file/52594>\
**Category:** Newbie\
**Tags:** root\
**Created:** [December 2, 2022, 11:07am UTC](https://root-forum.cern.ch/t/how-to-store-histograms-in-different-folders-in-a-root-file/52594 "2022-12-02T11:07:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divyang](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/7ea924/32.png) [@Divyang](https://root-forum.cern.ch/u/Divyang)\
**Post date:** [December 2, 2022, 11:07am UTC](https://root-forum.cern.ch/t/how-to-store-histograms-in-different-folders-in-a-root-file/52594/1 "2022-12-02T11:07:08Z")

</div>

Hello,

I have a different set of histograms and I want to store them in separate folders. I am new to ROOT, so I don’t know how to do this.

The following code is the pseudo-code for what I want to do. Please help me with this.

```auto
void test()
{
    TFile *fout = new TFile("test.root","RECREATE");
    TTree *tree = new TTree("tree","tree");
	
	Double_t X;
	Double_t Y;
	tree->Branch("X", &X, "X/D");
	tree->Branch("Y", &X, "Y/D");
	
	// I want these histograms in different folders
	TH1F *hist_X = new TH1F("hist_X", "X", 20, 0, 10);	// folder name: Many_hist_X
	TH1F *hist_Y = new TH1F("hist_Y", "Y", 20, 0, 10);	// folder name: Many_hist_Y
	
	for (int i=0; i<10; i++)
	{
		X = i;
		Y = i;
		
		hist_X->Fill(X);
		hist_Y->Fill(Y);
		
		tree->Fill();
	}
	
	fout->Write();
    fout->Close();
}

```

Thank you,  
Divyang.

---

<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:** [December 2, 2022, 12:29pm UTC](https://root-forum.cern.ch/t/how-to-store-histograms-in-different-folders-in-a-root-file/52594/2 "2022-12-02T12:29:08Z")

</div>

Use [mkdir](https://root.cern/doc/v626/classTDirectoryFile.html#a7956f3301635ca0dd5655e8e59a35d85) to create a directtory n a TFile.

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [December 2, 2022, 12:29pm UTC](https://root-forum.cern.ch/t/how-to-store-histograms-in-different-folders-in-a-root-file/52594/3 "2022-12-02T12:29:25Z")

</div>

[https://root.cern/doc/v608/dirs\_8C\_source.html](https://root.cern/doc/v608/dirs_8C_source.html)
