Belle II Software  release-05-02-19
DuplicateVertexMarkerModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributor: Francesco Tenchini *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 //Identify duplicate vertices (distinct particles, but built from the same daughters).
11 //Only works if the particle has exactly two daughters. Mainly used to deal when merging V0 vertices with hand-built ones.
12 
13 //Functionality is designed to be expanded as needed.
14 
15 #include <analysis/modules/DuplicateVertexMarker/DuplicateVertexMarkerModule.h>
16 
17 #include <analysis/dataobjects/Particle.h>
18 #include <analysis/dataobjects/ParticleList.h>
19 
20 #include <framework/datastore/StoreObjPtr.h>
21 #include <framework/logging/Logger.h>
22 
23 using namespace std;
24 using namespace Belle2;
25 
26 
27 //-----------------------------------------------------------------
28 // Register module
29 //-----------------------------------------------------------------
30 
31 REG_MODULE(DuplicateVertexMarker)
32 
34 {
35  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.");
36  setPropertyFlags(c_ParallelProcessingCertified);
37 
38  // Add parameters
39  addParam("particleList", m_particleList, "Input ParticleList name");
40  addParam("extraInfoName", m_extraInfoName,
41  "Extra-info field added to all particles in the input list. 1 for the best vertex, 0 for lower ranked ones.",
42  string("highQualityVertex"));
43  addParam("prioritiseV0", m_prioritiseV0,
44  "If a vertex is a V0, select it over its duplicate even if chi2 is worse.",
45  true);
46 }
47 
48 void DuplicateVertexMarkerModule::initialize()
49 {
50  StoreObjPtr<ParticleList>().isRequired(m_particleList);
51 
52  Variable::Manager& manager = Variable::Manager::Instance();
53  m_targetVar = manager.getVariable("chiProb");
54  if (m_targetVar == nullptr) {
55  B2ERROR("DuplicateVertexMarker: Variable::Manager doesn't have variable chiProb");
56  }
57 }
58 
59 void DuplicateVertexMarkerModule::event()
60 {
61  const StoreObjPtr<ParticleList> inPList(m_particleList);
62  if (!inPList)
63  return;
64 
65  const int size = inPList->getListSize();
66  for (int i = 0; i < size; i++) {
67  Particle* part = inPList->getParticle(i);
68  if (part->getNDaughters() != 2) { //ignore 3+ vertices
69  B2WARNING("Vertex does not have exactly 2 daughters! SKIP.");
70  continue;
71  }
72  if (part->hasExtraInfo(
73  m_extraInfoName)) { //if it already has info, it means it's already been discarded (or it won, but that shouldn't be possible here)
74  B2DEBUG(10, "Extra Info with given name is already set!");
75  continue;
76  }
77  for (int j = 0; j < size; j++) {//look for a clone among other particles in the event
78  Particle* cloneCand = inPList->getParticle(j);
79  bool particleFight = false;
80  if (cloneCand->getNDaughters() == 2) { //check if it's another 2-vertex with the same exact daughters
81  if (part == cloneCand) continue; //but not itself
82  if (cloneCand->hasExtraInfo(m_extraInfoName)) continue; //nor an already discarded one
83  B2DEBUG(10, "part has daughters (" << part->getDaughter(0)->getTrack() << ") and (" << part->getDaughter(1)->getTrack() << ")");
84  B2DEBUG(10, "cloneCand has daughters (" << cloneCand->getDaughter(0)->getTrack() << ") and (" << cloneCand->getDaughter(
85  1)->getTrack() << ")");
86  if (part->getDaughter(0)->getTrack() == cloneCand->getDaughter(0)->getTrack() &&
87  part->getDaughter(1)->getTrack() == cloneCand->getDaughter(1)->getTrack()) {
88  particleFight = true;
89  } else if (part->getDaughter(0)->getTrack() == cloneCand->getDaughter(1)->getTrack() &&
90  part->getDaughter(1)->getTrack() == cloneCand->getDaughter(0)->getTrack()) {
91  particleFight = true;
92  }
93  }
94  if (particleFight) { //fight; whoever loses gets a low quality flag
95  if (m_prioritiseV0) { //V0 have no dmID info (might not be the optimal way to tell them apart)
96  bool partNotV0 = part->hasExtraInfo("decayModeID");
97  bool cloneNotV0 = cloneCand->hasExtraInfo("decayModeID");
98  if (partNotV0 != cloneNotV0) { //one of them is V0 and the other not
99  (partNotV0) ? (part->addExtraInfo(m_extraInfoName, 0.0)) : (cloneCand->addExtraInfo(m_extraInfoName, 0.0));
100  if (partNotV0) {
101  B2DEBUG(10, "V0: Discarding Particle.");
102  } else B2DEBUG(10, "V0: Discarding Clone");
103  }
104  }
105  if (!(part->hasExtraInfo(m_extraInfoName) || cloneCand->hasExtraInfo(m_extraInfoName))) {
106  //if V0s aren't being checked, or have been checked but inconclusive (should not happen) check best fit
107  B2DEBUG(10, m_targetVar->function(part) << " vs " << m_targetVar->function(cloneCand));
108  if (m_targetVar->function(part) > m_targetVar->function(cloneCand)) {
109  cloneCand->addExtraInfo(m_extraInfoName, 0.0);
110  } else {
111  part->addExtraInfo(m_extraInfoName, 0.0);
112  continue; //The particle lost, and its clone will be picked up next in the for(i) loop.
113  }
114  }
115  }
116  }
117  if (!(part->hasExtraInfo(m_extraInfoName))) { //if it got there without a flag, there are no rival particles anymore;
118  part->addExtraInfo(m_extraInfoName, 1.0);//this is the best
119  continue; //no point in continuing the i-loop
120  }
121  }
122 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::Particle::addExtraInfo
void addExtraInfo(const std::string &name, float value)
Sets the user-defined data of given name to the given value.
Definition: Particle.cc:1224
Belle2::Particle::getDaughter
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
Definition: Particle.cc:595
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::StoreObjPtr
Type-safe access to single objects in the data store.
Definition: ParticleList.h:33
Belle2::Particle::getNDaughters
unsigned getNDaughters(void) const
Returns number of daughter particles.
Definition: Particle.h:625
Belle2::DuplicateVertexMarkerModule
Identify duplicate vertices (distinct particles, but built from the same daughters) and mark the one ...
Definition: DuplicateVertexMarkerModule.h:40
Belle2::Particle::getTrack
const Track * getTrack() const
Returns the pointer to the Track object that was used to create this Particle (ParticleType == c_Trac...
Definition: Particle.cc:770
Belle2::Particle
Class to store reconstructed particles.
Definition: Particle.h:77
Belle2::Particle::hasExtraInfo
bool hasExtraInfo(const std::string &name) const
Return wether the extra info with the given name is set.
Definition: Particle.cc:1154
Belle2::Variable::Manager
Global list of available variables.
Definition: Manager.h:108