ATLAS Offline Software
Interp3D.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include <TH3F.h>
8 
9 #include <iostream>
10 
11 double Interp3D::Interpol3d(double x, double y, double z, std::shared_ptr<TH3F> h) const {
12  int nx = h->GetNbinsX(), ny = h->GetNbinsY(), nz = h->GetNbinsZ();
13  int ibx = h->GetXaxis()->FindBin(x), iby = h->GetYaxis()->FindBin(y), ibz = h->GetZaxis()->FindBin(z);
14  int ibx2{0}, iby2{0}, ibz2{0};
15  double z000{0.}, z010{0.}, z110{0.}, z100{0.}, z001{0.}, z011{0.}, z111{0.}, z101{0.}, xc{0.}, yc{0.}, zc{0.}, xc2{0.}, yc2{0.},
16  zc2{0.}, u{0.}, t{0.}, v{0.}, r{0.};
17  if (ibx > nx)
18  ibx = nx;
19  else if (ibx == 0)
20  ibx = 1;
21  if (iby > ny)
22  iby = ny;
23  else if (iby == 0)
24  iby = 1;
25  if (ibz > nz)
26  ibz = nz;
27  else if (ibz == 0)
28  ibz = 1;
29  xc = h->GetXaxis()->GetBinCenter(ibx);
30  yc = h->GetYaxis()->GetBinCenter(iby);
31  zc = h->GetZaxis()->GetBinCenter(ibz);
32  //
33  z111 = h->GetBinContent(ibx, iby, ibz);
34 
35  // Test no interp for egamma object in the vicinity of the crack
36  bool doX = true;
37  bool doY = true;
38  auto itr = m_NoInterp.find(h->GetName());
39  if (itr != m_NoInterp.end()) {
40  for (auto rangeX : itr->second.xRange) {
41  if (x > rangeX.first && x < rangeX.second) doX = false;
42  }
43  double ay = std::abs(y);
44  for (auto rangeY : itr->second.yRange) {
45  if (ay > rangeY.first && ay < rangeY.second) doY = false;
46  }
47  }
48  if (m_debug)
49  std::cout << "Isolation type = " << h->GetName() << " pT = " << x << " pT interp ? " << doX << " eta = " << y << " eta interp ? "
50  << doY << " No interp cut = " << z111 << std::endl;
51 
52  if (!doX && !doY) return z111;
53 
54  if ((ibx > 1 || (ibx == 1 && x > xc)) && (ibx < nx || (ibx == nx && x < xc))) {
55  if (x > xc) {
56  ibx2 = ibx + 1;
57  } else {
58  ibx2 = ibx - 1;
59  }
60  xc2 = h->GetXaxis()->GetBinCenter(ibx2);
61  if ((iby > 1 || (iby == 1 && y > yc)) && (iby < ny || (iby == ny && y < yc))) {
62  if (y > yc) {
63  iby2 = iby + 1;
64  } else {
65  iby2 = iby - 1;
66  }
67  yc2 = h->GetYaxis()->GetBinCenter(iby2);
68  if ((ibz > 1 || (ibz == 1 && z > zc)) && (ibz < nz || (ibz == nz && z < zc))) {
69  if (z > zc) {
70  ibz2 = ibz + 1;
71  } else {
72  ibz2 = ibz - 1;
73  }
74  zc2 = h->GetZaxis()->GetBinCenter(ibz2);
75 
76  //
77  if (m_debug) {
78  std::cout << "Normal situation " << x << " " << ibx << " " << ibx2 << " " << y << " " << iby << " " << iby2 << " " << z
79  << " " << ibz << " " << ibz2 << std::endl;
80  std::cout << "Bin centers " << xc << " " << xc2 << " " << yc << " " << yc2 << " " << zc << " " << zc2 << std::endl;
81  }
82  //
83  z000 = h->GetBinContent(ibx2, iby2, ibz2);
84  z100 = h->GetBinContent(ibx, iby2, ibz2);
85  z010 = h->GetBinContent(ibx2, iby, ibz2);
86  z110 = h->GetBinContent(ibx, iby, ibz2);
87  z001 = h->GetBinContent(ibx2, iby2, ibz);
88  z101 = h->GetBinContent(ibx, iby2, ibz);
89  z011 = h->GetBinContent(ibx2, iby, ibz);
90 
91  t = (x - xc2) / (xc - xc2);
92  u = (y - yc2) / (yc - yc2);
93  v = (z - zc2) / (zc - zc2);
94  if (!doX) t = 1;
95  if (!doY) u = 1;
96 
97  if (m_debug) {
98  std::cout << "Cuts " << z000 << " " << z100 << " " << z010 << " " << z110 << " " << z001 << " " << z101 << " " << z011
99  << " " << z111 << std::endl;
100  std::cout << "interp coeff " << t << " " << u << " " << v << std::endl;
101  }
102 
103  r = z111 * t * u * v + z001 * (1. - t) * (1. - u) * v + z011 * (1. - t) * u * v + z101 * t * (1. - u) * v +
104  z110 * t * u * (1. - v) + z000 * (1. - t) * (1. - u) * (1. - v) + z010 * (1. - t) * u * (1. - v) +
105  z100 * t * (1. - u) * (1. - v);
106  } else {
107  z011 = h->GetBinContent(ibx2, iby, ibz);
108  z001 = h->GetBinContent(ibx2, iby2, ibz);
109  z101 = h->GetBinContent(ibx, iby2, ibz);
110  t = (x - xc2) / (xc - xc2);
111  u = (y - yc2) / (yc - yc2);
112  if (!doX) t = 1;
113  if (!doY) u = 1;
114  r = z111 * t * u + z011 * (1. - t) * u + z101 * t * (1. - u) + z001 * (1. - t) * (1. - u);
115  }
116  } else if ((ibz > 1 || (ibz == 1 && z > zc)) && (ibz < nz || (ibz == nz && z < zc))) {
117  if (z > zc) {
118  ibz2 = ibz + 1;
119  } else {
120  ibz2 = ibz - 1;
121  }
122 
123  z110 = h->GetBinContent(ibx, iby, ibz2);
124  z010 = h->GetBinContent(ibx2, iby, ibz2);
125  z011 = h->GetBinContent(ibx2, iby, ibz);
126  zc2 = h->GetYaxis()->GetBinCenter(ibz2);
127 
128  t = (x - xc2) / (xc - xc2);
129  if (!doX) t = 1;
130  v = (z - zc2) / (zc - zc2);
131  r = z111 * t * v + z011 * (1. - t) * v + z110 * t * (1. - v) + z010 * (1. - t) * (1. - v);
132 
133  } else {
134  z011 = h->GetBinContent(ibx2, iby, ibz);
135  t = (x - xc2) / (xc - xc2);
136  if (!doX) t = 1;
137  r = z111 * t + z011 * (1. - t);
138  }
139  } else {
140  if ((iby > 1 || (iby == 1 && y > yc)) && (iby < ny || (iby == ny && y < yc))) {
141  if (y > yc) {
142  iby2 = iby + 1;
143  } else {
144  iby2 = iby - 1;
145  }
146  yc2 = h->GetYaxis()->GetBinCenter(iby2);
147  if ((ibz > 1 || (ibz == 1 && z > zc)) && (ibz < nz || (ibz == nz && z < zc))) {
148  if (z > zc) {
149  ibz2 = ibz + 1;
150  } else {
151  ibz2 = ibz - 1;
152  }
153  zc2 = h->GetZaxis()->GetBinCenter(ibz2);
154  //
155  z100 = h->GetBinContent(ibx, iby2, ibz2);
156  z110 = h->GetBinContent(ibx, iby, ibz2);
157  z101 = h->GetBinContent(ibx, iby2, ibz);
158  u = (y - yc2) / (yc - yc2);
159  if (!doY) u = 1;
160  v = (z - zc2) / (zc - zc2);
161  r = z111 * u * v + z101 * (1. - u) * v + z110 * u * (1. - v) + z100 * (1. - u) * (1. - v);
162  } else {
163  z101 = h->GetBinContent(ibx, iby2, ibz);
164  u = (y - yc2) / (yc - yc2);
165  if (!doY) u = 1;
166  r = z111 * u + z101 * (1. - u);
167  }
168  } else if ((ibz > 1 || (ibz == 1 && z > zc)) && (ibz < nz || (ibz == nz && z < zc))) {
169  if (z > zc) {
170  ibz2 = ibz + 1;
171  } else {
172  ibz2 = ibz - 1;
173  }
174  z110 = h->GetBinContent(ibx, iby, ibz2);
175  zc2 = h->GetYaxis()->GetBinCenter(ibz2);
176  v = (z - zc2) / (zc - zc2);
177  r = z111 * v + z110 * (1. - v);
178  } else {
179  r = z111;
180  }
181  }
182 
183  if (m_debug) std::cout << "Cut " << r << std::endl;
184 
185  return r;
186 }
beamspotman.r
def r
Definition: beamspotman.py:676
Interp3D::m_debug
bool m_debug
Definition: Interp3D.h:29
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
x
#define x
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
Interp3D::m_NoInterp
std::map< std::string, VetoInterp > m_NoInterp
Definition: Interp3D.h:28
z
#define z
Interp3D::Interpol3d
double Interpol3d(double x, double y, double z, std::shared_ptr< TH3F > h) const
Definition: Interp3D.cxx:11
python.PyAthena.v
v
Definition: PyAthena.py:154
y
#define y
h
Interp3D.h
fitman.ay
ay
Definition: fitman.py:525