Belle II Software light-2406-ragdoll
ParticleDaughterVariables.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <analysis/variables/ParticleDaughterVariables.h>
11
12// include VariableManager
13#include <analysis/VariableManager/Manager.h>
14
15#include <analysis/variables/MCTruthVariables.h>
16
17// dataobjects
18#include <analysis/dataobjects/Particle.h>
19#include <mdst/dataobjects/MCParticle.h>
20
21// framework aux
22#include <framework/logging/Logger.h>
23#include <framework/gearbox/Const.h>
24
25#include <iostream>
26#include <cmath>
27
28using namespace std;
29
30namespace Belle2 {
35 namespace Variable {
36
37 double hasCharmedDaughter(const Particle* particle, const std::vector<double>& transition)
38 {
39 double Status = 0.0;
40
41 // Check if correct arguments
42 if (abs(transition[0]) != 1) {
43 B2ERROR("The parameter variable hasCharmedDaughter() only accepts 1 or -1 as an argument.");
44 return Const::doubleNaN;
45 }
46
47 // Check if particle exists
48 if (!particle) {
49 B2ERROR("This particle does not exist!");
50 return Const::doubleNaN;
51 }
52
53 // Check if MC particle exists
54 const MCParticle* mcp = particle->getMCParticle();
55 if (!mcp)
56 return Const::doubleNaN;
57
58 // MCParticle should be related to a B meson
59 if (abs(mcp->getPDG()) != 511 and abs(mcp->getPDG()) != 521)
60 return Const::doubleNaN;
61
62 // Check if the particle has daughters
63 int nDaughters = int(mcp->getNDaughters());
64 if (nDaughters < 1) {
65 B2ERROR("This particle does not have any daughters!");
66 return Const::doubleNaN;
67 }
68
69 // Get the PDG sign and load daughters
70 int motherPDGSign = (particle->getPDGCode()) / (abs(particle->getPDGCode()));
71 std::vector<MCParticle*> mcDaughters = mcp->getDaughters();
72
73 for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
74 int daughterPDG = mcDaughters[iDaughter]->getPDG();
75 int daughterPDGSign = daughterPDG / (abs(daughterPDG));
76
77 if (transition[0] == 1) {
78 if (((abs(daughterPDG) / 100) % 10 == 4 || (abs(daughterPDG) / 1000) % 10 == 4)
79 && motherPDGSign == daughterPDGSign) // charmed meson or baryon and b->anti-c transition
80 Status = 1.0;
81 } else if (transition[0] == -1) {
82 if (((abs(daughterPDG) / 100) % 10 == 4 || (abs(daughterPDG) / 1000) % 10 == 4)
83 && motherPDGSign == -daughterPDGSign) // charmed meson or baryon and b->c transition
84 Status = 1.0;
85 }
86 }
87
88 return Status;
89 }
90
91 double hasCharmoniumDaughter(const Particle* particle)
92 {
93 double Status = 0.0;
94
95 // Check if particle exists
96 if (!particle) {
97 B2ERROR("This particle does not exist!");
98 return Const::doubleNaN;
99 }
100
101 // Check if MC particle exists
102 const MCParticle* mcp = particle->getMCParticle();
103 if (!mcp)
104 return Const::doubleNaN;
105
106 // MCParticle should be related to a B meson
107 if (abs(mcp->getPDG()) != 511 and abs(mcp->getPDG()) != 521)
108 return Const::doubleNaN;
109
110 // Check if the particle has daughters
111 int nDaughters = int(mcp->getNDaughters());
112 if (nDaughters < 1) {
113 B2ERROR("This particle does not have any daughters!");
114 return Const::doubleNaN;
115 }
116
117 // Load daughters
118 std::vector<MCParticle*> mcDaughters = mcp->getDaughters();
119
120 for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
121 int daughterPDG = mcDaughters[iDaughter]->getPDG();
122 if ((abs(daughterPDG) / 10) % 10 == 4 && (abs(daughterPDG) / 100) % 10 == 4) // charmonium state: b->c anti-c q transition
123 Status = 1.0;
124 }
125
126 return Status;
127 }
128
129 double hasRealPhotonDaughter(const Particle* particle)
130 {
131 double Status = 0.0;
132
133 // Check if particle exists
134 if (!particle) {
135 B2ERROR("This particle does not exist!");
136 return Const::doubleNaN;
137 }
138
139 // Check if the particle has daughters
140 int nDaughters = int(particle->getNDaughters());
141 if (nDaughters < 1) {
142 B2ERROR("This particle does not have any daughters!");
143 return Const::doubleNaN;
144 }
145
146 // Load daughters
147 const std::vector<Particle*> daughters = particle->getDaughters();
148
149 for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
150 double photosFlag = particleMCPhotosParticle(daughters[iDaughter]);
151 int PDGcode = daughters[iDaughter]->getPDGCode();
152
153 // Is it a real photon?
154 if (PDGcode == Const::photon.getPDGCode() && photosFlag > -0.5 && photosFlag < 0.5) { // must not be from PHOTOS
155 Status = 1.0;
156 }
157 }
158
159 return Status;
160 }
161
162 VARIABLE_GROUP("DirectDaughterInfo");
163 REGISTER_VARIABLE("hasCharmedDaughter(i)", hasCharmedDaughter,
164 "If i = 1 is provided it checks for b -> anti-c / anti-b -> c transition and for i = -1 it checks for b -> c / anti-b -> anti-c transitions.\n"
165 "Returns 1 if at least one of the daughters on MC truth level is a charm meson. The particle's MC partner must be a B-meson.\n"
166 "Returns 0 if no charmed daughter found on MC truth level and NaN if no MC partner was found or the related MC particle isn't a B-meson.");
167 REGISTER_VARIABLE("hasCharmoniumDaughter", hasCharmoniumDaughter,
168 "Returns 1 if at least one of the daughters on MC truth level is a ccbar resonance. The particle's MC partner must be a B-meson.\n"
169 "Returns 0 if no ccbar resonance found on MC truth level and NaN if no MC partner was found or the related MC particle isn't a B-meson.");
170 REGISTER_VARIABLE("hasRealPhotonDaughter", hasRealPhotonDaughter,
171 "Returns 1 if on MC truth level there is at least one real photon daughter, a photon that was not created by photos.\n"
172 "Returns 0 if no real photon daughter found and NaN if the particle has no daughters.");
173 }
175}
static const double doubleNaN
quiet_NaN
Definition: Const.h:703
static const ParticleType photon
photon particle
Definition: Const.h:673
const MCParticle * getMCParticle() const
Returns the pointer to the MCParticle object that was used to create this Particle (ParticleType == c...
Definition: Particle.cc:942
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24
STL namespace.