Create the TrackHeed object for primary ionization
track = ROOT.Garfield.TrackHeed()
track.SetParticle(‘muon’) # Define the particle type (muon)
track.SetEnergy(180.e9) # Set particle energy (180 GeV for muon)
track.SetSensor(sensor)
track.Initialise(gas, True)# Attach the sensor to TrackHeed
track.EnableElectricField()
aval = ROOT.Garfield.AvalancheMicroscopic()
aval.SetSensor(sensor)
#aval.SetCollisionSteps(100)
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)
yi = ri * np.sin(thetai)
Launch the charged particle through Heed.
track.NewTrack(xi, yi, zi, 0., 0., 0., 0.)
Retrieve the clusters of ionization produced by Heed
clusters = track.GetClusters()
print(“Number of ionization clusters:”, len(clusters))
Iterate over each cluster
for cluster in clusters:
# Instead of getting number of electrons, directly process the cluster
n_electrons = cluster.GetElectrons() # Assuming this method exists to get electron details
if n_electrons is not None:
print(f"Cluster contains {len(n_electrons)} electrons.")
# Loop over each electron in this cluster
for electron in n_electrons:
# Retrieve the position of the electron
x_e, y_e, z_e, t_e = electron.GetPositionX(), electron.GetPositionY(), electron.GetPositionZ(), electron.GetTime()
# Optionally, you can print the position and time of the electron
print(f"Electron: Position: ({x_e}, {y_e}, {z_e}), Time: {t_e}")
# Simulate the avalanche for each electron
aval.AvalancheElectron(x_e, y_e, z_e, t_e, 0., 0., 0., 0.)
print(“… avalanche complete with”, aval.GetNumberOfElectronEndpoints(), “electron tracks.\n”) when i running this code i’m encountering with error
AttributeError Traceback (most recent call last)
Cell In[22], line 4
1 # Iterate over each cluster
2 for cluster in clusters:
3 # Instead of getting number of electrons, directly process the cluster
----> 4 n_electrons = cluster.GetElectrons() # Assuming this method exists to get electron details
5 if n_electrons is not None:
6 print(f"Cluster contains {len(n_electrons)} electrons.")
AttributeError: ‘Cluster’ object has no attribute ‘GetElectrons’
please someone help me my code is correct or incorrect? give some suggestions. I’m totally beginner in Garfield++