Skip to content

Commit

Permalink
Few more analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvbrt committed Nov 16, 2023
1 parent 81db22c commit 5ad051d
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 48 deletions.
72 changes: 72 additions & 0 deletions analyzers/dataframe/FCCAnalyses/Association.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#ifndef ASSOCIATION_ANALYZERS_H
#define ASSOCIATION_ANALYZERS_H

// EDM4hep
#include "edm4hep/MCRecoParticleAssociationCollection.h"


namespace FCCAnalyses :: Association {
/**
* \brief Analyzer to select associations with a mcparticle with a
* specified PDG ID.
*
* \param pdg Desired PDG ID of the partile.
*/
struct sel_PDG {
sel_PDG(const int pdg);
const int m_pdg;
template <typename T>
T operator() (
const T& inAssocColl);
};


/**
* \brief Analyzer to select associations with a mcparticle with a
* specified absolute value of PDG ID.
*
* \param pdg Desired absolute value of PDG ID of the partile.
*/
struct sel_absPDG {
const int m_pdg;

sel_absPDG(const int pdg) : m_pdg(pdg) {
if (m_pdg < 0) {
throw std::invalid_argument(
"Association::sel_absPDG: Received negative value!");
}
};

template <typename T>
auto operator() (const T& inAssocColl) {
T result;
result.setSubsetCollection();

for (const auto& assoc: inAssocColl) {
const auto& particle = assoc.getSim();
if (std::abs(particle.getPDG()) == m_pdg) {
result.push_back(assoc);
}
}

return result;
};
};


/**
* \brief Analyzer to select associations with a mcparticle with a
* specified generator status.
*
* \param pdg Desired generator status of the partile.
*/
struct sel_genStatus {
sel_genStatus(const int status);
const int m_status;
template <typename T>
T operator() (
const T& inAssocColl);
};
} /* FCCAnalyses::Association */

#endif /* ASSOCIATION_ANALYZERS_H */
17 changes: 15 additions & 2 deletions analyzers/dataframe/FCCAnalyses/ReconstructedParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ namespace ReconstructedParticle{
struct sel_absType {
sel_absType(const int type);
const int m_type;
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData>
operator()(ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in);
edm4hep::ReconstructedParticleCollection
operator()(edm4hep::ReconstructedParticleCollection& in);
};

/// select ReconstructedParticles with transverse momentum greater than a minimum value [GeV]
Expand Down Expand Up @@ -134,6 +134,19 @@ namespace ReconstructedParticle{
};


/**
* \brief Analyzer to select reconstructed particles by generator status
*
* \param status Desired generator status of the particles
*/
struct sel_genStatus {
sel_genStatus(const int status);
const int m_status;
edm4hep::ReconstructedParticleCollection operator() (
const edm4hep::MCRecoParticleAssociationCollection& inAssocColl);
};


/// return reconstructed particles
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> get(ROOT::VecOps::RVec<int> index, ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> in);

Expand Down
68 changes: 68 additions & 0 deletions analyzers/dataframe/src/Association.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "FCCAnalyses/Association.h"

// std
#include <cstdlib>
#include <cmath>


namespace FCCAnalyses :: Association {
sel_PDG::sel_PDG(const int pdg) : m_pdg(pdg) {};

template <typename T>
T sel_PDG::operator() (const T& inAssocColl) {
T result;
result.setSubsetCollection();

for (const auto& assoc: inAssocColl) {
const auto& particle = assoc.getSim();
if (particle.getPDG() == m_pdg) {
result.push_back(assoc);
}
}

return result;
}


/*
sel_absPDG::sel_absPDG(const int pdg) : m_pdg(pdg) {
if (m_pdg < 0) {
throw std::invalid_argument(
"Association::sel_absPDG: Received negative value!");
}
}
template <typename T>
auto sel_absPDG::operator() (const T& inAssocColl) {
T result;
result.setSubsetCollection();
for (const auto& assoc: inAssocColl) {
const auto& particle = assoc.getSim();
if (std::abs(particle.getPDG()) == m_pdg) {
result.push_back(assoc);
}
}
return result;
}
*/


sel_genStatus::sel_genStatus(const int status) : m_status(status) {};

template <typename T>
T sel_genStatus::operator() (const T& inAssocColl) {
T result;
result.setSubsetCollection();

for (const auto& assoc: inAssocColl) {
const auto& particle = assoc.getSim();
if (particle.getGeneratorStatus() == m_status) {
result.push_back(assoc);
}
}

return result;
}
} /* FCCAnalyses::Association */
62 changes: 55 additions & 7 deletions analyzers/dataframe/src/ReconstructedParticle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
#include <iostream>
#include <stdexcept>

// ROOT
#include <ROOT/RDataFrame.hxx>
#include <ROOT/RLogger.hxx>


#define rdfInfo R__LOG_INFO(ROOT::Detail::RDF::RDFLogChannel())


namespace FCCAnalyses{

namespace ReconstructedParticle{
Expand All @@ -24,6 +32,7 @@ ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> sel_type::operator()(
return result;
}


/// sel_absType
sel_absType::sel_absType(const int type) : m_type(type) {
if (m_type < 0) {
Expand All @@ -32,18 +41,21 @@ sel_absType::sel_absType(const int type) : m_type(type) {
}
}

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]);
edm4hep::ReconstructedParticleCollection sel_absType::operator()(
edm4hep::ReconstructedParticleCollection& inColl) {
edm4hep::ReconstructedParticleCollection result;
result.setSubsetCollection();

for (const auto& particle: inColl) {
if (std::abs(particle.getType()) == m_type) {
result.push_back(particle);
}
}

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) {
Expand Down Expand Up @@ -113,6 +125,8 @@ edm4hep::ReconstructedParticleCollection selPDG::operator() (
edm4hep::ReconstructedParticleCollection result;
result.setSubsetCollection();

rdfInfo << "Assoc coll size: " << inAssocColl.size();

for (const auto& assoc: inAssocColl) {
const auto& particle = assoc.getSim();
if (m_chargeConjugateAllowed) {
Expand Down Expand Up @@ -148,6 +162,40 @@ edm4hep::ReconstructedParticleCollection selUpTo::operator() (
return result;
}

sel_genStatus::sel_genStatus(int status) : m_status(status) {};

edm4hep::ReconstructedParticleCollection sel_genStatus::operator() (
const edm4hep::MCRecoParticleAssociationCollection& inAssocColl) {
edm4hep::ReconstructedParticleCollection result;
result.setSubsetCollection();


// std::cout << "******************************************" << std::endl;
for (const auto& assoc: inAssocColl) {
const auto& mcParticle = assoc.getSim();
const auto& recoParticle = assoc.getRec();
// std::cout << "------------------------------------" << std::endl;
// std::cout << "gen status: " << mcParticle.getGeneratorStatus() << std::endl;
// std::cout << "energy: " << mcParticle.getEnergy() << std::endl;
// std::cout << "pdg: " << mcParticle.getPDG() << std::endl;
// std::cout << "" << std::endl;
// std::cout << "type: " << recoParticle.getType() << std::endl;
// std::cout << "energy: " << recoParticle.getEnergy() << std::endl;
// std::cout << "momentum, x: " << recoParticle.getMomentum().x << std::endl;
// std::cout << "momentum, y: " << recoParticle.getMomentum().y << std::endl;
// std::cout << "momentum, z: " << recoParticle.getMomentum().z << std::endl;
// std::cout << "position, x: " << recoParticle.getReferencePoint().x << std::endl;
// std::cout << "position, y: " << recoParticle.getReferencePoint().y << std::endl;
// std::cout << "position, z: " << recoParticle.getReferencePoint().z << std::endl;
// std::cout << "goodnessOfPID: " << recoParticle.getGoodnessOfPID() << std::endl;
if (mcParticle.getGeneratorStatus() == m_status) {
result.push_back(assoc.getRec());
}
}

return result;
}


resonanceBuilder::resonanceBuilder(float arg_resonance_mass) {m_resonance_mass = arg_resonance_mass;}
ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> resonanceBuilder::operator()(ROOT::VecOps::RVec<edm4hep::ReconstructedParticleData> legs) {
Expand Down
Loading

0 comments on commit 5ad051d

Please sign in to comment.