Belle II Software  release-08-01-10
CDCTimeZeros.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 #include <cdc/dataobjects/WireID.h>
16 
17 namespace Belle2 {
26  class CDCTimeZeros: public TObject {
27  public:
28 
33 
40  void setT0(unsigned short iCLayer, unsigned short iWire, float t0)
41  {
42  m_t0s.insert(std::pair<unsigned short, float>(WireID(iCLayer, iWire).getEWire(), t0));
43  }
44 
50  void setT0(const WireID& wid, float t0)
51  {
52  m_t0s.insert(std::pair<unsigned short, float>(wid.getEWire(), t0));
53  }
54 
61  void addT0(unsigned short iCLayer, unsigned short iWire, float delta)
62  {
63  WireID wid(iCLayer, iWire);
64  std::map<unsigned short, float>::iterator it = m_t0s.find(wid.getEWire());
65  it->second += delta;
66  }
67 
73  void addT0(const WireID& wid, float delta)
74  {
75  std::map<unsigned short, float>::iterator it = m_t0s.find(wid.getEWire());
76  it->second += delta;
77  }
78 
82  unsigned short getEntries() const
83  {
84  return m_t0s.size();
85  }
86 
90  std::map<unsigned short, float> getT0s() const
91  {
92  return m_t0s;
93  }
94 
100  float getT0(const WireID& wid) const
101  {
102  std::map<unsigned short, float>::const_iterator it = m_t0s.find(wid.getEWire());
103  return it->second;
104  }
105 
109  void dump() const
110  {
111  std::cout << " " << std::endl;
112  std::cout << "t0 list" << std::endl;
113  std::cout << "# of entries= " << m_t0s.size() << std::endl;
114  std::cout << "in order of clayer#, wire#, t0" << std::endl;
115  for (auto const& ent : m_t0s) {
116  std::cout << WireID(ent.first).getICLayer() << " " << WireID(ent.first).getIWire() << " " << ent.second << std::endl;
117  }
118  }
119 
123  void outputToFile(std::string fileName) const
124  {
125  std::ofstream fout(fileName);
126 
127  if (fout.bad()) {
128  B2ERROR("Specified output file could not be opened!");
129  } else {
130  for (auto const& ent : m_t0s) {
131  fout << std::setw(2) << std::right << WireID(ent.first).getICLayer() << " " << std::setw(3) << WireID(
132  ent.first).getIWire() << " " << std::setw(15) << std::scientific << std::setprecision(8) << ent.second << std::endl;
133  }
134  fout.close();
135  }
136  }
137 
138  // ------------- Interface to global Millepede calibration ----------------
140  static unsigned short getGlobalUniqueID() {return 25;}
142  double getGlobalParam(unsigned short element, unsigned short)
143  {
144  return getT0(WireID(element));
145  }
147  void setGlobalParam(double value, unsigned short element, unsigned short)
148  {
149  WireID wire(element);
150  //This does not work, tries to insert, but we need an update
151  //setT0(wire.getICLayer(), wire.getIWire(), value);
152  m_t0s[wire.getEWire()] = value;
153  }
155  std::vector<std::pair<unsigned short, unsigned short>> listGlobalParams()
156  {
157  std::vector<std::pair<unsigned short, unsigned short>> result;
158  for (auto id_t0 : getT0s()) {
159  result.push_back({id_t0.first, 0});
160  }
161  return result;
162  }
163  // ------------------------------------------------------------------------
164 
165  private:
166  std::map<unsigned short, float> m_t0s;
169  };
170 
172 } // end namespace Belle2
173 
Database object for timing offset (t0).
Definition: CDCTimeZeros.h:26
void setT0(const WireID &wid, float t0)
Set t0 in the list.
Definition: CDCTimeZeros.h:50
static unsigned short getGlobalUniqueID()
Get global unique id.
Definition: CDCTimeZeros.h:140
void outputToFile(std::string fileName) const
Output the contents in text file format.
Definition: CDCTimeZeros.h:123
std::map< unsigned short, float > getT0s() const
Get the whole list.
Definition: CDCTimeZeros.h:90
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()
list stored global parameters
Definition: CDCTimeZeros.h:155
ClassDef(CDCTimeZeros, 2)
ClassDef.
void addT0(const WireID &wid, float delta)
Update t0 in the list.
Definition: CDCTimeZeros.h:73
double getGlobalParam(unsigned short element, unsigned short)
Get global parameter.
Definition: CDCTimeZeros.h:142
CDCTimeZeros()
Default constructor.
Definition: CDCTimeZeros.h:32
void setT0(unsigned short iCLayer, unsigned short iWire, float t0)
Set t0 in the list.
Definition: CDCTimeZeros.h:40
unsigned short getEntries() const
Get the no.
Definition: CDCTimeZeros.h:82
float getT0(const WireID &wid) const
Get t0 for the specified wire.
Definition: CDCTimeZeros.h:100
std::map< unsigned short, float > m_t0s
t0 list
Definition: CDCTimeZeros.h:166
void setGlobalParam(double value, unsigned short element, unsigned short)
Set global parameter.
Definition: CDCTimeZeros.h:147
void dump() const
Print out all contents.
Definition: CDCTimeZeros.h:109
void addT0(unsigned short iCLayer, unsigned short iWire, float delta)
Update t0 in the list.
Definition: CDCTimeZeros.h:61
Class to identify a wire inside the CDC.
Definition: WireID.h:34
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition: WireID.cc:24
unsigned short getIWire() const
Getter for wire within the layer.
Definition: WireID.h:145
unsigned short getEWire() const
Getter for encoded wire number.
Definition: WireID.h:154
Abstract base class for different kinds of events.