Belle II Software light-2406-ragdoll
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
17#include <framework/logging/Logger.h>
18
19using namespace std;
20using namespace Belle2;
21
22
23//-----------------------------------------------------------------
24// Register module
25//-----------------------------------------------------------------
26
27REG_MODULE(DuplicateVertexMarker);
28
30{
31 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.");
33
34 // Add parameters
35 addParam("particleList", m_particleList, "Input ParticleList name");
36 addParam("extraInfoName", m_extraInfoName,
37 "Extra-info field added to all particles in the input list. 1 for the best vertex, 0 for lower ranked ones.",
38 string("highQualityVertex"));
39 addParam("prioritiseV0", m_prioritiseV0,
40 "If a vertex is a V0, select it over its duplicate even if chi2 is worse.",
41 true);
42}
43
45{
46 m_inPList.isRequired(m_particleList);
47
49 m_targetVar = manager.getVariable("chiProb");
50 if (m_targetVar == nullptr) {
51 B2ERROR("DuplicateVertexMarker: Variable::Manager doesn't have variable chiProb");
52 }
53}
54
56{
57 const int size = m_inPList->getListSize();
58 for (int i = 0; i < size; i++) {
59 Particle* part = m_inPList->getParticle(i);
60 if (part->getNDaughters() != 2) { //ignore 3+ vertices
61 B2WARNING("Vertex does not have exactly 2 daughters! SKIP.");
62 continue;
63 }
64 if (part->hasExtraInfo(
65 m_extraInfoName)) { //if it already has info, it means it's already been discarded (or it won, but that shouldn't be possible here)
66 B2DEBUG(10, "Extra Info with given name is already set!");
67 continue;
68 }
69 for (int j = 0; j < size; j++) {//look for a clone among other particles in the event
70 Particle* cloneCand = m_inPList->getParticle(j);
71 bool particleFight = false;
72 if (cloneCand->getNDaughters() == 2) { //check if it's another 2-vertex with the same exact daughters
73 if (part == cloneCand) continue; //but not itself
74 if (cloneCand->hasExtraInfo(m_extraInfoName)) continue; //nor an already discarded one
75 B2DEBUG(10, "part has daughters (" << part->getDaughter(0)->getTrack() << ") and (" << part->getDaughter(1)->getTrack() << ")");
76 B2DEBUG(10, "cloneCand has daughters (" << cloneCand->getDaughter(0)->getTrack() << ") and (" << cloneCand->getDaughter(
77 1)->getTrack() << ")");
78 if (part->getDaughter(0)->getTrack() == cloneCand->getDaughter(0)->getTrack() &&
79 part->getDaughter(1)->getTrack() == cloneCand->getDaughter(1)->getTrack()) {
80 particleFight = true;
81 } else if (part->getDaughter(0)->getTrack() == cloneCand->getDaughter(1)->getTrack() &&
82 part->getDaughter(1)->getTrack() == cloneCand->getDaughter(0)->getTrack()) {
83 particleFight = true;
84 }
85 }
86 if (particleFight) { //fight; whoever loses gets a low quality flag
87 if (m_prioritiseV0) { //V0 have no dmID info (might not be the optimal way to tell them apart)
88 bool partNotV0 = part->hasExtraInfo("decayModeID");
89 bool cloneNotV0 = cloneCand->hasExtraInfo("decayModeID");
90 if (partNotV0 != cloneNotV0) { //one of them is V0 and the other not
91 (partNotV0) ? (part->addExtraInfo(m_extraInfoName, 0.0)) : (cloneCand->addExtraInfo(m_extraInfoName, 0.0));
92 if (partNotV0) {
93 B2DEBUG(10, "V0: Discarding Particle.");
94 } else B2DEBUG(10, "V0: Discarding Clone");
95 }
96 }
97 if (!(part->hasExtraInfo(m_extraInfoName) || cloneCand->hasExtraInfo(m_extraInfoName))) {
98 //if V0s aren't being checked, or have been checked but inconclusive (should not happen) check best fit
99 B2DEBUG(10, std::get<double>(m_targetVar->function(part)) << " vs " << std::get<double>(m_targetVar->function(cloneCand)));
100 if (std::get<double>(m_targetVar->function(part)) > std::get<double>(m_targetVar->function(cloneCand))) {
101 cloneCand->addExtraInfo(m_extraInfoName, 0.0);
102 } else {
103 part->addExtraInfo(m_extraInfoName, 0.0);
104 continue; //The particle lost, and its clone will be picked up next in the for(i) loop.
105 }
106 }
107 }
108 }
109 if (!(part->hasExtraInfo(m_extraInfoName))) { //if it got there without a flag, there are no rival particles anymore;
110 part->addExtraInfo(m_extraInfoName, 1.0);//this is the best
111 continue; //no point in continuing the i-loop
112 }
113 }
114}
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
const Variable::Manager::Var * m_targetVar
Pointer to target variable stored in the variable manager.
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
Global list of available variables.
Definition: Manager.h:101
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
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.
Definition: ClusterUtils.h:24
STL namespace.
FunctionPtr function
Pointer to function.
Definition: Manager.h:147