10#include <analysis/variables/InclusiveVariables.h>
12#include <analysis/dataobjects/Particle.h>
14#include <framework/gearbox/Const.h>
15#include <framework/logging/Logger.h>
26 int nDaughterPhotons(
const Particle* particle)
29 auto fspDaughters = particle->getFinalStateDaughters();
30 for (
auto* daughter : fspDaughters) {
38 int nDaughterNeutralHadrons(
const Particle* particle)
41 auto fspDaughters = particle->getFinalStateDaughters();
42 for (
auto* daughter : fspDaughters) {
51 int nDaughterCharged(
const Particle* particle,
const std::vector<double>& argument)
54 if (argument.size() == 1) {
55 absPDGCode = abs(std::lround(argument[0]));
59 auto fspDaughters = particle->getFinalStateDaughters();
60 for (
auto* daughter : fspDaughters) {
61 if (absPDGCode != 0) {
62 if (abs(daughter->getPDGCode()) == absPDGCode) {
65 }
else if (abs(daughter->getCharge()) > 0) {
72 int nCompositeDaughters(
const Particle* particle,
const std::vector<double>& argument)
75 if (argument.size() == 1) {
76 absPDGCode = abs(std::lround(argument[0]));
80 auto primaryDaughters = particle->getDaughters();
81 for (
auto* daughter : primaryDaughters) {
82 if (daughter->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
83 daughter->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
84 if (absPDGCode != 0) {
85 if (abs(daughter->getPDGCode()) == absPDGCode) {
96 int nCompositeAllGenerationDaughters(
const Particle* particle,
const std::vector<double>& argument)
99 if (argument.size() == 1) {
100 absPDGCode = abs(std::lround(argument[0]));
104 auto allDaughters = particle->getAllDaughters();
105 for (
auto* daughter : allDaughters) {
106 if (daughter->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
107 daughter->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
108 if (absPDGCode != 0) {
109 if (abs(daughter->getPDGCode()) == absPDGCode) {
122 if (arguments.size() == 1) {
124 auto func = [var](
const Particle * particle) ->
double {
126 if (particle->getNDaughters() == 0)
130 if (std::holds_alternative<double>(var->function(particle->getDaughter(0))))
132 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
133 sum += std::get<double>(var->function(particle->getDaughter(j)));
135 }
else if (std::holds_alternative<int>(var->function(particle->getDaughter(0))))
137 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
138 sum += std::get<int>(var->function(particle->getDaughter(j)));
141 return sum / particle->getNDaughters();
145 B2FATAL(
"The meta variable daughterAverageOf requires only one argument!");
151 VARIABLE_GROUP(
"For fully-inclusive particles");
153 REGISTER_VARIABLE(
"nDaughterPhotons", nDaughterPhotons,
154 "Returns the number of final state daughter photons.");
155 REGISTER_VARIABLE(
"nDaughterNeutralHadrons", nDaughterNeutralHadrons,
156 "Returns the number of K_L0 or neutrons among the final state daughters.");
157 REGISTER_VARIABLE(
"nDaughterCharged(pdg)", nDaughterCharged,
158 "Returns the number of charged daughters with the provided PDG code or the number "
159 "of all charged daughters if no argument has been provided. "
160 "The variable is flavor agnostic and it returns the sum of the number of particle and anti-particle.");
161 REGISTER_VARIABLE(
"nCompositeDaughters(pdg)", nCompositeDaughters,
162 "Returns the number of primary composite daughters with the provided PDG code or the number"
163 "of all primary composite daughters if no argument has been provided. "
164 "The variable is flavor agnostic and it returns the sum of the number of particle and anti-particle.");
165 REGISTER_VARIABLE(
"nCompositeAllGenerationDaughters(pdg)", nCompositeAllGenerationDaughters,
166 "Returns the number of all generations' composite daughters with the provided PDG code or the number"
167 "of all generations' composite daughters if no argument has been provided. "
168 "The variable is flavor agnostic and it returns the sum of the number of particle and anti-particle.");
169 REGISTER_METAVARIABLE(
"daughterAverageOf(variable)", daughterAverageOf,
170 "Returns the mean value of a variable over all daughters.", Manager::VariableDataType::c_double)
int getPDGCode() const
PDG code.
static const ParticleType neutron
neutron particle
static const ParticleType Klong
K^0_L particle.
static const double doubleNaN
quiet_NaN
static const ParticleType photon
photon particle
std::function< VarVariant(const Particle *)> FunctionPtr
functions stored take a const Particle* and return VarVariant.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
Abstract base class for different kinds of events.