Belle II Software development
ParticleExtractorFromROEModule.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 include
10#include <analysis/modules/ParticleExtractorFromROE/ParticleExtractorFromROEModule.h>
11
12// framework
13#include <framework/logging/Logger.h>
14#include <framework/datastore/StoreArray.h>
15
16// analysis
17#include <analysis/dataobjects/Particle.h>
18#include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
19#include <analysis/DecayDescriptor/ParticleListName.h>
20
21using namespace Belle2;
22
23//-----------------------------------------------------------------
24// Register module
25//-----------------------------------------------------------------
26
27REG_MODULE(ParticleExtractorFromROE);
28
29//-----------------------------------------------------------------
30// Implementation
31//-----------------------------------------------------------------
32
34{
35 // set module description (e.g. insert text)
36 setDescription("Extract Particles that belong to the ROE and fill them into ParticleLists.");
38
39 // Add parameters
40 std::vector<std::string> defaultList;
41 addParam("outputListNames", m_outputListNames,
42 "list of ParticleList names to be created", defaultList);
43 addParam("signalSideParticleListName", m_signalSideParticleListName,
44 "Name of signal side ParticleList. It is required if the function is called in the main path.", std::string(""));
45 addParam("maskName", m_maskName,
46 "List of all mask names for which the info will be printed.",
48
49 addParam("writeOut", m_writeOut,
50 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
51
52}
53
55{
57
59
60 const int nLists = m_outputListNames.size();
61 m_pdgCodes.resize(nLists);
62 m_absPdgCodes.resize(nLists);
63 m_outputAntiListNames.resize(nLists);
64 m_pLists.resize(nLists);
65 m_antiPLists.resize(nLists);
66
67 for (int iList = 0; iList < nLists; iList++) {
68
69 const auto listName = m_outputListNames[iList];
70
72 if (not dd.init(listName))
73 B2ERROR("Invalid PariticleList name: " << listName);
74
75 const DecayDescriptorParticle* mother = dd.getMother();
76
77 const std::string antiListName = ParticleListName::antiParticleListName(listName);
78 m_outputAntiListNames[iList] = antiListName;
79
80 const int pdgCode = mother->getPDGCode();
81 m_pdgCodes[iList] = pdgCode;
82 m_absPdgCodes[iList] = abs(pdgCode);
83
84 StoreObjPtr<ParticleList> particleList(listName);
85 m_pLists[iList] = particleList;
86
87 particleList.registerInDataStore(listName, flags);
88 if (listName != antiListName) {
89 StoreObjPtr<ParticleList> antiParticleList(antiListName);
90 antiParticleList.registerInDataStore(antiListName, flags);
91
92 m_antiPLists[iList] = antiParticleList;
93 }
94 }
95
96 if (not m_signalSideParticleListName.empty())
98
99}
100
101
103{
104 for (size_t iList = 0; iList < m_outputListNames.size(); iList++) {
105
106 const std::string listName = m_outputListNames[iList];
107 const std::string antiListName = m_outputAntiListNames[iList];
108 const int pdgCode = m_pdgCodes[iList];
109
110 m_pLists[iList].create();
111 m_pLists[iList]->initialize(pdgCode, listName);
112 if (listName != antiListName) {
113
114 m_antiPLists[iList].create();
115 m_antiPLists[iList]->initialize(-1 * pdgCode, antiListName);
116
117 m_pLists[iList]->bindAntiParticleList(*(m_antiPLists[iList]));
118 }
119 }
120
121
122 StoreObjPtr<RestOfEvent> roe("RestOfEvent");
123 if (roe.isValid()) {
124 const RestOfEvent* roe_tmp = &(*roe);
126 } else {
127
128 if (m_signalSideParticleListName.empty()) {
129 B2ERROR("RestOfEvent object is not valid and signalSideListName is not provided");
130 return;
131 }
132
134 const int nSignalSideCandidates = signaSideParticleList->getListSize();
135
136 if (nSignalSideCandidates > 1) {
137 B2ERROR("Signal side ParticleList has more than one candidate. There must be only one candidate.");
138 return;
139 } else if (nSignalSideCandidates == 0) {
140 return;
141 }
142
143 const Particle* particle = signaSideParticleList->getParticle(0);
144 const RestOfEvent* roe_from_particle = particle->getRelatedTo<RestOfEvent>();
145 extractParticlesFromROE(roe_from_particle);
146 }
147
148}
149
151{
152 auto particlesInROE = roe->getParticles(m_maskName, /* unpackComposite */ true);
153
154 for (auto part : particlesInROE) {
155 const int absPdg = abs(part->getPDGCode());
156
157 auto result = std::find(m_absPdgCodes.begin(), m_absPdgCodes.end(), absPdg);
158 if (result == m_absPdgCodes.end())
159 continue;
160
161 const int indexList = std::distance(m_absPdgCodes.begin(), result);
162 m_pLists[indexList]->addParticle(part);
163 }
164}
EStoreFlags
Flags describing behaviours of objects etc.
Definition: DataStore.h:69
@ c_WriteOut
Object/array should be saved by output modules.
Definition: DataStore.h:70
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Definition: DataStore.h:71
Represents a particle in the DecayDescriptor.
int getPDGCode() const
Return PDG code.
The DecayDescriptor stores information about a decay tree or parts of a decay tree.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
std::string m_signalSideParticleListName
output ParticleList names
std::vector< std::string > m_outputListNames
output ParticleList names
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
void extractParticlesFromROE(const RestOfEvent *roe)
Extract particles that belong to the given ROE and fill them in the output ParticleLists.
std::string m_maskName
mask name to be applied
std::vector< StoreObjPtr< ParticleList > > m_pLists
output ParticleList names
std::vector< StoreObjPtr< ParticleList > > m_antiPLists
output anti-ParticleList names
std::vector< int > m_pdgCodes
pdg codes of output ParticleList
std::vector< std::string > m_outputAntiListNames
output anti-ParticleList names
bool m_writeOut
toggle output particle list btw.
std::vector< int > m_absPdgCodes
pdg codes of output ParticleList
Class to store reconstructed particles.
Definition: Particle.h:75
This is a general purpose class for collecting reconstructed MDST data objects that are not used in r...
Definition: RestOfEvent.h:57
std::vector< const Particle * > getParticles(const std::string &maskName=c_defaultMaskName, bool unpackComposite=true) const
Get all Particles from ROE mask.
Definition: RestOfEvent.cc:45
static constexpr const char * c_defaultMaskName
Default mask name.
Definition: RestOfEvent.h:60
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
bool registerInDataStore(DataStore::EStoreFlags storeFlags=DataStore::c_WriteOut)
Register the object/array in the DataStore.
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:111
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.