-
Notifications
You must be signed in to change notification settings - Fork 199
support index-based selection #502
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
fce2d4a
8583260
a1413ca
24fc851
547242a
67704a9
598ad75
4ff8c17
1637717
7f736d2
5dcba23
609d6e4
6ff7a38
f1fe587
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| #define MCPARTICLE_ANALYZERS_H | ||
|
|
||
| #include <cmath> | ||
| #include <functional> | ||
| #include <vector> | ||
|
|
||
| #include "ROOT/RVec.hxx" | ||
|
|
@@ -30,26 +31,49 @@ namespace MCParticle{ | |
| bool operator() (ROOT::VecOps::RVec<edm4hep::MCParticleData> in); | ||
| }; | ||
|
|
||
| /// @brief Helper struct to select entries matching a certain predicate. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also provide an example of usage?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, sure - would you prefer this in the doxygen doc or on the PR? The general pattern is Where This object can then be used to obtain a copy-vector of passed objects from an input object list, or a set of passing indices, or a set of passing element for each of a list of input index vectors. The main motivation is that we save a lot of common boilerplate code when implementing selection functions (loop over containers, output allocation, copy operations, ...). The pattern also ensures that deep-copies are avoided where possible. We also gain the ability to apply the same selection functor transparently on index-based or copy-based selection logic, avoiding a need to duplicate logic if both are to be supported. It would actually be more elegant to generalise this to a template consuming an arbitrary input object type, rather than being restricted to the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice explanation, I think having it in Doxygen would be the best. Would you also add an example how to use this when working with the dataframe in Python? I mean a snipped a user might write.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added explanation for doxygen, including snippets. Also moved the |
||
| /// Supports two signatures - either a list of candidates is passed and a list | ||
| /// of accepted candidates returned, Or a list of indices in a vector of | ||
| /// candidates is passed and a list of accepted indices returned. The latter | ||
| /// is more compatible with index-based selection logic. | ||
| struct selByPredicate { | ||
| selByPredicate( | ||
| std::function<bool(const edm4hep::MCParticleData &)> thePredicate) | ||
| : m_predicate(thePredicate) {} | ||
| std::function<bool(const edm4hep::MCParticleData &)> m_predicate; | ||
| ROOT::VecOps::RVec<edm4hep::MCParticleData> | ||
| operator()(const ROOT::VecOps::RVec<edm4hep::MCParticleData> &in); | ||
| ROOT::VecOps::RVec<int> | ||
| operator()(const ROOT::VecOps::RVec<int> &indices, | ||
| const ROOT::VecOps::RVec<edm4hep::MCParticleData> &in); | ||
| ROOT::VecOps::RVec<ROOT::VecOps::RVec<int>> | ||
| operator()(const ROOT::VecOps::RVec<ROOT::VecOps::RVec<int>> &indices, | ||
| const ROOT::VecOps::RVec<edm4hep::MCParticleData> &in); | ||
| }; | ||
|
|
||
| /// select MCParticles with transverse momentum greater than a minimum value [GeV] | ||
| struct sel_pt { | ||
| struct sel_pt : selByPredicate { | ||
| sel_pt(float arg_min_pt); | ||
| float m_min_pt = 20; //> transverse momentum threshold [GeV] | ||
| ROOT::VecOps::RVec<edm4hep::MCParticleData> operator() (ROOT::VecOps::RVec<edm4hep::MCParticleData> in); | ||
| }; | ||
|
|
||
| /// select MCParticles with absolute pseudorapidity less than a max value | ||
| struct sel_eta : selByPredicate { | ||
| sel_eta(float arg_max_eta); | ||
| }; | ||
|
|
||
| /// select MCParticles with their status | ||
| struct sel_genStatus { | ||
| struct sel_genStatus : selByPredicate { | ||
| sel_genStatus(int arg_status); | ||
| int m_status = 1; //> Generator status | ||
| ROOT::VecOps::RVec<edm4hep::MCParticleData> operator() (ROOT::VecOps::RVec<edm4hep::MCParticleData> in); | ||
| }; | ||
|
|
||
| /// select MCParticles with their PDG id | ||
| struct sel_pdgID { | ||
| struct sel_pdgID : selByPredicate { | ||
| sel_pdgID(int arg_pdg, bool arg_chargeconjugate); | ||
| int m_pdg = 13; | ||
| bool m_chargeconjugate = true; | ||
| ROOT::VecOps::RVec<edm4hep::MCParticleData> operator() (ROOT::VecOps::RVec<edm4hep::MCParticleData> in); | ||
| }; | ||
|
|
||
| /// select MCParticles with a non-zero charge | ||
| struct sel_charged : selByPredicate { | ||
| sel_charged(); | ||
| }; | ||
|
|
||
| /// get MC history tree for a given MCParticle index | ||
|
|
@@ -116,7 +140,6 @@ namespace MCParticle{ | |
| ROOT::VecOps::RVec<edm4hep::MCParticleData> in , | ||
| ROOT::VecOps::RVec<int> ind); | ||
|
|
||
|
|
||
| /// return the parent index of a given list of MC particles | ||
| ROOT::VecOps::RVec<int> get_parentid(ROOT::VecOps::RVec<int> mcind, ROOT::VecOps::RVec<edm4hep::MCParticleData> mc, ROOT::VecOps::RVec<int> parents); | ||
|
|
||
|
|
@@ -210,6 +233,16 @@ namespace MCParticle{ | |
| /// return the list of stable particles from the decay of a mother particle, looking at the full decay chain recursively. i is the mother index in the Particle block | ||
| std::vector<int> get_list_of_stable_particles_from_decay( int i, ROOT::VecOps::RVec<edm4hep::MCParticleData> in, ROOT::VecOps::RVec<int> ind) ; | ||
|
|
||
| /// return the list of stable particles from the decays of a mother particle, | ||
| /// looking at the full decay chain recursively. i is the list of mother | ||
| /// indices to process in the Particle block. Will return a vector of vectors | ||
| /// - each vector is the set of children for one of the mothers in the input | ||
| /// vector | ||
| ROOT::VecOps::RVec<ROOT::VecOps::RVec<int>> | ||
| get_lists_of_stable_particles_from_decays( | ||
| ROOT::VecOps::RVec<int> i, ROOT::VecOps::RVec<edm4hep::MCParticleData> in, | ||
| ROOT::VecOps::RVec<int> ind); | ||
|
|
||
| /// return the list of particles from the decay of a mother particle. i is the mother index in the Particle block. | ||
| std::vector<int> get_list_of_particles_from_decay( int i, | ||
| ROOT::VecOps::RVec<edm4hep::MCParticleData> in, | ||
|
|
||
|
kjvbrt marked this conversation as resolved.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for figuring this out :)
Maybe
(otherwise you will reformat the entire file)is a bit redundant, as the same information is a few lines above.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, at some point we need to run formatter across the whole repository.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, maybe MR -> PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed (caught a long-term gitlab user :) )