Belle II Software development
CDCDedxInjectionTime.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
9#pragma once
10
11#include <framework/logging/Logger.h>
12
13#include <cmath>
14#include <iostream>
15#include <TObject.h>
16#include <TCanvas.h>
17#include <TH1F.h>
18
19namespace Belle2 {
29 class CDCDedxInjectionTime: public TObject {
30
31 public:
32
37
41 CDCDedxInjectionTime(const std::vector<std::vector<double>>& vinjcalib): m_injectionvar(vinjcalib) {};
42
47
48
53 void printCorrection(std::string svar, std::string sfx) const;
54
55
59 std::vector<std::vector<double>> getConstVector() const
60 {
61 return m_injectionvar;
62 };
63
67 const std::vector<double>& getTimeVector(unsigned int ring) const
68 {
69 if (ring > 1) B2ERROR("wrong index for injection ring ");
70 if (ring * 3 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
71 return m_injectionvar[ring * 3];
72 };
73
77 const std::vector<double>& getMeanVector(unsigned int ring) const
78 {
79 if (ring > 1) B2ERROR("wrong index for injection ring ");
80 if (ring * 3 + 1 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
81 return m_injectionvar[ring * 3 + 1];
82 };
83
87 const std::vector<double>& getResoVector(unsigned int ring) const
88 {
89 if (ring > 1) B2ERROR("wrong index for injection ring ");
90 if (ring * 3 + 2 >= m_injectionvar.size()) B2FATAL("CDCDedxInjectionTime: vector-of-vectors too short");
91 return m_injectionvar[ring * 3 + 2];
92 };
93
98 int getTimeBin(const std::vector<unsigned int>& array, unsigned int value) const
99 {
100 int nabove, nbelow, middle;
101 nabove = array.size() + 1;
102 nbelow = 0;
103 while (nabove - nbelow > 1) {
104 middle = (nabove + nbelow) / 2;
105 if (value == array[middle - 1]) return middle - 1;
106 if (value < array[middle - 1]) nabove = middle;
107 else nbelow = middle;
108 }
109 return nbelow - 1;
110 }
111
117 double getCorrection(std::string svar, unsigned int ring, unsigned int time) const;
118
119
120 private:
121
128 double getSafely(unsigned int iv, int k) const
129 {
130 const auto& vector = m_injectionvar[iv]; // assuming iv is valid index and vector not empty
131 int last = vector.size() - 1;
132 if (k < 0) k = 0;
133 else if (k > last) k = last;
134 return vector[k];
135 }
136
137
141 std::vector<std::vector<double>> m_injectionvar;
144 };
146} // end namespace Belle2
dE/dx injection time calibration constants
CDCDedxInjectionTime(const std::vector< std::vector< double > > &vinjcalib)
Constructor.
std::vector< std::vector< double > > getConstVector() const
Return vector of all constant vector of payload.
int getTimeBin(const std::vector< unsigned int > &array, unsigned int value) const
Return time bin for the given time array.
double getSafely(unsigned int iv, int k) const
Helper: safe access to a vector element.
const std::vector< double > & getResoVector(unsigned int ring) const
Return dedx reso vector.
const std::vector< double > & getTimeVector(unsigned int ring) const
Return time vector.
CDCDedxInjectionTime()
Default constructor.
void printCorrection(std::string svar, std::string sfx) const
Return dE/dx mean or norm-reso value for the given time and ring.
const std::vector< double > & getMeanVector(unsigned int ring) const
Return dedx mean vector.
double getCorrection(std::string svar, unsigned int ring, unsigned int time) const
Return dE/dx mean or norm-reso value for the given time and ring.
ClassDef(CDCDedxInjectionTime, 1)
ClassDef.
std::vector< std::vector< double > > m_injectionvar
CDC dE/dx injection time payloads for dEdx mean and reso.
Abstract base class for different kinds of events.