# Regarding the dy/dx of the histogram

**URL:** <https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726>\
**Category:** Newbie\
**Tags:** hist, root\
**Created:** [June 13, 2025, 2:10am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726 "2025-06-13T02:10:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![QinLi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/q/b5e925/32.png) [@QinLi](https://root-forum.cern.ch/u/QinLi)\
**Post date:** [June 13, 2025, 2:10am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726/1 "2025-06-13T02:10:45Z")

</div>

Dear Experts:  
I now have a TH1 histogram with the x-axis noted as T and the y-axis noted as N. Now perform a t=a+bT transformation on x, which transforms the x-axis to t, and then perform an E=2t\*t transformation, which transposes the x-axis to E. For example, a bin of the original histogram is (T0, T1), corresponding to N. and after t-transformation the bin becomes (t0, t1), and after E-transformation the bin becomes (E0, E1). Now, if I want to find dN/dE, should I use N/(E1-E0), or N/[(E1-E0)(T1-T0)], or should I use another method?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![devajith](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/devajith/32/37165_2.png) [@devajith](https://root-forum.cern.ch/u/devajith)\
**Post date:** [June 13, 2025, 5:48am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726/2 "2025-06-13T05:48:56Z")

</div>

Hi @QinLi,

Thank you for your question and welcome to the ROOT Forum.

It would be great if you can post a small snippet that could help us identify what you’re trying to achieve more clearly.

Cheers,  
Dev

---

<div class="post-metadata">

**Author:** ![QinLi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/q/b5e925/32.png) [@QinLi](https://root-forum.cern.ch/u/QinLi)\
**Post date:** [June 13, 2025, 8:14am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726/3 "2025-06-13T08:14:57Z")

</div>

Hi @devajith ,  
Thank you very much for your reply.  
The following is my sample code. On the last line of the code, I want to calculate dN/dE. May I ask if this calculation is correct?

 ![Screenshot from 2025-06-13 16-08-07](https://root-forum.cern.ch/uploads/default/original/3X/4/b/4b26d132daa270f22172df7b7f9f580a346fc09d.png)

---

<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 13, 2025, 8:23am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726/4 "2025-06-13T08:23:01Z")

</div>

Instead of a photo can you post the code, so we can copy/paste and try it ?

---

<div class="post-metadata">

**Author:** ![QinLi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/q/b5e925/32.png) [@QinLi](https://root-forum.cern.ch/u/QinLi)\
**Post date:** [June 13, 2025, 8:54am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726/5 "2025-06-13T08:54:21Z")

</div>

The following is my code:

```auto
{
    TH1D* h1 = new TH1D("gauss_hist", "Gaussian Distribution;X;Counts", 4096, 0, 4096);
    for (int i = 0; i < 10000; ++i) {
        h1->Fill(gRandom->Gaus(2048, 300));
    }
    h1->Draw();

    double Tstart = 1500;
    double Tend = 2500;
    double BinWidth = h1->GetBinWidth(Tstart);
    Double_t T[3000], Tlow[3000], Tup[3000], N[3000], dT[3000], dN[3000] = {0};
    int nn = 0;
    for(double i = Tstart; i <= Tend; i += BinWidth){
        T[nn] = h1->GetBinCenter(h1->FindBin(i));
        Tlow[nn] = h1->GetBinLowEdge(h1->FindBin(i));
        Tup[nn] = Tlow[nn] + BinWidth;
        dT[nn] = h1->GetBinWidth(h1->FindBin(i));
        N[nn] = h1->GetBinContent(h1->FindBin(i));
        nn++;
    }
    double E[2000], dE[2000], Elow[2000], Eup[2000] = {0.0};
    double t, dt, tlow, tup = 0.0;
    double c = 2600;
    double tac = 0.2;
    for(int i = 0; i < nn; i++){
        t = (c - T[i]) * tac;
        tlow = (c - Tlow[i]) * tac;
        tup = (c - Tup[i]) * tac;
        dt = tlow -tup;
        E[i] = 2 * t * t;
        Elow[i] = 2 * tlow * tlow;
        Eup[i] = 2 * tup *tup;
        dE[i] = Eup[i] - Elow[i];
        N[i] = N[i] / dE[i]; // dN/dE?
    }
}

```

---

<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 13, 2025, 9:27am UTC](https://root-forum.cern.ch/t/regarding-the-dy-dx-of-the-histogram/63726/6 "2025-06-13T09:27:39Z")

</div>

I am not sure to fully understand your problem.

N is your Y-axis, T your X-Axis. The value of dT you compte seems between the low edge of the bin and the upper edge of the bin but for these two values of T, N is the same. Therefore dN will be also nul. I might be wrong but, seems to me, dN sounds more like a difference between the N value of a bin i and the bin i+1 … But as I said I am not sure to fully understand what you are trying to do.
