# Cut 2D-histogram

**URL:** <https://root-forum.cern.ch/t/cut-2d-histogram/45368>\
**Category:** Newbie\
**Tags:** graphics, hist, root\
**Created:** [June 12, 2021, 7:09pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368 "2021-06-12T19:09:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![javivilladamigo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javivilladamigo/32/28683_2.png) [@javivilladamigo](https://root-forum.cern.ch/u/javivilladamigo)\
**Post date:** [June 12, 2021, 7:09pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/1 "2021-06-12T19:09:28Z")

</div>

Hi,  
I am currently trying to analyze the energy loss of electrons in an active target gas. When I drew a 2D histogram with the ∆E/∆s versus ∑∆s (i.e. energy loss per step divided by the length of the step, versus the accumulated depth of the electron) I get the following histogram:

[2d\_histo.pdf](https://root-forum.cern.ch/uploads/short-url/cZGz0iOWO07KhMTw4ynVOTAm4Op.pdf) (303.4 KB)

I don’t understand where this accumulation of points is coming from (it seems pretty unrealistic). Besides, the histogram seems to end sharply just above it. I do not know what is causing these effects

_ROOT Version:_ 6.22/07  
_Platform:_ MacOS  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![javivilladamigo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javivilladamigo/32/28683_2.png) [@javivilladamigo](https://root-forum.cern.ch/u/javivilladamigo)\
**Post date:** [June 12, 2021, 7:11pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/2 "2021-06-12T19:11:18Z")

</div>

By “accumulation of points” I meant the thick horizontal bar located around 60 keV/mm

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 12, 2021, 7:25pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/3 "2021-06-12T19:25:16Z")

</div>

Hi Javier,

true, both effects (the excess at 60 keV/mm and the cut-off at 75 keV/mm) look unrealistic. I’d suggest to check the code that produces your histogram.

---

<div class="post-metadata">

**Author:** ![javivilladamigo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javivilladamigo/32/28683_2.png) [@javivilladamigo](https://root-forum.cern.ch/u/javivilladamigo)\
**Post date:** [June 12, 2021, 9:48pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/4 "2021-06-12T21:48:42Z")

</div>

Hi yus, here is a piece of the code:

```auto
    string str;
    while(getline(*file, str))

    {
        *file >> stepNumber >> Edep >> stepLength;

        stepNumbervec.push_back(stepNumber);
        Edepvec.push_back(Edep);
        stepLengthvec.push_back(stepLength);
    }

    TCanvas *c2 = new TCanvas("c2", "Bragg canvas");
    Int_t bragg_bins = 1000; // bins of histogram
    TH2F *bragg_hist = new TH2F("bragg_hist", Form("%s, %.2f MeV, %.0f K, %.0f mbar, %.0f V/cm", string(gas).c_str(), initial_energy, temperature, pressure, electric_field), bragg_bins, 0, 1400, bragg_bins, 0, 200);
    
    
    Double_t depth = 0; // accumulated depth
    Double_t stoppingPower;
    
    for(Int_t i=0; i<Edepvec.size(); i++)
    {
        if (stepNumbervec[i] != 1)
        {
            // stick to the same electron? -> add the step length to the total range
            depth += stepLengthvec[i];
            stoppingPower = Edepvec[i]*1000/stepLengthvec[i];
            c2->cd();
            bragg_hist->Fill(depth, stoppingPower);
        }
        else
        {
            // another electron? -> filling the last step of the previous one and clear depth
            c1->cd();
            range_hist->Fill(depth);
            depth = 0;
        }
    }
    
    c2->cd();
    //bragg_hist->Rebin2D(4, 4);
    bragg_hist->Draw("COLZ");

```

I didn’t upload it originally because it seemed pretty straightforward to me… The code reads a .txt file with the step number of the electron trajectory, the energy lost in that step and the length of the step, for example:  
1 0.000125801 0.325053  
2 0.0325084 74.1814  
3 0.052952 120.936  
4 0.0850733 226.414  
5 0.0120996 31.1658  
(where the second column is in MeV, and the third is in mm).  
If you spot any problem please let me know. Otherwise I guess I will have to start looking at the Geant4 simulation that generates the file.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 13, 2021, 9:48am UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/5 "2021-06-13T09:48:50Z")

</div>

How large is this text file of yours? Can you post it here or maybe share it via your favorite file-sharing service like Dropbox/Google Drive/Mega etc.?

---

<div class="post-metadata">

**Author:** ![javivilladamigo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javivilladamigo/32/28683_2.png) [@javivilladamigo](https://root-forum.cern.ch/u/javivilladamigo)\
**Post date:** [June 13, 2021, 11:08am UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/6 "2021-06-13T11:08:17Z")

</div>

It is quite large actually. This is the link to the file uploaded to google drive:

> **[750keV.txt](https://drive.google.com/file/d/1LbKWvPisOdpMrBOnPtvbAJw7bcmTMuuE/view?usp=sharing)**
>
> Google Drive file.

I must say, however, that when I ran the simulation for protons, just to see if I recovered the Bragg peak, I got this histogram for 3 MeV protons:

 ![proton](https://root-forum.cern.ch/uploads/default/original/3X/7/5/75714ebb7557597a696f57270d326c90a1ad6774.png)

And none of the effects I observed with the electrons histogram appeared.

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [June 13, 2021, 3:25pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/7 "2021-06-13T15:25:58Z")

</div>

Yes, I reproduced the plot. There is probably something wrong with the way your text file was generated.

---

<div class="post-metadata">

**Author:** ![javivilladamigo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/javivilladamigo/32/28683_2.png) [@javivilladamigo](https://root-forum.cern.ch/u/javivilladamigo)\
**Post date:** [June 13, 2021, 3:37pm UTC](https://root-forum.cern.ch/t/cut-2d-histogram/45368/8 "2021-06-13T15:37:47Z")

</div>

Yes, that is what I am looking at right now. Guess I’ll have to post a topic in a Geant4 forum 😆. Thank you anyway for the help!
