Belle II Software  release-06-01-15
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 
19 using namespace std;
20 using namespace Belle2;
21 
22 
23 //-----------------------------------------------------------------
24 // Register module
25 //-----------------------------------------------------------------
26 
27 REG_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.");
32  setPropertyFlags(c_ParallelProcessingCertified);
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 
44 void DuplicateVertexMarkerModule::initialize()
45 {
46  m_inPList.isRequired(m_particleList);
47 
48  Variable::Manager& manager = Variable::Manager::Instance();
49  m_targetVar = manager.getVariable("chiProb");
50  if (m_targetVar == nullptr) {
51  B2ERROR("DuplicateVertexMarker: Variable::Manager doesn't have variable chiProb");
52  }
53 }
54 
55 void DuplicateVertexMarkerModule::event()
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, m_targetVar->function(part) << " vs " << m_targetVar->function(cloneCand));
100  if (m_targetVar->function(part) > 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 }
Identify duplicate vertices (distinct particles, but built from the same daughters) and mark the one ...
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
Definition: Particle.cc:814
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
Definition: Particle.cc:1219
void addExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1289
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:647
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:639
Global list of available variables.
Definition: Manager.h:98
#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.