Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 08:59:27

0001 #!/usr/bin/env python
0002 
0003 # scan through detector parameter space, and run npsim
0004 # this was used to try to brute force optics optimization
0005 
0006 import numpy as np 
0007 import math as m
0008 import sys, os, json, subprocess, shlex, re
0009 
0010 # get original compact file
0011 athenaDir = 'athena'
0012 compactInName = 'compact/drich_orig.xml'
0013 compactInFile = open(athenaDir+'/'+compactInName,'r')
0014 
0015 # lists
0016 def sep(): print('-'*40)
0017 def dictPrint(d): print(json.dumps(d,indent=4))
0018 it = {}
0019 i=0
0020 it['tuneX1'] = list(np.linspace( 50, 80, 4 ))
0021 it['tuneX2'] = list(np.linspace( 50, 80, 4 ))
0022 it['tuneZ1'] = list(np.linspace( -100, -40, 4 ))
0023 it['tuneZ2'] = list(np.linspace( -60, 0, 4 ))
0024 dictPrint(it)
0025 sep()
0026 print('i testName [tuneZ1, tuneX1,tuneZ2, tuneX2]')
0027 
0028 for tuneX1 in it['tuneX1']:
0029     for tuneZ1 in it['tuneZ1']:
0030         for tuneX2 in it['tuneX2']:
0031             for tuneZ2 in it['tuneZ2']:
0032 
0033                 # skip duplicate mirrors
0034                 if tuneX1==tuneX2 and tuneZ1==tuneZ2: continue
0035 
0036                 # set test name
0037                 testName = 'focus'
0038                 varList = [tuneX1,tuneZ1,tuneX2,tuneZ2]
0039                 for v in varList: testName += f'__{round(v,1)}'
0040                 print(i,testName,varList)
0041                 outRoot = "out/"+testName+".root"
0042 
0043                 # open new compact file
0044                 compactOutName = 'compact/drich.xml'
0045                 compactOutFile = open(athenaDir+'/'+compactOutName,'w')
0046 
0047                 # read original compact file, altering specified settings
0048                 compactInFile.seek(0,0)
0049                 for line in compactInFile.readlines():
0050                     line = re.sub('XXX1',f'{tuneX1}',line)
0051                     line = re.sub('XXX2',f'{tuneX2}',line)
0052                     line = re.sub('ZZZ1',f'{tuneZ1}',line)
0053                     line = re.sub('ZZZ2',f'{tuneZ2}',line)
0054                     compactOutFile.write(line)
0055                 compactOutFile.close()
0056 
0057                 # run npsim, and process results
0058                 def execute(l): subprocess.call(shlex.split(l))
0059                 os.system(f"exit | ./simulate.py -t12 -v -i svg -o {outRoot}")
0060                 #execute(f"./drawHits.exe {outRoot}")
0061 
0062                 i+=1
0063 
0064 compactInFile.close()