Belle II Software  release-08-01-10
PrintBeamParametersModule.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 <framework/modules/core/PrintBeamParametersModule.h>
10 #include <framework/logging/Logger.h>
11 
12 
13 using namespace Belle2;
14 
15 //-----------------------------------------------------------------
16 // Register the Module
17 //-----------------------------------------------------------------
18 REG_MODULE(PrintBeamParameters);
19 
20 //-----------------------------------------------------------------
21 // Implementation
22 //-----------------------------------------------------------------
23 
25 {
26  // Set module properties
27  setDescription("Print the BeamParameters everytime they change");
28 
29  // Parameter definitions
30 }
31 
33 {
34  if (!m_beamparams || !m_beamparams.hasChanged()) return;
35  std::stringstream out;
36  const ROOT::Math::PxPyPzEVector& her = m_beamparams->getHER();
37  const ROOT::Math::PxPyPzEVector& ler = m_beamparams->getLER();
38  const ROOT::Math::PxPyPzEVector& cms = her + ler;
39  const ROOT::Math::XYZVector& vtx = m_beamparams->getVertex();
40  out << "BeamParameters: cms Energy=" << m_beamparams->getMass() << " GeV, flags="
41  << m_beamparams->getGenerationFlagString() << std::endl
42  << " HER=(" << her.X() << ", " << her.Y() << ", " << her.Z() << ", " << her.E() << "), " << std::endl
43  << " LER=(" << ler.X() << ", " << ler.Y() << ", " << ler.Z() << ", " << ler.E() << "), " << std::endl
44  << " CMS=(" << cms.X() << ", " << cms.Y() << ", " << cms.Z() << ", " << cms.E() << "), " << std::endl
45  << " VTX=(" << vtx.X() << ", " << vtx.Y() << ", " << vtx.Z() << "), " << std::endl
46  << " CovHER=";
47  printCovMatrix(out, m_beamparams->getCovHER());
48  out << std::endl << " CovLER=";
49  printCovMatrix(out, m_beamparams->getCovLER());
50  out << std::endl << " CovVTX=";
51  printCovMatrix(out, m_beamparams->getCovVertex());
52  B2INFO(out.str());
53 }
54 
55 void PrintBeamParametersModule::printCovMatrix(std::ostream& out, const TMatrixDSym& cov)
56 {
57  // check for off diagonal elements
58  bool offdiag = cov(0, 1) != 0 || cov(0, 2) != 0 || cov(1, 2) != 0;
59  if (offdiag) {
60  // if so print full matrix
61  out << "[";
62  for (int i = 0; i < 3; ++i) {
63  out << (i > 0 ? ", " : "") << "(";
64  for (int j = 0; j < 3; ++j) {
65  out << cov(i, j) << (j < 2 ? ", " : ")");
66  }
67  }
68  out << "]";
69  } else {
70  // otherwise just print the diagonal
71  out << "diag(";
72  for (int i = 0; i < 3; ++i) {
73  out << cov(i, i) << (i < 2 ? ", " : ")");
74  }
75  }
76 }
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
static void printCovMatrix(std::ostream &out, const TMatrixDSym &cov)
print a covariance matrix and simplify it to three elements if the off diagonals are zero
DBObjPtr< BeamParameters > m_beamparams
Pointer to the BeamParameters.
void event() override
print the Beam Parameters if they changed
PrintBeamParametersModule()
Constructor: Sets the description, the properties and the parameters of the module.
REG_MODULE(arichBtest)
Register the Module.
Abstract base class for different kinds of events.