# Problems in ViewDrift and ViewSignal

**URL:** <https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124>\
**Category:** Garfield++\
**Tags:** root\
**Created:** [March 13, 2025, 8:41am UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124 "2025-03-13T08:41:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/58f4c7/32.png) [@kaka](https://root-forum.cern.ch/u/kaka)\
**Post date:** [March 13, 2025, 8:41am UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124/1 "2025-03-13T08:41:28Z")

</div>

Hi everyone,  
I am beginner of Garfieldpp.I tried to imitate Silicon in the example to output a gif of the drift lines and signals. I used the ComponentTcad2d and TrackHeed classes in the simulation, but the output remains the same instead of being updated.  
I attach the Plot code and the result.

```auto
double t = 0.;
double dt = 0.1;
const unsigned int nFrames = 100;
for (unsigned int i = 0; i < 100; ++i) {
  vDrift.Clear();
  drift.SetTimeWindow(t, t + dt);
  vDrift.Plot2d(true, true);
  vSignal.PlotSignal("anode");
  gSystem->ProcessEvents();
  constexpr bool gif = true;
  if (!gif) {
      char filename[50];
      sprintf(filename, "frames/frame_%03d.png", i);
      canvas.SaveAs(filename);
  } else {
  if (i == nFrames - 1) {
      canvas.Print("movie.gif++");
  } else {
      canvas.Print("movie.gif+3");
  }`Preformatted text`
  }
std::cout << "Drift time window: [" << t << ", " << t + dt << "] ns\n";
t += dt;
}
    std::cout << "End of GIF" << "\n";

```

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/7/b/7b4162731f3f1f3f5aebc6436d8ac30ac0e800ee.png)

---

<div class="post-metadata">

**Author:** ![StephanH](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@StephanH](https://root-forum.cern.ch/u/StephanH)\
**Post date:** [March 13, 2025, 9:14am UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124/2 "2025-03-13T09:14:13Z")

</div>

Hello! @hschindl will surely be able to help here.

---

<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:** [March 13, 2025, 4:24pm UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124/3 "2025-03-13T16:24:44Z")

</div>

Hi,  
you’re missing a line like

```cpp
drift.ResumeAvalanche();

```

after

```cpp
drift.SetTimeWindow(t, t + dt);

```

---

<div class="post-metadata">

**Author:** ![kaka](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/k/58f4c7/32.png) [@kaka](https://root-forum.cern.ch/u/kaka)\
**Post date:** [March 14, 2025, 1:38am UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124/4 "2025-03-14T01:38:22Z")

</div>

Thanks for your reply!  
I added this code as you suggested, but it doesn’t seem to work and the output is still the same as before.

---

<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:** [March 18, 2025, 6:35am UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124/6 "2025-03-18T06:35:08Z")

</div>

Hi,  
sorry for the late reply. The drift of the electrons and holes already happens in this loop:

```cpp
track.NewTrack(x0, y0, z0, t0, 0., -1, 0.);
for (const auto& cluster : track.GetClusters()) {
  drift.SetElectronSignalScalingFactor(cluster.n);
  drift.DriftElectron(cluster.x, cluster.y, cluster.z, cluster.t);
  drift.SetHoleSignalScalingFactor(cluster.n);
  drift.DriftHole(cluster.x, cluster.y, cluster.z, cluster.t);
}

```

So the drift line calculation and signal are already once this loop is finished.  
If you want to create an animation, you need to call `AddElectron`, `AddHole` instead of `DriftElectron`, `DriftHole` and then use `SetTimeWindow`, `ResumeAvalanche` in a subsequent loop to simulate the drift, as done in this example:

> **[Examples/Silicon/planar\_movie.C · master · garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/Silicon/planar_movie.C?ref_type=heads)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

There is however a catch; if you do that, you cannot do the scaling of the signal (`SetElectronSignalScalingFactor`, `SetHoleSignalScalingFactor`) the way it’s done in your program. I’ll need to implement an additional functionality to set a weighting factor for each electron/hole.

---

<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:** [April 1, 2025, 6:35am UTC](https://root-forum.cern.ch/t/problems-in-viewdrift-and-viewsignal/63124/7 "2025-04-01T06:35:52Z")

</div>

Closed on April 1, 2025, 6:35am UTC

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