From 15fa3c5a75b4fffe1976a449d6d18cae47dc78a4 Mon Sep 17 00:00:00 2001 From: Tamas Vami Date: Tue, 13 Aug 2024 13:59:20 -0700 Subject: [PATCH] Introduce EcalPreselectionSkimmer --- .../Recon/Skims/EcalPreselectionSkimmer.h | 66 +++++++++++++++++++ Recon/python/ecalPreselectionSkimmer.py | 63 ++++++++++++++++++ .../Recon/Skims/EcalPreselectionSkimmer.cxx | 62 +++++++++++++++++ Recon/test/ecal_preselection_skim.py | 17 +++++ 4 files changed, 208 insertions(+) create mode 100644 Recon/include/Recon/Skims/EcalPreselectionSkimmer.h create mode 100644 Recon/python/ecalPreselectionSkimmer.py create mode 100644 Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx create mode 100644 Recon/test/ecal_preselection_skim.py diff --git a/Recon/include/Recon/Skims/EcalPreselectionSkimmer.h b/Recon/include/Recon/Skims/EcalPreselectionSkimmer.h new file mode 100644 index 000000000..31e5d55d0 --- /dev/null +++ b/Recon/include/Recon/Skims/EcalPreselectionSkimmer.h @@ -0,0 +1,66 @@ +/** + * @file EcalPreselectionSkimmer.h + * @brief Processor used to pre-select events for the ECAL studies + * @author Tamas Almos Vami (UCSB) + */ + +#ifndef RECON_SKIMS_EcalPreselectionSkimmer_H_ +#define RECON_SKIMS_EcalPreselectionSkimmer_H_ + +//----------// +// LDMX // +//----------// +#include "Ecal/Event/EcalVetoResult.h" +#include "Framework/EventProcessor.h" +#include "Tools/AnalysisUtils.h" + +namespace recon { + +class EcalPreselectionSkimmer : public framework::Producer { + public: + // @param parameters Set of parameters used to configure this processor. + virtual void configure(framework::config::Parameters &); + + /** Constructor */ + EcalPreselectionSkimmer(const std::string &name, framework::Process &process); + + /** Destructor */ + ~EcalPreselectionSkimmer() = default; + + /** + * Run the processor and select events that pass pre-selection in ECAL + * + * @param event The event to process. + */ + void produce(framework::Event &event); + + private: + /// Collection Name for veto object + std::string ecal_veto_name_; + /// Pass Name for veto object + std::string ecal_veto_pass_; + /// Max value for summed det + double summed_det_max_; + /// Max value for summed tigh iso + double summed_tight_iso_max_; + /// Max value for ecal back energy + double ecal_back_energy_max_; + /// Max value for num readout hits + int n_readout_hits_max_; + /// Max value for shower rms + int shower_rms_max_; + /// Max value for shower rms in Y + int shower_y_std_max_; + /// Max value for shower rms in X + int shower_x_std_max_; + /// Max value for maximal cell deposition + double max_cell_dep_max_; + /// Max value for std layer hits + int std_layer_hit_max_; + /// Max value for num straight tracks + int n_straight_tracks_max_; + +}; // EcalPreselectionSkimmer +} // namespace recon + +#endif // RECON_SKIMS_EcalPreselectionSkimmer_H_ diff --git a/Recon/python/ecalPreselectionSkimmer.py b/Recon/python/ecalPreselectionSkimmer.py new file mode 100644 index 000000000..0c1806443 --- /dev/null +++ b/Recon/python/ecalPreselectionSkimmer.py @@ -0,0 +1,63 @@ +"""Configuration for PreselectionProcessor + +Sets all the default parameters that high so it leads to no preselection. + +Attributes: +------------- + +ecal_veto_name: string + Collection Name for veto object +ecal_veto_pass: string + Pass Name for veto object +summed_det_max: double + Max value for summed det +summed_tight_iso_max: double + Max value for summed tigh iso +ecal_back_energy_max: double + Max value for ecal back energy + n_readout_hits_max: int + Max value for num readout hits + shower_rms_max: int + Max value for shower rms + shower_y_std_max: int + Max value for shower rms in Y +shower_x_std_max: int + Max value for shower rms in X +max_cell_dep_max: double + Max value for maximal cell deposition +std_layer_hit_max: int + Max value for std layer hits +n_straight_tracks_max: int + Max value for num straight tracks + + +Examples +-------- + from LDMX.Recon.ecalPreselectionSkimmer import ecalPreselectionSkimmer + p.sequence.append( ecalPreselectionSkimmer ) +""" + +from LDMX.Framework import ldmxcfg + +class EcalPreselectionSkimmer(ldmxcfg.Producer) : + """Configuration for an ECAL-based pre-selection skimmer""" + + def __init__(self, name) : + super().__init__(name,'recon::EcalPreselectionSkimmer','Recon') + + self.ecal_veto_name = "EcalVeto" + self.ecal_veto_pass = "" + self.summed_det_max = 9999. + self.summed_tight_iso_max = 9999. + self.ecal_back_energy_max = 9999. + self.n_readout_hits_max = 9999 + self.shower_rms_max = 9999 + self.shower_y_std_max = 9999 + self.shower_x_std_max = 9999 + self.max_cell_dep_max = 9999. + self.std_layer_hit_max = 9999 + self.n_straight_tracks_max = 9999 + + +ecalPreselectionSkimmer = EcalPreselectionSkimmer("ecalPreselectionSkimmer") + diff --git a/Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx b/Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx new file mode 100644 index 000000000..9250d3d81 --- /dev/null +++ b/Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx @@ -0,0 +1,62 @@ +/** + * @file EcalPreselectionSkimmer.cxx + * @brief Processor used to pre-select events for the ECAL studies + * @author Tamas Almos Vami (UCSB) + */ + +#include "Recon/Skims/EcalPreselectionSkimmer.h" + +namespace recon { + +EcalPreselectionSkimmer::EcalPreselectionSkimmer(const std::string &name, + framework::Process &process) + : framework::Producer(name, process) {} + +void EcalPreselectionSkimmer::configure(framework::config::Parameters &ps) { + ecal_veto_name_ = ps.getParameter("ecal_veto_name"); + ecal_veto_pass_ = ps.getParameter("ecal_veto_pass"); + summed_det_max_ = ps.getParameter("summed_det_max"); // MeV + summed_tight_iso_max_ = + ps.getParameter("summed_tight_iso_max"); // MeV + ecal_back_energy_max_ = + ps.getParameter("ecal_back_energy_max"); // MeV + n_readout_hits_max_ = ps.getParameter("n_readout_hits_max"); + shower_rms_max_ = ps.getParameter("shower_rms_max"); + shower_y_std_max_ = ps.getParameter("shower_y_std_max"); + shower_x_std_max_ = ps.getParameter("shower_x_std_max"); + max_cell_dep_max_ = ps.getParameter("max_cell_dep_max"); // MeV + std_layer_hit_max_ = ps.getParameter("std_layer_hit_max"); + n_straight_tracks_max_ = ps.getParameter("n_straight_tracks_max"); + + return; +} + +void EcalPreselectionSkimmer::produce(framework::Event &event) { + bool passedPreselection{false}; + auto ecalVeto{ + event.getObject(ecal_veto_name_, ecal_veto_pass_)}; + + // Boolean to check if we pass preselection + passedPreselection = (ecalVeto.getSummedDet() < summed_det_max_) && + (ecalVeto.getSummedTightIso() < summed_tight_iso_max_) && + (ecalVeto.getEcalBackEnergy() < ecal_back_energy_max_) && + (ecalVeto.getNReadoutHits() < n_readout_hits_max_) && + (ecalVeto.getShowerRMS() < shower_rms_max_) && + (ecalVeto.getYStd() < shower_y_std_max_) && + (ecalVeto.getXStd() < shower_x_std_max_) && + (ecalVeto.getMaxCellDep() < max_cell_dep_max_) && + (ecalVeto.getStdLayerHit() < std_layer_hit_max_) && + (ecalVeto.getNStraightTracks() < n_straight_tracks_max_); + + // Tell the skimmer to keep or drop the event based on whether preselection + // passed + if (passedPreselection) { + ldmx_log(debug) << "This event passed preselection!"; + setStorageHint(framework::hint_shouldKeep); + } else { + setStorageHint(framework::hint_shouldDrop); + } +} +} // namespace recon + +DECLARE_PRODUCER_NS(recon, EcalPreselectionSkimmer); diff --git a/Recon/test/ecal_preselection_skim.py b/Recon/test/ecal_preselection_skim.py new file mode 100644 index 000000000..e204488ce --- /dev/null +++ b/Recon/test/ecal_preselection_skim.py @@ -0,0 +1,17 @@ +import os import sys + + thisPassName = "presel" inputName = sys.argv[1] + + from LDMX.Framework import ldmxcfg p = ldmxcfg.Process(thisPassName) + + p.termLogLevel = 0 + + p.inputFiles =[inputName] p.histogramFile = "histosPreskimmed.root" p.outputFiles =["eventsPreskimmed.root"] + + from LDMX.Recon.ecalPreselectionSkimmer import ecalPreselectionSkimmer ecalPreselectionSkimmer.summed_tight_iso_max = 1100. ecalPreselectionSkimmer.n_readout_hits_max = 90 +''' ## #Reminder for the possible things to cut on + + ecalPreselectionSkimmer.summed_det_max = 9999. ecalPreselectionSkimmer.summed_tight_iso_max = 9999. ecalPreselectionSkimmer.ecal_back_energy_max = 9999. ecalPreselectionSkimmer.n_readout_hits_max = 9999 ecalPreselectionSkimmer.shower_rms_max = 9999 ecalPreselectionSkimmer.shower_y_std_max = 9999 ecalPreselectionSkimmer.shower_x_std_max = 9999 ecalPreselectionSkimmer.max_cell_dep_max = 9999. ecalPreselectionSkimmer.std_layer_hit_max = 9999 ecalPreselectionSkimmer.n_straight_tracks_max = 9999 +''' + + p.sequence =[ecalPreselectionSkimmer] p.skimDefaultIsDrop() p.skimConsider(p.sequence[0].instanceName)