10#include <analysis/modules/ParticleListManipulator/ParticleListManipulatorModule.h>
14#include <framework/datastore/DataStore.h>
17#include <framework/logging/Logger.h>
20#include <analysis/DecayDescriptor/ParticleListName.h>
21#include <analysis/utility/ValueIndexPairSorting.h>
40 setDescription(
"Manipulates ParticleLists: copies/merges/performs particle selection");
46 vector<string> defaultList;
48 "list of input ParticleList names", defaultList);
52 addParam(
"variable",
m_variableName,
"Variable which defines the best duplicate (see ``selectLowest`` for ordering)",
53 std::string(
"mdstIndex"));
55 "If true, duplicate with lowest value of ``variable`` is accepted, otherwise higher one.",
true);
58 "If true, the output ParticleList will be saved by RootOutput. If false, it will be ignored when writing the file.",
false);
61 "If true, the flavor of the mother particle is ignored.",
false);
77 B2ERROR(
"ParticleListManipulatorModule::initialize Invalid output ParticleList name: " <<
m_outputListName);
87 string listLabel = mother->
getLabel();
91 " but the label 'all' is forbidden for user-defined lists of final-state particles." <<
92 " It could introduce *very* dangerous bugs.");
93 }
else if (listLabel ==
"V0" and
98 " but the label " << listLabel <<
" is not allowed for merged or copied particle lists.");
101 if (listLabel ==
"V0" and
111 B2ERROR(
"ParticleListManipulatorModule: cannot copy Particles from " << listName <<
112 " to itself! Use applyCuts() (ParticleSelector module) instead.");
114 B2ERROR(
"Invalid input ParticleList name: " << listName);
128 B2ERROR(
"Variable '" <<
m_variableName <<
"' is not available in Variable::Manager!");
132 B2ERROR(
"Variable '" <<
m_variableName <<
"' has wrong data type! It must be either double or integer.");
162 std::vector<int> idSeq;
172 typedef std::pair<double, unsigned int> ValueIndexPair;
173 std::vector<ValueIndexPair> valueToIndex;
178 if (!inPList.
isValid())
continue;
180 std::vector<int> fsParticles = inPList->getList(ParticleList::EParticleType::c_FlavorSpecificParticle,
false);
181 const std::vector<int>& scParticles = inPList->getList(ParticleList::EParticleType::c_SelfConjugatedParticle,
false);
182 const std::vector<int>& fsAntiParticles = inPList->getList(ParticleList::EParticleType::c_FlavorSpecificParticle,
true);
184 fsParticles.insert(fsParticles.end(), scParticles.begin(), scParticles.end());
185 fsParticles.insert(fsParticles.end(), fsAntiParticles.begin(), fsAntiParticles.end());
187 for (
int fsParticle : fsParticles) {
190 if (
m_cut->check(part)) {
191 double value = std::numeric_limits<double>::quiet_NaN();;
205 std::stable_sort(valueToIndex.begin(), valueToIndex.end(), ValueIndexPairSorting::lowerPair<ValueIndexPair>);
207 std::stable_sort(valueToIndex.begin(), valueToIndex.end(), ValueIndexPairSorting::higherPair<ValueIndexPair>);
211 for (
const auto& candidate : valueToIndex) {
214 std::vector<int> idSeq;
231 if (ignoreMotherFlavor) idSequence.push_back(abs(p->getPDGCode()));
232 else idSequence.push_back(p->getPDGCode());
234 if (p->getNDaughters() == 0) {
235 idSequence.push_back(p->getParticleSource());
236 idSequence.push_back(p->getMdstArrayIndex());
238 idSequence.push_back(p->getNDaughters());
239 auto daughters = p->getDaughters();
241 sort(daughters.begin(), daughters.end(), [](
const auto a,
const auto b) {
242 return a->getPDGCode() > b->getPDGCode();
245 for (
const auto& daughter : daughters)
253 bool sameSeq = (idSeqIN == idSeqOUT);
The ParticleType class for identifying different particle types.
static const ParticleSet finalStateParticlesSet
set of final set particles that can be created by the ParticleLoader
EStoreFlags
Flags describing behaviours of objects etc.
@ c_WriteOut
Object/array should be saved by output modules.
@ c_DontWriteOut
Object/array should be NOT saved by output modules.
Represents a particle in the DecayDescriptor.
int getPDGCode() const
Return PDG code.
std::string getLabel() const
The label of this particle, "default" returned, when no label set.
bool init(const std::string &str)
Initialise the DecayDescriptor from given string.
const DecayDescriptorParticle * getMother() const
return mother.
static std::unique_ptr< GeneralCut > compile(const std::string &cut)
Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead y...
void setDescription(const std::string &description)
Sets the description of the module.
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
bool m_isSelfConjugatedParticle
flag that indicates whether an anti-particle does not exist and therefore the output anti-ParticleLis...
ParticleListManipulatorModule()
Constructor.
bool m_preferLowest
Select the duplicate with the lowest value (instead of highest).
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
std::string m_variableName
Variable which defines the best duplicate.
std::vector< std::string > m_inputListNames
input ParticleList names
StoreArray< Particle > m_particles
StoreArray of Particles.
std::vector< std::vector< int > > m_particlesInTheList
This vector holds unique identifiers (vector of ints) of all particles that are already included in t...
std::unique_ptr< Variable::Cut > m_cut
cut object which performs the cuts
bool m_ignoreMotherFlavor
flag whether flavor of mother particle should be ignored
bool isUnique(const std::vector< int > &idSequence)
Compares input idSequence to all sequences already included in the list.
const Variable::Manager::Var * m_variable
Variable which defines the best duplicate selection.
void fillUniqueIdentifier(const Particle *p, std::vector< int > &idSequence, bool ignoreMotherFlavor)
Fills unique identifier for the input particle.
std::string m_cutParameter
selection criteria
DecayDescriptor m_decaydescriptor
Decay descriptor of the particle being selected.
bool m_exceptionForV0B2BII
true if the output List is V0 and input is K_S0:mdst, Lambda0:mdst, or gamma:v0mdst
bool m_writeOut
toggle Particle List btw.
int m_pdgCode
PDG code of the particles.
StoreObjPtr< ParticleList > m_particleList
output particle list
std::string m_outputAntiListName
output anti-particle list name
StoreObjPtr< ParticleList > m_antiParticleList
output anti-particle list
std::string m_outputListName
output ParticleList name
Class to store reconstructed particles.
int getArrayIndex() const
Returns this object's array index (in StoreArray), or -1 if not found.
bool isRequired(const std::string &name="")
Ensure this array/object has been registered previously.
Type-safe access to single objects in the data store.
bool isValid() const
Check whether the object was created.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
static Manager & Instance()
get singleton instance.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
std::string antiParticleListName(const std::string &listName)
Returns name of anti-particle-list corresponding to listName.
Abstract base class for different kinds of events.
VariableDataType variabletype
data type of variable
FunctionPtr function
Pointer to function.