Belle II Software development
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
25using namespace std;
26
27namespace Belle2 {
32 namespace Variable {
33
34 double hasCharmedDaughter(const Particle* particle, const std::vector<double>& transition)
35 {
36 double Status = 0.0;
37
38 // Check if correct arguments
39 if (abs(transition[0]) != 1) {
40 B2ERROR("The parameter variable hasCharmedDaughter() only accepts 1 or -1 as an argument.");
41 return Const::doubleNaN;
42 }
43
44 // Check if particle exists
45 if (!particle) {
46 B2ERROR("This particle does not exist!");
47 return Const::doubleNaN;
48 }
49
50 // Check if MC particle exists
51 const MCParticle* mcp = particle->getMCParticle();
52 if (!mcp)
53 return Const::doubleNaN;
54
55 // MCParticle should be related to a B meson
56 if (abs(mcp->getPDG()) != 511 and abs(mcp->getPDG()) != 521)
57 return Const::doubleNaN;
58
59 // Check if the particle has daughters
60 int nDaughters = int(mcp->getNDaughters());
61 if (nDaughters < 1) {
62 B2ERROR("This particle does not have any daughters!");
63 return Const::doubleNaN;
64 }
65
66 // Get the PDG sign and load daughters
67 int motherPDGSign = (particle->getPDGCode()) / (abs(particle->getPDGCode()));
68 std::vector<MCParticle*> mcDaughters = mcp->getDaughters();
69
70 for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
71 int daughterPDG = mcDaughters[iDaughter]->getPDG();
72 int daughterPDGSign = daughterPDG / (abs(daughterPDG));
73
74 if (transition[0] == 1) {
75 if (((abs(daughterPDG) / 100) % 10 == 4 || (abs(daughterPDG) / 1000) % 10 == 4)
76 && motherPDGSign == daughterPDGSign) // charmed meson or baryon and b->anti-c transition
77 Status = 1.0;
78 } else if (transition[0] == -1) {
79 if (((abs(daughterPDG) / 100) % 10 == 4 || (abs(daughterPDG) / 1000) % 10 == 4)
80 && motherPDGSign == -daughterPDGSign) // charmed meson or baryon and b->c transition
81 Status = 1.0;
82 }
83 }
84
85 return Status;
86 }
87
88 double hasCharmoniumDaughter(const Particle* particle)
89 {
90 double Status = 0.0;
91
92 // Check if particle exists
93 if (!particle) {
94 B2ERROR("This particle does not exist!");
95 return Const::doubleNaN;
96 }
97
98 // Check if MC particle exists
99 const MCParticle* mcp = particle->getMCParticle();
100 if (!mcp)
101 return Const::doubleNaN;
102
103 // MCParticle should be related to a B meson
104 if (abs(mcp->getPDG()) != 511 and abs(mcp->getPDG()) != 521)
105 return Const::doubleNaN;
106
107 // Check if the particle has daughters
108 int nDaughters = int(mcp->getNDaughters());
109 if (nDaughters < 1) {
110 B2ERROR("This particle does not have any daughters!");
111 return Const::doubleNaN;
112 }
113
114 // Load daughters
115 std::vector<MCParticle*> mcDaughters = mcp->getDaughters();
116
117 for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
118 int daughterPDG = mcDaughters[iDaughter]->getPDG();
119 if ((abs(daughterPDG) / 10) % 10 == 4 && (abs(daughterPDG) / 100) % 10 == 4) // charmonium state: b->c anti-c q transition
120 Status = 1.0;
121 }
122
123 return Status;
124 }
125
126 double hasRealPhotonDaughter(const Particle* particle)
127 {
128 double Status = 0.0;
129
130 // Check if particle exists
131 if (!particle) {
132 B2ERROR("This particle does not exist!");
133 return Const::doubleNaN;
134 }
135
136 // Check if the particle has daughters
137 int nDaughters = int(particle->getNDaughters());
138 if (nDaughters < 1) {
139 B2ERROR("This particle does not have any daughters!");
140 return Const::doubleNaN;
141 }
142
143 // Load daughters
144 const std::vector<Particle*> daughters = particle->getDaughters();
145
146 for (int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
147 double photosFlag = particleMCPhotosParticle(daughters[iDaughter]);
148 int PDGcode = daughters[iDaughter]->getPDGCode();
149
150 // Is it a real photon?
151 if (PDGcode == Const::photon.getPDGCode() && photosFlag > -0.5 && photosFlag < 0.5) { // must not be from PHOTOS
152 Status = 1.0;
153 }
154 }
155
156 return Status;
157 }
158
159 VARIABLE_GROUP("DirectDaughterInfo");
160 REGISTER_VARIABLE("hasCharmedDaughter(i)", hasCharmedDaughter,
161 "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"
162 "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"
163 "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.");
164 REGISTER_VARIABLE("hasCharmoniumDaughter", hasCharmoniumDaughter,
165 "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"
166 "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.");
167 REGISTER_VARIABLE("hasRealPhotonDaughter", hasRealPhotonDaughter,
168 "Returns 1 if on MC truth level there is at least one real photon daughter, a photon that was not created by photos.\n"
169 "Returns 0 if no real photon daughter found and NaN if the particle has no daughters.");
170 }
172}
static const double doubleNaN
quiet_NaN
Definition: Const.h:703
static const ParticleType photon
photon particle
Definition: Const.h:673
Abstract base class for different kinds of events.
STL namespace.