Belle II Software development
CDCTimeWalks.h
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#pragma once
9
10#include <map>
11#include <iostream>
12#include <fstream>
13#include <iomanip>
14#include <TObject.h>
15
16namespace Belle2 {
25 class CDCTimeWalks: public TObject {
26 public:
27
32
38 void setTwParamMode(unsigned short mode)
39 {
40 m_twParamMode = mode;
41 }
42
48 void setTimeWalkParams(unsigned short boardID, const std::vector<float>& params)
49 {
50 m_nTwParams = params.size();
51 m_tws.insert(std::pair<unsigned short, std::vector<float>>(boardID, params));
52 }
53
59 void addTimeWalks(unsigned short boardID, const std::vector<float>& deltas)
60 {
61 std::map<unsigned short, std::vector<float>>::iterator it = m_tws.find(boardID);
62 if (it != m_tws.end()) {
63 for (unsigned short i = 0; i < m_nTwParams; ++i) {
64 (it->second)[i] += deltas[i];
65 }
66 } else {
67 B2FATAL("Specified tw params not found in addTimeWalks !");
68 }
69 }
70
71
75 unsigned short getTwParamMode() const
76 {
77 return m_twParamMode;
78 }
79
83 unsigned short getEntries() const
84 {
85 return m_tws.size();
86 }
87
91 std::map<unsigned short, std::vector<float>> getTimeWalkParams() const
92 {
93 return m_tws;
94 }
95
101 const std::vector<float>& getTimeWalkParams(unsigned short boardID) const
102 {
103 std::map<unsigned short, std::vector<float>>::const_iterator it = m_tws.find(boardID);
104 if (it != m_tws.end()) {
105 return it->second;
106 } else {
107 B2FATAL("Specified tw params not found in getTimeWalks !");
108 }
109 }
110
114 void dump() const
115 {
116 std::cout << " " << std::endl;
117 std::cout << "Time walk coefficient list" << std::endl;
118 std::cout << "#entries= " << m_tws.size() << std::endl;
119 std::cout << m_twParamMode << " " << m_nTwParams << std::endl;
120 std::cout << "in order of board# and coefficients" << std::endl;
121
122 for (auto const& ent : m_tws) {
123 std::cout << ent.first;
124 for (unsigned short i = 0; i < m_nTwParams; ++i) {
125 std::cout << " " << (ent.second)[i];
126 }
127 std::cout << std::endl;
128 }
129 }
130
134 void outputToFile(std::string fileName) const
135 {
136 std::ofstream fout(fileName);
137
138 if (fout.bad()) {
139 B2ERROR("Specified output file could not be opened!");
140 } else {
141 fout << m_twParamMode << " " << m_nTwParams << std::endl;
142 for (auto const& ent : m_tws) {
143 fout << std::setw(3) << std::right << ent.first;
144 for (unsigned short i = 0; i < m_nTwParams; ++i) {
145 fout << " " << std::setw(15) << std::scientific << std::setprecision(8) << ent.second[i];
146 }
147 fout << std::endl;
148 }
149 fout.close();
150 }
151 }
152
153 // ------------- Interface to global Millepede calibration ----------------
155 static unsigned short getGlobalUniqueID() {return 26;}
157 double getGlobalParam(unsigned short element, unsigned short i) const
158 {
159 return (getTimeWalkParams(element))[i];
160 }
162 void setGlobalParam(double value, unsigned short element, unsigned short i)
163 {
164 std::map<unsigned short, std::vector<float>>::iterator it = m_tws.find(element);
165 if (it != m_tws.end()) {
166 (it->second)[i] = static_cast<float>(value);
167 } else {
168 m_tws.insert(std::pair<unsigned short, std::vector<float>>(element, {static_cast<float>(value), 0.}));
169 }
170 }
172 std::vector<std::pair<unsigned short, unsigned short>> listGlobalParams() const
173 {
174 std::vector<std::pair<unsigned short, unsigned short>> result;
175 for (auto id_timewalk : m_tws) {
176 result.push_back({id_timewalk.first, 0});
177 result.push_back({id_timewalk.first, 1});
178 }
179 return result;
180 }
181 // ------------------------------------------------------------------------
182
183 private:
184 unsigned short m_twParamMode =
185 1;
186 unsigned short m_nTwParams =
187 2;
188 std::map<unsigned short, std::vector<float>> m_tws;
191 };
192
194} // end namespace Belle2
Database object for time-walk.
Definition: CDCTimeWalks.h:25
double getGlobalParam(unsigned short element, unsigned short i) const
Get global parameter.
Definition: CDCTimeWalks.h:157
CDCTimeWalks()
Default constructor.
Definition: CDCTimeWalks.h:31
static unsigned short getGlobalUniqueID()
Get global unique id.
Definition: CDCTimeWalks.h:155
void outputToFile(std::string fileName) const
Output the contents in text file format.
Definition: CDCTimeWalks.h:134
void addTimeWalks(unsigned short boardID, const std::vector< float > &deltas)
Update the time-walk coefficients in the list.
Definition: CDCTimeWalks.h:59
unsigned short m_twParamMode
Mode for tw parameterization; the initial value should be the one for classdef=1; do not modify it.
Definition: CDCTimeWalks.h:184
unsigned short getTwParamMode() const
Get tw parameterization mode.
Definition: CDCTimeWalks.h:75
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams() const
list stored global parameters
Definition: CDCTimeWalks.h:172
void setTwParamMode(unsigned short mode)
Set tw parameterization mode mode=0: tw (in ns) = p0/sqrt(FADCsum); mode=1: tw( in ns) = p0*exp(-p1*F...
Definition: CDCTimeWalks.h:38
unsigned short getEntries() const
Get the no.
Definition: CDCTimeWalks.h:83
void setGlobalParam(double value, unsigned short element, unsigned short i)
Set global parameter.
Definition: CDCTimeWalks.h:162
unsigned short m_nTwParams
No.
Definition: CDCTimeWalks.h:186
void setTimeWalkParams(unsigned short boardID, const std::vector< float > &params)
Set the time-walk coefficients in the list.
Definition: CDCTimeWalks.h:48
const std::vector< float > & getTimeWalkParams(unsigned short boardID) const
Get the time-walk coefficients for the board.
Definition: CDCTimeWalks.h:101
std::map< unsigned short, std::vector< float > > m_tws
tw list
Definition: CDCTimeWalks.h:188
std::map< unsigned short, std::vector< float > > getTimeWalkParams() const
Get the whole list.
Definition: CDCTimeWalks.h:91
ClassDef(CDCTimeWalks, 2)
ClassDef.
void dump() const
Print all contents.
Definition: CDCTimeWalks.h:114
Abstract base class for different kinds of events.