# Interface of geant4 and garfield

**URL:** <https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293>\
**Category:** Garfield++\
**Created:** [January 27, 2021, 1:35pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293 "2021-01-27T13:35:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [January 27, 2021, 1:35pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/1 "2021-01-27T13:35:36Z")

</div>

@hschindl  
hi, i have installed the garfield and run its example geant4garfieldinterface. and also produced some graphs from the geant4 example TestEm5.  
but now i want to interface and want to use the output of geant4 in the garfield as input. how to do that? please need your help.!

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [January 29, 2021, 1:46pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/2 "2021-01-29T13:46:59Z")

</div>

waiting for your answer dear…

---

<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:** [January 29, 2021, 3:14pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/3 "2021-01-29T15:14:37Z")

</div>

It looks like a very similar question was asked and answered in this forum:

> [@Garfield++ documentation](https://root-forum.cern.ch/t/garfield-documentation/18037/2):
>
> [Garfield++ – simulation of tracking detectors](http://garfieldpp.web.cern.ch)[Garfield - simulation of gaseous detectors](http://garfield.web.cern.ch)[ROOT Forum -\> Search -\> garfield](https://root-forum.cern.ch/search?q=garfield%20order%3Alatest)

---

<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:** [January 31, 2021, 10:07am UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/4 "2021-01-31T10:07:18Z")

</div>

Hello,  
apologies for the late reply. You can find an discussion of different options for interfacing Geant4 and Garfield++ on the [Garfield++ website](https://garfieldpp.web.cern.ch/garfieldpp/examples/geant4-interface/). Which one to use depends very much on your application and what results you would like to obtain from your simulation.

I saw that you also sent an email on the same topic, so let’s perhaps follow this up by email…

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 1, 2021, 3:21pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/5 "2021-02-01T15:21:07Z")

</div>

thanks dear yes i have seen the garfield forum. and it was helpful. i got some hint. but i want to reproduce the graphs of this paper which i have uploaded here.

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 1, 2021, 3:38pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/6 "2021-02-01T15:38:34Z")

</div>

it cannot be uploaded the file is too big i’ll send you through email.

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 2, 2021, 1:21pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/7 "2021-02-02T13:21:50Z")

</div>

did you recieve my mail with the paper of which i want to regenrate the plots?  
if not can you provide me another mailing of your’s because on this mailing address the size of file is bigger and its rejecting.

---

<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 2, 2021, 1:40pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/8 "2021-02-02T13:40:46Z")

</div>

No, I didn’t get your mail. Can you upload it to a file-sharing platform (Dropbbox, Google Drive, etc.)? But why is the file so big if it’s only a plot?

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 4, 2021, 3:17pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/9 "2021-02-04T15:17:14Z")

</div>

haha… dear its a paper of which i want to re-generate the plots. here is its link please.  
[https://indico.cern.ch/event/667256/contributions/2731974/](https://indico.cern.ch/event/667256/contributions/2731974/)

---

<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 4, 2021, 3:31pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/10 "2021-02-04T15:31:59Z")

</div>

That is exactly the example described on the Garfield++ website:

[https://garfieldpp.web.cern.ch/garfieldpp/examples/geant4-interface/](https://garfieldpp.web.cern.ch/garfieldpp/examples/geant4-interface/)

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 5, 2021, 8:00am UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/11 "2021-02-05T08:00:12Z")

</div>

that means through the TestEm8 i have to do this.? and definitely i need your help in this regard, and will ask you please.

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 9, 2021, 2:46pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/12 "2021-02-09T14:46:51Z")

</div>

[@heinrich.schindler@cern.ch](mailto:heinrich.schindler@cern.ch) i’m stuck. i don’t know how to start. kindly help me i’m already very late dear.

---

<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:** [February 9, 2021, 3:24pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/13 "2021-02-09T15:24:39Z")

</div>

@hschindl Note that currently, the official [“Garfield++ → Geant4 interface”](https://garfieldpp.web.cern.ch/garfieldpp/examples/geant4-interface/) web page contains links to nonexistent web pages and two examples “.zip” files “at the bottom of the page”.

---

<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 10, 2021, 10:53pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/14 "2021-02-10T22:53:29Z")

</div>

Thanks a lot! Should be fixed now…

---

<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 10, 2021, 11:06pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/15 "2021-02-10T23:06:48Z")

</div>

Hi,  
sorry, I’m not particularly familiar with the Geant4/Garfield++ example myself and I must admit I’ve not looked into it for a while. I just gave it a go to run the macro provided on

> **[Examples/Geant4GarfieldInterface · master · garfield / garfieldpp](https://gitlab.cern.ch/garfield/garfieldpp/-/tree/master/Examples/Geant4GarfieldInterface)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

which is the example referred to on the Garfield++ website and in the presentation you sent.  
For me it seems to work fine, in that it runs over a handful of events and produces a ROOT output file with a tree and histograms of deposited energy, avalanche size and other variables scored in the simulation.  
Does this macro/program not work for you? At which point do you get stuck?

---

<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:** [February 11, 2021, 12:09pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/16 "2021-02-11T12:09:01Z")

</div>

@hschindl Now, [both links to “examples” point to the same source code](https://gitlab.cern.ch/garfield/garfieldpp/-/tree/master/Examples/Geant4GarfieldInterface). However, I cannot find any detailed description of how to (properly) modify it to switch the version (and the original “.zip” files, different for each of them, are missing, so one cannot check it).

---

<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 11, 2021, 1:14pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/17 "2021-02-11T13:14:43Z")

</div>

Yes, that’s true. I need to ask the author of the example about that…

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 14, 2021, 1:15pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/18 "2021-02-14T13:15:16Z")

</div>

thanks dear.

---

<div class="post-metadata">

**Author:** ![ahmer\_k](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ahmer_k/32/24214_2.png) [@ahmer\_k](https://root-forum.cern.ch/u/ahmer_k)\
**Post date:** [February 14, 2021, 1:19pm UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/19 "2021-02-14T13:19:29Z")

</div>

sorry i answering this much late. yes @hschindl@Wile_E_Coyote saying right in its post. as i have seen the presentation i only come to know i have to prepare the TestEm8 of electromagnetic example of Geant4. but what further how to produce plots or change gas mixture and how to produce graphs from it using root. that what i didn’t understand @hschindl !

---

<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 15, 2021, 8:41am UTC](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293/20 "2021-02-15T08:41:09Z")

</div>

Hi,  
the example on the repository uses a geometry consisting of a lead absorber block and a drift tube. As explained on the website, there are different options for simulating ionization in the drift tube. By default, the example will use the Geant4 `PAIPhot` model but let Garfield++ (Heed) handle the resulting electrons with less than 1 keV energy. I believe you can change these settings in `physics.mac`.

On the “Garfield” side of the interface, the gas mixture is defined in the function `InitializePhysics` of the class `GarfieldPhysics`.  
The Geant4 geometry description is done in `GarfieldDetectorConstruction::DefineVolumes`.  
If you want to change the gas composition, you will need to do it in both places to be consistent.

The histograms and ntuples to be filled are created in the class `GarfieldRunAction` and they are filled in `GarfieldEventAction::EndOfEventAction`. They are saved to a `.root` file which for a quick inspection you can open with the ROOT browser.

Can you provide a bit more details on what exactly you would like to simulate? Maybe there is an easier solution…

[Next page](https://root-forum.cern.ch/t/interface-of-geant4-and-garfield/43293.md?page=2)
