Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitMask3D.cxx
1/*
2 * CorrFitMask3D.cxx
3 *
4 * Created on: 12 lut 2023
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "CorrFitMask3D.h"
11
12#include "Cout.h"
13#include "Femto3DCF.h"
14#include "StdHist.h"
15
16#include <Rtypes.h>
17#include <TH1.h>
18#include <TString.h>
19
20namespace Hal {
21 Bool_t CorrFitMask3D::Init() {
22 fActiveBins = 0;
23 for (int i = 1; i < (int) fRawMask.size() - 1; i++) { // dont take into account overflow/underflow bins
24 for (int j = 1; j < (int) fRawMask[0].size() - 1; j++) {
25 for (int k = 1; k < (int) fRawMask[0][0].size() - 1; k++) {
26 if (fRawMask[i][j][k]) fActiveBins++;
27 }
28 }
29 }
30 return kTRUE;
31 }
32
33 Bool_t CorrFitMask3D::AreCompatible(TObject* cf) const {
34 auto func = dynamic_cast<Femto3DCF*>(cf);
35 if (!func) return kFALSE;
36
37 TString opts[3] = {"x", "y", "z"};
38 for (int i = 0; i < 3; i++) {
39 Int_t bins;
40 Double_t minim, maxim;
41 Std::GetAxisPar(*func->GetNum(), bins, minim, maxim, opts[i]);
42 if (fBins[i] != bins) return kFALSE;
43 if (fMin[i] != minim) return kFALSE;
44 if (fMax[i] != maxim) return kFALSE;
45 }
46 return kTRUE;
47 }
48
49
50 CorrFitMask3D::CorrFitMask3D(Int_t binsX,
51 Double_t minX,
52 Double_t maxX,
53 Int_t binsY,
54 Double_t minY,
55 Double_t maxY,
56 Int_t binsZ,
57 Double_t minZ,
58 Double_t maxZ) {
59 fBins[0] = binsX;
60 fBins[1] = binsY;
61 fBins[2] = binsZ;
62 fMin[0] = minX;
63 fMin[1] = minY;
64 fMin[2] = minZ;
65 fMax[0] = maxX;
66 fMax[1] = maxY;
67 fMax[2] = maxZ;
68 fRawMask.resize(fBins[0] + 2);
69 for (auto& i : fRawMask) {
70 i.resize(fBins[1] + 2);
71 for (auto& j : i) {
72 j.resize(fBins[2] + 2);
73 }
74 }
75 }
76
77 void CorrFitMask3D::ApplyRange(Double_t minX,
78 Double_t maxX,
79 Double_t minY,
80 Double_t maxY,
81 Double_t minZ,
82 Double_t maxZ,
83 Bool_t additive) {
84 int low[3], high[3];
85 double min[3] = {minX, minY, minZ};
86 double max[3] = {maxX, maxY, maxZ};
87 for (int i = 0; i < 3; i++) {
88 Double_t binW = 1.0 / ((fMax[i] - fMin[i]) / double(fBins[i]));
89 low[i] = (min[i] - fMin[i]) * binW;
90 high[i] = (max[i] - fMin[i]) * binW;
91 if (low[i] < 0) low[i] = 1;
92 if (high[i] > fBins[i] + 1) high[i] = fBins[i] + 1;
93 }
94 if (additive) {
95 for (int i = low[0]; i <= high[0]; i++) {
96 for (int j = low[1]; j <= high[1]; j++) {
97 for (int k = low[2]; k <= high[2]; k++) {
98 fRawMask[i][j][k] = true;
99 }
100 }
101 }
102 } else {
103 for (int i = 0; i < (int) fRawMask.size(); i++) {
104 for (int j = 0; j < (int) fRawMask[0].size(); j++) {
105 for (int k = 0; k < (int) fRawMask[0][0].size(); k++) {
106 if (i < low[0]) fRawMask[i][j][k] = false;
107 if (i > high[0]) fRawMask[i][j][k] = false;
108 if (j < low[1]) fRawMask[i][j][k] = false;
109 if (j > high[1]) fRawMask[i][j][k] = false;
110 if (k < low[2]) fRawMask[i][j][k] = false;
111 if (k > high[2]) fRawMask[i][j][k] = false;
112 }
113 }
114 }
115 }
116 }
117
118 void CorrFitMask3D::SetBin(Int_t binX, Int_t binY, Int_t binZ, Bool_t state) { fRawMask[binX][binY][binZ] = state; }
119
120 void CorrFitMask3D::Reset(Bool_t state) {
121 for (int i = 0; i < (int) fRawMask.size(); i++) {
122 for (int j = 0; j < (int) fRawMask[0].size(); j++) {
123 for (int k = 0; k < (int) fRawMask[0][0].size(); k++) {
124 fRawMask[i][j][k] = state;
125 }
126 }
127 }
128 }
129
130 void CorrFitMask3D::ApplyThreshold(const TH1& h, Double_t threshold) {
131 for (int i = 1; i <= h.GetNbinsX(); i++) {
132 for (int j = 1; j <= h.GetNbinsY(); j++) {
133 for (int k = 1; k <= h.GetNbinsZ(); k++) {
134 if (h.GetBinContent(i, j, k) <= threshold) { fRawMask[i][j][k] = false; }
135 }
136 }
137 }
138 }
139
140 void CorrFitMask3D::ApplyMask(EFitExtraMask mask, Bool_t additive) {
141 Array_3<Short_t> map;
142 map.MakeBigger(GetNbinsX() + 1, GetNbinsY() + 1, GetNbinsZ() + 1);
143 for (int i = 0; i <= GetNbinsX() + 1; i++) {
144 for (int j = 0; j <= GetNbinsY() + 1; j++) {
145 for (int k = 0; k <= GetNbinsZ() + 1; k++) {
146 map[i][j][k] = false;
147 }
148 }
149 }
150 CalcMap(map, mask);
151 for (int i = 0; i <= GetNbinsX() + 1; i++) {
152 for (int j = 0; j <= GetNbinsY() + 1; j++) {
153 for (int k = 0; k <= GetNbinsZ() + 1; k++) {
154 if (additive) {
155 if (map[i][j][k]) fRawMask[i][j][k] = true;
156 } else {
157 if (!map[i][j][k]) fRawMask[i][j][k] = false;
158 }
159 }
160 }
161 }
162 }
163
164 void CorrFitMask3D::CalcMap(Array_3<Short_t>& map, EFitExtraMask mask) {
165 if (mask == EFitExtraMask::kSlice) {
166 CalculateSliceBins(map);
167 } else if (mask == EFitExtraMask::kDiagonalSlice || mask == EFitExtraMask::kDiagonalSliceIgnored) {
168 CalculateDiagonalBins(map, mask);
169 } else if (mask == EFitExtraMask::kUltraDiagonalSlice || mask == EFitExtraMask::kUltraDiagonalSliceIgnored) {
170 CalculateUltradiagonalBins(map, mask);
171 }
172 }
173
174 void CorrFitMask3D::CalculateDiagonalBins(Array_3<Short_t>& map, EFitExtraMask mask) {
175 Int_t nBinX = GetNbinsX();
176 Int_t nBinY = GetNbinsY();
177 Int_t nBinZ = GetNbinsZ();
178 Double_t x = 0;
179 Int_t middle_x = 1 + int(nBinX * (x - fMin[0]) / (fMax[0] - fMin[0]));
180 // Int_t middle_y = 1 + int(nBinX * (x - fMin[1]) / (fMax[1] - fMin[1]));
181 // Int_t middle_z = 1 + int(nBinX * (x - fMin[2]) / (fMax[2] - fMin[2]));
182 CalculateSliceBins(map);
183
184 if (nBinX != nBinY || nBinY != nBinZ) {
186 "CorrFit3DCF::CalculateDiagonalBins cannot use cross bins, different number of bins in 3D, switch to slice", "M", kRed);
187 return;
188 }
189
190 // first diagonal with non-egde histo
191 if (middle_x != 1 || mask == EFitExtraMask::kDiagonalSliceIgnored) {
192 for (int i = 1; i <= nBinX; i++) {
193 Int_t a = i;
194 Int_t b = nBinX - i + 1;
195 // first diagonal
196 map[a][a][a] = true;
197 map[a][a][b] = true;
198 map[a][b][a] = true;
199 map[a][b][b] = true;
200 }
201 } else {
202 // diagonal with edges
203 for (int i = 1; i <= nBinX; i++) {
204 Int_t a = i;
205 // first diagonal
206 map[a][a][a] = true;
207 }
208 }
209 }
210
211 void CorrFitMask3D::CalculateUltradiagonalBins(Array_3<Short_t>& map, EFitExtraMask mask) {
212 Int_t nBinX = GetNbinsX();
213 Int_t nBinY = GetNbinsY();
214 Int_t nBinZ = GetNbinsZ();
215 Double_t x = 0;
216 Int_t middle_x = 1 + int(nBinX * (x - fMin[0]) / (fMax[0] - fMin[0]));
217 Int_t middle_y = 1 + int(nBinX * (x - fMin[1]) / (fMax[1] - fMin[1]));
218 Int_t middle_z = 1 + int(nBinX * (x - fMin[2]) / (fMax[2] - fMin[2]));
219 CalculateSliceBins(map);
220
221 if (nBinX != nBinY || nBinY != nBinZ) {
223 "CorrFit3DCF::CalculateUltradiagonalBins cannot use cross bins, different number of bins in 3D, switch to slice",
224 "M",
225 kRed);
226
227 return;
228 }
229
230 if (middle_x != 1 || mask == EFitExtraMask::kUltraDiagonalSliceIgnored) {
231 for (int i = 1; i <= nBinX; i++) {
232 Int_t a = i;
233 Int_t b = nBinX - i + 1;
234 // diagonals
235 map[a][a][a] = true;
236 map[a][a][b] = true;
237 map[a][b][a] = true;
238 map[a][b][b] = true;
239
240 map[middle_x][a][a] = true;
241 map[middle_x][a][b] = true;
242 map[a][middle_y][a] = true;
243 map[a][middle_y][b] = true;
244 map[a][a][middle_z] = true;
245 map[a][b][middle_z] = true;
246 }
247 } else {
248 for (int i = 1; i <= nBinX; i++) {
249
250 Int_t a = i;
251 // Int_t b = nBinX - i + 1;
252 // diagonals
253 map[a][a][a] = true;
254 map[middle_x][a][a] = true;
255 map[a][middle_y][a] = true;
256 map[a][a][middle_z] = true;
257 }
258 }
259 }
260
261 void CorrFitMask3D::CalculateSliceBins(Array_3<Short_t>& map) {
262 Int_t nBinX = GetNbinsX();
263 Int_t nBinY = GetNbinsY();
264 Int_t nBinZ = GetNbinsZ();
265 Double_t x = 0;
266 Int_t middle_x = 1 + int(nBinX * (x - fMin[0]) / (fMax[0] - fMin[0]));
267 Int_t middle_y = 1 + int(nBinX * (x - fMin[1]) / (fMax[1] - fMin[1]));
268 Int_t middle_z = 1 + int(nBinX * (x - fMin[2]) / (fMax[2] - fMin[2]));
269 for (int i = 1; i <= nBinX; i++) {
270 map[i][middle_y][middle_z] = true;
271 }
272 for (int j = 1; j <= nBinY; j++) {
273 map[middle_x][j][middle_z] = true;
274 }
275 for (int k = 1; k <= nBinZ; k++) {
276 map[middle_x][middle_y][k] = true;
277 }
278 }
279
280} // namespace Hal
static void Text(TString text, TString option="L", Color_t color=-1)
Definition Cout.cxx:92