Belle II Software development
CDCEDepToADCConversions.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 CDCEDepToADCConversions: public TObject {
26 public:
27
32
36 void setParamMode(unsigned short mode)
37 {
38 m_paramMode = mode;
39 }
40
45 void setGroupID(unsigned short mode)
46 {
47 m_groupID = mode;
48 }
49
55 void setParams(unsigned short id, const std::vector<float>& params)
56 {
57 m_cvs.insert(std::pair<unsigned short, std::vector<float>>(id, params));
58 }
59
63 unsigned short getParamMode() const
64 {
65 return m_paramMode;
66 }
67
71 unsigned short getGroupID() const
72 {
73 return m_groupID;
74 }
75
79 unsigned short getEntries() const
80 {
81 return m_cvs.size();
82 }
83
87 std::map<unsigned short, std::vector<float>> getParams() const
88 {
89 return m_cvs;
90 }
91
97 const std::vector<float>& getParams(unsigned short id) const
98 {
99 std::map<unsigned short, std::vector<float>>::const_iterator it = m_cvs.find(id);
100 if (it != m_cvs.end()) {
101 return it->second;
102 } else {
103 B2FATAL("Specified id not found in getParams !");
104 }
105 }
106
110 void dump() const
111 {
112 std::cout << " " << std::endl;
113 std::cout << "Edep-to-ADC conversion list" << std::endl;
114 std::cout << "#entries= " << m_cvs.size() << std::endl;
115 std::cout << m_paramMode << std::endl;
116 std::cout << "in order of id and parameters" << std::endl;
117
118 for (auto const& ent : m_cvs) {
119 std::cout << ent.first;
120 unsigned short np = (ent.second).size();
121 for (unsigned short i = 0; i < np; ++i) {
122 std::cout << " " << (ent.second)[i];
123 }
124 std::cout << std::endl;
125 }
126 }
127
132 void outputToFile(std::string fileName) const
133 {
134 std::ofstream fout(fileName);
135
136 if (fout.bad()) {
137 B2ERROR("Specified output file could not be opened!");
138 } else {
139 std::map<unsigned short, std::vector<float>>::const_iterator it = m_cvs.find(0);
140 int nParams = (it->second).size();
141 fout << m_paramMode << " " << nParams << std::endl;
142 fout << m_groupID << std::endl;
143 for (auto const& ent : m_cvs) {
144 fout << std::setw(3) << std::right << ent.first;
145 for (unsigned short i = 0; i < nParams; ++i) {
146 fout << " " << std::setw(15) << std::scientific << std::setprecision(8) << (ent.second)[i];
147 }
148 fout << std::endl;
149 }
150 fout.close();
151 }
152 }
153
154 private:
155 unsigned short m_paramMode = 0;
156 unsigned short m_groupID = 0;
157 std::map<unsigned short, std::vector<float>> m_cvs;
160 // Version histroy:
161 // v2: original: paramMode=0, nParams=6.
162 // v3: paramMode=1, nParams=7; added sigma for gaussian smearing;
163 // main-factor is now of order(1), while was of order(10) before;
164 // activated outputToFile().
165 };
166
168} // end namespace Belle2
Database object for energy-deposit to ADC-count conversion.
void outputToFile(std::string fileName) const
Output the contents in text file format.
CDCEDepToADCConversions()
Default constructor.
unsigned short m_paramMode
Mode for parameterization.
void setGroupID(unsigned short mode)
Set group id (parameterized per group) id=0: superLayerID; =1: layerID; =2: wireID.
std::map< unsigned short, std::vector< float > > getParams() const
Get the whole list.
unsigned short getEntries() const
Get the no.
ClassDef(CDCEDepToADCConversions, 3)
ClassDef.
std::map< unsigned short, std::vector< float > > m_cvs
cv list
const std::vector< float > & getParams(unsigned short id) const
Get the conv.
void setParamMode(unsigned short mode)
Set conversion parameterization mode.
unsigned short m_groupID
Group id (parameterized per group)
void setParams(unsigned short id, const std::vector< float > &params)
Set the conv.
void dump() const
Print all contents.
unsigned short getGroupID() const
Get group id.
unsigned short getParamMode() const
Get mode of conversion parameterization.
Abstract base class for different kinds of events.