Skip to content

Commit 36ed978

Browse files
committed
Add mixer script and config file
1 parent 967edb2 commit 36ed978

File tree

2 files changed

+126
-0
lines changed

2 files changed

+126
-0
lines changed

bin/event_mixer

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env python
2+
3+
import os
4+
import argparse
5+
import numpy as np
6+
import pandas as pd
7+
8+
from invisible_cities.core.system_of_units import kg, dalton, year
9+
from invisible_cities.core.configure import read_config_file
10+
from invisible_cities.evm.mixer import Event_Mixer, _check_enough_nevents
11+
from invisible_cities.evm.mixer import get_mixer_nevents, get_reco_and_sim_nevents
12+
13+
# parse the config filename
14+
parser = argparse.ArgumentParser(description="Run the event mixer by parsing the configuration file")
15+
parser.add_argument("config", type=str, help="config file")
16+
args = parser.parse_args()
17+
config_filename = os.path.expandvars(args.config)
18+
19+
# 2nubb half-life taken from EXO-200 Phys. Rev. C 89, 015502
20+
T12_2nubb = 2.165e+21 * year
21+
22+
if __name__ == "__main__":
23+
24+
conf = read_config_file(config_filename)
25+
26+
detector_db = conf.get("detector_db")
27+
inpath = conf.get("inpath")
28+
outpath = conf.get("outpath")
29+
isotopes = conf.get("isotopes")
30+
xenon_mass = conf.get("xenon_mass")
31+
enrichment = conf.get("enrichment")
32+
exposure = conf.get("exposure")
33+
T12_0nubb = conf.get("T12_0nubb")
34+
verbosity = conf.get("verbosity", default=0)
35+
ic_efficiencies = conf.get("ic_efficiencies")
36+
nevents_per_file = conf.get("nevents_per_file")
37+
38+
# compute initial number of 136Xe isotopes
39+
assert (0. <= enrichment) & (enrichment <= 1.)
40+
N0 = enrichment*(xenon_mass/(136. * dalton))
41+
42+
# get event df with (g4volume, isotope, nevts)
43+
nevent_df = get_mixer_nevents(exposure, detector_db, isotopes)
44+
45+
# get number of decays of signal-like events
46+
if "0nubb" in isotopes:
47+
if not T12_0nubb:
48+
raise Exception("0nubb half-life (T12_0nubb) is not provided")
49+
nevts = N0 * (np.log(2)/T12_0nubb) * exposure
50+
nevent_df.loc[len(nevent_df)] = ("ACTIVE", "0nubb", nevts)
51+
52+
if "2nubb" in isotopes:
53+
nevts = N0 * (np.log(2)/T12_2nubb) * exposure
54+
nevent_df.loc[len(nevent_df)] = ("ACTIVE", "2nubb", nevts)
55+
56+
# load processing efficiencies
57+
eff_df = pd.read_csv(os.path.expandvars(ic_efficiencies))
58+
59+
# add reconstruction efficiency and poissonize
60+
nevent_df.nevts = nevent_df.nevts * (eff_df.nreco/eff_df.nsim)
61+
nevent_df.nevts = np.random.poisson(nevent_df.nevts)
62+
63+
# check input events are enough to run the mixer
64+
_check_enough_nevents(nevent_df, eff_df)
65+
66+
# run mixer
67+
mixer = Event_Mixer(inpath, outpath, nevent_df, nevents_per_file, verbosity)
68+
mixer.run()

invisible_cities/config/mixer.conf

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
"""
2+
------------
3+
Event mixer:
4+
------------
5+
6+
:verbosity: (optional) default 0
7+
verbosity level, either 0 (no verbosity) or 1
8+
9+
:detector_db:
10+
detector database name
11+
12+
:inpath:
13+
address of the isaura input files for background/signal events.
14+
- The files for each isotope must be (by convention) at different locations as a function of
15+
the isotope and g4volume names. See the example path below.
16+
- The files must be (by convention) named such that they contain a file-number placed after the
17+
first "_" in the file. Namely, the file name must start by "name_{file_number}"
18+
19+
:isotopes:
20+
isotopes to include in the mixer. Any of 0nubb, 2nubb, 214Bi, 208Tl, 40K, 60Co.
21+
22+
:ic_efficiencies:
23+
csv file with number of reconstructed (after IC processing) and simulated events for each component.
24+
Numbers can be computed from get_reco_and_sim_nevents function in evm/mixer.py, and saved with
25+
pandas.DataFrame.to_csv function
26+
27+
:xenon_mass:
28+
total xenon mass of the detector
29+
30+
:enrichment:
31+
136Xe enrichment factor (value between 0 and 1)
32+
33+
:exposure:
34+
total exposure of the production.
35+
36+
:T12_0nubb:
37+
0nubb half-life. If 0nubb is not included in :isotopes:, this parameter is not required
38+
39+
:nevents_per_file:
40+
number of events per output file.
41+
42+
:out_path:
43+
output filename structure as a function of a file number variable, "file_number".
44+
By convention "file_number" must be placed after a first "_". See example below.
45+
"""
46+
verbosity = 1
47+
detector_db = "next100"
48+
inpath = "$ICDIR/database/test_data/mixer/{g4volume}/{isotope}/*_test.h5"
49+
isotopes = ["0nubb", "2nubb"]
50+
ic_efficiencies = "/path/to/ic_efficiencies.csv"
51+
52+
xenon_mass = 100. * kg
53+
enrichment = 0.9
54+
exposure = 1. * year
55+
T12_0nubb = 1.e+27 * year
56+
57+
nevents_per_file = 10
58+
outpath = "/tmp/mixer_{file_number}_tag.h5"

0 commit comments

Comments
 (0)