Skip to content

Commit

Permalink
function to select quantities on exact match (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
nfaltermann authored Feb 13, 2024
1 parent 61dbbf3 commit ac72633
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
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

0 comments on commit ac72633

Please sign in to comment.