diff --git a/anasen_fem/garfield_sim.py b/anasen_fem/garfield_sim.py new file mode 100644 index 0000000..6d3b1c5 --- /dev/null +++ b/anasen_fem/garfield_sim.py @@ -0,0 +1,79 @@ +import ROOT +import os +import sys + +# 1. FIX: Manually load the Garfield library if it's not in the ROOT namespace +# Update this path to your actual installation location +garfield_lib_path = "/home/vsitaraman/garfieldpp/install/lib/libGarfield.so" + +if os.path.exists(garfield_lib_path): + ROOT.gSystem.Load(garfield_lib_path) +else: + print(f"CRITICAL ERROR: {garfield_lib_path} not found.") + sys.exit(1) + +# Verify access +try: + test_gas = ROOT.Garfield.MediumMagboltz() +except AttributeError: + print("ERROR: Garfield shared library loaded, but 'Garfield' namespace not found.") + print("Ensure Garfield was compiled with -DWITH_PYTHON=ON") + sys.exit(1) + +# --- 2. GAS SETUP (96% He, 4% CO2) --- +gas = ROOT.Garfield.MediumMagboltz() +gas_file = "He96_CO2_4_260Torr.gas" + +if not os.path.exists(gas_file): + print("Generating new Magboltz gas table (260 Torr)...") + gas.SetComposition("he", 96.0, "co2", 4.0) + gas.SetTemperature(293.15) + gas.SetPressure(260.0) # Pressure in Torr + + # Grid must cover the field at the 18um wire surface (~100kV/cm) + gas.SetFieldGrid(10., 150000., 20, True) + + # 10 iterations is usually plenty for a simple mix + gas.GenerateGasTable(10) + gas.WriteGasFile(gas_file) +else: + print(f"Loading existing gas table: {gas_file}") + gas.LoadGasFile(gas_file) + +# --- 3. FIELD MAP SETUP --- +fm = ROOT.Garfield.ComponentElmer() + +# Update these filenames to match your Elmer SIF output exactly +# Assuming ElmerGrid was run on 'wires2d' directory +fm.Initialise("wires2d/mesh.nodes", + "wires2d/mesh.elements", + "wires2d/mesh.boundary", + "wires2d/elfield_anasen.result", "mm") + +# Set the medium (Body 13 from your Gmsh script) +fm.SetMedium(0, gas) + +# --- 4. SENSOR AND DRIFT SETUP --- +sensor = ROOT.Garfield.Sensor() +sensor.AddComponent(fm) + +# Heavy Ion Drift (RKF) - Best for the general track +drift = ROOT.Garfield.DriftLineRKF() +drift.SetSensor(sensor) + +# Electron Avalanche (Microscopic) - Best for high-field gain +aval = ROOT.Garfield.AvalancheMicroscopic() +aval.SetSensor(sensor) + +# --- 5. EXECUTION --- +# Starting position (e.g., near the IC wires at r=23mm or closer to Anodes) +x0, y0, z0, t0 = 35.0, 0.0, 0.0, 0.0 + +print(f"Simulating heavy ion drift from r={x0}...") +drift.DriftIon(x0, y0, z0, t0) + +print(f"Simulating electron avalanche from r={x0}...") +# AvalancheElectron(x, y, z, t, energy, dx, dy, dz) +aval.AvalancheElectron(x0, y0, z0, t0, 0.1, 0.0, 0.0, 0.0) + +print("Simulation complete.") \ No newline at end of file diff --git a/anasen_fem/run.py b/anasen_fem/run.py index 69bf0b5..397de45 100755 --- a/anasen_fem/run.py +++ b/anasen_fem/run.py @@ -2,7 +2,7 @@ import code import os # val=-178.3 -val=17.83 +val=89.15 count=11 while val<178.3+0.1: print(val) @@ -17,10 +17,11 @@ while val<178.3+0.1: os.system("cp Field_output.png png/Field_ouput_z_%02d_%1.4f.png"%(count,val)) val=val+17.83 count = count + 1 + break -os.system("tar -cvzf wiress2d/mesh.tar.gz wires2d/mesh_files") -os.system("rm -rf wires2d/mesh_files/*") -os.system("tar -cvzf wires2d/sif.tar.gz wires2d/sif_files") -os.system("rm -rf wires2d/sif_files/*") -os.system("tar -cvzf wires2d/vtu.tar.gz wires2d/vtu_files") -os.system("rm -rf wires2d/vtu_files/*") \ No newline at end of file +# os.system("tar -cvzf wiress2d/mesh.tar.gz wires2d/mesh_files") +# os.system("rm -rf wires2d/mesh_files/*") +# os.system("tar -cvzf wires2d/sif.tar.gz wires2d/sif_files") +# os.system("rm -rf wires2d/sif_files/*") +# os.system("tar -cvzf wires2d/vtu.tar.gz wires2d/vtu_files") +# os.system("rm -rf wires2d/vtu_files/*") \ No newline at end of file diff --git a/anasen_fem/scalars.dat.names b/anasen_fem/scalars.dat.names index a9ef646..95b8d83 100755 --- a/anasen_fem/scalars.dat.names +++ b/anasen_fem/scalars.dat.names @@ -2,7 +2,7 @@ Metadata for SaveScalars file: ./scalars.dat Elmer version: 26.1 Elmer compilation date: 2026-03-15 Solver input file: wires2d.sif -File started at: 2026/04/02 14:22:52 +File started at: 2026/04/02 15:10:11 Variables in columns of matrix: 1: res: potential difference diff --git a/anasen_fem/wires_gmsh2d_bc.py b/anasen_fem/wires_gmsh2d_bc.py index c40a8d8..2877de2 100755 --- a/anasen_fem/wires_gmsh2d_bc.py +++ b/anasen_fem/wires_gmsh2d_bc.py @@ -55,10 +55,10 @@ xarra_1 = np.array([37*np.cos(k*i+offset) for i in np.arange(0,24)]) yarra_1 = np.array([37*np.sin(k*i+offset) for i in np.arange(0,24)]) #cathodes, plane 1 at -zmax/2 -kc=2*np.pi/24. +kc=2*np.pi/48. offsetc = -4*kc + 2*kc - np.pi/24 #-pi/4 -xarrc_1 = np.array([42*np.cos(kc*i+offsetc) for i in np.arange(0,24)]) -yarrc_1 = np.array([42*np.sin(kc*i+offsetc) for i in np.arange(0,24)]) +xarrc_1 = np.array([42*np.cos(kc*i+offsetc) for i in np.arange(0,48)]) +yarrc_1 = np.array([42*np.sin(kc*i+offsetc) for i in np.arange(0,48)]) #needle at plane 2 at zmax/2 xarr_needle_2 = np.array([0]) @@ -84,8 +84,8 @@ yarra_2 = np.array([37*np.sin(k*i+offset) for i in np.arange(0,24)]) #cathodes, plane2 at +zmax/2 offsetc = offsetc-3*kc -xarrc_2 = np.array([42*np.cos(kc*i+offsetc) for i in np.arange(0,24)]) -yarrc_2 = np.array([42*np.sin(kc*i+offsetc) for i in np.arange(0,24)]) +xarrc_2 = np.array([42*np.cos(kc*i+offsetc) for i in np.arange(0,48)]) +yarrc_2 = np.array([42*np.sin(kc*i+offsetc) for i in np.arange(0,48)]) direction_needle_x = xarr_needle_2 - xarr_needle direction_needle_y = yarr_needle_2 - yarr_needle @@ -144,16 +144,16 @@ for i, (xn, yn) in enumerate(zip(xloc_needle, yloc_needle)): needle.append(ndisk) #create Guard Wires (48 total) -for i, (xg, yg) in enumerate(zip(xloc_g, yloc_g)): +for i, (xg, yg, xc, yc) in enumerate(zip(xloc_g, yloc_g, xloc_c, yloc_c)): gdisk = gmsh.model.occ.addDisk(xg, yg, 0, wire_radius, wire_radius) guard_wires.append(gdisk) + cdisk = gmsh.model.occ.addDisk(xc, yc, 0, wire_radius, wire_radius) + cathode_wires.append(cdisk) #create IC Anode and Cathode Wires (24 total each) -for i, (xa, ya, xc, yc) in enumerate(zip(xloc_a, yloc_a, xloc_c, yloc_c)): +for i, (xa, ya) in enumerate(zip(xloc_a, yloc_a)): adisk = gmsh.model.occ.addDisk(xa, ya, 0, wire_radius, wire_radius) - cdisk = gmsh.model.occ.addDisk(xc, yc, 0, wire_radius, wire_radius) anode_wires.append(adisk) - cathode_wires.append(cdisk) # Place IC wires only if flag is True if include_ic_wires: diff --git a/run_sx3.sh b/run_sx3.sh new file mode 100755 index 0000000..1269c84 --- /dev/null +++ b/run_sx3.sh @@ -0,0 +1,76 @@ +#Alpha runs at different spacer positions +#rm results_run*.root +#root -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_009_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run09.root; +#root -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_001_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run01.root; +#root -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_002_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run02.root; +#root -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_003_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run03.root; +#root -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_004_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run04.root; + +#alpha+gas 27Al +export DATASET="26Al" +export flip180="0" +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_009_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run09.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_012_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run12.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_013_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run13.root; +#exit + +#protons+gas, 27Al +export flip180="1" +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_015_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run15.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_017_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run17.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_018_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run18.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_019_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run19.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_020_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run20.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_021_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run21.root; +#root -q -b -x ../ANASEN_analysis/data/27Al_Data/Run_022_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run22.root; +#exit + +#27Al reaction data +#root -b -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_051_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run51.root; +#root -b -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_078_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run78.root; +#root -b -q -l -x ../ANASEN_analysis/data/27Al_Data/Run_081_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run81.root; + +#root -l -x results_run19.root results_run12.root -e "new TBrowser" +#exit +export DATASET="17F" +export flip180="0" +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_005_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run05.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_006_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run06.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_007_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run07.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_008_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run08.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_009_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run09.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_010_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run10.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_011_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run11.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_012_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run12.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_013_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run13.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Source_014_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run14.root; + +#17F pulser runs +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/PulserRun_015_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run15.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/PulserRun_016_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run16.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/PulserRun_017_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run17.root; + +#17F alpha run with gas +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/SourceRun_018_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run18.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/SourceRun_019_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run19.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/SourceRun_020_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run20.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/SourceRun_021_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run21.root; + +#17F reaction data +export flip180="1" +#export source_vertex=-57.28; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_035_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run35.root; +export source_vertex=-8.28; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_036_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root resulrs_run36.root; +export source_vertex=-27.88; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_037_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run37.root; +export source_vertex=11.32; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_038_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run38.root; +export source_vertex=30.92; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_039_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run39.root; +export source_vertex=50.52; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_041_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run41.root; +export source_vertex=70.12; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_042_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run42.root; +export source_vertex=109.32; root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_043_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run43.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/ProtonRun_043_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run43.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Run_099_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run99.root; +#root -q -l -b -x ../ANASEN_analysis/data/17F_Data/Run_104_mapped.root -e 'tree->Process("MakeVertex.C+O")'; mv Analyzer_SX3.root results_run104.root; +#mv Analyzer_SX3.root results_run19.root; + +unset souce_vertex +unset DATASET +unset flip180