Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions krcal/map_builder/config_DEMO.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
folder = '{folderin}'
file_in = '{filein}'
file_bootstrap_map = 'bootstrap.h5'
file_out_map = '{fileoutmap}'
file_out_hists = '{fileouthist}'

# Low Background Configuration File:
ref_Z_histogram = dict(
ref_histo_file = 'ref_histos.h5',
key_Z_histo = 'histo_Z_dst' )

# run number 0 is for MC
run_number = '{runnumber}'

# event selector control

quality_ranges = dict(
r_max = 70 ) # Max R for initial quality cuts

nS1_eff_min = 0 # Min nS1==1 eff. to continue map production.
nS1_eff_max = 1.00 # Max nS1==1 eff. to continue map production.

nS2_eff_min = 0 # Min nS2==1 eff. to continue map production.
nS2_eff_max = 1.00 # Max nS2==1 eff. to continue map production.

nsigmas_Zdst = 10 # Number of sigmas to consider Z dst correct.

n_dev_rate = 10 # Number of rel. dev. to consider rate dst correct.

band_sel_params = dict(
range_Z = (20, 320) , # Z range to apply selection.
range_E = (8500,10500) , # Energy range to apply sel.
nbins_z = 15 , # Number of bins in Z axis.
nbins_e = 25 , # Number of bins in energy axis.
nsigma_sel = 3.5 , # Number of sigmas to apply sel.
eff_min = 0.00 , # Min eff. to continue map prod.
eff_max = 1.00 ) # Max eff. to continue map prod.

# get automatic binning
thr_evts_for_sel_map_bins = 1e6 # Threshold to use 50 or 100 bins.
default_n_bins = 40 # If not specified: n_bins=50 or 100.

### Histograms params
ns1_histo_params = dict(
nbins_hist = 10 ,
range_hist = (0,10),
norm = True )

ns2_histo_params = dict(
nbins_hist = 10 ,
range_hist = (0,10),
norm = True )

rate_histo_params = dict(
bin_size = 180 ,
normed = False )

## Map parameters
map_params = dict(
nbins_z = 15 ,
nbins_e = 25 ,
z_range = (20, 320) ,
e_range = (8500,11000) ,
chi2_range = (0,10000) ,
lt_range = (0,100000) ,
nmin = 25 ,
maxFailed = 600 ,
r_max = 70 ,
r_fid = 70 ,
nStimeprofile = 1800 ,
x_range = (-70,70) ,
y_range = (-70,70) ,
detector = 'demopp' ,
zrange_dv = (300,400) ,
nbins_dv = 35 )
5 changes: 4 additions & 1 deletion krcal/map_builder/config_LBphys.conf
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ map_params = dict(
r_fid = 100 ,
nStimeprofile = 1800 ,
x_range = (-200,200) ,
y_range = (-200,200) )
y_range = (-200,200) ,
detector = 'new' ,
zrange_dv = (500, 625) ,
nbins_dv = 35 )
19 changes: 17 additions & 2 deletions krcal/map_builder/map_builder_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,12 @@ def add_krevol(maps : ASectorMap,
x_range : Tuple[float, float],
y_range : Tuple[float, float],
XYbins : Tuple[int, int],
**kwargs ) -> None:
detector : str = 'new',
zrange_dv : Tuple[float, float] = (500, 625),
nbins_dv : int = 35,
zrange_lt : Tuple[float,float] = (0, 550),
zslices_lt : int = 50,
**kwargs ) -> None:
"""
Adds time evolution dataframe to the map

Expand Down Expand Up @@ -546,7 +551,12 @@ def add_krevol(maps : ASectorMap,
xr_map = x_range,
yr_map = y_range,
nx_map = XYbins[0],
ny_map = XYbins[1])
ny_map = XYbins[1],
detector = detector,
zrange_lt = zrange_lt,
zslices_lt = zslices_lt,
zrange_dv = zrange_dv,
nbins_dv = nbins_dv)

pars_ec = cut_time_evolution(masks_time = masks_time,
dst = dst,
Expand All @@ -555,6 +565,7 @@ def add_krevol(maps : ASectorMap,

e0par = np.array([pars['e0'].mean(), pars['e0'].var()**0.5])
ltpar = np.array([pars['lt'].mean(), pars['lt'].var()**0.5])

print(" Mean core E0: {0:.1f}+-{1:.1f} pes".format(*e0par))
print(" Mean core Lt: {0:.1f}+-{1:.1f} mus".format(*ltpar))

Expand All @@ -578,6 +589,9 @@ def compute_map(dst : pd.DataFrame,
r_max : float = 200,
x_range : Tuple[float, float] = (-200,200),
y_range : Tuple[float, float] = (-200,200),
detector : str = 'new',
zrange_dv : Tuple[float, float] = (500, 625),
nbins_dv : int = 35 ,
**kwargs ) -> ASectorMap:

maps = calculate_map (dst = dst,
Expand Down Expand Up @@ -613,6 +627,7 @@ def compute_map(dst : pd.DataFrame,
ny = XYbins[1],
run_number = int(run_number))


return no_peripheral

def apply_cuts(dst : pd.DataFrame ,
Expand Down
78 changes: 74 additions & 4 deletions krcal/map_builder/map_builder_functions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from pytest import mark
from pytest import fixture
from numpy.testing import assert_raises
from numpy.testing import assert_allclose

from invisible_cities.io .dst_io import load_dst
from invisible_cities.core.testing_utils import assert_dataframes_close
from invisible_cities.core.configure import configure
from invisible_cities.reco.corrections import read_maps
from invisible_cities.reco.corrections import ASectorMap
from invisible_cities.reco.corrections import maps_coefficient_getter
import invisible_cities.database.load_db as DB

from . map_builder_functions import map_builder
from . checking_functions import AbortingMapCreation
Expand All @@ -37,10 +39,10 @@ def t_evol_table(MAPSDIR):

@mark.timeout(None)
@mark.dependency()
def test_scrip_runs_and_produces_correct_outputs(folder_test_dst ,
test_dst_file ,
output_maps_tmdir,
test_map_file ):
def test_script_runs_and_produces_correct_outputs(folder_test_dst ,
test_dst_file ,
output_maps_tmdir,
test_map_file ):
"""
Run map creation script and check if an ASectormap is the output.
"""
Expand Down Expand Up @@ -185,6 +187,74 @@ def test_correct_map_with_unsorted_dst(folder_test_dst ,
assert_dataframes_close(unsorted_maps.lt , sorted_maps.lt , rtol=1e-5)
assert_dataframes_close(unsorted_maps.ltu, sorted_maps.ltu, rtol=1e-5)

def test_detector_dependence(output_maps_tmdir,
folder_test_dst ,
test_dst_file ):
previous_map_f = os.path.join(output_maps_tmdir, 'test_out_map.h5')
previous_map = read_maps(previous_map_f)

config = configure('maps $ICARO/krcal/map_builder/config_LBphys.conf'.split())
histo_file_out = os.path.join(output_maps_tmdir, 'test_out_histo.h5')
demo_map_file_out= os.path.join(output_maps_tmdir, 'test_out_map_demo.h5')
default_n_bins = 15
run_number = 7517
map_params_new = copy.copy(config.as_namespace.map_params)
map_params_new['nmin'] = 100
map_params_new['detector'] = 'demopp'
map_params_new['nStimeprofile'] = 1200
config.update(dict(folder = folder_test_dst ,
file_in = test_dst_file ,
file_out_map = demo_map_file_out,
file_out_hists = histo_file_out ,
default_n_bins = default_n_bins ,
run_number = run_number ,
map_params = map_params_new ))

map_builder(config.as_namespace)
demo_map = read_maps(demo_map_file_out)
previous_driftv = previous_map.t_evol.dv
demo_driftv = demo_map .t_evol.dv
z_cathode_new = DB.DetectorGeo('new').ZMAX[0]
z_cathode_demo = DB.DetectorGeo('demopp').ZMAX[0]
ratio_cathodes = z_cathode_new/z_cathode_demo
assert_allclose ((previous_driftv/demo_driftv).values, ratio_cathodes)


def test_take_default_values_for_detector(output_maps_tmdir,
folder_test_dst ,
test_dst_file ):
previous_map_f = os.path.join(output_maps_tmdir, 'test_out_map.h5')
previous_map = read_maps(previous_map_f)

config = configure('maps $ICARO/krcal/map_builder/config_LBphys.conf'.split())
histo_file_out = os.path.join(output_maps_tmdir, 'test_out_histo.h5')
new_map_file_out = os.path.join(output_maps_tmdir, 'test_out_map_2.h5')
default_n_bins = 15
run_number = 7517
map_params_new = copy.copy(config.as_namespace.map_params)
map_params_new['nmin'] = 100
map_params_new['nStimeprofile'] = 1200
del config['map_params']['detector' ]
del config['map_params']['zrange_dv']
del config['map_params']['nbins_dv' ]
config.update(dict(folder = folder_test_dst ,
file_in = test_dst_file ,
file_out_map = new_map_file_out ,
file_out_hists = histo_file_out ,
default_n_bins = default_n_bins ,
run_number = run_number ,
map_params = map_params_new ))

map_builder(config.as_namespace)
new_map = read_maps(new_map_file_out)

assert_dataframes_close(previous_map.e0 , new_map.e0 , rtol=1e-5)
assert_dataframes_close(previous_map.e0u , new_map.e0u , rtol=1e-5)
assert_dataframes_close(previous_map.lt , new_map.lt , rtol=1e-5)
assert_dataframes_close(previous_map.ltu , new_map.ltu , rtol=1e-5)
assert_dataframes_close(previous_map.t_evol, new_map.t_evol, rtol=1e-5)


def test_exception_s1(folder_test_dst, test_dst_file, output_maps_tmdir):
"""
This test checks if exception raises when ns1=1 efficiency is out of range.
Expand Down