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) {
32 if (abs(daughter->getPDGCode()) == Const::photon.getPDGCode()) {
39 int nDaughterNeutralHadrons(
const Particle* particle)
42 auto fspDaughters = particle->getFinalStateDaughters();
43 for (
auto* daughter : fspDaughters) {
44 if (abs(daughter->getPDGCode()) == Const::neutron.getPDGCode()
45 or abs(daughter->getPDGCode()) == Const::Klong.getPDGCode()) {
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) {
121 Manager::FunctionPtr daughterAverageOf(
const std::vector<std::string>& arguments)
123 if (arguments.size() == 1) {
124 const Variable::Manager::Var* var = Manager::Instance().getVariable(arguments[0]);
125 auto func = [var](
const Particle * particle) ->
double {
127 if (particle->getNDaughters() == 0)
129 return Const::doubleNaN;
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)
Abstract base class for different kinds of events.