10#include "EventBinningCut.h"
14#include "EventComplexCut.h"
24 EventBinningCut::EventBinningCut() : EventCut(1) {}
26 Package* EventBinningCut::Report()
const {
28 report->
SetName(
"EventBinningCut");
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();
36 for (
auto val : fValuesUp[i]) {
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(); }
60 EventBinningCut::EventBinningCut(
const EventCut& cut,
const std::vector<std::vector<Double_t>>& init) :
61 EventCut(cut.GetCutSize()), fEventCut((EventCut*) cut.MakeCopy()) {
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;
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);
77 xvals.push_back(vals);
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);
89 EventBinningCut::EventBinningCut(
const EventCut& cut,
const std::initializer_list<std::initializer_list<Double_t>>& init) :
90 EventCut(cut.GetCutSize()) {
92 std::vector<std::vector<Double_t>> vec;
94 vec.push_back(Hal::Std::GetVector(i));
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));
105 void EventBinningCut::PreInit(
const std::vector<std::vector<Double_t>>& 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);
114 fBinConv.resize(cutSize);
115 fStepsNo.resize(cutSize);
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];
123 for (
auto i : fStepsNo) {
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];
134 EventBinningCut& EventBinningCut::operator=(
const EventBinningCut& other) {
135 if (&other ==
this)
return *
this;
137 if (fEventCut)
delete fEventCut;
139 fMinTotal = other.fMinTotal;
140 fMaxTotal = other.fMaxTotal;
141 fBinConv = other.fBinConv;
142 fStepsNo = other.fStepsNo;
143 fValuesUp = other.fValuesUp;
144 fTotalBinsNo = other.fTotalBinsNo;
149 EventBinningCut::~EventBinningCut() {
150 if (fEventCut)
delete fEventCut;
156 fLastPassed = fEventCut->
Pass(event);
160 Int_t EventBinningCut::CheckBin(
Event* ) {
161 if (!fLastPassed)
return -1;
164 for (
int iParam = 0; iParam <
GetCutSize(); iParam++) {
165 Double_t val = fEventCut->
GetValue(iParam);
167 for (
int iRange = 1; iRange < (int) fValuesUp[iParam].size(); iRange++) {
168 if (val <= fValuesUp[iParam][iRange]) {
break; }
171 if (bin < 0 || bin >=
int(fValuesUp[iParam].size())) { std::cout <<
" EER" << std::endl; }
172 res = res + bin * fBinConv.at(iParam);
178 if (fEventCut ==
nullptr) {
return kFALSE; }
180 return fEventCut->
Init(task_id);
185 EventBinningCut* EventBinningCut::MakeCopyImg()
const {
return new EventBinningCut(EventImaginaryCut(*fEventCut), fValuesUp); }
188 auto printF = [](TString name,
const std::vector<Double_t>& vec) {
189 std::cout << name << std::endl;
191 std::cout << i <<
" ";
193 std::cout << std::endl;
195 auto printI = [](TString name,
const std::vector<Int_t>& vec) {
196 std::cout << name << std::endl;
198 std::cout << i <<
" ";
200 std::cout << std::endl;
202 printF(
"MinTot", fMinTotal);
203 printF(
"MaxTot", fMaxTotal);
204 printI(
"BinConv", fBinConv);
205 printI(
"StepNo", fStepsNo);
207 for (
auto i : fValuesUp) {
208 printF(Form(
"vals_%i ", c++), i);
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 {
220 strings.push_back(fEventCut->
GetUnit(i));
223 std::vector<int> bins;
226 Int_t newBin = tmpBin % fBinConv[i];
227 Int_t tbin = (tmpBin - newBin) / fBinConv[i];
228 tmpBin = tmpBin - tbin * fBinConv[i];
232 mini.push_back(fValuesUp[i][bins[i]]);
233 maxi.push_back(fValuesUp[i][bins[i] + 1]);
240 return Form(
"Hal::EventBinningCut(%s)", fEventCut->
CutName().Data());
static void PrintInfo(TString text, Hal::EInfo status)
Cut & operator=(const Cut &other)
virtual TString CutName(Option_t *opt="") const
virtual Bool_t Init(Int_t=0)
void SetCollectionID(Int_t i)
TString GetUnit(Int_t i) const
virtual Cut * MakeCopy() const
void SetMinMax(Double_t min, Double_t max, Int_t i=0)
Double_t GetValue(Int_t i=0) const
Double_t GetMin(Int_t i=0) const
Double_t GetMax(Int_t i=0) const
Int_t GetCollectionID() const
void SetUnitName(TString name, Int_t i=0)
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)
virtual Bool_t Pass(Event *event)=0
void SetName(TString name)
void AddObject(TObject *object)