9#include "CorrFitMapRebin.h"
11#include "CorrFitInfo.h"
24 CorrFitMapRebin::CorrFitMapRebin() :
34 Bool_t CorrFitMapRebin::Compress(TString outFile) {
35 fInFile =
new TFile(fInFileName,
"read");
37 fInTree = (TTree*) fInFile->Get(
"map");
38 fOutFileName = outFile;
39 TObject* obj = fInfo->GetCf();
43 if (cf3d !=
nullptr) {
45 }
else if (cfsh !=
nullptr) {
47 }
else if (cf1d !=
nullptr) {
50 std::cout <<
"Unknown CF" << std::endl;
56 CorrFitMapRebin::~CorrFitMapRebin() {
67 Bool_t CorrFitMapRebin::Rebin1D() {
68 DividedHisto1D* obj = (DividedHisto1D*) fInfo->GetCf();
69 Int_t sizeX = obj->
GetNum()->GetNbinsX();
70 if (sizeX % fRebinX != 0) {
71 std::cout << Form(
"Cannot rebin X-axis in %s", obj->ClassName()) << std::endl;
75 TH1D* den = (TH1D*) obj->GetDen();
77 Array_1<Float_t>* data =
nullptr;
78 fInTree->SetBranchAddress(
"data", &data);
79 fOutFile =
new TFile(fOutFileName,
"recreate");
80 fOutTree =
new TTree(
"map",
"");
81 Array_1<Float_t>* newData =
new Array_1<Float_t>();
82 fOutTree->Branch(
"data", &newData);
84 newData->MakeBigger(data->GetSize() / fRebinX);
86 Array_1<Float_t> weight(sizeX);
88 Float_t* temp =
new Float_t[fRebinX];
90 for (
int i = 0; i < sizeX / fRebinX; i++) {
92 for (
int j = 0; j < fRebinX; j++) {
93 temp[j] = den->GetBinContent(i * fRebinX + j);
96 for (
int j = 0; j < fRebinX; j++) {
97 weight[i * fRebinX + j] = temp[j] / sum;
98 if (sum == 0) weight[i * fRebinX + j] = 1.0 / ((Float_t) fRebinX);
104 for (
int i = 0; i < fInTree->GetEntries(); i++) {
105 fInTree->GetEntry(i);
106 for (
int j = 0; j < newData->GetSize(); j++) {
108 for (
int k = 0; k < fRebinX; k++) {
109 sum += (*data)[j * fRebinX + k] * weight[j * fRebinX + k];
117 CorrFitInfo* newInfo =
new CorrFitInfo(*fInfo);
118 ((DividedHisto1D*) newInfo->GetCf())->Rebin(fRebinX,
"x");
126 Bool_t CorrFitMapRebin::Rebin3D() {
127 Femto3DCF* obj = (Femto3DCF*) fInfo->GetCf();
128 Int_t sizeX = obj->GetNum()->GetNbinsX();
129 Int_t sizeY = obj->GetNum()->GetNbinsY();
130 Int_t sizeZ = obj->GetNum()->GetNbinsZ();
131 TH3* den = (TH3*) obj->GetDen();
132 if (sizeX % fRebinX != 0) {
133 std::cout <<
"Cannot rebin X-axis in 3DCF" << std::endl;
136 if (sizeY % fRebinY != 0) {
137 std::cout <<
"Cannot rebin Y-axis in 3DCF" << std::endl;
140 if (sizeZ % fRebinZ != 0) {
141 std::cout <<
"Cannot rebin Z-axis in 3DCF" << std::endl;
144 Array_1<Float_t>* data =
nullptr;
145 fInTree->SetBranchAddress(
"data", &data);
146 fOutFile =
new TFile(fOutFileName,
"recreate");
147 fOutTree =
new TTree(
"map",
"");
148 Array_1<Float_t>* newData =
new Array_1<Float_t>();
149 fOutTree->Branch(
"data", &newData);
150 fInTree->GetEntry(0);
151 newData->MakeBigger(data->GetSize() / fRebinX / fRebinY / fRebinZ);
153 Array_3<Int_t> mapL(sizeX, sizeY, sizeZ);
154 Array_3<Float_t> mapW(sizeX, sizeY, sizeZ);
155 Array_3<Int_t> mapS(sizeX / fRebinX, sizeY / fRebinY, sizeZ / fRebinZ);
156 for (
int i = 0; i < sizeX; i++) {
157 for (
int j = 0; j < sizeY; j++) {
158 for (
int k = 0; k < sizeZ; k++) {
159 mapL[i][j][k] = Hal::Std::Bin3dToBin1d(sizeX, sizeY, i, j, k, kFALSE);
163 Int_t sizeXs = sizeX / fRebinX;
164 Int_t sizeYs = sizeY / fRebinY;
165 Int_t sizeZs = sizeZ / fRebinZ;
166 Double_t dummyScale = 1.0 / (Float_t)(fRebinX * fRebinY * fRebinZ);
167 Array_3<Float_t> temp(fRebinX, fRebinY, fRebinZ);
168 for (
int i = 0; i < sizeXs; i++) {
169 for (
int j = 0; j < sizeYs; j++) {
170 for (
int k = 0; k < sizeZs; k++) {
171 mapS[i][j][k] = Hal::Std::Bin3dToBin1d(sizeXs, sizeYs, i, j, k, kFALSE);
173 for (
int a = 0; a < fRebinX; a++) {
174 const Int_t tX = i * fRebinX + a;
175 for (
int b = 0; b < fRebinY; b++) {
176 const Int_t tY = j * fRebinY + b;
177 for (
int c = 0; c < fRebinZ; c++) {
178 const Int_t tZ = k * fRebinZ + c;
180 sum += den->GetBinContent(tX, tY, tZ);
184 for (
int a = 0; a < fRebinX; a++) {
185 const Int_t tX = i * fRebinX + a;
186 for (
int b = 0; b < fRebinY; b++) {
187 const Int_t tY = j * fRebinY + b;
188 for (
int c = 0; c < fRebinZ; c++) {
189 const Int_t tZ = k * fRebinZ + c;
190 mapW[tX][tY][tZ] = den->GetBinContent(tX, tY, tZ) / sum;
191 if (sum == 0) { mapW[tX][tY][tZ] = dummyScale; }
198 Int_t step = fInTree->GetEntries() / 100;
199 for (
int iEv = 0; iEv < fInTree->GetEntries(); iEv++) {
200 fInTree->GetEntry(iEv);
201 if (iEv % step) { Cout::ProgressBar(iEv, fInTree->GetEntries()); }
202 for (
int i = 0; i < sizeXs; i++) {
203 for (
int j = 0; j < sizeYs; j++) {
204 for (
int k = 0; k < sizeZs; k++) {
206 for (
int a = 0; a < fRebinX; a++) {
207 const Int_t tX = i * fRebinX + a;
208 for (
int b = 0; b < fRebinY; b++) {
209 const Int_t tY = j * fRebinY + b;
210 for (
int c = 0; c < fRebinZ; c++) {
211 const Int_t tZ = k * fRebinZ + c;
212 Int_t bin = mapL[tX][tY][tZ];
213 sum += (*data)[bin] * mapW[tX][tY][tZ];
217 (*newData)[mapS[i][j][k]] = sum;
224 CorrFitInfo* newInfo =
new CorrFitInfo(*fInfo);
225 ((DividedHisto3D*) newInfo->GetCf())->Rebin(fRebinX,
"x");
226 ((DividedHisto3D*) newInfo->GetCf())->Rebin(fRebinY,
"y");
227 ((DividedHisto3D*) newInfo->GetCf())->Rebin(fRebinZ,
"z");
236 fInFileName = inFile;
237 fRebinX = fRebinY = fRebinZ = nbins;