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()