Belle II Software development
CDCDedx2DCell.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 <TObject.h>
14#include <TH2F.h>
15
16namespace Belle2 {
26 class CDCDedx2DCell: public TObject {
27
28 public:
29
34
38 CDCDedx2DCell(short version, const std::vector<TH2F>& twodgains): m_version(version), m_twodgains(twodgains) {};
39
44
49 {
50 if (m_version != rhs.getVersion()) {
51 B2WARNING("2D cell gain parameters do not match, cannot merge!");
52 return *this;
53 }
54 for (unsigned int layer = 0; layer < getSize(); ++layer) {
55 const TH2F* newhist = rhs.getHist(layer);
56 if (newhist->GetEntries() > 0)m_twodgains[layer].Multiply(newhist);
57 else B2ERROR("ERROR! constant histograms is empty");
58 }
59 return *this;
60 }
61
64 short getVersion() const {return m_version; };
65
68 unsigned int getSize() const { return m_twodgains.size(); };
69
72 const TH2F* getHist(int layer) const
73 {
74 if (m_twodgains.size() == 0) {
75 B2ERROR("ERROR!");
76 return NULL;
77 }
78
79 if (m_twodgains.size() == 2) {
80 if (layer == 0) return &m_twodgains[0];
81 else if (layer == 1) return &m_twodgains[1];
82 else {
83 B2ERROR("ERROR! const histograms NOT found");
84 return NULL;
85 }
86 } else if (m_twodgains.size() == 56) {
87 return &m_twodgains[layer];
88 } else {
89 B2ERROR("ERROR! Something is wrong # of const histograms");
90 return NULL;
91 }
92 return NULL;
93 }
94
100 double getMean(unsigned int layer, int dbin, int ebin) const
101 {
102 int mylayer = 0;
103 if (layer >= 8 && m_twodgains.size() == 2) mylayer = 1;
104 else if (m_twodgains.size() == 56) mylayer = layer;
105
106 return m_twodgains[mylayer].GetBinContent(dbin, ebin);
107 }
108
114 double getMean(unsigned int layer, double doca, double enta) const
115 {
116 if (layer > 56) {
117 B2ERROR("Asking for a CDC layer beyond 56!");
118 return 0;
119 }
120
121 int mylayer = 0;
122 if (layer >= 8 && m_twodgains.size() == 2) mylayer = 1;
123 else if (m_twodgains.size() == 56) mylayer = layer;
124
125 // assume rotational symmetry
126 if (enta < -3.1416 / 2.0) enta += 3.1416 / 2.0;
127 if (enta > 3.1416 / 2.0) enta -= 3.1416 / 2.0;
128
129 // iterate bin number by one since TH2F bins start at 1 not 0
130 double dbinsize = m_twodgains[mylayer].GetXaxis()->GetBinCenter(2) - m_twodgains[mylayer].GetXaxis()->GetBinCenter(1);
131 int dbin = std::floor((doca - m_twodgains[mylayer].GetXaxis()->GetBinLowEdge(1)) / dbinsize) + 1;
132
133 double ebinsize = m_twodgains[mylayer].GetYaxis()->GetBinCenter(2) - m_twodgains[mylayer].GetYaxis()->GetBinCenter(1);
134 // int ebin = std::floor((std::sin(enta) - m_twodgains[mylayer].GetYaxis()->GetBinLowEdge(1)) / ebinsize) + 1;
135 int ebin = std::floor((enta - m_twodgains[mylayer].GetYaxis()->GetBinLowEdge(1)) / ebinsize) + 1;
136
137 double mean = 1.0;
138 if (dbin > 0 && dbin <= m_twodgains[mylayer].GetNbinsX() && ebin > 0 && ebin <= m_twodgains[mylayer].GetNbinsY())
139 mean = m_twodgains[mylayer].GetBinContent(dbin, ebin);
140 else if (dbin > m_twodgains[mylayer].GetNbinsX() && ebin > 0 && ebin <= m_twodgains[mylayer].GetNbinsY())
141 mean = m_twodgains[mylayer].GetBinContent(m_twodgains[mylayer].GetNbinsX(), ebin);
142 else
143 // B2WARNING("Problem with 2D CDC dE/dx calibration! " << doca << "\t" << dbin << "\t" << std::sin(enta) << "\t" << ebin);
144 B2WARNING("Problem with 2D CDC dE/dx calibration! " << doca << "\t" << dbin << "\t" << enta << "\t" << ebin);
145
146 return mean;
147 };
148
149 private:
153 short m_version;
154 std::vector<TH2F> m_twodgains;
157 };
159} // end namespace Belle2
dE/dx wire gain calibration constants
Definition: CDCDedx2DCell.h:26
short m_version
dE/dx gains versus DOCA and entrance angle may be different for different layers, so store as a vecto...
double getMean(unsigned int layer, double doca, double enta) const
Return dE/dx mean value for given DOCA and entrance angle.
ClassDef(CDCDedx2DCell, 5)
ClassDef.
CDCDedx2DCell()
Default constructor.
Definition: CDCDedx2DCell.h:33
~CDCDedx2DCell()
Destructor.
Definition: CDCDedx2DCell.h:43
CDCDedx2DCell & operator*=(CDCDedx2DCell const &rhs)
Combine payloads.
Definition: CDCDedx2DCell.h:48
const TH2F * getHist(int layer) const
Get the 2D histogram for the correction for this layer.
Definition: CDCDedx2DCell.h:72
std::vector< TH2F > m_twodgains
2D histograms of doca/enta gains, layer dependent
CDCDedx2DCell(short version, const std::vector< TH2F > &twodgains)
Constructor.
Definition: CDCDedx2DCell.h:38
double getMean(unsigned int layer, int dbin, int ebin) const
Return dE/dx mean value for the given bin.
short getVersion() const
Get the version for the 2D correction.
Definition: CDCDedx2DCell.h:64
unsigned int getSize() const
Get the number of histograms for the 2D correction.
Definition: CDCDedx2DCell.h:68
Abstract base class for different kinds of events.