Belle II Software development
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 <reconstruction/modules/ipMonitor/BeamSpotMonitorModule.h>
10#include <framework/dataobjects/EventMetaData.h>
11
12#include <TMatrixDSym.h>
13
14using namespace Belle2;
15
16//-----------------------------------------------------------------
17// Register the Module
18//-----------------------------------------------------------------
19REG_MODULE(BeamSpotMonitor);
20
21//-----------------------------------------------------------------
22// Implementation
23//-----------------------------------------------------------------
24
26{
27 // Set module properties
28 setDescription("Module for the monitoring of the BeamSpot position and size");
29
30 // Parameter definitions
31 addParam("outputFileName", m_rootFileName, "Name of output root file.", std::string("BeamSpotMonitor.root"));
32}
33
35{
36 m_EventMetaData.isRequired();
37
38 TDirectory* olddir = gDirectory;
39 m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
40
41 //tree initialization
42 m_tree = new TTree("bspt", "RECREATE");
43 b_exp = m_tree->Branch("exp", &m_exp, "exp/i");
44 b_run = m_tree->Branch("run", &m_run, "run/i");
45 b_x = m_tree->Branch("x", &m_x, "x/d");
46 b_y = m_tree->Branch("y", &m_y, "y/d");
47 b_z = m_tree->Branch("z", &m_z, "z/d");
48 b_xErr = m_tree->Branch("xErr", &m_xErr, "xErr/d");
49 b_yErr = m_tree->Branch("yErr", &m_yErr, "yErr/d");
50 b_zErr = m_tree->Branch("zErr", &m_zErr, "zErr/d");
51 b_xSize = m_tree->Branch("xSize", &m_xSize, "xSize/d");
52 b_ySize = m_tree->Branch("ySize", &m_ySize, "ySize/d");
53 b_zSize = m_tree->Branch("zSize", &m_zSize, "zSize/d");
54
55 olddir->cd();
56
57}
58
60{
61 if (! m_BeamSpotDB.isValid()) {
62 B2WARNING("No valid BeamSpot for the requested IoV");
63 } else {
65 }
66
67}
68
70{
71 m_exp = m_EventMetaData->getExperiment();
72 m_run = m_EventMetaData->getRun();
73 B2DEBUG(25, "monitoring beam spot for experiment = " << m_exp << ", run = " << m_run);
74
75 if (! m_BeamSpotDB.isValid())
76 return;
77
78 //retrieve vertex position
79 m_x = m_BeamSpot.getIPPosition().X();
80 m_y = m_BeamSpot.getIPPosition().Y();
81 m_z = m_BeamSpot.getIPPosition().Z();
82
83 //retrieve vertex position error
84 TMatrixDSym posErr = m_BeamSpot.getIPPositionCovMatrix();
85 m_xErr = sqrt(posErr[0][0]);
86 m_yErr = sqrt(posErr[1][1]);
87 m_zErr = sqrt(posErr[2][2]);
88
89 //retrieve beam spot size
90 TMatrixDSym size = m_BeamSpot.getSizeCovMatrix();
91 m_xSize = sqrt(size[0][0]);
92 m_ySize = sqrt(size[1][1]);
93 m_zSize = sqrt(size[2][2]);
94
95 m_tree->Fill();
96
97}
98
100{
101 TDirectory* olddir = gDirectory;
102 if (m_rootFilePtr != nullptr) {
103
104 m_rootFilePtr->cd();
105
106 //write the tree
107 m_tree->Write();
108
109 m_rootFilePtr->Close();
110
111 olddir->cd();
112 }
113}
114
std::string m_rootFileName
root file name
TBranch * b_xErr
X position error of the beam spot.
TTree * m_tree
pointer to the tree
TBranch * b_xSize
X position size of the beam spot.
virtual void initialize() override
initialize the TTree
TBranch * b_zSize
Z position size of the beam spot.
double m_xSize
X position size of the beam spot.
TBranch * b_yErr
Y position error of the beam spot.
virtual void event() override
fill trees
double m_xErr
X position error of the beam spot.
TBranch * b_y
Y position of the beam spot.
TBranch * b_exp
experiment number
virtual void terminate() override
print the payloads uniqueID and write tree to the rootfile
TBranch * b_x
X position of the beam spot.
double m_x
X position of the beam spot.
double m_yErr
Y position error of the beam spot.
DBObjPtr< BeamSpot > m_BeamSpotDB
beam spot payload from the database
TBranch * b_ySize
Y position size of the beam spot.
virtual void beginRun() override
check BeamSpot payload validity
double m_zSize
Z position size of the beam spot.
double m_zErr
Z position error of the beam spot.
TBranch * b_z
Z position of the beam spot.
double m_z
Z position of the beam spot.
BeamSpot m_BeamSpot
beam spot payload
double m_y
Y position of the beam spot.
TFile * m_rootFilePtr
pointer at root file used for storing histograms
BeamSpotMonitorModule()
Constructor: Sets the description, the properties and the parameters of the module.
StoreObjPtr< EventMetaData > m_EventMetaData
EventMetaData.
TBranch * b_zErr
Z position error of the beam spot.
double m_ySize
Y position size of the beam spot.
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
double sqrt(double a)
sqrt for double
Definition beamHelpers.h:28
Abstract base class for different kinds of events.