Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitHDFunc3D.cxx
1/*
2 * CorrFitHDFunc3D.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#include "CorrFitHDFunc3D.h"
10
11#include "CorrFitMask3D.h"
12
13#include <iostream>
14
15namespace Hal {
16 CorrFitHDFunc3D::CorrFitHDFunc3D() : CorrFitHDFunc(3) {}
17
18 void CorrFitHDFunc3D::SetMask(const CorrFitMask& mask, TH1* denominator, Bool_t hd) {
19 TH3* den3d = static_cast<TH3*>(denominator);
20 const CorrFitMask3D* mask3d = dynamic_cast<const CorrFitMask3D*>(&mask);
21 Int_t maxBins = TMath::Max(mask3d->GetNbinsX(), TMath::Max(mask3d->GetNbinsY(), mask3d->GetNbinsZ()));
22 fDenominatorHD.MakeBigger(
23 den3d->GetNbinsX() * 2 + 1, den3d->GetNbinsY() * 2 + 1, den3d->GetNbinsZ() * 2 + 1); //+1 to keep compatible with bin id
24 fDenominatorSum.MakeBigger(
25 den3d->GetNbinsX() + 1, den3d->GetNbinsY() + 1, den3d->GetNbinsZ() + 1); //+1 to keep compatible with bin id
26 fMapHD.MakeBigger(den3d->GetNbinsX() * 2 + 1, den3d->GetNbinsY() * 2 + 1, den3d->GetNbinsZ() * 2 + 1);
27 fMins[0] = den3d->GetXaxis()->GetBinLowEdge(1);
28 fMins[1] = den3d->GetYaxis()->GetBinLowEdge(1);
29 fMins[2] = den3d->GetZaxis()->GetBinLowEdge(1);
30 fSteps[0] = den3d->GetXaxis()->GetBinWidth(1) * 0.5;
31 fSteps[1] = den3d->GetYaxis()->GetBinWidth(1) * 0.5;
32 fSteps[2] = den3d->GetZaxis()->GetBinWidth(1) * 0.5;
33 RecalcHDBin(maxBins);
34 CalculateBinsArrays(*mask3d, hd);
35 if (hd == kFALSE) {
36 for (int i = 0; i < fBinsX.GetSize(); i++) {
37 Int_t binX = fBinsX[i];
38 Int_t binY = fBinsY[i];
39 Int_t binZ = fBinsZ[i];
40 fDenominatorHD[GetBinHD(binX)][GetBinHD(binY)][GetBinHD(binZ)] = den3d->GetBinContent(binX, binY, binZ);
41 fDenominatorSum[binX][binY][binZ] = 1;
42 }
43 return;
44 }
45
46 // calculate flags for HD bins && no of bins;
47
48
49 Spline3D spline(den3d, "yes");
50 std::cout << "REFIT START" << std::endl;
51 spline.Refit();
52 std::cout << "REFIT ENDL" << std::endl;
53 for (int i = 0; i < fBinsHDX.GetSize(); i++) {
54 Double_t binX = fBinsHDX[i];
55 Double_t x = EvalHDX(binX);
56 Double_t binY = fBinsHDY[i];
57 Double_t y = EvalHDY(binY);
58 Double_t binZ = fBinsHDZ[i];
59 Double_t z = EvalHDZ(binZ);
60 fDenominatorHD[binX][binY][binZ] = spline.Eval(x, y, z);
61 }
62 Int_t sizeX = fDenominatorSum.GetSize();
63 Int_t sizeY = fDenominatorSum[0].GetSize();
64 Int_t sizeZ = fDenominatorSum[0][0].GetSize();
65 for (int i = 1; i < sizeX; i++) {
66 Int_t binX = GetBinHD(i);
67 for (int j = 1; j < sizeY; j++) {
68 Int_t binY = GetBinHD(j);
69 for (int k = 1; k < sizeZ; k++) {
70 Int_t binZ = GetBinHD(k);
71 if (!mask3d->GetBinFlag(i, j, k)) continue;
72 Double_t sum = 0;
73 for (int a = -1; a < 2; a++) {
74 for (int b = -1; b < 2; b++) {
75 for (int c = -1; c < 2; c++) {
76 sum += fDenominatorHD[binX + a][binY + b][binZ + c];
77 }
78 }
79 }
80 if (sum == 0)
81 fDenominatorSum[i][j][k] = 0;
82 else
83 fDenominatorSum[i][j][k] = 1. / sum;
84 }
85 }
86 }
87 }
88
89 Double_t CorrFitHDFunc3D::GetBinCFVal(Int_t BinX, Int_t BinY, Int_t BinZ, Bool_t extrapolated) const {
90 if (extrapolated) {
91 Double_t val = 0;
92 Int_t xbin0 = GetBinHD(BinX);
93 Int_t ybin0 = GetBinHD(BinY);
94 Int_t zbin0 = GetBinHD(BinZ);
95 for (int i = -1; i < 2; i++) {
96 for (int j = -1; j < 2; j++) {
97 for (int k = -1; k < 2; k++) {
98 val += fDenominatorHD.Get(xbin0 + i, ybin0 + j, zbin0 + k) * fMapHD.Get(xbin0 + i, ybin0 + j, zbin0 + k);
99 }
100 }
101 }
102 return val * fDenominatorSum.Get(BinX, BinY, BinZ);
103 }
104 return fMapHD.Get(GetBinHD(BinX), GetBinHD(BinY), GetBinHD(BinZ));
105 }
106
107 void CorrFitHDFunc3D::CalculateBinsArrays(const CorrFitMask3D& mask, Bool_t hd) {
108 // calculate standard bins----------------------------------------------------
109 Int_t nonZeroBins = mask.GetActiveBins();
110 if (nonZeroBins != fBinsX.GetSize()) {
111 fBinsX.Resize(nonZeroBins);
112 fBinsY.Resize(nonZeroBins);
113 fBinsZ.Resize(nonZeroBins);
114 }
115 Array_3<Short_t> tempFlags(mask.GetNbinsX() * 2 + 1, mask.GetNbinsY() * 2 + 1, mask.GetNbinsZ() * 2 + 1);
116 Int_t hdBinsNo = 0;
117 Int_t binId = 0;
118 for (int i = 1; i <= mask.GetNbinsX(); i++) {
119 Int_t binX = GetBinHD(i);
120 for (int j = 1; j <= mask.GetNbinsY(); j++) {
121 Int_t binY = GetBinHD(j);
122 for (int k = 1; k <= mask.GetNbinsZ(); k++) {
123 Int_t binZ = GetBinHD(k);
124 if (mask.GetBinFlag(i, j, k)) {
125 fBinsX[binId] = i;
126 fBinsY[binId] = j;
127 fBinsZ[binId++] = k;
128 if (hd) {
129 for (int a = -1; a < 2; a++) {
130 for (int b = -1; b < 2; b++) {
131 for (int c = -1; c < 2; c++) {
132 // empty bin that will be filled
133 if (tempFlags[binX + a][binY + b][binZ + c] == 0) {
134 hdBinsNo++;
135 tempFlags[binX + a][binY + b][binZ + c] = 1;
136 }
137 }
138 }
139 }
140 } else {
141 hdBinsNo++;
142 tempFlags[binX][binY][binZ] = 1;
143 }
144 }
145 }
146 }
147 }
148 // calculate hd bins-------------------------------------------------------
149
150 fBinsHDX.Resize(hdBinsNo);
151 fBinsHDY.Resize(hdBinsNo);
152 fBinsHDZ.Resize(hdBinsNo);
153 Int_t hdBinNo = 0;
154 for (int i = 0; i < tempFlags.GetSize(); i++) {
155 for (int j = 0; j < tempFlags[0].GetSize(); j++) {
156 for (int k = 0; k < tempFlags[0][0].GetSize(); k++) {
157 if (tempFlags[i][j][k] == 1) {
158 fBinsHDX[hdBinNo] = i;
159 fBinsHDY[hdBinNo] = j;
160 fBinsHDZ[hdBinNo] = k;
161 ++hdBinNo;
162 }
163 }
164 }
165 }
166 }
167
168} // namespace Hal
Double_t Eval(Double_t x, Double_t y, Double_t z) const
Definition Splines.cxx:645