diff --git a/.gitignore b/.gitignore index c23f93b..b535c17 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,16 @@ bin/ configs/ events/ + +data/background_spectra/ + +.idea/ + +cluster-submit.py +states/ + +run-local.sh +simlocal_log.txt +gdb_commands + +craysim.egg-info/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4cffd43 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,70 @@ +FROM ubuntu:16.04 + +ENV TERM XTerm + +RUN apt-get update +RUN apt-get install -y wget + + +### ROOT +WORKDIR /usr/opt/ + +RUN wget https://root.cern.ch/download/root_v6.12.06.Linux-ubuntu16-x86_64-gcc5.4.tar.gz +RUN tar xvfz root_v6.12.06.Linux-ubuntu16-x86_64-gcc5.4.tar.gz +WORKDIR /usr/opt/root + +RUN apt-get install -y apt-utils cmake +RUN apt-get install -y libtbb2 g++ gcc +RUN apt-get install -y python +RUN apt-get install -y make +RUN apt-get install -y python-dev + +RUN apt-get update +RUN apt-get upgrade -y binutils + +### GEANT +WORKDIR /usr/opt + +RUN wget http://geant4.web.cern.ch/geant4/support/source/geant4.10.01.p03.tar.gz +RUN tar -xzf geant4.10.01.p03.tar.gz + +WORKDIR /usr/opt/geant_build + +RUN cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/opt/geant -DGEANT4_INSTALL_DATA=ON -DBUILD_SHARED_LIBS=ON /usr/opt/geant4.10.01.p03/ +RUN make -j8 +RUN make install +RUN rm -rf /usr/opt/geant_build + +### Python + +RUN apt-get update +RUN apt-get install -y python-pip + +RUN pip install numpy + +RUN apt-get install -y gdb +RUN apt-get install -y valgrind + +### CRAYFIS-SIM + +COPY data /usr/app/data +COPY include /usr/app/include +COPY src /usr/app/src +COPY pycraysim/pycraysim/utils /usr/app/scripts +COPY GNUmakefile /usr/app/ +COPY TestEm1.cc /usr/app/ + +COPY gdb_commands /usr/app/ +COPY seg_wrapper.sh /usr/app/ + +WORKDIR /usr/app/ + +RUN bash -c "export G4INSTALL=/usr/opt/geant/ && source /usr/opt/root/bin/thisroot.sh && source /usr/opt/geant/share/Geant4-10.1.3/geant4make/geant4make.sh && export G4G4WORKDIR=/usr/geant_workdir && make -j9" + +WORKDIR /usr/app/ +RUN bash -c "source /usr/opt/root/bin/thisroot.sh && python scripts/configs.py 10000 -n 3000 -j10 -o /output" + +COPY run.sh /usr/app/ +COPY run.py /usr/app/ + +CMD sh run.sh \ No newline at end of file diff --git a/data/config/run.mac.template b/config/run.mac.template similarity index 67% rename from data/config/run.mac.template rename to config/run.mac.template index 6cf4083..d0bc4d1 100644 --- a/data/config/run.mac.template +++ b/config/run.mac.template @@ -1,7 +1,7 @@ # example driver macro # beam energy in keV -/control/alias beamEnergy $beamEnergy +/control/alias beamEnergy 0 # beam particle (gamma, mu-, e-, etc) /control/alias bParticle $particle @@ -27,11 +27,6 @@ /control/alias seed2 $seed2 /random/setSeeds {seed1} {seed2} -# set this to 1 if you want the beam -# angle to be randomly distributed -/control/alias doRandom 1 - - /control/verbose 2 /run/verbose 2 @@ -44,22 +39,28 @@ /testem/det/setDepth {pixDepth} um /testem/det/setNPix {npix} +# set this if you want to use cuts different from the default (0.5um) +#/testem/phys/setCuts 0.5 um /run/initialize /gun/particle {bParticle} -#/gun/energy {beamEnergy} keV -/testem/gun/rndm {doRandom} +/gun/energy -1 keV # uncomment the following line if you want the energy # to be sampled from a histogram. -# the file should contain a TH1F named "particleEnergy", -# with the desired distribution in units of keV. +# the file should contain a TH1F named "energy", +# with the desired distribution in units of MeV. + +/testem/gun/energy/hist $energyHisto -/testem/gun/energyHisto $energyHisto +# uncomment the following if you want the angle theta to be sampled +# from a histogram. When sampling theta, the angle phi will be uniformly +# distributed. The file should contain a TH1F named "theta" in units of radians. +/testem/gun/theta/hist data/theta_cos2.root # how often to print progress @@ -69,4 +70,4 @@ /analysis/setFileName $output # run the specified number of events -/run/beamOn {ngen} +/run/beamOn {ngen} \ No newline at end of file diff --git a/data/background_spectra/README b/data/background_spectra/README deleted file mode 100644 index 222a3df..0000000 --- a/data/background_spectra/README +++ /dev/null @@ -1,2 +0,0 @@ -Each file contains histograms for background cosmic radiation at sea level. -Energy is given in MeV, flux is in 1 / s / cm^-2. diff --git a/data/background_spectra/e+.root b/data/background_spectra/e+.root deleted file mode 100644 index 7360916..0000000 Binary files a/data/background_spectra/e+.root and /dev/null differ diff --git a/data/background_spectra/e-.root b/data/background_spectra/e-.root deleted file mode 100644 index 13087e5..0000000 Binary files a/data/background_spectra/e-.root and /dev/null differ diff --git a/data/background_spectra/gamma.root b/data/background_spectra/gamma.root deleted file mode 100644 index 11a4dc8..0000000 Binary files a/data/background_spectra/gamma.root and /dev/null differ diff --git a/data/background_spectra/mu+.root b/data/background_spectra/mu+.root deleted file mode 100644 index e69ead4..0000000 Binary files a/data/background_spectra/mu+.root and /dev/null differ diff --git a/data/background_spectra/mu-.root b/data/background_spectra/mu-.root deleted file mode 100644 index dacfda7..0000000 Binary files a/data/background_spectra/mu-.root and /dev/null differ diff --git a/data/background_spectra/neutron.root b/data/background_spectra/neutron.root deleted file mode 100644 index 13fea72..0000000 Binary files a/data/background_spectra/neutron.root and /dev/null differ diff --git a/data/background_spectra/proton.root b/data/background_spectra/proton.root deleted file mode 100644 index 11a0124..0000000 Binary files a/data/background_spectra/proton.root and /dev/null differ diff --git a/data/diff_spectra/README b/data/diff_spectra/README new file mode 100644 index 0000000..8c4f7f6 --- /dev/null +++ b/data/diff_spectra/README @@ -0,0 +1,2 @@ +Source: https://github.com/swaneyjr/AirplaneCosmicSpectrum +This is DIFFERENTIAL spectra at sea level. diff --git a/data/diff_spectra/e+.dat b/data/diff_spectra/e+.dat new file mode 100644 index 0000000..d1966f6 --- /dev/null +++ b/data/diff_spectra/e+.dat @@ -0,0 +1,81 @@ +0.011294 6.912754113714E-06 +0.014219 8.21569988483745E-06 +0.017901 9.75536350688826E-06 +0.022536 1.15698910449686E-05 +0.028371 1.37008769139771E-05 +0.035717 1.61919015498089E-05 +0.044965 1.90857935076182E-05 +0.056607 2.24204923660206E-05 +0.071264 2.62230479522847E-05 +0.089717 3.04998153580735E-05 +0.11294 3.52230304776175E-05 +0.14219 4.03244964991915E-05 +0.17901 4.56701327863593E-05 +0.22536 5.10618981723173E-05 +0.28371 5.62379659303892E-05 +0.35717 6.08918423374971E-05 +0.44965 6.47096595742407E-05 +0.56608 6.74204824678977E-05 +0.71264 6.88439516065054E-05 +0.89717 6.8922031920449E-05 +1.1294 6.77214152675347E-05 +1.4219 6.54077624829588E-05 +1.7901 6.22089785794004E-05 +2.2536 5.83699105710532E-05 +2.8371 5.41190466647287E-05 +3.5717 4.96485573764971E-05 +4.4965 4.51069203985617E-05 +5.6607 4.0600046230926E-05 +7.1265 3.61973079903103E-05 +8.9717 3.19431779815502E-05 +11.295 2.78641433794673E-05 +14.219 2.39824989441335E-05 +17.901 2.03182078019703E-05 +22.536 1.69015092585623E-05 +28.371 1.3769141542965E-05 +35.717 1.09620569797416E-05 +44.965 8.51689202252719E-06 +56.607 6.45545551391666E-06 +71.265 4.77695221341802E-06 +89.716 3.45751280111317E-06 +112.94 2.45396751323077E-06 +142.19 1.71249579881554E-06 +179.01 1.17869822915547E-06 +225.36 8.02354861555871E-07 +283.71 5.41433332065681E-07 +357.17 3.62906731850952E-07 +449.65 2.42002279868683E-07 +566.08 1.60753006108832E-07 +712.65 1.06476055954714E-07 +897.16 7.0375311497041E-08 +1129.4 4.64436475294839E-08 +1421.9 3.06086385371354E-08 +1790.1 2.01562560943039E-08 +2253.6 1.32652567241597E-08 +2837.1 8.72613961725299E-09 +3571.7 5.73819923819996E-09 +4496.5 3.77243353674064E-09 +5660.8 2.47959846906465E-09 +7126.5 1.62963905260313E-09 +8971.7 1.07092446820664E-09 +11294 7.03787203225651E-10 +14219 4.62394936118268E-10 +17901 3.03802828656652E-10 +22536 1.99606272630061E-10 +28371 1.31144706355964E-10 +35717 8.61620850615325E-11 +44965 5.66080420262388E-11 +56608 3.71903285443165E-11 +71264 2.44342543952498E-11 +89716 1.60528790245929E-11 +112940 1.05473953266337E-11 +142190 6.92878919698013E-12 +179010 4.55189794598097E-12 +225360 2.99049455162931E-12 +283710 1.96470016335954E-12 +357170 1.29075751310548E-12 +449650 8.47996617880111E-13 +566080 5.57104768588322E-13 +712640 3.66015331637543E-13 +897160 2.40462986334895E-13 + diff --git a/data/diff_spectra/e-.dat b/data/diff_spectra/e-.dat new file mode 100644 index 0000000..28a9e9a --- /dev/null +++ b/data/diff_spectra/e-.dat @@ -0,0 +1,81 @@ +0.011294 0.002689187394332 +0.014219 0.002579048978592 +0.017901 0.002467476429373 +0.022536 0.002354051775208 +0.028371 0.002238402116545 +0.035717 0.00212023832646 +0.044965 0.001999400281882 +0.056607 0.00187589217173 +0.071264 0.001749910781723 +0.089717 0.00162190868036 +0.11294 0.001492654913588 +0.14219 0.001363040557935 +0.17901 0.001234384293589 +0.22536 0.001108104910314 +0.28371 0.000985713600424 +0.35717 0.000868711425533 +0.44965 0.000758478774442 +0.56608 0.000656154217899 +0.71264 0.000562584564949 +0.89717 0.000478232275623 +1.1294 0.000403265867032 +1.4219 0.000337446547504 +1.7901 0.000280379533019 +2.2536 0.000231429945562 +2.8371 0.000189843772937 +3.5717 0.000154812831942 +4.4965 0.000125525825465 +5.6607 0.000101202540635 +7.1265 8.11159983538443E-05 +8.9717 6.46177235973272E-05 +11.295 5.11296864248236E-05 +14.219 4.01596232582779E-05 +17.901 3.12774113726374E-05 +22.536 2.41290066381283E-05 +28.371 1.84142984652614E-05 +35.717 1.38832606679915E-05 +44.965 1.03272751735292E-05 +56.607 7.57083177578504E-06 +71.265 5.46470621078735E-06 +89.716 3.88220981178845E-06 +112.94 2.71441697341347E-06 +142.19 1.86834677874852E-06 +179.01 1.26732441647693E-06 +225.36 8.48174358283652E-07 +283.71 5.60861635094641E-07 +357.17 3.66988279909981E-07 +449.65 2.37978852527483E-07 +566.08 1.53153816272833E-07 +712.65 9.79490766465823E-08 +897.16 6.23234400034651E-08 +1129.4 3.94935618006647E-08 +1421.9 2.49380335616817E-08 +1790.1 1.57059476488079E-08 +2253.6 9.87103224260283E-09 +2837.1 6.19350083057176E-09 +3571.7 3.88088380776872E-09 +4496.5 2.4292664525271E-09 +5660.8 1.51935125275659E-09 +7126.5 9.49671541644838E-10 +8971.7 5.93296269893906E-10 +11294 3.70554491999807E-10 +14219 2.31313680482007E-10 +17901 1.44368910374307E-10 +22536 9.00913405951646E-11 +28371 5.62125043564442E-11 +35717 3.50694120677042E-11 +44965 2.18769679710806E-11 +56608 1.36460987201958E-11 +71264 8.51194404628308E-12 +89716 5.30903770775794E-12 +112940 3.31156606446165E-12 +142190 2.0651471837211E-12 +179010 1.28791346960435E-12 +225360 8.03218055899891E-13 +283710 5.00931728152928E-13 +357170 3.12402393643133E-13 +449650 1.9482667420574E-13 +566080 1.21498978209913E-13 +712640 7.57734559007221E-14 +897160 4.72547019216388E-14 + diff --git a/data/diff_spectra/gamma.dat b/data/diff_spectra/gamma.dat new file mode 100644 index 0000000..f52c2fe --- /dev/null +++ b/data/diff_spectra/gamma.dat @@ -0,0 +1,81 @@ +1.13E-02 1.87E-03 +1.42E-02 5.78E-03 +1.79E-02 1.79E-02 +2.25E-02 5.51E-02 +2.84E-02 1.66E-01 +3.57E-02 4.56E-01 +4.50E-02 9.00E-01 +5.66E-02 1.01E+00 +7.13E-02 7.58E-01 +8.97E-02 5.04E-01 +1.13E-01 3.27E-01 +1.42E-01 2.12E-01 +1.79E-01 1.38E-01 +2.25E-01 9.09E-02 +2.84E-01 6.04E-02 +3.57E-01 4.06E-02 +4.50E-01 2.77E-02 +5.66E-01 6.98E-02 +7.13E-01 1.34E-02 +8.97E-01 5.60E-03 +1.13E+00 6.97E-03 +1.42E+00 5.13E-03 +1.79E+00 3.84E-03 +2.25E+00 2.90E-03 +2.84E+00 2.22E-03 +3.57E+00 1.71E-03 +4.50E+00 1.32E-03 +5.66E+00 1.03E-03 +7.13E+00 7.99E-04 +8.97E+00 6.18E-04 +1.13E+01 4.74E-04 +1.42E+01 3.59E-04 +1.79E+01 2.67E-04 +2.25E+01 1.94E-04 +2.84E+01 1.37E-04 +3.57E+01 9.42E-05 +4.50E+01 6.26E-05 +5.66E+01 4.04E-05 +7.13E+01 2.53E-05 +8.97E+01 1.55E-05 +1.13E+02 9.33E-06 +1.42E+02 5.52E-06 +1.79E+02 3.23E-06 +2.25E+02 1.87E-06 +2.84E+02 1.08E-06 +3.57E+02 6.17E-07 +4.50E+02 3.53E-07 +5.66E+02 2.01E-07 +7.13E+02 1.14E-07 +8.97E+02 6.51E-08 +1.13E+03 3.70E-08 +1.42E+03 2.10E-08 +1.79E+03 1.19E-08 +2.25E+03 6.76E-09 +2.84E+03 3.83E-09 +3.57E+03 2.18E-09 +4.50E+03 1.23E-09 +5.66E+03 7.00E-10 +7.13E+03 3.97E-10 +8.97E+03 2.25E-10 +1.13E+04 1.28E-10 +1.42E+04 7.24E-11 +1.79E+04 4.10E-11 +2.25E+04 2.33E-11 +2.84E+04 1.32E-11 +3.57E+04 7.48E-12 +4.50E+04 4.24E-12 +5.66E+04 2.41E-12 +7.13E+04 1.36E-12 +8.97E+04 7.74E-13 +1.13E+05 4.39E-13 +1.42E+05 2.49E-13 +1.79E+05 1.41E-13 +2.25E+05 8.00E-14 +2.84E+05 4.54E-14 +3.57E+05 2.57E-14 +4.50E+05 1.46E-14 +5.66E+05 8.27E-15 +7.13E+05 4.69E-15 +8.97E+05 2.66E-15 + diff --git a/data/diff_spectra/mu+.dat b/data/diff_spectra/mu+.dat new file mode 100644 index 0000000..19a9f4a --- /dev/null +++ b/data/diff_spectra/mu+.dat @@ -0,0 +1,81 @@ +0.011294 1.26173569216985E-09 +0.014219 1.55890264199345E-09 +0.017901 1.92595052855896E-09 +0.022536 2.37929092970017E-09 +0.028371 2.93919634232651E-09 +0.035717 3.63067253816472E-09 +0.044965 4.48449587525947E-09 +0.056607 5.5385630991346E-09 +0.071264 6.83967248409842E-09 +0.089717 8.44530880769278E-09 +0.11294 1.04253103276171E-08 +0.14219 1.28679316007994E-08 +0.17901 1.58779302315174E-08 +0.22536 1.95847207638201E-08 +0.28371 2.41460947058135E-08 +0.35717 2.97535062073649E-08 +0.44965 3.66377211393377E-08 +0.56608 4.5076247736613E-08 +0.71264 5.53977437117546E-08 +0.89717 6.79939664126097E-08 +1.1294 8.33121051172514E-08 +1.4219 1.01885239856541E-07 +1.7901 1.24288131289989E-07 +2.2536 1.51159773156909E-07 +2.8371 1.83176612418543E-07 +3.5717 2.21021194793684E-07 +4.4965 2.65338025836637E-07 +5.6607 3.1668769116865E-07 +7.1265 3.75518250310106E-07 +8.9717 4.42129741325276E-07 +11.295 5.16782793107377E-07 +14.219 5.99804703719336E-07 +17.901 6.92027697774088E-07 +22.536 7.95038781353114E-07 +28.371 9.11611003187426E-07 +35.717 1.04561101659918E-06 +44.965 1.20120596986473E-06 +56.607 1.38120676315832E-06 +71.265 1.58490483764309E-06 +89.716 1.80613176605674E-06 +112.94 2.01675116545582E-06 +142.19 2.1984588701332E-06 +179.01 2.34893700020052E-06 +225.36 2.45634183429567E-06 +283.71 2.5140450295113E-06 +357.17 2.52063418388849E-06 +449.65 2.47864750070809E-06 +566.08 2.39288849433189E-06 +712.65 2.26905224451314E-06 +897.16 2.11294678152799E-06 +1129.4 1.93035847124502E-06 +1421.9 1.72713811975011E-06 +1790.1 1.50995604659241E-06 +2253.6 1.28624026829654E-06 +2837.1 1.06423097822524E-06 +3571.7 8.52519417530613E-07 +4496.5 6.59182801088131E-07 +5660.8 4.90681538258631E-07 +7126.5 3.50960367722511E-07 +8971.7 2.40945851540256E-07 +11294 1.58785018403949E-07 +14219 1.00509225737826E-07 +17901 6.12406959221397E-08 +22536 3.60126290669967E-08 +28371 2.05028771570566E-08 +35717 1.13401342176572E-08 +44965 6.11530800859797E-09 +56608 3.22633106214882E-09 +71264 1.67086453527603E-09 +89716 8.5181277652804E-10 +112940 4.28684184631739E-10 +142190 2.13357699128724E-10 +179010 1.05260351153269E-10 +225360 5.15586529965142E-11 +283710 2.5106495957919E-11 +357170 1.1238459063128E-11 +449650 4.95770202485376E-12 +566080 2.1793503911921E-12 +712640 9.55421835121602E-13 +897160 4.17888075003386E-13 + diff --git a/data/diff_spectra/mu-.dat b/data/diff_spectra/mu-.dat new file mode 100644 index 0000000..cdc50ee --- /dev/null +++ b/data/diff_spectra/mu-.dat @@ -0,0 +1,81 @@ +0.011294 1.23078100092017E-09 +0.014219 1.52042323137646E-09 +0.017901 1.87812688259201E-09 +0.022536 2.31986593255489E-09 +0.028371 2.86537041794303E-09 +0.035717 3.53897479636153E-09 +0.044965 4.37062672790963E-09 +0.056607 5.39719998832701E-09 +0.071264 6.6642272439789E-09 +0.089717 8.22763649404659E-09 +0.11294 1.01553731140714E-08 +0.14219 1.25333024264159E-08 +0.17901 1.54633486931837E-08 +0.22536 1.90714386602993E-08 +0.28371 2.35111337729491E-08 +0.35717 2.89687962058135E-08 +0.44965 3.5669123845335E-08 +0.56608 4.38824426266507E-08 +0.71264 5.39290906403059E-08 +0.89717 6.61911936156437E-08 +1.1294 8.11054087994195E-08 +1.4219 9.91928676891578E-08 +1.7901 1.21016493058529E-07 +2.2536 1.47203345475645E-07 +2.8371 1.78418820897792E-07 +3.5717 2.15335921742497E-07 +4.4965 2.58590889070848E-07 +5.6607 3.08734652934129E-07 +7.1265 3.66196491452731E-07 +8.9717 4.31233086716102E-07 +11.295 5.0400662683108E-07 +14.219 5.8464617233355E-07 +17.901 6.73620082956084E-07 +22.536 7.71925268027177E-07 +28.371 8.81479851474904E-07 +35.717 1.00507635805142E-06 +44.965 1.14576664363357E-06 +56.607 1.30552811967367E-06 +71.265 1.48349351412288E-06 +89.716 1.67433591064617E-06 +112.94 1.85024745989403E-06 +142.19 1.99578439334556E-06 +179.01 2.11291534712715E-06 +225.36 2.19222355437902E-06 +283.71 2.22869090438626E-06 +357.17 2.22163331627848E-06 +449.65 2.17360374543907E-06 +566.08 2.08897032604734E-06 +712.65 1.97278111544955E-06 +897.16 1.83013117383024E-06 +1129.4 1.66607213485201E-06 +1421.9 1.48568667928371E-06 +1790.1 1.29473833346287E-06 +2253.6 1.09958551856123E-06 +2837.1 9.07211776114866E-07 +3571.7 7.24818606842616E-07 +4496.5 5.59090376793188E-07 +5660.8 4.15277542078683E-07 +7126.5 2.96470603575589E-07 +8971.7 2.0321545317213E-07 +11294 1.33749076862655E-07 +14219 8.4577822726358E-08 +17901 5.14962564039684E-08 +22536 3.02675222222383E-08 +28371 1.72269491863213E-08 +35717 9.52688965168057E-09 +44965 5.13738516236392E-09 +56608 2.71056883624122E-09 +71264 1.40392870007439E-09 +89716 7.15838472899279E-10 +112940 3.60315301589689E-10 +142190 1.79361750286573E-10 +179010 8.85035594111962E-11 +225360 4.33578400196235E-11 +283710 2.11162447936965E-11 +357170 9.45261667163029E-12 +449650 4.17045860412233E-12 +566080 1.83350244924657E-12 +712640 8.03885096856871E-13 +897160 3.51639035184732E-13 + diff --git a/data/diff_spectra/neutron.dat b/data/diff_spectra/neutron.dat new file mode 100644 index 0000000..f83de9a --- /dev/null +++ b/data/diff_spectra/neutron.dat @@ -0,0 +1,80 @@ +1.13E-02 1.92E-02 +1.42E-02 1.57E-02 +1.79E-02 1.28E-02 +2.25E-02 1.05E-02 +2.84E-02 8.68E-03 +3.57E-02 7.20E-03 +4.50E-02 6.00E-03 +5.66E-02 5.03E-03 +7.13E-02 4.24E-03 +8.97E-02 3.60E-03 +1.13E-01 3.07E-03 +1.42E-01 2.64E-03 +1.79E-01 2.29E-03 +2.25E-01 1.99E-03 +2.84E-01 1.74E-03 +3.57E-01 1.53E-03 +4.50E-01 1.34E-03 +5.66E-01 1.18E-03 +7.13E-01 1.03E-03 +8.97E-01 8.94E-04 +1.13E+00 7.65E-04 +1.42E+00 6.43E-04 +1.79E+00 5.27E-04 +2.25E+00 4.20E-04 +2.84E+00 3.22E-04 +3.57E+00 2.38E-04 +4.50E+00 1.69E-04 +5.66E+00 1.17E-04 +7.13E+00 8.03E-05 +8.97E+00 5.64E-05 +1.13E+01 4.13E-05 +1.42E+01 3.17E-05 +1.79E+01 2.52E-05 +2.25E+01 2.08E-05 +2.84E+01 1.81E-05 +3.57E+01 1.66E-05 +4.50E+01 1.60E-05 +5.66E+01 1.57E-05 +7.13E+01 1.52E-05 +8.97E+01 1.39E-05 +1.13E+02 1.20E-05 +1.42E+02 9.64E-06 +1.79E+02 7.06E-06 +2.25E+02 4.65E-06 +2.84E+02 2.74E-06 +3.57E+02 1.45E-06 +4.50E+02 7.08E-07 +5.66E+02 3.30E-07 +7.13E+02 1.53E-07 +8.97E+02 7.43E-08 +1.13E+03 3.85E-08 +1.42E+03 2.13E-08 +1.79E+03 1.23E-08 +2.25E+03 7.27E-09 +2.84E+03 4.34E-09 +3.57E+03 2.60E-09 +4.50E+03 1.56E-09 +5.66E+03 9.32E-10 +7.13E+03 5.58E-10 +8.97E+03 3.34E-10 +1.13E+04 2.00E-10 +1.42E+04 1.19E-10 +1.79E+04 7.14E-11 +2.25E+04 4.27E-11 +2.84E+04 2.55E-11 +3.57E+04 1.53E-11 +4.50E+04 9.13E-12 +5.66E+04 5.46E-12 +7.13E+04 3.26E-12 +8.97E+04 1.95E-12 +1.13E+05 1.17E-12 +1.42E+05 6.99E-13 +1.79E+05 4.18E-13 +2.25E+05 2.50E-13 +2.84E+05 1.50E-13 +3.57E+05 8.98E-14 +4.50E+05 5.38E-14 +5.66E+05 3.22E-14 +7.13E+05 1.93E-14 +8.97E+05 1.16E-14 diff --git a/data/diff_spectra/proton.dat b/data/diff_spectra/proton.dat new file mode 100644 index 0000000..d10acba --- /dev/null +++ b/data/diff_spectra/proton.dat @@ -0,0 +1,80 @@ +1.13E-02 2.33E-07 +1.42E-02 2.19E-07 +1.79E-02 2.06E-07 +2.25E-02 1.94E-07 +2.84E-02 1.83E-07 +3.57E-02 1.73E-07 +4.50E-02 1.65E-07 +5.66E-02 1.58E-07 +7.13E-02 1.52E-07 +8.98E-02 1.48E-07 +1.13E-01 1.45E-07 +1.42E-01 1.44E-07 +1.79E-01 1.45E-07 +2.25E-01 1.48E-07 +2.84E-01 1.53E-07 +3.57E-01 1.60E-07 +4.50E-01 1.71E-07 +5.66E-01 1.85E-07 +7.13E-01 2.02E-07 +8.98E-01 2.24E-07 +1.13E+00 2.49E-07 +1.42E+00 2.79E-07 +1.79E+00 3.12E-07 +2.25E+00 3.51E-07 +2.84E+00 3.93E-07 +3.57E+00 4.39E-07 +4.50E+00 4.88E-07 +5.66E+00 5.39E-07 +7.13E+00 5.91E-07 +8.98E+00 6.43E-07 +1.13E+01 6.94E-07 +1.42E+01 7.42E-07 +1.79E+01 7.87E-07 +2.25E+01 8.26E-07 +2.84E+01 8.58E-07 +3.57E+01 8.81E-07 +4.50E+01 8.92E-07 +5.66E+01 8.86E-07 +7.13E+01 8.61E-07 +8.98E+01 8.12E-07 +1.13E+02 7.38E-07 +1.42E+02 6.43E-07 +1.79E+02 5.34E-07 +2.25E+02 4.23E-07 +2.84E+02 3.20E-07 +3.57E+02 2.33E-07 +4.50E+02 1.65E-07 +5.66E+02 1.14E-07 +7.13E+02 7.72E-08 +8.98E+02 5.17E-08 +1.13E+03 3.41E-08 +1.42E+03 2.17E-08 +1.79E+03 1.29E-08 +2.25E+03 6.34E-09 +2.84E+03 2.16E-09 +3.57E+03 6.59E-10 +4.50E+03 3.31E-10 +5.66E+03 2.19E-10 +7.13E+03 1.47E-10 +8.98E+03 9.59E-11 +1.13E+04 6.03E-11 +1.42E+04 3.69E-11 +1.79E+04 2.21E-11 +2.25E+04 1.29E-11 +2.84E+04 7.48E-12 +3.57E+04 4.26E-12 +4.50E+04 2.40E-12 +5.66E+04 1.33E-12 +7.13E+04 7.37E-13 +8.98E+04 4.05E-13 +1.13E+05 2.21E-13 +1.42E+05 1.20E-13 +1.79E+05 6.50E-14 +2.25E+05 3.51E-14 +2.84E+05 1.89E-14 +3.57E+05 1.01E-14 +4.50E+05 5.43E-15 +5.66E+05 2.90E-15 +7.13E+05 1.55E-15 +8.98E+05 8.29E-16 diff --git a/geant_image.py b/geant_image.py index 787ed98..01a3211 100644 --- a/geant_image.py +++ b/geant_image.py @@ -123,4 +123,4 @@ def random_composite(t, ntrack=20, trans=trans_linear): img = random_composite(t, ntrack=args.N, trans=trans_quant) img.save(args.output_file, format='jpeg', quality=98) - print "Saved to", args.output_file + print("Saved to", args.output_file) diff --git a/include/OutputManager.hh b/include/OutputManager.hh index ae9a2a4..d5d47d5 100644 --- a/include/OutputManager.hh +++ b/include/OutputManager.hh @@ -9,7 +9,7 @@ // the config file and dynamically allocate, // but it's a big pain in the ass to get the // DetectorConstruction to communicate with this object :( -#define MAX_PIX 5001 +#define MAX_PIX 3001 class OutputManager { diff --git a/pycraysim/pycraysim/__init__.py b/pycraysim/pycraysim/__init__.py new file mode 100644 index 0000000..b7b0605 --- /dev/null +++ b/pycraysim/pycraysim/__init__.py @@ -0,0 +1,2 @@ +from . import stream +from . import utils \ No newline at end of file diff --git a/pycraysim/pycraysim/stream/__init__.py b/pycraysim/pycraysim/stream/__init__.py new file mode 100644 index 0000000..cac411c --- /dev/null +++ b/pycraysim/pycraysim/stream/__init__.py @@ -0,0 +1 @@ +from .simstream import * \ No newline at end of file diff --git a/pycraysim/pycraysim/stream/simstream.py b/pycraysim/pycraysim/stream/simstream.py new file mode 100644 index 0000000..147f6c3 --- /dev/null +++ b/pycraysim/pycraysim/stream/simstream.py @@ -0,0 +1,182 @@ +import subprocess as sp + +from multiprocessing import Pool + +import os +import os.path as osp + +from ..utils import get_config_template, get_binary, seed_stream, PACKAGE_ROOT + +from string import Template + +from itertools import izip, repeat + +import tempfile + +__all__ = [ + 'sim_job', + 'sim_worker', + 'SimStream' +] + +def sim_worker(args): + config, working_dir, seed, template = args + + workspace = tempfile.mkdtemp(dir=working_dir) + + if template is None: + template = get_config_template() + + config_path = osp.abspath(osp.join(workspace, 'run.mac')) + output_path = osp.abspath(osp.join(workspace, 'output')) + + config = config.copy() + config['output'] = output_path + config['seed1'] = seed[0] + config['seed2'] = seed[1] + + with open(config_path, 'w') as f: + f.write( + Template(template).safe_substitute(**config) + ) + + process = sp.Popen( + args=[get_binary(), config_path], + cwd=PACKAGE_ROOT, + stdin=sp.PIPE, + stdout=sp.PIPE, + stderr=sp.PIPE + ) + + stdout, stderr = process.communicate() + retcode = process.wait() + + if retcode == 0: + return config, stdout, stderr, workspace, output_path + '.root' + else: + return config, stdout, stderr, workspace, None + +def naming(config): + config = config.copy() + + config.pop('energyHisto', None) + config.pop('output', None) + + props = sorted([(k, v) for k, v in config.items()], key=lambda x: x[0]) + name = '_'.join(['%s=%s' % (k, v) for k, v in props]) + return name + '.root' + + +def move(destination, config, stdout, stderr, retcode): + import shutil as sh + import json + + config = config.copy() + origin = config['output'] + '.root' + + try: + if retcode == 0: + sh.move(origin, destination) + else: + raise Exception('Return code is not 0!') + except: + import traceback + traceback.print_exc() + + with open(destination + '.json', 'w') as f: + json.dump(config, f) + + with open(destination + '.stdout', 'w') as f: + f.write(stdout) + + with open(destination + '.stderr', 'w') as f: + f.write(stderr) + + return destination + +def sim_job(config): + config = config.copy() + try: + target_dir = config.pop('target') + target_path = osp.join(target_dir, naming(config)) + + if osp.exists(target_path): + print('Output file already exists. Skipping.') + return + except: + import traceback + traceback.print_exc() + return + + workspace = tempfile.mkdtemp(prefix='crayfis-sim') + + try: + template = get_config_template() + + config_path = osp.abspath(osp.join(workspace, 'run.mac')) + output_path = osp.abspath(osp.join(workspace, 'output')) + + config['output'] = output_path + + with open(config_path, 'w') as f: + f.write( + Template(template).substitute(**config) + ) + + process = sp.Popen( + args=[get_binary(), config_path], + cwd=PACKAGE_ROOT, + stdin=sp.PIPE, + stdout=sp.PIPE, + stderr=sp.PIPE + ) + + stdout, stderr = process.communicate() + retcode = process.wait() + + move(target_path, config, stdout, stderr, retcode) + except: + import traceback + traceback.print_exc() + finally: + try: + import shutil as sh + sh.rmtree(workspace) + except: + import traceback + traceback.print_exc() + + +class SimStream(object): + def __init__(self, target_dir, configs, super_seed, copy_op=move, num_workers=1): + self.template = get_config_template() + self.work_dir = tempfile.mkdtemp(prefix='craysim') + + self.seed_stream = seed_stream(super_seed) + self.pool = Pool(num_workers, maxtasksperchild=1) + + config_stream = izip( + configs, repeat(self.work_dir), self.seed_stream, repeat(self.template) + ) + + self.result_stream = self.pool.imap(sim_worker, config_stream, chunksize=1) + self.copy_op = copy_op + self.target_dir = target_dir + + def stream(self): + for config, stdout, stderr, workspace, output_path in self.result_stream: + if output_path is None: + raise Exception(stdout + '\n\n' + stderr) + + try: + yield self.copy_op(self.target_dir, config, stdout, stderr) + except Exception as e: + import traceback + import warnings + + warnings.warn(str(config)) + traceback.print_exc() + + def clean(self): + import shutil as sh + sh.rmtree(self.work_dir) \ No newline at end of file diff --git a/pycraysim/pycraysim/utils/__init__.py b/pycraysim/pycraysim/utils/__init__.py new file mode 100644 index 0000000..abcd374 --- /dev/null +++ b/pycraysim/pycraysim/utils/__init__.py @@ -0,0 +1,5 @@ +from .configs import * +from .args import * + +if not check_spectra(particles): + generate_spectra(particles) diff --git a/scripts/utils.py b/pycraysim/pycraysim/utils/args.py similarity index 100% rename from scripts/utils.py rename to pycraysim/pycraysim/utils/args.py diff --git a/pycraysim/pycraysim/utils/configs.py b/pycraysim/pycraysim/utils/configs.py new file mode 100644 index 0000000..9c78c21 --- /dev/null +++ b/pycraysim/pycraysim/utils/configs.py @@ -0,0 +1,265 @@ +import os +import os.path as osp + +import array +import numpy as np + +particles = ['e-', 'e+', 'gamma', 'mu-', 'mu+', 'proton'] + +def get_package_root(): + path = osp.abspath(osp.dirname(__file__)) + + for i in range(3): + path = osp.split(path)[0] + + return path + +PACKAGE_ROOT = get_package_root() + +def seed_stream(super_seed): + import random + random.seed(super_seed) + + used_seeds= set() + + while True: + seed = (random.randrange(int(1.0e+6)), random.randrange(int(1.0e+6))) + + if seed in used_seeds: + continue + else: + used_seeds.add(seed) + yield seed + +def get_seeds(n, super_seed): + import random + random.seed(super_seed) + + numbers = [] + + while len(set(numbers)) != n: + numbers = [ + (random.randrange(int(1.0e+6)), random.randrange(int(1.0e+6))) + for _ in range(n) + ] + + return numbers + +def get_resource(paths, dir=True): + resourse = osp.abspath(osp.join(PACKAGE_ROOT, *paths)) + + assert osp.exists(resourse) and (osp.isdir if dir else osp.isfile)(resourse), \ + 'resourse {what} [{where}] does not seem like a {what}'.format( + where = resourse, what = 'directory' if dir else 'file' + ) + + return resourse + +get_dir = lambda *paths: get_resource(paths, dir=True) +get_file = lambda *paths: get_resource(paths, dir=False) + +get_config_path = lambda : get_file('config/run.mac.template') + +def get_config_template(path='config/run.mac.template'): + path = get_file(path) + + with open(path, 'r') as f: + return f.read() + +def get_spectrum(particle): + import ROOT as r + + try: + path = get_file('data/diff_spectra/', particle + '.dat') + + datfile = np.loadtxt(path) + except Exception as e: + datfile = np.loadtxt(particle) + raise e + + ns = np.arange(datfile.shape[0] + 1) + bins = 10.0 ** (ns / 10.0 - 2) + assert np.allclose(datfile[:, 0], (bins[1:] + bins[:-1]) / 2.0, rtol=1.0e-2, atol=0.0) + + # ROOT is picky and wants python array.array for TH1F constructor + binsx = array.array('d', bins) + h = r.TH1F("energy", particle, len(binsx)-1, binsx) + for i, rate in enumerate(datfile[:, 1]): + h.Fill( + (binsx[i] + binsx[i + 1]) / 2, + rate * (binsx[i + 1] - binsx[i]) + ) + + return h + +def check_spectra(particles=particles): + try: + spectra_dir = get_dir('data', 'background_spectra') + + for particle in particles: + if not osp.exists(osp.join(spectra_dir, particle + '.root')): + return False + + return True + except: + return False + +def generate_spectra(particles=particles): + import ROOT as r + + data_dir = get_dir('data') + spectra_dir = osp.join(data_dir, 'background_spectra') + + try: + os.makedirs(spectra_dir) + except: + pass + + for particle in particles: + f_out = r.TFile(osp.join(spectra_dir, particle + '.root'), 'RECREATE') + h = get_spectrum(particle) + h.Write() + f_out.Close() + + return spectra_dir + +def get_total_flux(path): + import ROOT as r + + f = r.TFile(path) + h = f.Get('energy') + + return np.sum([ + h.GetBinContent(i) + for i in range(h.GetSize()) + ]) + +def get_priors(data_root=get_dir('data'), spectra_dir='background_spectra'): + spectra_path = osp.join(data_root, spectra_dir) + + flux = dict() + for particle in particles: + particle_flux = get_total_flux(osp.join(spectra_path, particle + '.root')) + flux[particle] = particle_flux + + total_flux = np.sum([ v for k, v in flux.values() ]) + + return dict([ + (k, v / total_flux) + for k, v in flux.items() + ]) + +BINARY = 'TestEm1' + +def get_binary(): + return get_file('bin', BINARY) + +def generate_configs(output_dir, ngen=int(1.0e+5), pixWidth=1.5, pixDepth=(1, ), npix=5000, spectra_path=None, jobs=1): + print('Pixel depths: %s' % pixDepth) + + hist_dir = generate_spectra(particles=particles) + hists = [ + osp.join(hist_dir, p + '.root') + for p in particles + ] + + fluxes = [ get_total_flux(hist) for hist in hists ] + print("Total flux: %.3e" % np.sum(fluxes)) + print( + "Fluxes:\n %s" % '\n '.join([ + "%s: %.3e MeV" % (particle, flux) + for particle, flux in zip(particles, fluxes) + ]) + ) + + priors = [ flux / np.sum(fluxes) for flux in fluxes ] + print( + "Priors:\n %s" % '\n '.join([ + "%s: %.3e" % (particle, prior) + for particle, prior in zip(particles, priors) + ]) + ) + + assert len(hists), 'there is no data for cosmic background spectra!' + + if spectra_path is None: + spectra_path = hist_dir + + runtime_hists = [ + osp.join(spectra_path, osp.basename(hist)) + for hist in hists + ] + + for job in range(jobs): + for depth in pixDepth: + for particle, hist in zip(particles, runtime_hists): + name = '{particle}_{job:06d}_depth={depth}'.format(particle=particle, job=job, depth=depth) + config = dict( + beamEnergy=-1, + particle=particle, + energyHisto=hist, + ngen=ngen, + pixDepth=depth, + pixWidth=pixWidth, + npix=npix, + output=osp.join(output_dir, name) + ) + + yield name, config + +if __name__ == '__main__': + import argparse + import shutil as sh + + generate_spectra() + + parser = argparse.ArgumentParser(description='Generate configs for cosmic background simulation.') + parser.add_argument('ngen', type=str, help='number of particles of each type to shoot') + parser.add_argument('-o', '--output', default='./events/', type=str, help='simulation output directory') + parser.add_argument('-w', '--pixWidth', default=1.5, type=float, help='pixel width') + parser.add_argument('-n', '--npix', default=3000, type=int, help='linear size of the sensor') + parser.add_argument('-r', '--runtime_spectra_path', default='data/background_spectra/', type=str, help='overrides path to spectra files') + parser.add_argument('-s', '--super_seed', default=12345, type=int, help='seed to generate seeds') + parser.add_argument('-j', '--jobs', default=1000, type=int, help='split simulation between number of jobs (per particle type)') + parser.add_argument('-d', '--pixDepth', default=None, type=float, help='pixel depth (by default simulation enumerates a range of depths).') + parser.add_argument('-c', '--configs_output', default='./configs/', type=str, help='output for the generated config files') + + args = parser.parse_args() + + try: + os.makedirs(args.output) + except OSError: + pass + + with open(get_config_path(), 'r') as _f: + from string import Template + config = Template(_f.read()) + + configs = list(generate_configs( + output_dir = args.output, + ngen = args.ngen, + pixWidth = args.pixWidth, + pixDepth=[args.pixDepth] if args.pixDepth is not None else None, + npix = args.npix, + jobs=args.jobs, + spectra_path=args.runtime_spectra_path + )) + + super_seed = args.super_seed + + for (_, values), (seed1, seed2) in zip(configs, get_seeds(len(configs), super_seed=super_seed)): + values['seed1'] = seed1 + values['seed2'] = seed2 + + try: + os.makedirs(args.configs_output) + except OSError: + pass + + print('There are total %d tasks.' % len(configs)) + + for i, (name, values) in enumerate(configs): + path = osp.join(args.configs_output, '%09d_%s.mac' % (i, name)) + + with open(path, 'w') as f: + f.write(config.substitute(values)) diff --git a/pycraysim/scripts/craysim_job.py b/pycraysim/scripts/craysim_job.py new file mode 100644 index 0000000..303fd5b --- /dev/null +++ b/pycraysim/scripts/craysim_job.py @@ -0,0 +1,16 @@ +from pycraysim.stream import sim_job + +if __name__ == '__main__': + import sys + args = sys.argv[1:] + + config = dict() + + for arg in args: + tokens = arg.split('=') + assert len(tokens) == 2, 'arguments should be in form =' + + k, v = tokens + config[k] = v + + sim_job(config) \ No newline at end of file diff --git a/pycraysim/setup.py b/pycraysim/setup.py new file mode 100644 index 0000000..2cd03a0 --- /dev/null +++ b/pycraysim/setup.py @@ -0,0 +1,43 @@ +from setuptools import setup, find_packages + +setup( + name='craysim', + + version='0.1.1', + + description="""CRAYFIS simulation stream""", + + url='https://github.com/maxim-borisyak/crayfis-stream', + + author='Maxim Borisyak, Chase Shimmin', + author_email='mborisyak at hse dot ru', + + maintainer = 'Maxim Borisyak, Chase Shimmin', + maintainer_email = 'mborisyak at hse dot ru', + + license='MIT', + + classifiers=[ + 'Development Status :: 4 - Beta', + + 'Intended Audience :: Science/Research', + + 'License :: OSI Approved :: MIT License', + + 'Programming Language :: Python :: 3', + ], + + keywords='', + + packages=find_packages(where='.', exclude=['contrib', 'examples', 'docs', 'tests']), + + extras_require={ + 'dev': ['check-manifest'], + 'test': ['nose>=1.3.0'], + }, + + include_package_data=True, + + package_data = { + }, +) diff --git a/run-batch.py b/run-batch.py old mode 100755 new mode 100644 diff --git a/run.py b/run.py new file mode 100644 index 0000000..a0ec571 --- /dev/null +++ b/run.py @@ -0,0 +1,17 @@ +import os +import sys + +import subprocess + +if __name__ == '__main__': + print(sys.argv) + target = int(sys.argv[1]) + for item in os.listdir('./configs'): + path = os.path.join('./configs', item) + i = int(item.split('_')[0]) + if i == target: + retcode = subprocess.call([ + 'bash', 'seg_wrapper.sh', './bin/TestEm1', path + ]) + + sys.exit(retcode) diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..27b91ce --- /dev/null +++ b/run.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +source /usr/opt/root/bin/thisroot.sh +source /usr/opt/geant/share/Geant4-10.1.3/geant4make/geant4make.sh +python run.py $1 diff --git a/scripts/configs.py b/scripts/configs.py deleted file mode 100644 index 003f2b9..0000000 --- a/scripts/configs.py +++ /dev/null @@ -1,154 +0,0 @@ -from utils import dict_product -import os -import os.path as osp - -import numpy as np - -__all__ = [ - 'generate_configs' -] - - -def get_resourse(path, dir=True): - here = osp.dirname(osp.abspath(__file__)) - - resourse = osp.abspath(osp.join(here, path)) - assert osp.exists(resourse) and (osp.isdir if dir else osp.isfile)(resourse), \ - 'resourse %(what) [%(where)] does not seem like a %s' % dict( - where = resourse, what = 'directory' if dir else 'file' - ) - - return resourse - -get_dir = lambda path: get_resourse(path, dir=True) -get_file = lambda path: get_resourse(path, dir=False) - -def get_total_flux(path): - import ROOT as r - - f = r.TFile(path) - h = f.Get('particleEnergy') - - return np.sum([ - h.GetBinContent(i) - for i in range(h.GetSize()) - ]) - - -def generate_configs(output_dir, ngen=int(1.0e+5), pixDepth=1, pixWidth=1.5, npix=5000, spectra_path=None, jobs=1): - hist_dir = get_dir('../data/background_spectra') - hists = [ - osp.join(hist_dir, item) - for item in os.listdir(hist_dir) - if item.endswith('.root') - ] - - particle_names = [ - osp.basename(hist)[:-len('.root')] for hist in hists - ] - - fluxes = [ get_total_flux(hist) for hist in hists ] - print("Total flux: %.3e" % np.sum(fluxes)) - priors = [ flux / np.sum(fluxes) for flux in fluxes ] - print( - "Priors:\n %s" % '\n '.join([ - "%s: %.3e" % (particle, prior) - for particle, prior in zip(particle_names, priors) - ]) - ) - - assert len(hists), 'there is no data for cosmic background spectra!' - - if spectra_path is None: - spectra_path = hist_dir - - runtime_hists = [ - osp.join(spectra_path, osp.basename(hist)) - for hist in hists - ] - - configs = dict( - beamEnergy=-1, - particle_meta=[ - dict( - output=osp.join(output_dir, '%s_%04d' % (osp.basename(hist)[:-len('.root')], job)), - particle=particle_name, - energyHisto=hist, - job=job - ) - for particle_name, hist in zip(particle_names, runtime_hists) - for job in range(jobs) - ], - ngen=ngen, - pixDepth=pixDepth, - pixWidth=pixWidth, - npix=npix, - ) - - return dict_product(configs) - -def get_seeds(n, super_seed): - import random - random.seed(super_seed) - - numbers = [] - - while len(set(numbers)) != n: - numbers = [ - (random.randrange(int(1.0e+6)), random.randrange(int(1.0e+6))) - for _ in range(n) - ] - - return numbers - -if __name__ == '__main__': - import argparse - import shutil as sh - - parser = argparse.ArgumentParser(description='Generate configs for cosmic background simulation.') - parser.add_argument('ngen', type=str, help='number of particles of each type to shoot') - parser.add_argument('-o', '--output', default='./events/', type=str, help='simulation output directory') - parser.add_argument('-d', '--pixDepth', default=1.0, type=float, help='pixel depth') - parser.add_argument('-w', '--pixWidth', default=1.5, type=float, help='pixel width') - parser.add_argument('-n', '--npix', default=5000, type=float, help='linear size of the sensor') - parser.add_argument('-r', '--runtime_spectra_path', default='data/background_spectra/', type=str, help='overrides path to spectra files') - parser.add_argument('-s', '--super_seed', default=12345, type=int, help='seed to generate seeds') - parser.add_argument('-j', '--jobs', default=1, type=int, help='split simulation between number of jobs (per particle type)') - parser.add_argument('-c', '--configs_output', default='./configs/', type=str, help='output for the generated config files') - - args = parser.parse_args() - - try: - os.makedirs(args.output) - except OSError: - pass - - with open(get_file('../data/config/run.mac.template'), 'r') as _f: - from string import Template - config = Template(_f.read()) - - configs = list(generate_configs( - output_dir = args.output, - ngen = args.ngen, - pixDepth = args.pixDepth, - pixWidth = args.pixWidth, - npix = args.npix, - jobs=args.jobs, - spectra_path=args.runtime_spectra_path - )) - - try: - os.makedirs(args.configs_output) - except OSError: - pass - - super_seed = args.super_seed - - for values, (seed1, seed2) in zip(configs, get_seeds(len(configs), super_seed=super_seed)): - particle = values['particle'] - job = values['job'] - values['seed1'] = seed1 - values['seed2'] = seed2 - - with open(osp.join(args.configs_output, '%s_%04d.mac' % (particle, job)), 'w') as f: - f.write(config.substitute(values))