# How to Simulate charged-particle tracks using Heed. i have tryied many time but not getting result,

**URL:** <https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775>\
**Category:** Garfield++\
**Tags:** python, root\
**Created:** [September 25, 2024, 5:32am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775 "2024-09-25T05:32:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dk\_ntm](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/54ee81/32.png) [@Dk\_ntm](https://root-forum.cern.ch/u/Dk_ntm)\
**Post date:** [September 25, 2024, 5:32am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/1 "2024-09-25T05:32:24Z")

</div>

import ROOT  
import gmsh  
import ctypes  
import sys  
import math  
import numpy as np  
import matplotlib.pyplot as plt  
gmsh.initialize()

# Set relevant LEM parameters.

# LEM thickness in cm

lem\_th = 0.04;

# copper thickness

lem\_cpth = 0.0035;  
#LEM pitch in cm  
lem\_pitch = 0.07;

# X-width of drift simulation will cover between +/- axis\_x

axis\_x = 0.1;

# Y-width of drift simulation will cover between +/- axis\_y

axis\_y = 0.1;  
axis\_z = 0.25 + lem\_th / 2 + lem\_cpth;

# Define the medium.

ROOT.gSystem.Load(“/home/dileshwar/garfieldpp/install/lib/libmagboltz.so.11”)  
ROOT.gSystem.Load(“/home/dileshwar/garfieldpp/install/lib/libGarfield.so”)  
gas = ROOT.Garfield.MediumMagboltz()  
gas.SetTemperature(293.15) #Set the temperature [K]  
gas.SetPressure(740.)  
gas.EnableDrift()  
gas.SetComposition(“Ar”, 70., “co2”, 30.)#Specify the gas mixture (Ar/CO2 70:30)s.  
#gas.LoadIonMobility(‘/share/Garfield/Data/IonMobility\_Ar+\_Ar.txt’)  
gas.Initialise(True)

# Define the gas medium using Magboltz.

gas = ROOT.Garfield.MediumMagboltz()  
gas.SetTemperature(293.15) # in Kelvin  
gas.SetPressure(740.) # in Torr  
gas.EnableDrift() # Enable electron drift in the medium  
gas.SetComposition(“Ar”, 70., “co2”, 30.) # Set gas mixture composition (70% Ar, 30% CO2)

# Read in the 3D field map.

elm = ROOT.Garfield.ComponentElmer(  
“gemcell/mesh.header”, “gemcell/mesh.elements”, “gemcell/mesh.nodes”,  
“gemcell/dielectrics.dat”, “gemcell/gemcell.result”, “cm”  
)  
elm.EnablePeriodicityX() # Enable periodicity in X  
elm.EnableMirrorPeriodicityY() # Enable mirror periodicity in Y  
elm.SetMedium(0, gas) # Assign the medium to region 0

# Create a Sensor object.

sensor = ROOT.Garfield.Sensor()  
sensor.AddComponent(elm)  
sensor.SetArea(-axis\_x, -axis\_y, -axis\_z, axis\_x, axis\_y, axis\_z)  
track = ROOT.Garfield.TrackHeed()  
track.SetSensor(sensor) # Set the sensor for Heed  
track.SetParticle(“muon”) # You can change this to the desired particle type (e.g., “electron”, “muon”)  
track.SetEnergy(180.e9) # Set the particle energy (in eV). Adjust as needed.

drift = ROOT.Garfield.DriftLineRKF()  
drift.SetGainFluctuationsPolya(0., 20000.)  
drift.SetSensor(sensor)  
driftView = ROOT.Garfield.ViewDrift()  
cD = ROOT.TCanvas(“cD”, “”, 600, 600)  
driftView.SetCanvas(cD)

drift.EnablePlotting(driftView)  
track.EnablePlotting(driftView)  
zi = 0.5 \* lem\_th + lem\_cpth + 0.1 # Starting z position  
ri = (lem\_pitch / 2) \* np.random.uniform() # Random radius within the LEM pitch  
thetai = np.random.uniform() \* 2 \* np.pi # Random angle  
xi = ri \* np.cos(thetai) # x position based on random angle  
yi = ri \* np.sin(thetai)  
track.NewTrack(xi, yi, zi, 0., 0., 0., 0.) # Assume particle moving in -z direction

# Loop over the clusters along the track.

for cluster in track.GetClusters():  
# Loop over the electrons in the cluster.  
for electron in cluster.electrons:  
drift.DriftElectron(electron.x , electron.y, electron.z, electron.t)

# Draw the canvas to visualize drift lines and tracs

#cD.Draw()

# Visualize the drift lines and field using ViewFEMesh.

cGeom = ROOT.TCanvas(“cD”, “”)  
viewMesh = ROOT.Garfield.ViewFEMesh()  
viewMesh.SetArea(-axis\_x, -axis\_z, -axis\_y, axis\_x, axis\_z, axis\_y)  
viewMesh.SetCanvas(cGeom)  
viewMesh.SetComponent(elm)  
viewMesh.SetPlane(0, -1, 0, 0, 0, 0) # Set plane for plotting  
viewMesh.SetFillMesh(True)  
viewMesh.SetColor(1, ROOT.kGray)  
viewMesh.SetColor(2, ROOT.kYellow + 3)  
viewMesh.SetColor(3, ROOT.kYellow + 3)  
viewMesh.EnableAxes()  
viewMesh.SetXaxisTitle(“x (cm)”)  
viewMesh.SetYaxisTitle(“y (cm)”)  
viewMesh.SetViewDrift(driftView)  
viewMesh.Plot()  
cGeom.Draw()

---

<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:** [September 25, 2024, 5:50am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/2 "2024-09-25T05:50:21Z")

</div>

Hi,  
did you try one of the examples on the repository that use Heed? For instance this one?

> **[Examples/Heed/edep.py · master · garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/Heed/edep.py?ref_type=heads)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

Or this one:

> **[Examples/DriftTube/mdt.py · master · garfield / garfieldpp · GitLab](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/DriftTube/mdt.py?ref_type=heads)**
>
> http://garfieldpp.web.cern.ch/garfieldpp/

Or this one:

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

---

<div class="post-metadata">

**Author:** ![Dk\_ntm](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/54ee81/32.png) [@Dk\_ntm](https://root-forum.cern.ch/u/Dk_ntm)\
**Post date:** [September 25, 2024, 7:58am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/3 "2024-09-25T07:58:18Z")

</div>

Thank you for your quick reply! i haven’t use examples on the repository that use Heed. Can you tell me what is wrong in code, please give me suggestions.

---

<div class="post-metadata">

**Author:** ![Piet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/piet/32/12536_2.png) [@Piet](https://root-forum.cern.ch/u/Piet)\
**Post date:** [September 25, 2024, 8:39am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/4 "2024-09-25T08:39:36Z")

</div>

Can you tell us what is the error or the non-desired/expected result you obtained?  
Without your input files (“gemcell/mesh.header”, “gemcell/mesh.elements”, “gemcell/mesh.nodes”, “gemcell/dielectrics.dat”, “gemcell/gemcell.result”) we can not run your example.  
Kind regards  
Piet

---

<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:** [September 25, 2024, 8:45am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/5 "2024-09-25T08:45:51Z")

</div>

Indeed, you didn’t really gave us any hint as to what error you got. Having said that, looking at your code I believe the issue is that you didn’t load a gas file. `DriftLineRKF` (and `AvalancheMC`) need pre-computed tables of transport coefficients like drift velocity, diffusion coefficients, etc. to simulate electron drift lines.

---

<div class="post-metadata">

**Author:** ![Dk\_ntm](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/54ee81/32.png) [@Dk\_ntm](https://root-forum.cern.ch/u/Dk_ntm)\
**Post date:** [September 25, 2024, 9:15am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/6 "2024-09-25T09:15:17Z")

</div>

i am encountering with error  
MediumMagboltz::SetComposition: Ar/CO2 (70/30)  
ComponentElmer::Initialise:  
Read 97248 nodes and 67732 elements from file gemcell/mesh.header.  
Read potentials from file gemcell/gemcell.result.  
Set material 0 of 4 to eps 1.  
Set material 1 of 4 to eps 3.23.  
Set material 2 of 4 to eps 1e+10.  
Set material 3 of 4 to eps 1e+10.  
ComponentElmer::Initialise: Finished.  
ComponentElmer::Prepare:  
Caching the bounding boxes of all elements… done.  
Initialized tetrahedral tree.  
DriftLineRKF::SetGainFluctuationsPolya: Mean avalanche size set to 20000.

DriftLineRKF::GetVelocity:  
Cannot retrieve drift velocity at (-0.008794, 0.010352, 0.135514).  
DriftLineRKF::DriftLine:  
Cannot retrieve drift velocity at initial position (-0.008794, 0.010352, 0.135514).  
DriftLineRKF::GetVelocity:  
Cannot retrieve drift velocity at (-0.008634, 0.008446, 0.137157).  
DriftLineRKF::DriftLine:  
Cannot retrieve drift velocity at initial position (-0.008634, 0.008446, 0.137157).  
DriftLineRKF::GetVelocity:  
Cannot retrieve drift velocity at (-0.006294, -0.020242, 0.161458).  
DriftLineRKF::DriftLine:  
Cannot retrieve drift velocity at initial position (-0.006294, -0.020242, 0.161458).  
DriftLineRKF::GetVelocity:  
Cannot retrieve drift velocity at (-0.004516, -0.042723, 0.180503).  
DriftLineRKF::DriftLine:  
Cannot retrieve drift velocity at initial position (-0.004516, -0.042723, 0.180503).  
DriftLineRKF::GetVelocity:  
Cannot retrieve drift velocity at (-0.003966, -0.049413, 0.186216).  
DriftLineRKF::DriftLine:  
Cannot retrieve drift velocity at initial position (-0.003966, -0.049413, 0.186216).

---

<div class="post-metadata">

**Author:** ![Piet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/piet/32/12536_2.png) [@Piet](https://root-forum.cern.ch/u/Piet)\
**Post date:** [September 25, 2024, 9:29am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/7 "2024-09-25T09:29:37Z")

</div>

> [@Dk\_ntm](#):
>
> DriftLineRKF::GetVelocity:  
> Cannot retrieve drift velocity at (-0.008794, 0.010352, 0.135514).

Indeed, as @hschindl pointed out, this is a typical error message you get when you do not have set the correct gas medium for DriftLineRKF. He also pointed you to the examples, because for instance [here](https://gitlab.cern.ch/garfield/garfieldpp/-/blob/master/Examples/DriftTube/mdt.py#L9-L11) you can see that before using DriftLineRKF one loads a gasfile.

---

<div class="post-metadata">

**Author:** ![Dk\_ntm](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/d/54ee81/32.png) [@Dk\_ntm](https://root-forum.cern.ch/u/Dk_ntm)\
**Post date:** [September 25, 2024, 9:50am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/8 "2024-09-25T09:50:02Z")

</div>

Thanks for support & understanding 🙏

---

<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:** [October 9, 2024, 9:51am UTC](https://root-forum.cern.ch/t/how-to-simulate-charged-particle-tracks-using-heed-i-have-tryied-many-time-but-not-getting-result/61775/9 "2024-10-09T09:51:00Z")

</div>

Closed on October 9, 2024, 9:51am UTC

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