Belle II Software  release-08-01-10
EnergyMask.cc
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 #include <top/reconstruction_cpp/EnergyMask.h>
10 #include <framework/logging/Logger.h>
11 #include <algorithm>
12 #include <cmath>
13 
14 
15 namespace Belle2 {
20  namespace TOP {
21 
22  unsigned EnergyMask::s_Nmin = 4;
23  unsigned EnergyMask::s_Nmax = 256;
24 
25  EnergyMask::EnergyMask(double dyde, double dydL, double dydx, double dy, double dL, double dx, double dE):
26  m_dE(dE), m_Wy(dy / std::abs(dyde))
27  {
28  if (dy <= 0) {
29  B2ERROR("TOP::EnergyMask: dy must be > 0");
30  return;
31  }
32 
33  std::vector<double> x;
34  x.push_back(m_Wy);
35  x.push_back(std::abs(dL * dydL / dyde));
36  x.push_back(std::abs(dx * dydx / dyde));
37  std::sort(x.begin(), x.end());
38 
39  m_A = x[2];
40  m_B = x[1];
41  m_C = x[0];
42 
43  unsigned N = (m_A + m_B + m_C) / 2.0 / dE + 1;
44  if (N < s_Nmin or N > s_Nmax) return;
45 
46  if (m_C / m_A > 0.001) {
47  for (unsigned i = 0; i <= N; i++) {
48  double E = i * dE;
49  double p = threeSquareConvolution(E);
50  m_mask.push_back(p);
51  }
52  } else {
53  for (unsigned i = 0; i <= N; i++) {
54  double E = i * dE;
55  double p = twoSquareConvolution(E);
56  m_mask.push_back(p);
57  }
58  }
59  }
60 
61 
62  double EnergyMask::getMask(double E) const
63  {
64  if (m_C / m_A > 0.001) {
65  return threeSquareConvolution(E);
66  } else {
67  return twoSquareConvolution(E);
68  }
69  }
70 
71 
72  double EnergyMask::getMask(int i) const
73  {
74  if (m_mask.empty()) return getMask(i * m_dE);
75  return mask(i);
76  }
77 
78 
79  double EnergyMask::getMask(int i, double fract) const
80  {
81  if (m_mask.empty()) return getMask((i + fract) * m_dE);
82 
83  if (fract < 0) {
84  i--;
85  fract += 1;
86  }
87  return mask(i) * (1 - fract) + mask(i + 1) * fract;
88  }
89 
90 
91  double EnergyMask::twoSquareConvolution(double E) const
92  {
93  double x1 = (m_A - m_B) / 2;
94  double x2 = (m_A + m_B) / 2;
95  double x = std::abs(E);
96 
97  if (x < x1) {
98  return 1 / m_A * m_Wy;
99  } else if (x < x2) {
100  return (x2 - x) / (x2 - x1) / m_A * m_Wy;
101  } else {
102  return 0;
103  }
104  }
105 
106 
108  {
109  double halfWid = (m_A + m_B + m_C) / 2;
110  if (std::abs(E) >= halfWid) return 0;
111 
112  double t1 = halfWid - E;
113  double t2 = halfWid + E;
114  double p = t1 * t1 + t2 * t2;
115 
116  double t3 = t1 - m_A;
117  double t4 = t2 - m_A;
118  p -= copysign(t3 * t3, t3) + copysign(t4 * t4, t4);
119 
120  t3 = t1 - m_B;
121  t4 = t2 - m_B;
122  p -= copysign(t3 * t3, t3) + copysign(t4 * t4, t4);
123 
124  t3 = t1 - m_C;
125  t4 = t2 - m_C;
126  p -= copysign(t3 * t3, t3) + copysign(t4 * t4, t4);
127 
128  return p / (4 * m_A * m_B * m_C) * m_Wy;
129  }
130 
131  } //TOP
133 } //Belle2
R E
internal precision of FFTW codelets
double threeSquareConvolution(double E) const
Returns a value of convolution of three square distributions at given photon energy.
Definition: EnergyMask.cc:107
double m_C
the smallset energy full width
Definition: EnergyMask.h:129
double mask(int i) const
Returns mask value at given index from stored discrete mask.
Definition: EnergyMask.h:138
double twoSquareConvolution(double E) const
Returns a value of convolution of two square distributions at given photon energy using the largest t...
Definition: EnergyMask.cc:91
double m_Wy
enegy full width of dy
Definition: EnergyMask.h:126
std::vector< double > m_mask
discrete mask (half of)
Definition: EnergyMask.h:130
EnergyMask(double dyde, double dydL, double dydx, double dy, double dL, double dx, double dE)
Constructor.
Definition: EnergyMask.cc:25
double m_A
the largest energy full width
Definition: EnergyMask.h:127
double m_B
the middle energy full width
Definition: EnergyMask.h:128
const std::vector< double > & getMask() const
Returns discrete mask (note: only half of the mask is stored)
Definition: EnergyMask.h:68
static unsigned s_Nmin
minimal mask size
Definition: EnergyMask.h:132
double m_dE
energy step
Definition: EnergyMask.h:125
static unsigned s_Nmax
maximal mask size
Definition: EnergyMask.h:133
Abstract base class for different kinds of events.