Belle II Software  release-06-02-00
PseudoVertexFitterModule.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 
9 #include <analysis/modules/PseudoVertexFitter/PseudoVertexFitterModule.h>
10 #include <analysis/dataobjects/Particle.h>
11 #include <analysis/dataobjects/ParticleList.h>
12 #include <framework/database/DBObjPtr.h>
13 
14 using namespace std;
15 
16 namespace Belle2 {
23  //-----------------------------------------------------------------
24  // Register module
25  //-----------------------------------------------------------------
26 
27  REG_MODULE(PseudoVertexFitter)
28 
29  //-----------------------------------------------------------------
30  // Implementation
31  //-----------------------------------------------------------------
32 
34  {
35  // set module description (e.g. insert text)
36  setDescription("Pseudo fitter adds a covariance matrix which is sum of the daughter covariance matrices.");
37  setPropertyFlags(c_ParallelProcessingCertified);
38 
39  // Add parameters
40  addParam("listName", m_listName, "name of particle list", string(""));
41  }
42 
43  void PseudoVertexFitterModule::initialize()
44  {
45  if (m_listName == "") {
46  B2ERROR("No list name specified! Please enter the list name of the particle you want to add a covariance matrix to.");
47  return;
48  }
49  B2INFO("PseudoVertexFitter: adding covariance matrix to " << m_listName);
50 
51  }
52 
53  void PseudoVertexFitterModule::event()
54  {
55  StoreObjPtr<ParticleList> plist(m_listName);
56  if (!plist) {
57  B2ERROR("ParticleList " << m_listName << " not found");
58  return;
59  }
60 
61  std::vector<unsigned int> toRemove;
62  unsigned int n = plist->getListSize();
63  for (unsigned i = 0; i < n; i++) {
64  Particle* particle = plist->getParticle(i);
65 
66  bool ok = add_matrix(particle);
67 
68  if (!ok) particle->setPValue(-1);
69  }
70  }
71 
72  bool PseudoVertexFitterModule::add_matrix(Particle* mother)
73  {
74  // steering starts here
75  if (mother->getNDaughters() < 2) return false;
76 
77  bool ok = false;
78 
79  const std::vector<Particle*> daughters = mother->getDaughters();
80  std::vector<TMatrixFSym> daughter_matrices;
81  daughter_matrices.reserve(daughters.size());
82  for (auto daughter : daughters) {
83  daughter_matrices.push_back(daughter->getMomentumVertexErrorMatrix());
84  }
85 
86  TMatrixFSym mother_errMatrix(7);
87  for (int i = 0; i < 7; i++) {
88  for (int j = 0; j < 7; j++) {
89  for (unsigned int k = 0; k < daughters.size(); k++) {
90  mother_errMatrix[i][j] += daughter_matrices[k][i][j];
91  }
92  }
93  }
94 
95  mother->setMomentumVertexErrorMatrix(mother_errMatrix);
96  if (mother->getMomentumVertexErrorMatrix() == mother_errMatrix) {
97  ok = true;
98  }
99  if (!ok) return false;
100  return true;
101  }
103 } // end Belle2 namespace
104 
Base class for Modules.
Definition: Module.h:72
Class to store reconstructed particles.
Definition: Particle.h:74
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:95
#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.