# Set Range of a TTree-\>Draw("histogram2:histogram1")

**URL:** <https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798>\
**Category:** Newbie\
**Created:** [May 10, 2023, 1:11pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798 "2023-05-10T13:11:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marlGon1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@marlGon1](https://root-forum.cern.ch/u/marlGon1)\
**Post date:** [May 10, 2023, 1:11pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798/1 "2023-05-10T13:11:01Z")

</div>

Hi,  
I’m working on a detector simulation and I want to study the influence of the detectors positions. I can draw it pretty easily from the simulation’s output root files like that:

```auto
 SimuTree->Draw("DetectorEvents.Position.Z:DetectorEvents.Position.X")

```

which work perfectly if I want to check my sensitives volumes geometry but I’d like to set the range of the Y axis (Position.Z) so I can visualise the different height where I put my detectors. I tried to retrieve the 2D histogram like that TH2F _h2 = (TH2F_)gPad-\>GetPrimitive(“htemp”); (to then use SetUserRange) but it appears it is empty.  
Too be clear I want 3 figures for my 3 different detector heigh with the same Y axis range.

Thanks in advance,  
Maël.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 10, 2023, 1:14pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798/2 "2023-05-10T13:14:39Z")

</div>

[TTree::Draw](https://root.cern/doc/master/classTTree.html#a73450649dc6e54b5b94516c468523e45)

BTW. You need something like: `tree->Draw("y:x", "y > some_min && y < some_max");`

---

<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:** [May 10, 2023, 1:18pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798/3 "2023-05-10T13:18:19Z")

</div>

Welcome to the ROOT forum.

The second parameter od TTree::Draw allows to define conditions on the variable. Something like:

```auto
 SimuTree->Draw("DetectorEvents.Position.Z:DetectorEvents.Position.X","DetectorEvents.Position.Z>a && DetectorEvents.Position.Z<b")

```

---

<div class="post-metadata">

**Author:** ![marlGon1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@marlGon1](https://root-forum.cern.ch/u/marlGon1)\
**Post date:** [May 10, 2023, 1:28pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798/4 "2023-05-10T13:28:13Z")

</div>

I have tried, it does not allow me to set the range. With your proposition I have a figures ranged between 1004 and 1014 mm (let’s call it configuration 1, 10 mm is the height of may detectors) which is not exactly what I want. I’d like to draw something between 1000 mm and 1100 mm so I can see that my detectors volumes are low and if I set the center of my detector to 1050 (let’s call it configuration 2) I will clearly see that with configuration 2 my detectors are placed upper than with configuration 1.

- this bias the shape of my detectors which appears to look like columns (bc the Y axis range is equal to the heigh of the detectors) while it look like a puck in reality.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [May 10, 2023, 1:40pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798/5 "2023-05-10T13:40:30Z")

</div>

```cpp
TCanvas *c = new TCanvas("c", "c");
c->DrawFrame(some_x_min, 1000., some_x_max, 1100., "Black Magic;X [mm];Z [mm]");
SimuTree->Draw("DetectorEvents.Position.Z:DetectorEvents.Position.X", "DetectorEvents.Position.Z > 1004. && DetectorEvents.Position.Z < 1014.", "SAME")

```

---

<div class="post-metadata">

**Author:** ![marlGon1](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/f08c70/32.png) [@marlGon1](https://root-forum.cern.ch/u/marlGon1)\
**Post date:** [May 10, 2023, 2:03pm UTC](https://root-forum.cern.ch/t/set-range-of-a-ttree-draw-histogram2-histogram1/54798/6 "2023-05-10T14:03:36Z")

</div>

It worked !

thank you,  
Maël.
