Belle II Software  release-05-01-25
PseudoVertexFitterModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2019 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Klemens Lautenbach *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/modules/PseudoVertexFitter/PseudoVertexFitterModule.h>
12 #include <analysis/dataobjects/Particle.h>
13 #include <analysis/dataobjects/ParticleList.h>
14 #include <framework/database/DBObjPtr.h>
15 
16 using namespace std;
17 
18 namespace Belle2 {
25  //-----------------------------------------------------------------
26  // Register module
27  //-----------------------------------------------------------------
28 
29  REG_MODULE(PseudoVertexFitter)
30 
31  //-----------------------------------------------------------------
32  // Implementation
33  //-----------------------------------------------------------------
34 
36  {
37  // set module description (e.g. insert text)
38  setDescription("Pseudo fitter adds a covariance matrix which is sum of the daughter covariance matrices.");
39  setPropertyFlags(c_ParallelProcessingCertified);
40 
41  // Add parameters
42  addParam("listName", m_listName, "name of particle list", string(""));
43  }
44 
45  void PseudoVertexFitterModule::initialize()
46  {
47  if (m_listName == "") {
48  B2ERROR("No list name specified! Please enter the list name of the particle you want to add a covariance matrix to.");
49  return;
50  }
51  B2INFO("PseudoVertexFitter: adding covariance matrix to " << m_listName);
52 
53  }
54 
55  void PseudoVertexFitterModule::event()
56  {
57  StoreObjPtr<ParticleList> plist(m_listName);
58  if (!plist) {
59  B2ERROR("ParticleList " << m_listName << " not found");
60  return;
61  }
62 
63  std::vector<unsigned int> toRemove;
64  unsigned int n = plist->getListSize();
65  for (unsigned i = 0; i < n; i++) {
66  Particle* particle = plist->getParticle(i);
67 
68  bool ok = add_matrix(particle);
69 
70  if (!ok) particle->setPValue(-1);
71  }
72  }
73 
74  bool PseudoVertexFitterModule::add_matrix(Particle* mother)
75  {
76  // steering starts here
77  if (mother->getNDaughters() < 2) return false;
78 
79  bool ok = false;
80 
81  const std::vector<Particle*> daughters = mother->getDaughters();
82  std::vector<TMatrixFSym> daughter_matrices;
83  daughter_matrices.reserve(daughters.size());
84  for (auto daughter : daughters) {
85  daughter_matrices.push_back(daughter->getMomentumVertexErrorMatrix());
86  }
87 
88  TMatrixFSym mother_errMatrix(7);
89  for (int i = 0; i < 7; i++) {
90  for (int j = 0; j < 7; j++) {
91  for (unsigned int k = 0; k < daughters.size(); k++) {
92  mother_errMatrix[i][j] += daughter_matrices[k][i][j];
93  }
94  }
95  }
96 
97  mother->setMomentumVertexErrorMatrix(mother_errMatrix);
98  if (mother->getMomentumVertexErrorMatrix() == mother_errMatrix) {
99  ok = true;
100  }
101  if (!ok) return false;
102  return true;
103  }
105 } // end Belle2 namespace
106 
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::PseudoVertexFitterModule
Pseudo Vertex fitter module.
Definition: PseudoVertexFitterModule.h:37
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
Class to store reconstructed particles.
Definition: Particle.h:77