Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce EcalPreselectionSkimmer #1389

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions Recon/include/Recon/Skims/EcalPreselectionSkimmer.h
Original file line number Diff line number Diff line change
@@ -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"
tvami marked this conversation as resolved.
Show resolved Hide resolved

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);
tvami marked this conversation as resolved.
Show resolved Hide resolved

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_
63 changes: 63 additions & 0 deletions Recon/python/ecalPreselectionSkimmer.py
Original file line number Diff line number Diff line change
@@ -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")

tvami marked this conversation as resolved.
Show resolved Hide resolved
62 changes: 62 additions & 0 deletions Recon/src/Recon/Skims/EcalPreselectionSkimmer.cxx
Original file line number Diff line number Diff line change
@@ -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<std::string>("ecal_veto_name");
ecal_veto_pass_ = ps.getParameter<std::string>("ecal_veto_pass");
summed_det_max_ = ps.getParameter<double>("summed_det_max"); // MeV
summed_tight_iso_max_ =
ps.getParameter<double>("summed_tight_iso_max"); // MeV
ecal_back_energy_max_ =
ps.getParameter<double>("ecal_back_energy_max"); // MeV
n_readout_hits_max_ = ps.getParameter<int>("n_readout_hits_max");
shower_rms_max_ = ps.getParameter<int>("shower_rms_max");
shower_y_std_max_ = ps.getParameter<int>("shower_y_std_max");
shower_x_std_max_ = ps.getParameter<int>("shower_x_std_max");
max_cell_dep_max_ = ps.getParameter<double>("max_cell_dep_max"); // MeV
std_layer_hit_max_ = ps.getParameter<int>("std_layer_hit_max");
n_straight_tracks_max_ = ps.getParameter<int>("n_straight_tracks_max");

return;
}

void EcalPreselectionSkimmer::produce(framework::Event &event) {
bool passedPreselection{false};
auto ecalVeto{
tvami marked this conversation as resolved.
Show resolved Hide resolved
event.getObject<ldmx::EcalVetoResult>(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);
}
tvami marked this conversation as resolved.
Show resolved Hide resolved
}
} // namespace recon

DECLARE_PRODUCER_NS(recon, EcalPreselectionSkimmer);
17 changes: 17 additions & 0 deletions Recon/test/ecal_preselection_skim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os import sys
tvami marked this conversation as resolved.
Show resolved Hide resolved

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)