# Modification to source code

**URL:** <https://root-forum.cern.ch/t/modification-to-source-code/48978>\
**Category:** Garfield++\
**Created:** [February 28, 2022, 2:03pm UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978 "2022-02-28T14:03:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyq](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dyq/32/29543_2.png) [@dyq](https://root-forum.cern.ch/u/dyq)\
**Post date:** [February 28, 2022, 2:03pm UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978/1 "2022-02-28T14:03:37Z")

</div>

Hello!

I am currently trying to use garfield++ to simulate electron drifting motion using class AvalancheMC:  
**AvalancheMC drift;**  
**double x0 = …**  
**double y0 = …**  
**double z0 = …**  
**double t0 = …**  
**drift.DriftElectron(x0,y0,z0,t0)**  
I have loaded the field map exported from COMSOL and have also loaded gas table. The contour plot of the electric potential seems fine.  
No errors were shown when I ran it, but no electron drift lines were drawn in the pop up window. It seems electrons didn’t drift at all no matter which position it starts from.  
To understand what is going on, I tried to modify the source code “AvalancheMC.cc” in my _source_ directory so that it can print out my customized error messages and print out the electric field for certain coordinates, but the modification I made to the source code doesn’t have any effect when I re-run the simulation code:  
**cmake .**  
**make**  
**./example**  
Could you help me find the right way to do it?  
Are there any other ways to print out the electric field for a given position?  
I can provide more information if needed. Thanks a lot for any help you may give.

---

<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:** [February 28, 2022, 3:12pm UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978/2 "2022-02-28T15:12:04Z")

</div>

I think @hschindl can help.

---

<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:** [February 28, 2022, 3:20pm UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978/3 "2022-02-28T15:20:19Z")

</div>

If you modify the source files you need to run `make; make install` in your Garfield++ `build` folder.

To probe the electric field at a given position you can do something like this:

```auto
Medium* medium = nullptr;
double ex = 0., ey = 0., ez = 0., v = 0.;
int status = 0;
fm.ElectricField(0, 0, 0, ex, ey, ez, v, medium, status);
std::printf("E = (%15.8f, %15.8f %15.8f), V = %15.8f, status = %d\n", ex, ey, ez, v, status);

```

where `fm` is your `ComponentComsol` object.

---

<div class="post-metadata">

**Author:** ![dyq](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dyq/32/29543_2.png) [@dyq](https://root-forum.cern.ch/u/dyq)\
**Post date:** [February 28, 2022, 4:08pm UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978/4 "2022-02-28T16:08:45Z")

</div>

Thanks for your reply! These lines of code works. I will modify the source files and see whether I can figure out the issue. If I still cannot make the electron drift in the simulation and I want to ask some questions about it, should I add a new topic or just keep asking in this post?

---

<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 1, 2022, 5:51am UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978/5 "2022-03-01T05:51:38Z")

</div>

As you prefer. Maybe it’s easier to keep the same thread?

---

<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:** [March 15, 2022, 5:51am UTC](https://root-forum.cern.ch/t/modification-to-source-code/48978/6 "2022-03-15T05:51:55Z")

</div>

Closed on March 15, 2022, 5:51am UTC

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