# How to get the Min and max value from a tree variable

**URL:** <https://root-forum.cern.ch/t/how-to-get-the-min-and-max-value-from-a-tree-variable/50341>\
**Category:** Newbie\
**Created:** [June 9, 2022, 2:44pm UTC](https://root-forum.cern.ch/t/how-to-get-the-min-and-max-value-from-a-tree-variable/50341 "2022-06-09T14:44:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dil/32/26887_2.png) [@Dil](https://root-forum.cern.ch/u/Dil)\
**Post date:** [June 9, 2022, 2:44pm UTC](https://root-forum.cern.ch/t/how-to-get-the-min-and-max-value-from-a-tree-variable/50341/1 "2022-06-09T14:44:15Z")

</div>

Hello Rooters,  
I need to get the Min and Max value from the tree variable.  
I have 4 variables.  
QSq,xBj , ixB(xB bin numbers), jQ2(QSq bin numbers)  
I can read the variables properly.  
But I need to find the QSq min and max values from each bin.

When I introduce following line.my root session exit unexpectedly.  
Q2Min[j]= tree-\>GetMinimum(“QSq”);

Please see attached code and my root file.Could you please help me to figure this out?

Thanks  
Dil  
[Tree\_reading.cpp](https://root-forum.cern.ch/uploads/short-url/kPS7JBlqYgDy2DQJP2G6z6eIr6a.cpp) (1.2 KB)  
[xBQ2binning.root](https://root-forum.cern.ch/uploads/short-url/sALEkNAFqAfOp2vmsa7ik5H8kIJ.root) (1.9 MB)

---

<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:** [June 9, 2022, 3:04pm UTC](https://root-forum.cern.ch/t/how-to-get-the-min-and-max-value-from-a-tree-variable/50341/2 "2022-06-09T15:04:14Z")

</div>

May be it is s stupid question, but why not simply do:

```auto
% root xBQ2binning.root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.27/01 https://root.cern |
  | (c) 1995-2022, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Jun 08 2022, 14:00:07 |
  | From heads/master@v6-25-02-1465-gc9ea7609ee |
  | With Apple clang version 13.1.6 (clang-1316.0.21.2.5) |
  | Try '.help'/'.?', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------------

root [0] 
Attaching file xBQ2binning.root as _file0...
(TFile *) 0x7fb2bcfd96b0
root [1] xBQ2binning_tree->GetMinimum("QSq")
(double) 1.5011401
root [2] 

```

---

<div class="post-metadata">

**Author:** ![Dil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dil/32/26887_2.png) [@Dil](https://root-forum.cern.ch/u/Dil)\
**Post date:** [June 9, 2022, 3:25pm UTC](https://root-forum.cern.ch/t/how-to-get-the-min-and-max-value-from-a-tree-variable/50341/3 "2022-06-09T15:25:18Z")

</div>

Hello,  
Yes,I can do what you mentioned without introducing binning.  
But I need to find the Q2 [min,max] value inside each bin and generate some uniform random numbers.

Thanks  
Dil

---

<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:** [June 9, 2022, 3:39pm UTC](https://root-forum.cern.ch/t/how-to-get-the-min-and-max-value-from-a-tree-variable/50341/4 "2022-06-09T15:39:05Z")

</div>

So you what to work on the resulting histogram.

```auto
xBQ2binning_tree->Draw("QSq","","goff")
->now htemp is ready to be used .....

```
