Skip to content

Commit

Permalink
Added information text to reduction. Also modified the sfCalculator i…
Browse files Browse the repository at this point in the history
…nput works. This refs #4303
  • Loading branch information
JeanBilheux committed Mar 6, 2012
1 parent 7bfd240 commit 46a90d8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,10 @@ def calculateAndFit(numerator='',
return cal1

#if __name__ == '__main__':
def calculate(string_runs=None, list_peak_back=None, output_path=None):
def calculate(string_runs=None,
list_attenuator=None,
list_peak_back=None,
output_path=None):
"""
In this current version, the program will automatically calculates
the scaling function for up to, and included, 6 attenuators.
Expand All @@ -524,6 +527,8 @@ def calculate(string_runs=None, list_peak_back=None, output_path=None):
The string runs has to be specified this way:
string_runs = "run#1:nbr_attenuator, run#2:nbr_attenuator...."
list_attenuator: list of attenuators
the list_peak_back is specified this way:
list_peak_back =
[[peak_min_run1, peak_max_run1, back_min_run1, back_max_run1],
Expand All @@ -540,35 +545,33 @@ def calculate(string_runs=None, list_peak_back=None, output_path=None):
list_runs = ['55889', '55890', '55891', '55892', '55893', '55894',
'55895', '55896', '55897', '55898', '55899', '55900',
'55901', '55902']
list_attenuator = [0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4]


nexus_path = '/mnt/hgfs/j35/results/'
pre = 'REF_L_'
nexus_path_pre = nexus_path + pre
post = '_event.nxs'

for (offset, item) in enumerate(list_runs):
list_runs[offset] = nexus_path_pre + list_runs[offset] + post
list_runs[offset] = nexus_path_pre + offset + post

else:
#ex: string_runs="/mnt/hgfs/j35/REF_L_55889_event.nxs:0,
# /mnt/hgfs/j35/REF_L_55890_event.nxs:1,
# /mnt/hgfs/j35/REF_L_55891_event.nxs:1,
# /mnt/hgfs/j35/REF_L_55892_event.nxs:1,
# /mnt/hgfs/j35/REF_L_55893_event.nxs:1,
# /mnt/hgfs/j35/REF_L_55894_event.nxs:1,
# /mnt/hgfs/j35/REF_L_55895_event.nxs:1,
# /mnt/hgfs/j35/REF_L_55896_event.nxs:2,
# /mnt/hgfs/j35/REF_L_55897_event.nxs:2,
# /mnt/hgfs/j35/REF_L_55898_event.nxs:2,
# /mnt/hgfs/j35/REF_L_55899_event.nxs:3,
# /mnt/hgfs/j35/REF_L_55900_event.nxs:3,
# /mnt/hgfs/j35/REF_L_55901_event.nxs:4,
# /mnt/hgfs/j35/REF_L_55902_event.nxs:4"
dico = createIndividualList(string_runs)
list_runs = dico['list_runs']

for (offset, item) in enumerate(list_runs):
_File = FileFinder.findRuns("REF_L%d" %item)
if len(_File)>0 and os.path.isfile(_File[0]):
list_runs[offset] = _File[0]
else:
msg = "RefLReduction: could not find run %d\n" % _run
msg += "Add your data folder to your User Data Directories in the File menu"
raise RuntimeError(msg)

list_attenuator = dico['list_attenuator']

if (list_attenuator is None):
list_attenuator = [0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4]

if (list_peak_back is None):
list_peak_back = zeros((len(list_runs), 4)) #[peak_min, peak_max, back_min, back_max]
list_peak_back[9, ] = [128, 136, 120, 145]
Expand Down Expand Up @@ -665,7 +668,9 @@ def calculate(string_runs=None, list_peak_back=None, output_path=None):
if (output_path is None):
output_path = '/home/j35/Desktop/'

output_pre = 'SFcalculator_lr' + str(lambdaRequest[0][0])
_lambdaRequest = "{0:.2f}".format(lambdaRequest[0][0])

output_pre = 'SFcalculator_lr' + str(_lambdaRequest)
output_ext = '.txt'
output_file = output_path + output_pre + output_ext

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,18 +797,32 @@ def applySF(InputWorkspace,
Function that apply scaling factor to data using sfCalculator.txt
file created by the sfCalculator procedure
"""


print 'Apply SF'
#retrieve the lambdaRequested and check if we can find the sfCalculator
#file corresponding to that lambda
_lr = getLambdaValue(mtd[InputWorkspace])
_lr_value = _lr[0]

output_path= sfCalculatorPath
output_pre = 'SFcalculator_lr' + str(_lr_value)
_lr_value = float("{0:.2f}".format(_lr_value))
print '-> Lambda Requested: {0:2f}'.format(_lr_value)
delta_range = 0.05
# print '-> using delta range: {0:2f}'.format(delta_range)
list_of_delta = _lr_value + 0.01 * (numpy.arange(11) - 5)
list_of_output_pre = ''
output_ext = '.txt'
sfCalculatorFile = output_path+ output_pre + output_ext

if (os.path.isfile(sfCalculatorFile)):
output_path= sfCalculatorPath
sfCalculatorFile = None
print '-> Checking if SF file of lambda requested exists'
for i in list_of_delta:
output_pre = 'SFcalculator_lr' + str(i)
_sfCalculatorFile = output_path + output_pre + output_ext
if (os.path.isfile(_sfCalculatorFile)):
sfCalculatorFile = _sfCalculatorFile
# print '--> File ' + _sfCalculatorFile + ' ... FOUND and will be used'

if (sfCalculatorFile is not None):

print '--> Using scaling facto file ' + sfCalculatorFile

#parse file and put info into array
f = open(sfCalculatorFile,'r')
Expand All @@ -828,8 +842,8 @@ def applySF(InputWorkspace,
s1h_value = s1h[0]
s2h_value = s2h[0]

print 's1h_value={0:f}'.format(s1h_value)
print 's2h_value={0:f}'.format(s2h_value)
# print 's1h_value={0:f}'.format(s1h_value)
# print 's2h_value={0:f}'.format(s2h_value)

#locate the row with s1h and s2h having the right value
s1h_precision = slitsValuePrecision * s1h_value
Expand Down Expand Up @@ -864,6 +878,10 @@ def applySF(InputWorkspace,

return OutputWorkspace

else:

print '--> scaling factor file for requested lambda NOT FOUND!'

return InputWorkspace

def _applySFtoArray(workspace,a,b,a_error,b_error):
Expand Down

0 comments on commit 46a90d8

Please sign in to comment.