Belle II Software  release-05-02-19
PrintBeamParametersModule.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2013 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Martin Ritter *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <framework/modules/core/PrintBeamParametersModule.h>
12 #include <framework/logging/Logger.h>
13 
14 
15 using namespace Belle2;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(PrintBeamParameters)
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
27 {
28  // Set module properties
29  setDescription("Print the BeamParameters everytime they change");
30 
31  // Parameter definitions
32 }
33 
35 {
36  if (!m_beamparams || !m_beamparams.hasChanged()) return;
37  std::stringstream out;
38  const TLorentzVector& her = m_beamparams->getHER();
39  const TLorentzVector& ler = m_beamparams->getLER();
40  const TLorentzVector& cms = her + ler;
41  const TVector3& vtx = m_beamparams->getVertex();
42  out << "BeamParameters: cms Energy=" << m_beamparams->getMass() << " GeV, flags="
43  << m_beamparams->getGenerationFlagString() << std::endl
44  << " HER=(" << her.X() << ", " << her.Y() << ", " << her.Z() << ", " << her.E() << "), " << std::endl
45  << " LER=(" << ler.X() << ", " << ler.Y() << ", " << ler.Z() << ", " << ler.E() << "), " << std::endl
46  << " CMS=(" << cms.X() << ", " << cms.Y() << ", " << cms.Z() << ", " << cms.E() << "), " << std::endl
47  << " VTX=(" << vtx.X() << ", " << vtx.Y() << ", " << vtx.Z() << "), " << std::endl
48  << " CovHER=";
49  printCovMatrix(out, m_beamparams->getCovHER());
50  out << std::endl << " CovLER=";
51  printCovMatrix(out, m_beamparams->getCovLER());
52  out << std::endl << " CovVTX=";
53  printCovMatrix(out, m_beamparams->getCovVertex());
54  B2INFO(out.str());
55 }
56 
57 void PrintBeamParametersModule::printCovMatrix(std::ostream& out, const TMatrixDSym& cov)
58 {
59  // check for off diagonal elements
60  bool offdiag = cov(0, 1) != 0 || cov(0, 2) != 0 || cov(1, 2) != 0;
61  if (offdiag) {
62  // if so print full matrix
63  out << "[";
64  for (int i = 0; i < 3; ++i) {
65  out << (i > 0 ? ", " : "") << "(";
66  for (int j = 0; j < 3; ++j) {
67  out << cov(i, j) << (j < 2 ? ", " : ")");
68  }
69  }
70  out << "]";
71  } else {
72  // otherwise just print the diagonal
73  out << "diag(";
74  for (int i = 0; i < 3; ++i) {
75  out << cov(i, i) << (i < 2 ? ", " : ")");
76  }
77  }
78 }
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::PrintBeamParametersModule
Print the BeamParameters everytime they change.
Definition: PrintBeamParametersModule.h:38
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PrintBeamParametersModule::m_beamparams
DBObjPtr< BeamParameters > m_beamparams
Pointer to the BeamParameters.
Definition: PrintBeamParametersModule.h:55
Belle2::PrintBeamParametersModule::printCovMatrix
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
Definition: PrintBeamParametersModule.cc:57
Belle2::PrintBeamParametersModule::event
void event() override
print the Beam Parameters if they changed
Definition: PrintBeamParametersModule.cc:34