# Energy distribution Plot

**URL:** <https://root-forum.cern.ch/t/energy-distribution-plot/54684>\
**Category:** ROOT\
**Tags:** tree, hist, root\
**Created:** [April 30, 2023, 10:57pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684 "2023-04-30T22:57:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yasir\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yasir_ali/32/32696_2.png) [@Yasir\_Ali](https://root-forum.cern.ch/u/Yasir_Ali)\
**Post date:** [April 30, 2023, 10:57pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/1 "2023-04-30T22:57:07Z")

</div>

Dear Experts

I want to plot energy distribution in 3D plot using the attached macro and Root file but I don’t see proper filling of histogram What is see is also attached in Screen shot. Please check my Macro and Suggest What could be wrong. Thanks

[lumi3.edm4hep.root](https://root-forum.cern.ch/uploads/short-url/zFny63mwsnlm9XzgNoQ5imjf9VH.root) (3.0 MB)

 ![Screenshot from 2023-05-01 00-56-06](https://root-forum.cern.ch/uploads/default/original/3X/4/d/4dbced7613c8fe669abf6636121930584056605c.png)

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ Not Provided  
_Platform:_ Not Provided  
_Compiler:_ Not Provided

* * *

[draw\_Performance.C](https://root-forum.cern.ch/uploads/short-url/sctdEkf9i0Y3GLJRadgE90SgRc3.C) (3.2 KB)

---

<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 1, 2023, 6:04am UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/2 "2023-05-01T06:04:42Z")

</div>

In your ROOT files, there are only 10 events:

`root -b -q lumi3.edm4hep.root -e 'events->Scan("MCParticles.generatorStatus");'`

This makes no sense:

`hist3->Fill(posX[iParticle], posY[iParticle], posZ[iParticle], energy[iParticle]);`

Maybe you want:

```cpp
for (int iHit = 0; iHit < energy.GetSize(); iHit++)
  hist3->Fill(posX[iHit], posY[iHit], posZ[iHit], energy[iHit]);

```

---

<div class="post-metadata">

**Author:** ![Yasir\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yasir_ali/32/32696_2.png) [@Yasir\_Ali](https://root-forum.cern.ch/u/Yasir_Ali)\
**Post date:** [May 1, 2023, 2:10pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/3 "2023-05-01T14:10:15Z")

</div>

Thanks @Wile_E_Coyote It worked and now I can see

 ![3Dplot_crystal_study](https://root-forum.cern.ch/uploads/default/original/3X/6/4/64a75c95c2f3d0202ac0f493611df42dd6ae2193.png)  
This is for detector size 10cm x 10cm and I would like to see deposition in 1mm Can you Please suggest How can i plot that.  
Thanks a lot

---

<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 1, 2023, 4:02pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/4 "2023-05-01T16:02:58Z")

</div>

You can draw the inner part only, e.g.:

```cpp
hist3->Draw("LEGO2Z");
hist3->GetXaxis()->SetRangeUser(-2., 2.);
hist3->GetYaxis()->SetRangeUser(-2., 2.);
hist3->GetZaxis()->SetRangeUser(-66150., -66000.);
if (gPad) { gPad->Modified(); gPad->Update(); }

```

Or you can create the histogram with small axes ranges, e.g.:  
`auto hist3 = new TH3F("X:Y:Z", "Hit position 3D", 40, -2., 2., 40, -2., 2., 50, -66150., -66000.);`

---

<div class="post-metadata">

**Author:** ![Yasir\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yasir_ali/32/32696_2.png) [@Yasir\_Ali](https://root-forum.cern.ch/u/Yasir_Ali)\
**Post date:** [May 1, 2023, 4:06pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/5 "2023-05-01T16:06:07Z")

</div>

OK Thanks

---

<div class="post-metadata">

**Author:** ![Yasir\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yasir_ali/32/32696_2.png) [@Yasir\_Ali](https://root-forum.cern.ch/u/Yasir_Ali)\
**Post date:** [May 1, 2023, 5:19pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/6 "2023-05-01T17:19:59Z")

</div>

Hi @ [Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote) I have added some code to plot projections Now I want to see e.g., the energy deposit within a slice along the z axis. Please suggest How can i see that.  
Part of my code is as follows:  
for (map\<string,TH3\*\>::const\_iterator itr = h3.begin(); itr != h3.end(); itr++)  
{  
//gStyle-\>SetOptStat(0);

```
    string hname = itr->first;
    TH3* h = (TH3*)itr->second->Clone();
    h->Scale(1.0/float(h->Integral()));

    TCanvas* c = new TCanvas("c", "", 1000, 1000);

    TH2* h2yx = (TH2*)h->Project3D("yx")->Clone();
  
    c->cd();
    h2yx->Draw("colz");
    gPad->SetLogx(0); gPad->SetLogy(0); gPad->SetLogz(0);
    ss.str(""); ss << "test2D_yx_" << hname << ".png";
    c->SaveAs(TString(ss.str()));

```

---

<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 1, 2023, 5:49pm UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/7 "2023-05-01T17:49:33Z")

</div>

**Before** doing the projection, try: `h->GetZaxis()->SetRangeUser(some_z_min, some_z_max);`

---

<div class="post-metadata">

**Author:** ![Yasir\_Ali](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/yasir_ali/32/32696_2.png) [@Yasir\_Ali](https://root-forum.cern.ch/u/Yasir_Ali)\
**Post date:** [May 2, 2023, 10:23am UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/8 "2023-05-02T10:23:57Z")

</div>

@ [Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote) I tried this but does not produce slice in z axis Can You Please suggest the errors

```
   TH2* h1 = (TH2*)h->Project3D("z slice")->Clone();
    h1->GetZaxis()->SetRangeUser(zmin, zmax);
    h1->Draw("colz");
    gPad->SetLogx(0); gPad->SetLogy(1); gPad->SetLogz(0);
    ss.str(""); ss << "Zslice" << hname << ".png";
    c->SaveAs(TString(ss.str()));

```

---

<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 2, 2023, 11:33am UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/9 "2023-05-02T11:33:23Z")

</div>

I wrote: **BEFORE**

BTW. Read also: [TH3::Project3D](https://root.cern/doc/master/classTH3.html#a94dd0a21d42fd95756e906e7f50fa293)

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 16, 2023, 11:34am UTC](https://root-forum.cern.ch/t/energy-distribution-plot/54684/10 "2023-05-16T11:34:01Z")

</div>

Closed on May 16, 2023, 11:34am UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
