|
| 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() |
0 commit comments