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

function to select quantities on exact match #250

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 13 additions & 0 deletions include/basefunctions.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,19 @@ inline auto FilterAbsMin(const float &cut) {
};
}

/// Function to apply an exact filter requirement to an integer quantity.
/// Returns true if the value is equal to the given value
///
/// \param cut The value of the filter
///
/// \returns a lambda function to be used in RDF Define
inline auto FilterEqualInt(const int &cut) {
return [cut](const ROOT::RVec<int> &values) {
ROOT::RVec<int> mask = values == cut;
return mask;
};
}

/// Function to combine two RVec Masks by multiplying the two RVec elementwise
///
/// \param mask_1 The first mask
Expand Down
2 changes: 2 additions & 0 deletions include/physicsobjects.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ ROOT::RDF::RNode CheckForDiLeptonPairs(
const std::string &leptons_phi, const std::string &leptons_mass,
const std::string &leptons_charge, const std::string &leptons_mask,
const float dR_cut);
ROOT::RDF::RNode SelectInt(ROOT::RDF::RNode df, const std::string &maskname,
const std::string &nameID, const int &IDvalue);
namespace muon {
ROOT::RDF::RNode CutID(ROOT::RDF::RNode df, const std::string &maskname,
const std::string &nameID);
Expand Down
15 changes: 15 additions & 0 deletions src/physicsobjects.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,21 @@ ROOT::RDF::RNode CheckForDiLeptonPairs(
leptons_charge, leptons_mask});
return df1;
}
/// Function to select objects based on matching a specific integer value
///
/// \param[in] df the input dataframe
/// \param[out] maskname the name of the new mask to be added as column to
/// the dataframe
/// \param[in] nameID name of the ID column in the NanoAOD
/// \param[in] IDvalue value that has to match
///
/// \return a dataframe containing the new mask
ROOT::RDF::RNode SelectInt(ROOT::RDF::RNode df, const std::string &maskname,
const std::string &nameID, const int &IDvalue) {
auto df1 =
df.Define(maskname, basefunctions::FilterEqualInt(IDvalue), {nameID});
return df1;
}

/// Muon specific functions
namespace muon {
Expand Down
Loading