Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitHDFunc1D.cxx
1/*
2 * CorrFitHDFunc1Da.cpp
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 "CorrFitHDFunc1D.h"
10
11namespace Hal {
12 CorrFitHDFunc1D::CorrFitHDFunc1D() : CorrFitHDFunc(1) {}
13
14 void CorrFitHDFunc1D::SetMask(const CorrFitMask& mask, TH1* denominator, Bool_t hd) {
15 const CorrFitMask1D* mask1d = dynamic_cast<const CorrFitMask1D*>(&mask);
16 Int_t maxBins = mask1d->GetNBins() * 2 + 1;
17 fDenominatorHD.Resize(maxBins); //+1 to keep compatible with bin id
18 fDenominatorSum.Resize(denominator->GetNbinsX() + 1); //+1 to keep compatible with bin id
19 fMapHD.Resize(maxBins);
20 fMins[0] = denominator->GetXaxis()->GetBinLowEdge(1);
21 fSteps[0] = denominator->GetXaxis()->GetBinWidth(1) * 0.5;
22 RecalcHDBin(mask1d->GetNBins());
23 CalculateBinsArrays(*mask1d, hd);
24 if (hd == kFALSE) {
25 for (int i = 0; i < fBins.GetSize(); i++) {
26 Int_t bin = fBins[i];
27 fDenominatorHD[GetBinHD(bin)] = denominator->GetBinContent(bin);
28 fDenominatorSum[bin] = 1;
29 }
30 return;
31 }
32 // calculate flags for HD bins && no of bins;
33
34 Spline1D spline(denominator, denominator->GetBinContent(1), denominator->GetBinContent(denominator->GetNbinsX()));
35 spline.Refit();
36 for (int i = 0; i < fBinsHD.GetSize(); i++) {
37 Double_t bin = fBinsHD[i];
38 Double_t x = EvalHD(bin);
39 fDenominatorHD[bin] = spline.Eval(x);
40 }
41 for (int i = 1; i < fDenominatorSum.GetSize(); i++) {
42 if (!mask1d->GetBinFlag(i)) continue;
43 Int_t bin = GetBinHD(i);
44 Double_t prev = fDenominatorHD[bin - 1];
45 Double_t curr = fDenominatorHD[bin];
46 Double_t next = fDenominatorHD[bin + 1];
47 Double_t sum = prev + curr + next;
48 if (sum == 0) {
49 fDenominatorSum[i] = 0;
50 } else {
51 fDenominatorSum[i] = 1.0 / sum;
52 }
53 }
54 }
55
56 Double_t CorrFitHDFunc1D::GetBinCFVal(Int_t BinX, Bool_t extrapolated) const {
57 Int_t bin = GetBinHD(BinX);
58 if (extrapolated) {
59 // CF *weight
60 Double_t low = fMapHD.Get(bin - 1) * fDenominatorHD.Get(bin - 1);
61 Double_t med = fMapHD.Get(bin) * fDenominatorHD.Get(bin);
62 Double_t high = fMapHD.Get(bin + 1) * fDenominatorHD.Get(bin + 1);
63 Double_t scale = fDenominatorSum.Get(BinX);
64 return scale * (low + med + high);
65 } else {
66 return fMapHD.Get(bin);
67 }
68 }
69
70 void CorrFitHDFunc1D::CalculateBinsArrays(const CorrFitMask1D& mask, Bool_t hd) {
71 Int_t nonZero = mask.GetActiveBins();
72 if (nonZero != fBins.GetSize()) fBins.Resize(nonZero);
73 Int_t binId = 0;
74 Int_t hdBinsNo = 0;
75 Array_1<Short_t> tempFlags(mask.GetNBins() * 2 + 1);
76 for (int i = 1; i <= mask.GetNBins(); i++) {
77 if (mask.GetBinFlag(i)) {
78 fBins[binId++] = i;
79 Int_t binHd = GetBinHD(i);
80 if (!hd) {
81 ++hdBinsNo;
82 tempFlags[binHd] = 1;
83 } else {
84 for (int a = -1; a <= -1; a++) {
85 if (tempFlags[binHd + a] == 0) {
86 ++hdBinsNo;
87 tempFlags[binHd + a] = 1;
88 }
89 }
90 }
91 }
92 }
93 fBinsHD.Resize(hdBinsNo);
94 Int_t hdBinsId = 0;
95 for (int i = 0; i < tempFlags.GetSize(); i++) {
96 if (tempFlags[i] == 1) fBinsHD[hdBinsId++] = i;
97 }
98 }
99
100 CorrFitHDFunc1D::~CorrFitHDFunc1D() {}
101} // namespace Hal
Double_t Eval(Double_t x) const
Definition Splines.cxx:55