# Storing C Struct in Tree

**URL:** <https://root-forum.cern.ch/t/storing-c-struct-in-tree/51583>\
**Category:** Newbie\
**Created:** [September 15, 2022, 6:57pm UTC](https://root-forum.cern.ch/t/storing-c-struct-in-tree/51583 "2022-09-15T18:57:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie2](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/n/b4bc9f/32.png) [@newbie2](https://root-forum.cern.ch/u/newbie2)\
**Post date:** [September 15, 2022, 6:57pm UTC](https://root-forum.cern.ch/t/storing-c-struct-in-tree/51583/1 "2022-09-15T18:57:51Z")

</div>

ROOT Version : 6.26  
Platform : Debian 11  
Compiler : GCC 10.2

```auto
#include <iostream>
#include "TFile.h"
#include "TTree.h"

struct Event{
  int NParticle;
  double b, PsiEP;
};

int main(int argc, char **argv){
	TFile File("test.root", "recreate");
	TTree Tree("Events", "Event Info");

	Event E;
	Tree.Branch("Event", &E, "NParticle/I:b/D:PsiEP/D");

	E = {10, 0.5, -0.5};
	Tree.Fill();

	File.Write();
	File.Close();
	return 0;
}

```

Not getting stored in _test.root_. Am I missing something here ? What is the correct  
procedure to store C-like structs in a Tree ? (Apart from creating branches for each  
member variable separately 😃 )

---

<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:** [September 15, 2022, 11:05pm UTC](https://root-forum.cern.ch/t/storing-c-struct-in-tree/51583/2 "2022-09-15T23:05:11Z")

</div>

When using the leaflist way of creating branch you must order your data member in decrease order of size (and list them in the comment the same order):

```auto
struct Event{
  double b, PsiEP;
  int NParticle;
};

```

You are usually better off generating and loading a “dictionary” for the struct. See [I/O of custom classes - ROOT](https://root.cern/manual/io_custom_classes) or use `gInterpreter->GenerateDictionary("Event", "Event.h");`
