Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
SubCut.cxx
1/*
2 * SubCut.cxx
3 *
4 * Created on: 10 gru 2016
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "SubCut.h"
11
12#include "Cut.h"
13#include "Package.h"
14#include "Parameter.h"
15
16#include <TAxis.h>
17#include <TH1.h>
18#include <TMathBase.h>
19#include <TRandom.h>
20
21namespace Hal {
22 SubCut::SubCut(Int_t size) : TObject(), fMin(nullptr), fMax(nullptr), fValue(nullptr), fUnitName(nullptr) {
23 fSize = size;
24 if (fSize > 0) {
25 fMin = new Double_t[fSize];
26 fMax = new Double_t[fSize];
27 fValue = new Double_t[fSize];
28 fUnitName = new TString[fSize];
29 } else {
30 fSize = 1;
31 fMin = new Double_t[1];
32 fMax = new Double_t[1];
33 fValue = new Double_t[1];
34 fUnitName = new TString[1];
35 }
36 for (int i = 0; i < fSize; i++) {
37 fMin[i] = -1E+9;
38 fMax[i] = 1E+9;
39 fValue[i] = 0;
40 fUnitName[i] = "unknown [XU]";
41 }
42 }
43
44 SubCut::SubCut(const SubCut& other) : TObject(other) {
45 this->fSize = other.fSize;
46 this->fMin = new Double_t[fSize];
47 this->fMax = new Double_t[fSize];
48 this->fValue = new Double_t[fSize];
49 this->fUnitName = new TString[fSize];
50 for (int i = 0; i < fSize; i++) {
51 this->fMin[i] = other.fMin[i];
52 this->fMax[i] = other.fMax[i];
53 this->fValue[i] = other.fValue[i];
54 this->fUnitName[i] = other.fUnitName[i];
55 }
56 }
57
58 SubCut::~SubCut() {
59 delete[] fMin;
60 delete[] fMax;
61 delete[] fUnitName;
62 delete[] fValue;
63 }
64
66 if (this == &other) {
67 return *this;
68 } else {
69 this->fSize = other.fSize;
70 this->fMin = new Double_t[fSize];
71 this->fMax = new Double_t[fSize];
72 this->fValue = new Double_t[fSize];
73 this->fUnitName = new TString[fSize];
74 for (int i = 0; i < fSize; i++) {
75 this->fMin[i] = other.fMin[i];
76 this->fMax[i] = other.fMax[i];
77 this->fValue[i] = other.fValue[i];
78 this->fUnitName[i] = other.fUnitName[i];
79 }
80 return *this;
81 }
82 }
83
84 void SubCut::SetMin(Double_t val, Int_t i) { fMin[i] = val; }
85
86 void SubCut::SetMax(Double_t val, Int_t i) { fMax[i] = val; }
87
88 void SubCutHisto::AddToReport(Package* report) const {
89 report->AddObject(new ParameterString("Label", "Acceptance Histogram"));
90 report->AddObject(fAcceptanceHistogram->Clone());
91 }
93 for (Int_t i = 0; i < fSize; i++) {
94 if (fValue[i] > fMax[i] || fValue[i] < fMin[i]) { return kFALSE; }
95 }
96 return kTRUE;
97 }
98
100 for (Int_t i = 0; i < fSize; i++) {
101 Double_t val = TMath::Abs(fValue[i]);
102 if (val > fMax[i] || val < fMin[i]) { return kFALSE; }
103 }
104 return kTRUE;
105 }
106
107 //================================sub cut histo =============================================================================
108
109 SubCutHisto::SubCutHisto(Int_t size) : fSize(size), fAcceptanceHistogram(NULL), fParX(-1), fParY(-1), fParZ(-1) {}
110
112 TObject(other), fSize(other.fSize), fParX(other.fParX), fParY(other.fParY), fParZ(other.fParZ) {
113 if (other.fAcceptanceHistogram != NULL) {
114 this->fAcceptanceHistogram = (TH1*) other.fAcceptanceHistogram->Clone();
115 fAcceptanceHistogram->SetDirectory(0);
116 }
117 }
118
119 SubCutHisto::~SubCutHisto() {
120 if (fAcceptanceHistogram) delete fAcceptanceHistogram;
121 }
122
123 Bool_t SubCutHisto::Validate(Double_t x, Double_t y, Double_t z) {
124 Double_t prob = 0;
125 switch (fSize) {
126 case 1: prob = fAcceptanceHistogram->GetBinContent(fAcceptanceHistogram->FindBin(x)); break;
127 case 2: prob = fAcceptanceHistogram->GetBinContent(fAcceptanceHistogram->FindFixBin(x, y)); break;
128 case 3: prob = fAcceptanceHistogram->GetBinContent(fAcceptanceHistogram->FindFixBin(x, y, z)); break;
129 default: break;
130 }
131 if (prob == 0) return kFALSE;
132 if (prob == 1) return kTRUE;
133 Double_t randval = gRandom->Rndm();
134 if (randval <= prob) {
135 return kTRUE;
136 } else {
137 return kFALSE;
138 }
139 }
140
141 Bool_t SubCutHisto::ValidateAbs(Double_t x, Double_t y, Double_t z) {
142 return Validate(TMath::Abs(x), TMath::Abs(y), TMath::Abs(z));
143 }
144
145 Bool_t SubCutHisto::Init(const Cut& thisCut, Int_t par1, Int_t par2, Int_t par3) {
146 if (fAcceptanceHistogram == nullptr) return kFALSE;
147 fAcceptanceHistogram->GetXaxis()->SetTitle(thisCut.GetUnit(par1));
148 if (par2 != -1) fAcceptanceHistogram->GetYaxis()->SetTitle(thisCut.GetUnit(par2));
149 if (par3 != -1) fAcceptanceHistogram->GetZaxis()->SetTitle(thisCut.GetUnit(par3));
150 return kFALSE;
151 }
152
154 if (h.InheritsFrom("TH3")) {
155 if (fSize != 3) return kFALSE;
156 for (int i = 0; i <= h.GetNbinsX() + 1; i++) {
157 for (int j = 0; j <= h.GetNbinsY() + 1; j++) {
158 for (int k = 0; k <= h.GetNbinsZ() + 1; k++) {
159 Double_t cont = h.GetBinContent(i, j, k);
160 if (cont < 0 || cont > 1) return kFALSE;
161 }
162 }
163 }
164 } else if (h.InheritsFrom("TH2")) {
165 if (fSize != 2) return kFALSE;
166 for (int i = 0; i <= h.GetNbinsX() + 1; i++) {
167 for (int j = 0; j <= h.GetNbinsY() + 1; j++) {
168 Double_t cont = h.GetBinContent(i, j);
169 if (cont < 0 || cont > 1) return kFALSE;
170 }
171 }
172 } else {
173 if (fSize != 1) return kFALSE;
174 for (int i = 0; i <= h.GetNbinsX() + 1; i++) {
175 Double_t cont = h.GetBinContent(i);
176 if (cont < 0 || cont > 1) return kFALSE;
177 }
178 }
179 fAcceptanceHistogram = (TH1*) h.Clone();
180 fAcceptanceHistogram->SetDirectory(0);
181 return kTRUE;
182 }
183
185 if (this == &other) {
186 return *this;
187 } else {
188 this->fSize = other.fSize;
189 if (other.fAcceptanceHistogram != nullptr) {
190 this->fAcceptanceHistogram = (TH1*) other.fAcceptanceHistogram->Clone();
191 fAcceptanceHistogram->SetDirectory(0);
192 }
193 return *this;
194 }
195 }
196
197
198 SubCutRectangle::SubCutRectangle() : fParX(0), fParY(0) {}
199
200 void SubCutRectangle::AddSquare(Double_t xmin, Double_t xmax, Double_t ymin, Double_t ymax) {
201 if (xmin > xmax) {
202 fMinX.push_back(xmax);
203 fMaxX.push_back(xmin);
204 } else {
205 fMinX.push_back(xmin);
206 fMaxX.push_back(xmax);
207 }
208 if (ymin > ymax) {
209 fMinY.push_back(ymax);
210 fMaxY.push_back(ymin);
211 } else {
212 fMinY.push_back(ymin);
213 fMaxY.push_back(ymax);
214 }
215 }
216
217 Int_t SubCutRectangle::Validate(Double_t x, Double_t y) {
218 Int_t res = 0;
219 for (unsigned int i = 0; i < fMinX.size(); i++) {
220 if (x >= fMinX[i] && x <= fMaxX[i] && y >= fMinY[i] && y <= fMaxY[i]) res++;
221 }
222 return res;
223 }
224
226 report->AddObject(new ParameterString("Label", "SquareCutReport"));
227 report->AddObject(new ParameterInt("XPar", fParX));
228 report->AddObject(new ParameterInt("YPar", fParY));
229 report->AddObject(new ParameterString("XParName", fNameX));
230 report->AddObject(new ParameterString("YParName", fNameY));
231 for (unsigned int i = 0; i < fMinX.size(); i++) {
232 report->AddObject(new ParameterDouble(Form("x_{min} %i", i), fMinX[i]));
233 report->AddObject(new ParameterDouble(Form("x_{max} %i", i), fMaxX[i]));
234 report->AddObject(new ParameterDouble(Form("y_{min} %i", i), fMinY[i]));
235 report->AddObject(new ParameterDouble(Form("y_{max} %i", i), fMaxY[i]));
236 }
237 }
238
239 Bool_t SubCutRectangle::Init(const Cut& thisCut, Int_t par1, Int_t par2) {
240 fParX = par1;
241 fParY = par2;
242 fNameX = thisCut.GetUnit(fParX);
243 fNameY = thisCut.GetUnit(fParY);
244 if (fMinX.size() > 0) return kTRUE;
245 return kFALSE;
246 }
247
248 SubCutRectangle::~SubCutRectangle() {}
249} // namespace Hal
Definition Cut.h:40
TString GetUnit(Int_t i) const
Definition Cut.h:311
void AddObject(TObject *object)
Definition Package.cxx:209
Bool_t ValidateAbs(Double_t x, Double_t y=0, Double_t z=0)
Definition SubCut.cxx:141
Bool_t SetAcceptanceHistogram(const TH1 &h)
Definition SubCut.cxx:153
SubCutHisto(Int_t size=3)
Definition SubCut.cxx:109
void AddToReport(Package *report) const
Definition SubCut.cxx:88
SubCutHisto & operator=(const SubCutHisto &other)
Definition SubCut.cxx:184
Bool_t Init(const Cut &thisCut, Int_t par1, Int_t par2=-1, Int_t par3=-1)
Definition SubCut.cxx:145
Bool_t Validate(Double_t x, Double_t y=0, Double_t z=0)
Definition SubCut.cxx:123
Int_t Validate(Double_t x, Double_t y)
Definition SubCut.cxx:217
Bool_t Init(const Cut &thisCut, Int_t par1, Int_t par2=1)
Definition SubCut.cxx:239
void AddToReport(Package *report) const
Definition SubCut.cxx:225
void SetMax(Double_t val, Int_t i=0)
Definition SubCut.cxx:86
Bool_t ValidateAbs()
Definition SubCut.cxx:99
void SetMin(Double_t val, Int_t i=0)
Definition SubCut.cxx:84
SubCut(Int_t size=1)
Definition SubCut.cxx:22
Bool_t Validate()
Definition SubCut.cxx:92
SubCut & operator=(const SubCut &other)
Definition SubCut.cxx:65