Belle II Software  release-05-01-25
CDCPropSpeeds.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 <vector>
13 #include <iostream>
14 #include <fstream>
15 #include <iomanip>
16 #include <TObject.h>
17 
18 namespace Belle2 {
27  class CDCPropSpeeds: public TObject {
28  public:
29 
33  enum {c_nSlayers = 56};
38  CDCPropSpeeds() {}
39 
45  void setSpeed(unsigned short iCLayer, float speed)
46  {
47  m_speeds.at(iCLayer) = speed;
48  }
49 
55  void addSpeed(unsigned short iCLayer, float delta)
56  {
57  m_speeds.at(iCLayer) += delta;
58  }
59 
63  unsigned short getEntries() const
64  {
65  return m_speeds.size();
66  }
67 
71  std::vector<float> getSpeeds() const
72  {
73  return m_speeds;
74  }
75 
81  float getSpeed(unsigned short iCLayer) const
82  {
83  return m_speeds[iCLayer];
84  }
85 
89  void dump() const
90  {
91  std::cout << " " << std::endl;
92  std::cout << "PropSpeed list" << std::endl;
93  std::cout << "#entries= " << m_speeds.size() << std::endl;
94  std::cout << "in order of clayer and speed (cm/ns)" << std::endl;
95 
96  for (unsigned short iCL = 0; iCL < m_speeds.size(); ++iCL) {
97  std::cout << iCL << " " << m_speeds[iCL] << std::endl;
98  }
99  }
100 
104  void outputToFile(std::string fileName) const
105  {
106  std::ofstream fout(fileName);
107 
108  if (fout.bad()) {
109  B2ERROR("Specified output file could not be opened!");
110  } else {
111  for (unsigned short iCL = 0; iCL < m_speeds.size(); ++iCL) {
112  fout << std::setw(2) << std::right << iCL << " " << std::setw(15) << std::scientific << std::setprecision(
113  8) << m_speeds[iCL] << std::endl;
114  }
115  fout.close();
116  }
117  }
118 
119  private:
120  // std::vector<float> m_speeds; /**< list of speed*/
121  std::vector<float> m_speeds = std::vector<float>(c_nSlayers);
122  ClassDef(CDCPropSpeeds, 1);
123  };
124 
126 } // end namespace Belle2
Belle2::CDCPropSpeeds::getSpeed
float getSpeed(unsigned short iCLayer) const
Get the speed for the specified layer.
Definition: CDCPropSpeeds.h:89
Belle2::CDCPropSpeeds::getSpeeds
std::vector< float > getSpeeds() const
Get the whole list.
Definition: CDCPropSpeeds.h:79
Belle2::CDCPropSpeeds::setSpeed
void setSpeed(unsigned short iCLayer, float speed)
Set the speed in the list.
Definition: CDCPropSpeeds.h:53
Belle2::CDCPropSpeeds::ClassDef
ClassDef(CDCPropSpeeds, 1)
ClassDef.
Belle2::CDCPropSpeeds::dump
void dump() const
Print out contents.
Definition: CDCPropSpeeds.h:97
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CDCPropSpeeds::m_speeds
std::vector< float > m_speeds
list of speed
Definition: CDCPropSpeeds.h:129
Belle2::CDCPropSpeeds::addSpeed
void addSpeed(unsigned short iCLayer, float delta)
Update the speed in the list.
Definition: CDCPropSpeeds.h:63
Belle2::CDCPropSpeeds::outputToFile
void outputToFile(std::string fileName) const
Output the contents in text file format.
Definition: CDCPropSpeeds.h:112
Belle2::CDCPropSpeeds::CDCPropSpeeds
CDCPropSpeeds()
Default constructor.
Definition: CDCPropSpeeds.h:46
Belle2::CDCPropSpeeds::getEntries
unsigned short getEntries() const
Get the no.
Definition: CDCPropSpeeds.h:71