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/DecayDescriptor.h>
19#include <analysis/DecayDescriptor/DecayDescriptorParticle.h>
20#include <analysis/DecayDescriptor/ParticleListName.h>
21
22using namespace Belle2;
23
24//-----------------------------------------------------------------
25// Register module
26//-----------------------------------------------------------------
27
28REG_MODULE(ParticleExtractorFromROE);
29
30//-----------------------------------------------------------------
31// Implementation
32//-----------------------------------------------------------------
33
35{
36 // set module description (e.g. insert text)
37 setDescription("Extract Particles that belong to the ROE and fill them into ParticleLists.");
39
40 // Add parameters
41 std::vector<std::string> defaultList;
42 addParam("outputListNames", m_outputListNames,
43 "list of ParticleList names to be created", defaultList);
44 addParam("signalSideParticleListName", m_signalSideParticleListName,
45 "Name of signal side ParticleList. It is required if the function is called in the main path.", std::string(""));
46 addParam("maskName", m_maskName,
47 "List of all mask names for which the info will be printed.",
49
50 addParam("writeOut", m_writeOut,
51 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.", false);
52
53}
54
56{
58
60
61 const int nLists = m_outputListNames.size();
62 m_pdgCodes.resize(nLists);
63 m_absPdgCodes.resize(nLists);
64 m_outputAntiListNames.resize(nLists);
65 m_pLists.resize(nLists);
66 m_antiPLists.resize(nLists);
67
68 for (int iList = 0; iList < nLists; iList++) {
69
70 const auto listName = m_outputListNames[iList];
71
73 if (not dd.init(listName))
74 B2ERROR("Invalid PariticleList name: " << listName);
75
76 const DecayDescriptorParticle* mother = dd.getMother();
77
78 const std::string antiListName = ParticleListName::antiParticleListName(listName);
79 m_outputAntiListNames[iList] = antiListName;
80
81 const int pdgCode = mother->getPDGCode();
82 m_pdgCodes[iList] = pdgCode;
83 m_absPdgCodes[iList] = abs(pdgCode);
84
85 StoreObjPtr<ParticleList> particleList(listName);
86 m_pLists[iList] = particleList;
87
88 particleList.registerInDataStore(listName, flags);
89 if (listName != antiListName) {
90 StoreObjPtr<ParticleList> antiParticleList(antiListName);
91 antiParticleList.registerInDataStore(antiListName, flags);
92
93 m_antiPLists[iList] = antiParticleList;
94 }
95 }
96
97 if (not m_signalSideParticleListName.empty())
99
100}
101
102
104{
105 for (size_t iList = 0; iList < m_outputListNames.size(); iList++) {
106
107 const std::string listName = m_outputListNames[iList];
108 const std::string antiListName = m_outputAntiListNames[iList];
109 const int pdgCode = m_pdgCodes[iList];
110
111 m_pLists[iList].create();
112 m_pLists[iList]->initialize(pdgCode, listName);
113 if (listName != antiListName) {
114
115 m_antiPLists[iList].create();
116 m_antiPLists[iList]->initialize(-1 * pdgCode, antiListName);
117
118 m_pLists[iList]->bindAntiParticleList(*(m_antiPLists[iList]));
119 }
120 }
121
122
123 StoreObjPtr<RestOfEvent> roe("RestOfEvent");
124 if (roe.isValid()) {
125 const RestOfEvent* roe_tmp = &(*roe);
127 } else {
128
129 if (m_signalSideParticleListName.empty()) {
130 B2ERROR("RestOfEvent object is not valid and signalSideListName is not provided");
131 return;
132 }
133
135 const int nSignalSideCandidates = signaSideParticleList->getListSize();
136
137 if (nSignalSideCandidates > 1) {
138 B2ERROR("Signal side ParticleList has more than one candidate. There must be only one candidate.");
139 return;
140 } else if (nSignalSideCandidates == 0) {
141 return;
142 }
143
144 const Particle* particle = signaSideParticleList->getParticle(0);
145 const RestOfEvent* roe_from_particle = particle->getRelatedTo<RestOfEvent>();
146 extractParticlesFromROE(roe_from_particle);
147 }
148
149}
150
152{
153 auto particlesInROE = roe->getParticles(m_maskName, /* unpackComposite */ true);
154
155 for (auto part : particlesInROE) {
156 const int absPdg = abs(part->getPDGCode());
157
158 auto result = std::find(m_absPdgCodes.begin(), m_absPdgCodes.end(), absPdg);
159 if (result == m_absPdgCodes.end())
160 continue;
161
162 const int indexList = std::distance(m_absPdgCodes.begin(), result);
163 m_pLists[indexList]->addParticle(part);
164 }
165}
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:76
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:40
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:95
bool isValid() const
Check whether the object was created.
Definition: StoreObjPtr.h:110
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:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.