# TCutG for binning

**URL:** <https://root-forum.cern.ch/t/tcutg-for-binning/52822>\
**Category:** Newbie\
**Created:** [December 19, 2022, 5:00pm UTC](https://root-forum.cern.ch/t/tcutg-for-binning/52822 "2022-12-19T17:00:48Z")\
**Posts on this page:** 3\
**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:** [December 19, 2022, 5:00pm UTC](https://root-forum.cern.ch/t/tcutg-for-binning/52822/1 "2022-12-19T17:00:49Z")

</div>

Hello experts,

I have 9 bins defined(see picture). I want to know, How to use TCutG to define the histograms for each bin.(need to draw the missing massSq distributions for each bin)

I have defined my binning as a function.(int EffBin\_pim) Attached the code. Is there a way to call this inside TCutG.

Could you please give me a clue?

 ![Screen Shot 2022-12-18 at 1.47.04 PM](https://root-forum.cern.ch/uploads/default/original/3X/e/6/e6ec79bc538e5d57c785cff342aeef588c7ffb79.jpeg)

```auto
int iBinEff_pim(double pp, double theta_p){
    // Make sure each case is exclusive
    if (theta_p>fE->Eval(pp)&&theta_p<fBW2->Eval(pp)&&pp<pMax){
        if (pp<pMin) {
            return 0;
        } else if (pp>pMin&&pp<pLimit){
            //central block with three theta bins
            fCut->SetParameter(0,upper);
            if (theta_p>fCut->Eval(pp)){
                // top two bins
                if (pp<pMid){
                    return 1;
                } else {
                    return 2;
                }
            } else {
                fCut->SetParameter(0,lower);
                if (theta_p>fCut->Eval(pp)){
                    // middle two bins
                    if (pp<pMid){
                        return 3;
                    } else {
                        return 4;
                    }
                }
                // Bottom two bins
                if (pp<pMid){
                    return 5;
                } else {
                    return 6;
                }
            }
        }
        if (pp<pMax) {
            // Two theta bins in maximal momentum bin
            fHiP->SetParameter(0,middle);
            if (theta_p>fHiP->Eval(pp)) {
                return 7;
            } else {
                return 8;
            }
        }
    }
    return -1;
}

```

Thank You  
Dil

---

<div class="post-metadata">

**Author:** ![moneta](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/moneta/32/19423_2.png) [@moneta](https://root-forum.cern.ch/u/moneta)\
**Post date:** [December 21, 2022, 9:18am UTC](https://root-forum.cern.ch/t/tcutg-for-binning/52822/2 "2022-12-21T09:18:41Z")

</div>

Hi,  
@couet can maybe help you on this,

Best regards

Lorenzo

---

<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 21, 2022, 9:53am UTC](https://root-forum.cern.ch/t/tcutg-for-binning/52822/3 "2022-12-21T09:53:09Z")

</div>

> [@Dil](#):
>
> I have 9 bins defined(see picture).

Seems to me you have much more. According to your plot.

Which area of the plot do you want to select with the cut ?  
To use a TCutG when drawing a TH2 use the option:

“[cutg]” Draw only the sub-range selected by the [TCutG](https://root.cern/doc/master/classTCutG.html) named “cutg”.
