9 #include <analysis/dataobjects/RestOfEvent.h>
11 #include <framework/datastore/StoreArray.h>
13 #include <analysis/dataobjects/Particle.h>
14 #include <mdst/dataobjects/MCParticle.h>
15 #include <mdst/dataobjects/Track.h>
16 #include <mdst/dataobjects/ECLCluster.h>
17 #include <mdst/dataobjects/KLMCluster.h>
19 #include <analysis/ClusterUtility/ClusterUtils.h>
21 #include <TLorentzVector.h>
28 for (
auto* particleToAdd : particlesToAdd) {
29 std::vector<const Particle*> daughters = particleToAdd->getFinalStateDaughters();
30 for (
auto* daughter : daughters) {
33 if (allParticles[myIndex]->isCopyOf(daughter,
true)) {
39 B2DEBUG(10,
"\t\tAdding particle with PDG " << daughter->getPDGCode());
48 std::vector<const Particle*> result;
52 B2DEBUG(10,
"ROE contains no particles, masks are empty too");
59 bool maskFound =
false;
61 if (mask.getName() == maskName) {
63 source = mask.getParticles();
68 B2FATAL(
"No " << maskName <<
" mask defined in current ROE!");
71 for (
const int index : source) {
72 if ((allParticles[index]->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
73 allParticles[index]->getParticleSource() == Particle::EParticleSourceObject::c_V0) && unpackComposite) {
74 auto fsdaughters = allParticles[index]->getFinalStateDaughters();
75 for (
auto* daughter : fsdaughters) {
76 result.push_back(daughter);
80 result.push_back(allParticles[index]);
87 auto particles =
getParticles(maskName, unpackComposite);
88 std::vector<const Particle*> photons;
89 for (
auto* particle : particles) {
90 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster) {
91 photons.push_back(particle);
99 auto particles =
getParticles(maskName, unpackComposite);
100 std::vector<const Particle*> hadrons;
101 for (
auto* particle : particles) {
102 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_KLMCluster) {
103 hadrons.push_back(particle);
110 bool unpackComposite)
const
112 auto particles =
getParticles(maskName, unpackComposite);
113 std::vector<const Particle*> charged;
114 for (
auto* particle : particles) {
115 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Track) {
116 if (pdg == 0 || pdg == abs(particle->getPDGCode())) {
117 charged.push_back(particle);
127 if (maskName !=
"" && !
hasMask(maskName)) {
128 B2FATAL(
"No " << maskName <<
" mask defined in current ROE!");
131 std::vector<const Particle*> particlesROE =
getParticles(maskName);
138 B2FATAL(
"Creation of ROE Mask with an empty name is not allowed!");
141 B2FATAL(
"ROE Mask already exists!");
143 Mask elon(name, origin);
152 B2FATAL(
"No " << maskName <<
" mask defined in current ROE!");
154 std::string maskNameToGetParticles = maskName;
155 if (!mask->isValid()) {
156 maskNameToGetParticles =
"";
158 std::vector<const Particle*> allROEParticles =
getParticles(maskNameToGetParticles);
159 std::vector<const Particle*> toKeepinROE;
160 for (
auto* roeParticle : allROEParticles) {
164 toKeepinROE.push_back(roeParticle);
168 if (listType != roeParticle->getParticleSource()) {
169 toKeepinROE.push_back(roeParticle);
170 }
else if (discard) {
172 toKeepinROE.push_back(roeParticle);
176 mask->clearParticles();
177 mask->addParticles(toKeepinROE);
181 const std::shared_ptr<Variable::Cut>& eclCut,
const std::shared_ptr<Variable::Cut>& klmCut,
bool updateExisting)
185 B2FATAL(
"ROE Mask does not exist!");
187 std::string sourceName =
"";
188 if (updateExisting) {
190 sourceName = maskName;
193 std::vector<const Particle*> allROEParticles =
getParticles(sourceName,
false);
194 std::vector<const Particle*> maskedParticles;
196 for (
auto* particle : allROEParticles) {
197 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Track && (!trackCut || trackCut->check(particle))) {
198 maskedParticles.push_back(particle);
200 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_ECLCluster && (!eclCut || eclCut->check(particle))) {
201 maskedParticles.push_back(particle);
203 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_KLMCluster && (!klmCut || klmCut->check(particle))) {
204 maskedParticles.push_back(particle);
207 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_Composite or
208 particle->getParticleSource() == Particle::EParticleSourceObject::c_V0) {
209 maskedParticles.push_back(particle);
212 mask->clearParticles();
213 mask->addParticles(maskedParticles);
220 B2FATAL(
"ROE Mask does not exist!");
222 std::vector<const Particle*> allROEParticles =
getParticles(name,
false);
223 std::vector<int> indicesToErase;
225 for (
auto* maskParticle : allROEParticles) {
227 for (
auto* daughterV0 : daughtersV0) {
228 if (daughterV0->isCopyOf(maskParticle,
true)) {
233 indicesToErase.push_back(maskParticle->getArrayIndex());
236 if (daughtersV0.size() != indicesToErase.size()) {
237 B2DEBUG(10,
"Only " << indicesToErase.size() <<
" daughters are excluded from mask particles. Abort");
240 std::string toprint =
"We will erase next indices from " + name +
" mask: ";
241 for (
auto& i : indicesToErase) {
242 toprint += std::to_string(i) +
" ";
244 B2DEBUG(10, toprint);
246 mask->addV0(particleV0, indicesToErase);
253 B2FATAL(
"ROE Mask does not exist!");
255 if (!mask->isValid()) {
258 if (particleV0->
getParticleSource() != Particle::EParticleSourceObject::c_Composite and
263 for (
auto* daughter : daughtersV0) {
264 if (daughter->getParticleSource() != Particle::EParticleSourceObject::c_Track) {
268 if (mask->hasV0(particleV0)) {
277 if (mask.getName() == name) {
285 TLorentzVector roe4Vector;
287 for (
const Particle* particle : myParticles) {
290 if (particle->getParticleSource() == Particle::EParticleSourceObject::c_KLMCluster and !
m_useKLMEnergy) {
293 roe4Vector += particle->get4Vector();
302 if (mask.getName() == name) {
318 int nROEneutralECLClusters =
getPhotons(maskName).size();
319 int nROEchargedECLClusters = 0;
321 if (roeParticle->getECLCluster()) ++nROEchargedECLClusters;
324 return nROEneutralECLClusters + nROEchargedECLClusters;
329 int nROEKLMClusters =
getHadrons(maskName).size();
330 return nROEKLMClusters;
336 TLorentzVector roe4VectorECLClusters;
339 for (
auto& roeCluster : roeClusters) {
341 roe4VectorECLClusters += roeCluster->get4Vector();
344 return roe4VectorECLClusters;
349 for (
auto* listParticle : particlesToUpdate) {
350 if (roeParticle->
isCopyOf(listParticle,
true)) {
359 std::vector<std::string> maskNames;
362 maskNames.push_back(mask.getName());
370 std::string tab =
" - ";
371 if (maskName !=
"") {
374 B2WARNING(
"No mask with the name '" << maskName <<
"' exists in this ROE! Nothing else to print");
380 B2INFO(tab <<
"ROE is nested");
383 B2INFO(tab <<
"ROE is build from generated particles");
387 B2WARNING(
"This ROE has KLM energy included into its 4-vector!");
391 unsigned int nPhotons =
getPhotons(maskName, unpackComposite).size();
392 unsigned int nNeutralHadrons =
getHadrons(maskName, unpackComposite).size();
393 B2INFO(tab <<
"No. of Charged particles in ROE: " << nCharged);
394 B2INFO(tab <<
"No. of Photons in ROE: " << nPhotons);
395 B2INFO(tab <<
"No. of K_L0 and neutrons in ROE: " << nNeutralHadrons);
397 unsigned int nParticles =
getParticles(maskName, unpackComposite).size();
398 B2INFO(tab <<
"No. of generated particles in ROE: " << nParticles);
405 auto particles =
getParticles(maskName, unpackComposite);
406 if (particles.size() == 0) {
407 B2INFO(tab <<
"No indices to print");
410 std::string printoutIndex = tab +
"|";
411 std::string printoutPDG = tab +
"|";
412 for (
const auto particle : particles) {
413 printoutIndex += std::to_string(particle->getArrayIndex()) +
" | ";
414 printoutPDG += std::to_string(particle->getPDGCode()) +
" | ";
417 B2INFO(printoutIndex);
423 std::set<int> source;
424 if (maskName ==
"") {
428 bool maskFound =
false;
430 if (mask.getName() == maskName) {
432 source = mask.getParticles();
437 B2FATAL(
"No " << maskName <<
" mask defined in current ROE!");
440 int particlePDG = (pdgCode == 0) ?
getPDGCode() : pdgCode;
441 auto isFlavored = (isSelfConjugated) ? Particle::EFlavorType::c_Unflavored : Particle::EFlavorType::c_Flavored;
442 return particles.appendNew(
get4Vector(maskName), particlePDG, isFlavored, std::vector(source.begin(),
443 source.end()), Particle::PropertyFlags::c_IsUnspecified);
@ c_nPhotons
CR is split into n photons (N1)
Class to store reconstructed particles.
std::vector< const Belle2::Particle * > getFinalStateDaughters() const
Returns a vector of pointers to Final State daughter particles.
EParticleSourceObject
particle source enumerators
bool isCopyOf(const Particle *oParticle, bool doDetailedComparison=false) const
Returns true if this Particle and oParticle are copies of each other.
EParticleSourceObject getParticleSource() const
Returns particle source as defined with enum EParticleSourceObject.
int getPDGCode() const
Gets the PDG code of the rest of event.
std::set< int > m_particleIndices
StoreArray indices to unused particles.
TLorentzVector get4Vector(const std::string &maskName="") const
Get 4-momentum vector all (no mask) or a subset (use mask) of all Tracks and ECLClusters in ROE.
int getNTracks(const std::string &maskName="") const
Get number of all (no mask) or a subset (use mask) of all Tracks in ROE.
void initializeMask(const std::string &name, const std::string &origin="unknown")
Initialize new mask.
bool checkCompatibilityOfMaskAndV0(const std::string &name, const Particle *particleV0)
Check if V0 can be added, maybe should be moved to private.
bool hasParticle(const Particle *particle, const std::string &maskName="") const
Check if ROE has StoreArray index of given to the list of unused tracks in the event.
void updateMaskWithCuts(const std::string &name, const std::shared_ptr< Variable::Cut > &trackCut=nullptr, const std::shared_ptr< Variable::Cut > &eclCut=nullptr, const std::shared_ptr< Variable::Cut > &klmCut=nullptr, bool updateExisting=false)
Update mask with cuts.
void print(const std::string &maskName="", bool unpackComposite=true) const
Prints the contents of a RestOfEvent object to screen.
bool hasMask(const std::string &name) const
True if this ROE object has mask.
bool m_isFromMC
MC ROE indicator.
std::vector< const Particle * > getChargedParticles(const std::string &maskName="", unsigned int pdg=0, bool unpackComposite=true) const
Get charged particles from ROE mask.
int getNECLClusters(const std::string &maskName="") const
Get number of all (no mask) or a subset (use mask) of all ECLclusters in ROE.
std::vector< const Particle * > getHadrons(const std::string &maskName="", bool unpackComposite=true) const
Get hadrons from ROE mask.
std::vector< const Particle * > getParticles(const std::string &maskName="", bool unpackComposite=true) const
Get all Particles from ROE mask.
void printIndices(const std::string &maskName="", bool unpackComposite=true, const std::string &tab=" - ") const
Prints indices in the given set in a single line.
Mask * findMask(const std::string &name)
Helper method to find ROE mask.
void addParticles(const std::vector< const Particle * > &particle)
Add StoreArray indices of given Particles to the list of unused particles in the event.
std::vector< std::string > getMaskNames() const
Get vector of all mask names of the ROE object.
int getNKLMClusters(const std::string &maskName="") const
Get number of all remaining KLM clusters.
void updateMaskWithV0(const std::string &name, const Particle *particleV0)
Update mask with composite particle.
bool m_useKLMEnergy
Include KLM energy into ROE 4-vector.
Particle * convertToParticle(const std::string &maskName="", int pdgCode=0, bool isSelfConjugated=true)
Converts ROE to Particle and adds it to StoreArray.
TLorentzVector get4VectorNeutralECLClusters(const std::string &maskName="") const
Get 4-momentum vector all (no mask) or a subset (use mask) of all ECLClusters in ROE.
std::vector< Mask > m_masks
List of the ROE masks.
void excludeParticlesFromMask(const std::string &maskName, const std::vector< const Particle * > &particles, Particle::EParticleSourceObject listType, bool discard)
Update mask by keeping or excluding particles.
bool isInParticleList(const Particle *roeParticle, const std::vector< const Particle * > &particlesToUpdate) const
Checks if a particle has its copy in the provided list.
bool m_isNested
Nested ROE indicator.
std::vector< const Particle * > getPhotons(const std::string &maskName="", bool unpackComposite=true) const
Get photons from ROE mask.
Accessor to arrays stored in the data store.
Abstract base class for different kinds of events.
Structure of Rest of Event mask.