Belle II Software  release-06-02-00
BeamSpotMonitorModule.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 <tracking/modules/ipMonitor/BeamSpotMonitorModule.h>
10 #include <framework/datastore/StoreObjPtr.h>
11 #include <framework/dataobjects/EventMetaData.h>
12 
13 #include <TVector3.h>
14 #include <TMatrixDSym.h>
15 
16 using namespace Belle2;
17 using namespace std;
18 
19 //-----------------------------------------------------------------
20 // Register the Module
21 //-----------------------------------------------------------------
22 REG_MODULE(BeamSpotMonitor)
23 
24 //-----------------------------------------------------------------
25 // Implementation
26 //-----------------------------------------------------------------
27 
29 {
30  // Set module properties
31  setDescription("Module for the monitoring of the BeamSpot position and size");
32 
33  // Parameter definitions
34  addParam("outputFileName", m_rootFileName, "Name of output root file.", std::string("BeamSpotMonitor.root"));
35 }
36 
38 {
39 
40  TDirectory* olddir = gDirectory;
41  m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
42 
43  //tree initialization
44  m_tree = new TTree("bspt", "RECREATE");
45  b_exp = m_tree->Branch("exp", &m_exp, "exp/i");
46  b_run = m_tree->Branch("run", &m_run, "run/i");
47  b_x = m_tree->Branch("x", &m_x, "x/d");
48  b_y = m_tree->Branch("y", &m_y, "y/d");
49  b_z = m_tree->Branch("z", &m_z, "z/d");
50  b_xErr = m_tree->Branch("xErr", &m_xErr, "xErr/d");
51  b_yErr = m_tree->Branch("yErr", &m_yErr, "yErr/d");
52  b_zErr = m_tree->Branch("zErr", &m_zErr, "zErr/d");
53  b_xSize = m_tree->Branch("xSize", &m_xSize, "xSize/d");
54  b_ySize = m_tree->Branch("ySize", &m_ySize, "ySize/d");
55  b_zSize = m_tree->Branch("zSize", &m_zSize, "zSize/d");
56 
57  olddir->cd();
58 
59 }
60 
62 {
63  if (! m_BeamSpotDB.isValid()) {
64  B2WARNING("No valid BeamSpot for the requested IoV");
65  } else {
66  m_BeamSpot = *m_BeamSpotDB;
67  }
68 
69 }
70 
72 {
73 
75  m_exp = meta->getExperiment();
76  m_run = meta->getRun();
77  B2DEBUG(25, "monitoring beam spot for experiment = " << m_exp << ", run = " << m_run);
78 
79  if (! m_BeamSpotDB.isValid())
80  return;
81 
82  //retrieve vertex position
83  m_x = m_BeamSpot.getIPPosition().X();
84  m_y = m_BeamSpot.getIPPosition().Y();
85  m_z = m_BeamSpot.getIPPosition().Z();
86 
87  //retrieve vertex position error
88  TMatrixDSym posErr = m_BeamSpot.getIPPositionCovMatrix();
89  m_xErr = sqrt(posErr[0][0]);
90  m_yErr = sqrt(posErr[1][1]);
91  m_zErr = sqrt(posErr[2][2]);
92 
93  //retrieve beam spot size
94  TMatrixDSym size = m_BeamSpot.getSizeCovMatrix();
95  m_xSize = sqrt(size[0][0]);
96  m_ySize = sqrt(size[1][1]);
97  m_zSize = sqrt(size[2][2]);
98 
99  m_tree->Fill();
100 
101 }
102 
104 {
105  TDirectory* olddir = gDirectory;
106  if (m_rootFilePtr != nullptr) {
107 
108  m_rootFilePtr->cd();
109 
110  //write the tree
111  m_tree->Write();
112 
113  m_rootFilePtr->Close();
114 
115  olddir->cd();
116  }
117 }
118 
Module for the monitoring of the BeamSpot position and size.
virtual void initialize() override
initialize the TTree
virtual void event() override
fill trees
virtual void terminate() override
print the payloads uniqueID and write tree to the rootfile
virtual void beginRun() override
check BeamSpot payload validity
Base class for Modules.
Definition: Module.h:72
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.