diff --git a/Recon/include/Recon/Skims/EcalPreselectionSkimmer.h b/Recon/include/Recon/Skims/EcalPreselectionSkimmer.h new file mode 100644 index 000000000..534700d70 --- /dev/null +++ b/Recon/include/Recon/Skims/EcalPreselectionSkimmer.h @@ -0,0 +1,65 @@ +/** + * @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" + +namespace recon { + +class EcalPreselectionSkimmer : public framework::Producer { + public: + /** Constructor */ + EcalPreselectionSkimmer(const std::string &name, framework::Process &process); + + /** Destructor */ + ~EcalPreselectionSkimmer() = default; + + // Configure this processor with a set of parameters passed + virtual void configure(framework::config::Parameters &) final; + + /** + * Run the processor and select events that pass pre-selection in ECAL + * + * @param event The event to process. + */ + virtual void produce(framework::Event &event) final; + + 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..1d5ccb6b9 --- /dev/null +++ b/Recon/python/ecalPreselectionSkimmer.py @@ -0,0 +1,60 @@ +"""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 + ecal_pres_skimmer = EcalPreselectionSkimmer() + p.sequence.append( ecal_pres_skimmer ) +""" + +from LDMX.Framework import ldmxcfg + +class EcalPreselectionSkimmer(ldmxcfg.Producer) : + """Configuration for an ECAL-based pre-selection skimmer""" + + def __init__(self, name = "ecalPreselectionSkimmer") : + 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 diff --git a/Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx b/Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx new file mode 100644 index 000000000..8b51868f6 --- /dev/null +++ b/Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx @@ -0,0 +1,64 @@ +/** + * @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}; + const 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); + } + // Add the boolean to the event + event.add("EcalPreselectionDecision", passedPreselection); +} +} // 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..e9fd8fe9a --- /dev/null +++ b/Recon/test/ecal_preselection_skim.py @@ -0,0 +1,34 @@ +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.outputFiles =["eventsPreskimmed.root"] + +from LDMX.Recon.ecalPreselectionSkimmer import EcalPreselectionSkimmer +ecal_pres_skimmer = EcalPreselectionSkimmer() +ecal_pres_skimmer.summed_tight_iso_max = 1100. +ecal_pres_skimmer.n_readout_hits_max = 90 +''' +## Reminder for the possible things to cut on +ecal_pres_skimmer.summed_det_max = 9999. +ecal_pres_skimmer.summed_tight_iso_max = 9999. +ecal_pres_skimmer.ecal_back_energy_max = 9999. +ecal_pres_skimmer.n_readout_hits_max = 9999 +ecal_pres_skimmer.shower_rms_max = 9999 +ecal_pres_skimmer.shower_y_std_max = 9999 +ecal_pres_skimmer.shower_x_std_max = 9999 +ecal_pres_skimmer.max_cell_dep_max = 9999. +ecal_pres_skimmer.std_layer_hit_max = 9999 +ecal_pres_skimmer.n_straight_tracks_max = 9999 +''' + +p.sequence =[ecal_pres_skimmer] +p.skimDefaultIsDrop() +p.skimConsider(p.sequence[0].instanceName)