Belle II Software  release-08-01-10
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 <TMatrixDSym.h>
14 
15 using namespace Belle2;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(BeamSpotMonitor);
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
27 {
28  // Set module properties
29  setDescription("Module for the monitoring of the BeamSpot position and size");
30 
31  // Parameter definitions
32  addParam("outputFileName", m_rootFileName, "Name of output root file.", std::string("BeamSpotMonitor.root"));
33 }
34 
36 {
37  m_EventMetaData.isRequired();
38 
39  TDirectory* olddir = gDirectory;
40  m_rootFilePtr = new TFile(m_rootFileName.c_str(), "RECREATE");
41 
42  //tree initialization
43  m_tree = new TTree("bspt", "RECREATE");
44  b_exp = m_tree->Branch("exp", &m_exp, "exp/i");
45  b_run = m_tree->Branch("run", &m_run, "run/i");
46  b_x = m_tree->Branch("x", &m_x, "x/d");
47  b_y = m_tree->Branch("y", &m_y, "y/d");
48  b_z = m_tree->Branch("z", &m_z, "z/d");
49  b_xErr = m_tree->Branch("xErr", &m_xErr, "xErr/d");
50  b_yErr = m_tree->Branch("yErr", &m_yErr, "yErr/d");
51  b_zErr = m_tree->Branch("zErr", &m_zErr, "zErr/d");
52  b_xSize = m_tree->Branch("xSize", &m_xSize, "xSize/d");
53  b_ySize = m_tree->Branch("ySize", &m_ySize, "ySize/d");
54  b_zSize = m_tree->Branch("zSize", &m_zSize, "zSize/d");
55 
56  olddir->cd();
57 
58 }
59 
61 {
62  if (! m_BeamSpotDB.isValid()) {
63  B2WARNING("No valid BeamSpot for the requested IoV");
64  } else {
66  }
67 
68 }
69 
71 {
72  m_exp = m_EventMetaData->getExperiment();
73  m_run = m_EventMetaData->getRun();
74  B2DEBUG(25, "monitoring beam spot for experiment = " << m_exp << ", run = " << m_run);
75 
76  if (! m_BeamSpotDB.isValid())
77  return;
78 
79  //retrieve vertex position
83 
84  //retrieve vertex position error
85  TMatrixDSym posErr = m_BeamSpot.getIPPositionCovMatrix();
86  m_xErr = sqrt(posErr[0][0]);
87  m_yErr = sqrt(posErr[1][1]);
88  m_zErr = sqrt(posErr[2][2]);
89 
90  //retrieve beam spot size
91  TMatrixDSym size = m_BeamSpot.getSizeCovMatrix();
92  m_xSize = sqrt(size[0][0]);
93  m_ySize = sqrt(size[1][1]);
94  m_zSize = sqrt(size[2][2]);
95 
96  m_tree->Fill();
97 
98 }
99 
101 {
102  TDirectory* olddir = gDirectory;
103  if (m_rootFilePtr != nullptr) {
104 
105  m_rootFilePtr->cd();
106 
107  //write the tree
108  m_tree->Write();
109 
110  m_rootFilePtr->Close();
111 
112  olddir->cd();
113  }
114 }
115 
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.
const TMatrixDSym & getIPPositionCovMatrix() const
Get the covariance matrix of the measured IP position.
Definition: BeamSpot.h:72
const TMatrixDSym & getSizeCovMatrix() const
Get the covariance matrix of the size of the IP position modeled as a gaussian.
Definition: BeamSpot.h:78
const TVector3 & getIPPosition() const
Get the IP position.
Definition: BeamSpot.h:66
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
REG_MODULE(arichBtest)
Register the Module.
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:560
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28
Abstract base class for different kinds of events.