# How to keep two picture on one canvas?

**URL:** <https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203>\
**Category:** Garfield++\
**Created:** [October 12, 2021, 7:40am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203 "2021-10-12T07:40:31Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 12, 2021, 7:40am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/1 "2021-10-12T07:40:31Z")

</div>

Hello,sir.  
About the example of drift tube ,I want to draw two signal figure on one canvas, how should i set the function?

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 12, 2021, 7:42am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/2 "2021-10-12T07:42:24Z")

</div>

I mean… like the “hold on” in matlab

---

<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:** [October 12, 2021, 7:44am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/3 "2021-10-12T07:44:00Z")

</div>

Can you be a bit more precise ? do you have already some C++ macro ?

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 12, 2021, 7:54am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/4 "2021-10-12T07:54:22Z")

</div>

The example “drift tube”, which output a figure about signal and time. Now i want to try different position of particle source and put these signal curve on a same canvas(one picture).

I don’t have macro , I just made some modify on the original file…

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 12, 2021, 8:03am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/5 "2021-10-12T08:03:17Z")

</div>

Hi,  
I think I know what you mean. The `PlotSignal` function of the `ViewSignal` class has an argument `same`. If you set it to `true`, then it will keep the existing plot.  
Alternatively, you could just store the signal in a ROOT histogram and make the plot yourself…

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 12, 2021, 8:09am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/6 "2021-10-12T08:09:39Z")

</div>

I have tried “ViewSignal class - void PlotSignal - const bool same=true” but finally I got a empty canvas

 ![2021-10-12 16-08-27 的屏幕截图](https://root-forum.cern.ch/uploads/default/original/3X/d/a/dae1bdf13ba47dd73875a6cb0063c9e5973f1f59.png)

By the way, how could I store the signal in ROOT histogram?

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 12, 2021, 9:38am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/7 "2021-10-12T09:38:32Z")

</div>

If you want to draw multiple signals on the same canvas in the drift tube example, you can replace the line

```auto
if (plotSignal) signalView.PlotSignal("s");

```

by

```auto
if (plotSignal) {
  if (j == 0) {
   signalView.PlotSignal("s");
  } else {
    signalView.PlotSignal("s", true, false, false, false, true);
  }
}

```

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 12, 2021, 9:49am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/8 "2021-10-12T09:49:42Z")

</div>

Assuming you do this in a loop with counter `j` (like in the drift tube example), you can do something like this to save the signal pulse to a histogram:

```auto
std::string hname = "hSignal" + std::to_string(j);
TH1F hSignal(hname.c_str(), "", nbins, tmin, tmin + nbins * tstep);
for (unsigned int k = 0; k < nbins; ++k) {
  hSignal.SetBinContent(k + 1, sensor.GetSignal("s", k));
}
// hSignal.DrawCopy();

```

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 13, 2021, 12:27am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/9 "2021-10-13T00:27:09Z")

</div>

That works!

Why I should set the flag to false when j=0 and set the flag to true otherwise.I don’t get the principle, Why couldn’t I set “true” all the time…

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 13, 2021, 12:34am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/10 "2021-10-13T00:34:18Z")

</div>

About the ROOT histogram. I copy these code to the source code, but …it seems nothing happened.  
Does ROOT have some interface or some visuable graph or anything? Actually I know little about ROOT…

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 13, 2021, 6:03am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/11 "2021-10-13T06:03:43Z")

</div>

Ok, I’ll try to fix that.

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 13, 2021, 6:19am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/12 "2021-10-13T06:19:02Z")

</div>

Yes, you need to “draw” the histogram to show it. I’ve attached a modified version of the drift tube example…

[mdt.C](https://root-forum.cern.ch/uploads/short-url/iAD5Opk8u6y4BVTBHTPYazw3B1h.C) (4.3 KB)

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 15, 2021, 2:04am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/13 "2021-10-15T02:04:05Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 15, 2021, 2:07am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/14 "2021-10-15T02:07:47Z")

</div>

One more question. When electrons reach the anode, theoretically only a negative signal is generated, but the output diagram in the example has a positive signal. why…

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 15, 2021, 5:08am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/15 "2021-10-15T05:08:25Z")

</div>

You’re right, the induced current pulse is indeed negative. The signal shown on the plot is the convolution of the induced current pulse with a bipolar transfer function.

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 15, 2021, 6:00am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/16 "2021-10-15T06:00:41Z")

</div>

On some reference, the researcher simulated the signal like follow.

 ![2021-10-15 13-47-39 的屏幕截图](https://root-forum.cern.ch/uploads/default/original/3X/1/d/1d019c4d3fdfe5b95d600bff0c7ae8cb2c24e696.png)

Does it mean their result was not convoluted by the transfer function? I have used PlotElectronSignal() however coudn’t get the graph like that. Also, they use “the number of electrons” to describe the value of signal, but GARFIELD use unit fc, whether the program have some opinion to switch it?

Appreciated for your reply!

---

<div class="post-metadata">

**Author:** ![hschindl](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/h/977dab/32.png) [@hschindl](https://root-forum.cern.ch/u/hschindl)\
**Post date:** [October 15, 2021, 10:02am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/17 "2021-10-15T10:02:59Z")

</div>

These two figures were also made by convoluting the induced current with a transfer function.  
I don’t know off-hand what model/parameterisation of the transfer function was used in this thesis (and in these two plots in particular) but it might be different from the one we are using in the drift tube example.

There is no pre-implemented option to switch the units from fC to number of electrons but you could do the scaling yourself…

---

<div class="post-metadata">

**Author:** ![lyp](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/ecc23a/32.png) [@lyp](https://root-forum.cern.ch/u/lyp)\
**Post date:** [October 18, 2021, 12:19am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/18 "2021-10-18T00:19:57Z")

</div>

I got it, thank you Mr.

---

<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:** [November 1, 2021, 12:20am UTC](https://root-forum.cern.ch/t/how-to-keep-two-picture-on-one-canvas/47203/19 "2021-11-01T00:20:25Z")

</div>

Closed on November 1, 2021, 12:20am UTC

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