def IRENE(argv=sys.argv): """ IRENE DRIVER """ CFP = configure(argv) fpp = Irene(run_number=CFP['RUN_NUMBER']) files_in = glob(CFP['FILE_IN']) files_in.sort() fpp.set_input_files(files_in) fpp.set_pmap_store(CFP['FILE_OUT'], compression=CFP['COMPRESSION']) fpp.set_print(nprint=CFP['NPRINT']) fpp.set_BLR(n_baseline=CFP['NBASELINE'], thr_trigger=CFP['THR_TRIGGER']*units.adc) fpp.set_MAU(n_MAU=CFP['NMAU'], thr_MAU=CFP['THR_MAU']*units.adc) fpp.set_CSUM(thr_csum=CFP['THR_CSUM']*units.pes) fpp.set_S1(tmin=CFP['S1_TMIN']*units.mus, tmax=CFP['S1_TMAX']*units.mus, stride=CFP['S1_STRIDE'], lmin=CFP['S1_LMIN'], lmax=CFP['S1_LMAX']) fpp.set_S2(tmin=CFP['S2_TMIN']*units.mus, tmax=CFP['S2_TMAX']*units.mus, stride=CFP['S2_STRIDE'], lmin=CFP['S2_LMIN'], lmax=CFP['S2_LMAX']) fpp.set_SiPM(thr_zs=CFP['THR_ZS']*units.pes, thr_sipm_s2=CFP['THR_SIPM_S2']*units.pes) t0 = time() nevts = CFP['NEVENTS'] if not CFP['RUN_ALL'] else -1 nevt = fpp.run(nmax=nevts, store_pmaps=True) t1 = time() dt = t1 - t0 print("run {} evts in {} s, time/event = {}".format(nevt, dt, dt/nevt))
def ANASTASIA(argv=sys.argv): """ ANASTASIA driver """ CFP = configure(argv) if CFP["INFO"]: print(__doc__) # Increate thresholds by 1% for safety PMT_NOISE_CUT_RAW = CFP["PMT_NOISE_CUT_RAW"] * 1.01 PMT_NOISE_CUT_BLR = CFP["PMT_NOISE_CUT_BLR"] * 1.01 SIPM_ZS_METHOD = CFP["SIPM_ZS_METHOD"] SIPM_NOISE_CUT = CFP["SIPM_NOISE_CUT"] COMPRESSION = CFP["COMPRESSION"] with tb.open_file(CFP["FILE_IN"], "r+", filters=tbl.filters(CFP["COMPRESSION"])) as h5in: pmtblr = h5in.root.RD.pmtblr pmtcwf = h5in.root.RD.pmtcwf sipmrwf = h5in.root.RD.sipmrwf pmtdf = DB.DataPMT() sipmdf = DB.DataSiPM() NEVT, NPMT, PMTWL = pmtcwf.shape NEVT, NSIPM, SIPMWL = sipmrwf.shape print_configuration({"# PMT": NPMT, "PMT WL": PMTWL, "# SiPM": NSIPM, "SIPM WL": SIPMWL, "# events in DST": NEVT}) # Create instance of the noise sampler and compute noise thresholds sipms_noise_sampler_ = SiPMsNoiseSampler(SIPMWL) if SIPM_ZS_METHOD == "FRACTION": sipms_thresholds_ = sipms_noise_sampler_.ComputeThresholds( SIPM_NOISE_CUT, sipmdf['adc_to_pes']) else: sipms_thresholds_ = np.ones(NSIPM) * SIPM_NOISE_CUT if "/ZS" not in h5in: h5in.create_group(h5in.root, "ZS") if "/ZS/PMT" in h5in: h5in.remove_node("/ZS", "PMT") if "/ZS/BLR" in h5in: h5in.remove_node("/ZS", "BLR") if "/ZS/SiPM" in h5in: h5in.remove_node("/ZS", "SiPM") # Notice the Int16, not Float32! bad for compression pmt_zs_ = h5in.create_earray(h5in.root.ZS, "PMT", atom=tb.Int16Atom(), shape=(0, NPMT, PMTWL), expectedrows=NEVT, filters=tbl.filters(COMPRESSION)) blr_zs_ = h5in.create_earray(h5in.root.ZS, "BLR", atom=tb.Int16Atom(), shape=(0, NPMT, PMTWL), expectedrows=NEVT, filters=tbl.filters(COMPRESSION)) sipm_zs_ = h5in.create_earray(h5in.root.ZS, "SiPM", atom=tb.Int16Atom(), shape=(0, NSIPM, SIPMWL), expectedrows=NEVT, filters=tbl.filters(COMPRESSION)) adc_to_pes = abs(1.0/pmtdf["adc_to_pes"].reshape(NPMT, 1)) t0 = time() for i in define_event_loop(CFP, NEVT): sumpmt = np.sum(pmtcwf[i] * adc_to_pes, axis=0) selection = np.tile(sumpmt > PMT_NOISE_CUT_RAW, (NPMT, 1)) pmtzs = np.where(selection, pmtcwf[i], 0) blr = wfm.subtract_baseline(FE.CEILING - pmtblr[i]) sumpmt = np.sum(blr * adc_to_pes, axis=0) selection = np.tile(sumpmt > PMT_NOISE_CUT_BLR, (NPMT, 1)) blrzs = np.where(selection, blr, 0) pmt_zs_.append(pmtzs[np.newaxis]) blr_zs_.append(blrzs[np.newaxis]) sipmzs = sipmrwf[i] if "/MC" not in h5in: sipmzs = wfm.subtract_baseline(sipmzs, 200) sipmzs = wfm.noise_suppression(sipmzs, sipms_thresholds_) sipm_zs_.append(sipmzs[np.newaxis]) t1 = time() dt = t1-t0 print("ANASTASIA has run over {} events in {} seconds".format(i+1, dt)) print("Leaving ANASTASIA. Safe travels!")
def DOROTHEA(argv=sys.argv): """ DOROTHEA driver """ CFP = configure(argv) if CFP["INFO"]: print(__doc__) COMPRESSION = CFP["COMPRESSION"] # open the input file with tb.open_file(CFP["FILE_IN"], "r") as h5in: # access the PMT ZS data in file pmtzs_ = h5in.root.ZS.PMT blrzs_ = h5in.root.ZS.BLR sipmzs_ = h5in.root.ZS.SiPM NEVT, NPMT, PMTWL = pmtzs_.shape NEVT, NSIPM, SIPMWL = sipmzs_.shape print_configuration({"# PMT": NPMT, "PMT WL": PMTWL, "# SiPM": NSIPM, "SIPM WL": SIPMWL, "# events in DST": NEVT}) pmtdf = DB.DataPMT() sipmdf = DB.DataSiPM() pmt_to_pes = abs(1.0 / pmtdf.adc_to_pes.reshape(NPMT, 1)) sipm_to_pes = abs(1.0 / sipmdf.adc_to_pes.reshape(NSIPM, 1)) # open the output file with tb.open_file(CFP["FILE_OUT"], "w", filters=tbl.filters(COMPRESSION)) as h5out: # create groups and copy MC data to the new file if "/MC" in h5in: mcgroup = h5out.create_group(h5out.root, "MC") twfgroup = h5out.create_group(h5out.root, "TWF") h5in.root.MC.MCTracks.copy(newparent=mcgroup) h5in.root.MC.FEE.copy(newparent=mcgroup) h5in.root.TWF.PMT.copy(newparent=twfgroup) h5in.root.TWF.SiPM.copy(newparent=twfgroup) if "/Run" in h5in: rungroup = h5out.create_group(h5out.root, "Run") h5in.root.Run.runInfo.copy(newparent=rungroup) h5in.root.Run.events.copy(newparent=rungroup) pmapsgroup = h5out.create_group(h5out.root, "PMAPS") # create a table to store pmaps (rebined, linked, zs wfs) pmaps_ = h5out.create_table(pmapsgroup, "PMaps", PMAP, "Store for PMaps", tbl.filters(COMPRESSION)) pmaps_blr_ = h5out.create_table(pmapsgroup, "PMapsBLR", PMAP, "Store for PMaps made with BLR", tbl.filters(COMPRESSION)) # add index in event column pmaps_.cols.event.create_index() pmaps_blr_.cols.event.create_index() # LOOP t0 = time() for i in define_event_loop(CFP, NEVT): pmtwf = np.sum(pmtzs_[i] * pmt_to_pes, axis=0) blrwf = np.sum(blrzs_[i] * pmt_to_pes, axis=0) sipmwfs = sipmzs_[i] * sipm_to_pes pmap = build_pmap(pmtwf, sipmwfs) classify_peaks(pmap, **CFP) tbl.store_pmap(pmap, pmaps_, i) pmap_blr = build_pmap(blrwf, sipmwfs) classify_peaks(pmap_blr, **CFP) tbl.store_pmap(pmap_blr, pmaps_blr_, i) t1 = time() dt = t1 - t0 print("DOROTHEA has run over {} events in {} seconds".format(i+1, dt)) print("Leaving DOROTHEA. Safe travels!")
def DOROTHEA(argv=sys.argv): """ DOROTHEA driver """ CFP = configure(argv) if CFP["INFO"]: print(__doc__) COMPRESSION = CFP["COMPRESSION"] # open the input file with tb.open_file(CFP["FILE_IN"], "r") as h5in: # access the PMT ZS data in file pmtzs_ = h5in.root.ZS.PMT blrzs_ = h5in.root.ZS.BLR sipmzs_ = h5in.root.ZS.SiPM NEVT, NPMT, PMTWL = pmtzs_.shape NEVT, NSIPM, SIPMWL = sipmzs_.shape print_configuration({ "# PMT": NPMT, "PMT WL": PMTWL, "# SiPM": NSIPM, "SIPM WL": SIPMWL, "# events in DST": NEVT }) pmtdf = DB.DataPMT() sipmdf = DB.DataSiPM() pmt_to_pes = abs(1.0 / pmtdf.adc_to_pes.reshape(NPMT, 1)) sipm_to_pes = abs(1.0 / sipmdf.adc_to_pes.reshape(NSIPM, 1)) # open the output file with tb.open_file(CFP["FILE_OUT"], "w", filters=tbl.filters(COMPRESSION)) as h5out: # create groups and copy MC data to the new file if "/MC" in h5in: mcgroup = h5out.create_group(h5out.root, "MC") twfgroup = h5out.create_group(h5out.root, "TWF") h5in.root.MC.MCTracks.copy(newparent=mcgroup) h5in.root.MC.FEE.copy(newparent=mcgroup) h5in.root.TWF.PMT.copy(newparent=twfgroup) h5in.root.TWF.SiPM.copy(newparent=twfgroup) if "/Run" in h5in: rungroup = h5out.create_group(h5out.root, "Run") h5in.root.Run.runInfo.copy(newparent=rungroup) h5in.root.Run.events.copy(newparent=rungroup) pmapsgroup = h5out.create_group(h5out.root, "PMAPS") # create a table to store pmaps (rebined, linked, zs wfs) pmaps_ = h5out.create_table(pmapsgroup, "PMaps", PMAP, "Store for PMaps", tbl.filters(COMPRESSION)) pmaps_blr_ = h5out.create_table(pmapsgroup, "PMapsBLR", PMAP, "Store for PMaps made with BLR", tbl.filters(COMPRESSION)) # add index in event column pmaps_.cols.event.create_index() pmaps_blr_.cols.event.create_index() # LOOP t0 = time() for i in define_event_loop(CFP, NEVT): pmtwf = np.sum(pmtzs_[i] * pmt_to_pes, axis=0) blrwf = np.sum(blrzs_[i] * pmt_to_pes, axis=0) sipmwfs = sipmzs_[i] * sipm_to_pes pmap = build_pmap(pmtwf, sipmwfs) classify_peaks(pmap, **CFP) tbl.store_pmap(pmap, pmaps_, i) pmap_blr = build_pmap(blrwf, sipmwfs) classify_peaks(pmap_blr, **CFP) tbl.store_pmap(pmap_blr, pmaps_blr_, i) t1 = time() dt = t1 - t0 print("DOROTHEA has run over {} events in {} seconds".format( i + 1, dt)) print("Leaving DOROTHEA. Safe travels!")
def ISIDORA(argv=sys.argv): CFP = configure(argv) if CFP["INFO"]: print(""" ISIDORA: 1. Reads an Nh5 file produced by DIOMIRA, which stores the raw waveforms (RWF) for the PMTs and SiPMs waveforms, as well as data on geometry, sensors and MC. The RDWF of the PMTs show negative swing due to the HPF of the EP FEE electronics 2. Performs DBLR on the PMT RWF and produces corrected waveforms (CWF). 3. Adds the CWF and ancilliary info to the DST 4. Computes the energy of the PMTs per each event and writes to DST """) N_BASELINE = CFP["N_BASELINE"] THR_TRIGGER = CFP["THR_TRIGGER"] ACUM_DISCHARGE_LENGTH = CFP["ACUM_DISCHARGE_LENGTH"] ACUM_TAU = CFP["ACUM_TAU"] ACUM_COMPRESS = CFP["ACUM_COMPRESS"] COMPRESSION = CFP["COMPRESSION"] # open the input file in mode append with tb.open_file(CFP["FILE_IN"], "a", filters=tbl.filters(COMPRESSION)) as h5in: # access the PMT raw data in file pmtrd_ = h5in.root.RD.pmtrwf # PMT raw data must exist NEVENTS_DST, NPMT, PMTWL = pmtrd_.shape print_configuration({"# PMT": NPMT, "PMT WL": PMTWL, "# events in DST": NEVENTS_DST}) # create an extensible array to store the CWF waveforms # if it exists remove and create again if "/RD/pmtcwf" in h5in: h5in.remove_node("/RD", "pmtcwf") pmtcwf = h5in.create_earray(h5in.root.RD, "pmtcwf", atom=tb.Int16Atom(), shape=(0, NPMT, PMTWL), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) # if "/RD/pmtacum" in h5in: # h5in.remove_node("/RD", "pmtacum") # # pmtacum = h5in.create_earray(h5in.root.RD, "pmtacum", # atom=tb.Int16Atom(), # shape=(0, NPMT, PMTWL), # expectedrows=NEVENTS_DST) if "/Deconvolution" not in h5in: h5in.create_group(h5in.root, "Deconvolution") if "/Deconvolution/Parameters" in h5in: h5in.remove_node("/Deconvolution", "Parameters") if "/Deconvolution/BL" in h5in: h5in.remove_node("/Deconvolution", "BL") deconv_table = h5in.create_table(h5in.root.Deconvolution, "Parameters", DECONV_PARAM, "Deconvolution parameters", tbl.filters("NOCOMPR")) tbl.store_deconv_table(deconv_table, CFP) bl_array = h5in.create_earray(h5in.root.Deconvolution, "BL", atom=tb.Int16Atom(), shape=(0, NPMT, 3), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) # LOOP t0 = time() for i in define_event_loop(CFP, NEVENTS_DST): data = DBLR(pmtrd_[i], n_baseline=N_BASELINE, thr_trigger=THR_TRIGGER, discharge_length=ACUM_DISCHARGE_LENGTH, acum_tau=ACUM_TAU, acum_compress=ACUM_COMPRESS) signal_r, bl_data = data[0], data[2:] # append to pmtcwf pmtcwf.append(signal_r.reshape(1, NPMT, PMTWL)) bl_array.append(np.array(bl_data).T[np.newaxis]) # append to pmtacum # pmtacum.append(acum.reshape(1, NPMT, PMTWL)) t1 = time() dt = t1 - t0 pmtcwf.flush() bl_array.flush() # pmtacum.flush() print("ISIDORA has run over {} events in {} seconds".format(i+1, dt)) print("Leaving ISIDORA. Safe travels!")
def DIOMIRA(argv=sys.argv): """ Diomira driver """ CFP = configure(argv) if CFP["INFO"]: print(""" DIOMIRA: 1. Reads a MCRD file produced by art/centella, which stores MCRD waveforms for PMTs (bins of 1 ns) and SiPMs (bins of 1 mus) 2. Simulates the response of the energy plane and outputs both RWF and TWF 3. Simulates the response of the tracking plane in the SiPMs and outputs SiPM RWF 4. Add a table describing the FEE parameters used for simulation 5. Copies the tables on geometry, detector data and MC """) # open the input file with tables.open_file(CFP["FILE_IN"], "r") as h5in: # access the PMT raw data in file pmtrd_ = h5in.root.pmtrd sipmrd_ = h5in.root.sipmrd NEVENTS_DST, NPMT, PMTWL = pmtrd_.shape PMTWL_FEE = int(PMTWL / FE.t_sample) NEVENTS_DST, NSIPM, SIPMWL = sipmrd_.shape print_configuration({ "# PMT": NPMT, "PMT WL": PMTWL, "PMT WL (FEE)": PMTWL_FEE, "# SiPM": NSIPM, "SIPM WL": SIPMWL, "# events in DST": NEVENTS_DST }) # access the geometry and the sensors metadata info mctrk_t = h5in.root.MC.MCTracks sipmdf = DB.DataSiPM() # Create instance of the noise sampler noise_sampler_ = SiPMsNoiseSampler(SIPMWL, True) sipms_thresholds_ = CFP["NOISE_CUT"] * np.array(sipmdf["adc_to_pes"]) COMPRESSION = CFP["COMPRESSION"] # open the output file with tables.open_file(CFP["FILE_OUT"], "w", filters=tbl.filters(COMPRESSION)) as h5out: # create a group to store sensors IDs sgroup = h5out.create_group(h5out.root, "Sensors") # copy DataSiPM & DataPMT table h5in.root.Sensors.DataSiPM.copy(newparent=sgroup) h5in.root.Sensors.DataPMT.copy(newparent=sgroup) # create a group to store MC data mcgroup = h5out.create_group(h5out.root, "MC") # copy the mctrk table mctrk_t.copy(newparent=mcgroup) # create a table to store Energy plane FEE, hang it from MC group fee_table = h5out.create_table(mcgroup, "FEE", FEE, "EP-FEE parameters", tbl.filters("NOCOMPR")) # create a group to store True waveform data twfgroup = h5out.create_group(h5out.root, "TWF") # create a table to store true waveform (zs, rebinned) pmt_twf_table = h5out.create_table(twfgroup, "PMT", SENSOR_WF, "Store for PMTs TWF", tbl.filters(COMPRESSION)) sipm_twf_table = h5out.create_table(twfgroup, "SiPM", SENSOR_WF, "Store for SiPM TWF", tbl.filters(COMPRESSION)) # and index in event column pmt_twf_table.cols.event.create_index() sipm_twf_table.cols.event.create_index() # fill FEE table tbl.store_FEE_table(fee_table) # create a group to store RawData h5out.create_group(h5out.root, "RD") # create an extensible array to store the RWF waveforms pmtrwf = h5out.create_earray(h5out.root.RD, "pmtrwf", atom=tables.Int16Atom(), shape=(0, NPMT, PMTWL_FEE), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) pmtblr = h5out.create_earray(h5out.root.RD, "pmtblr", atom=tables.Int16Atom(), shape=(0, NPMT, PMTWL_FEE), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) sipmrwf = h5out.create_earray(h5out.root.RD, "sipmrwf", atom=tables.Int16Atom(), shape=(0, NSIPM, SIPMWL), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) # LOOP t0 = time() for i in define_event_loop(CFP, NEVENTS_DST): # supress zeros in MCRD and rebin the ZS function in 1 mus bins rebin = int(units.mus / units.ns) trueSiPM = wfm.zero_suppression(sipmrd_[i], 0.) # dict_map applies a function to the dictionary values truePMT = cf.dict_map( lambda df: wfm.rebin_df(df, rebin), wfm.zero_suppression(pmtrd_[i], 0., to_mus=int(units.ns / units.ms))) # store in table tbl.store_wf_table(i, pmt_twf_table, truePMT) tbl.store_wf_table(i, sipm_twf_table, trueSiPM) # simulate PMT response and return an array with RWF;BLR # convert to float, append to EVector dataPMT, blrPMT = simulate_pmt_response(i, pmtrd_) pmtrwf.append(dataPMT.astype(int).reshape(1, NPMT, PMTWL_FEE)) pmtblr.append(blrPMT.astype(int).reshape(1, NPMT, PMTWL_FEE)) # simulate SiPM response and return an array with RWF # convert to float, zero suppress and dump to table dataSiPM = simulate_sipm_response(i, sipmrd_, noise_sampler_) dataSiPM = wfm.to_adc(dataSiPM, sipmdf) dataSiPM = wfm.noise_suppression(dataSiPM, sipms_thresholds_) sipmrwf.append(dataSiPM.astype(int).reshape(1, NSIPM, SIPMWL)) pmtrwf.flush() sipmrwf.flush() pmtblr.flush() t1 = time() dt = t1 - t0 print("DIOMIRA has run over {} events in {} seconds".format( i + 1, dt)) print("Leaving Diomira. Safe travels!")
def ISIDORA(argv=sys.argv): CFP = configure(argv) if CFP["INFO"]: print(""" ISIDORA: 1. Reads an Nh5 file produced by DIOMIRA, which stores the raw waveforms (RWF) for the PMTs and SiPMs waveforms, as well as data on geometry, sensors and MC. The RDWF of the PMTs show negative swing due to the HPF of the EP FEE electronics 2. Performs DBLR on the PMT RWF and produces corrected waveforms (CWF). 3. Adds the CWF and ancilliary info to the DST 4. Computes the energy of the PMTs per each event and writes to DST """) N_BASELINE = CFP["N_BASELINE"] THR_TRIGGER = CFP["THR_TRIGGER"] ACUM_DISCHARGE_LENGTH = CFP["ACUM_DISCHARGE_LENGTH"] ACUM_TAU = CFP["ACUM_TAU"] ACUM_COMPRESS = CFP["ACUM_COMPRESS"] # open the input file in mode append with tb.open_file(CFP["FILE_IN"], "a") as h5in: # access the PMT raw data in file pmtrd_ = h5in.root.RD.pmtrwf # PMT raw data must exist NEVENTS_DST, NPMT, PMTWL = pmtrd_.shape logger.info("nof PMTs = {} WF side = {} ".format(NPMT, PMTWL)) logger.info("nof events in input DST = {} ".format(NEVENTS_DST)) # create an extensible array to store the CWF waveforms # if it exists remove and create again if "/RD/pmtcwf" in h5in: h5in.remove_node("/RD", "pmtcwf") pmtcwf = h5in.create_earray(h5in.root.RD, "pmtcwf", atom=tb.Int16Atom(), shape=(0, NPMT, PMTWL), expectedrows=NEVENTS_DST) # if "/RD/pmtacum" in h5in: # h5in.remove_node("/RD", "pmtacum") # # pmtacum = h5in.create_earray(h5in.root.RD, "pmtacum", # atom=tb.Int16Atom(), # shape=(0, NPMT, PMTWL), # expectedrows=NEVENTS_DST) if "/Deconvolution" not in h5in: h5in.create_group(h5in.root, "Deconvolution") if "/Deconvolution/Parameters" in h5in: h5in.remove_node("/Deconvolution", "Parameters") deconv_table = h5in.create_table(h5in.root.Deconvolution, "Parameters", DECONV_PARAM, "Deconvolution parameters", tbl.filters("NOCOMPR")) tbl.store_deconv_table(deconv_table, CFP) # LOOP t0 = time() for i in define_event_loop(CFP, NEVENTS_DST): signal_r, acum, baseline, baseline_end, \ noise_rms = DBLR(pmtrd_[i], n_baseline=N_BASELINE, thr_trigger=THR_TRIGGER, acum_discharge_length=ACUM_DISCHARGE_LENGTH, acum_tau=ACUM_TAU, acum_compress=ACUM_COMPRESS) # append to pmtcwf pmtcwf.append(signal_r.reshape(1, NPMT, PMTWL)) # append to pmtacum #pmtacum.append(acum.reshape(1, NPMT, PMTWL)) t1 = time() dt = t1 - t0 pmtcwf.flush() #pmtacum.flush() print("ISIDORA has run over {} events in {} seconds".format(i + 1, dt)) print("Leaving ISIDORA. Safe travels!")
def DIOMIRA(argv=sys.argv): """ Diomira driver """ CFP = configure(argv) if CFP["INFO"]: print(""" DIOMIRA: 1. Reads a MCRD file produced by art/centella, which stores MCRD waveforms for PMTs (bins of 1 ns) and SiPMs (bins of 1 mus) 2. Simulates the response of the energy plane and outputs both RWF and TWF 3. Simulates the response of the tracking plane in the SiPMs and outputs SiPM RWF 4. Add a table describing the FEE parameters used for simulation 5. Copies the tables on geometry, detector data and MC """) # open the input file with tables.open_file(CFP["FILE_IN"], "r") as h5in: # access the PMT raw data in file pmtrd_ = h5in.root.pmtrd sipmrd_ = h5in.root.sipmrd NEVENTS_DST, NPMT, PMTWL = pmtrd_.shape PMTWL_FEE = int(PMTWL/FE.t_sample) NEVENTS_DST, NSIPM, SIPMWL = sipmrd_.shape print_configuration({"# PMT": NPMT, "PMT WL": PMTWL, "PMT WL (FEE)": PMTWL_FEE, "# SiPM": NSIPM, "SIPM WL": SIPMWL, "# events in DST": NEVENTS_DST}) # access the geometry and the sensors metadata info mctrk_t = h5in.root.MC.MCTracks sipmdf = DB.DataSiPM() # Create instance of the noise sampler noise_sampler_ = SiPMsNoiseSampler(SIPMWL, True) sipms_thresholds_ = CFP["NOISE_CUT"] * np.array(sipmdf["adc_to_pes"]) COMPRESSION = CFP["COMPRESSION"] # open the output file with tables.open_file(CFP["FILE_OUT"], "w", filters=tbl.filters(COMPRESSION)) as h5out: # create a group to store sensors IDs sgroup = h5out.create_group(h5out.root, "Sensors") # copy DataSiPM & DataPMT table h5in.root.Sensors.DataSiPM.copy(newparent=sgroup) h5in.root.Sensors.DataPMT.copy(newparent=sgroup) # create a group to store MC data mcgroup = h5out.create_group(h5out.root, "MC") # copy the mctrk table mctrk_t.copy(newparent=mcgroup) # create a table to store Energy plane FEE, hang it from MC group fee_table = h5out.create_table(mcgroup, "FEE", FEE, "EP-FEE parameters", tbl.filters("NOCOMPR")) # create a group to store True waveform data twfgroup = h5out.create_group(h5out.root, "TWF") # create a table to store true waveform (zs, rebinned) pmt_twf_table = h5out.create_table(twfgroup, "PMT", SENSOR_WF, "Store for PMTs TWF", tbl.filters(COMPRESSION)) sipm_twf_table = h5out.create_table(twfgroup, "SiPM", SENSOR_WF, "Store for SiPM TWF", tbl.filters(COMPRESSION)) # and index in event column pmt_twf_table.cols.event.create_index() sipm_twf_table.cols.event.create_index() # fill FEE table tbl.store_FEE_table(fee_table) # create a group to store RawData h5out.create_group(h5out.root, "RD") # create an extensible array to store the RWF waveforms pmtrwf = h5out.create_earray(h5out.root.RD, "pmtrwf", atom=tables.Int16Atom(), shape=(0, NPMT, PMTWL_FEE), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) pmtblr = h5out.create_earray(h5out.root.RD, "pmtblr", atom=tables.Int16Atom(), shape=(0, NPMT, PMTWL_FEE), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) sipmrwf = h5out.create_earray(h5out.root.RD, "sipmrwf", atom=tables.Int16Atom(), shape=(0, NSIPM, SIPMWL), expectedrows=NEVENTS_DST, filters=tbl.filters(COMPRESSION)) # LOOP t0 = time() for i in define_event_loop(CFP, NEVENTS_DST): # supress zeros in MCRD and rebin the ZS function in 1 mus bins rebin = int(units.mus/units.ns) trueSiPM = wfm.zero_suppression(sipmrd_[i], 0.) # dict_map applies a function to the dictionary values truePMT = cf.dict_map(lambda df: wfm.rebin_df(df, rebin), wfm.zero_suppression(pmtrd_[i], 0., to_mus=int(units.ns/units.ms))) # store in table tbl.store_wf_table(i, pmt_twf_table, truePMT) tbl.store_wf_table(i, sipm_twf_table, trueSiPM) # simulate PMT response and return an array with RWF;BLR # convert to float, append to EVector dataPMT, blrPMT = simulate_pmt_response(i, pmtrd_) pmtrwf.append(dataPMT.astype(int).reshape(1, NPMT, PMTWL_FEE)) pmtblr.append(blrPMT.astype(int).reshape(1, NPMT, PMTWL_FEE)) # simulate SiPM response and return an array with RWF # convert to float, zero suppress and dump to table dataSiPM = simulate_sipm_response(i, sipmrd_, noise_sampler_) dataSiPM = wfm.to_adc(dataSiPM, sipmdf) dataSiPM = wfm.noise_suppression(dataSiPM, sipms_thresholds_) sipmrwf.append(dataSiPM.astype(int).reshape(1, NSIPM, SIPMWL)) pmtrwf.flush() sipmrwf.flush() pmtblr.flush() t1 = time() dt = t1 - t0 print("DIOMIRA has run over {} events in {} seconds".format(i+1, dt)) print("Leaving Diomira. Safe travels!")
def ANASTASIA(argv=sys.argv): """ ANASTASIA driver """ CFP = configure(argv) if CFP["INFO"]: print(__doc__) # Increate thresholds by 1% for safety PMT_NOISE_CUT_RAW = CFP["PMT_NOISE_CUT_RAW"] * 1.01 PMT_NOISE_CUT_BLR = CFP["PMT_NOISE_CUT_BLR"] * 1.01 SIPM_ZS_METHOD = CFP["SIPM_ZS_METHOD"] SIPM_NOISE_CUT = CFP["SIPM_NOISE_CUT"] with tb.open_file(CFP["FILE_IN"], "r+") as h5in: pmtblr = h5in.root.RD.pmtblr pmtcwf = h5in.root.RD.pmtcwf sipmrwf = h5in.root.RD.sipmrwf sipmdf = DB.DataSiPM() NEVT, NPMT, PMTWL = pmtcwf.shape NEVT, NSIPM, SIPMWL = sipmrwf.shape logger.info("# events in DST = {}".format(NEVT)) logger.info("#PMTs = {} #SiPMs = {}".format(NPMT, NSIPM)) logger.info("PMT WFL = {} SiPM WFL = {}".format(PMTWL, SIPMWL)) # Create instance of the noise sampler and compute noise thresholds sipms_noise_sampler_ = SiPMsNoiseSampler(SIPMWL) if SIPM_ZS_METHOD == "FRACTION": sipms_thresholds_ = sipms_noise_sampler_.ComputeThresholds( SIPM_NOISE_CUT, sipmdf['adc_to_pes']) else: sipms_thresholds_ = np.ones(NSIPM) * SIPM_NOISE_CUT if "/ZS" not in h5in: h5in.create_group(h5in.root, "ZS") if "/ZS/PMT" in h5in: h5in.remove_node("/ZS", "PMT") if "/ZS/BLR" in h5in: h5in.remove_node("/ZS", "BLR") if "/ZS/SiPM" in h5in: h5in.remove_node("/ZS", "SiPM") # Notice the Int16, not Float32! bad for compression pmt_zs_ = h5in.create_earray(h5in.root.ZS, "PMT", atom=tb.Int16Atom(), shape=(0, NPMT, PMTWL), expectedrows=NEVT) blr_zs_ = h5in.create_earray(h5in.root.ZS, "BLR", atom=tb.Int16Atom(), shape=(0, NPMT, PMTWL), expectedrows=NEVT) sipm_zs_ = h5in.create_earray(h5in.root.ZS, "SiPM", atom=tb.Int16Atom(), shape=(0, NSIPM, SIPMWL), expectedrows=NEVT) t0 = time() for i in define_event_loop(CFP, NEVT): pmtzs = wfm.noise_suppression(pmtcwf[i], PMT_NOISE_CUT_RAW) blrzs = wfm.subtract_baseline(FE.CEILING - pmtblr[i]) blrzs = wfm.noise_suppression(blrzs, PMT_NOISE_CUT_BLR) pmt_zs_.append(pmtzs[np.newaxis]) blr_zs_.append(blrzs[np.newaxis]) sipmzs = sipmrwf[i] if "/MC" not in h5in: sipmzs = wfm.subtract_baseline(sipmzs, 200) sipmzs = wfm.noise_suppression(sipmzs, sipms_thresholds_) sipm_zs_.append(sipmzs[np.newaxis]) t1 = time() dt = t1 - t0 print("ANASTASIA has run over {} events in {} seconds".format( i + 1, dt)) print("Leaving ANASTASIA. Safe travels!")
def DOROTHEA(argv=sys.argv): """ DOROTHEA driver """ CFP = configure(argv) if CFP["INFO"]: print(__doc__) FILE_IN = CFP["FILE_IN"] FILE_OUT = CFP["FILE_OUT"] COMPRESSION = CFP["COMPRESSION"] NEVENTS = CFP["NEVENTS"] logger.info("Debug level = {}".format(CFP["VERBOSITY"])) logger.info("Input file = {}".format(FILE_IN)) logger.info("Output file = {}".format(FILE_OUT)) logger.info("# events requested = {}".format(NEVENTS)) logger.info("Compression library/level = {}".format(COMPRESSION)) # open the input file with tb.open_file(FILE_IN, "r") as h5in: # access the PMT ZS data in file pmtzs_ = h5in.root.ZS.PMT blrzs_ = h5in.root.ZS.BLR sipmzs_ = h5in.root.ZS.SiPM NEVT, NPMT, PMTWL = pmtzs_.shape NEVT, NSIPM, SIPMWL = sipmzs_.shape logger.info("# events in DST: {}".format(NEVT)) logger.info("# PMTs = {}, # SiPMs = {} ".format(NPMT, NSIPM)) logger.info("PMT WFL = {}, SiPM WFL = {}".format(PMTWL, SIPMWL)) pmtdf = DB.DataPMT() sipmdf = DB.DataSiPM() pmt_to_pes = abs(1.0 / pmtdf.adc_to_pes.reshape(NPMT, 1)) sipm_to_pes = abs(1.0 / sipmdf.adc_to_pes.reshape(NSIPM, 1)) # open the output file with tb.open_file(FILE_OUT, "w", filters=tbl.filters(COMPRESSION)) as h5out: # create groups and copy MC data to the new file if "/MC" in h5in: mcgroup = h5out.create_group(h5out.root, "MC") twfgroup = h5out.create_group(h5out.root, "TWF") h5in.root.MC.MCTracks.copy(newparent=mcgroup) h5in.root.MC.FEE.copy(newparent=mcgroup) h5in.root.TWF.PMT.copy(newparent=twfgroup) h5in.root.TWF.SiPM.copy(newparent=twfgroup) pmapsgroup = h5out.create_group(h5out.root, "PMAPS") # create a table to store pmaps (rebined, linked, zs wfs) pmaps_ = h5out.create_table(pmapsgroup, "PMaps", PMAP, "Store for PMaps", tbl.filters(COMPRESSION)) pmaps_blr_ = h5out.create_table(pmapsgroup, "PMapsBLR", PMAP, "Store for PMaps made with BLR", tbl.filters(COMPRESSION)) # add index in event column pmaps_.cols.event.create_index() pmaps_blr_.cols.event.create_index() # LOOP t0 = time() for i in define_event_loop(CFP, NEVT): pmtwf = np.sum(pmtzs_[i] * pmt_to_pes, axis=0) blrwf = np.sum(blrzs_[i] * pmt_to_pes, axis=0) sipmwfs = sipmzs_[i] * sipm_to_pes pmap = build_pmap(pmtwf, sipmwfs) classify_peaks(pmap, **CFP) tbl.store_pmap(pmap, pmaps_, i) pmap_blr = build_pmap(blrwf, sipmwfs) classify_peaks(pmap_blr, **CFP) tbl.store_pmap(pmap_blr, pmaps_blr_, i) t1 = time() dt = t1 - t0 print("DOROTHEA has run over {} events in {} seconds".format( i + 1, dt)) print("Leaving DOROTHEA. Safe travels!")