Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
CorrFitMask1D.cxx
1/*
2 * CorrFitMask1D.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 "CorrFitMask1D.h"
10
11namespace Hal {
12 Bool_t CorrFitMask1D::AreCompatible(TObject* cf) const {
13 auto func = dynamic_cast<Femto1DCF*>(cf);
14 if (!func) return kFALSE;
15 Int_t bins;
16 Double_t minim, maxim;
17 Std::GetAxisPar(*func->GetNum(), bins, minim, maxim, "x");
18 if (fBins != bins) return kFALSE;
19 if (fMin != minim) return kFALSE;
20 if (fMax != maxim) return kFALSE;
21 return kTRUE;
22 }
23
24 void CorrFitMask1D::Reset(Bool_t state) {
25 for (auto& i : fRawMask) {
26 i = state;
27 }
28 }
29
30 void CorrFitMask1D::ApplyThreshold(const TH1& h, Double_t threshold) {
31 for (int i = 1; i <= h.GetNbinsX(); i++) {
32 if (h.GetBinContent(i) <= threshold) { fRawMask[i] = false; }
33 }
34 }
35
36 CorrFitMask1D::CorrFitMask1D(Int_t bins, Double_t min, Double_t max) : fBins(bins), fMin(min), fMax(max) {
37 fRawMask.resize(fBins + 2);
38 for (auto& i : fRawMask) {
39 i = false;
40 }
41 }
42
43 void CorrFitMask1D::ApplyRange(Double_t min, Double_t max, Bool_t additive) {
44 Double_t binW = 1.0 / ((fMax - fMin) / double(fBins));
45 int low = (min - fMin) * binW + 1;
46 int high = (max - fMin) * binW + 1;
47 if (low < 0) low = 1;
48 if (high > fBins + 1) high = fBins + 1;
49 if (additive) {
50 for (int i = low; i <= high; i++) {
51 fRawMask[i] = true;
52 }
53 } else {
54 for (int i = 0; i < low; i++) {
55 fRawMask[i] = false;
56 }
57 for (int i = high + 1; i < (int) fRawMask.size(); i++) {
58 fRawMask[i] = false;
59 }
60 }
61 }
62
63 Bool_t CorrFitMask1D::Init() {
64 fActiveBins = 0;
65 for (unsigned int i = 1; i < fRawMask.size() - 1; i++) {
66 if (fRawMask[i]) fActiveBins++;
67 }
68
69 return kTRUE;
70 }
71
72 void CorrFitMask1D::SetBin(Int_t bin, Bool_t state) { fRawMask[bin] = state; }
73
74} // namespace Hal