Belle II Software development
DuplicateVertexMarkerModule.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//Identify duplicate vertices (distinct particles, but built from the same daughters).
9//Only works if the particle has exactly two daughters. Mainly used to deal when merging V0 vertices with hand-built ones.
10
11//Functionality is designed to be expanded as needed.
12
13#include <analysis/modules/DuplicateVertexMarker/DuplicateVertexMarkerModule.h>
14
15#include <analysis/dataobjects/Particle.h>
16#include <analysis/variables/BasicParticleInformation.h>
17
18#include <framework/logging/Logger.h>
19
20using namespace std;
21using namespace Belle2;
22
23
24//-----------------------------------------------------------------
25// Register module
26//-----------------------------------------------------------------
27
28REG_MODULE(DuplicateVertexMarker);
29
31{
32 setDescription("Identify duplicate vertices (distinct particles, but built from the same daughters) and mark the one with best chi2. Only works if the particle has exactly two daughters. Mainly used to deal when merging V0 vertices with hand-built ones.");
34
35 // Add parameters
36 addParam("particleList", m_particleList, "Input ParticleList name");
37 addParam("extraInfoName", m_extraInfoName,
38 "Extra-info field added to all particles in the input list. 1 for the best vertex, 0 for lower ranked ones.",
39 string("highQualityVertex"));
40 addParam("prioritiseV0", m_prioritiseV0,
41 "If a vertex is a V0, select it over its duplicate even if chi2 is worse.",
42 true);
43}
44
46{
47 m_inPList.isRequired(m_particleList);
48}
49
51{
52 const int size = m_inPList->getListSize();
53 for (int i = 0; i < size; i++) {
54 Particle* part = m_inPList->getParticle(i);
55 if (part->getNDaughters() != 2) { //ignore 3+ vertices
56 B2WARNING("Vertex does not have exactly 2 daughters! SKIP.");
57 continue;
58 }
59 if (part->hasExtraInfo(
60 m_extraInfoName)) { //if it already has info, it means it's already been discarded (or it won, but that shouldn't be possible here)
61 B2DEBUG(10, "Extra Info with given name is already set!");
62 continue;
63 }
64 for (int j = 0; j < size; j++) {//look for a clone among other particles in the event
65 Particle* cloneCand = m_inPList->getParticle(j);
66 bool particleFight = false;
67 if (cloneCand->getNDaughters() == 2) { //check if it's another 2-vertex with the same exact daughters
68 if (part == cloneCand) continue; //but not itself
69 if (cloneCand->hasExtraInfo(m_extraInfoName)) continue; //nor an already discarded one
70 B2DEBUG(10, "part has daughters (" << part->getDaughter(0)->getTrack() << ") and (" << part->getDaughter(1)->getTrack() << ")");
71 B2DEBUG(10, "cloneCand has daughters (" << cloneCand->getDaughter(0)->getTrack() << ") and (" << cloneCand->getDaughter(
72 1)->getTrack() << ")");
73 if (part->getDaughter(0)->getTrack() == cloneCand->getDaughter(0)->getTrack() &&
74 part->getDaughter(1)->getTrack() == cloneCand->getDaughter(1)->getTrack()) {
75 particleFight = true;
76 } else if (part->getDaughter(0)->getTrack() == cloneCand->getDaughter(1)->getTrack() &&
77 part->getDaughter(1)->getTrack() == cloneCand->getDaughter(0)->getTrack()) {
78 particleFight = true;
79 }
80 }
81 if (particleFight) { //fight; whoever loses gets a low quality flag
82 if (m_prioritiseV0) { //V0 have no dmID info (might not be the optimal way to tell them apart)
83 bool partNotV0 = part->hasExtraInfo("decayModeID");
84 bool cloneNotV0 = cloneCand->hasExtraInfo("decayModeID");
85 if (partNotV0 != cloneNotV0) { //one of them is V0 and the other not
86 (partNotV0) ? (part->addExtraInfo(m_extraInfoName, 0.0)) : (cloneCand->addExtraInfo(m_extraInfoName, 0.0));
87 if (partNotV0) {
88 B2DEBUG(10, "V0: Discarding Particle.");
89 } else B2DEBUG(10, "V0: Discarding Clone");
90 }
91 }
92 if (!(part->hasExtraInfo(m_extraInfoName) || cloneCand->hasExtraInfo(m_extraInfoName))) {
93 //if V0s aren't being checked, or have been checked but inconclusive (should not happen) check best fit
94 if (Variable::particlePvalue(part) > Variable::particlePvalue(cloneCand)) {
95 cloneCand->addExtraInfo(m_extraInfoName, 0.0);
96 } else {
97 part->addExtraInfo(m_extraInfoName, 0.0);
98 continue; //The particle lost, and its clone will be picked up next in the for(i) loop.
99 }
100 }
101 }
102 }
103 if (!(part->hasExtraInfo(m_extraInfoName))) { //if it got there without a flag, there are no rival particles anymore;
104 part->addExtraInfo(m_extraInfoName, 1.0);//this is the best
105 continue; //no point in continuing the i-loop
106 }
107 }
108}
virtual void initialize() override
Initialize the Module.
virtual void event() override
Event processor.
StoreObjPtr< ParticleList > m_inPList
input particle list
bool m_prioritiseV0
if one of the decay is a V0, prioritise that before checking vertex quality
std::string m_particleList
input ParticleList name
std::string m_extraInfoName
output extra-info name
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
Class to store reconstructed particles.
Definition: Particle.h:75
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
Definition: Particle.cc:845
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1266
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:727
void addExtraInfo(const std::string &name, double value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1336
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:631
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
Abstract base class for different kinds of events.
STL namespace.