Skip to content
Snippets Groups Projects
Commit 3486049a authored by Greg Henning's avatar Greg Henning
Browse files

[changed] 2D calibration, to make it much faster

parent 86be80ff
Branches
No related merge requests found
......@@ -20,10 +20,12 @@ source `hostname`_env/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
echo "# Infos:"
echo -e "\n\n# -*- Infos -*-"
pwd
python --version
echo -e "-*-..........-*-\n"
echo $TMPDIR
echo "# Running tasks"
......
......@@ -8,35 +8,48 @@
# -*- purpose: -*-
'''
Module docstring
provide one function to calibrate a 1D histogram
'''
import sys,os
#adding scripts path
sys.path.append(os.path.dirname(os.path.realpath(__file__))+"/lib")
import sys,os
import argparse
from pyhisto.histogram import Histogram as histo
def calibrate1D(h: histo,
offset: float = 0.0,
slope: float = 1.0) -> histo:
'''Return a calibrated histogram
params:
- h (pyhisto.Histogram), required
- offset (float), default = 0.0
- slope (float), default = 1.0
'''
new_h = h.copy()
for b in new_h:
b.lowedge = b.lowedge * slope + offset
b.upedge = b.upedge * slope + offset
b.upedge, b.lowedge = max(b.upedge, b.lowedge), min(b.upedge, b.lowedge)
new_h.frombins(new_h.bins)
return new_h
if __name__=="__main__":
parser = argparse.ArgumentParser(description='calibrate a 1D hisotgrams')
parser.add_argument('--slope', type=float, nargs='?',
default=1.0,
help="slope")
parser.add_argument('--offset', type=float,
default=0., nargs='?',
help="offset")
parser.add_argument('file', type=str,
nargs='?',
help="histogram.1d.txt file to read and calibrate")
args = parser.parse_args()
if os.path.exists(args.file) and os.path.isfile(args.file):
h = histo(fromfile=args.file)
for b in h:
b.lowedge = b.lowedge*args.slope + args.offset
b.upedge = b.upedge*args.slope + args.offset
b.upedge, b.lowedge = max(b.upedge, b.lowedge), min(b.upedge, b.lowedge)
h._frombins(h.bins)
print(h)
parser = argparse.ArgumentParser(description='calibrate a 1D hisotgrams')
parser.add_argument('--slope', type=float, nargs='?',
default=1.0,
help="slope")
parser.add_argument('--offset', type=float,
default=0., nargs='?',
help="offset")
parser.add_argument('file', type=str,
nargs='?',
help="histogram.1d.txt file to read and calibrate")
args = parser.parse_args()
if os.path.exists(args.file) and os.path.isfile(args.file):
h = calibrate1D(histo(fromfile=args.file),
args.offset, args.slope)
print(h)
# EOF
#!/bin/bash
#echo -e "# Calibrated bidim '$1', using parameters :\n# x offset = $2,\n# x slope= $3,\n# y offset = $4,\n# y slope = $5"
xnbins=$(head -n 6 $1 | grep xnbins | cut -d "=" -f 2 | xargs)
ynbins=$(head -n 6 $1 | grep ynbins | cut -d "=" -f 2 | xargs)
xmin=$(head -n 6 $1 | grep xmin | cut -d "=" -f 2)
new_xmin=$(echo "scale=5; $xmin * $3 + $2" | bc -l)
#echo "# $xmin -> $new_xmin"
xmax=$(head -n 6 $1 | grep xmax | cut -d "=" -f 2)
new_xmax=$(echo "scale=5; $xmax * $3 + $2" | bc -l)
#echo "# $xmax -> $new_xmax"
ymin=$(head -n 6 $1 | grep ymin | cut -d "=" -f 2)
new_ymin=$(echo "scale=5; $ymin * $5 + $4" | bc -l)
#echo "# $ymin -> $new_ymin"
ymax=$(head -n 6 $1 | grep ymax | cut -d "=" -f 2)
new_ymax=$(echo "scale=5; $ymax * $5 + $4" | bc -l)
#echo "# $ymax -> $new_ymax"
echo "# xnbins = $xnbins"
echo "# xmin = $new_xmin"
echo "# xmax = $new_xmax"
echo "# ynbins = $ynbins"
echo "# ymin = $new_ymin"
echo "# ymax = $new_ymax"
tail -n +7 $1
......@@ -45,7 +45,7 @@ def task_calibrate_ge_2D():
'targets': [target_file],
'actions': [
(create_folder, (str(h2_file.parent).replace("raw", "calibrated_2D"),)),
f"""./env.run scripts/calibrate2D.py --xoffset={time_offset} --xslope={time_slope} --yoffset={energy_offset} --yslope={energy_slope} {zh2_file} > {target_file}""",
f"""./scripts/calibrate2D.py {zh2_file} {time_offset} {time_slope} {energy_offset}{energy_slope} > {target_file}""",
],
'verbosity': 2
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment