# Show event by event from leaf

**URL:** <https://root-forum.cern.ch/t/show-event-by-event-from-leaf/45729>\
**Category:** Newbie\
**Tags:** root\
**Created:** [July 7, 2021, 1:40pm UTC](https://root-forum.cern.ch/t/show-event-by-event-from-leaf/45729 "2021-07-07T13:40:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karl007](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/8491ac/32.png) [@Karl007](https://root-forum.cern.ch/u/Karl007)\
**Post date:** [July 7, 2021, 1:40pm UTC](https://root-forum.cern.ch/t/show-event-by-event-from-leaf/45729/1 "2021-07-07T13:40:37Z")

</div>

Hi, I am trying to draw two leafs (leaf1 vs leaf2) in a branch of tree. I managed to draw all entries together using:

```auto
  f = new TFile("myfile.root");
  if ((!f) || f->IsZombie()) {delete f; return;} 
  f->GetObject("mytree", t);
  if (!t) {delete f; return;} // just a precaution
  gROOT->cd();

  TTree *gt = (TTree *) f->Get("mytree");

  TH2D *h2 = new TH2D("h2", "tracks;x;z", 100, -100, 100, 100, -100, 100);
  h2->Sumw2(kTRUE);
  
  t->Project("h2", "leaf1:leaf2", "");

  delete f;

  h2->Draw("COL");
  h2->SetStats(0); //hide stats

```

But what I see is all events (entries from both leafs drawn. How do I filter to see event by event?

---

<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:** [July 7, 2021, 2:02pm UTC](https://root-forum.cern.ch/t/show-event-by-event-from-leaf/45729/2 "2021-07-07T14:02:02Z")

</div>

> [@Karl007](#):
>
> How do I filter to see event by event?

What do you mean exactly ? the `Project` command will fill `h2` with leaf1 and leaf2 along x and y axis… I am not sure "event by event"mean is that case.

---

<div class="post-metadata">

**Author:** ![Karl007](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/8491ac/32.png) [@Karl007](https://root-forum.cern.ch/u/Karl007)\
**Post date:** [July 7, 2021, 2:07pm UTC](https://root-forum.cern.ch/t/show-event-by-event-from-leaf/45729/3 "2021-07-07T14:07:41Z")

</div>

Attached is what I get. They are 100 events. I would like to show only one event if possible.

For example:

I wanted to loop over all entries in my tree and draw only one by one but it didn’t work and it showed the same result:

```auto
  //for (int i=0;i<events;i++){
	// cout<<"Event "<<i<<endl;
	// gt->GetEntry(i);
	// TH2D *h2 = new TH2D("h2", " tracks;x;z", 100, -100, 100, 100, -100, 100);
	// h2->Sumw2(kTRUE);
	// t->Project("h2", "leaf1:leaf2", "");

```

---

<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:** [July 7, 2021, 5:23pm UTC](https://root-forum.cern.ch/t/show-event-by-event-from-leaf/45729/4 "2021-07-07T17:23:54Z")

</div>

Have a look at the [2 last parameters of TTree::Project](https://root.cern/doc/master/classTTree.html#ac8709d1729aac2ff342dba3a06b4e006). The number of event and the last event. Use it to select on 1.
