Skip to content

Commit

Permalink
Merge pull request #312 from kjvbrt/sel_type
Browse files Browse the repository at this point in the history
Implementing selection by type for Reconstructed particles
  • Loading branch information
kjvbrt authored Sep 19, 2023
2 parents f1078cd + 813303d commit b969668
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 1 deletion.
18 changes: 18 additions & 0 deletions analyzers/dataframe/FCCAnalyses/ReconstructedParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ namespace ReconstructedParticle{
float operator() (ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in) ;
};

/// select ReconstructedParticles by type
/// Note: type might not correspond to PDG ID
struct sel_type {
sel_type(const int type);
const int m_type;
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData>
operator()(ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in);
};

/// select ReconstructedParticles by type absolute value
/// Note: type might not correspond to PDG ID
struct sel_absType {
sel_absType(const int type);
const int m_type;
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData>
operator()(ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in);
};

/// select ReconstructedParticles with transverse momentum greater than a minimum value [GeV]
struct sel_pt {
sel_pt(float arg_min_pt);
Expand Down
40 changes: 40 additions & 0 deletions analyzers/dataframe/src/ReconstructedParticle.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
#include "FCCAnalyses/ReconstructedParticle.h"

// std
#include <cstdlib>
#include <iostream>
#include <stdexcept>

namespace FCCAnalyses{

namespace ReconstructedParticle{

/// sel_type
sel_type::sel_type(const int type) : m_type(type) {}

ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> sel_type::operator()(
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in) {
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> result;
result.reserve(in.size());
for (size_t i = 0; i < in.size(); ++i) {
if (in[i].type == m_type) {
result.emplace_back(in[i]);
}
}
return result;
}

/// sel_absType
sel_absType::sel_absType(const int type) : m_type(type) {
if (m_type < 0) {
throw std::invalid_argument(
"ReconstructedParticle::sel_absType: Received negative value!");
}
}

ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> sel_absType::operator()(
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in) {
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> result;
result.reserve(in.size());
for (size_t i = 0; i < in.size(); ++i) {
if (std::abs(in[i].type) == m_type) {
result.emplace_back(in[i]);
}
}
return result;
}

/// sel_pt
sel_pt::sel_pt(float arg_min_pt) : m_min_pt(arg_min_pt) {};
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> sel_pt::operator() (ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in) {
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> result;
Expand Down
6 changes: 5 additions & 1 deletion tests/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ find_catch_instance()
# list of labels that we want to ignore
set(filter_tests "")

add_executable(unittest unittest.cpp myutils.cpp algorithms.cpp)
add_executable(unittest unittest.cpp
myutils.cpp
algorithms.cpp
ReconstructedParticle.cpp
)
target_link_libraries(unittest PUBLIC FCCAnalyses gfortran PRIVATE Catch2::Catch2WithMain)
target_include_directories(unittest PUBLIC ${VDT_INCLUDE_DIR})
target_compile_definitions(unittest PUBLIC "-DTEST_INPUT_DATA_DIR=${TEST_INPUT_DATA_DIR}")
Expand Down
51 changes: 51 additions & 0 deletions tests/unittest/ReconstructedParticle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "FCCAnalyses/ReconstructedParticle.h"

// Catch2
#include "catch2/catch_test_macros.hpp"
#include <catch2/catch_approx.hpp>

TEST_CASE("sel_type", "[ReconstructedParticle]") {
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> pVec;
edm4hep::ReconstructedParticleData p1;
p1.type = 11;
pVec.push_back(p1);
edm4hep::ReconstructedParticleData p2;
p2.type = 13;
pVec.push_back(p2);
edm4hep::ReconstructedParticleData p3;
p3.type = -11;
pVec.push_back(p3);
edm4hep::ReconstructedParticleData p4;
p4.type = -13;
pVec.push_back(p4);
FCCAnalyses::ReconstructedParticle::sel_type selType{11};
auto res = selType(pVec);
REQUIRE(res.size() == 1);
REQUIRE(res[0].type == 11);
}

TEST_CASE("sel_absType", "[ReconstructedParticle]") {
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> pVec;
edm4hep::ReconstructedParticleData p1;
p1.type = 11;
pVec.push_back(p1);
edm4hep::ReconstructedParticleData p2;
p2.type = 13;
pVec.push_back(p2);
edm4hep::ReconstructedParticleData p3;
p3.type = -11;
pVec.push_back(p3);
edm4hep::ReconstructedParticleData p4;
p4.type = -13;
pVec.push_back(p4);
FCCAnalyses::ReconstructedParticle::sel_absType selAbsType{11};
auto res = selAbsType(pVec);
REQUIRE(res.size() == 2);
REQUIRE(res[0].type == 11);
REQUIRE(res[1].type == -11);
}

TEST_CASE("sel_absType__neg_type", "[ReconstructedParticle]") {
REQUIRE_THROWS_AS(FCCAnalyses::ReconstructedParticle::sel_absType(-17),
std::invalid_argument);
}

0 comments on commit b969668

Please sign in to comment.