Belle II Software  release-05-02-19
CDCTimeZeros.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2016 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Makoto Uchida (original), 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 #include <cdc/dataobjects/WireID.h>
18 
19 namespace Belle2 {
28  class CDCTimeZeros: public TObject {
29  public:
30 
34  CDCTimeZeros() {}
35 
42  void setT0(unsigned short iCLayer, unsigned short iWire, float t0)
43  {
44  m_t0s.insert(std::pair<unsigned short, float>(WireID(iCLayer, iWire).getEWire(), t0));
45  }
46 
52  void setT0(const WireID& wid, float t0)
53  {
54  m_t0s.insert(std::pair<unsigned short, float>(wid.getEWire(), t0));
55  }
56 
63  void addT0(unsigned short iCLayer, unsigned short iWire, float delta)
64  {
65  WireID wid(iCLayer, iWire);
66  std::map<unsigned short, float>::iterator it = m_t0s.find(wid.getEWire());
67  it->second += delta;
68  }
69 
75  void addT0(const WireID& wid, float delta)
76  {
77  std::map<unsigned short, float>::iterator it = m_t0s.find(wid.getEWire());
78  it->second += delta;
79  }
80 
84  unsigned short getEntries() const
85  {
86  return m_t0s.size();
87  }
88 
92  std::map<unsigned short, float> getT0s() const
93  {
94  return m_t0s;
95  }
96 
102  float getT0(const WireID& wid) const
103  {
104  std::map<unsigned short, float>::const_iterator it = m_t0s.find(wid.getEWire());
105  return it->second;
106  }
107 
111  void dump() const
112  {
113  std::cout << " " << std::endl;
114  std::cout << "t0 list" << std::endl;
115  std::cout << "# of entries= " << m_t0s.size() << std::endl;
116  std::cout << "in order of clayer#, wire#, t0" << std::endl;
117  for (auto const& ent : m_t0s) {
118  std::cout << WireID(ent.first).getICLayer() << " " << WireID(ent.first).getIWire() << " " << ent.second << std::endl;
119  }
120  }
121 
125  void outputToFile(std::string fileName) const
126  {
127  std::ofstream fout(fileName);
128 
129  if (fout.bad()) {
130  B2ERROR("Specified output file could not be opened!");
131  } else {
132  for (auto const& ent : m_t0s) {
133  fout << std::setw(2) << std::right << WireID(ent.first).getICLayer() << " " << std::setw(3) << WireID(
134  ent.first).getIWire() << " " << std::setw(15) << std::scientific << std::setprecision(8) << ent.second << std::endl;
135  }
136  fout.close();
137  }
138  }
139 
140  // ------------- Interface to global Millepede calibration ----------------
142  static unsigned short getGlobalUniqueID() {return 25;}
144  double getGlobalParam(unsigned short element, unsigned short)
145  {
146  return getT0(WireID(element));
147  }
149  void setGlobalParam(double value, unsigned short element, unsigned short)
150  {
151  WireID wire(element);
152  //This does not work, tries to insert, but we need an update
153  //setT0(wire.getICLayer(), wire.getIWire(), value);
154  m_t0s[wire.getEWire()] = value;
155  }
157  std::vector<std::pair<unsigned short, unsigned short>> listGlobalParams()
158  {
159  std::vector<std::pair<unsigned short, unsigned short>> result;
160  for (auto id_t0 : getT0s()) {
161  result.push_back({id_t0.first, 0});
162  }
163  return result;
164  }
165  // ------------------------------------------------------------------------
166 
167  private:
168  std::map<unsigned short, float> m_t0s;
170  ClassDef(CDCTimeZeros, 2);
171  };
172 
174 } // end namespace Belle2
175 
Belle2::WireID
Class to identify a wire inside the CDC.
Definition: WireID.h:44
Belle2::CDCTimeZeros::dump
void dump() const
Print out all contents.
Definition: CDCTimeZeros.h:119
Belle2::CDCTimeZeros::getGlobalParam
double getGlobalParam(unsigned short element, unsigned short)
Get global parameter.
Definition: CDCTimeZeros.h:152
Belle2::CDCTimeZeros::m_t0s
std::map< unsigned short, float > m_t0s
t0 list
Definition: CDCTimeZeros.h:176
Belle2::WireID::getEWire
unsigned short getEWire() const
Getter for encoded wire number.
Definition: WireID.h:164
Belle2::CDCTimeZeros::setT0
void setT0(unsigned short iCLayer, unsigned short iWire, float t0)
Set t0 in the list.
Definition: CDCTimeZeros.h:50
Belle2::CDCTimeZeros::outputToFile
void outputToFile(std::string fileName) const
Output the contents in text file format.
Definition: CDCTimeZeros.h:133
Belle2::CDCTimeZeros::setGlobalParam
void setGlobalParam(double value, unsigned short element, unsigned short)
Set global parameter.
Definition: CDCTimeZeros.h:157
Belle2::CDCTimeZeros::ClassDef
ClassDef(CDCTimeZeros, 2)
ClassDef.
Belle2::CDCTimeZeros::getT0
float getT0(const WireID &wid) const
Get t0 for the specified wire.
Definition: CDCTimeZeros.h:110
Belle2::CDCTimeZeros::getEntries
unsigned short getEntries() const
Get the no.
Definition: CDCTimeZeros.h:92
Belle2::CDCTimeZeros::listGlobalParams
std::vector< std::pair< unsigned short, unsigned short > > listGlobalParams()
list stored global parameters
Definition: CDCTimeZeros.h:165
Belle2::CDCTimeZeros::CDCTimeZeros
CDCTimeZeros()
Default constructor.
Definition: CDCTimeZeros.h:42
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCTimeZeros
Database object for timing offset (t0).
Definition: CDCTimeZeros.h:36
Belle2::CDCTimeZeros::getGlobalUniqueID
static unsigned short getGlobalUniqueID()
Get global unique id.
Definition: CDCTimeZeros.h:150
Belle2::CDCTimeZeros::addT0
void addT0(unsigned short iCLayer, unsigned short iWire, float delta)
Update t0 in the list.
Definition: CDCTimeZeros.h:71
Belle2::CDCTimeZeros::getT0s
std::map< unsigned short, float > getT0s() const
Get the whole list.
Definition: CDCTimeZeros.h:100
Belle2::WireID::getIWire
unsigned short getIWire() const
Getter for wire within the layer.
Definition: WireID.h:155
Belle2::WireID::getICLayer
unsigned short getICLayer() const
Getter for continuous layer numbering.
Definition: WireID.cc:26