Belle II Software  release-05-01-25
CDCTimeWalks.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: CDC group *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #pragma once
11 
12 #include <map>
13 #include <iostream>
14 #include <fstream>
15 #include <iomanip>
16 #include <TObject.h>
17 
18 namespace Belle2 {
27  class CDCTimeWalks: public TObject {
28  public:
29 
33  CDCTimeWalks() {}
34 
40  void setTwParamMode(unsigned short mode)
41  {
42  m_twParamMode = mode;
43  }
44 
50  void setTimeWalkParams(unsigned short boardID, const std::vector<float>& params)
51  {
52  m_nTwParams = params.size();
53  m_tws.insert(std::pair<unsigned short, std::vector<float>>(boardID, params));
54  }
55 
61  void addTimeWalks(unsigned short boardID, const std::vector<float>& deltas)
62  {
63  std::map<unsigned short, std::vector<float>>::iterator it = m_tws.find(boardID);
64  if (it != m_tws.end()) {
65  for (unsigned short i = 0; i < m_nTwParams; ++i) {
66  (it->second)[i] += deltas[i];
67  }
68  } else {
69  B2FATAL("Specified tw params not found in addTimeWalks !");
70  }
71  }
72 
73 
77  unsigned short getTwParamMode() const
78  {
79  return m_twParamMode;
80  }
81 
85  unsigned short getEntries() const
86  {
87  return m_tws.size();
88  }
89 
93  std::map<unsigned short, std::vector<float>> getTimeWalkParams() const
94  {
95  return m_tws;
96  }
97 
103  const std::vector<float>& getTimeWalkParams(unsigned short boardID) const
104  {
105  std::map<unsigned short, std::vector<float>>::const_iterator it = m_tws.find(boardID);
106  if (it != m_tws.end()) {
107  return it->second;
108  } else {
109  B2FATAL("Specified tw params not found in getTimeWalks !");
110  }
111  }
112 
116  void dump() const
117  {
118  std::cout << " " << std::endl;
119  std::cout << "Time walk coefficient list" << std::endl;
120  std::cout << "#entries= " << m_tws.size() << std::endl;
121  std::cout << m_twParamMode << " " << m_nTwParams << std::endl;
122  std::cout << "in order of board# and coefficients" << std::endl;
123 
124  for (auto const& ent : m_tws) {
125  std::cout << ent.first;
126  for (unsigned short i = 0; i < m_nTwParams; ++i) {
127  std::cout << " " << (ent.second)[i];
128  }
129  std::cout << std::endl;
130  }
131  }
132 
136  void outputToFile(std::string fileName) const
137  {
138  std::ofstream fout(fileName);
139 
140  if (fout.bad()) {
141  B2ERROR("Specified output file could not be opened!");
142  } else {
143  fout << m_twParamMode << " " << m_nTwParams << std::endl;
144  for (auto const& ent : m_tws) {
145  fout << std::setw(3) << std::right << ent.first;
146  for (unsigned short i = 0; i < m_nTwParams; ++i) {
147  fout << " " << std::setw(15) << std::scientific << std::setprecision(8) << ent.second[i];
148  }
149  fout << std::endl;
150  }
151  fout.close();
152  }
153  }
154 
155  // ------------- Interface to global Millepede calibration ----------------
157  static unsigned short getGlobalUniqueID() {return 26;}
159  double getGlobalParam(unsigned short element, unsigned short i) const
160  {
161  return (getTimeWalkParams(element))[i];
162  }
164  void setGlobalParam(double value, unsigned short element, unsigned short i)
165  {
166  // TODO: this does not allow updates
167  //setTimeWalkParam(element, value);
168  // directly access the map
169  // m_tws[element] = value;
170  std::map<unsigned short, std::vector<float>>::iterator it = m_tws.find(element);
171  if (it != m_tws.end()) {
172  it->second[i] = value;
173  } else {
174  B2FATAL("Specified tw params not found in setGlobalParam !");
175  }
176  }
178  std::vector<std::pair<unsigned short, unsigned short>> listGlobalParams() const
179  {
180  std::vector<std::pair<unsigned short, unsigned short>> result;
181  for (auto id_timewalk : m_tws) {
182  result.push_back({id_timewalk.first, 0});
183  }
184  return result;
185  }
186  // ------------------------------------------------------------------------
187 
188  private:
189  unsigned short m_twParamMode =
190  0;
191  unsigned short m_nTwParams =
192  1;
193  std::map<unsigned short, std::vector<float>> m_tws;
195  ClassDef(CDCTimeWalks, 2);
196  };
197 
199 } // end namespace Belle2
Belle2::CDCTimeWalks::getTwParamMode
unsigned short getTwParamMode() const
Get tw parameterization mode.
Definition: CDCTimeWalks.h:85
Belle2::CDCTimeWalks::getTimeWalkParams
std::map< unsigned short, std::vector< float > > getTimeWalkParams() const
Get the whole list.
Definition: CDCTimeWalks.h:101
Belle2::CDCTimeWalks::getGlobalParam
double getGlobalParam(unsigned short element, unsigned short i) const
Get global parameter.
Definition: CDCTimeWalks.h:167
Belle2::CDCTimeWalks::ClassDef
ClassDef(CDCTimeWalks, 2)
ClassDef.
Belle2::CDCTimeWalks
Database object for time-walk.
Definition: CDCTimeWalks.h:35
Belle2::CDCTimeWalks::listGlobalParams
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams() const
list stored global parameters
Definition: CDCTimeWalks.h:186
Belle2::CDCTimeWalks::addTimeWalks
void addTimeWalks(unsigned short boardID, const std::vector< float > &deltas)
Update the time-walk coefficients in the list.
Definition: CDCTimeWalks.h:69
Belle2::CDCTimeWalks::getEntries
unsigned short getEntries() const
Get the no.
Definition: CDCTimeWalks.h:93
Belle2::CDCTimeWalks::setTimeWalkParams
void setTimeWalkParams(unsigned short boardID, const std::vector< float > &params)
Set the time-walk coefficients in the list.
Definition: CDCTimeWalks.h:58
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCTimeWalks::m_tws
std::map< unsigned short, std::vector< float > > m_tws
tw list
Definition: CDCTimeWalks.h:201
Belle2::CDCTimeWalks::m_twParamMode
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:197
Belle2::CDCTimeWalks::setTwParamMode
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:48
Belle2::CDCTimeWalks::CDCTimeWalks
CDCTimeWalks()
Default constructor.
Definition: CDCTimeWalks.h:41
Belle2::CDCTimeWalks::setGlobalParam
void setGlobalParam(double value, unsigned short element, unsigned short i)
Set global parameter.
Definition: CDCTimeWalks.h:172
Belle2::CDCTimeWalks::dump
void dump() const
Print all contents.
Definition: CDCTimeWalks.h:124
Belle2::CDCTimeWalks::outputToFile
void outputToFile(std::string fileName) const
Output the contents in text file format.
Definition: CDCTimeWalks.h:144
Belle2::CDCTimeWalks::getGlobalUniqueID
static unsigned short getGlobalUniqueID()
Get global unique id.
Definition: CDCTimeWalks.h:165
Belle2::CDCTimeWalks::m_nTwParams
unsigned short m_nTwParams
No.
Definition: CDCTimeWalks.h:199