From f001bb21e0fac532815b25bb08645f35ead55823 Mon Sep 17 00:00:00 2001 From: James Szalkie Date: Tue, 26 May 2026 10:55:34 -0400 Subject: [PATCH] fixed memory issues and dual plotting --- ELoss/E_vs_x_proton.dat | 1000 ++++++++++++++++++------------------- ELoss/PCEnergyAnalysis.py | 332 +++++++++++- 2 files changed, 811 insertions(+), 521 deletions(-) diff --git a/ELoss/E_vs_x_proton.dat b/ELoss/E_vs_x_proton.dat index 19b2de2..61524a0 100644 --- a/ELoss/E_vs_x_proton.dat +++ b/ELoss/E_vs_x_proton.dat @@ -1,501 +1,501 @@ Distance_cm Energy_MeV --0.0 33.0 -29.698539147985517 32.933887775551106 -59.34840915890574 32.867775551102206 -88.94958934093333 32.80166332665331 -118.50205979899215 32.73555110220441 -148.0058005607748 32.66943887775551 -177.46079078755548 32.60332665330662 -206.86700960670004 32.537214428857716 -236.22443611150226 32.47110220440882 -265.53304936106696 32.40498997995992 -294.79282838014143 32.33887775551103 -324.00375215899635 32.27276553106213 -353.1657996532586 32.20665330661323 -382.2789497837747 32.14054108216433 -411.3431814364727 32.07442885771543 -440.35847346219265 32.00831663326654 -469.3248046765606 31.94220440881764 -498.24215385982154 31.876092184368744 -527.1104997566963 31.809979959919847 -555.9298210762291 31.743867735470946 -584.7000964916286 31.67775551102205 -613.421304640123 31.611643286573152 -642.0934241227984 31.545531062124255 -670.7164335044446 31.479418837675357 -699.2903113133973 31.41330661322646 -727.8150360413819 31.34719438877756 -756.2905861433475 31.281082164328662 -784.7169400373159 31.214969939879765 -813.0940761042139 31.148857715430868 -841.4219726877116 31.08274549098197 -869.7006080940591 31.016633266533074 -897.9299605919233 30.950521042084173 -926.1100084122152 30.884408817635276 -954.2407297479318 30.81829659318638 -982.3221027539823 30.75218436873748 -1010.3541055470193 30.686072144288584 -1038.3367162052687 30.619959919839687 -1066.2699127683582 30.553847695390786 -1094.1536732371399 30.48773547094189 -1121.9879755735235 30.42162324649299 -1149.7727977002955 30.355511022044094 -1177.5081175009434 30.289398797595197 -1205.1942122319128 30.2232865731463 -1232.832893424255 30.1571743486974 -1260.4256519716414 30.091062124248502 -1287.9724232673782 30.024949899799605 -1315.4731427428615 29.958837675350708 -1342.927745867937 29.89272545090181 -1370.3361681512577 29.826613226452913 -1397.6983451406443 29.760501002004013 -1425.014212423436 29.694388777555115 -1452.2837056268577 29.628276553106218 -1479.5067604183716 29.56216432865732 -1506.6833125060366 29.496052104208424 -1533.813297638866 29.429939879759523 -1560.8966516071807 29.363827655310626 -1587.933310242973 29.29771543086173 -1614.9232094202587 29.23160320641283 -1641.8662850554354 29.165490981963934 -1668.7624731076385 29.099378757515037 -1695.6117095790994 29.033266533066136 -1722.4139305154952 28.96715430861724 -1749.1690720063136 28.901042084168342 -1775.8770701852027 28.834929859719445 -1802.5378612303277 28.768817635270548 -1829.1513813647261 28.70270541082165 -1855.7175668566638 28.63659318637275 -1882.2363540199842 28.570480961923852 -1908.7076792144705 28.504368737474955 -1935.1314788461948 28.438256513026058 -1961.507689367872 28.37214428857716 -1987.836247279214 28.306032064128264 -2014.1170891272832 28.239919839679363 -2040.3501515068401 28.173807615230466 -2066.535371060704 28.10769539078157 -2092.672684480099 28.04158316633267 -2118.7620285050066 27.975470941883774 -2144.8033399245164 27.909358717434877 -2170.7965563272287 27.843246492985976 -2196.741615485756 27.77713426853708 -2222.638454463638 27.711022044088182 -2248.487010231546 27.644909819639285 -2274.2872198110445 27.578797595190387 -2300.0390202749404 27.51268537074149 -2325.7423487476317 27.44657314629259 -2351.39714240545 27.380460921843692 -2377.0033384770154 27.314348697394795 -2402.560874243579 27.248236472945898 -2428.0696870393685 27.182124248497 -2453.5297142519357 27.1160120240481 -2478.9408933224963 27.049899799599203 -2504.303161746281 26.983787575150306 -2529.616457072875 26.91767535070141 -2554.880716906562 26.85156312625251 -2580.095878906666 26.785450901803614 -2605.261880787894 26.719338677354713 -2630.3786603206736 26.653226452905816 -2655.446155331499 26.58711422845692 -2680.4643037032665 26.52100200400802 -2705.4330433756145 26.454889779559124 -2730.352312345261 26.388777555110227 -2755.2220486663437 26.322665330661327 -2780.04219045075 26.25655310621243 -2804.812675868461 26.190440881763532 -2829.5334431478823 26.124328657314635 -2854.2044305761774 26.058216432865738 -2878.8255764996034 25.99210420841684 -2903.3968193238425 25.92599198396794 -2927.918097514331 25.859879759519043 -2952.3893495965954 25.793767535070145 -2976.810514163705 25.727655310621248 -3001.1815307104935 25.66154308617235 -3025.5023387757533 25.595430861723454 -3049.7728771086977 25.529318637274553 -3073.9930845203135 25.463206412825656 -3098.162899883695 25.39709418837676 -3122.282262134362 25.33098196392786 -3146.3511102705857 25.264869739478964 -3170.3693833537104 25.198757515030064 -3194.337020508472 25.132645290581166 -3218.253960923324 25.06653306613227 -3242.1201438507524 25.000420841683372 -3265.9355086075943 24.934308617234475 -3289.6999945753555 24.868196392785578 -3313.4135412005257 24.802084168336677 -3337.07608799489 24.73597194388778 -3360.687574535847 24.669859719438882 -3384.247940466719 24.603747494989985 -3407.7571254970603 24.537635270541088 -3431.21506940297 24.47152304609219 -3454.6217120273996 24.40541082164329 -3477.976993280454 24.339298597194393 -3501.280853139706 24.273186372745496 -3524.533231650495 24.2070741482966 -3547.7340689262305 24.1409619238477 -3570.8833051486936 24.074849699398804 -3593.9808805683388 24.008737474949903 -3617.0267355045858 23.942625250501006 -3640.020810346125 23.87651302605211 -3662.963045551209 23.810400801603212 -3685.8533816479444 23.744288577154315 -3708.6917598216746 23.678176352705417 -3731.478121534972 23.612064128256517 -3754.2124077232756 23.54595190380762 -3776.894559175513 23.479839679358722 -3799.5245167519824 23.413727454909825 -3822.1022213846345 23.347615230460928 -3844.62761407736 23.281503006012027 -3867.100635906262 23.21539078156313 -3889.521228019948 23.149278557114233 -3911.889331639798 23.083166332665336 -3934.204888060244 23.01705410821644 -3956.4678386490427 22.95094188376754 -3978.6781248475504 22.88482965931864 -4000.835688170987 22.818717434869743 -4022.940470208712 22.752605210420846 -4044.9924126244878 22.68649298597195 -4066.9914571567415 22.62038076152305 -4088.937545618831 22.554268537074154 -4110.830619899304 22.488156312625254 -4132.670621962155 22.422044088176357 -4154.457493847083 22.35593186372746 -4176.191177669747 22.289819639278562 -4197.871615622014 22.223707414829665 -4219.498749972214 22.157595190380768 -4241.072523065382 22.091482965931867 -4262.592877323503 22.02537074148297 -4284.059755245763 21.959258517034073 -4305.473099408782 21.893146292585175 -4326.832853075756 21.827034068136278 -4348.138959720929 21.76092184368738 -4369.3913622762075 21.69480961923848 -4390.590003607196 21.628697394789583 -4411.734826658197 21.562585170340686 -4432.825774452426 21.49647294589179 -4453.862790092243 21.43036072144289 -4474.84581675937 21.364248496993994 -4495.774797715111 21.298136272545094 -4516.649676300566 21.232024048096196 -4537.470395936849 21.1659118236473 -4558.236900125293 21.099799599198402 -4578.949132447662 21.033687374749505 -4599.607036566355 20.967575150300604 -4620.210556224604 20.901462925851707 -4640.75963524668 20.83535070140281 -4661.254217538082 20.769238476953912 -4681.694247085738 20.703126252505015 -4702.079667958189 20.637014028056118 -4722.410424305778 20.570901803607217 -4742.686460360833 20.50478957915832 -4762.907720437851 20.438677354709423 -4783.074148933674 20.372565130260526 -4803.185690327662 20.30645290581163 -4823.242289181865 20.24034068136273 -4843.243890183165 20.17422845691383 -4863.190438755917 20.108116232464933 -4883.081880353256 20.042004008016036 -4902.918159844812 19.97589178356714 -4922.699222183827 19.909779559118242 -4942.425012407296 19.843667334669345 -4962.095475636121 19.777555110220444 -4981.710557075248 19.711442885771547 -5001.270202013817 19.64533066132265 -5020.774355825288 19.579218436873752 -5040.22296396758 19.513106212424855 -5059.615971983196 19.446993987975958 -5078.953325499351 19.380881763527057 -5098.234970228088 19.31476953907816 -5117.460851966399 19.248657314629263 -5136.630916596335 19.182545090180366 -5155.745110085117 19.11643286573147 -5174.803378485236 19.05032064128257 -5193.80566793456 18.98420841683367 -5212.751924656419 18.918096192384773 -5231.642094959707 18.851983967935876 -5250.476125238964 18.78587174348698 -5269.253961974459 18.71975951903808 -5287.975551732269 18.65364729458918 -5306.6408413661375 18.587535070140284 -5325.249778248604 18.521422845691387 -5343.802309623175 18.45531062124249 -5362.298382373392 18.389198396793592 -5380.7379434690665 18.323086172344695 -5399.120939966323 18.256973947895794 -5417.447319007647 18.190861723446897 -5435.717027821926 18.124749498998 -5453.9300137244845 18.058637274549103 -5472.086224117112 17.992525050100205 -5490.185606488088 17.92641282565131 -5508.228108412204 17.860300601202407 -5526.213677550774 17.79418837675351 -5544.142261651646 17.728076152304613 -5562.013808549201 17.661963927855716 -5579.828266164356 17.59585170340682 -5597.585582504554 17.52973947895792 -5615.285705663746 17.46362725450902 -5632.928583822376 17.397515030060124 -5650.514165247356 17.331402805611226 -5668.04239829203 17.26529058116233 -5685.513231396143 17.199178356713432 -5702.9266133264655 17.133066132264535 -5720.28249326522 17.066953907815634 -5737.580820226112 17.000841683366737 -5754.821542965892 16.93472945891784 -5772.004610327597 16.868617234468942 -5789.1299712404825 16.802505010020045 -5806.197574719937 16.736392785571145 -5823.207369867393 16.670280561122247 -5840.159305870241 16.60416833667335 -5857.053332001721 16.538056112224453 -5873.889397620817 16.471943887775556 -5890.667452172145 16.40583166332666 -5907.387445185827 16.339719438877758 -5924.049326277364 16.27360721442886 -5940.653045147503 16.207494989979963 -5957.198551582089 16.141382765531066 -5973.685795451918 16.07527054108217 -5990.114726712581 16.00915831663327 -6006.485295404288 15.943046092184371 -6022.7974516517115 15.876933867735472 -6039.051145776818 15.810821643286575 -6055.246328576608 15.744709418837678 -6071.382950804004 15.678597194388779 -6087.4609628898315 15.612484969939882 -6103.4803153485955 15.546372745490984 -6119.4409587782675 15.480260521042085 -6135.342843860052 15.414148296593188 -6151.185921358156 15.348036072144291 -6166.9701421195405 15.281923847695392 -6182.695457073673 15.215811623246495 -6198.361817232265 15.149699398797598 -6213.969173689 15.083587174348699 -6229.517477619259 15.017474949899801 -6245.006680279835 14.951362725450904 -6260.436733008635 14.885250501002005 -6275.807587224379 14.819138276553108 -6291.1191944262855 14.753026052104211 -6306.371506193751 14.686913827655312 -6321.564474186018 14.620801603206415 -6336.698050402029 14.554689378757518 -6351.772187083139 14.488577154308619 -6366.78683627359 14.422464929859721 -6381.741949917212 14.356352705410824 -6396.637480036148 14.290240480961925 -6411.47337873047 14.224128256513028 -6426.249598177784 14.15801603206413 -6440.966090632828 14.091903807615232 -6455.6228084270615 14.025791583166335 -6470.21970396824 13.959679358717437 -6484.756729739988 13.893567134268539 -6499.2338383013575 13.827454909819641 -6513.650982286377 13.761342685370744 -6528.008114403596 13.695230460921845 -6542.305187435611 13.629118236472948 -6556.542154238595 13.563006012024049 -6570.7189677418055 13.496893787575152 -6584.835581097525 13.430781563126255 -6598.89194772431 13.364669338677356 -6612.888020945308 13.298557114228458 -6626.823753944136 13.232444889779561 -6640.699099975233 13.166332665330662 -6654.514012363323 13.100220440881765 -6668.268444502865 13.034108216432868 -6681.962349857501 12.967995991983969 -6695.595681959485 12.901883767535072 -6709.168394409115 12.835771543086175 -6722.680440874151 12.769659318637276 -6736.131775089225 12.703547094188378 -6749.522350855248 12.637434869739481 -6762.8521220388075 12.571322645290582 -6776.121042571553 12.505210420841685 -6789.329066449585 12.439098196392788 -6802.4761478882565 12.372985971943889 -6815.562241263209 12.306873747494992 -6828.587300839945 12.240761523046094 -6841.551280831695 12.174649298597195 -6854.454135513344 12.108537074148298 -6867.295819220789 12.042424849699401 -6880.076286350286 11.976312625250502 -6892.795491357805 11.910200400801605 -6905.453388758377 11.844088176352708 -6918.049933125438 11.777975951903809 -6930.585079090179 11.711863727454912 -6943.058781340893 11.645751503006013 -6955.470994622323 11.579639278557115 -6967.821673735016 11.513527054108218 -6980.110773534678 11.44741482965932 -6992.338249092873 11.381302605210422 -7004.5040555208625 11.315190380761525 -7016.608147803913 11.249078156312626 -7028.650480976439 11.182965931863729 -7040.631010125335 11.116853707414831 -7052.549690389383 11.050741482965933 -7064.406476958673 10.984629258517035 -7076.201325074046 10.918517034068138 -7087.934190026544 10.85240480961924 -7099.60502715689 10.786292585170342 -7111.21379185499 10.720180360721445 -7122.760439559452 10.654068136272546 -7134.244925757143 10.587955911823649 -7145.667206014094 10.521843687374751 -7157.02723595994 10.455731462925852 -7168.324971221456 10.389619238476955 -7179.560367437682 10.323507014028058 -7190.73338029474 10.257394789579159 -7201.843965525624 10.191282565130262 -7212.892078910052 10.125170340681365 -7223.877790915855 10.059058116232466 -7234.801460338063 9.992945891783569 -7245.66333558652 9.926833667334671 -7256.463380871922 9.860721442885772 -7267.2015600995255 9.794609218436875 -7277.877836864428 9.728496993987978 -7288.492174446746 9.662384769539079 -7299.044535806673 9.596272545090182 -7309.534883579439 9.530160320641285 -7319.963180070143 9.464048096192386 -7330.329387248463 9.397935871743488 -7340.633466743253 9.33182364729459 -7350.875379837002 9.265711422845692 -7361.055087460162 9.199599198396795 -7371.172550185347 9.133486973947896 -7381.227728221382 9.067374749498999 -7391.22058140721 9.001262525050102 -7401.151069205656 8.935150300601203 -7411.019150697023 8.869038076152306 -7420.824784572539 8.802925851703408 -7430.567929127635 8.73681362725451 -7440.248542255047 8.670701402805612 -7449.866581437753 8.604589178356715 -7459.4220037417135 8.538476953907816 -7468.914765808433 8.472364729458919 -7478.344823847322 8.406252505010022 -7487.712133627855 8.340140280561123 -7497.01665047152 8.274028056112225 -7506.258329243552 8.207915831663328 -7515.43712434444 8.14180360721443 -7524.552989701199 8.075691382765532 -7533.6058787584025 8.009579158316635 -7542.595744468962 7.943466933867736 -7551.522539284647 7.877354709418839 -7560.3862151463345 7.811242484969941 -7569.186723473977 7.745130260521043 -7577.924015156278 7.679018036072145 -7586.5980405400705 7.612905811623247 -7595.208749419369 7.546793587174349 -7603.756091024105 7.480681362725452 -7612.240014008516 7.414569138276554 -7620.66046643918 7.348456913827656 -7629.017395782684 7.282344689378759 -7637.3107488929045 7.216232464929861 -7645.540471997888 7.1501202404809625 -7653.706510686314 7.084008016032065 -7661.808809893522 7.017895791583167 -7669.847313887088 6.951783567134269 -7677.821966251913 6.885671342685372 -7685.7327098748365 6.819559118236474 -7693.579486928711 6.753446893787576 -7701.362238855949 6.687334669338678 -7709.080906351496 6.6212224448897805 -7716.735429345216 6.555110220440882 -7724.325746983651 6.488997995991984 -7731.851797611131 6.422885771543087 -7739.313518750205 6.356773547094189 -7746.710847081353 6.290661322645291 -7754.043718421948 6.224549098196394 -7761.312067704433 6.158436873747496 -7768.51582895366 6.092324649298598 -7775.65493526337 6.0262124248497 -7782.729318771744 5.960100200400802 -7789.738910635999 5.893987975951904 -7796.683641005956 5.827875751503006 -7803.563438996544 5.761763527054109 -7810.37823265917 5.695651302605211 -7817.127948951886 5.629539078156313 -7823.8125137083025 5.563426853707416 -7830.4318516051635 5.4973146292585175 -7836.9858861285 5.4312024048096195 -7843.4745395382915 5.365090180360722 -7849.897732831539 5.298977955911824 -7856.255385703643 5.232865731462926 -7862.547416508003 5.166753507014029 -7868.7737422137 5.100641282565131 -7874.9342783611555 5.034529058116233 -7881.028939015637 4.9684168336673356 -7887.057636718446 4.9023046092184375 -7893.020282435662 4.836192384769539 -7898.916785504247 4.770080160320642 -7904.747053575342 4.703967935871744 -7910.510992554552 4.637855711422846 -7916.208506538997 4.571743486973948 -7921.839497750897 4.505631262525051 -7927.403866467423 4.439519038076153 -7932.901510946536 4.373406813627255 -7938.332327348497 4.307294589178357 -7943.696209652697 4.241182364729459 -7948.993049569444 4.175070140280561 -7954.222736446275 4.108957915831664 -7959.385157168335 4.042845691382766 -7964.480196052317 3.976733466933868 -7969.507734733394 3.9106212424849702 -7974.46765204451 3.8445090180360726 -7979.359823887344 3.7783967935871745 -7984.184123094149 3.712284569138277 -7988.940419279613 3.6461723446893792 -7993.628578681748 3.580060120240481 -7998.248463990733 3.5139478957915835 -8002.799934164464 3.447835671342686 -8007.282844229422 3.381723446893788 -8011.6970450653125 3.31561122244489 -8016.042383171666 3.249498997995992 -8020.318700414417 3.1833867735470944 -8024.5258337501355 3.117274549098197 -8028.663614925306 3.0511623246492987 -8032.7318701476515 2.985050100200401 -8036.730419726044 2.918937875751503 -8040.659077675046 2.8528256513026053 -8044.5176512795015 2.7867134268537077 -8048.305940613859 2.7206012024048096 -8052.023738010081 2.654488977955912 -8055.670827466938 2.5883767535070143 -8059.246983992304 2.5222645290581163 -8062.751972868586 2.4561523046092186 -8066.185548829699 2.390040080160321 -8069.547455135898 2.323927855711423 -8072.837422530229 2.2578156312625253 -8076.055168057304 2.191703406813627 -8079.200393721412 2.1255911823647295 -8082.272784956375 2.059478957915832 -8085.272008874114 1.993366733466934 -8088.197712252063 1.9272545090180364 -8091.049519211336 1.8611422845691385 -8093.827028527408 1.7950300601202407 -8096.529810502678 1.728917835671343 -8099.157403315166 1.6628056112224452 -8101.709308739268 1.5966933867735473 -8104.184987112374 1.5305811623246495 -8106.583851395084 1.4644689378757516 -8108.905260142514 1.398356713426854 -8111.148509170924 1.332244488977956 -8113.31282167006 1.2661322645290582 -8115.397336483493 1.2000200400801606 -8117.401094269531 1.1339078156312627 -8119.323021289297 1.067795591182365 -8121.161910694649 1.001683366733467 -8122.916401498088 0.9355711422845693 -8124.584956068862 0.8694589178356715 -8126.165838325319 0.8033466933867737 -8127.657097346345 0.7372344689378758 -8129.056565906336 0.6711222444889781 -8130.361892181427 0.6050100200400803 -8131.570638455064 0.5388977955911824 -8132.6805075679595 0.47278557114228464 -8133.689802748298 0.40667334669338684 -8134.59829970906 0.34056112224448903 -8135.408837323968 0.27444889779559123 -8136.130231350632 0.20833667334669342 -8136.783265500461 0.14222444889779562 -8137.4188914140395 0.0761122244488978 -8138.289806276097 0.01 +-0.0 20.0 +12.004960341817172 19.95993987975952 +23.98964201736537 19.919879759519038 +35.95403279928156 19.87981963927856 +47.8981204715152 19.839759519038076 +59.82189282933158 19.799699398797596 +71.72533767933199 19.759639278557113 +83.60844283945664 19.719579158316634 +95.47119613900456 19.67951903807615 +107.31358541863614 19.63945891783567 +119.1355985303925 19.59939879759519 +130.93722333769784 19.55933867735471 +142.7184477153773 19.51927855711423 +154.47925954966414 19.479218436873747 +166.21964673820682 19.439158316633268 +177.93959719008618 19.399098196392785 +189.63909882581686 19.359038076152306 +201.31813957736523 19.318977955911823 +212.97670738815043 19.278917835671344 +224.61479021306178 19.23885771543086 +236.23237601845952 19.19879759519038 +247.82945278219168 19.1587374749499 +259.4060084935945 19.11867735470942 +270.96203115350795 19.07861723446894 +282.4975087742806 19.038557114228457 +294.01242937977463 18.998496993987978 +305.5067810053806 18.958436873747495 +316.9805516980169 18.918376753507015 +328.43372951614475 18.878316633266532 +339.8663025297676 18.838256513026053 +351.2782588204458 18.79819639278557 +362.669586481295 18.75813627254509 +374.0402736170009 18.718076152304608 +385.39030834381686 18.67801603206413 +396.7196787895775 18.63795591182365 +408.0283731549779 18.597895791583166 +419.31637982576467 18.557835671342687 +430.58368713504734 18.517775551102204 +441.8302832511163 18.477715430861725 +453.05615635388847 18.437655310621242 +464.2612946349039 18.397595190380763 +475.44568629733817 18.35753507014028 +486.6093195559983 18.3174749498998 +497.75218263733467 18.277414829659318 +508.87426377943666 18.237354709418838 +519.9755512320438 18.197294589178355 +531.0560332565411 18.157234468937876 +542.1156981259685 18.117174348697397 +553.1545341250206 18.077114228456914 +564.1725295500464 18.037054108216434 +575.1696727090575 17.99699398797595 +586.1459519217227 17.956933867735472 +597.1013555193769 17.91687374749499 +608.0358718450148 17.87681362725451 +618.9494892532997 17.836753507014027 +629.8421961105564 17.796693386773548 +640.7139807947792 17.756633266533065 +651.5648316956248 17.716573146292586 +662.3947372144183 17.676513026052106 +673.2036857641508 17.636452905811623 +683.9916657694749 17.596392785571144 +694.7586656667115 17.55633266533066 +705.50467390384 17.51627254509018 +716.2296789405049 17.4762124248497 +726.9336692480065 17.43615230460922 +737.6166333093062 17.396092184368737 +748.2785596190165 17.356032064128257 +758.919436683406 17.315971943887774 +769.5392530203891 17.275911823647295 +780.1379971595287 17.235851703406816 +790.7156576420305 17.195791583166333 +801.2722230462253 17.155731462925853 +811.8076821486147 17.11567134268537 +822.3220237086892 17.07561122244489 +832.8152363078991 17.03555110220441 +843.2873085393342 16.99549098196393 +853.7382290077255 16.955430861723446 +864.1679863294327 16.915370741482967 +874.5765691324449 16.875310621242484 +884.9639660563674 16.835250501002005 +895.3301657524224 16.79519038076152 +905.6751568834343 16.755130260521042 +915.9989281238289 16.715070140280563 +926.3014681596235 16.67501002004008 +936.5827656884155 16.6349498997996 +946.8428094193811 16.594889779559118 +957.0815880732588 16.55482965931864 +967.2990903823483 16.514769539078156 +977.4953050904932 16.474709418837676 +987.6702209530791 16.434649298597193 +997.8238267370164 16.394589178356714 +1007.9561112207365 16.35452905811623 +1018.0670631941748 16.314468937875752 +1028.156671458765 16.274408817635273 +1038.2249248274256 16.23434869739479 +1048.2718121245452 16.19428857715431 +1058.2973221859763 16.154228456913827 +1068.3014438590164 16.114168336673348 +1078.2841660024014 16.074108216432865 +1088.2454774862856 16.034048096192386 +1098.1853671922354 15.993987975951903 +1108.103824013208 15.953927855711422 +1118.0008368535425 15.91386773547094 +1127.8763946289428 15.87380761523046 +1137.7304862664625 15.833747494989979 +1147.5631008529945 15.793687374749497 +1157.3742275229429 15.753627254509016 +1167.1638552701836 15.713567134268535 +1176.9319730603706 15.673507014028054 +1186.6785698704548 15.633446893787573 +1196.4036346886658 15.593386773547094 +1206.1071565144957 15.553326653306613 +1215.7891243586785 15.513266533066131 +1225.449527243173 15.47320641282565 +1235.0883542011434 15.43314629258517 +1244.70559427694 15.393086172344688 +1254.3012365260793 15.353026052104207 +1263.8752700152234 15.312965931863726 +1273.4276838221597 15.272905811623245 +1282.9584670357797 15.232845691382764 +1292.4676087560574 15.192785571142283 +1301.955098094027 15.152725450901803 +1311.4209241717626 15.112665330661322 +1320.8650761223519 15.072605210420841 +1330.2875430898753 15.03254509018036 +1339.6883142293823 14.992484969939879 +1349.0673787068665 14.952424849699398 +1358.424725699242 14.912364729458917 +1367.7603443943174 14.872304609218435 +1377.0742239907715 14.832244488977954 +1386.3663536981269 14.792184368737473 +1395.6367227367234 14.752124248496992 +1404.8853203376923 14.712064128256511 +1414.1121357429279 14.672004008016032 +1423.317158205062 14.63194388777555 +1432.5003769965256 14.59188376753507 +1441.6617815512257 14.551823647294588 +1450.8013613011033 14.511763527054107 +1459.9191055344168 14.471703406813626 +1469.01500355005 14.431643286573145 +1478.0890446574824 14.391583166332664 +1487.1412181767578 14.351523046092183 +1496.1715134384535 14.311462925851702 +1505.1799197836492 14.27140280561122 +1514.1664265638938 14.23134268537074 +1523.1310231411737 14.19128256513026 +1532.0736988878805 14.151222444889779 +1540.9944431867757 14.111162324649298 +1549.8932454309581 14.071102204408817 +1558.7700950238293 14.031042084168336 +1567.6249813790587 13.990981963927855 +1576.457893920548 13.950921843687373 +1585.2688220823961 13.910861723446892 +1594.0577553088622 13.870801603206411 +1602.8246830543294 13.83074148296593 +1611.5695947832678 13.790681362725449 +1620.292479970196 13.75062124248497 +1628.9933280996452 13.710561122244489 +1637.6721286661177 13.670501002004007 +1646.3288711740504 13.630440881763526 +1654.9635451377737 13.590380761523045 +1663.576140081473 13.550320641282564 +1672.1666455391476 13.510260521042083 +1680.7350510545693 13.470200400801602 +1689.2813462744693 13.43014028056112 +1697.8055208897172 13.39008016032064 +1706.30756450391 13.350020040080159 +1714.787466692128 13.309959919839677 +1723.2452170390538 13.269899799599198 +1731.6808051389326 13.229839679358717 +1740.0942205955243 13.189779559118236 +1748.485453022062 13.149719438877755 +1756.8544920412062 13.109659318637274 +1765.201327285 13.069599198396793 +1773.5259483948237 13.029539078156311 +1781.8283450213487 12.98947895791583 +1790.1085068244913 12.94941883767535 +1798.366423473366 12.909358717434868 +1806.6020846462386 12.869298597194387 +1814.815480030478 12.829238476953906 +1823.006599322509 12.789178356713427 +1831.1754322277643 12.749118236472945 +1839.3219684606352 12.709058116232464 +1847.4461977444223 12.668997995991983 +1855.5481098112878 12.628937875751502 +1863.627694402204 12.588877755511021 +1871.684941266905 12.54881763527054 +1879.719840163835 12.508757515030059 +1887.7323808600984 12.468697394789578 +1895.722553131409 12.428637274549097 +1903.6903468185924 12.388577154308615 +1911.6357518099082 12.348517034068136 +1919.5587579416467 12.308456913827655 +1927.4593550157244 12.268396793587174 +1935.3375328424584 12.228336673346693 +1943.193281240514 12.188276553106212 +1951.0265900368515 12.14821643286573 +1958.8374490666745 12.10815631262525 +1966.6258481733762 12.068096192384768 +1974.391777208487 12.028036072144287 +1982.1352260316207 11.987975951903806 +1989.8561845104227 11.947915831663325 +1997.554642520515 11.907855711422844 +2005.2305899454436 11.867795591182364 +2012.8840166766263 11.827735470941883 +2020.5149126132972 11.787675350701402 +2028.123267662455 11.747615230460921 +2035.7090717388087 11.70755511022044 +2043.2723147647253 11.667494989979959 +2050.812986670176 11.627434869739478 +2058.3310773926833 11.587374749498997 +2065.826576877268 11.547314629258516 +2073.299475076398 11.507254509018034 +2080.749761949933 11.467194388777553 +2088.1774274945883 11.427134268537074 +2095.5824617448034 11.387074148296593 +2102.9648547087063 11.347014028056112 +2110.324596367168 11.30695390781563 +2117.661676708255 11.26689378757515 +2124.9760857271804 11.226833667334668 +2132.267813426253 11.186773547094187 +2139.536849814829 11.146713426853706 +2146.783184909265 11.106653306613225 +2154.0068087328677 11.066593186372744 +2161.2077113158493 11.026533066132263 +2168.385882695281 10.986472945891782 +2175.541312915047 10.946412825651302 +2182.6739920258024 10.906352705410821 +2189.783910084928 10.86629258517034 +2196.8710571564884 10.82623246492986 +2203.935423311192 10.786172344689378 +2210.9769986263514 10.746112224448897 +2217.9957731858435 10.706052104208416 +2224.9917370800736 10.665991983967935 +2231.96488040594 10.625931863727454 +2238.9151932668 10.585871743486972 +2245.842665778164 10.545811623246491 +2252.7472880775113 10.50575150300601 +2259.629050298767 10.465691382765531 +2266.4879425624626 10.42563126252505 +2273.323954995514 10.385571142284569 +2280.1370777312027 10.345511022044088 +2286.9273009091526 10.305450901803606 +2293.6946146753153 10.265390781563125 +2300.4390091819537 10.225330661322644 +2307.1604745876293 10.185270541082163 +2313.859001057194 10.145210420841682 +2320.534578761782 10.105150300601201 +2327.1872451995137 10.06509018036072 +2333.817138037164 10.02503006012024 +2340.424348582387 9.98496993987976 +2347.00886891868 9.944909819639278 +2353.5706910889135 9.904849699398797 +2360.1098070949556 9.864789579158316 +2366.626208897291 9.824729458917835 +2373.119888414632 9.784669338677354 +2379.59083752353 9.744609218436873 +2386.0390480579763 9.704549098196392 +2392.464511809 9.66448897795591 +2398.8672205242597 9.62442885771543 +2405.2471659076296 9.584368737474948 +2411.6043396187792 9.544308617234469 +2417.93873327275 9.504248496993988 +2424.250338439522 9.464188376753507 +2430.539146643575 9.424128256513026 +2436.805149363448 9.384068136272544 +2443.048338031286 9.344008016032063 +2449.268704032386 9.303947895791582 +2455.46623870473 9.263887775551101 +2461.64093333852 9.22382765531062 +2467.792779175697 9.183767535070139 +2473.9217674094593 9.143707414829658 +2480.0278891837715 9.103647294589177 +2486.1111355928656 9.063587174348697 +2492.171497680737 9.023527054108216 +2498.20896644063 8.983466933867735 +2504.223532814517 8.943406813627254 +2510.2151876925723 8.903346693386773 +2516.1839219126327 8.863286573146292 +2522.129726259655 8.82322645290581 +2528.0525914651616 8.78316633266533 +2533.9525082066802 8.743106212424848 +2539.829467107172 8.703046092184367 +2545.6834587344556 8.662985971943886 +2551.5144736006155 8.622925851703407 +2557.3225021614085 8.582865731462926 +2563.107534815654 8.542805611222445 +2568.8695619046202 8.502745490981964 +2574.6085737113963 8.462685370741482 +2580.3245604602585 8.422625250501001 +2586.0175123160216 8.38256513026052 +2591.687419383384 8.342505010020039 +2597.3342717062606 8.302444889779558 +2602.9580592671027 8.262384769539077 +2608.558771986211 8.222324649298596 +2614.1363997210337 8.182264529058115 +2619.6909322654533 8.142204408817635 +2625.2223593490653 8.102144288577154 +2630.7306706364384 8.062084168336673 +2636.2158557263683 8.022024048096192 +2641.677904151115 7.981963927855711 +2647.1168053756282 7.94190380761523 +2652.5325487967607 7.901843687374749 +2657.925123742466 7.8617835671342675 +2663.2945194709832 7.821723446893786 +2668.640725170008 7.781663326653306 +2673.9637299558485 7.741603206412825 +2679.2635228725658 7.701543086172344 +2684.5400928911 7.661482965931863 +2689.7934289083805 7.621422845691382 +2695.023519746421 7.5813627254509015 +2700.2303541513957 7.54130260521042 +2705.4139207927014 7.501242484969939 +2710.5742082620013 7.461182364729458 +2715.711205072251 7.421122244488977 +2720.824899656706 7.381062124248496 +2725.9152803679126 7.341002004008016 +2730.982335476679 7.300941883767535 +2736.026053171025 7.2608817635270535 +2741.046421555114 7.220821643286572 +2746.0434286481654 7.180761523046091 +2751.017062383342 7.14070140280561 +2755.9673106066207 7.10064128256513 +2760.8941610756383 7.060581162324649 +2765.7976014585147 7.020521042084168 +2770.6776193326546 6.980460921843687 +2775.5342021835236 6.9404008016032055 +2780.3673374034 6.900340681362724 +2785.1770122901034 6.860280561122244 +2789.9632140456947 6.820220440881763 +2794.7259297751502 6.780160320641282 +2799.4651464850117 6.740100200400801 +2804.1808510820033 6.70004008016032 +2808.8730303716234 6.659979959919839 +2813.5416710567056 6.619919839679358 +2818.186759735949 6.579859719438877 +2822.8082829024183 6.539799599198396 +2827.4062269420097 6.499739478957915 +2831.9805781318855 6.459679358717434 +2836.531322638874 6.419619238476953 +2841.0584465178335 6.379559118236473 +2845.5619357099827 6.3394989979959915 +2850.0417760411897 6.29943887775551 +2854.4979532202265 6.259378757515029 +2858.930452836981 6.219318637274548 +2863.339260360632 6.179258517034068 +2867.7243611377776 6.139198396793587 +2872.085740390524 6.099138276553106 +2876.4233832145273 6.059078156312625 +2880.737274576992 6.0190180360721435 +2885.0273993146184 5.978957915831662 +2889.293742131504 5.938897795591182 +2893.5362875969927 5.898837675350701 +2897.7550201434724 5.85877755511022 +2901.9499240641176 5.818717434869739 +2906.1209835105788 5.778657314629258 +2910.26818249061 5.738597194388777 +2914.3915048656413 5.698537074148296 +2918.490934348287 5.658476953907815 +2922.566454499789 5.618416833667334 +2926.618048727399 5.578356713426853 +2930.6457002816874 5.538296593186372 +2934.6493922537834 5.498236472945891 +2938.6291075725435 5.458176352705411 +2942.5848290016415 5.4181162324649295 +2946.5165391365817 5.378056112224448 +2950.4242204016314 5.337995991983967 +2954.3078550466657 5.297935871743486 +2958.167425143929 5.257875751503005 +2962.0029125847027 5.217815631262525 +2965.8142990758797 5.177755511022044 +2969.6015661364413 5.137695390781563 +2973.364695093831 5.0976352705410815 +2977.103667080224 5.0575751503006 +2980.8184630286873 5.01751503006012 +2984.5090636692235 4.977454909819639 +2988.1754495246973 4.937394789579158 +2991.817600906638 4.897334669338677 +2995.435497910913 4.857274549098196 +2999.0291204132686 4.817214428857715 +3002.598448064728 4.777154308617234 +3006.1434602868467 4.737094188376753 +3009.6641362668147 4.697034068136272 +3013.1604549523995 4.656973947895791 +3016.6323950467254 4.61691382765531 +3020.079935002878 4.576853707414829 +3023.50305301833 4.5367935871743486 +3026.901727029177 4.496733466933867 +3030.2759347041765 4.456673346693386 +3033.6256534385807 4.416613226452905 +3036.950860347752 4.376553106212424 +3040.2515322605536 4.336492985971943 +3043.527645712502 4.296432865731463 +3046.7791769386704 4.256372745490982 +3050.0061018663323 4.2163126252505005 +3053.208396107331 4.176252505010019 +3056.3860349501592 4.136192384769538 +3059.538993351741 4.096132264529057 +3062.6672459288893 4.056072144288577 +3065.770766949438 4.016012024048096 +3068.8495303230115 3.9759519038076148 +3071.9035095914332 3.9358917835671337 +3074.9326779187368 3.895831663326653 +3077.9370080807676 3.855771543086172 +3080.9164724543493 3.8157114228456908 +3083.8710430059905 3.77565130260521 +3086.800691280106 3.735591182364729 +3089.705388386725 3.695531062124248 +3092.5851049886537 3.655470941883767 +3095.4398112880654 3.615410821643286 +3098.269477012478 3.575350701402805 +3101.074071400087 3.5352905811623243 +3103.853563184408 3.495230460921843 +3106.6079205781925 3.455170340681362 +3109.3371112565665 3.4151102204408814 +3112.0411023393444 3.3750501002004003 +3114.719860372463 3.334989979959919 +3117.3733513084767 3.2949298597194385 +3120.001540486058 3.2548697394789574 +3122.604392608425 3.2148096192384763 +3125.181871720631 3.1747494989979956 +3127.733941185635 3.1346893787575145 +3130.2605636590615 3.094629258517034 +3132.761701062565 3.0545691382765527 +3135.2373145556885 3.0145090180360716 +3137.6873645061128 2.974448897795591 +3140.1118104581683 2.93438877755511 +3142.5106110994843 2.8943286573146287 +3144.883724225627 2.854268537074148 +3147.2311067025703 2.814208416833667 +3149.552714426832 2.774148296593186 +3151.848502283076 2.734088176352705 +3154.1184240989833 2.694028056112224 +3156.3624325971628 2.653967935871743 +3158.5804793438456 2.6139078156312623 +3160.772514694097 2.573847695390781 +3162.938487733234 2.5337875751503 +3165.078346214121 2.4937274549098194 +3167.192036489969 2.4536673346693383 +3169.2795034422275 2.413607214428857 +3171.3406904031267 2.3735470941883765 +3173.3755390723504 2.3334869739478954 +3175.3839894272974 2.2934268537074143 +3177.3659796262973 2.2533667334669336 +3179.321445904103 2.2133066132264525 +3181.2503224588754 2.1732464929859714 +3183.1525413298145 2.1331863727454907 +3185.0280322644658 2.0931262525050096 +3186.8767225746346 2.0530661322645285 +3188.698536979705 2.013006012024048 +3190.493397436011 1.972945891783567 +3192.2612229507567 1.932885771543086 +3194.0019293787764 1.8928256513026052 +3195.715429200238 1.852765531062124 +3197.4016312771373 1.8127054108216432 +3199.0604405861745 1.7726452905811623 +3200.691757925294 1.7325851703406812 +3202.2954795908404 1.6925250501002003 +3203.8714970218916 1.6524649298597194 +3205.4196964079156 1.6124048096192383 +3206.939958255419 1.5723446893787574 +3208.4321569087438 1.5322845691382765 +3209.8961600196076 1.4922244488977956 +3211.331827959366 1.4521643286573145 +3212.739013167362 1.4121042084168336 +3214.1175594280726 1.3720440881763527 +3215.4673010691545 1.3319839679358716 +3216.7880620719543 1.2919238476953907 +3218.0796550856808 1.2518637274549098 +3219.341880336359 1.2118036072144287 +3220.5745244220984 1.1717434869739478 +3221.777358987393 1.131683366733467 +3222.950139271537 1.0916232464929858 +3224.0926025304434 1.051563126252505 +3225.204466338055 1.011503006012024 +3226.285426784458 0.971442885771543 +3227.335156604663 0.931382765531062 +3228.353303297527 0.8913226452905811 +3229.339487332344 0.8512625250501001 +3230.2933005968616 0.8112024048096191 +3231.214305322723 0.7711422845691382 +3232.1020338436997 0.7310821643286572 +3232.9559897137706 0.6910220440881764 +3233.7756509569062 0.6509619238476954 +3234.5604765658722 0.6109018036072144 +3235.30991784901 0.5708416833667335 +3236.0234368864194 0.5307815631262525 +3236.7005352545007 0.4907214428857715 +3237.340797377451 0.4506613226452906 +3237.9439544585052 0.4106012024048096 +3238.509977099474 0.37054108216432863 +3239.039207832505 0.3304809619238477 +3239.532549955435 0.29042084168336674 +3239.9917393995006 0.25036072144288574 +3240.419750968563 0.2103006012024048 +3240.821457352705 0.17024048096192385 +3241.204868151086 0.13018036072144287 +3241.5840701519737 0.09012024048096191 +3241.989400353421 0.05006012024048096 +3242.5361575547254 0.01 diff --git a/ELoss/PCEnergyAnalysis.py b/ELoss/PCEnergyAnalysis.py index cba0b38..28f9b79 100644 --- a/ELoss/PCEnergyAnalysis.py +++ b/ELoss/PCEnergyAnalysis.py @@ -8,16 +8,12 @@ Created on Wed May 20 13:32:14 2026 import numpy as np import pandas as pd from scipy.interpolate import interp1d -import argparse import uproot import pycatima as catima from scipy.integrate import cumulative_trapezoid import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt -import threading -import time -import sys import cmd import shlex import textwrap @@ -26,17 +22,18 @@ import atexit import os import periodictable as pt import re +from matplotlib.colors import PowerNorm #Run program from terminal or IDE, and prompts will provide user steps -histfile = os.path.expanduser("~/.uproot_shell_history") +#histfile = os.path.expanduser("~/.uproot_shell_history") -try: - readline.read_history_file(histfile) -except FileNotFoundError: - pass +#try: +# readline.read_history_file(histfile) +#except FileNotFoundError: +# pass -atexit.register(readline.write_history_file, histfile) +#atexit.register(readline.write_history_file, histfile) #data = [z, mass_u, maximum MeV, name] alpha_data = [2, 4.0026, 40, "alpha"] @@ -253,6 +250,69 @@ def resolve_particle(name): except Exception: raise ValueError(f"Unknown particle/isotope: {name}") + +def update_plot_data(name, values): + for i, (existing_name, _) in enumerate(plot_data): + if existing_name == name: + plot_data[i] = (name, values) + return + plot_data.append((name, values)) + +def process_file(filename): + + tree = uproot.open(filename)["tree"] + + branches = ["Tb", "thetab", "sx3Z"] + + data = tree.arrays(branches, library="np") + + Ei = data["Tb"] + theta = np.radians(data["thetab"]) + sx3Z = data["sx3Z"] + + mask = np.sin(theta) != 0 + + Ei = Ei[mask] + theta = theta[mask] + sx3Z = sx3Z[mask] + + sin_theta = np.sin(theta) + + radii = np.array([3.2, 4.2, 6.6]) + + dA = radii[0] / sin_theta + dC = radii[1] / sin_theta + dsx3 = radii[2] / sin_theta + + # Determine particle from filename + lower = filename.lower() + + if "proton" in lower: + particle = "proton" + elif "alpha" in lower: + particle = "alpha" + else: + particle = "proton" + + print(f"Computing energies for {particle}...") + + EA = energy_loss(particle, Ei, dA) + EC = energy_loss(particle, Ei, dC) + Esx3 = energy_loss(particle, Ei, dsx3) + + Elost = Ei - Esx3 + Eprop = EA - EC + + return { + "particle": particle, + "Ei": Ei, + "sx3Z": sx3Z, + "EA": EA, + "EC": EC, + "Esx3": Esx3, + "Elost": Elost, + "Eprop": Eprop + } class MyInteractiveApp(cmd.Cmd): def __init__(self): @@ -405,11 +465,28 @@ class MyInteractiveApp(cmd.Cmd): plt.figure(figsize=(8,6)) plt.plot(x, E) + plt.xlabel("Distance (cm)") plt.ylabel("Energy (MeV)") plt.title(f"Energy Loss Curve {label.capitalize()}") plt.grid(True) - plt.show() + textstr = f"T = {self.T:.2f} K\nP = {self.P:.2f} Torr" + + plt.gca().text( + 0.02, 0.02, + textstr, + transform=plt.gca().transAxes, + fontsize=10, + verticalalignment='bottom', + bbox=dict(boxstyle="round", facecolor="white", alpha=0.7) + ) + + plt.tight_layout() + filename = f"Energy_Loss_Curve_{label}.png" + plt.savefig(filename, dpi=300, bbox_inches="tight") + plt.close() + + print(f"Saved plot: {filename}") except Exception as e: print(f"Error in make_table: {e}") @@ -755,6 +832,10 @@ class MyInteractiveApp(cmd.Cmd): def do_make_plots(self, arg): import os + + global plot_data + + plot_data = [] args = shlex.split(arg) @@ -782,6 +863,9 @@ class MyInteractiveApp(cmd.Cmd): Ei = Ei[mask] theta = theta[mask] sx3Z = sx3Z[mask] + + update_plot_data(f"{particle}_Ei", Ei) + update_plot_data(f"{particle}_sx3Z", sx3Z) sin_theta = np.sin(theta) @@ -799,6 +883,12 @@ class MyInteractiveApp(cmd.Cmd): Elost = Ei - Esx3 Eprop = EA - EC + + update_plot_data(f"{particle}_EA", EA) + update_plot_data(f"{particle}_EC", EC) + update_plot_data(f"{particle}_Esx3", Esx3) + update_plot_data(f"{particle}_Elost", Elost) + update_plot_data(f"{particle}_Eprop", Eprop) base = f"{particle}_plots" os.makedirs(base, exist_ok=True) @@ -810,29 +900,29 @@ class MyInteractiveApp(cmd.Cmd): plt.hist(Elost, bins=200) plt.xlabel("Energy Loss (MeV)") plt.ylabel("Counts") - plt.title("Total Energy Loss Distribution") + plt.title(f"{particle} Total Energy Loss Distribution") plt.grid(True) plt.tight_layout() plt.savefig(f"{base}/Elost_hist.png", dpi=300) plt.close() - # 2. Histogram: sx3Z + #Histogram: sx3Z plt.figure(figsize=(7,5)) plt.hist(sx3Z, bins=100) plt.xlabel("SX3 Z") plt.ylabel("Counts") - plt.title("SX3 Position Distribution") + plt.title(f"{particle} SX3 Position Distribution") plt.grid(True) plt.tight_layout() plt.savefig(f"{base}/sx3Z_hist.png", dpi=300) plt.close() - # 3. 2D: Elost vs sx3Z + #2D: Elost vs sx3Z plt.figure(figsize=(7,6)) - plt.hist2d(Elost, sx3Z, bins=200) - plt.xlabel("Energy Loss (MeV)") - plt.ylabel("SX3 Z") - plt.title("Energy Loss vs SX3 Position") + plt.hist2d(sx3Z, Elost, bins=200) + plt.ylabel("Energy Loss (MeV)") + plt.xlabel("SX3 Z") + plt.title(f"{particle} Energy Loss vs SX3 Position") plt.colorbar(label="Counts") plt.tight_layout() plt.savefig(f"{base}/Elost_vs_sx3Z.png", dpi=300) @@ -843,7 +933,7 @@ class MyInteractiveApp(cmd.Cmd): plt.hist2d(EA, Esx3, bins=200) plt.xlabel("EA (MeV)") plt.ylabel("Esx3 (MeV)") - plt.title("Anode vs SX3 Energy") + plt.title(f"{particle} Anode vs SX3 Energy") plt.colorbar(label="Counts") plt.tight_layout() plt.savefig(f"{base}/EA_vs_Esx3.png", dpi=300) @@ -854,14 +944,214 @@ class MyInteractiveApp(cmd.Cmd): plt.hist2d(Eprop, sx3Z, bins=200) plt.xlabel("EA - EC (MeV)") plt.ylabel("SX3 Z") - plt.title("Energy Propagation Difference vs Position") + plt.title(f"{particle} Energy Propagation Difference vs Position") plt.colorbar(label="Counts") plt.tight_layout() plt.savefig(f"{base}/Eprop_vs_sx3Z.png", dpi=300) plt.close() + + plt.figure(figsize=(7,6)) + plt.hist2d(Esx3, Eprop, bins=200) + plt.ylabel("PCEnergy") + plt.xlabel("SX3 Energy (MeV)") + plt.title(f"{particle} Energy Propagation Difference vs sx3 Energy") + plt.colorbar(label="Counts") + plt.xlim(0,30) + plt.ylim(0,.45) + plt.tight_layout() + plt.savefig(f"{base}/Eprop_vs_Esx3.png", dpi=300) + plt.close() print("Plotting complete.") + def do_dual_plotter(self, arg): + args = shlex.split(arg) + + if len(args) < 2: + print("Usage: make dual plots proton_data.root alpha_data.root") + return + + file1 = args[0] + file2 = args[1] + + #Helper function + + + #Process both files + data1 = process_file(f"../Armory/{file1}") + data2 = process_file(f"../Armory/{file2}") + + outdir = "dual_plots" + os.makedirs(outdir, exist_ok=True) + + print(f"Saving plots to: {outdir}") + + #Overlay histogram: Elost + plt.figure(figsize=(8,6)) + + plt.hist( + data1["Elost"], + bins=200, + histtype='step', + linewidth=2, + density=True, + label=data1["particle"] + ) + + plt.hist( + data2["Elost"], + bins=200, + histtype='step', + linewidth=2, + density=True, + label=data2["particle"] + ) + + plt.xlabel("Energy Loss (MeV)") + plt.ylabel("Normalized Counts") + plt.title("Energy Loss Comparison") + plt.legend() + plt.grid(True) + plt.tight_layout() + + plt.savefig(f"{outdir}/Elost_overlay.png", dpi=300) + plt.close() + + #Overlay histogram: sx3Z + plt.figure(figsize=(8,6)) + + plt.hist( + data1["sx3Z"], + bins=150, + histtype='step', + linewidth=2, + density=True, + label=data1["particle"] + ) + + plt.hist( + data2["sx3Z"], + bins=150, + histtype='step', + linewidth=2, + density=True, + label=data2["particle"] + ) + + plt.xlabel("SX3 Z") + plt.ylabel("Normalized Counts") + plt.title("SX3 Position Comparison") + plt.legend() + plt.grid(True) + plt.tight_layout() + + plt.savefig(f"{outdir}/sx3Z_overlay.png", dpi=300) + plt.close() + + #Side-by-side 2D plots + fig, axes = plt.subplots(1, 2, figsize=(14,6)) + + h1 = axes[0].hist2d( + data1["sx3Z"], + data1["Elost"], + bins=200 + ) + + axes[0].set_title(f'{data1["particle"]} Elost vs SX3') + axes[0].set_xlabel("SX3 Z") + axes[0].set_ylabel("Energy Loss (MeV)") + + h2 = axes[1].hist2d( + data2["sx3Z"], + data2["Elost"], + bins=200 + ) + + axes[1].set_title(f'{data2["particle"]} Elost vs SX3') + axes[1].set_xlabel("SX3 Z") + axes[1].set_ylabel("Energy Loss (MeV)") + + fig.colorbar(h1[3], ax=axes[0], label="Counts") + fig.colorbar(h2[3], ax=axes[1], label="Counts") + + plt.tight_layout() + + plt.savefig(f"{outdir}/Elost_vs_sx3_comparison.png", dpi=300) + plt.close() + + #EA vs Esx3 overlay scatter + plt.figure(figsize=(8,6)) + + plt.scatter( + data1["EA"], + data1["Esx3"], + s=1, + alpha=0.3, + label=data1["particle"] + ) + + plt.scatter( + data2["EA"], + data2["Esx3"], + s=1, + alpha=0.3, + label=data2["particle"] + ) + + plt.xlabel("EA (MeV)") + plt.ylabel("Esx3 (MeV)") + plt.title("Anode vs SX3 Energy") + plt.legend() + plt.grid(True) + plt.tight_layout() + + plt.savefig(f"{outdir}/EA_vs_Esx3_overlay.png", dpi=300) + plt.close() + + #PCE vs SiE + + combined_Esx3 = np.concatenate([ + data1["Esx3"], + data2["Esx3"] + ]) + + combined_Eprop = np.concatenate([ + data1["Eprop"], + data2["Eprop"] + ]) + + plt.figure(figsize=(7,6)) + + plt.hist2d( + combined_Esx3, + combined_Eprop, + bins=100, + range=[[0,30],[0,0.45]], + cmap='viridis' # same default matplotlib style + ) + + plt.ylabel("PCEnergy") + plt.xlabel("SX3 Energy (MeV)") + + plt.title( + f'{data1["particle"]} + {data2["particle"]} ' + 'Energy Propagation Difference vs SX3 Energy' + ) + + plt.colorbar(label="Counts") + + plt.xlim(0,30) + plt.ylim(0,0.45) + + plt.tight_layout() + + plt.savefig(f"{outdir}/Combined_Eprop_vs_Esx3.png", dpi=300) + + plt.close() + + print("Dual plotting complete.") + + #exec(open("PCEnergyAnalysis.py").read()) if __name__ == "__main__":