10#include <analysis/variables/InclusiveVariables.h>
12#include <analysis/dataobjects/Particle.h>
14#include <framework/gearbox/Const.h>
15#include <framework/logging/Logger.h>
16#include <framework/utilities/Conversion.h>
27 int nDaughterPhotons(
const Particle* particle)
30 auto fspDaughters = particle->getFinalStateDaughters();
31 for (
auto* daughter : fspDaughters) {
39 int nDaughterNeutralHadrons(
const Particle* particle)
42 auto fspDaughters = particle->getFinalStateDaughters();
43 for (
auto* daughter : fspDaughters) {
52 int nDaughterCharged(
const Particle* particle,
const std::vector<double>& argument)
55 if (argument.size() == 1) {
56 absPDGCode = abs(std::lround(argument[0]));
60 auto fspDaughters = particle->getFinalStateDaughters();
61 for (
auto* daughter : fspDaughters) {
62 if (absPDGCode != 0) {
63 if (abs(daughter->getPDGCode()) == absPDGCode) {
66 }
else if (abs(daughter->getCharge()) > 0) {
73 int nCompositeDaughters(
const Particle* particle,
const std::vector<double>& argument)
76 if (argument.size() == 1) {
77 absPDGCode = abs(std::lround(argument[0]));
81 auto primaryDaughters = particle->getDaughters();
82 for (
auto* daughter : primaryDaughters) {
83 if (daughter->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
84 daughter->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
85 if (absPDGCode != 0) {
86 if (abs(daughter->getPDGCode()) == absPDGCode) {
97 int nCompositeAllGenerationDaughters(
const Particle* particle,
const std::vector<double>& argument)
100 if (argument.size() == 1) {
101 absPDGCode = abs(std::lround(argument[0]));
105 auto allDaughters = particle->getAllDaughters();
106 for (
auto* daughter : allDaughters) {
107 if (daughter->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
108 daughter->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
109 if (absPDGCode != 0) {
110 if (abs(daughter->getPDGCode()) == absPDGCode) {
123 if (arguments.size() == 1) {
125 auto func = [var](
const Particle * particle) ->
double {
127 if (particle->getNDaughters() == 0)
131 if (std::holds_alternative<double>(var->function(particle->getDaughter(0))))
133 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
134 sum += std::get<double>(var->function(particle->getDaughter(j)));
136 }
else if (std::holds_alternative<int>(var->function(particle->getDaughter(0))))
138 for (
unsigned j = 0; j < particle->getNDaughters(); ++j) {
139 sum += std::get<int>(var->function(particle->getDaughter(j)));
142 return sum / particle->getNDaughters();
146 B2FATAL(
"The meta variable daughterAverageOf requires only one argument!");
152 VARIABLE_GROUP(
"For fully-inclusive particles");
154 REGISTER_VARIABLE(
"nDaughterPhotons", nDaughterPhotons,
155 "Returns the number of final state daughter photons.");
156 REGISTER_VARIABLE(
"nDaughterNeutralHadrons", nDaughterNeutralHadrons,
157 "Returns the number of K_L0 or neutrons among the final state daughters.");
158 REGISTER_VARIABLE(
"nDaughterCharged(pdg)", nDaughterCharged,
159 "Returns the number of charged daughters with the provided PDG code or the number "
160 "of all charged daughters if no argument has been provided. "
161 "The variable is flavor agnostic and it returns the sum of the number of particle and anti-particle.");
162 REGISTER_VARIABLE(
"nCompositeDaughters(pdg)", nCompositeDaughters,
163 "Returns the number of primary composite daughters with the provided PDG code or the number"
164 "of all primary composite daughters if no argument has been provided. "
165 "The variable is flavor agnostic and it returns the sum of the number of particle and anti-particle.");
166 REGISTER_VARIABLE(
"nCompositeAllGenerationDaughters(pdg)", nCompositeAllGenerationDaughters,
167 "Returns the number of all generations' composite daughters with the provided PDG code or the number"
168 "of all generations' composite daughters if no argument has been provided. "
169 "The variable is flavor agnostic and it returns the sum of the number of particle and anti-particle.");
170 REGISTER_METAVARIABLE(
"daughterAverageOf(variable)", daughterAverageOf,
171 "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.