Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
EventBinningCut.cxx
1/*
2 * EventBinCut.cxx
3 *
4 * Created on: 1 paź 2018
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9
10#include "EventBinningCut.h"
11
12#include "Cout.h"
13#include "Cut.h"
14#include "EventComplexCut.h"
15#include "Package.h"
16#include "Parameter.h"
17#include "Std.h"
18
19#include <TList.h>
20#include <iostream>
21
22
23namespace Hal {
24 EventBinningCut::EventBinningCut() : EventCut(1) {}
25
26 Package* EventBinningCut::Report() const {
27 Package* report = fEventCut->Report();
28 report->SetName("EventBinningCut");
29
30 for (int i = 0; i < GetCutSize(); i++) {
31 auto* name = new ParameterString(Form("CutUnit[%i]", i), fEventCut->GetUnit(i));
32 auto* minimum = new ParameterDouble(Form("CutMin[%i]", i), fEventCut->GetMin(i));
33 auto* maximum = new ParameterDouble(Form("CutMax[%i]", i), fEventCut->GetMax(i));
34 TList* list = new TList();
35 int j = 0;
36 for (auto val : fValuesUp[i]) {
37 auto* range = new ParameterDouble(Form("Par[%i][%i]", i, j++), val);
38 list->AddLast(range);
39 }
40 report->AddObject(name);
41 report->AddObject(minimum);
42 report->AddObject(maximum);
43 report->AddObject(list);
44 }
45 report->AddObject(fEventCut->Report());
46 return report;
47 }
48
49 EventBinningCut::EventBinningCut(const EventBinningCut& other) : EventCut(other) {
50 fMinTotal = other.fMinTotal;
51 fMaxTotal = other.fMaxTotal;
52 fBinConv = other.fBinConv;
53 fStepsNo = other.fStepsNo;
54 fValuesUp = other.fValuesUp;
55 fTotalBinsNo = other.fTotalBinsNo;
56 fLastPassed = other.fLastPassed;
57 if (other.fEventCut) { fEventCut = (EventCut*) other.fEventCut->MakeCopy(); }
58 }
59
60 EventBinningCut::EventBinningCut(const EventCut& cut, const std::vector<std::vector<Double_t>>& init) :
61 EventCut(cut.GetCutSize()), fEventCut((EventCut*) cut.MakeCopy()) {
62 PreInit(init);
63 }
64
65 EventBinningCut::EventBinningCut(const EventCut& cut, const std::initializer_list<int>& init) :
66 EventCut(cut.GetCutSize()), fEventCut((EventCut*) cut.MakeCopy()) {
67 std::vector<std::vector<Double_t>> xvals;
68 Int_t counter = 0;
69 for (auto val : init) {
70 std::vector<Double_t> vals;
71 Double_t minX = cut.GetMin(counter);
72 Double_t maxX = cut.GetMax(counter);
73 Double_t step = (maxX - minX) / Double_t(val);
74 for (int i = 0; i <= val; i++) {
75 vals.push_back(minX + i * step);
76 }
77 xvals.push_back(vals);
78 counter++;
79 }
80 for (int i = counter; i < GetCutSize(); i++) {
81 std::vector<Double_t> vals;
82 vals.push_back(fEventCut->GetMin(i));
83 vals.push_back(fEventCut->GetMax(i));
84 xvals.push_back(vals);
85 }
86 PreInit(xvals);
87 }
88
89 EventBinningCut::EventBinningCut(const EventCut& cut, const std::initializer_list<std::initializer_list<Double_t>>& init) :
90 EventCut(cut.GetCutSize()) {
91 fEventCut = (EventCut*) cut.MakeCopy();
92 std::vector<std::vector<Double_t>> vec;
93 for (auto i : init) {
94 vec.push_back(Hal::Std::GetVector(i));
95 }
96 for (int i = (int) vec.size(); i < fEventCut->GetCutSize(); i++) {
97 std::vector<Double_t> temp;
98 temp.push_back(fEventCut->GetMin(i));
99 temp.push_back(fEventCut->GetMax(i));
100 vec.push_back(temp);
101 }
102 PreInit(vec);
103 }
104
105 void EventBinningCut::PreInit(const std::vector<std::vector<Double_t>>& vals) {
106 Int_t cutSize = fEventCut->GetCutSize();
107 fValuesUp = vals;
108 if (int(fValuesUp.size()) != cutSize) { Cout::PrintInfo("Wrong setting in event cut binned", EInfo::kCriticalError); }
109 for (int i = 0; i < cutSize; i++) {
110 fEventCut->SetMinMax(fValuesUp[i][0], fValuesUp[i][fValuesUp[i].size() - 1], i);
111 SetMinMax(fEventCut->GetMin(i), fEventCut->GetMax(i), i);
112 SetUnitName(fEventCut->GetUnit(i), i);
113 }
114 fBinConv.resize(cutSize);
115 fStepsNo.resize(cutSize);
116 fBinConv[0] = 1;
117 fStepsNo[0] = fValuesUp[0].size() - 1;
118 for (int i = 1; i < cutSize; i++) {
119 fStepsNo[i] = fValuesUp[i].size() - 1;
120 fBinConv[i] = fBinConv[i - 1] * fStepsNo[i - 1];
121 }
122 fTotalBinsNo = 1;
123 for (auto i : fStepsNo) {
124 fTotalBinsNo *= i;
125 }
126 fMinTotal.resize(cutSize);
127 fMaxTotal.resize(cutSize);
128 for (int i = 0; i < cutSize; i++) {
129 fMinTotal[i] = fValuesUp[i][0];
130 fMaxTotal[i] = fValuesUp[i][fValuesUp[i].size() - 1];
131 }
132 }
133
134 EventBinningCut& EventBinningCut::operator=(const EventBinningCut& other) {
135 if (&other == this) return *this;
136 EventCut::operator=(other);
137 if (fEventCut) delete fEventCut;
138 fEventCut = nullptr;
139 fMinTotal = other.fMinTotal;
140 fMaxTotal = other.fMaxTotal;
141 fBinConv = other.fBinConv;
142 fStepsNo = other.fStepsNo;
143 fValuesUp = other.fValuesUp;
144 fTotalBinsNo = other.fTotalBinsNo;
145 if (other.fEventCut) fEventCut = (EventCut*) other.fEventCut->MakeCopy();
146 return *this;
147 }
148
149 EventBinningCut::~EventBinningCut() {
150 if (fEventCut) delete fEventCut;
151 }
152
154
156 fLastPassed = fEventCut->Pass(event);
157 return fLastPassed;
158 }
159
160 Int_t EventBinningCut::CheckBin(Event* /*event*/) {
161 if (!fLastPassed) return -1;
162 Int_t res = 0;
163
164 for (int iParam = 0; iParam < GetCutSize(); iParam++) {
165 Double_t val = fEventCut->GetValue(iParam);
166 Int_t bin = 0;
167 for (int iRange = 1; iRange < (int) fValuesUp[iParam].size(); iRange++) {
168 if (val <= fValuesUp[iParam][iRange]) { break; }
169 bin++;
170 }
171 if (bin < 0 || bin >= int(fValuesUp[iParam].size())) { std::cout << " EER" << std::endl; }
172 res = res + bin * fBinConv.at(iParam);
173 }
174 return res;
175 }
176
177 Bool_t EventBinningCut::Init(Int_t task_id) {
178 if (fEventCut == nullptr) { return kFALSE; }
179 fEventCut->SetCollectionID(GetCollectionID());
180 return fEventCut->Init(task_id);
181 }
182
183 EventBinningCut* EventBinningCut::MakeCopyReal() const { return new EventBinningCut(EventRealCut(*fEventCut), fValuesUp); }
184
185 EventBinningCut* EventBinningCut::MakeCopyImg() const { return new EventBinningCut(EventImaginaryCut(*fEventCut), fValuesUp); }
186
187 void EventBinningCut::Print(Option_t* /*opt*/) const {
188 auto printF = [](TString name, const std::vector<Double_t>& vec) {
189 std::cout << name << std::endl;
190 for (auto i : vec) {
191 std::cout << i << " ";
192 }
193 std::cout << std::endl;
194 };
195 auto printI = [](TString name, const std::vector<Int_t>& vec) {
196 std::cout << name << std::endl;
197 for (auto i : vec) {
198 std::cout << i << " ";
199 }
200 std::cout << std::endl;
201 };
202 printF("MinTot", fMinTotal);
203 printF("MaxTot", fMaxTotal);
204 printI("BinConv", fBinConv);
205 printI("StepNo", fStepsNo);
206 int c = 0;
207 for (auto i : fValuesUp) {
208 printF(Form("vals_%i ", c++), i);
209 };
210 }
211
212 void EventBinningCut::GetBinParam(Int_t bin,
213 std::vector<Double_t>& mini,
214 std::vector<Double_t>& maxi,
215 std::vector<TString>& strings) const {
216 mini.clear();
217 maxi.clear();
218 strings.clear();
219 for (int i = 0; i < GetCutSize(); i++) {
220 strings.push_back(fEventCut->GetUnit(i));
221 }
222 Int_t tmpBin = bin;
223 std::vector<int> bins;
224 bins.resize(GetCutSize());
225 for (int i = GetCutSize() - 1; i >= 0; i--) {
226 Int_t newBin = tmpBin % fBinConv[i];
227 Int_t tbin = (tmpBin - newBin) / fBinConv[i];
228 tmpBin = tmpBin - tbin * fBinConv[i];
229 bins[i] = tbin;
230 }
231 for (int i = 0; i < GetCutSize(); i++) {
232 mini.push_back(fValuesUp[i][bins[i]]);
233 maxi.push_back(fValuesUp[i][bins[i] + 1]);
234 }
235
236 // TODO Fix this
237 }
238
239 TString EventBinningCut::CutName(Option_t* /*opt*/) const {
240 return Form("Hal::EventBinningCut(%s)", fEventCut->CutName().Data());
241 }
242
243} // namespace Hal
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
Cut & operator=(const Cut &other)
Definition Cut.cxx:170
virtual TString CutName(Option_t *opt="") const
Definition Cut.cxx:214
virtual Bool_t Init(Int_t=0)
Definition Cut.h:346
void SetCollectionID(Int_t i)
Definition Cut.h:247
TString GetUnit(Int_t i) const
Definition Cut.h:311
virtual Cut * MakeCopy() const
Definition Cut.h:317
void SetMinMax(Double_t min, Double_t max, Int_t i=0)
Definition Cut.cxx:93
Double_t GetValue(Int_t i=0) const
Definition Cut.h:285
Int_t GetCutSize() const
Definition Cut.h:252
Double_t GetMin(Int_t i=0) const
Definition Cut.h:273
Double_t GetMax(Int_t i=0) const
Definition Cut.h:279
Int_t GetCollectionID() const
Definition Cut.h:257
void SetUnitName(TString name, Int_t i=0)
Definition Cut.h:241
virtual TString CutName(Option_t *opt="") const
virtual void Print(Option_t *opt=0) const
virtual Bool_t Pass(Event *event)
EventBinningCut * MakeCopy() const
virtual Bool_t Init(Int_t task_id)
EventCut(const Int_t i=1)
Definition EventCut.cxx:12
virtual Bool_t Pass(Event *event)=0
Package * Report() const
Definition Package.cxx:129
void SetName(TString name)
Definition Package.cxx:298
void AddObject(TObject *object)
Definition Package.cxx:209