Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update source files for photon emitter, custom ptracer, and relevant examples #2

Merged
merged 21 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
eaa9313
Add source files for photon emitter and custom ptracer
andrewgait Oct 8, 2024
4c2b66d
Add MPhys directory with previous results and update scripts and note…
andrewgait Oct 9, 2024
2e1bca5
More updates to match current mitsuba3 master branch
andrewgait Oct 10, 2024
35b5afc
Update script for running scaling tests
andrewgait Oct 10, 2024
0f7be73
Tidy up Single_Emitter directory by moving images / csv / xml to sepa…
andrewgait Oct 11, 2024
9ec2e3a
Add previous work images to the png directory
andrewgait Oct 11, 2024
ea09a02
Update new single emitter test
andrewgait Oct 15, 2024
0446ea9
Merge branch 'dev' into 1-update-to-include-manchester-photon-emitter…
andrewgait Oct 15, 2024
d4ff195
Minor adjustments to xml and notebooks so that notebook size is reduced
andrewgait Oct 15, 2024
18efcd6
Save diff pngs to png directory; update gitignore
andrewgait Oct 16, 2024
4446c2d
Update "old" photon emitter on old file name to preserve history
andrewgait Oct 16, 2024
8088696
Rename file to photon_emitter_old
andrewgait Oct 16, 2024
e4b79d8
Address majority of review comments:
andrewgait Oct 17, 2024
20a71ad
This file isn't needed either
andrewgait Oct 17, 2024
7cbf451
More tidying up of the MPhys directory structure
andrewgait Oct 17, 2024
3d6bb04
Change to log-log plots in scaling / performance graphs
andrewgait Oct 17, 2024
b5a55f5
Update directory structure to keep copies of local and cluster data
andrewgait Oct 17, 2024
264c49e
Updates to separate timing plots into a different script, and run loc…
andrewgait Oct 22, 2024
f4d5a17
Add error box-plots to plots
andrewgait Oct 23, 2024
d824577
Add results from cluster runs
andrewgait Oct 24, 2024
9d45fa5
Add tests / experiments folder in single emitter directory and copy r…
andrewgait Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/.vs

# Jupyter
/.ipynb_checkpoints
*.ipynb_checkpoints

# Python
__pycache__
Expand All @@ -28,3 +28,10 @@ __pycache__
/docs/src/quickstart
/docs/src/generated
/docs/resources

# new png output / csv input
/MPhys/Single_Emitter/png/*intensity*
/MPhys/Single_Emitter/png/*diff*
/MPhys/Single_Emitter/png/*new*
*1000000*csv
/MPhys/Single_Emitter/cluster*
19 changes: 19 additions & 0 deletions MPhys/Direct import/bintxt/photons_geometry.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
9
-0.113022,1085.58,108.496
-0.13300599999999999,1086.568957,108.642851
-0.140442,1145.79,114.511
-0.14450033,1146.778534,114.661943
-0.102064,1061.52,106.092
-0.090696,1062.508767,106.241032
-0.160648,1190.17,118.944
-0.19853160000000003,1191.1671900000001,119.0086326
-0.0846522,1023.28,102.272
-0.1037399,1024.278464,102.3240078
-0.0926797,1040.91,104.033
-0.06807650000000001,1041.899362,104.176381
-0.108372,1075.37,107.476
-0.133239,1076.3681909999998,107.530734
-0.0847504,1023.49,102.294
-0.0357074,1024.485055,102.38036939999999
-0.160807,1190.52,118.979
-0.2047805,1191.516421,119.0511911
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
9,3.31874,-0.104399,106.604,1066.64,0.00247168,0.0478558,0.998851,270.5980936414827
10,3.31874,-0.136313,113.606,1136.73,0.0439212,0.0743342,0.996266,383.72751894873835
11,3.31874,-0.122911,110.665,1107.29,-0.0439221,0.125615,0.991106,402.6323520971465

10 changes: 5 additions & 5 deletions MPhys/Direct import/python input.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"id": "a07ccfc1",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -46,7 +46,7 @@
"\n",
"#load data from original G4 output (csv format)\n",
"column_names = [\"time (ps)\", \"x\", \"y\", \"z\", \"px\", \"py\", \"pz\", \"E (MeV)\"]\n",
"photon_data_full = pd.read_csv('../Single_Emitter/photons_with_wavelength.csv', names = column_names,nrows=100)\n",
"photon_data_full = pd.read_csv('../Single_Emitter/csv/photons_with_wavelength.csv', names = column_names,nrows=100)\n",
"initial_number_of_photons = photon_data_full.count()[0]\n",
"print(initial_number_of_photons)\n",
"\n",
Expand Down Expand Up @@ -81,7 +81,7 @@
"photon_detected.reset_index(drop=True, inplace= True)\n",
"\n",
"#Can be removed later. Outputs characteristics of saved photons.\n",
"photon_detected.to_csv('./photons_detected_spectral.csv' )\n",
"photon_detected.to_csv('./csv/photons_detected_spectral.csv' )\n",
"final_number_of_photons = photon_detected.count()[0]\n",
"fraction_detected = final_number_of_photons/initial_number_of_photons\n",
"print (\"{0:.4} of emitted photon in G4 are actually detected.\".format(fraction_detected))"
Expand Down Expand Up @@ -127,7 +127,7 @@
"metadata": {},
"outputs": [],
"source": [
"with open(\"photons_geometry.txt\",'w')as f:\n",
"with open(\"bintxt/photons_geometry.txt\",'w')as f:\n",
" f.write(f\"{len(x_position)}\\n\")\n",
" for x1,y1,z1,x2,y2,z2 in zip(x_position,y_position,z_position,x_target,y_target,z_target):\n",
" f.write(f\"{x1},{z1},{y1}\\n\")\n",
Expand Down Expand Up @@ -214,7 +214,7 @@
" },\n",
" 'photon1':{\n",
" 'type': 'photon_emitter',\n",
"# 'filename':'../Rich Geometry/photon_geometry.bin',\n",
"# 'filename':'../Rich Geometry/bintxt/photon_geometry.bin',\n",
" 'photon_list': photon_list\n",
" }\n",
"}\n",
Expand Down

Large diffs are not rendered by default.

371 changes: 44 additions & 327 deletions MPhys/Rich_Geometry/Convert.gdml file.ipynb

Large diffs are not rendered by default.

71 changes: 23 additions & 48 deletions MPhys/Rich_Geometry/One emitter for One photon .ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "04bb9e3f",
"metadata": {},
"outputs": [],
Expand All @@ -17,7 +17,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "d5fdc1cf",
"metadata": {},
"outputs": [],
Expand All @@ -27,18 +27,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "e408199c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.3136 of emitted photon in G4 are actually detected.\n"
]
}
],
"outputs": [],
"source": [
"#Values for linear interpolation.\n",
"wavelength_steps = [100, 200, 230, 270, 300, 330, 370, 400, 430, 470, 500, 530, 570, 600, 630, 670, 700, 1000]\n",
Expand All @@ -47,7 +39,7 @@
"\n",
"#load data from original G4 output (csv format)\n",
"column_names = [\"time (ps)\", \"x\", \"y\", \"z\", \"px\", \"py\", \"pz\", \"E (MeV)\"]\n",
"photon_data_full = pd.read_csv('/hepgpu6-data1/kevans/Photons_1000000_filtered.csv', names = column_names, nrows=100000)\n",
"photon_data_full = pd.read_csv('./test_data/Photons_1000000_filtered.csv', names = column_names, nrows=100000)\n",
"initial_number_of_photons = photon_data_full.count()[0]\n",
"\n",
"def ev_to_nm (energy):\n",
Expand Down Expand Up @@ -81,15 +73,15 @@
"photon_detected.reset_index(drop=True, inplace= True)\n",
"\n",
"#Can be removed later. Outputs characteristics of saved photons.\n",
"photon_detected.to_csv('./photons_detected_spectral.csv' )\n",
"photon_detected.to_csv('./test_data/test_photons_detected_spectral.csv' )\n",
"final_number_of_photons = photon_detected.count()[0]\n",
"fraction_detected = final_number_of_photons/initial_number_of_photons\n",
"print (\"{0:.4} of emitted photon in G4 are actually detected.\".format(fraction_detected))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "658d3f43",
"metadata": {},
"outputs": [],
Expand All @@ -113,35 +105,26 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"id": "3b5908ef",
"metadata": {},
"outputs": [],
"source": [
"tree = ET.parse('base_geometry.xml')\n",
"tree = ET.parse('test_data/base_geometry.xml')\n",
"root = tree.getroot()\n",
"for emitter in root.iter('emitter'):\n",
" print(emitter.attrib)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"id": "02589cc9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.0 2000.0 355.0\n",
"0.0 1000.0 600.0\n"
]
}
],
"outputs": [],
"source": [
"# parse the xml file to get information from the 1st mirror\n",
"tree = ET.parse('base_geometry.xml')\n",
"tree = ET.parse('test_data/base_geometry.xml')\n",
"root = tree.getroot()\n",
"for shape in root.iter('shape'):\n",
" if shape.get('id') == 'mirror_spherical':\n",
Expand All @@ -162,7 +145,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"id": "d3e1e8a5",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -208,18 +191,10 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"id": "8c77ea1c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3136\n"
]
}
],
"outputs": [],
"source": [
"# # calculate the distance between the photons and the mirror\n",
"# distance = []\n",
Expand All @@ -232,7 +207,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "01fe4d07",
"metadata": {},
"outputs": [],
Expand All @@ -241,7 +216,7 @@
"def add_spot_emitter(x, z, y, x_target, z_target, y_target, cutoff_angle):\n",
" \n",
" # parsing the xml file of the scene\n",
" tree = ET.parse('base_geometry.xml')\n",
" tree = ET.parse('test_data/base_geometry.xml')\n",
" root = tree.getroot()\n",
" # add a spot emitter to the scene\n",
" ### here, the y and z axis are switched (because the scene is rotated by 90 degrees?) ###\n",
Expand All @@ -253,21 +228,21 @@
" # modify the cutoff angle of the light\n",
" \n",
" # write it all on a new xml file.\n",
" tree.write(\"full_geometry.xml\")\n",
" tree.write(\"xml/full_geometry.xml\")\n",
"\n",
"# add spot emitters\n",
"add_spot_emitter(x_position, z_position, y_position, x_target, z_target, y_target, cutoff_angle)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"id": "f60c23ca",
"metadata": {},
"outputs": [],
"source": [
"# test cutoff values of the emitter\n",
"tree = ET.parse('full_geometry.xml')\n",
"tree = ET.parse('xml/full_geometry.xml')\n",
"root = tree.getroot()\n",
"for emitter in root.iter('emitter'):\n",
" for float in emitter.iter('float'):\n",
Expand All @@ -276,15 +251,15 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "05acad4a",
"metadata": {},
"outputs": [],
"source": [
"# %%time\n",
"# # render the scene\n",
"# mi.set_variant('scalar_rgb')\n",
"# scene = mi.load_file('full_geometry.xml')\n",
"# scene = mi.load_file('xml/full_geometry.xml')\n",
"# image = mi.render(scene)\n",
"# plt.figure(figsize = (20,20))\n",
"# plt.axis('off')\n",
Expand Down Expand Up @@ -316,7 +291,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
34 changes: 10 additions & 24 deletions MPhys/Rich_Geometry/Write_binary_file.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "12360dbe",
"metadata": {},
"outputs": [],
Expand All @@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"id": "4c1a30d3",
"metadata": {},
"outputs": [],
Expand All @@ -25,24 +25,10 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "91ea6570",
"metadata": {},
"outputs": [
{
"ename": "KeyboardInterrupt",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"Input \u001b[0;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 25>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 25\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(initial_number_of_photons):\n\u001b[1;32m 26\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m j \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;28mlen\u001b[39m(wavelength_steps)):\n\u001b[1;32m 27\u001b[0m \u001b[38;5;66;03m#find index in wavelength_steps corresponding to the photon.\u001b[39;00m\n\u001b[0;32m---> 28\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mphoton_data_full\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mloc\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mWavelength (nm)\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[38;5;241m<\u001b[39mwavelength_steps[j]:\n\u001b[1;32m 29\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m 30\u001b[0m \u001b[38;5;66;03m#Use linear interpolation to calculate QE at this wavelength.\u001b[39;00m\n",
"File \u001b[0;32m/hepgpu6-data1/yangyang/Mphys/miniconda/envs/MitsubaMphy/lib/python3.10/site-packages/pandas/core/indexing.py:1065\u001b[0m, in \u001b[0;36m_LocationIndexer.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 1063\u001b[0m key \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(\u001b[38;5;28mlist\u001b[39m(x) \u001b[38;5;28;01mif\u001b[39;00m is_iterator(x) \u001b[38;5;28;01melse\u001b[39;00m x \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m key)\n\u001b[1;32m 1064\u001b[0m key \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(com\u001b[38;5;241m.\u001b[39mapply_if_callable(x, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj) \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m key)\n\u001b[0;32m-> 1065\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_is_scalar_access\u001b[49m\u001b[43m(\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m)\u001b[49m:\n\u001b[1;32m 1066\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39m_get_value(\u001b[38;5;241m*\u001b[39mkey, takeable\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_takeable)\n\u001b[1;32m 1067\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_getitem_tuple(key)\n",
"File \u001b[0;32m/hepgpu6-data1/yangyang/Mphys/miniconda/envs/MitsubaMphy/lib/python3.10/site-packages/pandas/core/indexing.py:1148\u001b[0m, in \u001b[0;36m_LocIndexer._is_scalar_access\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 1145\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 1147\u001b[0m ax \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mobj\u001b[38;5;241m.\u001b[39maxes[i]\n\u001b[0;32m-> 1148\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28;43misinstance\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43max\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mMultiIndex\u001b[49m\u001b[43m)\u001b[49m:\n\u001b[1;32m 1149\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mFalse\u001b[39;00m\n\u001b[1;32m 1151\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(k, \u001b[38;5;28mstr\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m ax\u001b[38;5;241m.\u001b[39m_supports_partial_string_indexing:\n\u001b[1;32m 1152\u001b[0m \u001b[38;5;66;03m# partial string indexing, df.loc['2000', 'A']\u001b[39;00m\n\u001b[1;32m 1153\u001b[0m \u001b[38;5;66;03m# should not be considered scalar\u001b[39;00m\n",
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
]
}
],
"outputs": [],
"source": [
"#Values for linear interpolation.\n",
"wavelength_steps = [100, 200, 230, 270, 300, 330, 370, 400, 430, 470, 500, 530, 570, 600, 630, 670, 700, 1000]\n",
Expand All @@ -51,7 +37,7 @@
"\n",
"#load data from original G4 output (csv format)\n",
"column_names = [\"time (ps)\", \"x\", \"y\", \"z\", \"px\", \"py\", \"pz\", \"E (MeV)\"]\n",
"photon_data_full = pd.read_csv('/hepgpu6-data1/kevans/Photons_1000000_filtered.csv', names = column_names)\n",
"photon_data_full = pd.read_csv('./test_data/Photons_1000000_filtered.csv', names = column_names)\n",
"initial_number_of_photons = photon_data_full.count()[0]\n",
"\n",
"def ev_to_nm (energy):\n",
Expand Down Expand Up @@ -85,7 +71,7 @@
"photon_detected.reset_index(drop=True, inplace= True)\n",
"\n",
"#Can be removed later. Outputs characteristics of saved photons.\n",
"photon_detected.to_csv('./photons_detected_spectral.csv' )\n",
"photon_detected.to_csv('./test_data/photons_detected_spectral.csv' )\n",
"final_number_of_photons = photon_detected.count()[0]\n",
"fraction_detected = final_number_of_photons/initial_number_of_photons\n",
"print (\"{0:.4} of emitted photon in G4 are actually detected.\".format(fraction_detected))"
Expand Down Expand Up @@ -124,7 +110,7 @@
"source": [
"import struct\n",
"\n",
"with open(\"photon_geometry.bin\", \"wb\") as f:\n",
"with open(\"bintxt/photon_geometry.bin\", \"wb\") as f:\n",
" f.write(struct.pack(\"<Q\", len(x_position))) # Use 'Q' format for 64-bit unsigned integer (size_t)\n",
" for x1, y1, z1, x2, y2, z2 in zip(x_position, y_position, z_position, x_target, y_target, z_target):\n",
" f.write(struct.pack(\"<f\", x1))\n",
Expand All @@ -149,7 +135,7 @@
"\n",
"#load data from original G4 output (csv format)\n",
"column_names = [\"time (ps)\", \"x\", \"y\", \"z\", \"px\", \"py\", \"pz\", \"E (MeV)\"]\n",
"photon_data_full = pd.read_csv('/hepgpu6-data1/kevans/Photons_1000000_filtered.csv', names = column_names, nrows=10000)\n",
"photon_data_full = pd.read_csv('./test_data/Photons_1000000_filtered.csv', names = column_names, nrows=10000)\n",
"initial_number_of_photons = photon_data_full.count()[0]\n",
"\n",
"def ev_to_nm (energy):\n",
Expand Down Expand Up @@ -183,7 +169,7 @@
"photon_detected.reset_index(drop=True, inplace= True)\n",
"\n",
"#Can be removed later. Outputs characteristics of saved photons.\n",
"photon_detected.to_csv('./photons_detected_spectral.csv' )\n",
"photon_detected.to_csv('./test_data/photons_detected_spectral.csv' )\n",
"final_number_of_photons = photon_detected.count()[0]\n",
"fraction_detected = final_number_of_photons/initial_number_of_photons\n",
"print (\"{0:.4} of emitted photon in G4 are actually detected.\".format(fraction_detected))\n",
Expand Down Expand Up @@ -240,7 +226,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading